2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "r600_formats.h"
25 #include "r600_opcodes.h"
26 #include "r600_shader.h"
29 #include "sb/sb_public.h"
31 #include "pipe/p_shader_tokens.h"
32 #include "tgsi/tgsi_info.h"
33 #include "tgsi/tgsi_parse.h"
34 #include "tgsi/tgsi_scan.h"
35 #include "tgsi/tgsi_dump.h"
36 #include "util/u_bitcast.h"
37 #include "util/u_memory.h"
38 #include "util/u_math.h"
43 Why CAYMAN got loops for lots of instructions is explained here.
45 -These 8xx t-slot only ops are implemented in all vector slots.
46 MUL_LIT, FLT_TO_UINT, INT_TO_FLT, UINT_TO_FLT
47 These 8xx t-slot only opcodes become vector ops, with all four
48 slots expecting the arguments on sources a and b. Result is
49 broadcast to all channels.
50 MULLO_INT, MULHI_INT, MULLO_UINT, MULHI_UINT, MUL_64
51 These 8xx t-slot only opcodes become vector ops in the z, y, and
53 EXP_IEEE, LOG_IEEE/CLAMPED, RECIP_IEEE/CLAMPED/FF/INT/UINT/_64/CLAMPED_64
54 RECIPSQRT_IEEE/CLAMPED/FF/_64/CLAMPED_64
57 The w slot may have an independent co-issued operation, or if the
58 result is required to be in the w slot, the opcode above may be
59 issued in the w slot as well.
60 The compiler must issue the source argument to slots z, y, and x
63 /* Contents of r0 on entry to various shaders
69 GS - r0.xyw, r1.xyz = per-vertex offsets
75 .w = tess factor base.
77 TES - .x = TessCoord.x
79 - .z = RelPatchID (??)
82 PS - face_gpr.z = SampleMask
85 #define R600_SHADER_BUFFER_INFO_SEL (512 + R600_BUFFER_INFO_OFFSET / 16)
86 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
87 struct r600_pipe_shader
*pipeshader
,
88 union r600_shader_key key
);
90 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
91 int size
, unsigned comp_mask
) {
96 if (ps
->num_arrays
== ps
->max_arrays
) {
98 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
99 sizeof(struct r600_shader_array
));
102 int n
= ps
->num_arrays
;
105 ps
->arrays
[n
].comp_mask
= comp_mask
;
106 ps
->arrays
[n
].gpr_start
= start_gpr
;
107 ps
->arrays
[n
].gpr_count
= size
;
110 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
114 fprintf(stderr
, "STREAMOUT\n");
115 for (i
= 0; i
< so
->num_outputs
; i
++) {
116 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
117 so
->output
[i
].start_component
;
118 fprintf(stderr
, " %i: MEM_STREAM%d_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
120 so
->output
[i
].stream
,
121 so
->output
[i
].output_buffer
,
122 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
123 so
->output
[i
].register_index
,
128 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
132 static int store_shader(struct pipe_context
*ctx
,
133 struct r600_pipe_shader
*shader
)
135 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
138 if (shader
->bo
== NULL
) {
139 shader
->bo
= (struct r600_resource
*)
140 pipe_buffer_create(ctx
->screen
, 0, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
141 if (shader
->bo
== NULL
) {
144 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
145 if (R600_BIG_ENDIAN
) {
146 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
147 ptr
[i
] = util_cpu_to_le32(shader
->shader
.bc
.bytecode
[i
]);
150 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
152 rctx
->b
.ws
->buffer_unmap(shader
->bo
->buf
);
158 int r600_pipe_shader_create(struct pipe_context
*ctx
,
159 struct r600_pipe_shader
*shader
,
160 union r600_shader_key key
)
162 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
163 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
165 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
,
166 tgsi_get_processor_type(sel
->tokens
));
167 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
169 unsigned export_shader
;
171 shader
->shader
.bc
.isa
= rctx
->isa
;
174 fprintf(stderr
, "--------------------------------------------------------------\n");
175 tgsi_dump(sel
->tokens
, 0);
177 if (sel
->so
.num_outputs
) {
178 r600_dump_streamout(&sel
->so
);
181 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
183 R600_ERR("translation from TGSI failed !\n");
186 if (shader
->shader
.processor_type
== PIPE_SHADER_VERTEX
) {
187 /* only disable for vertex shaders in tess paths */
191 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_CTRL
);
192 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_EVAL
);
193 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_COMPUTE
);
195 /* disable SB for shaders using doubles */
196 use_sb
&= !shader
->shader
.uses_doubles
;
198 use_sb
&= !shader
->shader
.uses_atomics
;
199 use_sb
&= !shader
->shader
.uses_images
;
200 use_sb
&= !shader
->shader
.uses_helper_invocation
;
202 /* Check if the bytecode has already been built. */
203 if (!shader
->shader
.bc
.bytecode
) {
204 r
= r600_bytecode_build(&shader
->shader
.bc
);
206 R600_ERR("building bytecode failed !\n");
211 sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
212 if (dump
&& !sb_disasm
) {
213 fprintf(stderr
, "--------------------------------------------------------------\n");
214 r600_bytecode_disasm(&shader
->shader
.bc
);
215 fprintf(stderr
, "______________________________________________________________\n");
216 } else if ((dump
&& sb_disasm
) || use_sb
) {
217 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
220 R600_ERR("r600_sb_bytecode_process failed !\n");
225 if (shader
->gs_copy_shader
) {
228 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
229 &shader
->gs_copy_shader
->shader
, dump
, 0);
234 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
238 /* Store the shader in a buffer. */
239 if ((r
= store_shader(ctx
, shader
)))
243 switch (shader
->shader
.processor_type
) {
244 case PIPE_SHADER_TESS_CTRL
:
245 evergreen_update_hs_state(ctx
, shader
);
247 case PIPE_SHADER_TESS_EVAL
:
249 evergreen_update_es_state(ctx
, shader
);
251 evergreen_update_vs_state(ctx
, shader
);
253 case PIPE_SHADER_GEOMETRY
:
254 if (rctx
->b
.chip_class
>= EVERGREEN
) {
255 evergreen_update_gs_state(ctx
, shader
);
256 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
258 r600_update_gs_state(ctx
, shader
);
259 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
262 case PIPE_SHADER_VERTEX
:
263 export_shader
= key
.vs
.as_es
;
264 if (rctx
->b
.chip_class
>= EVERGREEN
) {
266 evergreen_update_ls_state(ctx
, shader
);
267 else if (key
.vs
.as_es
)
268 evergreen_update_es_state(ctx
, shader
);
270 evergreen_update_vs_state(ctx
, shader
);
273 r600_update_es_state(ctx
, shader
);
275 r600_update_vs_state(ctx
, shader
);
278 case PIPE_SHADER_FRAGMENT
:
279 if (rctx
->b
.chip_class
>= EVERGREEN
) {
280 evergreen_update_ps_state(ctx
, shader
);
282 r600_update_ps_state(ctx
, shader
);
285 case PIPE_SHADER_COMPUTE
:
286 evergreen_update_ls_state(ctx
, shader
);
295 r600_pipe_shader_destroy(ctx
, shader
);
299 void r600_pipe_shader_destroy(struct pipe_context
*ctx UNUSED
, struct r600_pipe_shader
*shader
)
301 r600_resource_reference(&shader
->bo
, NULL
);
302 r600_bytecode_clear(&shader
->shader
.bc
);
303 r600_release_command_buffer(&shader
->command_buffer
);
307 * tgsi -> r600 shader
309 struct r600_shader_tgsi_instruction
;
311 struct r600_shader_src
{
318 boolean kc_rel
; /* true if cache bank is indexed */
327 struct r600_shader_ctx
{
328 struct tgsi_shader_info info
;
329 struct tgsi_array_info
*array_infos
;
330 /* flag for each tgsi temp array if its been spilled or not */
331 bool *spilled_arrays
;
332 struct tgsi_parse_context parse
;
333 const struct tgsi_token
*tokens
;
335 unsigned file_offset
[TGSI_FILE_COUNT
];
337 const struct r600_shader_tgsi_instruction
*inst_info
;
338 struct r600_bytecode
*bc
;
339 struct r600_shader
*shader
;
340 struct r600_shader_src src
[4];
343 uint32_t max_driver_temp_used
;
344 /* needed for evergreen interpolation */
345 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
346 /* evergreen/cayman also store sample mask in face register */
348 /* sample id is .w component stored in fixed point position register */
349 int fixed_pt_position_gpr
;
351 boolean clip_vertex_write
;
353 unsigned edgeflag_output
;
354 int helper_invoc_reg
;
355 int cs_block_size_reg
;
356 int cs_grid_size_reg
;
357 bool cs_block_size_loaded
, cs_grid_size_loaded
;
359 int next_ring_offset
;
360 int gs_out_ring_offset
;
362 struct r600_shader
*gs_for_vs
;
363 int gs_export_gpr_tregs
[4];
364 int gs_rotated_input
[2];
365 const struct pipe_stream_output_info
*gs_stream_output_info
;
366 unsigned enabled_stream_buffers_mask
;
367 unsigned tess_input_info
; /* temp with tess input offsets */
368 unsigned tess_output_info
; /* temp with tess input offsets */
369 unsigned thread_id_gpr
; /* temp with thread id calculated for images */
372 struct r600_shader_tgsi_instruction
{
374 int (*process
)(struct r600_shader_ctx
*ctx
);
377 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
378 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
379 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
380 static inline int callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
381 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
382 static int tgsi_else(struct r600_shader_ctx
*ctx
);
383 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
384 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
385 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
386 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
387 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
388 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
389 unsigned int dst_reg
);
390 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
391 const struct r600_shader_src
*shader_src
,
393 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
394 unsigned dst_reg
, unsigned mask
);
396 static bool ctx_needs_stack_workaround_8xx(struct r600_shader_ctx
*ctx
)
398 if (ctx
->bc
->family
== CHIP_HEMLOCK
||
399 ctx
->bc
->family
== CHIP_CYPRESS
||
400 ctx
->bc
->family
== CHIP_JUNIPER
)
405 static int tgsi_last_instruction(unsigned writemask
)
409 for (i
= 0; i
< 4; i
++) {
410 if (writemask
& (1 << i
)) {
417 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
419 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
422 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
423 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
427 if (i
->Instruction
.Label
) {
428 R600_ERR("label unsupported\n");
432 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
433 if (i
->Src
[j
].Register
.Dimension
) {
434 switch (i
->Src
[j
].Register
.File
) {
435 case TGSI_FILE_CONSTANT
:
436 case TGSI_FILE_HW_ATOMIC
:
438 case TGSI_FILE_INPUT
:
439 if (ctx
->type
== PIPE_SHADER_GEOMETRY
||
440 ctx
->type
== PIPE_SHADER_TESS_CTRL
||
441 ctx
->type
== PIPE_SHADER_TESS_EVAL
)
443 case TGSI_FILE_OUTPUT
:
444 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
447 R600_ERR("unsupported src %d (file %d, dimension %d)\n", j
,
448 i
->Src
[j
].Register
.File
,
449 i
->Src
[j
].Register
.Dimension
);
454 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
455 if (i
->Dst
[j
].Register
.Dimension
) {
456 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
458 R600_ERR("unsupported dst (dimension)\n");
465 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
467 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
468 interpolate
== TGSI_INTERPOLATE_LINEAR
||
469 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
471 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
475 case TGSI_INTERPOLATE_LOC_CENTER
:
478 case TGSI_INTERPOLATE_LOC_CENTROID
:
481 case TGSI_INTERPOLATE_LOC_SAMPLE
:
486 return is_linear
* 3 + loc
;
492 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
495 int i
= eg_get_interpolator_index(
496 ctx
->shader
->input
[input
].interpolate
,
497 ctx
->shader
->input
[input
].interpolate_location
);
499 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
502 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
505 struct r600_bytecode_alu alu
;
506 int gpr
= 0, base_chan
= 0;
507 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
509 /* work out gpr and base_chan from index */
511 base_chan
= (2 * (ij_index
% 2)) + 1;
513 for (i
= 0; i
< 8; i
++) {
514 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
517 alu
.op
= ALU_OP2_INTERP_ZW
;
519 alu
.op
= ALU_OP2_INTERP_XY
;
521 if ((i
> 1) && (i
< 6)) {
522 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
526 alu
.dst
.chan
= i
% 4;
528 alu
.src
[0].sel
= gpr
;
529 alu
.src
[0].chan
= (base_chan
- (i
% 2));
531 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
533 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
536 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
543 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
546 struct r600_bytecode_alu alu
;
548 for (i
= 0; i
< 4; i
++) {
549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
551 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
553 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
558 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
563 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
571 * Special export handling in shaders
573 * shader export ARRAY_BASE for EXPORT_POS:
576 * 62, 63 are clip distance vectors
578 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
579 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
580 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
581 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
582 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
583 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
584 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
585 * exclusive from render target index)
586 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
589 * shader export ARRAY_BASE for EXPORT_PIXEL:
591 * 61 computed Z vector
593 * The use of the values exported in the computed Z vector are controlled
594 * by DB_SHADER_CONTROL:
595 * Z_EXPORT_ENABLE - Z as a float in RED
596 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
597 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
598 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
599 * DB_SOURCE_FORMAT - export control restrictions
604 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
605 static int r600_spi_sid(struct r600_shader_io
* io
)
607 int index
, name
= io
->name
;
609 /* These params are handled differently, they don't need
610 * semantic indices, so we'll use 0 for them.
612 if (name
== TGSI_SEMANTIC_POSITION
||
613 name
== TGSI_SEMANTIC_PSIZE
||
614 name
== TGSI_SEMANTIC_EDGEFLAG
||
615 name
== TGSI_SEMANTIC_FACE
||
616 name
== TGSI_SEMANTIC_SAMPLEMASK
)
619 if (name
== TGSI_SEMANTIC_GENERIC
) {
620 /* For generic params simply use sid from tgsi */
623 /* For non-generic params - pack name and sid into 8 bits */
624 index
= 0x80 | (name
<<3) | (io
->sid
);
627 /* Make sure that all really used indices have nonzero value, so
628 * we can just compare it to 0 later instead of comparing the name
629 * with different values to detect special cases. */
636 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
637 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
639 switch (semantic_name
) {
640 case TGSI_SEMANTIC_POSITION
:
642 case TGSI_SEMANTIC_PSIZE
:
644 case TGSI_SEMANTIC_CLIPDIST
:
647 case TGSI_SEMANTIC_GENERIC
:
649 return 4 + index
- 9;
651 /* same explanation as in the default statement,
652 * the only user hitting this is st/nine.
656 /* patch indices are completely separate and thus start from 0 */
657 case TGSI_SEMANTIC_TESSOUTER
:
659 case TGSI_SEMANTIC_TESSINNER
:
661 case TGSI_SEMANTIC_PATCH
:
665 /* Don't fail here. The result of this function is only used
666 * for LS, TCS, TES, and GS, where legacy GL semantics can't
667 * occur, but this function is called for all vertex shaders
668 * before it's known whether LS will be compiled or not.
674 /* turn input into interpolate on EG */
675 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
679 if (ctx
->shader
->input
[index
].spi_sid
) {
680 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
681 if (ctx
->shader
->input
[index
].interpolate
> 0) {
682 evergreen_interp_assign_ij_index(ctx
, index
);
683 r
= evergreen_interp_alu(ctx
, index
);
685 r
= evergreen_interp_flat(ctx
, index
);
691 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
693 struct r600_bytecode_alu alu
;
695 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
696 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
698 for (i
= 0; i
< 4; i
++) {
699 memset(&alu
, 0, sizeof(alu
));
700 alu
.op
= ALU_OP3_CNDGT
;
703 alu
.dst
.sel
= gpr_front
;
704 alu
.src
[0].sel
= ctx
->face_gpr
;
705 alu
.src
[1].sel
= gpr_front
;
706 alu
.src
[2].sel
= gpr_back
;
713 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
720 /* execute a single slot ALU calculation */
721 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
722 int dst_sel
, int dst_chan
,
723 int src0_sel
, unsigned src0_chan_val
,
724 int src1_sel
, unsigned src1_chan_val
)
726 struct r600_bytecode_alu alu
;
729 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
730 for (i
= 0; i
< 4; i
++) {
731 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
733 alu
.src
[0].sel
= src0_sel
;
734 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
735 alu
.src
[0].value
= src0_chan_val
;
737 alu
.src
[0].chan
= src0_chan_val
;
738 alu
.src
[1].sel
= src1_sel
;
739 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
740 alu
.src
[1].value
= src1_chan_val
;
742 alu
.src
[1].chan
= src1_chan_val
;
743 alu
.dst
.sel
= dst_sel
;
745 alu
.dst
.write
= i
== dst_chan
;
747 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
754 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
756 alu
.src
[0].sel
= src0_sel
;
757 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
758 alu
.src
[0].value
= src0_chan_val
;
760 alu
.src
[0].chan
= src0_chan_val
;
761 alu
.src
[1].sel
= src1_sel
;
762 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
763 alu
.src
[1].value
= src1_chan_val
;
765 alu
.src
[1].chan
= src1_chan_val
;
766 alu
.dst
.sel
= dst_sel
;
767 alu
.dst
.chan
= dst_chan
;
770 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
776 /* execute a single slot ALU calculation */
777 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
778 int dst_sel
, int dst_chan
,
779 int src0_sel
, unsigned src0_chan_val
,
780 int src1_sel
, unsigned src1_chan_val
,
781 int src2_sel
, unsigned src2_chan_val
)
783 struct r600_bytecode_alu alu
;
786 /* validate this for other ops */
787 assert(op
== ALU_OP3_MULADD_UINT24
|| op
== ALU_OP3_CNDE_INT
|| op
== ALU_OP3_BFE_UINT
);
788 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
790 alu
.src
[0].sel
= src0_sel
;
791 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
792 alu
.src
[0].value
= src0_chan_val
;
794 alu
.src
[0].chan
= src0_chan_val
;
795 alu
.src
[1].sel
= src1_sel
;
796 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
797 alu
.src
[1].value
= src1_chan_val
;
799 alu
.src
[1].chan
= src1_chan_val
;
800 alu
.src
[2].sel
= src2_sel
;
801 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
802 alu
.src
[2].value
= src2_chan_val
;
804 alu
.src
[2].chan
= src2_chan_val
;
805 alu
.dst
.sel
= dst_sel
;
806 alu
.dst
.chan
= dst_chan
;
809 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
815 /* put it in temp_reg.x */
816 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
818 int temp_reg
, bool is_patch_var
)
822 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
824 Dimension - patch0_offset (input_vals.z),
825 Non-dim - patch0_data_offset (input_vals.w)
827 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
829 ctx
->tess_output_info
, 0,
831 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
837 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
839 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
842 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
844 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
847 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
850 i
= ctx
->shader
->noutput
++;
851 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
852 ctx
->shader
->output
[i
].sid
= 0;
853 ctx
->shader
->output
[i
].gpr
= 0;
854 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
855 ctx
->shader
->output
[i
].write_mask
= 0x4;
856 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
861 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
863 struct r600_bytecode_alu alu
;
866 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
867 alu
.op
= ctx
->inst_info
->op
;
870 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
876 static void choose_spill_arrays(struct r600_shader_ctx
*ctx
, int *regno
, unsigned *scratch_space_needed
)
878 // pick largest array and spill it, repeat until the number of temps is under limit or we run out of arrays
879 unsigned n
= ctx
->info
.array_max
[TGSI_FILE_TEMPORARY
];
880 unsigned narrays_left
= n
;
881 bool *spilled
= ctx
->spilled_arrays
; // assumed calloc:ed
883 *scratch_space_needed
= 0;
884 while (*regno
> 124 && narrays_left
) {
886 unsigned largest
= 0;
887 unsigned largest_index
= 0;
889 for (i
= 0; i
< n
; i
++) {
890 unsigned size
= ctx
->array_infos
[i
].range
.Last
- ctx
->array_infos
[i
].range
.First
+ 1;
891 if (!spilled
[i
] && size
> largest
) {
897 spilled
[largest_index
] = true;
899 *scratch_space_needed
+= largest
;
904 if (narrays_left
== 0) {
905 ctx
->info
.indirect_files
&= ~(1 << TGSI_FILE_TEMPORARY
);
909 /* Take spilled temp arrays into account when translating tgsi register
910 * indexes into r600 gprs if spilled is false, or scratch array offset if
912 static int map_tgsi_reg_index_to_r600_gpr(struct r600_shader_ctx
*ctx
, unsigned tgsi_reg_index
, bool *spilled
)
915 unsigned spilled_size
= 0;
917 for (i
= 0; i
< ctx
->info
.array_max
[TGSI_FILE_TEMPORARY
]; i
++) {
918 if (tgsi_reg_index
>= ctx
->array_infos
[i
].range
.First
&& tgsi_reg_index
<= ctx
->array_infos
[i
].range
.Last
) {
919 if (ctx
->spilled_arrays
[i
]) {
920 /* vec4 index into spilled scratch memory */
922 return tgsi_reg_index
- ctx
->array_infos
[i
].range
.First
+ spilled_size
;
925 /* regular GPR array */
927 return tgsi_reg_index
- spilled_size
+ ctx
->file_offset
[TGSI_FILE_TEMPORARY
];
931 if (tgsi_reg_index
< ctx
->array_infos
[i
].range
.First
)
933 if (ctx
->spilled_arrays
[i
]) {
934 spilled_size
+= ctx
->array_infos
[i
].range
.Last
- ctx
->array_infos
[i
].range
.First
+ 1;
938 /* regular GPR index, minus the holes from spilled arrays */
941 return tgsi_reg_index
- spilled_size
+ ctx
->file_offset
[TGSI_FILE_TEMPORARY
];
944 /* look up spill area base offset and array size for a spilled temp array */
945 static void get_spilled_array_base_and_size(struct r600_shader_ctx
*ctx
, unsigned tgsi_reg_index
,
946 unsigned *array_base
, unsigned *array_size
)
951 for (i
= 0; i
< ctx
->info
.array_max
[TGSI_FILE_TEMPORARY
]; i
++) {
952 if (ctx
->spilled_arrays
[i
]) {
953 unsigned size
= ctx
->array_infos
[i
].range
.Last
- ctx
->array_infos
[i
].range
.First
+ 1;
955 if (tgsi_reg_index
>= ctx
->array_infos
[i
].range
.First
&& tgsi_reg_index
<= ctx
->array_infos
[i
].range
.Last
) {
956 *array_base
= offset
;
957 *array_size
= size
- 1; /* hw counts from 1 */
967 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
969 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
970 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
972 switch (d
->Declaration
.File
) {
973 case TGSI_FILE_INPUT
:
974 for (j
= 0; j
< count
; j
++) {
975 i
= ctx
->shader
->ninput
+ j
;
976 assert(i
< ARRAY_SIZE(ctx
->shader
->input
));
977 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
978 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
979 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
980 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
981 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
982 if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
983 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
984 switch (ctx
->shader
->input
[i
].name
) {
985 case TGSI_SEMANTIC_FACE
:
986 if (ctx
->face_gpr
!= -1)
987 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
989 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
991 case TGSI_SEMANTIC_COLOR
:
994 case TGSI_SEMANTIC_POSITION
:
995 ctx
->fragcoord_input
= i
;
997 case TGSI_SEMANTIC_PRIMID
:
998 /* set this for now */
999 ctx
->shader
->gs_prim_id_input
= true;
1000 ctx
->shader
->ps_prim_id_input
= i
;
1003 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1004 if ((r
= evergreen_interp_input(ctx
, i
)))
1007 } else if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
1008 /* FIXME probably skip inputs if they aren't passed in the ring */
1009 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
1010 ctx
->next_ring_offset
+= 16;
1011 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
1012 ctx
->shader
->gs_prim_id_input
= true;
1015 ctx
->shader
->ninput
+= count
;
1017 case TGSI_FILE_OUTPUT
:
1018 for (j
= 0; j
< count
; j
++) {
1019 i
= ctx
->shader
->noutput
+ j
;
1020 assert(i
< ARRAY_SIZE(ctx
->shader
->output
));
1021 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
1022 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
1023 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
1024 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
1025 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
1026 if (ctx
->type
== PIPE_SHADER_VERTEX
||
1027 ctx
->type
== PIPE_SHADER_GEOMETRY
||
1028 ctx
->type
== PIPE_SHADER_TESS_EVAL
) {
1029 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
1030 switch (d
->Semantic
.Name
) {
1031 case TGSI_SEMANTIC_CLIPDIST
:
1033 case TGSI_SEMANTIC_PSIZE
:
1034 ctx
->shader
->vs_out_misc_write
= 1;
1035 ctx
->shader
->vs_out_point_size
= 1;
1037 case TGSI_SEMANTIC_EDGEFLAG
:
1038 ctx
->shader
->vs_out_misc_write
= 1;
1039 ctx
->shader
->vs_out_edgeflag
= 1;
1040 ctx
->edgeflag_output
= i
;
1042 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
1043 ctx
->shader
->vs_out_misc_write
= 1;
1044 ctx
->shader
->vs_out_viewport
= 1;
1046 case TGSI_SEMANTIC_LAYER
:
1047 ctx
->shader
->vs_out_misc_write
= 1;
1048 ctx
->shader
->vs_out_layer
= 1;
1050 case TGSI_SEMANTIC_CLIPVERTEX
:
1051 ctx
->clip_vertex_write
= TRUE
;
1055 if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
1056 ctx
->gs_out_ring_offset
+= 16;
1058 } else if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
1059 switch (d
->Semantic
.Name
) {
1060 case TGSI_SEMANTIC_COLOR
:
1061 ctx
->shader
->nr_ps_max_color_exports
++;
1066 ctx
->shader
->noutput
+= count
;
1068 case TGSI_FILE_TEMPORARY
:
1069 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
1070 if (d
->Array
.ArrayID
) {
1072 unsigned idx
= map_tgsi_reg_index_to_r600_gpr(ctx
,
1077 r600_add_gpr_array(ctx
->shader
, idx
,
1078 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
1084 case TGSI_FILE_CONSTANT
:
1085 case TGSI_FILE_SAMPLER
:
1086 case TGSI_FILE_SAMPLER_VIEW
:
1087 case TGSI_FILE_ADDRESS
:
1088 case TGSI_FILE_BUFFER
:
1089 case TGSI_FILE_IMAGE
:
1090 case TGSI_FILE_MEMORY
:
1093 case TGSI_FILE_HW_ATOMIC
:
1094 i
= ctx
->shader
->nhwatomic_ranges
;
1095 ctx
->shader
->atomics
[i
].start
= d
->Range
.First
;
1096 ctx
->shader
->atomics
[i
].end
= d
->Range
.Last
;
1097 ctx
->shader
->atomics
[i
].hw_idx
= ctx
->shader
->atomic_base
+ ctx
->shader
->nhwatomic
;
1098 ctx
->shader
->atomics
[i
].array_id
= d
->Array
.ArrayID
;
1099 ctx
->shader
->atomics
[i
].buffer_id
= d
->Dim
.Index2D
;
1100 ctx
->shader
->nhwatomic_ranges
++;
1101 ctx
->shader
->nhwatomic
+= count
;
1104 case TGSI_FILE_SYSTEM_VALUE
:
1105 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
1106 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
1107 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
1108 break; /* Already handled from allocate_system_value_inputs */
1109 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
1111 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1113 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
1115 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
||
1116 d
->Semantic
.Name
== TGSI_SEMANTIC_TESSOUTER
) {
1117 int param
= r600_get_lds_unique_index(d
->Semantic
.Name
, 0);
1118 int dreg
= d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
? 3 : 2;
1119 unsigned temp_reg
= r600_get_temp(ctx
);
1121 r
= get_lds_offset0(ctx
, 2, temp_reg
, true);
1125 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1128 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1132 do_lds_fetch_values(ctx
, temp_reg
, dreg
, 0xf);
1134 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSCOORD
) {
1138 for (i
= 0; i
< 2; i
++) {
1139 struct r600_bytecode_alu alu
;
1140 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1141 alu
.op
= ALU_OP1_MOV
;
1143 alu
.src
[0].chan
= 0 + i
;
1145 alu
.dst
.chan
= 0 + i
;
1147 alu
.last
= (i
== 1) ? 1 : 0;
1148 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1151 /* ADD r1.z, 1.0f, -r0.x */
1152 struct r600_bytecode_alu alu
;
1153 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1154 alu
.op
= ALU_OP2_ADD
;
1155 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
1157 alu
.src
[1].chan
= 0;
1163 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1166 /* ADD r1.z, r1.z, -r1.y */
1167 alu
.op
= ALU_OP2_ADD
;
1169 alu
.src
[0].chan
= 2;
1171 alu
.src
[1].chan
= 1;
1177 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1183 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1189 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
1191 struct tgsi_parse_context parse
;
1195 unsigned name
, alternate_name
;
1197 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
1199 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
1204 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1208 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1209 while (!tgsi_parse_end_of_tokens(&parse
)) {
1210 tgsi_parse_token(&parse
);
1212 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1213 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1214 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1215 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1216 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1218 int interpolate
, location
, k
;
1220 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1221 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1222 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1223 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1224 /* Needs sample positions, currently those are always available */
1226 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1229 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1230 k
= eg_get_interpolator_index(interpolate
, location
);
1232 ctx
->eg_interpolators
[k
].enabled
= true;
1234 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1235 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1236 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1237 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1238 if (d
->Semantic
.Name
== inputs
[k
].name
||
1239 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1240 inputs
[k
].enabled
= true;
1247 tgsi_parse_free(&parse
);
1249 if (ctx
->info
.reads_samplemask
&&
1250 (ctx
->info
.uses_linear_sample
|| ctx
->info
.uses_persp_sample
)) {
1251 inputs
[1].enabled
= true;
1254 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1256 /* assign gpr to each interpolator according to priority */
1257 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1258 if (ctx
->eg_interpolators
[i
].enabled
) {
1259 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1263 num_baryc
= (num_baryc
+ 1) >> 1;
1264 gpr_offset
+= num_baryc
;
1267 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1268 boolean enabled
= inputs
[i
].enabled
;
1269 int *reg
= inputs
[i
].reg
;
1270 unsigned name
= inputs
[i
].name
;
1273 int gpr
= gpr_offset
+ num_regs
++;
1274 ctx
->shader
->nsys_inputs
++;
1276 // add to inputs, allocate a gpr
1277 k
= ctx
->shader
->ninput
++;
1278 ctx
->shader
->input
[k
].name
= name
;
1279 ctx
->shader
->input
[k
].sid
= 0;
1280 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1281 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1282 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1286 return gpr_offset
+ num_regs
;
1290 * for evergreen we need to scan the shader to find the number of GPRs we need to
1291 * reserve for interpolation and system values
1293 * we need to know if we are going to emit any sample or centroid inputs
1294 * if perspective and linear are required
1296 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1300 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1303 * Could get this information from the shader info. But right now
1304 * we interpolate all declared inputs, whereas the shader info will
1305 * only contain the bits if the inputs are actually used, so it might
1308 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1310 /* skip position/face/mask/sampleid */
1311 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1312 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1313 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1314 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1317 k
= eg_get_interpolator_index(
1318 ctx
->info
.input_interpolate
[i
],
1319 ctx
->info
.input_interpolate_loc
[i
]);
1321 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1324 /* XXX PULL MODEL and LINE STIPPLE */
1326 return allocate_system_value_inputs(ctx
, 0);
1329 /* sample_id_sel == NULL means fetch for current sample */
1330 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1332 struct r600_bytecode_vtx vtx
;
1335 t1
= r600_get_temp(ctx
);
1337 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1338 vtx
.op
= FETCH_OP_VFETCH
;
1339 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1340 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1341 if (sample_id
== NULL
) {
1342 assert(ctx
->fixed_pt_position_gpr
!= -1);
1344 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1348 struct r600_bytecode_alu alu
;
1350 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1351 alu
.op
= ALU_OP1_MOV
;
1352 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1356 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1363 vtx
.mega_fetch_count
= 16;
1369 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1370 vtx
.num_format_all
= 2;
1371 vtx
.format_comp_all
= 1;
1372 vtx
.use_const_fields
= 0;
1374 vtx
.endian
= r600_endian_swap(32);
1375 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1377 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1384 static int eg_load_helper_invocation(struct r600_shader_ctx
*ctx
)
1387 struct r600_bytecode_alu alu
;
1389 /* do a vtx fetch with wqm set on the vtx fetch */
1390 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1391 alu
.op
= ALU_OP1_MOV
;
1392 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1394 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1395 alu
.src
[0].value
= 0xffffffff;
1398 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1402 /* do a vtx fetch in VPM mode */
1403 struct r600_bytecode_vtx vtx
;
1404 memset(&vtx
, 0, sizeof(vtx
));
1405 vtx
.op
= FETCH_OP_GET_BUFFER_RESINFO
;
1406 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1407 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1409 vtx
.mega_fetch_count
= 16; /* no idea here really... */
1410 vtx
.dst_gpr
= ctx
->helper_invoc_reg
;
1412 vtx
.dst_sel_y
= 7; /* SEL_Y */
1413 vtx
.dst_sel_z
= 7; /* SEL_Z */
1414 vtx
.dst_sel_w
= 7; /* SEL_W */
1415 vtx
.data_format
= FMT_32
;
1416 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
1418 ctx
->bc
->cf_last
->vpm
= 1;
1422 static int cm_load_helper_invocation(struct r600_shader_ctx
*ctx
)
1425 struct r600_bytecode_alu alu
;
1427 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1428 alu
.op
= ALU_OP1_MOV
;
1429 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1431 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1432 alu
.src
[0].value
= 0xffffffff;
1435 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1439 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1440 alu
.op
= ALU_OP1_MOV
;
1441 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1443 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1446 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_VALID_PIXEL_MODE
);
1450 return ctx
->helper_invoc_reg
;
1453 static int load_block_grid_size(struct r600_shader_ctx
*ctx
, bool load_block
)
1455 struct r600_bytecode_vtx vtx
;
1458 if (ctx
->cs_block_size_loaded
)
1459 return ctx
->cs_block_size_reg
;
1460 if (ctx
->cs_grid_size_loaded
)
1461 return ctx
->cs_grid_size_reg
;
1463 t1
= load_block
? ctx
->cs_block_size_reg
: ctx
->cs_grid_size_reg
;
1464 struct r600_bytecode_alu alu
;
1465 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1466 alu
.op
= ALU_OP1_MOV
;
1467 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1471 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1475 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1476 vtx
.op
= FETCH_OP_VFETCH
;
1477 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1478 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1482 vtx
.mega_fetch_count
= 16;
1488 vtx
.data_format
= FMT_32_32_32_32
;
1489 vtx
.num_format_all
= 1;
1490 vtx
.format_comp_all
= 0;
1491 vtx
.use_const_fields
= 0;
1492 vtx
.offset
= load_block
? 0 : 16; // first element is size of buffer
1493 vtx
.endian
= r600_endian_swap(32);
1494 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1496 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1501 ctx
->cs_block_size_loaded
= true;
1503 ctx
->cs_grid_size_loaded
= true;
1507 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1508 const struct tgsi_full_src_register
*tgsi_src
,
1509 struct r600_shader_src
*r600_src
)
1511 memset(r600_src
, 0, sizeof(*r600_src
));
1512 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1513 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1514 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1515 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1516 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1517 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1519 if (tgsi_src
->Register
.File
== TGSI_FILE_TEMPORARY
) {
1523 idx
= map_tgsi_reg_index_to_r600_gpr(ctx
, tgsi_src
->Register
.Index
, &spilled
);
1526 int reg
= r600_get_temp(ctx
);
1529 r600_src
->sel
= reg
;
1531 if (ctx
->bc
->chip_class
< R700
) {
1532 struct r600_bytecode_output cf
;
1534 memset(&cf
, 0, sizeof(struct r600_bytecode_output
));
1535 cf
.op
= CF_OP_MEM_SCRATCH
;
1545 get_spilled_array_base_and_size(ctx
, tgsi_src
->Register
.Index
,
1546 &cf
.array_base
, &cf
.array_size
);
1548 if (tgsi_src
->Register
.Indirect
) {
1549 cf
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
1550 cf
.index_gpr
= ctx
->bc
->ar_reg
;
1553 cf
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ
;
1554 cf
.array_base
+= idx
;
1558 r
= r600_bytecode_add_output(ctx
->bc
, &cf
);
1561 struct r600_bytecode_vtx vtx
;
1563 if (r600_bytecode_get_need_wait_ack(ctx
->bc
)) {
1564 r600_bytecode_need_wait_ack(ctx
->bc
, false);
1565 r
= r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
1568 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1569 vtx
.op
= FETCH_OP_READ_SCRATCH
;
1571 vtx
.uncached
= 1; // Must bypass cache since prior spill written in same invocation
1573 vtx
.data_format
= FMT_32_32_32_32
;
1574 vtx
.num_format_all
= V_038010_SQ_NUM_FORMAT_INT
;
1575 vtx
.dst_sel_x
= tgsi_src
->Register
.SwizzleX
;
1576 vtx
.dst_sel_y
= tgsi_src
->Register
.SwizzleY
;
1577 vtx
.dst_sel_z
= tgsi_src
->Register
.SwizzleZ
;
1578 vtx
.dst_sel_w
= tgsi_src
->Register
.SwizzleW
;
1580 get_spilled_array_base_and_size(ctx
, tgsi_src
->Register
.Index
,
1581 &vtx
.array_base
, &vtx
.array_size
);
1583 if (tgsi_src
->Register
.Indirect
) {
1585 vtx
.src_gpr
= ctx
->bc
->ar_reg
;
1588 vtx
.array_base
+= idx
;
1592 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1599 if (tgsi_src
->Register
.Indirect
)
1600 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1602 r600_src
->sel
= idx
;
1608 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1610 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1611 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1612 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1614 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1615 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1616 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1619 index
= tgsi_src
->Register
.Index
;
1620 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1621 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1622 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1623 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1624 r600_src
->swizzle
[0] = 2; // Z value
1625 r600_src
->swizzle
[1] = 2;
1626 r600_src
->swizzle
[2] = 2;
1627 r600_src
->swizzle
[3] = 2;
1628 r600_src
->sel
= ctx
->face_gpr
;
1629 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1630 r600_src
->swizzle
[0] = 3; // W value
1631 r600_src
->swizzle
[1] = 3;
1632 r600_src
->swizzle
[2] = 3;
1633 r600_src
->swizzle
[3] = 3;
1634 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1635 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1636 r600_src
->swizzle
[0] = 0;
1637 r600_src
->swizzle
[1] = 1;
1638 r600_src
->swizzle
[2] = 4;
1639 r600_src
->swizzle
[3] = 4;
1640 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1641 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1642 r600_src
->swizzle
[0] = 3;
1643 r600_src
->swizzle
[1] = 3;
1644 r600_src
->swizzle
[2] = 3;
1645 r600_src
->swizzle
[3] = 3;
1647 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1648 r600_src
->swizzle
[0] = 0;
1649 r600_src
->swizzle
[1] = 0;
1650 r600_src
->swizzle
[2] = 0;
1651 r600_src
->swizzle
[3] = 0;
1653 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_THREAD_ID
) {
1655 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_ID
) {
1657 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1658 r600_src
->swizzle
[0] = 3;
1659 r600_src
->swizzle
[1] = 3;
1660 r600_src
->swizzle
[2] = 3;
1661 r600_src
->swizzle
[3] = 3;
1663 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1664 r600_src
->swizzle
[0] = 2;
1665 r600_src
->swizzle
[1] = 2;
1666 r600_src
->swizzle
[2] = 2;
1667 r600_src
->swizzle
[3] = 2;
1669 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1671 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1673 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1675 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1676 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1677 r600_src
->sel
= ctx
->tess_input_info
;
1678 r600_src
->swizzle
[0] = 2;
1679 r600_src
->swizzle
[1] = 2;
1680 r600_src
->swizzle
[2] = 2;
1681 r600_src
->swizzle
[3] = 2;
1683 r600_src
->sel
= ctx
->tess_input_info
;
1684 r600_src
->swizzle
[0] = 3;
1685 r600_src
->swizzle
[1] = 3;
1686 r600_src
->swizzle
[2] = 3;
1687 r600_src
->swizzle
[3] = 3;
1689 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1691 r600_src
->swizzle
[0] = 0;
1692 r600_src
->swizzle
[1] = 0;
1693 r600_src
->swizzle
[2] = 0;
1694 r600_src
->swizzle
[3] = 0;
1695 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1697 r600_src
->swizzle
[0] = 3;
1698 r600_src
->swizzle
[1] = 3;
1699 r600_src
->swizzle
[2] = 3;
1700 r600_src
->swizzle
[3] = 3;
1701 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_GRID_SIZE
) {
1702 r600_src
->sel
= load_block_grid_size(ctx
, false);
1703 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_SIZE
) {
1704 r600_src
->sel
= load_block_grid_size(ctx
, true);
1705 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_HELPER_INVOCATION
) {
1706 r600_src
->sel
= ctx
->helper_invoc_reg
;
1707 r600_src
->swizzle
[0] = 0;
1708 r600_src
->swizzle
[1] = 0;
1709 r600_src
->swizzle
[2] = 0;
1710 r600_src
->swizzle
[3] = 0;
1713 if (tgsi_src
->Register
.Indirect
)
1714 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1715 r600_src
->sel
= tgsi_src
->Register
.Index
;
1716 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1718 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1719 if (tgsi_src
->Register
.Dimension
) {
1720 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1721 if (tgsi_src
->Dimension
.Indirect
) {
1722 r600_src
->kc_rel
= 1;
1728 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1729 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1730 unsigned int dst_reg
)
1732 struct r600_bytecode_vtx vtx
;
1733 unsigned int ar_reg
;
1737 struct r600_bytecode_alu alu
;
1739 memset(&alu
, 0, sizeof(alu
));
1741 alu
.op
= ALU_OP2_ADD_INT
;
1742 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1743 alu
.src
[0].chan
= ar_chan
;
1745 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1746 alu
.src
[1].value
= offset
;
1748 alu
.dst
.sel
= dst_reg
;
1749 alu
.dst
.chan
= ar_chan
;
1753 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1758 ar_reg
= ctx
->bc
->ar_reg
;
1761 memset(&vtx
, 0, sizeof(vtx
));
1762 vtx
.buffer_id
= cb_idx
;
1763 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1764 vtx
.src_gpr
= ar_reg
;
1765 vtx
.src_sel_x
= ar_chan
;
1766 vtx
.mega_fetch_count
= 16;
1767 vtx
.dst_gpr
= dst_reg
;
1768 vtx
.dst_sel_x
= 0; /* SEL_X */
1769 vtx
.dst_sel_y
= 1; /* SEL_Y */
1770 vtx
.dst_sel_z
= 2; /* SEL_Z */
1771 vtx
.dst_sel_w
= 3; /* SEL_W */
1772 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1773 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1774 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1775 vtx
.endian
= r600_endian_swap(32);
1776 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1778 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1784 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1786 struct r600_bytecode_vtx vtx
;
1788 unsigned index
= src
->Register
.Index
;
1789 unsigned vtx_id
= src
->Dimension
.Index
;
1790 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1791 int offset_chan
= vtx_id
% 3;
1794 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1795 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1797 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1800 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1801 t2
= r600_get_temp(ctx
);
1803 if (src
->Dimension
.Indirect
) {
1805 struct r600_bytecode_alu alu
;
1808 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1809 if (src
->DimIndirect
.Index
> 0) {
1810 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1818 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1819 at least this is what fglrx seems to do. */
1820 for (i
= 0; i
< 3; i
++) {
1821 treg
[i
] = r600_get_temp(ctx
);
1823 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1825 for (i
= 0; i
< 3; i
++) {
1826 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1827 alu
.op
= ALU_OP1_MOV
;
1828 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1829 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1830 alu
.dst
.sel
= treg
[i
];
1834 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1838 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1839 alu
.op
= ALU_OP1_MOV
;
1840 alu
.src
[0].sel
= treg
[0];
1845 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1852 if (src
->Register
.Indirect
) {
1854 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1856 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1858 /* pull the value from index_reg */
1859 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1862 V_SQ_ALU_SRC_LITERAL
, first
);
1865 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1868 V_SQ_ALU_SRC_LITERAL
, 4,
1869 offset_reg
, offset_chan
);
1874 index
= src
->Register
.Index
- first
;
1877 memset(&vtx
, 0, sizeof(vtx
));
1878 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1879 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1880 vtx
.src_gpr
= offset_reg
;
1881 vtx
.src_sel_x
= offset_chan
;
1882 vtx
.offset
= index
* 16; /*bytes*/
1883 vtx
.mega_fetch_count
= 16;
1884 vtx
.dst_gpr
= dst_reg
;
1885 vtx
.dst_sel_x
= 0; /* SEL_X */
1886 vtx
.dst_sel_y
= 1; /* SEL_Y */
1887 vtx
.dst_sel_z
= 2; /* SEL_Z */
1888 vtx
.dst_sel_w
= 3; /* SEL_W */
1889 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1890 vtx
.use_const_fields
= 1;
1892 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1895 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1901 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1903 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1906 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1907 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1909 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1910 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1911 /* primitive id is in R0.z */
1912 ctx
->src
[i
].sel
= 0;
1913 ctx
->src
[i
].swizzle
[0] = 2;
1916 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1917 int treg
= r600_get_temp(ctx
);
1919 fetch_gs_input(ctx
, src
, treg
);
1920 ctx
->src
[i
].sel
= treg
;
1921 ctx
->src
[i
].rel
= 0;
1928 /* Tessellation shaders pass outputs to the next shader using LDS.
1930 * LS outputs = TCS(HS) inputs
1931 * TCS(HS) outputs = TES(DS) inputs
1933 * The LDS layout is:
1934 * - TCS inputs for patch 0
1935 * - TCS inputs for patch 1
1936 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1938 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1939 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1940 * - TCS outputs for patch 1
1941 * - Per-patch TCS outputs for patch 1
1942 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1943 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1946 * All three shaders VS(LS), TCS, TES share the same LDS space.
1948 /* this will return with the dw address in temp_reg.x */
1949 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1950 const struct tgsi_full_dst_register
*dst
,
1951 const struct tgsi_full_src_register
*src
,
1952 int stride_bytes_reg
, int stride_bytes_chan
)
1954 struct tgsi_full_dst_register reg
;
1955 ubyte
*name
, *index
, *array_first
;
1958 struct tgsi_shader_info
*info
= &ctx
->info
;
1959 /* Set the register description. The address computation is the same
1960 * for sources and destinations. */
1962 reg
.Register
.File
= src
->Register
.File
;
1963 reg
.Register
.Index
= src
->Register
.Index
;
1964 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1965 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1966 reg
.Indirect
= src
->Indirect
;
1967 reg
.Dimension
= src
->Dimension
;
1968 reg
.DimIndirect
= src
->DimIndirect
;
1972 /* If the register is 2-dimensional (e.g. an array of vertices
1973 * in a primitive), calculate the base address of the vertex. */
1974 if (reg
.Register
.Dimension
) {
1976 if (reg
.Dimension
.Indirect
) {
1978 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1980 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1981 /* pull the value from index_reg */
1985 sel
= V_SQ_ALU_SRC_LITERAL
;
1986 chan
= reg
.Dimension
.Index
;
1989 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1991 stride_bytes_reg
, stride_bytes_chan
,
1998 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1999 name
= info
->input_semantic_name
;
2000 index
= info
->input_semantic_index
;
2001 array_first
= info
->input_array_first
;
2002 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
2003 name
= info
->output_semantic_name
;
2004 index
= info
->output_semantic_index
;
2005 array_first
= info
->output_array_first
;
2010 if (reg
.Register
.Indirect
) {
2013 /* Add the relative address of the element. */
2014 if (reg
.Indirect
.ArrayID
)
2015 first
= array_first
[reg
.Indirect
.ArrayID
];
2017 first
= reg
.Register
.Index
;
2019 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
2021 /* pull the value from index_reg */
2022 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2024 V_SQ_ALU_SRC_LITERAL
, 16,
2030 param
= r600_get_lds_unique_index(name
[first
],
2034 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
2035 index
[reg
.Register
.Index
]);
2038 /* add to base_addr - passed in temp_reg.x */
2040 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2043 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2051 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
2052 unsigned dst_reg
, unsigned mask
)
2054 struct r600_bytecode_alu alu
;
2057 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
2058 ctx
->bc
->force_add_cf
= 1;
2060 lasti
= tgsi_last_instruction(mask
);
2061 for (i
= 1; i
<= lasti
; i
++) {
2062 if (!(mask
& (1 << i
)))
2065 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2068 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2072 for (i
= 0; i
<= lasti
; i
++) {
2073 if (!(mask
& (1 << i
)))
2076 /* emit an LDS_READ_RET */
2077 memset(&alu
, 0, sizeof(alu
));
2078 alu
.op
= LDS_OP1_LDS_READ_RET
;
2079 alu
.src
[0].sel
= temp_reg
;
2080 alu
.src
[0].chan
= i
;
2081 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
2082 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2084 alu
.is_lds_idx_op
= true;
2086 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2090 for (i
= 0; i
<= lasti
; i
++) {
2091 if (!(mask
& (1 << i
)))
2094 /* then read from LDS_OQ_A_POP */
2095 memset(&alu
, 0, sizeof(alu
));
2097 alu
.op
= ALU_OP1_MOV
;
2098 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
2099 alu
.src
[0].chan
= 0;
2100 alu
.dst
.sel
= dst_reg
;
2104 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2111 static int fetch_mask(struct tgsi_src_register
*reg
)
2114 mask
|= 1 << reg
->SwizzleX
;
2115 mask
|= 1 << reg
->SwizzleY
;
2116 mask
|= 1 << reg
->SwizzleZ
;
2117 mask
|= 1 << reg
->SwizzleW
;
2121 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
2124 unsigned temp_reg
= r600_get_temp(ctx
);
2126 r
= get_lds_offset0(ctx
, 2, temp_reg
,
2127 src
->Register
.Dimension
? false : true);
2131 /* the base address is now in temp.x */
2132 r
= r600_get_byte_address(ctx
, temp_reg
,
2133 NULL
, src
, ctx
->tess_output_info
, 1);
2137 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
2143 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
2146 unsigned temp_reg
= r600_get_temp(ctx
);
2148 /* t.x = ips * r0.y */
2149 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2151 ctx
->tess_input_info
, 0,
2157 /* the base address is now in temp.x */
2158 r
= r600_get_byte_address(ctx
, temp_reg
,
2159 NULL
, src
, ctx
->tess_input_info
, 1);
2163 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
2169 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
2172 unsigned temp_reg
= r600_get_temp(ctx
);
2174 r
= get_lds_offset0(ctx
, 1, temp_reg
,
2175 src
->Register
.Dimension
? false : true);
2178 /* the base address is now in temp.x */
2179 r
= r600_get_byte_address(ctx
, temp_reg
,
2181 ctx
->tess_output_info
, 1);
2185 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
2191 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
2193 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2196 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2197 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
2199 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
2200 int treg
= r600_get_temp(ctx
);
2201 fetch_tes_input(ctx
, src
, treg
);
2202 ctx
->src
[i
].sel
= treg
;
2203 ctx
->src
[i
].rel
= 0;
2205 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
2206 int treg
= r600_get_temp(ctx
);
2207 fetch_tcs_input(ctx
, src
, treg
);
2208 ctx
->src
[i
].sel
= treg
;
2209 ctx
->src
[i
].rel
= 0;
2211 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
2212 int treg
= r600_get_temp(ctx
);
2213 fetch_tcs_output(ctx
, src
, treg
);
2214 ctx
->src
[i
].sel
= treg
;
2215 ctx
->src
[i
].rel
= 0;
2221 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
2223 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2224 struct r600_bytecode_alu alu
;
2225 int i
, j
, k
, nconst
, r
;
2227 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2228 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
2231 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
2233 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2234 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
2238 if (ctx
->src
[i
].rel
) {
2239 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
2240 int treg
= r600_get_temp(ctx
);
2241 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
2244 ctx
->src
[i
].kc_bank
= 0;
2245 ctx
->src
[i
].kc_rel
= 0;
2246 ctx
->src
[i
].sel
= treg
;
2247 ctx
->src
[i
].rel
= 0;
2250 int treg
= r600_get_temp(ctx
);
2251 for (k
= 0; k
< 4; k
++) {
2252 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2253 alu
.op
= ALU_OP1_MOV
;
2254 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2255 alu
.src
[0].chan
= k
;
2256 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
2257 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
2258 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
2264 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2268 ctx
->src
[i
].sel
= treg
;
2276 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
2277 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
2279 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2280 struct r600_bytecode_alu alu
;
2281 int i
, j
, k
, nliteral
, r
;
2283 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2284 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2288 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2289 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2290 int treg
= r600_get_temp(ctx
);
2291 for (k
= 0; k
< 4; k
++) {
2292 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2293 alu
.op
= ALU_OP1_MOV
;
2294 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2295 alu
.src
[0].chan
= k
;
2296 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
2302 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2306 ctx
->src
[i
].sel
= treg
;
2313 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
2315 int i
, r
, count
= ctx
->shader
->ninput
;
2317 for (i
= 0; i
< count
; i
++) {
2318 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2319 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
2327 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2328 int stream
, unsigned *stream_item_size UNUSED
)
2330 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2331 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2335 /* Sanity checking. */
2336 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2337 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2341 for (i
= 0; i
< so
->num_outputs
; i
++) {
2342 if (so
->output
[i
].output_buffer
>= 4) {
2343 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2344 so
->output
[i
].output_buffer
);
2350 /* Initialize locations where the outputs are stored. */
2351 for (i
= 0; i
< so
->num_outputs
; i
++) {
2353 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2354 start_comp
[i
] = so
->output
[i
].start_component
;
2355 /* Lower outputs with dst_offset < start_component.
2357 * We can only output 4D vectors with a write mask, e.g. we can
2358 * only output the W component at offset 3, etc. If we want
2359 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2360 * to move it to X and output X. */
2361 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2362 unsigned tmp
= r600_get_temp(ctx
);
2364 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2365 struct r600_bytecode_alu alu
;
2366 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2367 alu
.op
= ALU_OP1_MOV
;
2368 alu
.src
[0].sel
= so_gpr
[i
];
2369 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2374 if (j
== so
->output
[i
].num_components
- 1)
2376 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2385 /* Write outputs to buffers. */
2386 for (i
= 0; i
< so
->num_outputs
; i
++) {
2387 struct r600_bytecode_output output
;
2389 if (stream
!= -1 && stream
!= so
->output
[i
].stream
)
2392 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2393 output
.gpr
= so_gpr
[i
];
2394 output
.elem_size
= so
->output
[i
].num_components
- 1;
2395 if (output
.elem_size
== 2)
2396 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2397 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2398 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2399 output
.burst_count
= 1;
2400 /* array_size is an upper limit for the burst_count
2401 * with MEM_STREAM instructions */
2402 output
.array_size
= 0xFFF;
2403 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2405 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2406 switch (so
->output
[i
].output_buffer
) {
2408 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2411 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2414 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2417 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2420 output
.op
+= so
->output
[i
].stream
* 4;
2421 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2422 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2424 switch (so
->output
[i
].output_buffer
) {
2426 output
.op
= CF_OP_MEM_STREAM0
;
2429 output
.op
= CF_OP_MEM_STREAM1
;
2432 output
.op
= CF_OP_MEM_STREAM2
;
2435 output
.op
= CF_OP_MEM_STREAM3
;
2438 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2440 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2449 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2451 struct r600_bytecode_alu alu
;
2454 if (!ctx
->shader
->vs_out_edgeflag
)
2457 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2459 /* clamp(x, 0, 1) */
2460 memset(&alu
, 0, sizeof(alu
));
2461 alu
.op
= ALU_OP1_MOV
;
2462 alu
.src
[0].sel
= reg
;
2467 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2469 memset(&alu
, 0, sizeof(alu
));
2470 alu
.op
= ALU_OP1_FLT_TO_INT
;
2471 alu
.src
[0].sel
= reg
;
2475 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2478 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2479 struct r600_pipe_shader
*gs
,
2480 struct pipe_stream_output_info
*so
)
2482 struct r600_shader_ctx ctx
= {};
2483 struct r600_shader
*gs_shader
= &gs
->shader
;
2484 struct r600_pipe_shader
*cshader
;
2485 unsigned ocnt
= gs_shader
->noutput
;
2486 struct r600_bytecode_alu alu
;
2487 struct r600_bytecode_vtx vtx
;
2488 struct r600_bytecode_output output
;
2489 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2490 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2491 int next_clip_pos
= 61, next_param
= 0;
2494 bool only_ring_0
= true;
2495 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2499 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2500 sizeof(struct r600_shader_io
));
2502 cshader
->shader
.noutput
= ocnt
;
2504 ctx
.shader
= &cshader
->shader
;
2505 ctx
.bc
= &ctx
.shader
->bc
;
2506 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2508 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2509 rctx
->screen
->has_compressed_msaa_texturing
);
2511 ctx
.bc
->isa
= rctx
->isa
;
2514 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2516 /* R0.x = R0.x & 0x3fffffff */
2517 memset(&alu
, 0, sizeof(alu
));
2518 alu
.op
= ALU_OP2_AND_INT
;
2519 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2520 alu
.src
[1].value
= 0x3fffffff;
2522 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2524 /* R0.y = R0.x >> 30 */
2525 memset(&alu
, 0, sizeof(alu
));
2526 alu
.op
= ALU_OP2_LSHR_INT
;
2527 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2528 alu
.src
[1].value
= 0x1e;
2532 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2534 /* fetch vertex data from GSVS ring */
2535 for (i
= 0; i
< ocnt
; ++i
) {
2536 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2539 out
->ring_offset
= i
* 16;
2541 memset(&vtx
, 0, sizeof(vtx
));
2542 vtx
.op
= FETCH_OP_VFETCH
;
2543 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2544 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2545 vtx
.mega_fetch_count
= 16;
2546 vtx
.offset
= out
->ring_offset
;
2547 vtx
.dst_gpr
= out
->gpr
;
2553 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2554 vtx
.use_const_fields
= 1;
2556 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2559 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2561 ctx
.temp_reg
= i
+ 1;
2562 for (ring
= 3; ring
>= 0; --ring
) {
2563 bool enabled
= false;
2564 for (i
= 0; i
< so
->num_outputs
; i
++) {
2565 if (so
->output
[i
].stream
== ring
) {
2568 only_ring_0
= false;
2572 if (ring
!= 0 && !enabled
) {
2573 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2578 // Patch up jump label
2579 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2580 cf_pop
= ctx
.bc
->cf_last
;
2582 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2583 cf_jump
->pop_count
= 1;
2584 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2585 cf_pop
->pop_count
= 1;
2588 /* PRED_SETE_INT __, R0.y, ring */
2589 memset(&alu
, 0, sizeof(alu
));
2590 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2591 alu
.src
[0].chan
= 1;
2592 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2593 alu
.src
[1].value
= ring
;
2594 alu
.execute_mask
= 1;
2595 alu
.update_pred
= 1;
2597 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2599 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2600 cf_jump
= ctx
.bc
->cf_last
;
2603 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2604 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2607 /* bc adds nops - copy it */
2608 if (ctx
.bc
->chip_class
== R600
) {
2609 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2610 alu
.op
= ALU_OP0_NOP
;
2612 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2614 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2617 /* export vertex data */
2618 /* XXX factor out common code with r600_shader_from_tgsi ? */
2619 for (i
= 0; i
< ocnt
; ++i
) {
2620 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2621 bool instream0
= true;
2622 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2625 for (j
= 0; j
< so
->num_outputs
; j
++) {
2626 if (so
->output
[j
].register_index
== i
) {
2627 if (so
->output
[j
].stream
== 0)
2629 if (so
->output
[j
].stream
> 0)
2635 memset(&output
, 0, sizeof(output
));
2636 output
.gpr
= out
->gpr
;
2637 output
.elem_size
= 3;
2638 output
.swizzle_x
= 0;
2639 output
.swizzle_y
= 1;
2640 output
.swizzle_z
= 2;
2641 output
.swizzle_w
= 3;
2642 output
.burst_count
= 1;
2643 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2644 output
.op
= CF_OP_EXPORT
;
2645 switch (out
->name
) {
2646 case TGSI_SEMANTIC_POSITION
:
2647 output
.array_base
= 60;
2648 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2651 case TGSI_SEMANTIC_PSIZE
:
2652 output
.array_base
= 61;
2653 if (next_clip_pos
== 61)
2655 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2656 output
.swizzle_y
= 7;
2657 output
.swizzle_z
= 7;
2658 output
.swizzle_w
= 7;
2659 ctx
.shader
->vs_out_misc_write
= 1;
2660 ctx
.shader
->vs_out_point_size
= 1;
2662 case TGSI_SEMANTIC_LAYER
:
2664 /* duplicate it as PARAM to pass to the pixel shader */
2665 output
.array_base
= next_param
++;
2666 r600_bytecode_add_output(ctx
.bc
, &output
);
2667 last_exp_param
= ctx
.bc
->cf_last
;
2669 output
.array_base
= 61;
2670 if (next_clip_pos
== 61)
2672 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2673 output
.swizzle_x
= 7;
2674 output
.swizzle_y
= 7;
2675 output
.swizzle_z
= 0;
2676 output
.swizzle_w
= 7;
2677 ctx
.shader
->vs_out_misc_write
= 1;
2678 ctx
.shader
->vs_out_layer
= 1;
2680 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2682 /* duplicate it as PARAM to pass to the pixel shader */
2683 output
.array_base
= next_param
++;
2684 r600_bytecode_add_output(ctx
.bc
, &output
);
2685 last_exp_param
= ctx
.bc
->cf_last
;
2687 output
.array_base
= 61;
2688 if (next_clip_pos
== 61)
2690 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2691 ctx
.shader
->vs_out_misc_write
= 1;
2692 ctx
.shader
->vs_out_viewport
= 1;
2693 output
.swizzle_x
= 7;
2694 output
.swizzle_y
= 7;
2695 output
.swizzle_z
= 7;
2696 output
.swizzle_w
= 0;
2698 case TGSI_SEMANTIC_CLIPDIST
:
2699 /* spi_sid is 0 for clipdistance outputs that were generated
2700 * for clipvertex - we don't need to pass them to PS */
2701 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2702 ctx
.shader
->cull_dist_write
= gs
->shader
.cull_dist_write
;
2703 ctx
.shader
->cc_dist_mask
= gs
->shader
.cc_dist_mask
;
2705 /* duplicate it as PARAM to pass to the pixel shader */
2706 output
.array_base
= next_param
++;
2707 r600_bytecode_add_output(ctx
.bc
, &output
);
2708 last_exp_param
= ctx
.bc
->cf_last
;
2710 output
.array_base
= next_clip_pos
++;
2711 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2713 case TGSI_SEMANTIC_FOG
:
2714 output
.swizzle_y
= 4; /* 0 */
2715 output
.swizzle_z
= 4; /* 0 */
2716 output
.swizzle_w
= 5; /* 1 */
2719 output
.array_base
= next_param
++;
2722 r600_bytecode_add_output(ctx
.bc
, &output
);
2723 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2724 last_exp_param
= ctx
.bc
->cf_last
;
2726 last_exp_pos
= ctx
.bc
->cf_last
;
2729 if (!last_exp_pos
) {
2730 memset(&output
, 0, sizeof(output
));
2732 output
.elem_size
= 3;
2733 output
.swizzle_x
= 7;
2734 output
.swizzle_y
= 7;
2735 output
.swizzle_z
= 7;
2736 output
.swizzle_w
= 7;
2737 output
.burst_count
= 1;
2739 output
.op
= CF_OP_EXPORT
;
2740 output
.array_base
= 60;
2741 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2742 r600_bytecode_add_output(ctx
.bc
, &output
);
2743 last_exp_pos
= ctx
.bc
->cf_last
;
2746 if (!last_exp_param
) {
2747 memset(&output
, 0, sizeof(output
));
2749 output
.elem_size
= 3;
2750 output
.swizzle_x
= 7;
2751 output
.swizzle_y
= 7;
2752 output
.swizzle_z
= 7;
2753 output
.swizzle_w
= 7;
2754 output
.burst_count
= 1;
2756 output
.op
= CF_OP_EXPORT
;
2757 output
.array_base
= next_param
++;
2758 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2759 r600_bytecode_add_output(ctx
.bc
, &output
);
2760 last_exp_param
= ctx
.bc
->cf_last
;
2763 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2764 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2766 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2767 cf_pop
= ctx
.bc
->cf_last
;
2769 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2770 cf_jump
->pop_count
= 1;
2771 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2772 cf_pop
->pop_count
= 1;
2774 if (ctx
.bc
->chip_class
== CAYMAN
)
2775 cm_bytecode_add_cf_end(ctx
.bc
);
2777 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2778 ctx
.bc
->cf_last
->end_of_program
= 1;
2781 gs
->gs_copy_shader
= cshader
;
2782 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2786 return r600_bytecode_build(ctx
.bc
);
2789 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2792 struct r600_bytecode_alu alu
;
2795 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2796 alu
.op
= ALU_OP2_ADD_INT
;
2797 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2798 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2799 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2800 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2803 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2810 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so UNUSED
, int stream
, bool ind
)
2812 struct r600_bytecode_output output
;
2815 int effective_stream
= stream
== -1 ? 0 : stream
;
2818 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2819 if (ctx
->gs_for_vs
) {
2820 /* for ES we need to lookup corresponding ring offset expected by GS
2821 * (map this output to GS input by name and sid) */
2822 /* FIXME precompute offsets */
2824 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2825 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2826 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2827 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2828 ring_offset
= in
->ring_offset
;
2831 if (ring_offset
== -1)
2834 ring_offset
= idx
* 16;
2838 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2840 /* next_ring_offset after parsing input decls contains total size of
2841 * single vertex data, gs_next_vertex - current vertex index */
2843 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2845 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2846 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2847 output
.elem_size
= 3;
2848 output
.comp_mask
= 0xF;
2849 output
.burst_count
= 1;
2852 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2854 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2859 output
.op
= CF_OP_MEM_RING
; break;
2861 output
.op
= CF_OP_MEM_RING1
; break;
2863 output
.op
= CF_OP_MEM_RING2
; break;
2865 output
.op
= CF_OP_MEM_RING3
; break;
2869 output
.array_base
= ring_offset
>> 2; /* in dwords */
2870 output
.array_size
= 0xfff;
2871 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2873 output
.array_base
= ring_offset
>> 2; /* in dwords */
2874 r600_bytecode_add_output(ctx
->bc
, &output
);
2877 ++ctx
->gs_next_vertex
;
2882 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2885 struct r600_bytecode_vtx vtx
;
2886 int temp_val
= ctx
->temp_reg
;
2887 /* need to store the TCS output somewhere */
2888 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2890 V_SQ_ALU_SRC_LITERAL
, 0,
2895 /* used by VS/TCS */
2896 if (ctx
->tess_input_info
) {
2897 /* fetch tcs input values into resv space */
2898 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2899 vtx
.op
= FETCH_OP_VFETCH
;
2900 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2901 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2902 vtx
.mega_fetch_count
= 16;
2903 vtx
.data_format
= FMT_32_32_32_32
;
2904 vtx
.num_format_all
= 2;
2905 vtx
.format_comp_all
= 1;
2906 vtx
.use_const_fields
= 0;
2907 vtx
.endian
= r600_endian_swap(32);
2908 vtx
.srf_mode_all
= 1;
2910 vtx
.dst_gpr
= ctx
->tess_input_info
;
2915 vtx
.src_gpr
= temp_val
;
2918 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2923 /* used by TCS/TES */
2924 if (ctx
->tess_output_info
) {
2925 /* fetch tcs output values into resv space */
2926 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2927 vtx
.op
= FETCH_OP_VFETCH
;
2928 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2929 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2930 vtx
.mega_fetch_count
= 16;
2931 vtx
.data_format
= FMT_32_32_32_32
;
2932 vtx
.num_format_all
= 2;
2933 vtx
.format_comp_all
= 1;
2934 vtx
.use_const_fields
= 0;
2935 vtx
.endian
= r600_endian_swap(32);
2936 vtx
.srf_mode_all
= 1;
2938 vtx
.dst_gpr
= ctx
->tess_output_info
;
2943 vtx
.src_gpr
= temp_val
;
2946 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2953 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2959 /* fetch tcs input values into input_vals */
2960 ctx
->tess_input_info
= r600_get_temp(ctx
);
2961 ctx
->tess_output_info
= 0;
2962 r
= r600_fetch_tess_io_info(ctx
);
2966 temp_reg
= r600_get_temp(ctx
);
2967 /* dst reg contains LDS address stride * idx */
2968 /* MUL vertexID, vertex_dw_stride */
2969 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2971 ctx
->tess_input_info
, 1,
2972 0, 1); /* rel id in r0.y? */
2976 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2977 struct r600_bytecode_alu alu
;
2978 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2981 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2984 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2989 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2991 temp_reg
, param
? 1 : 0,
2992 V_SQ_ALU_SRC_LITERAL
, 8);
2997 for (j
= 0; j
< 2; j
++) {
2998 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2999 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3000 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
3001 alu
.src
[0].sel
= temp_reg
;
3002 alu
.src
[0].chan
= chan
;
3003 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
3004 alu
.src
[1].chan
= j
* 2;
3005 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
3006 alu
.src
[2].chan
= (j
* 2) + 1;
3010 alu
.is_lds_idx_op
= true;
3011 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3019 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
3021 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3022 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
3024 int temp_reg
= r600_get_temp(ctx
);
3025 struct r600_bytecode_alu alu
;
3026 unsigned write_mask
= dst
->Register
.WriteMask
;
3028 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
3031 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
3035 /* the base address is now in temp.x */
3036 r
= r600_get_byte_address(ctx
, temp_reg
,
3037 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
3042 lasti
= tgsi_last_instruction(write_mask
);
3043 for (i
= 1; i
<= lasti
; i
++) {
3045 if (!(write_mask
& (1 << i
)))
3047 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
3050 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
3055 for (i
= 0; i
<= lasti
; i
++) {
3056 if (!(write_mask
& (1 << i
)))
3059 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
3060 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
3061 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3062 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
3063 alu
.src
[0].sel
= temp_reg
;
3064 alu
.src
[0].chan
= i
;
3066 alu
.src
[1].sel
= dst
->Register
.Index
;
3067 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
3068 alu
.src
[1].chan
= i
;
3070 alu
.src
[2].sel
= dst
->Register
.Index
;
3071 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
3072 alu
.src
[2].chan
= i
+ 1;
3076 alu
.is_lds_idx_op
= true;
3077 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3083 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3084 alu
.op
= LDS_OP2_LDS_WRITE
;
3085 alu
.src
[0].sel
= temp_reg
;
3086 alu
.src
[0].chan
= i
;
3088 alu
.src
[1].sel
= dst
->Register
.Index
;
3089 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
3090 alu
.src
[1].chan
= i
;
3092 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
3095 alu
.is_lds_idx_op
= true;
3096 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3103 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
3104 int output_idx
, int nc
)
3107 unsigned temp_reg
= r600_get_temp(ctx
);
3108 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
3109 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
3112 param
= r600_get_lds_unique_index(name
, 0);
3113 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
3118 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
3121 V_SQ_ALU_SRC_LITERAL
, param
* 16);
3126 do_lds_fetch_values(ctx
, temp_reg
, dreg
, ((1u << nc
) - 1));
3130 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
3132 int stride
, outer_comps
, inner_comps
;
3133 int tessinner_idx
= -1, tessouter_idx
= -1;
3136 int temp_reg
= r600_get_temp(ctx
);
3137 int treg
[3] = {-1, -1, -1};
3138 struct r600_bytecode_alu alu
;
3139 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
3141 /* only execute factor emission for invocation 0 */
3142 /* PRED_SETE_INT __, R0.x, 0 */
3143 memset(&alu
, 0, sizeof(alu
));
3144 alu
.op
= ALU_OP2_PRED_SETE_INT
;
3145 alu
.src
[0].chan
= 2;
3146 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3147 alu
.execute_mask
= 1;
3148 alu
.update_pred
= 1;
3150 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
3152 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
3153 cf_jump
= ctx
->bc
->cf_last
;
3155 treg
[0] = r600_get_temp(ctx
);
3156 switch (ctx
->shader
->tcs_prim_mode
) {
3157 case PIPE_PRIM_LINES
:
3158 stride
= 8; /* 2 dwords, 1 vec2 store */
3162 case PIPE_PRIM_TRIANGLES
:
3163 stride
= 16; /* 4 dwords, 1 vec4 store */
3166 treg
[1] = r600_get_temp(ctx
);
3168 case PIPE_PRIM_QUADS
:
3169 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
3172 treg
[1] = r600_get_temp(ctx
);
3173 treg
[2] = r600_get_temp(ctx
);
3180 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
3181 /* TF_WRITE takes index in R.x, value in R.y */
3182 for (j
= 0; j
< ctx
->shader
->noutput
; j
++) {
3183 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSINNER
)
3185 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSOUTER
)
3189 if (tessouter_idx
== -1)
3192 if (tessinner_idx
== -1 && inner_comps
)
3195 if (tessouter_idx
!= -1) {
3196 r
= r600_tess_factor_read(ctx
, tessouter_idx
, outer_comps
);
3201 if (tessinner_idx
!= -1) {
3202 r
= r600_tess_factor_read(ctx
, tessinner_idx
, inner_comps
);
3207 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
3208 /* r.x = relpatchid(r0.y) * tf_stride */
3210 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
3211 /* add incoming r0.w to it: t.x = t.x + r0.w */
3212 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3215 V_SQ_ALU_SRC_LITERAL
, stride
,
3220 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
3221 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
3222 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
3224 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
3227 else if (out_comp
== 0)
3231 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
3232 treg
[i
/ 2], (2 * (i
% 2)),
3234 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
3237 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
3238 treg
[i
/ 2], 1 + (2 * (i
%2)),
3239 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
3244 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
3245 struct r600_bytecode_gds gds
;
3247 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
3248 gds
.src_gpr
= treg
[i
/ 2];
3249 gds
.src_sel_x
= 2 * (i
% 2);
3250 gds
.src_sel_y
= 1 + (2 * (i
% 2));
3256 gds
.op
= FETCH_OP_TF_WRITE
;
3257 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
3262 // Patch up jump label
3263 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
3264 cf_pop
= ctx
->bc
->cf_last
;
3266 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
3267 cf_jump
->pop_count
= 1;
3268 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
3269 cf_pop
->pop_count
= 1;
3275 * We have to work out the thread ID for load and atomic
3276 * operations, which store the returned value to an index
3277 * in an intermediate buffer.
3278 * The index is calculated by taking the thread id,
3279 * calculated from the MBCNT instructions.
3280 * Then the shader engine ID is multiplied by 256,
3281 * and the wave id is added.
3282 * Then the result is multipled by 64 and thread id is
3285 static int load_thread_id_gpr(struct r600_shader_ctx
*ctx
)
3287 struct r600_bytecode_alu alu
;
3290 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3291 alu
.op
= ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT
;
3292 alu
.dst
.sel
= ctx
->temp_reg
;
3294 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3295 alu
.src
[0].value
= 0xffffffff;
3297 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3301 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3302 alu
.op
= ALU_OP1_MBCNT_32HI_INT
;
3303 alu
.dst
.sel
= ctx
->temp_reg
;
3305 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3306 alu
.src
[0].value
= 0xffffffff;
3308 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3312 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3313 alu
.op
= ALU_OP3_MULADD_UINT24
;
3314 alu
.dst
.sel
= ctx
->temp_reg
;
3316 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_SE_ID
;
3317 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3318 alu
.src
[1].value
= 256;
3319 alu
.src
[2].sel
= EG_V_SQ_ALU_SRC_HW_WAVE_ID
;
3323 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3327 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3328 ctx
->thread_id_gpr
, 1,
3330 V_SQ_ALU_SRC_LITERAL
, 0x40,
3337 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
3338 struct r600_pipe_shader
*pipeshader
,
3339 union r600_shader_key key
)
3341 struct r600_screen
*rscreen
= rctx
->screen
;
3342 struct r600_shader
*shader
= &pipeshader
->shader
;
3343 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
3344 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
3345 struct tgsi_full_immediate
*immediate
;
3346 struct r600_shader_ctx ctx
;
3347 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
3348 unsigned output_done
, noutput
;
3352 int next_param_base
= 0, next_clip_base
;
3353 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
3355 bool ring_outputs
= false;
3356 bool lds_outputs
= false;
3357 bool lds_inputs
= false;
3358 bool pos_emitted
= false;
3360 ctx
.bc
= &shader
->bc
;
3361 ctx
.shader
= shader
;
3363 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
3364 rscreen
->has_compressed_msaa_texturing
);
3365 ctx
.tokens
= tokens
;
3366 tgsi_scan_shader(tokens
, &ctx
.info
);
3367 shader
->indirect_files
= ctx
.info
.indirect_files
;
3369 int narrays
= ctx
.info
.array_max
[TGSI_FILE_TEMPORARY
];
3370 ctx
.array_infos
= calloc(narrays
, sizeof(*ctx
.array_infos
));
3371 ctx
.spilled_arrays
= calloc(narrays
, sizeof(bool));
3372 tgsi_scan_arrays(tokens
, TGSI_FILE_TEMPORARY
, narrays
, ctx
.array_infos
);
3374 shader
->uses_helper_invocation
= false;
3375 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
3376 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
3377 shader
->nsys_inputs
= 0;
3379 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0 ||
3380 ctx
.info
.file_count
[TGSI_FILE_BUFFER
] > 0;
3381 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
3382 tgsi_parse_init(&ctx
.parse
, tokens
);
3383 ctx
.type
= ctx
.info
.processor
;
3384 shader
->processor_type
= ctx
.type
;
3385 ctx
.bc
->type
= shader
->processor_type
;
3388 case PIPE_SHADER_VERTEX
:
3389 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
3390 shader
->vs_as_es
= key
.vs
.as_es
;
3391 shader
->vs_as_ls
= key
.vs
.as_ls
;
3392 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
3393 if (shader
->vs_as_es
)
3394 ring_outputs
= true;
3395 if (shader
->vs_as_ls
)
3398 case PIPE_SHADER_GEOMETRY
:
3399 ring_outputs
= true;
3400 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
3401 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
3403 case PIPE_SHADER_TESS_CTRL
:
3404 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
3405 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3409 case PIPE_SHADER_TESS_EVAL
:
3410 shader
->tes_as_es
= key
.tes
.as_es
;
3411 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3413 if (shader
->tes_as_es
)
3414 ring_outputs
= true;
3416 case PIPE_SHADER_FRAGMENT
:
3417 shader
->two_side
= key
.ps
.color_two_side
;
3418 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3419 shader
->rat_base
= key
.ps
.nr_cbufs
;
3420 shader
->image_size_const_offset
= key
.ps
.image_size_const_offset
;
3422 case PIPE_SHADER_COMPUTE
:
3423 shader
->rat_base
= 0;
3424 shader
->image_size_const_offset
= ctx
.info
.file_count
[TGSI_FILE_SAMPLER
];
3430 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3431 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3433 ctx
.gs_for_vs
= NULL
;
3436 ctx
.next_ring_offset
= 0;
3437 ctx
.gs_out_ring_offset
= 0;
3438 ctx
.gs_next_vertex
= 0;
3439 ctx
.gs_stream_output_info
= &so
;
3441 ctx
.thread_id_gpr
= -1;
3443 ctx
.fixed_pt_position_gpr
= -1;
3444 ctx
.fragcoord_input
= -1;
3445 ctx
.colors_used
= 0;
3446 ctx
.clip_vertex_write
= 0;
3448 ctx
.helper_invoc_reg
= -1;
3449 ctx
.cs_block_size_reg
= -1;
3450 ctx
.cs_grid_size_reg
= -1;
3451 ctx
.cs_block_size_loaded
= false;
3452 ctx
.cs_grid_size_loaded
= false;
3454 shader
->nr_ps_color_exports
= 0;
3455 shader
->nr_ps_max_color_exports
= 0;
3458 /* register allocations */
3459 /* Values [0,127] correspond to GPR[0..127].
3460 * Values [128,159] correspond to constant buffer bank 0
3461 * Values [160,191] correspond to constant buffer bank 1
3462 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3463 * Values [256,287] correspond to constant buffer bank 2 (EG)
3464 * Values [288,319] correspond to constant buffer bank 3 (EG)
3465 * Other special values are shown in the list below.
3466 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3467 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3468 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3469 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3470 * 248 SQ_ALU_SRC_0: special constant 0.0.
3471 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3472 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3473 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3474 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3475 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3476 * 254 SQ_ALU_SRC_PV: previous vector result.
3477 * 255 SQ_ALU_SRC_PS: previous scalar result.
3479 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3480 ctx
.file_offset
[i
] = 0;
3483 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3485 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3486 if (ctx
.info
.num_inputs
)
3487 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3489 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3490 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3491 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3493 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3495 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3496 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_HELPER_INVOCATION
) {
3497 ctx
.helper_invoc_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3498 shader
->uses_helper_invocation
= true;
3502 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3503 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3504 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3506 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3507 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3508 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3509 bool add_tesscoord
= false, add_tess_inout
= false;
3510 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3511 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3512 /* if we have tesscoord save one reg */
3513 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3514 add_tesscoord
= true;
3515 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3516 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3517 add_tess_inout
= true;
3519 if (add_tesscoord
|| add_tess_inout
)
3520 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3522 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3524 if (ctx
.type
== PIPE_SHADER_COMPUTE
) {
3525 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3526 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3527 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_GRID_SIZE
)
3528 ctx
.cs_grid_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3529 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_BLOCK_SIZE
)
3530 ctx
.cs_block_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3534 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3535 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3536 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3537 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3538 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3540 /* Outside the GPR range. This will be translated to one of the
3541 * kcache banks later. */
3542 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3543 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3545 pipeshader
->scratch_space_needed
= 0;
3546 int regno
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3547 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
];
3549 choose_spill_arrays(&ctx
, ®no
, &pipeshader
->scratch_space_needed
);
3550 shader
->indirect_files
= ctx
.info
.indirect_files
;
3552 shader
->needs_scratch_space
= pipeshader
->scratch_space_needed
!= 0;
3554 ctx
.bc
->ar_reg
= ++regno
;
3555 ctx
.bc
->index_reg
[0] = ++regno
;
3556 ctx
.bc
->index_reg
[1] = ++regno
;
3558 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3559 ctx
.tess_input_info
= ++regno
;
3560 ctx
.tess_output_info
= ++regno
;
3561 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3562 ctx
.tess_input_info
= 0;
3563 ctx
.tess_output_info
= ++regno
;
3564 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3565 ctx
.gs_export_gpr_tregs
[0] = ++regno
;
3566 ctx
.gs_export_gpr_tregs
[1] = ++regno
;
3567 ctx
.gs_export_gpr_tregs
[2] = ++regno
;
3568 ctx
.gs_export_gpr_tregs
[3] = ++regno
;
3569 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3570 ctx
.gs_rotated_input
[0] = ++regno
;
3571 ctx
.gs_rotated_input
[1] = ++regno
;
3573 ctx
.gs_rotated_input
[0] = 0;
3574 ctx
.gs_rotated_input
[1] = 1;
3578 if (shader
->uses_images
) {
3579 ctx
.thread_id_gpr
= ++regno
;
3581 ctx
.temp_reg
= ++regno
;
3583 shader
->max_arrays
= 0;
3584 shader
->num_arrays
= 0;
3585 if (indirect_gprs
) {
3587 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3588 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3589 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3590 ctx
.file_offset
[TGSI_FILE_INPUT
],
3593 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3594 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3595 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3596 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3602 ctx
.literals
= NULL
;
3603 ctx
.max_driver_temp_used
= 0;
3605 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3606 ctx
.info
.colors_written
== 1;
3607 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3608 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3610 if (ctx
.type
== PIPE_SHADER_VERTEX
||
3611 ctx
.type
== PIPE_SHADER_GEOMETRY
||
3612 ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3613 shader
->cc_dist_mask
= (1 << (ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
] +
3614 ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
])) - 1;
3615 shader
->clip_dist_write
= (1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
]) - 1;
3616 shader
->cull_dist_write
= ((1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
]) - 1) << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
];
3619 if (shader
->vs_as_gs_a
)
3620 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3622 if (ctx
.thread_id_gpr
!= -1) {
3623 r
= load_thread_id_gpr(&ctx
);
3628 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3629 r600_fetch_tess_io_info(&ctx
);
3631 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3632 tgsi_parse_token(&ctx
.parse
);
3633 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3634 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3635 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3636 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3637 if(ctx
.literals
== NULL
) {
3641 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3642 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3643 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3644 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3647 case TGSI_TOKEN_TYPE_DECLARATION
:
3648 r
= tgsi_declaration(&ctx
);
3652 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3653 case TGSI_TOKEN_TYPE_PROPERTY
:
3656 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3662 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3663 shader
->ring_item_sizes
[1] = 0;
3664 shader
->ring_item_sizes
[2] = 0;
3665 shader
->ring_item_sizes
[3] = 0;
3667 /* Process two side if needed */
3668 if (shader
->two_side
&& ctx
.colors_used
) {
3669 int i
, count
= ctx
.shader
->ninput
;
3670 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3672 /* additional inputs will be allocated right after the existing inputs,
3673 * we won't need them after the color selection, so we don't need to
3674 * reserve these gprs for the rest of the shader code and to adjust
3675 * output offsets etc. */
3676 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3677 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3679 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3680 if (ctx
.face_gpr
== -1) {
3681 i
= ctx
.shader
->ninput
++;
3682 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3683 ctx
.shader
->input
[i
].spi_sid
= 0;
3684 ctx
.shader
->input
[i
].gpr
= gpr
++;
3685 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3688 for (i
= 0; i
< count
; i
++) {
3689 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3690 int ni
= ctx
.shader
->ninput
++;
3691 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3692 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3693 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3694 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3695 // TGSI to LLVM needs to know the lds position of inputs.
3696 // Non LLVM path computes it later (in process_twoside_color)
3697 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3698 ctx
.shader
->input
[i
].back_color_input
= ni
;
3699 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3700 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3707 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3708 shader
->nr_ps_max_color_exports
= 8;
3710 if (ctx
.shader
->uses_helper_invocation
) {
3711 if (ctx
.bc
->chip_class
== CAYMAN
)
3712 r
= cm_load_helper_invocation(&ctx
);
3714 r
= eg_load_helper_invocation(&ctx
);
3720 * XXX this relies on fixed_pt_position_gpr only being present when
3721 * this shader should be executed per sample. Should be the case for now...
3723 if (ctx
.fixed_pt_position_gpr
!= -1 && ctx
.info
.reads_samplemask
) {
3725 * Fix up sample mask. The hw always gives us coverage mask for
3726 * the pixel. However, for per-sample shading, we need the
3727 * coverage for the shader invocation only.
3728 * Also, with disabled msaa, only the first bit should be set
3729 * (luckily the same fixup works for both problems).
3730 * For now, we can only do it if we know this shader is always
3731 * executed per sample (due to usage of bits in the shader
3732 * forcing per-sample execution).
3733 * If the fb is not multisampled, we'd do unnecessary work but
3734 * it should still be correct.
3735 * It will however do nothing for sample shading according
3736 * to MinSampleShading.
3738 struct r600_bytecode_alu alu
;
3739 int tmp
= r600_get_temp(&ctx
);
3740 assert(ctx
.face_gpr
!= -1);
3741 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3743 alu
.op
= ALU_OP2_LSHL_INT
;
3744 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3745 alu
.src
[0].value
= 0x1;
3746 alu
.src
[1].sel
= ctx
.fixed_pt_position_gpr
;
3747 alu
.src
[1].chan
= 3;
3752 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3755 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3756 alu
.op
= ALU_OP2_AND_INT
;
3757 alu
.src
[0].sel
= tmp
;
3758 alu
.src
[1].sel
= ctx
.face_gpr
;
3759 alu
.src
[1].chan
= 2;
3760 alu
.dst
.sel
= ctx
.face_gpr
;
3764 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3768 if (ctx
.fragcoord_input
>= 0) {
3769 if (ctx
.bc
->chip_class
== CAYMAN
) {
3770 for (j
= 0 ; j
< 4; j
++) {
3771 struct r600_bytecode_alu alu
;
3772 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3773 alu
.op
= ALU_OP1_RECIP_IEEE
;
3774 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3775 alu
.src
[0].chan
= 3;
3777 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3779 alu
.dst
.write
= (j
== 3);
3780 alu
.last
= (j
== 3);
3781 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3785 struct r600_bytecode_alu alu
;
3786 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3787 alu
.op
= ALU_OP1_RECIP_IEEE
;
3788 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3789 alu
.src
[0].chan
= 3;
3791 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3795 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3800 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3801 struct r600_bytecode_alu alu
;
3804 /* GS thread with no output workaround - emit a cut at start of GS */
3805 if (ctx
.bc
->chip_class
== R600
)
3806 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3808 for (j
= 0; j
< 4; j
++) {
3809 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3810 alu
.op
= ALU_OP1_MOV
;
3811 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3812 alu
.src
[0].value
= 0;
3813 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3816 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3821 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3822 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3823 ctx
.gs_rotated_input
[0], 2,
3825 V_SQ_ALU_SRC_LITERAL
, 1);
3829 for (i
= 0; i
< 6; i
++) {
3830 int rotated
= (i
+ 4) % 6;
3831 int offset_reg
= i
/ 3;
3832 int offset_chan
= i
% 3;
3833 int rotated_offset_reg
= rotated
/ 3;
3834 int rotated_offset_chan
= rotated
% 3;
3836 if (offset_reg
== 0 && offset_chan
== 2)
3838 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3839 rotated_offset_chan
= 3;
3841 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3842 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3843 ctx
.gs_rotated_input
[0], 2,
3844 offset_reg
, offset_chan
,
3845 rotated_offset_reg
, rotated_offset_chan
);
3852 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3853 r600_fetch_tess_io_info(&ctx
);
3855 if (shader
->two_side
&& ctx
.colors_used
) {
3856 if ((r
= process_twoside_color_inputs(&ctx
)))
3860 tgsi_parse_init(&ctx
.parse
, tokens
);
3861 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3862 tgsi_parse_token(&ctx
.parse
);
3863 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3864 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3865 r
= tgsi_is_supported(&ctx
);
3868 ctx
.max_driver_temp_used
= 0;
3869 /* reserve first tmp for everyone */
3870 r600_get_temp(&ctx
);
3872 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3873 if ((r
= tgsi_split_constant(&ctx
)))
3875 if ((r
= tgsi_split_literal_constant(&ctx
)))
3877 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3878 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3880 } else if (lds_inputs
) {
3881 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3884 if (ctx
.bc
->chip_class
== CAYMAN
)
3885 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3886 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3887 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3889 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3890 r
= ctx
.inst_info
->process(&ctx
);
3894 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3895 r
= r600_store_tcs_output(&ctx
);
3905 /* Reset the temporary register counter. */
3906 ctx
.max_driver_temp_used
= 0;
3908 noutput
= shader
->noutput
;
3910 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3911 unsigned clipdist_temp
[2];
3913 clipdist_temp
[0] = r600_get_temp(&ctx
);
3914 clipdist_temp
[1] = r600_get_temp(&ctx
);
3916 /* need to convert a clipvertex write into clipdistance writes and not export
3917 the clip vertex anymore */
3919 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3920 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3921 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3923 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3924 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3927 /* reset spi_sid for clipvertex output to avoid confusing spi */
3928 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3930 shader
->clip_dist_write
= 0xFF;
3931 shader
->cc_dist_mask
= 0xFF;
3933 for (i
= 0; i
< 8; i
++) {
3937 for (j
= 0; j
< 4; j
++) {
3938 struct r600_bytecode_alu alu
;
3939 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3940 alu
.op
= ALU_OP2_DOT4
;
3941 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3942 alu
.src
[0].chan
= j
;
3944 alu
.src
[1].sel
= 512 + i
;
3945 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3946 alu
.src
[1].chan
= j
;
3948 alu
.dst
.sel
= clipdist_temp
[oreg
];
3950 alu
.dst
.write
= (j
== ochan
);
3953 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3960 /* Add stream outputs. */
3961 if (so
.num_outputs
) {
3963 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3965 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3968 emit_streamout(&ctx
, &so
, -1, NULL
);
3970 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3971 convert_edgeflag_to_int(&ctx
);
3973 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3974 r600_emit_tess_factor(&ctx
);
3977 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3978 if (ctx
.shader
->noutput
)
3979 emit_lds_vs_writes(&ctx
);
3981 } else if (ring_outputs
) {
3982 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3983 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3984 ctx
.gs_export_gpr_tregs
[1] = -1;
3985 ctx
.gs_export_gpr_tregs
[2] = -1;
3986 ctx
.gs_export_gpr_tregs
[3] = -1;
3988 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3992 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3994 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3995 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3996 output
[j
].gpr
= shader
->output
[i
].gpr
;
3997 output
[j
].elem_size
= 3;
3998 output
[j
].swizzle_x
= 0;
3999 output
[j
].swizzle_y
= 1;
4000 output
[j
].swizzle_z
= 2;
4001 output
[j
].swizzle_w
= 3;
4002 output
[j
].burst_count
= 1;
4003 output
[j
].type
= 0xffffffff;
4004 output
[j
].op
= CF_OP_EXPORT
;
4006 case PIPE_SHADER_VERTEX
:
4007 case PIPE_SHADER_TESS_EVAL
:
4008 switch (shader
->output
[i
].name
) {
4009 case TGSI_SEMANTIC_POSITION
:
4010 output
[j
].array_base
= 60;
4011 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4015 case TGSI_SEMANTIC_PSIZE
:
4016 output
[j
].array_base
= 61;
4017 output
[j
].swizzle_y
= 7;
4018 output
[j
].swizzle_z
= 7;
4019 output
[j
].swizzle_w
= 7;
4020 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4023 case TGSI_SEMANTIC_EDGEFLAG
:
4024 output
[j
].array_base
= 61;
4025 output
[j
].swizzle_x
= 7;
4026 output
[j
].swizzle_y
= 0;
4027 output
[j
].swizzle_z
= 7;
4028 output
[j
].swizzle_w
= 7;
4029 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4032 case TGSI_SEMANTIC_LAYER
:
4033 /* spi_sid is 0 for outputs that are
4034 * not consumed by PS */
4035 if (shader
->output
[i
].spi_sid
) {
4036 output
[j
].array_base
= next_param_base
++;
4037 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4039 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
4041 output
[j
].array_base
= 61;
4042 output
[j
].swizzle_x
= 7;
4043 output
[j
].swizzle_y
= 7;
4044 output
[j
].swizzle_z
= 0;
4045 output
[j
].swizzle_w
= 7;
4046 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4049 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
4050 /* spi_sid is 0 for outputs that are
4051 * not consumed by PS */
4052 if (shader
->output
[i
].spi_sid
) {
4053 output
[j
].array_base
= next_param_base
++;
4054 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4056 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
4058 output
[j
].array_base
= 61;
4059 output
[j
].swizzle_x
= 7;
4060 output
[j
].swizzle_y
= 7;
4061 output
[j
].swizzle_z
= 7;
4062 output
[j
].swizzle_w
= 0;
4063 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4066 case TGSI_SEMANTIC_CLIPVERTEX
:
4069 case TGSI_SEMANTIC_CLIPDIST
:
4070 output
[j
].array_base
= next_clip_base
++;
4071 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4073 /* spi_sid is 0 for clipdistance outputs that were generated
4074 * for clipvertex - we don't need to pass them to PS */
4075 if (shader
->output
[i
].spi_sid
) {
4077 /* duplicate it as PARAM to pass to the pixel shader */
4078 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
4079 output
[j
].array_base
= next_param_base
++;
4080 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4083 case TGSI_SEMANTIC_FOG
:
4084 output
[j
].swizzle_y
= 4; /* 0 */
4085 output
[j
].swizzle_z
= 4; /* 0 */
4086 output
[j
].swizzle_w
= 5; /* 1 */
4088 case TGSI_SEMANTIC_PRIMID
:
4089 output
[j
].swizzle_x
= 2;
4090 output
[j
].swizzle_y
= 4; /* 0 */
4091 output
[j
].swizzle_z
= 4; /* 0 */
4092 output
[j
].swizzle_w
= 4; /* 0 */
4097 case PIPE_SHADER_FRAGMENT
:
4098 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
4099 /* never export more colors than the number of CBs */
4100 if (shader
->output
[i
].sid
>= max_color_exports
) {
4105 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
4106 output
[j
].array_base
= shader
->output
[i
].sid
;
4107 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4108 shader
->nr_ps_color_exports
++;
4109 shader
->ps_color_export_mask
|= (0xf << (shader
->output
[i
].sid
* 4));
4111 /* If the i-th target format is set, all previous target formats must
4112 * be non-zero to avoid hangs. - from radeonsi, seems to apply to eg as well.
4114 if (shader
->output
[i
].sid
> 0)
4115 for (unsigned x
= 0; x
< shader
->output
[i
].sid
; x
++)
4116 shader
->ps_color_export_mask
|= (1 << (x
*4));
4118 if (shader
->output
[i
].sid
> shader
->ps_export_highest
)
4119 shader
->ps_export_highest
= shader
->output
[i
].sid
;
4120 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
4121 for (k
= 1; k
< max_color_exports
; k
++) {
4123 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4124 output
[j
].gpr
= shader
->output
[i
].gpr
;
4125 output
[j
].elem_size
= 3;
4126 output
[j
].swizzle_x
= 0;
4127 output
[j
].swizzle_y
= 1;
4128 output
[j
].swizzle_z
= 2;
4129 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
4130 output
[j
].burst_count
= 1;
4131 output
[j
].array_base
= k
;
4132 output
[j
].op
= CF_OP_EXPORT
;
4133 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4134 shader
->nr_ps_color_exports
++;
4135 if (k
> shader
->ps_export_highest
)
4136 shader
->ps_export_highest
= k
;
4137 shader
->ps_color_export_mask
|= (0xf << (j
* 4));
4140 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
4141 output
[j
].array_base
= 61;
4142 output
[j
].swizzle_x
= 2;
4143 output
[j
].swizzle_y
= 7;
4144 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
4145 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4146 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
4147 output
[j
].array_base
= 61;
4148 output
[j
].swizzle_x
= 7;
4149 output
[j
].swizzle_y
= 1;
4150 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
4151 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4152 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
4153 output
[j
].array_base
= 61;
4154 output
[j
].swizzle_x
= 7;
4155 output
[j
].swizzle_y
= 7;
4156 output
[j
].swizzle_z
= 0;
4157 output
[j
].swizzle_w
= 7;
4158 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4160 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
4165 case PIPE_SHADER_TESS_CTRL
:
4168 R600_ERR("unsupported processor type %d\n", ctx
.type
);
4173 if (output
[j
].type
== 0xffffffff) {
4174 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4175 output
[j
].array_base
= next_param_base
++;
4179 /* add fake position export */
4180 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
4181 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4183 output
[j
].elem_size
= 3;
4184 output
[j
].swizzle_x
= 7;
4185 output
[j
].swizzle_y
= 7;
4186 output
[j
].swizzle_z
= 7;
4187 output
[j
].swizzle_w
= 7;
4188 output
[j
].burst_count
= 1;
4189 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4190 output
[j
].array_base
= 60;
4191 output
[j
].op
= CF_OP_EXPORT
;
4195 /* add fake param output for vertex shader if no param is exported */
4196 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
4197 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4199 output
[j
].elem_size
= 3;
4200 output
[j
].swizzle_x
= 7;
4201 output
[j
].swizzle_y
= 7;
4202 output
[j
].swizzle_z
= 7;
4203 output
[j
].swizzle_w
= 7;
4204 output
[j
].burst_count
= 1;
4205 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4206 output
[j
].array_base
= 0;
4207 output
[j
].op
= CF_OP_EXPORT
;
4211 /* add fake pixel export */
4212 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
4213 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4215 output
[j
].elem_size
= 3;
4216 output
[j
].swizzle_x
= 7;
4217 output
[j
].swizzle_y
= 7;
4218 output
[j
].swizzle_z
= 7;
4219 output
[j
].swizzle_w
= 7;
4220 output
[j
].burst_count
= 1;
4221 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4222 output
[j
].array_base
= 0;
4223 output
[j
].op
= CF_OP_EXPORT
;
4225 shader
->nr_ps_color_exports
++;
4226 shader
->ps_color_export_mask
= 0xf;
4231 /* set export done on last export of each type */
4232 for (k
= noutput
- 1, output_done
= 0; k
>= 0; k
--) {
4233 if (!(output_done
& (1 << output
[k
].type
))) {
4234 output_done
|= (1 << output
[k
].type
);
4235 output
[k
].op
= CF_OP_EXPORT_DONE
;
4238 /* add output to bytecode */
4239 for (i
= 0; i
< noutput
; i
++) {
4240 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
4246 /* add program end */
4247 if (ctx
.bc
->chip_class
== CAYMAN
)
4248 cm_bytecode_add_cf_end(ctx
.bc
);
4250 const struct cf_op_info
*last
= NULL
;
4252 if (ctx
.bc
->cf_last
)
4253 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
4255 /* alu clause instructions don't have EOP bit, so add NOP */
4256 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
)
4257 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
4259 ctx
.bc
->cf_last
->end_of_program
= 1;
4262 /* check GPR limit - we have 124 = 128 - 4
4263 * (4 are reserved as alu clause temporary registers) */
4264 if (ctx
.bc
->ngpr
> 124) {
4265 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
4270 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
4271 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
4275 free(ctx
.spilled_arrays
);
4276 free(ctx
.array_infos
);
4278 tgsi_parse_free(&ctx
.parse
);
4281 free(ctx
.spilled_arrays
);
4282 free(ctx
.array_infos
);
4284 tgsi_parse_free(&ctx
.parse
);
4288 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
4290 const unsigned tgsi_opcode
=
4291 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
4292 R600_ERR("%s tgsi opcode unsupported\n",
4293 tgsi_get_opcode_name(tgsi_opcode
));
4297 static int tgsi_end(struct r600_shader_ctx
*ctx UNUSED
)
4302 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
4303 const struct r600_shader_src
*shader_src
,
4306 bc_src
->sel
= shader_src
->sel
;
4307 bc_src
->chan
= shader_src
->swizzle
[chan
];
4308 bc_src
->neg
= shader_src
->neg
;
4309 bc_src
->abs
= shader_src
->abs
;
4310 bc_src
->rel
= shader_src
->rel
;
4311 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
4312 bc_src
->kc_bank
= shader_src
->kc_bank
;
4313 bc_src
->kc_rel
= shader_src
->kc_rel
;
4316 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
4322 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
4324 bc_src
->neg
= !bc_src
->neg
;
4327 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
4328 const struct tgsi_full_dst_register
*tgsi_dst
,
4330 struct r600_bytecode_alu_dst
*r600_dst
)
4332 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4334 if (tgsi_dst
->Register
.File
== TGSI_FILE_TEMPORARY
) {
4338 idx
= map_tgsi_reg_index_to_r600_gpr(ctx
, tgsi_dst
->Register
.Index
, &spilled
);
4341 struct r600_bytecode_output cf
;
4344 bool add_pending_output
= true;
4346 memset(&cf
, 0, sizeof(struct r600_bytecode_output
));
4347 get_spilled_array_base_and_size(ctx
, tgsi_dst
->Register
.Index
,
4348 &cf
.array_base
, &cf
.array_size
);
4350 /* If no component has spilled, reserve a register and add the spill code
4351 * ctx->bc->n_pending_outputs is cleared after each instruction group */
4352 if (ctx
->bc
->n_pending_outputs
== 0) {
4353 reg
= r600_get_temp(ctx
);
4355 /* If we are already spilling and the output address is the same like
4356 * before then just reuse the same slot */
4357 struct r600_bytecode_output
*tmpl
= &ctx
->bc
->pending_outputs
[ctx
->bc
->n_pending_outputs
-1];
4358 if ((cf
.array_base
+ idx
== tmpl
->array_base
) ||
4359 (cf
.array_base
== tmpl
->array_base
&&
4360 tmpl
->index_gpr
== ctx
->bc
->ar_reg
&&
4361 tgsi_dst
->Register
.Indirect
)) {
4362 reg
= ctx
->bc
->pending_outputs
[0].gpr
;
4363 add_pending_output
= false;
4365 reg
= r600_get_temp(ctx
);
4369 r600_dst
->sel
= reg
;
4370 r600_dst
->chan
= swizzle
;
4371 r600_dst
->write
= 1;
4372 if (inst
->Instruction
.Saturate
) {
4373 r600_dst
->clamp
= 1;
4376 /* Add new outputs as pending */
4377 if (add_pending_output
) {
4378 cf
.op
= CF_OP_MEM_SCRATCH
;
4381 cf
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
4383 cf
.comp_mask
= inst
->Dst
[0].Register
.WriteMask
;
4390 if (tgsi_dst
->Register
.Indirect
) {
4391 if (ctx
->bc
->chip_class
< R700
)
4392 cf
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
4394 cf
.type
= 3; // V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND_ACK;
4395 cf
.index_gpr
= ctx
->bc
->ar_reg
;
4398 cf
.array_base
+= idx
;
4402 r
= r600_bytecode_add_pending_output(ctx
->bc
, &cf
);
4406 if (ctx
->bc
->chip_class
>= R700
)
4407 r600_bytecode_need_wait_ack(ctx
->bc
, true);
4412 r600_dst
->sel
= idx
;
4416 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
4417 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
4419 r600_dst
->chan
= swizzle
;
4420 r600_dst
->write
= 1;
4421 if (inst
->Instruction
.Saturate
) {
4422 r600_dst
->clamp
= 1;
4424 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
4425 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
4429 if (tgsi_dst
->Register
.Indirect
)
4430 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
4434 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
, int dest_temp
, int op_override
)
4436 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4437 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4438 struct r600_bytecode_alu alu
;
4439 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4441 int swizzle_x
= inst
->Src
[0].Register
.SwizzleX
;
4444 switch (write_mask
) {
4446 if (swizzle_x
== 2) {
4453 if (swizzle_x
== 2) {
4462 if (swizzle_x
== 0) {
4469 if (swizzle_x
== 0) {
4480 lasti
= tgsi_last_instruction(write_mask
);
4481 for (i
= 0; i
<= lasti
; i
++) {
4483 if (!(write_mask
& (1 << i
)))
4486 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4489 if (use_tmp
|| dest_temp
) {
4490 alu
.dst
.sel
= use_tmp
? ctx
->temp_reg
: dest_temp
;
4494 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4496 if (i
== 1 || i
== 3)
4499 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4501 alu
.op
= op_override
? op_override
: ctx
->inst_info
->op
;
4502 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
4503 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4505 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4506 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4509 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
4510 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
4513 /* handle some special cases */
4514 if (i
== 1 || i
== 3) {
4515 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
4516 case TGSI_OPCODE_DABS
:
4517 r600_bytecode_src_set_abs(&alu
.src
[0]);
4526 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4532 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4534 lasti
= tgsi_last_instruction(write_mask
);
4535 /* move result from temp to dst */
4536 for (i
= 0; i
<= lasti
; i
++) {
4537 if (!(write_mask
& (1 << i
)))
4540 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4541 alu
.op
= ALU_OP1_MOV
;
4544 alu
.dst
.sel
= dest_temp
;
4548 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4549 alu
.src
[0].sel
= ctx
->temp_reg
;
4550 alu
.src
[0].chan
= use_tmp
- 1;
4551 alu
.last
= (i
== lasti
);
4553 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4561 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
4563 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4564 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4565 /* confirm writemasking */
4566 if ((write_mask
& 0x3) != 0x3 &&
4567 (write_mask
& 0xc) != 0xc) {
4568 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
4571 return tgsi_op2_64_params(ctx
, false, false, 0, 0);
4574 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4576 return tgsi_op2_64_params(ctx
, true, false, 0, 0);
4579 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4581 return tgsi_op2_64_params(ctx
, true, true, 0, 0);
4584 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4586 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4587 struct r600_bytecode_alu alu
;
4590 int tmp
= r600_get_temp(ctx
);
4592 for (i
= 0; i
< lasti
+ 1; i
++) {
4594 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4595 alu
.op
= ctx
->inst_info
->op
;
4596 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4597 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4600 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4601 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4610 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4617 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4619 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4620 struct r600_bytecode_alu alu
;
4621 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4622 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4623 /* use temp register if trans_only and more than one dst component */
4624 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4625 unsigned op
= ctx
->inst_info
->op
;
4627 if (op
== ALU_OP2_MUL_IEEE
&&
4628 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4631 for (i
= 0; i
<= lasti
; i
++) {
4632 if (!(write_mask
& (1 << i
)))
4635 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4637 alu
.dst
.sel
= ctx
->temp_reg
;
4641 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4645 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4646 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4649 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4650 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4652 if (i
== lasti
|| trans_only
) {
4655 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4661 /* move result from temp to dst */
4662 for (i
= 0; i
<= lasti
; i
++) {
4663 if (!(write_mask
& (1 << i
)))
4666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4667 alu
.op
= ALU_OP1_MOV
;
4668 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4669 alu
.src
[0].sel
= ctx
->temp_reg
;
4670 alu
.src
[0].chan
= i
;
4671 alu
.last
= (i
== lasti
);
4673 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4681 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4683 return tgsi_op2_s(ctx
, 0, 0);
4686 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4688 return tgsi_op2_s(ctx
, 1, 0);
4691 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4693 return tgsi_op2_s(ctx
, 0, 1);
4696 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4698 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4699 struct r600_bytecode_alu alu
;
4701 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4703 for (i
= 0; i
< lasti
+ 1; i
++) {
4705 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4707 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4708 alu
.op
= ctx
->inst_info
->op
;
4710 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4712 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4714 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4719 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4727 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4729 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4730 struct r600_bytecode_alu alu
;
4732 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4734 for (i
= 0; i
< lasti
+ 1; i
++) {
4736 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4738 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4739 alu
.op
= ALU_OP1_MOV
;
4741 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4743 if (i
== 1 || i
== 3)
4744 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4745 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4750 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4758 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4760 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4761 struct r600_bytecode_alu alu
;
4762 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4765 for (i
= 0; i
<= 3; i
++) {
4766 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4767 alu
.op
= ctx
->inst_info
->op
;
4769 alu
.dst
.sel
= ctx
->temp_reg
;
4772 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4773 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4779 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4784 /* Replicate significand result across channels. */
4785 for (i
= 0; i
<= 3; i
++) {
4786 if (!(write_mask
& (1 << i
)))
4789 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4790 alu
.op
= ALU_OP1_MOV
;
4791 alu
.src
[0].chan
= (i
& 1) + 2;
4792 alu
.src
[0].sel
= ctx
->temp_reg
;
4794 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4797 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4802 for (i
= 0; i
<= 3; i
++) {
4803 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4804 /* MOV third channels to writemask dst1 */
4805 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4806 alu
.op
= ALU_OP1_MOV
;
4807 alu
.src
[0].chan
= 1;
4808 alu
.src
[0].sel
= ctx
->temp_reg
;
4810 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4812 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4822 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4824 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4825 struct r600_bytecode_alu alu
;
4827 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4828 int temp_reg
= r600_get_temp(ctx
);
4830 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4831 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4833 for (c
= 0; c
< 2; c
++) {
4835 if (write_mask
& (0x3 << dchan
)) {
4836 /* split into 24-bit int and 8-bit int */
4837 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4838 alu
.op
= ALU_OP2_AND_INT
;
4839 alu
.dst
.sel
= temp_reg
;
4840 alu
.dst
.chan
= dchan
;
4841 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4842 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4843 alu
.src
[1].value
= 0xffffff00;
4845 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4849 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4850 alu
.op
= ALU_OP2_AND_INT
;
4851 alu
.dst
.sel
= temp_reg
;
4852 alu
.dst
.chan
= dchan
+ 1;
4853 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4854 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4855 alu
.src
[1].value
= 0xff;
4858 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4864 for (c
= 0; c
< 2; c
++) {
4866 if (write_mask
& (0x3 << dchan
)) {
4867 for (i
= dchan
; i
<= dchan
+ 1; i
++) {
4868 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4869 alu
.op
= i
== dchan
? ctx
->inst_info
->op
: ALU_OP1_UINT_TO_FLT
;
4871 alu
.src
[0].sel
= temp_reg
;
4872 alu
.src
[0].chan
= i
;
4873 alu
.dst
.sel
= temp_reg
;
4876 if (ctx
->bc
->chip_class
== CAYMAN
)
4877 alu
.last
= i
== dchan
+ 1;
4879 alu
.last
= 1; /* trans only ops on evergreen */
4881 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4888 for (c
= 0; c
< 2; c
++) {
4890 if (write_mask
& (0x3 << dchan
)) {
4891 for (i
= 0; i
< 4; i
++) {
4892 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4893 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4895 alu
.src
[0].chan
= dchan
+ (i
/ 2);
4896 if (i
== 0 || i
== 2)
4897 alu
.src
[0].sel
= temp_reg
;
4899 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4900 alu
.src
[0].value
= 0x0;
4902 alu
.dst
.sel
= ctx
->temp_reg
;
4907 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4912 for (i
= 0; i
<= 1; i
++) {
4913 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4914 alu
.op
= ALU_OP2_ADD_64
;
4916 alu
.src
[0].chan
= fp64_switch(i
);
4917 alu
.src
[0].sel
= ctx
->temp_reg
;
4919 alu
.src
[1].chan
= fp64_switch(i
+ 2);
4920 alu
.src
[1].sel
= ctx
->temp_reg
;
4921 tgsi_dst(ctx
, &inst
->Dst
[0], dchan
+ i
, &alu
.dst
);
4924 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4934 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4936 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4937 struct r600_bytecode_alu alu
;
4939 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4940 int treg
= r600_get_temp(ctx
);
4941 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4942 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4944 /* do a 64->32 into a temp register */
4945 r
= tgsi_op2_64_params(ctx
, true, false, treg
, ALU_OP1_FLT64_TO_FLT32
);
4949 for (i
= 0; i
<= lasti
; i
++) {
4950 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4952 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4953 alu
.op
= ctx
->inst_info
->op
;
4955 alu
.src
[0].chan
= i
;
4956 alu
.src
[0].sel
= treg
;
4957 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4958 alu
.last
= (i
== lasti
);
4960 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4968 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4971 struct r600_shader_src
*src
,
4974 struct r600_bytecode_alu alu
;
4975 const int last_slot
= 3;
4978 /* these have to write the result to X/Y by the looks of it */
4979 for (int i
= 0 ; i
< last_slot
; i
++) {
4980 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4983 r600_bytecode_src(&alu
.src
[0], src
, 1);
4984 r600_bytecode_src(&alu
.src
[1], src
, 0);
4987 r600_bytecode_src_set_abs(&alu
.src
[1]);
4989 alu
.dst
.sel
= dst_reg
;
4991 alu
.dst
.write
= (i
== 0 || i
== 1);
4993 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4995 r
= r600_bytecode_add_alu(bc
, &alu
);
5003 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
5005 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5007 struct r600_bytecode_alu alu
;
5008 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5009 int t1
= ctx
->temp_reg
;
5011 /* should only be one src regs */
5012 assert(inst
->Instruction
.NumSrcRegs
== 1);
5014 /* only support one double at a time */
5015 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
5016 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
5018 r
= cayman_emit_unary_double_raw(
5019 ctx
->bc
, ctx
->inst_info
->op
, t1
,
5021 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
5022 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
5026 for (i
= 0 ; i
<= lasti
; i
++) {
5027 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5029 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5030 alu
.op
= ALU_OP1_MOV
;
5031 alu
.src
[0].sel
= t1
;
5032 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
5033 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5037 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5044 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
5046 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5048 struct r600_bytecode_alu alu
;
5049 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5051 for (i
= 0 ; i
< last_slot
; i
++) {
5052 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5053 alu
.op
= ctx
->inst_info
->op
;
5054 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5055 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
5057 /* RSQ should take the absolute value of src */
5058 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
5059 r600_bytecode_src_set_abs(&alu
.src
[j
]);
5062 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5063 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5065 if (i
== last_slot
- 1)
5067 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5074 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
5076 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5078 struct r600_bytecode_alu alu
;
5079 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5080 int t1
= ctx
->temp_reg
;
5082 for (k
= 0; k
<= lasti
; k
++) {
5083 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
5086 for (i
= 0 ; i
< 4; i
++) {
5087 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5088 alu
.op
= ctx
->inst_info
->op
;
5089 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5090 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
5094 alu
.dst
.write
= (i
== k
);
5097 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5103 for (i
= 0 ; i
<= lasti
; i
++) {
5104 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5106 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5107 alu
.op
= ALU_OP1_MOV
;
5108 alu
.src
[0].sel
= t1
;
5109 alu
.src
[0].chan
= i
;
5110 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5114 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5123 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
5125 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5127 struct r600_bytecode_alu alu
;
5128 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5129 int t1
= ctx
->temp_reg
;
5131 /* t1 would get overwritten below if we actually tried to
5132 * multiply two pairs of doubles at a time. */
5133 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
5134 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
5136 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
5138 for (i
= 0; i
< 4; i
++) {
5139 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5140 alu
.op
= ctx
->inst_info
->op
;
5141 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5142 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
5149 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5154 for (i
= 0; i
<= lasti
; i
++) {
5155 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5157 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5158 alu
.op
= ALU_OP1_MOV
;
5159 alu
.src
[0].sel
= t1
;
5160 alu
.src
[0].chan
= i
;
5161 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5165 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5174 * Emit RECIP_64 + MUL_64 to implement division.
5176 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
5178 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5180 struct r600_bytecode_alu alu
;
5181 int t1
= ctx
->temp_reg
;
5184 /* Only support one double at a time. This is the same constraint as
5185 * in DMUL lowering. */
5186 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
5187 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
5189 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
5191 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
5195 for (int i
= 0; i
< 4; i
++) {
5196 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5197 alu
.op
= ALU_OP2_MUL_64
;
5199 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
5201 alu
.src
[1].sel
= t1
;
5202 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
5209 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5214 for (int i
= 0; i
< 2; i
++) {
5215 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5216 alu
.op
= ALU_OP1_MOV
;
5217 alu
.src
[0].sel
= t1
;
5218 alu
.src
[0].chan
= i
;
5219 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
5223 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5231 * r600 - trunc to -PI..PI range
5232 * r700 - normalize by dividing by 2PI
5235 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
5238 struct r600_bytecode_alu alu
;
5240 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5241 alu
.op
= ALU_OP3_MULADD
;
5245 alu
.dst
.sel
= ctx
->temp_reg
;
5248 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5250 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5251 alu
.src
[1].chan
= 0;
5252 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
5253 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
5254 alu
.src
[2].chan
= 0;
5256 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5260 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5261 alu
.op
= ALU_OP1_FRACT
;
5264 alu
.dst
.sel
= ctx
->temp_reg
;
5267 alu
.src
[0].sel
= ctx
->temp_reg
;
5268 alu
.src
[0].chan
= 0;
5270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5275 alu
.op
= ALU_OP3_MULADD
;
5279 alu
.dst
.sel
= ctx
->temp_reg
;
5282 alu
.src
[0].sel
= ctx
->temp_reg
;
5283 alu
.src
[0].chan
= 0;
5285 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5286 alu
.src
[1].chan
= 0;
5287 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
5288 alu
.src
[2].chan
= 0;
5290 if (ctx
->bc
->chip_class
== R600
) {
5291 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
5292 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
5294 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5295 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
5300 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5306 static int cayman_trig(struct r600_shader_ctx
*ctx
)
5308 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5309 struct r600_bytecode_alu alu
;
5310 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5313 r
= tgsi_setup_trig(ctx
);
5318 for (i
= 0; i
< last_slot
; i
++) {
5319 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5320 alu
.op
= ctx
->inst_info
->op
;
5323 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5324 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5326 alu
.src
[0].sel
= ctx
->temp_reg
;
5327 alu
.src
[0].chan
= 0;
5328 if (i
== last_slot
- 1)
5330 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5337 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
5339 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5340 struct r600_bytecode_alu alu
;
5342 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5344 r
= tgsi_setup_trig(ctx
);
5348 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5349 alu
.op
= ctx
->inst_info
->op
;
5351 alu
.dst
.sel
= ctx
->temp_reg
;
5354 alu
.src
[0].sel
= ctx
->temp_reg
;
5355 alu
.src
[0].chan
= 0;
5357 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5361 /* replicate result */
5362 for (i
= 0; i
< lasti
+ 1; i
++) {
5363 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5366 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5367 alu
.op
= ALU_OP1_MOV
;
5369 alu
.src
[0].sel
= ctx
->temp_reg
;
5370 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5373 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5380 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
5382 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5383 struct r600_bytecode_alu alu
;
5386 for (i
= 0; i
< 4; i
++) {
5387 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5388 alu
.op
= ctx
->inst_info
->op
;
5392 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5394 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
5395 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5398 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5403 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5408 /* kill must be last in ALU */
5409 ctx
->bc
->force_add_cf
= 1;
5410 ctx
->shader
->uses_kill
= TRUE
;
5414 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
5416 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5417 struct r600_bytecode_alu alu
;
5420 /* tmp.x = max(src.y, 0.0) */
5421 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5422 alu
.op
= ALU_OP2_MAX
;
5423 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
5424 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5425 alu
.src
[1].chan
= 1;
5427 alu
.dst
.sel
= ctx
->temp_reg
;
5432 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5436 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
5442 if (ctx
->bc
->chip_class
== CAYMAN
) {
5443 for (i
= 0; i
< 3; i
++) {
5444 /* tmp.z = log(tmp.x) */
5445 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5446 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5447 alu
.src
[0].sel
= ctx
->temp_reg
;
5448 alu
.src
[0].chan
= 0;
5449 alu
.dst
.sel
= ctx
->temp_reg
;
5457 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5462 /* tmp.z = log(tmp.x) */
5463 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5464 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5465 alu
.src
[0].sel
= ctx
->temp_reg
;
5466 alu
.src
[0].chan
= 0;
5467 alu
.dst
.sel
= ctx
->temp_reg
;
5471 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5476 chan
= alu
.dst
.chan
;
5479 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
5480 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5481 alu
.op
= ALU_OP3_MUL_LIT
;
5482 alu
.src
[0].sel
= sel
;
5483 alu
.src
[0].chan
= chan
;
5484 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
5485 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
5486 alu
.dst
.sel
= ctx
->temp_reg
;
5491 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5495 if (ctx
->bc
->chip_class
== CAYMAN
) {
5496 for (i
= 0; i
< 3; i
++) {
5497 /* dst.z = exp(tmp.x) */
5498 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5499 alu
.op
= ALU_OP1_EXP_IEEE
;
5500 alu
.src
[0].sel
= ctx
->temp_reg
;
5501 alu
.src
[0].chan
= 0;
5502 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5508 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5513 /* dst.z = exp(tmp.x) */
5514 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5515 alu
.op
= ALU_OP1_EXP_IEEE
;
5516 alu
.src
[0].sel
= ctx
->temp_reg
;
5517 alu
.src
[0].chan
= 0;
5518 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
5520 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5527 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5528 alu
.op
= ALU_OP1_MOV
;
5529 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
5530 alu
.src
[0].chan
= 0;
5531 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
5532 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
5533 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5537 /* dst.y = max(src.x, 0.0) */
5538 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5539 alu
.op
= ALU_OP2_MAX
;
5540 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5541 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5542 alu
.src
[1].chan
= 0;
5543 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
5544 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
5545 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5550 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5551 alu
.op
= ALU_OP1_MOV
;
5552 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5553 alu
.src
[0].chan
= 0;
5554 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
5555 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
5557 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5564 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
5566 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5567 struct r600_bytecode_alu alu
;
5570 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5572 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
5574 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5575 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5576 r600_bytecode_src_set_abs(&alu
.src
[i
]);
5578 alu
.dst
.sel
= ctx
->temp_reg
;
5581 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5584 /* replicate result */
5585 return tgsi_helper_tempx_replicate(ctx
);
5588 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
5590 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5591 struct r600_bytecode_alu alu
;
5594 for (i
= 0; i
< 4; i
++) {
5595 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5596 alu
.src
[0].sel
= ctx
->temp_reg
;
5597 alu
.op
= ALU_OP1_MOV
;
5599 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5600 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5603 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5610 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
5612 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5613 struct r600_bytecode_alu alu
;
5616 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5617 alu
.op
= ctx
->inst_info
->op
;
5618 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5619 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5621 alu
.dst
.sel
= ctx
->temp_reg
;
5624 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5627 /* replicate result */
5628 return tgsi_helper_tempx_replicate(ctx
);
5631 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5633 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5635 struct r600_bytecode_alu alu
;
5636 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5638 for (i
= 0; i
< 3; i
++) {
5639 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5640 alu
.op
= ALU_OP1_LOG_IEEE
;
5641 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5642 alu
.dst
.sel
= ctx
->temp_reg
;
5647 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5653 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5654 alu
.op
= ALU_OP2_MUL
;
5655 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5656 alu
.src
[1].sel
= ctx
->temp_reg
;
5657 alu
.dst
.sel
= ctx
->temp_reg
;
5660 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5664 for (i
= 0; i
< last_slot
; i
++) {
5665 /* POW(a,b) = EXP2(b * LOG2(a))*/
5666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5667 alu
.op
= ALU_OP1_EXP_IEEE
;
5668 alu
.src
[0].sel
= ctx
->temp_reg
;
5670 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5671 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5672 if (i
== last_slot
- 1)
5674 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5681 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5683 struct r600_bytecode_alu alu
;
5687 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5688 alu
.op
= ALU_OP1_LOG_IEEE
;
5689 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5690 alu
.dst
.sel
= ctx
->temp_reg
;
5693 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5697 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5698 alu
.op
= ALU_OP2_MUL
;
5699 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5700 alu
.src
[1].sel
= ctx
->temp_reg
;
5701 alu
.dst
.sel
= ctx
->temp_reg
;
5704 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5707 /* POW(a,b) = EXP2(b * LOG2(a))*/
5708 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5709 alu
.op
= ALU_OP1_EXP_IEEE
;
5710 alu
.src
[0].sel
= ctx
->temp_reg
;
5711 alu
.dst
.sel
= ctx
->temp_reg
;
5714 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5717 return tgsi_helper_tempx_replicate(ctx
);
5720 static int emit_mul_int_op(struct r600_bytecode
*bc
,
5721 struct r600_bytecode_alu
*alu_src
)
5723 struct r600_bytecode_alu alu
;
5726 if (bc
->chip_class
== CAYMAN
) {
5727 for (i
= 0; i
< 4; i
++) {
5729 alu
.dst
.write
= (i
== alu_src
->dst
.chan
);
5730 alu
.last
= (i
== 3);
5732 r
= r600_bytecode_add_alu(bc
, &alu
);
5738 r
= r600_bytecode_add_alu(bc
, &alu
);
5745 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5747 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5748 struct r600_bytecode_alu alu
;
5750 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5751 int lasti
= tgsi_last_instruction(write_mask
);
5752 int tmp0
= ctx
->temp_reg
;
5753 int tmp1
= r600_get_temp(ctx
);
5754 int tmp2
= r600_get_temp(ctx
);
5755 int tmp3
= r600_get_temp(ctx
);
5758 /* Use additional temp if dst register and src register are the same */
5759 if (inst
->Src
[0].Register
.Index
== inst
->Dst
[0].Register
.Index
||
5760 inst
->Src
[1].Register
.Index
== inst
->Dst
[0].Register
.Index
) {
5761 tmp4
= r600_get_temp(ctx
);
5766 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5768 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5769 * 2. tmp0.z = lo (tmp0.x * src2)
5770 * 3. tmp0.w = -tmp0.z
5771 * 4. tmp0.y = hi (tmp0.x * src2)
5772 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5773 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5774 * 7. tmp1.x = tmp0.x - tmp0.w
5775 * 8. tmp1.y = tmp0.x + tmp0.w
5776 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5777 * 10. tmp0.z = hi(tmp0.x * src1) = q
5778 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5780 * 12. tmp0.w = src1 - tmp0.y = r
5781 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5782 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5786 * 15. tmp1.z = tmp0.z + 1 = q + 1
5787 * 16. tmp1.w = tmp0.z - 1 = q - 1
5791 * 15. tmp1.z = tmp0.w - src2 = r - src2
5792 * 16. tmp1.w = tmp0.w + src2 = r + src2
5796 * 17. tmp1.x = tmp1.x & tmp1.y
5798 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5799 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5801 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5802 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5806 * Same as unsigned, using abs values of the operands,
5807 * and fixing the sign of the result in the end.
5810 for (i
= 0; i
< 4; i
++) {
5811 if (!(write_mask
& (1<<i
)))
5816 /* tmp2.x = -src0 */
5817 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5818 alu
.op
= ALU_OP2_SUB_INT
;
5824 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5826 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5829 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5832 /* tmp2.y = -src1 */
5833 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5834 alu
.op
= ALU_OP2_SUB_INT
;
5840 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5842 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5845 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5848 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5849 /* it will be a sign of the quotient */
5852 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5853 alu
.op
= ALU_OP2_XOR_INT
;
5859 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5860 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5863 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5867 /* tmp2.x = |src0| */
5868 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5869 alu
.op
= ALU_OP3_CNDGE_INT
;
5876 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5877 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5878 alu
.src
[2].sel
= tmp2
;
5879 alu
.src
[2].chan
= 0;
5882 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5885 /* tmp2.y = |src1| */
5886 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5887 alu
.op
= ALU_OP3_CNDGE_INT
;
5894 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5895 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5896 alu
.src
[2].sel
= tmp2
;
5897 alu
.src
[2].chan
= 1;
5900 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5905 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5906 if (ctx
->bc
->chip_class
== CAYMAN
) {
5907 /* tmp3.x = u2f(src2) */
5908 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5909 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5916 alu
.src
[0].sel
= tmp2
;
5917 alu
.src
[0].chan
= 1;
5919 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5923 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5926 /* tmp0.x = recip(tmp3.x) */
5927 for (j
= 0 ; j
< 3; j
++) {
5928 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5929 alu
.op
= ALU_OP1_RECIP_IEEE
;
5933 alu
.dst
.write
= (j
== 0);
5935 alu
.src
[0].sel
= tmp3
;
5936 alu
.src
[0].chan
= 0;
5940 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5945 alu
.op
= ALU_OP2_MUL
;
5947 alu
.src
[0].sel
= tmp0
;
5948 alu
.src
[0].chan
= 0;
5950 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5951 alu
.src
[1].value
= 0x4f800000;
5956 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5960 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5961 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5967 alu
.src
[0].sel
= tmp3
;
5968 alu
.src
[0].chan
= 0;
5971 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5975 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5976 alu
.op
= ALU_OP1_RECIP_UINT
;
5983 alu
.src
[0].sel
= tmp2
;
5984 alu
.src
[0].chan
= 1;
5986 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5990 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5994 /* 2. tmp0.z = lo (tmp0.x * src2) */
5995 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5996 alu
.op
= ALU_OP2_MULLO_UINT
;
6002 alu
.src
[0].sel
= tmp0
;
6003 alu
.src
[0].chan
= 0;
6005 alu
.src
[1].sel
= tmp2
;
6006 alu
.src
[1].chan
= 1;
6008 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
6011 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
6014 /* 3. tmp0.w = -tmp0.z */
6015 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6016 alu
.op
= ALU_OP2_SUB_INT
;
6022 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6023 alu
.src
[1].sel
= tmp0
;
6024 alu
.src
[1].chan
= 2;
6027 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6030 /* 4. tmp0.y = hi (tmp0.x * src2) */
6031 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6032 alu
.op
= ALU_OP2_MULHI_UINT
;
6038 alu
.src
[0].sel
= tmp0
;
6039 alu
.src
[0].chan
= 0;
6042 alu
.src
[1].sel
= tmp2
;
6043 alu
.src
[1].chan
= 1;
6045 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
6048 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
6051 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
6052 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6053 alu
.op
= ALU_OP3_CNDE_INT
;
6060 alu
.src
[0].sel
= tmp0
;
6061 alu
.src
[0].chan
= 1;
6062 alu
.src
[1].sel
= tmp0
;
6063 alu
.src
[1].chan
= 3;
6064 alu
.src
[2].sel
= tmp0
;
6065 alu
.src
[2].chan
= 2;
6068 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6071 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
6072 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6073 alu
.op
= ALU_OP2_MULHI_UINT
;
6079 alu
.src
[0].sel
= tmp0
;
6080 alu
.src
[0].chan
= 2;
6082 alu
.src
[1].sel
= tmp0
;
6083 alu
.src
[1].chan
= 0;
6085 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
6088 /* 7. tmp1.x = tmp0.x - tmp0.w */
6089 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6090 alu
.op
= ALU_OP2_SUB_INT
;
6096 alu
.src
[0].sel
= tmp0
;
6097 alu
.src
[0].chan
= 0;
6098 alu
.src
[1].sel
= tmp0
;
6099 alu
.src
[1].chan
= 3;
6102 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6105 /* 8. tmp1.y = tmp0.x + tmp0.w */
6106 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6107 alu
.op
= ALU_OP2_ADD_INT
;
6113 alu
.src
[0].sel
= tmp0
;
6114 alu
.src
[0].chan
= 0;
6115 alu
.src
[1].sel
= tmp0
;
6116 alu
.src
[1].chan
= 3;
6119 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6122 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
6123 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6124 alu
.op
= ALU_OP3_CNDE_INT
;
6131 alu
.src
[0].sel
= tmp0
;
6132 alu
.src
[0].chan
= 1;
6133 alu
.src
[1].sel
= tmp1
;
6134 alu
.src
[1].chan
= 1;
6135 alu
.src
[2].sel
= tmp1
;
6136 alu
.src
[2].chan
= 0;
6139 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6142 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
6143 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6144 alu
.op
= ALU_OP2_MULHI_UINT
;
6150 alu
.src
[0].sel
= tmp0
;
6151 alu
.src
[0].chan
= 0;
6154 alu
.src
[1].sel
= tmp2
;
6155 alu
.src
[1].chan
= 0;
6157 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6160 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
6163 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
6164 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6165 alu
.op
= ALU_OP2_MULLO_UINT
;
6172 alu
.src
[0].sel
= tmp2
;
6173 alu
.src
[0].chan
= 1;
6175 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6178 alu
.src
[1].sel
= tmp0
;
6179 alu
.src
[1].chan
= 2;
6181 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
6184 /* 12. tmp0.w = src1 - tmp0.y = r */
6185 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6186 alu
.op
= ALU_OP2_SUB_INT
;
6193 alu
.src
[0].sel
= tmp2
;
6194 alu
.src
[0].chan
= 0;
6196 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6199 alu
.src
[1].sel
= tmp0
;
6200 alu
.src
[1].chan
= 1;
6203 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6206 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
6207 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6208 alu
.op
= ALU_OP2_SETGE_UINT
;
6214 alu
.src
[0].sel
= tmp0
;
6215 alu
.src
[0].chan
= 3;
6217 alu
.src
[1].sel
= tmp2
;
6218 alu
.src
[1].chan
= 1;
6220 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
6224 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6227 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
6228 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6229 alu
.op
= ALU_OP2_SETGE_UINT
;
6236 alu
.src
[0].sel
= tmp2
;
6237 alu
.src
[0].chan
= 0;
6239 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6242 alu
.src
[1].sel
= tmp0
;
6243 alu
.src
[1].chan
= 1;
6246 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6249 if (mod
) { /* UMOD */
6251 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
6252 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6253 alu
.op
= ALU_OP2_SUB_INT
;
6259 alu
.src
[0].sel
= tmp0
;
6260 alu
.src
[0].chan
= 3;
6263 alu
.src
[1].sel
= tmp2
;
6264 alu
.src
[1].chan
= 1;
6266 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
6270 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6273 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
6274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6275 alu
.op
= ALU_OP2_ADD_INT
;
6281 alu
.src
[0].sel
= tmp0
;
6282 alu
.src
[0].chan
= 3;
6284 alu
.src
[1].sel
= tmp2
;
6285 alu
.src
[1].chan
= 1;
6287 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
6291 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6296 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
6297 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6298 alu
.op
= ALU_OP2_ADD_INT
;
6304 alu
.src
[0].sel
= tmp0
;
6305 alu
.src
[0].chan
= 2;
6306 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6309 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6312 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
6313 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6314 alu
.op
= ALU_OP2_ADD_INT
;
6320 alu
.src
[0].sel
= tmp0
;
6321 alu
.src
[0].chan
= 2;
6322 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
6325 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6330 /* 17. tmp1.x = tmp1.x & tmp1.y */
6331 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6332 alu
.op
= ALU_OP2_AND_INT
;
6338 alu
.src
[0].sel
= tmp1
;
6339 alu
.src
[0].chan
= 0;
6340 alu
.src
[1].sel
= tmp1
;
6341 alu
.src
[1].chan
= 1;
6344 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6347 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
6348 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
6349 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6350 alu
.op
= ALU_OP3_CNDE_INT
;
6357 alu
.src
[0].sel
= tmp1
;
6358 alu
.src
[0].chan
= 0;
6359 alu
.src
[1].sel
= tmp0
;
6360 alu
.src
[1].chan
= mod
? 3 : 2;
6361 alu
.src
[2].sel
= tmp1
;
6362 alu
.src
[2].chan
= 2;
6365 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6368 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
6369 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6370 alu
.op
= ALU_OP3_CNDE_INT
;
6383 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6387 alu
.src
[0].sel
= tmp1
;
6388 alu
.src
[0].chan
= 1;
6389 alu
.src
[1].sel
= tmp1
;
6390 alu
.src
[1].chan
= 3;
6391 alu
.src
[2].sel
= tmp0
;
6392 alu
.src
[2].chan
= 2;
6395 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6400 /* fix the sign of the result */
6404 /* tmp0.x = -tmp0.z */
6405 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6406 alu
.op
= ALU_OP2_SUB_INT
;
6412 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6413 alu
.src
[1].sel
= tmp0
;
6414 alu
.src
[1].chan
= 2;
6417 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6420 /* sign of the remainder is the same as the sign of src0 */
6421 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
6422 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6423 alu
.op
= ALU_OP3_CNDGE_INT
;
6431 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6434 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6435 alu
.src
[1].sel
= tmp0
;
6436 alu
.src
[1].chan
= 2;
6437 alu
.src
[2].sel
= tmp0
;
6438 alu
.src
[2].chan
= 0;
6441 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6446 /* tmp0.x = -tmp0.z */
6447 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6448 alu
.op
= ALU_OP2_SUB_INT
;
6454 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6455 alu
.src
[1].sel
= tmp0
;
6456 alu
.src
[1].chan
= 2;
6459 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6462 /* fix the quotient sign (same as the sign of src0*src1) */
6463 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
6464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6465 alu
.op
= ALU_OP3_CNDGE_INT
;
6473 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6476 alu
.src
[0].sel
= tmp2
;
6477 alu
.src
[0].chan
= 2;
6478 alu
.src
[1].sel
= tmp0
;
6479 alu
.src
[1].chan
= 2;
6480 alu
.src
[2].sel
= tmp0
;
6481 alu
.src
[2].chan
= 0;
6484 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6491 for (i
= 0; i
<= lasti
; ++i
) {
6492 if (!(write_mask
& (1<<i
)))
6495 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6496 alu
.op
= ALU_OP1_MOV
;
6497 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6498 alu
.src
[0].sel
= tmp4
;
6499 alu
.src
[0].chan
= i
;
6503 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6511 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
6513 return tgsi_divmod(ctx
, 0, 0);
6516 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
6518 return tgsi_divmod(ctx
, 1, 0);
6521 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
6523 return tgsi_divmod(ctx
, 0, 1);
6526 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
6528 return tgsi_divmod(ctx
, 1, 1);
6532 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
6534 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6535 struct r600_bytecode_alu alu
;
6537 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6538 int last_inst
= tgsi_last_instruction(write_mask
);
6540 for (i
= 0; i
< 4; i
++) {
6541 if (!(write_mask
& (1<<i
)))
6544 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6545 alu
.op
= ALU_OP1_TRUNC
;
6547 alu
.dst
.sel
= ctx
->temp_reg
;
6551 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6554 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6559 for (i
= 0; i
< 4; i
++) {
6560 if (!(write_mask
& (1<<i
)))
6563 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6564 alu
.op
= ctx
->inst_info
->op
;
6566 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6568 alu
.src
[0].sel
= ctx
->temp_reg
;
6569 alu
.src
[0].chan
= i
;
6571 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
6573 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6581 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6583 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6584 struct r600_bytecode_alu alu
;
6586 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6587 int last_inst
= tgsi_last_instruction(write_mask
);
6590 for (i
= 0; i
< 4; i
++) {
6591 if (!(write_mask
& (1<<i
)))
6594 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6595 alu
.op
= ALU_OP2_SUB_INT
;
6597 alu
.dst
.sel
= ctx
->temp_reg
;
6601 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6602 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6606 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6611 /* dst = (src >= 0 ? src : tmp) */
6612 for (i
= 0; i
< 4; i
++) {
6613 if (!(write_mask
& (1<<i
)))
6616 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6617 alu
.op
= ALU_OP3_CNDGE_INT
;
6621 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6623 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6624 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6625 alu
.src
[2].sel
= ctx
->temp_reg
;
6626 alu
.src
[2].chan
= i
;
6630 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6637 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6639 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6640 struct r600_bytecode_alu alu
;
6642 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6643 int last_inst
= tgsi_last_instruction(write_mask
);
6645 /* tmp = (src >= 0 ? src : -1) */
6646 for (i
= 0; i
< 4; i
++) {
6647 if (!(write_mask
& (1<<i
)))
6650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6651 alu
.op
= ALU_OP3_CNDGE_INT
;
6654 alu
.dst
.sel
= ctx
->temp_reg
;
6658 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6659 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6660 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6664 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6669 /* dst = (tmp > 0 ? 1 : tmp) */
6670 for (i
= 0; i
< 4; i
++) {
6671 if (!(write_mask
& (1<<i
)))
6674 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6675 alu
.op
= ALU_OP3_CNDGT_INT
;
6679 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6681 alu
.src
[0].sel
= ctx
->temp_reg
;
6682 alu
.src
[0].chan
= i
;
6684 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6686 alu
.src
[2].sel
= ctx
->temp_reg
;
6687 alu
.src
[2].chan
= i
;
6691 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6700 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6702 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6703 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6704 int last_inst
= tgsi_last_instruction(write_mask
);
6705 struct r600_bytecode_alu alu
;
6708 /* tmp = (src > 0 ? 1 : src) */
6709 for (i
= 0; i
<= last_inst
; i
++) {
6710 if (!(write_mask
& (1 << i
)))
6712 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6713 alu
.op
= ALU_OP3_CNDGT
;
6716 alu
.dst
.sel
= ctx
->temp_reg
;
6719 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6720 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6721 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6725 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6730 /* dst = (-tmp > 0 ? -1 : tmp) */
6731 for (i
= 0; i
<= last_inst
; i
++) {
6732 if (!(write_mask
& (1 << i
)))
6734 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6735 alu
.op
= ALU_OP3_CNDGT
;
6737 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6739 alu
.src
[0].sel
= ctx
->temp_reg
;
6740 alu
.src
[0].chan
= i
;
6743 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6746 alu
.src
[2].sel
= ctx
->temp_reg
;
6747 alu
.src
[2].chan
= i
;
6751 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6758 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6760 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6761 struct r600_bytecode_alu alu
;
6764 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6765 int last_inst
= tgsi_last_instruction(write_mask
);
6767 t1
= r600_get_temp(ctx
);
6769 for (i
= 0; i
< 4; i
++) {
6770 if (!(write_mask
& (1<<i
)))
6773 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6774 alu
.op
= ALU_OP2_SETGE_INT
;
6775 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6776 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6777 alu
.src
[1].value
= 32;
6778 alu
.dst
.sel
= ctx
->temp_reg
;
6781 alu
.last
= i
== last_inst
;
6782 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6787 for (i
= 0; i
< 4; i
++) {
6788 if (!(write_mask
& (1<<i
)))
6791 /* create mask tmp */
6792 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6793 alu
.op
= ALU_OP2_BFM_INT
;
6797 alu
.last
= i
== last_inst
;
6799 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6800 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6802 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6807 t2
= r600_get_temp(ctx
);
6809 for (i
= 0; i
< 4; i
++) {
6810 if (!(write_mask
& (1<<i
)))
6813 /* shift insert left */
6814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6815 alu
.op
= ALU_OP2_LSHL_INT
;
6819 alu
.last
= i
== last_inst
;
6821 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6822 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6824 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6829 for (i
= 0; i
< 4; i
++) {
6830 if (!(write_mask
& (1<<i
)))
6833 /* actual bitfield insert */
6834 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6835 alu
.op
= ALU_OP3_BFI_INT
;
6837 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6840 alu
.last
= i
== last_inst
;
6842 alu
.src
[0].sel
= t1
;
6843 alu
.src
[0].chan
= i
;
6844 alu
.src
[1].sel
= t2
;
6845 alu
.src
[1].chan
= i
;
6846 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6848 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6853 for (i
= 0; i
< 4; i
++) {
6854 if (!(write_mask
& (1<<i
)))
6856 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6857 alu
.op
= ALU_OP3_CNDE_INT
;
6859 alu
.src
[0].sel
= ctx
->temp_reg
;
6860 alu
.src
[0].chan
= i
;
6861 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6863 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6865 alu
.src
[1].sel
= alu
.dst
.sel
;
6866 alu
.src
[1].chan
= i
;
6868 alu
.last
= i
== last_inst
;
6869 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6876 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6878 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6879 struct r600_bytecode_alu alu
;
6882 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6883 int last_inst
= tgsi_last_instruction(write_mask
);
6885 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6886 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6890 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6891 for (i
= 0; i
< 4; i
++) {
6892 if (!(write_mask
& (1<<i
)))
6895 /* t1 = FFBH_INT / FFBH_UINT */
6896 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6897 alu
.op
= ctx
->inst_info
->op
;
6901 alu
.last
= i
== last_inst
;
6903 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6905 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6910 t2
= r600_get_temp(ctx
);
6912 for (i
= 0; i
< 4; i
++) {
6913 if (!(write_mask
& (1<<i
)))
6917 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6918 alu
.op
= ALU_OP2_SUB_INT
;
6922 alu
.last
= i
== last_inst
;
6924 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6925 alu
.src
[0].value
= 31;
6926 alu
.src
[1].sel
= t1
;
6927 alu
.src
[1].chan
= i
;
6929 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6934 for (i
= 0; i
< 4; i
++) {
6935 if (!(write_mask
& (1<<i
)))
6938 /* result = t1 >= 0 ? t2 : t1 */
6939 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6940 alu
.op
= ALU_OP3_CNDGE_INT
;
6942 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6945 alu
.last
= i
== last_inst
;
6947 alu
.src
[0].sel
= t1
;
6948 alu
.src
[0].chan
= i
;
6949 alu
.src
[1].sel
= t2
;
6950 alu
.src
[1].chan
= i
;
6951 alu
.src
[2].sel
= t1
;
6952 alu
.src
[2].chan
= i
;
6954 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6962 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6964 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6965 struct r600_bytecode_alu alu
;
6966 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6968 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6970 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6972 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6973 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6974 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6975 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6978 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6981 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6984 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6985 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6987 /* NOTE: currently offset is not perspective correct */
6988 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6989 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6990 int sample_gpr
= -1;
6991 int gradientsH
, gradientsV
;
6992 struct r600_bytecode_tex tex
;
6994 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6995 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6998 gradientsH
= r600_get_temp(ctx
);
6999 gradientsV
= r600_get_temp(ctx
);
7000 for (i
= 0; i
< 2; i
++) {
7001 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7002 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
7003 tex
.src_gpr
= interp_gpr
;
7004 tex
.src_sel_x
= interp_base_chan
+ 0;
7005 tex
.src_sel_y
= interp_base_chan
+ 1;
7008 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
7013 tex
.inst_mod
= 1; // Use per pixel gradient calculation
7015 tex
.resource_id
= tex
.sampler_id
;
7016 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7021 for (i
= 0; i
< 2; i
++) {
7022 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7023 alu
.op
= ALU_OP3_MULADD
;
7025 alu
.src
[0].sel
= gradientsH
;
7026 alu
.src
[0].chan
= i
;
7027 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
7028 alu
.src
[1].sel
= sample_gpr
;
7029 alu
.src
[1].chan
= 2;
7032 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
7034 alu
.src
[2].sel
= interp_gpr
;
7035 alu
.src
[2].chan
= interp_base_chan
+ i
;
7036 alu
.dst
.sel
= ctx
->temp_reg
;
7040 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7045 for (i
= 0; i
< 2; i
++) {
7046 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7047 alu
.op
= ALU_OP3_MULADD
;
7049 alu
.src
[0].sel
= gradientsV
;
7050 alu
.src
[0].chan
= i
;
7051 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
7052 alu
.src
[1].sel
= sample_gpr
;
7053 alu
.src
[1].chan
= 3;
7056 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
7058 alu
.src
[2].sel
= ctx
->temp_reg
;
7059 alu
.src
[2].chan
= i
;
7060 alu
.dst
.sel
= ctx
->temp_reg
;
7064 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7070 tmp
= r600_get_temp(ctx
);
7071 for (i
= 0; i
< 8; i
++) {
7072 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7073 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
7076 if ((i
> 1 && i
< 6)) {
7082 alu
.dst
.chan
= i
% 4;
7084 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
7085 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
7086 alu
.src
[0].sel
= ctx
->temp_reg
;
7087 alu
.src
[0].chan
= 1 - (i
% 2);
7089 alu
.src
[0].sel
= interp_gpr
;
7090 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
7092 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
7093 alu
.src
[1].chan
= 0;
7095 alu
.last
= i
% 4 == 3;
7096 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
7098 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7103 // INTERP can't swizzle dst
7104 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7105 for (i
= 0; i
<= lasti
; i
++) {
7106 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7109 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7110 alu
.op
= ALU_OP1_MOV
;
7111 alu
.src
[0].sel
= tmp
;
7112 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
7113 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7115 alu
.last
= i
== lasti
;
7116 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7125 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
7127 struct r600_bytecode_alu alu
;
7130 for (i
= 0; i
< 4; i
++) {
7131 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7132 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
7133 alu
.op
= ALU_OP0_NOP
;
7136 alu
.op
= ALU_OP1_MOV
;
7137 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7138 alu
.src
[0].sel
= ctx
->temp_reg
;
7139 alu
.src
[0].chan
= i
;
7144 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7151 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
7153 struct r600_bytecode_alu_src
*bc_src
,
7154 const struct r600_shader_src
*shader_src
)
7156 struct r600_bytecode_alu alu
;
7158 int lasti
= tgsi_last_instruction(writemask
);
7161 r600_bytecode_src(&bc_src
[0], shader_src
, 0);
7162 r600_bytecode_src(&bc_src
[1], shader_src
, 1);
7163 r600_bytecode_src(&bc_src
[2], shader_src
, 2);
7164 r600_bytecode_src(&bc_src
[3], shader_src
, 3);
7167 temp_reg
= r600_get_temp(ctx
);
7169 for (i
= 0; i
< lasti
+ 1; i
++) {
7170 if (!(writemask
& (1 << i
)))
7172 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7173 alu
.op
= ALU_OP1_MOV
;
7174 alu
.dst
.sel
= temp_reg
;
7177 alu
.src
[0] = bc_src
[i
];
7181 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7184 memset(&bc_src
[i
], 0, sizeof(*bc_src
));
7185 bc_src
[i
].sel
= temp_reg
;
7192 static int tgsi_op3_dst(struct r600_shader_ctx
*ctx
, int dst
)
7194 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7195 struct r600_bytecode_alu alu
;
7196 struct r600_bytecode_alu_src srcs
[4][4];
7198 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7199 unsigned op
= ctx
->inst_info
->op
;
7201 if (op
== ALU_OP3_MULADD_IEEE
&&
7202 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
7203 op
= ALU_OP3_MULADD
;
7205 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
7206 r
= tgsi_make_src_for_op3(ctx
, inst
->Dst
[0].Register
.WriteMask
,
7207 srcs
[j
], &ctx
->src
[j
]);
7212 for (i
= 0; i
< lasti
+ 1; i
++) {
7213 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7218 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
7219 alu
.src
[j
] = srcs
[j
][i
];
7223 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7233 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7240 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
7242 return tgsi_op3_dst(ctx
, -1);
7245 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
7247 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7248 struct r600_bytecode_alu alu
;
7250 unsigned op
= ctx
->inst_info
->op
;
7251 if (op
== ALU_OP2_DOT4_IEEE
&&
7252 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
7255 for (i
= 0; i
< 4; i
++) {
7256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7258 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
7259 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
7262 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7264 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
7265 /* handle some special cases */
7266 switch (inst
->Instruction
.Opcode
) {
7267 case TGSI_OPCODE_DP2
:
7269 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
7270 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
7273 case TGSI_OPCODE_DP3
:
7275 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
7276 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
7285 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7292 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
7295 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7296 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
7297 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
7298 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
7299 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
7300 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
7303 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
7306 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7307 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
7310 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
7312 struct r600_bytecode_vtx vtx
;
7313 struct r600_bytecode_alu alu
;
7314 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7316 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
7317 int sampler_index_mode
= inst
->Src
[1].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7319 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
7320 if (src_requires_loading
) {
7321 for (i
= 0; i
< 4; i
++) {
7322 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7323 alu
.op
= ALU_OP1_MOV
;
7324 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7325 alu
.dst
.sel
= ctx
->temp_reg
;
7330 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7334 src_gpr
= ctx
->temp_reg
;
7337 memset(&vtx
, 0, sizeof(vtx
));
7338 vtx
.op
= FETCH_OP_VFETCH
;
7339 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
7340 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
7341 vtx
.src_gpr
= src_gpr
;
7342 vtx
.mega_fetch_count
= 16;
7343 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7344 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
7345 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
7346 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
7347 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
7348 vtx
.use_const_fields
= 1;
7349 vtx
.buffer_index_mode
= sampler_index_mode
;
7351 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
7354 if (ctx
->bc
->chip_class
>= EVERGREEN
)
7357 for (i
= 0; i
< 4; i
++) {
7358 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7359 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7362 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7363 alu
.op
= ALU_OP2_AND_INT
;
7366 alu
.dst
.sel
= vtx
.dst_gpr
;
7369 alu
.src
[0].sel
= vtx
.dst_gpr
;
7370 alu
.src
[0].chan
= i
;
7372 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7373 alu
.src
[1].sel
+= (id
* 2);
7374 alu
.src
[1].chan
= i
% 4;
7375 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7379 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7384 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
7385 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7386 alu
.op
= ALU_OP2_OR_INT
;
7389 alu
.dst
.sel
= vtx
.dst_gpr
;
7392 alu
.src
[0].sel
= vtx
.dst_gpr
;
7393 alu
.src
[0].chan
= 3;
7395 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
7396 alu
.src
[1].chan
= 0;
7397 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7400 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7407 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
, int reg_idx
, int offset
, int eg_buffer_base
)
7409 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7411 int id
= tgsi_tex_get_src_gpr(ctx
, reg_idx
) + offset
;
7412 int sampler_index_mode
= inst
->Src
[reg_idx
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7414 if (ctx
->bc
->chip_class
< EVERGREEN
) {
7415 struct r600_bytecode_alu alu
;
7416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7417 alu
.op
= ALU_OP1_MOV
;
7418 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7419 /* r600 we have them at channel 2 of the second dword */
7420 alu
.src
[0].sel
+= (id
* 2) + 1;
7421 alu
.src
[0].chan
= 1;
7422 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7423 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
7425 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7430 struct r600_bytecode_vtx vtx
;
7431 memset(&vtx
, 0, sizeof(vtx
));
7432 vtx
.op
= FETCH_OP_GET_BUFFER_RESINFO
;
7433 vtx
.buffer_id
= id
+ eg_buffer_base
;
7434 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
7436 vtx
.mega_fetch_count
= 16; /* no idea here really... */
7437 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7438 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
7439 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 4 : 7; /* SEL_Y */
7440 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 4 : 7; /* SEL_Z */
7441 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 4 : 7; /* SEL_W */
7442 vtx
.data_format
= FMT_32_32_32_32
;
7443 vtx
.buffer_index_mode
= sampler_index_mode
;
7445 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
7452 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
7454 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7455 struct r600_bytecode_tex tex
;
7456 struct r600_bytecode_tex grad_offs
[3];
7457 struct r600_bytecode_alu alu
;
7459 int r
, i
, j
, n_grad_offs
= 0;
7461 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
7462 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7463 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
7464 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
7466 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
7467 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7468 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
7470 /* Texture fetch instructions can only use gprs as source.
7471 * Also they cannot negate the source or take the absolute value */
7472 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
7473 tgsi_tex_src_requires_loading(ctx
, 0)) ||
7474 read_compressed_msaa
|| txf_add_offsets
;
7476 boolean src_loaded
= FALSE
;
7477 unsigned sampler_src_reg
= 1;
7478 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
7479 boolean has_txq_cube_array_z
= false;
7480 unsigned sampler_index_mode
;
7481 int array_index_offset_channel
= -1;
7483 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
7484 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7485 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
7486 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
7487 ctx
->shader
->has_txq_cube_array_z_comp
= true;
7488 has_txq_cube_array_z
= true;
7491 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
7492 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7493 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
7494 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
7495 sampler_src_reg
= 2;
7497 /* TGSI moves the sampler to src reg 3 for TXD */
7498 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
7499 sampler_src_reg
= 3;
7501 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7503 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
7505 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
7506 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
7507 if (ctx
->bc
->chip_class
< EVERGREEN
)
7508 ctx
->shader
->uses_tex_buffers
= true;
7509 return r600_do_buffer_txq(ctx
, 1, 0, R600_MAX_CONST_BUFFERS
);
7511 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
7512 if (ctx
->bc
->chip_class
< EVERGREEN
)
7513 ctx
->shader
->uses_tex_buffers
= true;
7514 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
7518 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
7520 /* Add perspective divide */
7521 if (ctx
->bc
->chip_class
== CAYMAN
) {
7523 for (i
= 0; i
< 3; i
++) {
7524 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7525 alu
.op
= ALU_OP1_RECIP_IEEE
;
7526 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7528 alu
.dst
.sel
= ctx
->temp_reg
;
7534 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7541 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7542 alu
.op
= ALU_OP1_RECIP_IEEE
;
7543 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7545 alu
.dst
.sel
= ctx
->temp_reg
;
7546 alu
.dst
.chan
= out_chan
;
7549 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7554 for (i
= 0; i
< 3; i
++) {
7555 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7556 alu
.op
= ALU_OP2_MUL
;
7557 alu
.src
[0].sel
= ctx
->temp_reg
;
7558 alu
.src
[0].chan
= out_chan
;
7559 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7560 alu
.dst
.sel
= ctx
->temp_reg
;
7563 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7568 alu
.op
= ALU_OP1_MOV
;
7569 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7570 alu
.src
[0].chan
= 0;
7571 alu
.dst
.sel
= ctx
->temp_reg
;
7575 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7579 src_gpr
= ctx
->temp_reg
;
7583 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7584 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7585 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7586 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7587 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
7589 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
7590 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
7592 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
7593 for (i
= 0; i
< 4; i
++) {
7594 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7595 alu
.op
= ALU_OP2_CUBE
;
7596 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7597 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
7598 alu
.dst
.sel
= ctx
->temp_reg
;
7603 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7608 /* tmp1.z = RCP_e(|tmp1.z|) */
7609 if (ctx
->bc
->chip_class
== CAYMAN
) {
7610 for (i
= 0; i
< 3; i
++) {
7611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7612 alu
.op
= ALU_OP1_RECIP_IEEE
;
7613 alu
.src
[0].sel
= ctx
->temp_reg
;
7614 alu
.src
[0].chan
= 2;
7616 alu
.dst
.sel
= ctx
->temp_reg
;
7622 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7627 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7628 alu
.op
= ALU_OP1_RECIP_IEEE
;
7629 alu
.src
[0].sel
= ctx
->temp_reg
;
7630 alu
.src
[0].chan
= 2;
7632 alu
.dst
.sel
= ctx
->temp_reg
;
7636 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7641 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7642 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7643 * muladd has no writemask, have to use another temp
7645 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7646 alu
.op
= ALU_OP3_MULADD
;
7649 alu
.src
[0].sel
= ctx
->temp_reg
;
7650 alu
.src
[0].chan
= 0;
7651 alu
.src
[1].sel
= ctx
->temp_reg
;
7652 alu
.src
[1].chan
= 2;
7654 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7655 alu
.src
[2].chan
= 0;
7656 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7658 alu
.dst
.sel
= ctx
->temp_reg
;
7662 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7667 alu
.op
= ALU_OP3_MULADD
;
7670 alu
.src
[0].sel
= ctx
->temp_reg
;
7671 alu
.src
[0].chan
= 1;
7672 alu
.src
[1].sel
= ctx
->temp_reg
;
7673 alu
.src
[1].chan
= 2;
7675 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7676 alu
.src
[2].chan
= 0;
7677 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7679 alu
.dst
.sel
= ctx
->temp_reg
;
7684 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7687 /* write initial compare value into Z component
7688 - W src 0 for shadow cube
7689 - X src 1 for shadow cube array */
7690 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7691 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7692 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7693 alu
.op
= ALU_OP1_MOV
;
7694 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7695 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7697 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7698 alu
.dst
.sel
= ctx
->temp_reg
;
7702 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7707 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7708 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7709 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7710 int mytmp
= r600_get_temp(ctx
);
7711 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7712 alu
.op
= ALU_OP1_MOV
;
7713 alu
.src
[0].sel
= ctx
->temp_reg
;
7714 alu
.src
[0].chan
= 3;
7715 alu
.dst
.sel
= mytmp
;
7719 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7723 /* Evaluate the array index according to floor(idx + 0.5). This
7724 * needs to be done before merging the face select value, because
7725 * otherwise the fractional part of the array index will interfere
7726 * with the face select value */
7727 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7728 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7729 alu
.op
= ALU_OP1_RNDNE
;
7730 alu
.dst
.sel
= ctx
->temp_reg
;
7734 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7738 /* Because the array slice index and the cube face index are merged
7739 * into one value we have to make sure the array slice index is >= 0,
7740 * otherwise the face selection will fail */
7741 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7742 alu
.op
= ALU_OP2_MAX
;
7743 alu
.src
[0].sel
= ctx
->temp_reg
;
7744 alu
.src
[0].chan
= 3;
7745 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
7746 alu
.dst
.sel
= ctx
->temp_reg
;
7750 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7754 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7755 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7756 alu
.op
= ALU_OP3_MULADD
;
7758 alu
.src
[0].sel
= ctx
->temp_reg
;
7759 alu
.src
[0].chan
= 3;
7760 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7761 alu
.src
[1].chan
= 0;
7762 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7763 alu
.src
[2].sel
= mytmp
;
7764 alu
.src
[2].chan
= 0;
7765 alu
.dst
.sel
= ctx
->temp_reg
;
7769 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7772 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7773 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7774 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7775 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7776 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7777 tex
.src_gpr
= r600_get_temp(ctx
);
7782 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7783 tex
.coord_type_x
= 1;
7784 tex
.coord_type_y
= 1;
7785 tex
.coord_type_z
= 1;
7786 tex
.coord_type_w
= 1;
7787 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7788 alu
.op
= ALU_OP1_MOV
;
7789 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7790 alu
.dst
.sel
= tex
.src_gpr
;
7794 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7798 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7805 /* for cube forms of lod and bias we need to route things */
7806 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7807 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7808 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7809 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7810 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7811 alu
.op
= ALU_OP1_MOV
;
7812 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7813 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7814 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7816 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7817 alu
.dst
.sel
= ctx
->temp_reg
;
7821 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7827 src_gpr
= ctx
->temp_reg
;
7830 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7831 int temp_h
= 0, temp_v
= 0;
7834 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7835 if (src_loaded
== TRUE
)
7839 for (i
= start_val
; i
< 3; i
++) {
7840 int treg
= r600_get_temp(ctx
);
7849 for (j
= 0; j
< 4; j
++) {
7850 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7851 alu
.op
= ALU_OP1_MOV
;
7852 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7858 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7863 for (i
= 1; i
< 3; i
++) {
7864 /* set gradients h/v */
7865 struct r600_bytecode_tex
*t
= &grad_offs
[n_grad_offs
++];
7866 memset(t
, 0, sizeof(struct r600_bytecode_tex
));
7867 t
->op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7868 FETCH_OP_SET_GRADIENTS_V
;
7869 t
->sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7870 t
->sampler_index_mode
= sampler_index_mode
;
7871 t
->resource_id
= t
->sampler_id
+ R600_MAX_CONST_BUFFERS
;
7872 t
->resource_index_mode
= sampler_index_mode
;
7874 t
->src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7880 t
->dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7881 t
->dst_sel_x
= t
->dst_sel_y
= t
->dst_sel_z
= t
->dst_sel_w
= 7;
7882 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7883 t
->coord_type_x
= 1;
7884 t
->coord_type_y
= 1;
7885 t
->coord_type_z
= 1;
7886 t
->coord_type_w
= 1;
7891 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7892 /* Gather4 should follow the same rules as bilinear filtering, but the hardware
7893 * incorrectly forces nearest filtering if the texture format is integer.
7894 * The only effect it has on Gather4, which always returns 4 texels for
7895 * bilinear filtering, is that the final coordinates are off by 0.5 of
7898 * The workaround is to subtract 0.5 from the unnormalized coordinates,
7899 * or (0.5 / size) from the normalized coordinates.
7901 if (inst
->Texture
.ReturnType
== TGSI_RETURN_TYPE_SINT
||
7902 inst
->Texture
.ReturnType
== TGSI_RETURN_TYPE_UINT
) {
7903 int treg
= r600_get_temp(ctx
);
7905 /* mov array and comparison oordinate to temp_reg if needed */
7906 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7907 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7908 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
) && !src_loaded
) {
7909 int end
= inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
? 3 : 2;
7910 for (i
= 2; i
<= end
; i
++) {
7911 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7912 alu
.op
= ALU_OP1_MOV
;
7913 alu
.dst
.sel
= ctx
->temp_reg
;
7916 alu
.last
= (i
== end
);
7917 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7918 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7924 if (inst
->Texture
.Texture
== TGSI_TEXTURE_RECT
||
7925 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
) {
7926 for (i
= 0; i
< 2; i
++) {
7927 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7928 alu
.op
= ALU_OP2_ADD
;
7929 alu
.dst
.sel
= ctx
->temp_reg
;
7934 alu
.src
[0].sel
= ctx
->temp_reg
;
7935 alu
.src
[0].chan
= i
;
7937 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7938 alu
.src
[1].sel
= V_SQ_ALU_SRC_0_5
;
7940 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7946 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7947 tex
.op
= FETCH_OP_GET_TEXTURE_RESINFO
;
7948 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7949 tex
.sampler_index_mode
= sampler_index_mode
;
7950 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7951 tex
.resource_index_mode
= sampler_index_mode
;
7961 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7965 /* coord.xy = -0.5 * (1.0/int_to_flt(size)) + coord.xy */
7966 if (ctx
->bc
->chip_class
== CAYMAN
) {
7968 for (i
= 0; i
< 2; i
++) {
7969 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7970 alu
.op
= ALU_OP1_INT_TO_FLT
;
7974 alu
.src
[0].sel
= treg
;
7975 alu
.src
[0].chan
= i
;
7976 alu
.last
= (i
== 1) ? 1 : 0;
7977 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7981 for (j
= 0; j
< 2; j
++) {
7982 for (i
= 0; i
< 3; i
++) {
7983 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7984 alu
.op
= ALU_OP1_RECIP_IEEE
;
7985 alu
.src
[0].sel
= treg
;
7986 alu
.src
[0].chan
= j
;
7993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7999 for (i
= 0; i
< 2; i
++) {
8000 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8001 alu
.op
= ALU_OP1_INT_TO_FLT
;
8005 alu
.src
[0].sel
= treg
;
8006 alu
.src
[0].chan
= i
;
8008 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8012 for (i
= 0; i
< 2; i
++) {
8013 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8014 alu
.op
= ALU_OP1_RECIP_IEEE
;
8015 alu
.src
[0].sel
= treg
;
8016 alu
.src
[0].chan
= i
;
8021 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8026 for (i
= 0; i
< 2; i
++) {
8027 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8028 alu
.op
= ALU_OP3_MULADD
;
8030 alu
.dst
.sel
= ctx
->temp_reg
;
8034 alu
.src
[0].sel
= treg
;
8035 alu
.src
[0].chan
= i
;
8036 alu
.src
[1].sel
= V_SQ_ALU_SRC_0_5
;
8039 alu
.src
[2].sel
= ctx
->temp_reg
;
8040 alu
.src
[2].chan
= i
;
8042 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
8043 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8049 src_gpr
= ctx
->temp_reg
;
8053 if (src_requires_loading
&& !src_loaded
) {
8054 for (i
= 0; i
< 4; i
++) {
8055 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8056 alu
.op
= ALU_OP1_MOV
;
8057 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8058 alu
.dst
.sel
= ctx
->temp_reg
;
8063 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8068 src_gpr
= ctx
->temp_reg
;
8071 /* get offset values */
8072 if (inst
->Texture
.NumOffsets
) {
8073 assert(inst
->Texture
.NumOffsets
== 1);
8075 /* The texture offset feature doesn't work with the TXF instruction
8076 * and must be emulated by adding the offset to the texture coordinates. */
8077 if (txf_add_offsets
) {
8078 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
8080 switch (inst
->Texture
.Texture
) {
8081 case TGSI_TEXTURE_3D
:
8082 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8083 alu
.op
= ALU_OP2_ADD_INT
;
8084 alu
.src
[0].sel
= src_gpr
;
8085 alu
.src
[0].chan
= 2;
8086 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8087 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
8088 alu
.dst
.sel
= src_gpr
;
8092 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8097 case TGSI_TEXTURE_2D
:
8098 case TGSI_TEXTURE_SHADOW2D
:
8099 case TGSI_TEXTURE_RECT
:
8100 case TGSI_TEXTURE_SHADOWRECT
:
8101 case TGSI_TEXTURE_2D_ARRAY
:
8102 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
8103 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8104 alu
.op
= ALU_OP2_ADD_INT
;
8105 alu
.src
[0].sel
= src_gpr
;
8106 alu
.src
[0].chan
= 1;
8107 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8108 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
8109 alu
.dst
.sel
= src_gpr
;
8113 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8118 case TGSI_TEXTURE_1D
:
8119 case TGSI_TEXTURE_SHADOW1D
:
8120 case TGSI_TEXTURE_1D_ARRAY
:
8121 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
8122 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8123 alu
.op
= ALU_OP2_ADD_INT
;
8124 alu
.src
[0].sel
= src_gpr
;
8125 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8126 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
8127 alu
.dst
.sel
= src_gpr
;
8130 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8134 /* texture offsets do not apply to other texture targets */
8137 switch (inst
->Texture
.Texture
) {
8138 case TGSI_TEXTURE_3D
:
8139 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
8141 case TGSI_TEXTURE_2D
:
8142 case TGSI_TEXTURE_SHADOW2D
:
8143 case TGSI_TEXTURE_RECT
:
8144 case TGSI_TEXTURE_SHADOWRECT
:
8145 case TGSI_TEXTURE_2D_ARRAY
:
8146 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
8147 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
8149 case TGSI_TEXTURE_1D
:
8150 case TGSI_TEXTURE_SHADOW1D
:
8151 case TGSI_TEXTURE_1D_ARRAY
:
8152 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
8153 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
8158 /* Obtain the sample index for reading a compressed MSAA color texture.
8159 * To read the FMASK, we use the ldfptr instruction, which tells us
8160 * where the samples are stored.
8161 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
8162 * which is the identity mapping. Each nibble says which physical sample
8163 * should be fetched to get that sample.
8165 * Assume src.z contains the sample index. It should be modified like this:
8166 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
8167 * Then fetch the texel with src.
8169 if (read_compressed_msaa
) {
8170 unsigned sample_chan
= 3;
8171 unsigned temp
= r600_get_temp(ctx
);
8174 /* temp.w = ldfptr() */
8175 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8176 tex
.op
= FETCH_OP_LD
;
8177 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
8178 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
8179 tex
.sampler_index_mode
= sampler_index_mode
;
8180 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
8181 tex
.resource_index_mode
= sampler_index_mode
;
8182 tex
.src_gpr
= src_gpr
;
8184 tex
.dst_sel_x
= 7; /* mask out these components */
8187 tex
.dst_sel_w
= 0; /* store X */
8192 tex
.offset_x
= offset_x
;
8193 tex
.offset_y
= offset_y
;
8194 tex
.offset_z
= offset_z
;
8195 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8199 /* temp.x = sample_index*4 */
8200 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8201 alu
.op
= ALU_OP2_MULLO_INT
;
8202 alu
.src
[0].sel
= src_gpr
;
8203 alu
.src
[0].chan
= sample_chan
;
8204 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8205 alu
.src
[1].value
= 4;
8209 r
= emit_mul_int_op(ctx
->bc
, &alu
);
8213 /* sample_index = temp.w >> temp.x */
8214 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8215 alu
.op
= ALU_OP2_LSHR_INT
;
8216 alu
.src
[0].sel
= temp
;
8217 alu
.src
[0].chan
= 3;
8218 alu
.src
[1].sel
= temp
;
8219 alu
.src
[1].chan
= 0;
8220 alu
.dst
.sel
= src_gpr
;
8221 alu
.dst
.chan
= sample_chan
;
8224 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8228 /* sample_index & 0xF */
8229 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8230 alu
.op
= ALU_OP2_AND_INT
;
8231 alu
.src
[0].sel
= src_gpr
;
8232 alu
.src
[0].chan
= sample_chan
;
8233 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8234 alu
.src
[1].value
= 0xF;
8235 alu
.dst
.sel
= src_gpr
;
8236 alu
.dst
.chan
= sample_chan
;
8239 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8243 /* visualize the FMASK */
8244 for (i
= 0; i
< 4; i
++) {
8245 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8246 alu
.op
= ALU_OP1_INT_TO_FLT
;
8247 alu
.src
[0].sel
= src_gpr
;
8248 alu
.src
[0].chan
= sample_chan
;
8249 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8253 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8261 /* does this shader want a num layers from TXQ for a cube array? */
8262 if (has_txq_cube_array_z
) {
8263 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
8265 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8266 alu
.op
= ALU_OP1_MOV
;
8268 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
8269 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
8270 /* with eg each dword is number of cubes */
8271 alu
.src
[0].sel
+= id
/ 4;
8272 alu
.src
[0].chan
= id
% 4;
8274 /* r600 we have them at channel 2 of the second dword */
8275 alu
.src
[0].sel
+= (id
* 2) + 1;
8276 alu
.src
[0].chan
= 2;
8278 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
8279 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
8281 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8284 /* disable writemask from texture instruction */
8285 inst
->Dst
[0].Register
.WriteMask
&= ~4;
8288 opcode
= ctx
->inst_info
->op
;
8289 if (opcode
== FETCH_OP_GATHER4
&&
8290 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
8291 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
8292 struct r600_bytecode_tex
*t
;
8293 opcode
= FETCH_OP_GATHER4_O
;
8295 /* GATHER4_O/GATHER4_C_O use offset values loaded by
8296 SET_TEXTURE_OFFSETS instruction. The immediate offset values
8297 encoded in the instruction are ignored. */
8298 t
= &grad_offs
[n_grad_offs
++];
8299 memset(t
, 0, sizeof(struct r600_bytecode_tex
));
8300 t
->op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
8301 t
->sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
8302 t
->sampler_index_mode
= sampler_index_mode
;
8303 t
->resource_id
= t
->sampler_id
+ R600_MAX_CONST_BUFFERS
;
8304 t
->resource_index_mode
= sampler_index_mode
;
8306 t
->src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
8307 t
->src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
8308 t
->src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
8309 if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
8310 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)
8311 /* make sure array index selector is 0, this is just a safety
8312 * precausion because TGSI seems to emit something strange here */
8315 t
->src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
8325 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
8326 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
8327 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
8328 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
8329 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
8330 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
8331 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
8333 case FETCH_OP_SAMPLE
:
8334 opcode
= FETCH_OP_SAMPLE_C
;
8336 case FETCH_OP_SAMPLE_L
:
8337 opcode
= FETCH_OP_SAMPLE_C_L
;
8339 case FETCH_OP_SAMPLE_LB
:
8340 opcode
= FETCH_OP_SAMPLE_C_LB
;
8342 case FETCH_OP_SAMPLE_G
:
8343 opcode
= FETCH_OP_SAMPLE_C_G
;
8345 /* Texture gather variants */
8346 case FETCH_OP_GATHER4
:
8347 opcode
= FETCH_OP_GATHER4_C
;
8349 case FETCH_OP_GATHER4_O
:
8350 opcode
= FETCH_OP_GATHER4_C_O
;
8355 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8358 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
8359 tex
.sampler_index_mode
= sampler_index_mode
;
8360 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
8361 tex
.resource_index_mode
= sampler_index_mode
;
8362 tex
.src_gpr
= src_gpr
;
8363 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8365 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
8366 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
8367 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
8370 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
8371 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
8372 tex
.inst_mod
= texture_component_select
;
8374 if (ctx
->bc
->chip_class
== CAYMAN
) {
8375 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8376 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8377 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8378 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8380 /* GATHER4 result order is different from TGSI TG4 */
8381 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 1 : 7;
8382 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 2 : 7;
8383 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 0 : 7;
8384 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8387 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
8388 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8389 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8393 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
8400 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8401 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8402 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8403 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8407 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
8412 } else if (src_loaded
) {
8418 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
8419 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
8420 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
8421 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
8422 tex
.src_rel
= ctx
->src
[0].rel
;
8425 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
8426 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
8427 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
8428 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
8432 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
8435 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
8436 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
8437 tex
.coord_type_x
= 1;
8438 tex
.coord_type_y
= 1;
8440 tex
.coord_type_z
= 1;
8441 tex
.coord_type_w
= 1;
8443 tex
.offset_x
= offset_x
;
8444 tex
.offset_y
= offset_y
;
8445 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
8446 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
8447 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
8451 tex
.offset_z
= offset_z
;
8454 /* Put the depth for comparison in W.
8455 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
8456 * Some instructions expect the depth in Z. */
8457 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
8458 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
8459 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
8460 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
8461 opcode
!= FETCH_OP_SAMPLE_C_L
&&
8462 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
8463 tex
.src_sel_w
= tex
.src_sel_z
;
8466 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
8467 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
8468 if (opcode
== FETCH_OP_SAMPLE_C_L
||
8469 opcode
== FETCH_OP_SAMPLE_C_LB
) {
8470 /* the array index is read from Y */
8471 tex
.coord_type_y
= 0;
8472 array_index_offset_channel
= tex
.src_sel_y
;
8474 /* the array index is read from Z */
8475 tex
.coord_type_z
= 0;
8476 tex
.src_sel_z
= tex
.src_sel_y
;
8477 array_index_offset_channel
= tex
.src_sel_z
;
8479 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
8480 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
) {
8481 tex
.coord_type_z
= 0;
8482 array_index_offset_channel
= tex
.src_sel_z
;
8483 } else if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
8484 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
8485 (ctx
->bc
->chip_class
>= EVERGREEN
))
8486 /* the array index is read from Z, coordinate will be corrected elsewhere */
8487 tex
.coord_type_z
= 0;
8489 /* We have array access to 1D or 2D ARRAY, the coordinates are not int ->
8490 * evaluate the array index */
8491 if (array_index_offset_channel
>= 0 &&
8492 opcode
!= FETCH_OP_LD
&&
8493 opcode
!= FETCH_OP_GET_TEXTURE_RESINFO
) {
8494 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8495 alu
.src
[0].sel
= tex
.src_gpr
;
8496 alu
.src
[0].chan
= array_index_offset_channel
;
8497 alu
.src
[0].rel
= tex
.src_rel
;
8498 alu
.op
= ALU_OP1_RNDNE
;
8499 alu
.dst
.sel
= tex
.src_gpr
;
8500 alu
.dst
.chan
= array_index_offset_channel
;
8501 alu
.dst
.rel
= tex
.src_rel
;
8504 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8509 /* mask unused source components */
8510 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
8511 switch (inst
->Texture
.Texture
) {
8512 case TGSI_TEXTURE_2D
:
8513 case TGSI_TEXTURE_RECT
:
8517 case TGSI_TEXTURE_1D_ARRAY
:
8521 case TGSI_TEXTURE_1D
:
8529 /* Emit set gradient and offset instructions. */
8530 for (i
= 0; i
< n_grad_offs
; ++i
) {
8531 r
= r600_bytecode_add_tex(ctx
->bc
, &grad_offs
[i
]);
8536 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8540 /* add shadow ambient support - gallium doesn't do it yet */
8544 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
8545 struct tgsi_full_src_register
*src
)
8549 if (src
->Register
.Indirect
) {
8550 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
8551 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
8552 return ctx
->shader
->atomics
[i
].hw_idx
;
8555 uint32_t index
= src
->Register
.Index
;
8556 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
8557 if (ctx
->shader
->atomics
[i
].buffer_id
!= (unsigned)src
->Dimension
.Index
)
8559 if (index
> ctx
->shader
->atomics
[i
].end
)
8561 if (index
< ctx
->shader
->atomics
[i
].start
)
8563 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
8564 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
8571 static int tgsi_set_gds_temp(struct r600_shader_ctx
*ctx
,
8572 int *uav_id_p
, int *uav_index_mode_p
)
8574 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8575 int uav_id
, uav_index_mode
= 0;
8577 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8579 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
8581 if (inst
->Src
[0].Register
.Indirect
) {
8583 struct r600_bytecode_alu alu
;
8584 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8585 alu
.op
= ALU_OP2_LSHL_INT
;
8586 alu
.src
[0].sel
= get_address_file_reg(ctx
, inst
->Src
[0].Indirect
.Index
);
8587 alu
.src
[0].chan
= 0;
8588 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8589 alu
.src
[1].value
= 2;
8590 alu
.dst
.sel
= ctx
->temp_reg
;
8594 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8598 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8601 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4);
8607 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8609 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4,
8615 *uav_index_mode_p
= uav_index_mode
;
8619 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
8621 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8623 struct r600_bytecode_gds gds
;
8625 int uav_index_mode
= 0;
8626 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8628 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8632 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8633 gds
.op
= FETCH_OP_GDS_READ_RET
;
8634 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8635 gds
.uav_id
= is_cm
? 0 : uav_id
;
8636 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8637 gds
.src_gpr
= ctx
->temp_reg
;
8638 gds
.src_sel_x
= (is_cm
) ? 0 : 4;
8646 gds
.alloc_consume
= !is_cm
;
8647 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8651 ctx
->bc
->cf_last
->vpm
= 1;
8655 /* this fixes up 1D arrays properly */
8656 static int load_index_src(struct r600_shader_ctx
*ctx
, int src_index
, int *idx_gpr
)
8658 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8660 struct r600_bytecode_alu alu
;
8661 int temp_reg
= r600_get_temp(ctx
);
8663 for (i
= 0; i
< 4; i
++) {
8664 bool def_val
= true, write_zero
= false;
8665 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8666 alu
.op
= ALU_OP1_MOV
;
8667 alu
.dst
.sel
= temp_reg
;
8670 switch (inst
->Memory
.Texture
) {
8671 case TGSI_TEXTURE_BUFFER
:
8672 case TGSI_TEXTURE_1D
:
8673 if (i
== 1 || i
== 2 || i
== 3) {
8677 case TGSI_TEXTURE_1D_ARRAY
:
8678 if (i
== 1 || i
== 3)
8681 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], 1);
8685 case TGSI_TEXTURE_2D
:
8686 if (i
== 2 || i
== 3)
8696 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8697 alu
.src
[0].value
= 0;
8698 } else if (def_val
) {
8699 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], i
);
8705 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8709 *idx_gpr
= temp_reg
;
8713 static int load_buffer_coord(struct r600_shader_ctx
*ctx
, int src_idx
,
8716 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8718 if (inst
->Src
[src_idx
].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8719 int value
= (ctx
->literals
[4 * inst
->Src
[src_idx
].Register
.Index
+ inst
->Src
[src_idx
].Register
.SwizzleX
]);
8720 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8722 V_SQ_ALU_SRC_LITERAL
, value
>> 2,
8727 struct r600_bytecode_alu alu
;
8728 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8729 alu
.op
= ALU_OP2_LSHR_INT
;
8730 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_idx
], 0);
8731 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8732 alu
.src
[1].value
= 2;
8733 alu
.dst
.sel
= temp_reg
;
8736 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8743 static int tgsi_load_buffer(struct r600_shader_ctx
*ctx
)
8745 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8746 /* have to work out the offset into the RAT immediate return buffer */
8747 struct r600_bytecode_vtx vtx
;
8748 struct r600_bytecode_cf
*cf
;
8750 int temp_reg
= r600_get_temp(ctx
);
8751 unsigned rat_index_mode
;
8754 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8755 base
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8757 r
= load_buffer_coord(ctx
, 1, temp_reg
);
8760 ctx
->bc
->cf_last
->barrier
= 1;
8761 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8762 vtx
.op
= FETCH_OP_VFETCH
;
8763 vtx
.buffer_id
= inst
->Src
[0].Register
.Index
+ base
;
8764 vtx
.buffer_index_mode
= rat_index_mode
;
8765 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8766 vtx
.src_gpr
= temp_reg
;
8768 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8769 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
8770 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
8771 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
8772 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
8773 vtx
.num_format_all
= 1;
8774 vtx
.format_comp_all
= 1;
8775 vtx
.srf_mode_all
= 0;
8777 if (inst
->Dst
[0].Register
.WriteMask
& 8) {
8778 vtx
.data_format
= FMT_32_32_32_32
;
8779 vtx
.use_const_fields
= 0;
8780 } else if (inst
->Dst
[0].Register
.WriteMask
& 4) {
8781 vtx
.data_format
= FMT_32_32_32
;
8782 vtx
.use_const_fields
= 0;
8783 } else if (inst
->Dst
[0].Register
.WriteMask
& 2) {
8784 vtx
.data_format
= FMT_32_32
;
8785 vtx
.use_const_fields
= 0;
8787 vtx
.data_format
= FMT_32
;
8788 vtx
.use_const_fields
= 0;
8791 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8794 cf
= ctx
->bc
->cf_last
;
8799 static int tgsi_load_rat(struct r600_shader_ctx
*ctx
)
8801 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8802 /* have to work out the offset into the RAT immediate return buffer */
8803 struct r600_bytecode_vtx vtx
;
8804 struct r600_bytecode_cf
*cf
;
8807 unsigned format
, num_format
, format_comp
, endian
;
8808 const struct util_format_description
*desc
;
8809 unsigned rat_index_mode
;
8810 unsigned immed_base
;
8812 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8814 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8815 r
= load_index_src(ctx
, 1, &idx_gpr
);
8820 egcm_load_index_reg(ctx
->bc
, 1, false);
8822 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8823 cf
= ctx
->bc
->cf_last
;
8825 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
8826 cf
->rat
.inst
= V_RAT_INST_NOP_RTN
;
8827 cf
->rat
.index_mode
= rat_index_mode
;
8828 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8829 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8830 cf
->output
.index_gpr
= idx_gpr
;
8831 cf
->output
.comp_mask
= 0xf;
8832 cf
->output
.burst_count
= 1;
8836 cf
->output
.elem_size
= 0;
8838 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8839 cf
= ctx
->bc
->cf_last
;
8842 desc
= util_format_description(inst
->Memory
.Format
);
8843 r600_vertex_data_type(inst
->Memory
.Format
,
8844 &format
, &num_format
, &format_comp
, &endian
);
8845 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8846 vtx
.op
= FETCH_OP_VFETCH
;
8847 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8848 vtx
.buffer_index_mode
= rat_index_mode
;
8849 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8850 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8852 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8853 vtx
.dst_sel_x
= desc
->swizzle
[0];
8854 vtx
.dst_sel_y
= desc
->swizzle
[1];
8855 vtx
.dst_sel_z
= desc
->swizzle
[2];
8856 vtx
.dst_sel_w
= desc
->swizzle
[3];
8857 vtx
.srf_mode_all
= 1;
8858 vtx
.data_format
= format
;
8859 vtx
.num_format_all
= num_format
;
8860 vtx
.format_comp_all
= format_comp
;
8861 vtx
.endian
= endian
;
8863 vtx
.mega_fetch_count
= 3;
8864 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8867 cf
= ctx
->bc
->cf_last
;
8872 static int tgsi_load_lds(struct r600_shader_ctx
*ctx
)
8874 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8875 struct r600_bytecode_alu alu
;
8877 int temp_reg
= r600_get_temp(ctx
);
8879 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8880 alu
.op
= ALU_OP1_MOV
;
8881 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8882 alu
.dst
.sel
= temp_reg
;
8885 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8889 r
= do_lds_fetch_values(ctx
, temp_reg
,
8890 ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
, inst
->Dst
[0].Register
.WriteMask
);
8896 static int tgsi_load(struct r600_shader_ctx
*ctx
)
8898 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8899 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8900 return tgsi_load_rat(ctx
);
8901 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8902 return tgsi_load_gds(ctx
);
8903 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8904 return tgsi_load_buffer(ctx
);
8905 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8906 return tgsi_load_lds(ctx
);
8910 static int tgsi_store_buffer_rat(struct r600_shader_ctx
*ctx
)
8912 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8913 struct r600_bytecode_cf
*cf
;
8915 unsigned rat_index_mode
;
8917 int temp_reg
= r600_get_temp(ctx
), treg2
= r600_get_temp(ctx
);
8919 r
= load_buffer_coord(ctx
, 0, treg2
);
8923 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8925 egcm_load_index_reg(ctx
->bc
, 1, false);
8927 for (i
= 0; i
<= 3; i
++) {
8928 struct r600_bytecode_alu alu
;
8929 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8930 alu
.op
= ALU_OP1_MOV
;
8931 alu
.dst
.sel
= temp_reg
;
8933 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
8934 alu
.last
= (i
== 3);
8936 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8941 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8942 for (i
= 0; i
<= lasti
; i
++) {
8943 struct r600_bytecode_alu alu
;
8944 if (!((1 << i
) & inst
->Dst
[0].Register
.WriteMask
))
8947 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8950 V_SQ_ALU_SRC_LITERAL
, i
);
8954 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8955 alu
.op
= ALU_OP1_MOV
;
8956 alu
.dst
.sel
= ctx
->temp_reg
;
8959 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8962 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8966 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8967 cf
= ctx
->bc
->cf_last
;
8969 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8970 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8971 cf
->rat
.index_mode
= rat_index_mode
;
8972 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8973 cf
->output
.gpr
= ctx
->temp_reg
;
8974 cf
->output
.index_gpr
= temp_reg
;
8975 cf
->output
.comp_mask
= 1;
8976 cf
->output
.burst_count
= 1;
8979 cf
->output
.elem_size
= 0;
8984 static int tgsi_store_rat(struct r600_shader_ctx
*ctx
)
8986 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8987 struct r600_bytecode_cf
*cf
;
8988 bool src_requires_loading
= false;
8989 int val_gpr
, idx_gpr
;
8991 unsigned rat_index_mode
;
8993 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8995 r
= load_index_src(ctx
, 0, &idx_gpr
);
8999 if (inst
->Src
[1].Register
.File
!= TGSI_FILE_TEMPORARY
)
9000 src_requires_loading
= true;
9002 if (src_requires_loading
) {
9003 struct r600_bytecode_alu alu
;
9004 for (i
= 0; i
< 4; i
++) {
9005 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9006 alu
.op
= ALU_OP1_MOV
;
9007 alu
.dst
.sel
= ctx
->temp_reg
;
9010 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
9014 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9018 val_gpr
= ctx
->temp_reg
;
9020 val_gpr
= tgsi_tex_get_src_gpr(ctx
, 1);
9022 egcm_load_index_reg(ctx
->bc
, 1, false);
9024 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
9025 cf
= ctx
->bc
->cf_last
;
9027 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
;
9028 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
9029 cf
->rat
.index_mode
= rat_index_mode
;
9030 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
9031 cf
->output
.gpr
= val_gpr
;
9032 cf
->output
.index_gpr
= idx_gpr
;
9033 cf
->output
.comp_mask
= 0xf;
9034 cf
->output
.burst_count
= 1;
9037 cf
->output
.elem_size
= 0;
9041 static int tgsi_store_lds(struct r600_shader_ctx
*ctx
)
9043 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9044 struct r600_bytecode_alu alu
;
9046 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
9047 int temp_reg
= r600_get_temp(ctx
);
9050 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9051 alu
.op
= ALU_OP1_MOV
;
9052 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9053 alu
.dst
.sel
= temp_reg
;
9056 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9060 lasti
= tgsi_last_instruction(write_mask
);
9061 for (i
= 1; i
<= lasti
; i
++) {
9062 if (!(write_mask
& (1 << i
)))
9064 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
9067 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
9071 for (i
= 0; i
<= lasti
; i
++) {
9072 if (!(write_mask
& (1 << i
)))
9075 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
9076 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
9077 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9078 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
9080 alu
.src
[0].sel
= temp_reg
;
9081 alu
.src
[0].chan
= i
;
9082 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
9083 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
+ 1);
9085 alu
.is_lds_idx_op
= true;
9087 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9093 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9094 alu
.op
= LDS_OP2_LDS_WRITE
;
9096 alu
.src
[0].sel
= temp_reg
;
9097 alu
.src
[0].chan
= i
;
9098 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
9101 alu
.is_lds_idx_op
= true;
9103 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9110 static int tgsi_store(struct r600_shader_ctx
*ctx
)
9112 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9113 if (inst
->Dst
[0].Register
.File
== TGSI_FILE_BUFFER
)
9114 return tgsi_store_buffer_rat(ctx
);
9115 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_MEMORY
)
9116 return tgsi_store_lds(ctx
);
9118 return tgsi_store_rat(ctx
);
9121 static int tgsi_atomic_op_rat(struct r600_shader_ctx
*ctx
)
9123 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9124 /* have to work out the offset into the RAT immediate return buffer */
9125 struct r600_bytecode_alu alu
;
9126 struct r600_bytecode_vtx vtx
;
9127 struct r600_bytecode_cf
*cf
;
9130 unsigned format
, num_format
, format_comp
, endian
;
9131 const struct util_format_description
*desc
;
9132 unsigned rat_index_mode
;
9133 unsigned immed_base
;
9136 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
9137 rat_base
= ctx
->shader
->rat_base
;
9139 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
) {
9140 immed_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
9141 rat_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
9143 r
= load_buffer_coord(ctx
, 1, ctx
->temp_reg
);
9146 idx_gpr
= ctx
->temp_reg
;
9148 r
= load_index_src(ctx
, 1, &idx_gpr
);
9153 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
9155 if (ctx
->inst_info
->op
== V_RAT_INST_CMPXCHG_INT_RTN
) {
9156 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9157 alu
.op
= ALU_OP1_MOV
;
9158 alu
.dst
.sel
= ctx
->thread_id_gpr
;
9161 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
9163 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9168 alu
.op
= ALU_OP1_MOV
;
9169 alu
.dst
.sel
= ctx
->thread_id_gpr
;
9170 if (ctx
->bc
->chip_class
== CAYMAN
)
9175 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
9177 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9181 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9182 alu
.op
= ALU_OP1_MOV
;
9183 alu
.dst
.sel
= ctx
->thread_id_gpr
;
9186 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
9188 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9194 egcm_load_index_reg(ctx
->bc
, 1, false);
9195 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
9196 cf
= ctx
->bc
->cf_last
;
9198 cf
->rat
.id
= rat_base
+ inst
->Src
[0].Register
.Index
;
9199 cf
->rat
.inst
= ctx
->inst_info
->op
;
9200 cf
->rat
.index_mode
= rat_index_mode
;
9201 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
9202 cf
->output
.gpr
= ctx
->thread_id_gpr
;
9203 cf
->output
.index_gpr
= idx_gpr
;
9204 cf
->output
.comp_mask
= 0xf;
9205 cf
->output
.burst_count
= 1;
9209 cf
->output
.elem_size
= 0;
9210 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
9211 cf
= ctx
->bc
->cf_last
;
9215 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
9216 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
) {
9217 desc
= util_format_description(inst
->Memory
.Format
);
9218 r600_vertex_data_type(inst
->Memory
.Format
,
9219 &format
, &num_format
, &format_comp
, &endian
);
9220 vtx
.dst_sel_x
= desc
->swizzle
[0];
9228 vtx
.op
= FETCH_OP_VFETCH
;
9229 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
9230 vtx
.buffer_index_mode
= rat_index_mode
;
9231 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
9232 vtx
.src_gpr
= ctx
->thread_id_gpr
;
9234 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
9238 vtx
.use_const_fields
= 0;
9239 vtx
.srf_mode_all
= 1;
9240 vtx
.data_format
= format
;
9241 vtx
.num_format_all
= num_format
;
9242 vtx
.format_comp_all
= format_comp
;
9243 vtx
.endian
= endian
;
9245 vtx
.mega_fetch_count
= 0xf;
9246 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
9249 cf
= ctx
->bc
->cf_last
;
9255 static int get_gds_op(int opcode
)
9258 case TGSI_OPCODE_ATOMUADD
:
9259 return FETCH_OP_GDS_ADD_RET
;
9260 case TGSI_OPCODE_ATOMAND
:
9261 return FETCH_OP_GDS_AND_RET
;
9262 case TGSI_OPCODE_ATOMOR
:
9263 return FETCH_OP_GDS_OR_RET
;
9264 case TGSI_OPCODE_ATOMXOR
:
9265 return FETCH_OP_GDS_XOR_RET
;
9266 case TGSI_OPCODE_ATOMUMIN
:
9267 return FETCH_OP_GDS_MIN_UINT_RET
;
9268 case TGSI_OPCODE_ATOMUMAX
:
9269 return FETCH_OP_GDS_MAX_UINT_RET
;
9270 case TGSI_OPCODE_ATOMXCHG
:
9271 return FETCH_OP_GDS_XCHG_RET
;
9272 case TGSI_OPCODE_ATOMCAS
:
9273 return FETCH_OP_GDS_CMP_XCHG_RET
;
9279 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
9281 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9282 struct r600_bytecode_gds gds
;
9283 struct r600_bytecode_alu alu
;
9284 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
9287 int uav_index_mode
= 0;
9288 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
9291 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
9295 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
9299 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
) {
9300 if (inst
->Src
[3].Register
.File
== TGSI_FILE_IMMEDIATE
) {
9301 int value
= (ctx
->literals
[4 * inst
->Src
[3].Register
.Index
+ inst
->Src
[3].Register
.SwizzleX
]);
9302 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9303 alu
.op
= ALU_OP1_MOV
;
9304 alu
.dst
.sel
= ctx
->temp_reg
;
9305 alu
.dst
.chan
= is_cm
? 2 : 1;
9306 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
9307 alu
.src
[0].value
= value
;
9310 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9314 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9315 alu
.op
= ALU_OP1_MOV
;
9316 alu
.dst
.sel
= ctx
->temp_reg
;
9317 alu
.dst
.chan
= is_cm
? 2 : 1;
9318 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
9321 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9326 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
9327 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
9328 int abs_value
= abs(value
);
9329 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
9330 gds_op
= FETCH_OP_GDS_SUB_RET
;
9331 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9332 alu
.op
= ALU_OP1_MOV
;
9333 alu
.dst
.sel
= ctx
->temp_reg
;
9334 alu
.dst
.chan
= is_cm
? 1 : 0;
9335 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
9336 alu
.src
[0].value
= abs_value
;
9339 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9343 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9344 alu
.op
= ALU_OP1_MOV
;
9345 alu
.dst
.sel
= ctx
->temp_reg
;
9346 alu
.dst
.chan
= is_cm
? 1 : 0;
9347 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
9350 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9356 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
9358 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
9359 gds
.uav_id
= is_cm
? 0 : uav_id
;
9360 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
9361 gds
.src_gpr
= ctx
->temp_reg
;
9363 gds
.src_sel_x
= is_cm
? 0 : 4;
9364 gds
.src_sel_y
= is_cm
? 1 : 0;
9365 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
)
9366 gds
.src_sel_z
= is_cm
? 2 : 1;
9373 gds
.alloc_consume
= !is_cm
;
9375 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
9378 ctx
->bc
->cf_last
->vpm
= 1;
9382 static int get_lds_op(int opcode
)
9385 case TGSI_OPCODE_ATOMUADD
:
9386 return LDS_OP2_LDS_ADD_RET
;
9387 case TGSI_OPCODE_ATOMAND
:
9388 return LDS_OP2_LDS_AND_RET
;
9389 case TGSI_OPCODE_ATOMOR
:
9390 return LDS_OP2_LDS_OR_RET
;
9391 case TGSI_OPCODE_ATOMXOR
:
9392 return LDS_OP2_LDS_XOR_RET
;
9393 case TGSI_OPCODE_ATOMUMIN
:
9394 return LDS_OP2_LDS_MIN_UINT_RET
;
9395 case TGSI_OPCODE_ATOMUMAX
:
9396 return LDS_OP2_LDS_MAX_UINT_RET
;
9397 case TGSI_OPCODE_ATOMIMIN
:
9398 return LDS_OP2_LDS_MIN_INT_RET
;
9399 case TGSI_OPCODE_ATOMIMAX
:
9400 return LDS_OP2_LDS_MAX_INT_RET
;
9401 case TGSI_OPCODE_ATOMXCHG
:
9402 return LDS_OP2_LDS_XCHG_RET
;
9403 case TGSI_OPCODE_ATOMCAS
:
9404 return LDS_OP3_LDS_CMP_XCHG_RET
;
9410 static int tgsi_atomic_op_lds(struct r600_shader_ctx
*ctx
)
9412 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9413 int lds_op
= get_lds_op(inst
->Instruction
.Opcode
);
9416 struct r600_bytecode_alu alu
;
9417 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9419 alu
.is_lds_idx_op
= true;
9421 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
9422 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], 0);
9423 if (lds_op
== LDS_OP3_LDS_CMP_XCHG_RET
)
9424 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[3], 0);
9426 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
9427 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9431 /* then read from LDS_OQ_A_POP */
9432 memset(&alu
, 0, sizeof(alu
));
9434 alu
.op
= ALU_OP1_MOV
;
9435 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
9436 alu
.src
[0].chan
= 0;
9437 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
9440 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9447 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
9449 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9450 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
9451 return tgsi_atomic_op_rat(ctx
);
9452 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
9453 return tgsi_atomic_op_gds(ctx
);
9454 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
9455 return tgsi_atomic_op_rat(ctx
);
9456 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
9457 return tgsi_atomic_op_lds(ctx
);
9461 static int tgsi_resq(struct r600_shader_ctx
*ctx
)
9463 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9464 unsigned sampler_index_mode
;
9465 struct r600_bytecode_tex tex
;
9467 boolean has_txq_cube_array_z
= false;
9469 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
||
9470 (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
&& inst
->Memory
.Texture
== TGSI_TEXTURE_BUFFER
)) {
9471 if (ctx
->bc
->chip_class
< EVERGREEN
)
9472 ctx
->shader
->uses_tex_buffers
= true;
9473 unsigned eg_buffer_base
= 0;
9474 eg_buffer_base
= R600_IMAGE_REAL_RESOURCE_OFFSET
;
9475 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
9476 eg_buffer_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
9477 return r600_do_buffer_txq(ctx
, 0, ctx
->shader
->image_size_const_offset
, eg_buffer_base
);
9480 if (inst
->Memory
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
&&
9481 inst
->Dst
[0].Register
.WriteMask
& 4) {
9482 ctx
->shader
->has_txq_cube_array_z_comp
= true;
9483 has_txq_cube_array_z
= true;
9486 sampler_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
9487 if (sampler_index_mode
)
9488 egcm_load_index_reg(ctx
->bc
, 1, false);
9491 /* does this shader want a num layers from TXQ for a cube array? */
9492 if (has_txq_cube_array_z
) {
9493 int id
= tgsi_tex_get_src_gpr(ctx
, 0) + ctx
->shader
->image_size_const_offset
;
9494 struct r600_bytecode_alu alu
;
9496 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9497 alu
.op
= ALU_OP1_MOV
;
9499 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
9500 /* with eg each dword is either number of cubes */
9501 alu
.src
[0].sel
+= id
/ 4;
9502 alu
.src
[0].chan
= id
% 4;
9503 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
9504 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
9506 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9509 /* disable writemask from texture instruction */
9510 inst
->Dst
[0].Register
.WriteMask
&= ~4;
9512 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
9513 tex
.op
= ctx
->inst_info
->op
;
9514 tex
.sampler_id
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ inst
->Src
[0].Register
.Index
;
9515 tex
.sampler_index_mode
= sampler_index_mode
;
9516 tex
.resource_id
= tex
.sampler_id
;
9517 tex
.resource_index_mode
= sampler_index_mode
;
9522 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
9523 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
9524 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
9525 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
9526 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
9527 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
9534 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
9536 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9537 struct r600_bytecode_alu alu
;
9538 unsigned lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9539 struct r600_bytecode_alu_src srcs
[2][4];
9543 /* optimize if it's just an equal balance */
9544 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
9545 for (i
= 0; i
< lasti
+ 1; i
++) {
9546 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9550 alu
.op
= ALU_OP2_ADD
;
9551 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
9552 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9554 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9559 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9567 for (i
= 0; i
< lasti
+ 1; i
++) {
9568 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9571 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9572 alu
.op
= ALU_OP2_ADD
;
9573 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9574 alu
.src
[0].chan
= 0;
9575 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
9576 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
9577 alu
.dst
.sel
= ctx
->temp_reg
;
9583 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9588 /* (1 - src0) * src2 */
9589 for (i
= 0; i
< lasti
+ 1; i
++) {
9590 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9593 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9594 alu
.op
= ALU_OP2_MUL
;
9595 alu
.src
[0].sel
= ctx
->temp_reg
;
9596 alu
.src
[0].chan
= i
;
9597 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9598 alu
.dst
.sel
= ctx
->temp_reg
;
9604 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9609 /* src0 * src1 + (1 - src0) * src2 */
9611 for (i
= 0; i
< 2; i
++) {
9612 r
= tgsi_make_src_for_op3(ctx
, inst
->Dst
[0].Register
.WriteMask
,
9613 srcs
[i
], &ctx
->src
[i
]);
9618 for (i
= 0; i
< lasti
+ 1; i
++) {
9619 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9622 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9623 alu
.op
= ALU_OP3_MULADD
;
9625 alu
.src
[0] = srcs
[0][i
];
9626 alu
.src
[1] = srcs
[1][i
];
9627 alu
.src
[2].sel
= ctx
->temp_reg
;
9628 alu
.src
[2].chan
= i
;
9630 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9635 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9642 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
9644 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9645 struct r600_bytecode_alu alu
;
9647 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9648 struct r600_bytecode_alu_src srcs
[3][4];
9652 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
9654 ctx
->src
[0].abs
= 0;
9655 ctx
->src
[0].neg
= 0;
9660 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
9661 r
= tgsi_make_src_for_op3(ctx
, inst
->Dst
[0].Register
.WriteMask
,
9662 srcs
[j
], &ctx
->src
[j
]);
9667 for (i
= 0; i
< lasti
+ 1; i
++) {
9668 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9671 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9673 alu
.src
[0] = srcs
[0][i
];
9674 alu
.src
[1] = srcs
[2][i
];
9675 alu
.src
[2] = srcs
[1][i
];
9677 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9683 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9690 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
9692 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9693 struct r600_bytecode_alu alu
;
9695 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9697 for (i
= 0; i
< lasti
+ 1; i
++) {
9698 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9701 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9702 alu
.op
= ALU_OP3_CNDE_INT
;
9703 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9704 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9705 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
9706 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9712 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9719 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
9721 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9722 struct r600_bytecode_alu alu
;
9726 /* result.x = 2^floor(src); */
9727 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9728 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9730 alu
.op
= ALU_OP1_FLOOR
;
9731 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9733 alu
.dst
.sel
= ctx
->temp_reg
;
9737 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9741 if (ctx
->bc
->chip_class
== CAYMAN
) {
9742 for (i
= 0; i
< 3; i
++) {
9743 alu
.op
= ALU_OP1_EXP_IEEE
;
9744 alu
.src
[0].sel
= ctx
->temp_reg
;
9745 alu
.src
[0].chan
= 0;
9747 alu
.dst
.sel
= ctx
->temp_reg
;
9749 alu
.dst
.write
= i
== 0;
9751 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9756 alu
.op
= ALU_OP1_EXP_IEEE
;
9757 alu
.src
[0].sel
= ctx
->temp_reg
;
9758 alu
.src
[0].chan
= 0;
9760 alu
.dst
.sel
= ctx
->temp_reg
;
9764 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9770 /* result.y = tmp - floor(tmp); */
9771 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9772 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9774 alu
.op
= ALU_OP1_FRACT
;
9775 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9777 alu
.dst
.sel
= ctx
->temp_reg
;
9779 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9788 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9793 /* result.z = RoughApprox2ToX(tmp);*/
9794 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
9795 if (ctx
->bc
->chip_class
== CAYMAN
) {
9796 for (i
= 0; i
< 3; i
++) {
9797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9798 alu
.op
= ALU_OP1_EXP_IEEE
;
9799 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9801 alu
.dst
.sel
= ctx
->temp_reg
;
9808 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9813 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9814 alu
.op
= ALU_OP1_EXP_IEEE
;
9815 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9817 alu
.dst
.sel
= ctx
->temp_reg
;
9823 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9829 /* result.w = 1.0;*/
9830 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
9831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9833 alu
.op
= ALU_OP1_MOV
;
9834 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9835 alu
.src
[0].chan
= 0;
9837 alu
.dst
.sel
= ctx
->temp_reg
;
9841 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9845 return tgsi_helper_copy(ctx
, inst
);
9848 static int tgsi_log(struct r600_shader_ctx
*ctx
)
9850 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9851 struct r600_bytecode_alu alu
;
9855 /* result.x = floor(log2(|src|)); */
9856 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9857 if (ctx
->bc
->chip_class
== CAYMAN
) {
9858 for (i
= 0; i
< 3; i
++) {
9859 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9861 alu
.op
= ALU_OP1_LOG_IEEE
;
9862 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9863 r600_bytecode_src_set_abs(&alu
.src
[0]);
9865 alu
.dst
.sel
= ctx
->temp_reg
;
9871 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9877 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9879 alu
.op
= ALU_OP1_LOG_IEEE
;
9880 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9881 r600_bytecode_src_set_abs(&alu
.src
[0]);
9883 alu
.dst
.sel
= ctx
->temp_reg
;
9887 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9892 alu
.op
= ALU_OP1_FLOOR
;
9893 alu
.src
[0].sel
= ctx
->temp_reg
;
9894 alu
.src
[0].chan
= 0;
9896 alu
.dst
.sel
= ctx
->temp_reg
;
9901 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9906 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
9907 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9909 if (ctx
->bc
->chip_class
== CAYMAN
) {
9910 for (i
= 0; i
< 3; i
++) {
9911 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9913 alu
.op
= ALU_OP1_LOG_IEEE
;
9914 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9915 r600_bytecode_src_set_abs(&alu
.src
[0]);
9917 alu
.dst
.sel
= ctx
->temp_reg
;
9924 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9929 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9931 alu
.op
= ALU_OP1_LOG_IEEE
;
9932 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9933 r600_bytecode_src_set_abs(&alu
.src
[0]);
9935 alu
.dst
.sel
= ctx
->temp_reg
;
9940 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9947 alu
.op
= ALU_OP1_FLOOR
;
9948 alu
.src
[0].sel
= ctx
->temp_reg
;
9949 alu
.src
[0].chan
= 1;
9951 alu
.dst
.sel
= ctx
->temp_reg
;
9956 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9960 if (ctx
->bc
->chip_class
== CAYMAN
) {
9961 for (i
= 0; i
< 3; i
++) {
9962 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9963 alu
.op
= ALU_OP1_EXP_IEEE
;
9964 alu
.src
[0].sel
= ctx
->temp_reg
;
9965 alu
.src
[0].chan
= 1;
9967 alu
.dst
.sel
= ctx
->temp_reg
;
9974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9979 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9980 alu
.op
= ALU_OP1_EXP_IEEE
;
9981 alu
.src
[0].sel
= ctx
->temp_reg
;
9982 alu
.src
[0].chan
= 1;
9984 alu
.dst
.sel
= ctx
->temp_reg
;
9989 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9994 if (ctx
->bc
->chip_class
== CAYMAN
) {
9995 for (i
= 0; i
< 3; i
++) {
9996 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9997 alu
.op
= ALU_OP1_RECIP_IEEE
;
9998 alu
.src
[0].sel
= ctx
->temp_reg
;
9999 alu
.src
[0].chan
= 1;
10001 alu
.dst
.sel
= ctx
->temp_reg
;
10008 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10013 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10014 alu
.op
= ALU_OP1_RECIP_IEEE
;
10015 alu
.src
[0].sel
= ctx
->temp_reg
;
10016 alu
.src
[0].chan
= 1;
10018 alu
.dst
.sel
= ctx
->temp_reg
;
10023 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10030 alu
.op
= ALU_OP2_MUL
;
10032 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10033 r600_bytecode_src_set_abs(&alu
.src
[0]);
10035 alu
.src
[1].sel
= ctx
->temp_reg
;
10036 alu
.src
[1].chan
= 1;
10038 alu
.dst
.sel
= ctx
->temp_reg
;
10043 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10048 /* result.z = log2(|src|);*/
10049 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
10050 if (ctx
->bc
->chip_class
== CAYMAN
) {
10051 for (i
= 0; i
< 3; i
++) {
10052 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10054 alu
.op
= ALU_OP1_LOG_IEEE
;
10055 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10056 r600_bytecode_src_set_abs(&alu
.src
[0]);
10058 alu
.dst
.sel
= ctx
->temp_reg
;
10065 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10070 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10072 alu
.op
= ALU_OP1_LOG_IEEE
;
10073 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10074 r600_bytecode_src_set_abs(&alu
.src
[0]);
10076 alu
.dst
.sel
= ctx
->temp_reg
;
10081 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10087 /* result.w = 1.0; */
10088 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
10089 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10091 alu
.op
= ALU_OP1_MOV
;
10092 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
10093 alu
.src
[0].chan
= 0;
10095 alu
.dst
.sel
= ctx
->temp_reg
;
10100 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10105 return tgsi_helper_copy(ctx
, inst
);
10108 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
10110 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10111 struct r600_bytecode_alu alu
;
10113 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10114 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
10116 assert(inst
->Dst
[0].Register
.Index
< 3);
10117 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10119 switch (inst
->Instruction
.Opcode
) {
10120 case TGSI_OPCODE_ARL
:
10121 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
10123 case TGSI_OPCODE_ARR
:
10124 alu
.op
= ALU_OP1_FLT_TO_INT
;
10126 case TGSI_OPCODE_UARL
:
10127 alu
.op
= ALU_OP1_MOV
;
10134 for (i
= 0; i
<= lasti
; ++i
) {
10135 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10137 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
10138 alu
.last
= i
== lasti
;
10142 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10147 if (inst
->Dst
[0].Register
.Index
> 0)
10148 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
10150 ctx
->bc
->ar_loaded
= 0;
10154 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
10156 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10157 struct r600_bytecode_alu alu
;
10159 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10161 switch (inst
->Instruction
.Opcode
) {
10162 case TGSI_OPCODE_ARL
:
10163 memset(&alu
, 0, sizeof(alu
));
10164 alu
.op
= ALU_OP1_FLOOR
;
10165 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
10167 for (i
= 0; i
<= lasti
; ++i
) {
10168 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
10170 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
10171 alu
.last
= i
== lasti
;
10172 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
10177 memset(&alu
, 0, sizeof(alu
));
10178 alu
.op
= ALU_OP1_FLT_TO_INT
;
10179 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
10180 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
10182 /* FLT_TO_INT is trans-only on r600/r700 */
10184 for (i
= 0; i
<= lasti
; ++i
) {
10186 alu
.src
[0].chan
= i
;
10187 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
10191 case TGSI_OPCODE_ARR
:
10192 memset(&alu
, 0, sizeof(alu
));
10193 alu
.op
= ALU_OP1_FLT_TO_INT
;
10194 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
10196 /* FLT_TO_INT is trans-only on r600/r700 */
10198 for (i
= 0; i
<= lasti
; ++i
) {
10199 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
10201 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
10202 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
10207 case TGSI_OPCODE_UARL
:
10208 memset(&alu
, 0, sizeof(alu
));
10209 alu
.op
= ALU_OP1_MOV
;
10210 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
10212 for (i
= 0; i
<= lasti
; ++i
) {
10213 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
10215 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
10216 alu
.last
= i
== lasti
;
10217 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
10227 ctx
->bc
->ar_loaded
= 0;
10231 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
10233 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10234 struct r600_bytecode_alu alu
;
10237 for (i
= 0; i
< 4; i
++) {
10238 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10240 alu
.op
= ALU_OP2_MUL
;
10241 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10243 if (i
== 0 || i
== 3) {
10244 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
10246 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
10249 if (i
== 0 || i
== 2) {
10250 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
10252 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
10256 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10263 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
,
10264 struct r600_bytecode_alu_src
*src
)
10266 struct r600_bytecode_alu alu
;
10269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10271 alu
.execute_mask
= 1;
10272 alu
.update_pred
= 1;
10274 alu
.dst
.sel
= ctx
->temp_reg
;
10279 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
10280 alu
.src
[1].chan
= 0;
10284 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
10290 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
10292 unsigned force_pop
= ctx
->bc
->force_add_cf
;
10296 if (ctx
->bc
->cf_last
) {
10297 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
10299 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
10303 if (alu_pop
== 1) {
10304 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
10305 ctx
->bc
->force_add_cf
= 1;
10306 } else if (alu_pop
== 2) {
10307 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
10308 ctx
->bc
->force_add_cf
= 1;
10315 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
10316 ctx
->bc
->cf_last
->pop_count
= pops
;
10317 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10323 static inline int callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
10326 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
10330 unsigned entry_size
= stack
->entry_size
;
10332 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
10333 elements
+= stack
->push
;
10335 switch (ctx
->bc
->chip_class
) {
10338 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
10339 * the stack must be reserved to hold the current active/continue
10341 if (reason
== FC_PUSH_VPM
|| stack
->push
> 0) {
10347 /* r9xx: any stack operation on empty stack consumes 2 additional
10352 /* FIXME: do the two elements added above cover the cases for the
10356 /* r8xx+: 2 extra elements are not always required, but one extra
10357 * element must be added for each of the following cases:
10358 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
10360 * (Currently we don't use ALU_ELSE_AFTER.)
10361 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
10362 * PUSH instruction executed.
10364 * NOTE: it seems we also need to reserve additional element in some
10365 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
10366 * then STACK_SIZE should be 2 instead of 1 */
10367 if (reason
== FC_PUSH_VPM
|| stack
->push
> 0) {
10377 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
10378 * for all chips, so we use 4 in the final formula, not the real entry_size
10382 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
10384 if (entries
> stack
->max_entries
)
10385 stack
->max_entries
= entries
;
10389 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
10393 --ctx
->bc
->stack
.push
;
10394 assert(ctx
->bc
->stack
.push
>= 0);
10397 --ctx
->bc
->stack
.push_wqm
;
10398 assert(ctx
->bc
->stack
.push_wqm
>= 0);
10401 --ctx
->bc
->stack
.loop
;
10402 assert(ctx
->bc
->stack
.loop
>= 0);
10410 static inline int callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
10414 ++ctx
->bc
->stack
.push
;
10417 ++ctx
->bc
->stack
.push_wqm
;
10420 ++ctx
->bc
->stack
.loop
;
10426 return callstack_update_max_depth(ctx
, reason
);
10429 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
10431 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
10433 sp
->mid
= realloc((void *)sp
->mid
,
10434 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
10435 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
10439 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
10441 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
10442 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
10443 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
10447 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
10449 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
10459 static int emit_return(struct r600_shader_ctx
*ctx
)
10461 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
10465 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
10468 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
10469 ctx
->bc
->cf_last
->pop_count
= pops
;
10470 /* XXX work out offset */
10474 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
10479 static void emit_testflag(struct r600_shader_ctx
*ctx
)
10484 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
10486 emit_testflag(ctx
);
10487 emit_jump_to_offset(ctx
, 1, 4);
10488 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
10489 pops(ctx
, ifidx
+ 1);
10493 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
10495 emit_testflag(ctx
);
10497 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10498 ctx
->bc
->cf_last
->pop_count
= 1;
10500 fc_set_mid(ctx
, fc_sp
);
10506 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
,
10507 struct r600_bytecode_alu_src
*src
)
10509 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
10510 bool needs_workaround
= false;
10511 int elems
= callstack_push(ctx
, FC_PUSH_VPM
);
10513 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1)
10514 needs_workaround
= true;
10516 if (ctx
->bc
->chip_class
== EVERGREEN
&& ctx_needs_stack_workaround_8xx(ctx
)) {
10517 unsigned dmod1
= (elems
- 1) % ctx
->bc
->stack
.entry_size
;
10518 unsigned dmod2
= (elems
) % ctx
->bc
->stack
.entry_size
;
10520 if (elems
&& (!dmod1
|| !dmod2
))
10521 needs_workaround
= true;
10524 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
10525 * LOOP_STARTxxx for nested loops may put the branch stack into a state
10526 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
10527 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
10528 if (needs_workaround
) {
10529 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
10530 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10531 alu_type
= CF_OP_ALU
;
10534 emit_logic_pred(ctx
, opcode
, alu_type
, src
);
10536 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
10538 fc_pushlevel(ctx
, FC_IF
);
10543 static int tgsi_if(struct r600_shader_ctx
*ctx
)
10545 struct r600_bytecode_alu_src alu_src
;
10546 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
10548 return emit_if(ctx
, ALU_OP2_PRED_SETNE
, &alu_src
);
10551 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
10553 struct r600_bytecode_alu_src alu_src
;
10554 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
10555 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10558 static int tgsi_else(struct r600_shader_ctx
*ctx
)
10560 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
10561 ctx
->bc
->cf_last
->pop_count
= 1;
10563 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
10564 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
10568 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
10572 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
10573 R600_ERR("if/endif unbalanced in shader\n");
10577 /* ALU_EXTENDED needs 4 DWords instead of two, adjust jump target offset accordingly */
10578 if (ctx
->bc
->cf_last
->eg_alu_extended
)
10581 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
10582 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ offset
;
10583 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
10585 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ offset
;
10589 callstack_pop(ctx
, FC_PUSH_VPM
);
10593 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
10595 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
10596 * limited to 4096 iterations, like the other LOOP_* instructions. */
10597 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
10599 fc_pushlevel(ctx
, FC_LOOP
);
10601 /* check stack depth */
10602 callstack_push(ctx
, FC_LOOP
);
10606 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
10610 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
10612 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
10613 R600_ERR("loop/endloop in shader code are not paired.\n");
10617 /* fixup loop pointers - from r600isa
10618 LOOP END points to CF after LOOP START,
10619 LOOP START point to CF after LOOP END
10620 BRK/CONT point to LOOP END CF
10622 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
10624 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10626 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
10627 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
10629 /* XXX add LOOPRET support */
10631 callstack_pop(ctx
, FC_LOOP
);
10635 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
10639 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
10641 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
10646 R600_ERR("Break not inside loop/endloop pair\n");
10650 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10652 fc_set_mid(ctx
, fscp
- 1);
10657 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
10659 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10660 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
10663 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10664 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
10666 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10668 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
10669 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10670 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
10675 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
10677 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10678 struct r600_bytecode_alu alu
;
10680 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10683 for (i
= 0; i
< lasti
+ 1; i
++) {
10684 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10687 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10690 alu
.dst
.sel
= ctx
->temp_reg
;
10693 alu
.op
= ALU_OP2_MULLO_UINT
;
10694 for (j
= 0; j
< 2; j
++) {
10695 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
10699 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10705 for (i
= 0; i
< lasti
+ 1; i
++) {
10706 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10709 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10710 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10712 alu
.op
= ALU_OP2_ADD_INT
;
10714 alu
.src
[0].sel
= ctx
->temp_reg
;
10715 alu
.src
[0].chan
= i
;
10717 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
10721 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10728 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
10730 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10731 struct r600_bytecode_alu alu
;
10733 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10735 /* temp.xy = f32_to_f16(src) */
10736 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10737 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
10739 alu
.dst
.sel
= ctx
->temp_reg
;
10741 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10742 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10746 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10748 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10752 /* dst.x = temp.y * 0x10000 + temp.x */
10753 for (i
= 0; i
< lasti
+ 1; i
++) {
10754 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10757 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10758 alu
.op
= ALU_OP3_MULADD_UINT24
;
10760 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10761 alu
.last
= i
== lasti
;
10762 alu
.src
[0].sel
= ctx
->temp_reg
;
10763 alu
.src
[0].chan
= 1;
10764 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10765 alu
.src
[1].value
= 0x10000;
10766 alu
.src
[2].sel
= ctx
->temp_reg
;
10767 alu
.src
[2].chan
= 0;
10768 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10776 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
10778 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10779 struct r600_bytecode_alu alu
;
10781 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10783 /* temp.x = src.x */
10784 /* note: no need to mask out the high bits */
10785 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10786 alu
.op
= ALU_OP1_MOV
;
10788 alu
.dst
.sel
= ctx
->temp_reg
;
10790 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10791 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10795 /* temp.y = src.x >> 16 */
10796 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10797 alu
.op
= ALU_OP2_LSHR_INT
;
10799 alu
.dst
.sel
= ctx
->temp_reg
;
10801 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10802 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10803 alu
.src
[1].value
= 16;
10805 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10809 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
10810 for (i
= 0; i
< lasti
+ 1; i
++) {
10811 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10813 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10814 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10815 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
10816 alu
.src
[0].sel
= ctx
->temp_reg
;
10817 alu
.src
[0].chan
= i
% 2;
10818 alu
.last
= i
== lasti
;
10819 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10827 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
10829 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10830 struct r600_bytecode_alu alu
;
10831 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10835 if ((inst
->Src
[0].Register
.File
== inst
->Dst
[0].Register
.File
&&
10836 inst
->Src
[0].Register
.Index
== inst
->Dst
[0].Register
.Index
) ||
10837 (inst
->Src
[2].Register
.File
== inst
->Dst
[0].Register
.File
&&
10838 inst
->Src
[2].Register
.Index
== inst
->Dst
[0].Register
.Index
))
10839 dst
= r600_get_temp(ctx
);
10841 r
= tgsi_op3_dst(ctx
, dst
);
10845 for (i
= 0; i
< lasti
+ 1; i
++) {
10846 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10847 alu
.op
= ALU_OP2_SETGE_INT
;
10848 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
10849 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10850 alu
.src
[1].value
= 32;
10851 alu
.dst
.sel
= ctx
->temp_reg
;
10856 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10861 for (i
= 0; i
< lasti
+ 1; i
++) {
10862 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10863 alu
.op
= ALU_OP3_CNDE_INT
;
10865 alu
.src
[0].sel
= ctx
->temp_reg
;
10866 alu
.src
[0].chan
= i
;
10868 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10870 alu
.src
[1].sel
= dst
;
10872 alu
.src
[1].sel
= alu
.dst
.sel
;
10873 alu
.src
[1].chan
= i
;
10874 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
10878 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10886 static int tgsi_clock(struct r600_shader_ctx
*ctx
)
10888 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10889 struct r600_bytecode_alu alu
;
10892 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10893 alu
.op
= ALU_OP1_MOV
;
10894 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10895 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_LO
;
10896 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10899 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10900 alu
.op
= ALU_OP1_MOV
;
10901 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10902 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_HI
;
10904 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10910 static int emit_u64add(struct r600_shader_ctx
*ctx
, int op
,
10912 int src0_sel
, int src0_chan
,
10913 int src1_sel
, int src1_chan
)
10915 struct r600_bytecode_alu alu
;
10919 if (op
== ALU_OP2_ADD_INT
)
10920 opc
= ALU_OP2_ADDC_UINT
;
10922 opc
= ALU_OP2_SUBB_UINT
;
10924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10926 alu
.dst
.sel
= treg
;
10929 alu
.src
[0].sel
= src0_sel
;
10930 alu
.src
[0].chan
= src0_chan
+ 0;
10931 alu
.src
[1].sel
= src1_sel
;
10932 alu
.src
[1].chan
= src1_chan
+ 0;
10933 alu
.src
[1].neg
= 0;
10934 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10938 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10940 alu
.dst
.sel
= treg
;
10943 alu
.src
[0].sel
= src0_sel
;
10944 alu
.src
[0].chan
= src0_chan
+ 1;
10945 alu
.src
[1].sel
= src1_sel
;
10946 alu
.src
[1].chan
= src1_chan
+ 1;
10947 alu
.src
[1].neg
= 0;
10948 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10952 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10954 alu
.dst
.sel
= treg
;
10958 alu
.src
[0].sel
= src0_sel
;
10959 alu
.src
[0].chan
= src0_chan
+ 0;
10960 alu
.src
[1].sel
= src1_sel
;
10961 alu
.src
[1].chan
= src1_chan
+ 0;
10962 alu
.src
[1].neg
= 0;
10963 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10967 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10969 alu
.dst
.sel
= treg
;
10972 alu
.src
[0].sel
= treg
;
10973 alu
.src
[0].chan
= 1;
10974 alu
.src
[1].sel
= treg
;
10975 alu
.src
[1].chan
= 2;
10977 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10983 static int egcm_u64add(struct r600_shader_ctx
*ctx
)
10985 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10986 struct r600_bytecode_alu alu
;
10988 int treg
= ctx
->temp_reg
;
10989 int op
= ALU_OP2_ADD_INT
, opc
= ALU_OP2_ADDC_UINT
;
10991 if (ctx
->src
[1].neg
) {
10992 op
= ALU_OP2_SUB_INT
;
10993 opc
= ALU_OP2_SUBB_UINT
;
10995 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10997 alu
.dst
.sel
= treg
;
11000 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
11001 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
11002 alu
.src
[1].neg
= 0;
11003 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11007 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11009 alu
.dst
.sel
= treg
;
11012 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
11013 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
11014 alu
.src
[1].neg
= 0;
11015 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11019 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11021 alu
.dst
.sel
= treg
;
11025 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
11026 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
11027 alu
.src
[1].neg
= 0;
11028 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11034 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
11035 alu
.src
[0].sel
= treg
;
11036 alu
.src
[0].chan
= 1;
11037 alu
.src
[1].sel
= treg
;
11038 alu
.src
[1].chan
= 2;
11040 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11043 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11044 alu
.op
= ALU_OP1_MOV
;
11045 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
11046 alu
.src
[0].sel
= treg
;
11047 alu
.src
[0].chan
= 0;
11049 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11055 /* result.y = mul_high a, b
11057 result.y += a.x * b.y + a.y * b.x;
11059 static int egcm_u64mul(struct r600_shader_ctx
*ctx
)
11061 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
11062 struct r600_bytecode_alu alu
;
11064 int treg
= ctx
->temp_reg
;
11066 /* temp.x = mul_lo a.x, b.x */
11067 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11068 alu
.op
= ALU_OP2_MULLO_UINT
;
11069 alu
.dst
.sel
= treg
;
11072 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
11073 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
11074 r
= emit_mul_int_op(ctx
->bc
, &alu
);
11078 /* temp.y = mul_hi a.x, b.x */
11079 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11080 alu
.op
= ALU_OP2_MULHI_UINT
;
11081 alu
.dst
.sel
= treg
;
11084 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
11085 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
11086 r
= emit_mul_int_op(ctx
->bc
, &alu
);
11090 /* temp.z = mul a.x, b.y */
11091 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11092 alu
.op
= ALU_OP2_MULLO_UINT
;
11093 alu
.dst
.sel
= treg
;
11096 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
11097 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
11098 r
= emit_mul_int_op(ctx
->bc
, &alu
);
11102 /* temp.w = mul a.y, b.x */
11103 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11104 alu
.op
= ALU_OP2_MULLO_UINT
;
11105 alu
.dst
.sel
= treg
;
11108 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
11109 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
11110 r
= emit_mul_int_op(ctx
->bc
, &alu
);
11114 /* temp.z = temp.z + temp.w */
11115 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11116 alu
.op
= ALU_OP2_ADD_INT
;
11117 alu
.dst
.sel
= treg
;
11120 alu
.src
[0].sel
= treg
;
11121 alu
.src
[0].chan
= 2;
11122 alu
.src
[1].sel
= treg
;
11123 alu
.src
[1].chan
= 3;
11125 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11129 /* temp.y = temp.y + temp.z */
11130 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11131 alu
.op
= ALU_OP2_ADD_INT
;
11132 alu
.dst
.sel
= treg
;
11135 alu
.src
[0].sel
= treg
;
11136 alu
.src
[0].chan
= 1;
11137 alu
.src
[1].sel
= treg
;
11138 alu
.src
[1].chan
= 2;
11140 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11144 /* dst.x = temp.x */
11145 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11146 alu
.op
= ALU_OP1_MOV
;
11147 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
11148 alu
.src
[0].sel
= treg
;
11149 alu
.src
[0].chan
= 0;
11150 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11154 /* dst.y = temp.y */
11155 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11156 alu
.op
= ALU_OP1_MOV
;
11157 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
11158 alu
.src
[0].sel
= treg
;
11159 alu
.src
[0].chan
= 1;
11161 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11168 static int emit_u64sge(struct r600_shader_ctx
*ctx
,
11170 int src0_sel
, int src0_base_chan
,
11171 int src1_sel
, int src1_base_chan
)
11174 /* for 64-bit sge */
11175 /* result = (src0.y > src1.y) || ((src0.y == src1.y) && src0.x >= src1.x)) */
11176 r
= single_alu_op2(ctx
, ALU_OP2_SETGT_UINT
,
11178 src0_sel
, src0_base_chan
+ 1,
11179 src1_sel
, src1_base_chan
+ 1);
11183 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11185 src0_sel
, src0_base_chan
,
11186 src1_sel
, src1_base_chan
);
11190 r
= single_alu_op2(ctx
, ALU_OP2_SETE_INT
,
11192 src0_sel
, src0_base_chan
+ 1,
11193 src1_sel
, src1_base_chan
+ 1);
11197 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
11204 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11213 /* this isn't a complete div it's just enough for qbo shader to work */
11214 static int egcm_u64div(struct r600_shader_ctx
*ctx
)
11216 struct r600_bytecode_alu alu
;
11217 struct r600_bytecode_alu_src alu_num_hi
, alu_num_lo
, alu_denom_hi
, alu_denom_lo
, alu_src
;
11219 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
11221 /* make sure we are dividing my a const with 0 in the high bits */
11222 if (ctx
->src
[1].sel
!= V_SQ_ALU_SRC_LITERAL
)
11224 if (ctx
->src
[1].value
[ctx
->src
[1].swizzle
[1]] != 0)
11226 /* make sure we are doing one division */
11227 if (inst
->Dst
[0].Register
.WriteMask
!= 0x3)
11230 /* emit_if uses ctx->temp_reg so we can't */
11231 int treg
= r600_get_temp(ctx
);
11232 int tmp_num
= r600_get_temp(ctx
);
11233 int sub_tmp
= r600_get_temp(ctx
);
11235 /* tmp quot are tmp_num.zw */
11236 r600_bytecode_src(&alu_num_lo
, &ctx
->src
[0], 0);
11237 r600_bytecode_src(&alu_num_hi
, &ctx
->src
[0], 1);
11238 r600_bytecode_src(&alu_denom_lo
, &ctx
->src
[1], 0);
11239 r600_bytecode_src(&alu_denom_hi
, &ctx
->src
[1], 1);
11241 /* MOV tmp_num.xy, numerator */
11242 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11244 alu_num_lo
.sel
, alu_num_lo
.chan
,
11248 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11250 alu_num_hi
.sel
, alu_num_hi
.chan
,
11255 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11257 V_SQ_ALU_SRC_LITERAL
, 0,
11262 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11264 V_SQ_ALU_SRC_LITERAL
, 0,
11269 /* treg 0 is log2_denom */
11270 /* normally this gets the MSB for the denom high value
11271 - however we know this will always be 0 here. */
11272 r
= single_alu_op2(ctx
,
11275 V_SQ_ALU_SRC_LITERAL
, 32,
11280 /* normally check demon hi for 0, but we know it is already */
11281 /* t0.z = num_hi >= denom_lo */
11282 r
= single_alu_op2(ctx
,
11283 ALU_OP2_SETGE_UINT
,
11285 alu_num_hi
.sel
, alu_num_hi
.chan
,
11286 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
11290 memset(&alu_src
, 0, sizeof(alu_src
));
11291 alu_src
.sel
= treg
;
11293 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11297 /* for loops in here */
11298 /* get msb t0.x = msb(src[1].x) first */
11299 int msb_lo
= util_last_bit(alu_denom_lo
.value
);
11300 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11302 V_SQ_ALU_SRC_LITERAL
, msb_lo
,
11307 /* unroll the asm here */
11308 for (i
= 0; i
< 31; i
++) {
11309 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11311 V_SQ_ALU_SRC_LITERAL
, i
,
11316 /* we can do this on the CPU */
11317 uint32_t denom_lo_shl
= alu_denom_lo
.value
<< (31 - i
);
11318 /* t0.z = tmp_num.y >= t0.z */
11319 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11322 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
11326 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
11333 memset(&alu_src
, 0, sizeof(alu_src
));
11334 alu_src
.sel
= treg
;
11336 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11340 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
11343 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
11347 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11350 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
11354 r
= tgsi_endif(ctx
);
11359 /* log2_denom is always <= 31, so manually peel the last loop
11362 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11365 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
11369 memset(&alu_src
, 0, sizeof(alu_src
));
11370 alu_src
.sel
= treg
;
11372 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11376 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
11379 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
11383 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11386 V_SQ_ALU_SRC_LITERAL
, 1U);
11389 r
= tgsi_endif(ctx
);
11393 r
= tgsi_endif(ctx
);
11397 /* onto the second loop to unroll */
11398 for (i
= 0; i
< 31; i
++) {
11399 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11401 V_SQ_ALU_SRC_LITERAL
, (63 - (31 - i
)),
11406 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
<< (31 - i
);
11407 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11409 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
11414 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11416 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
11421 r
= emit_u64sge(ctx
, sub_tmp
,
11427 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
11434 memset(&alu_src
, 0, sizeof(alu_src
));
11435 alu_src
.sel
= treg
;
11437 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11442 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
11449 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11456 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11463 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11466 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
11470 r
= tgsi_endif(ctx
);
11475 /* log2_denom is always <= 63, so manually peel the last loop
11478 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
;
11479 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11481 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
11486 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11488 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
11493 r
= emit_u64sge(ctx
, sub_tmp
,
11499 memset(&alu_src
, 0, sizeof(alu_src
));
11500 alu_src
.sel
= sub_tmp
;
11502 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11506 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
11513 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11516 V_SQ_ALU_SRC_LITERAL
, 1U);
11519 r
= tgsi_endif(ctx
);
11523 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11524 alu
.op
= ALU_OP1_MOV
;
11525 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
11526 alu
.src
[0].sel
= tmp_num
;
11527 alu
.src
[0].chan
= 2;
11528 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11532 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11533 alu
.op
= ALU_OP1_MOV
;
11534 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
11535 alu
.src
[0].sel
= tmp_num
;
11536 alu
.src
[0].chan
= 3;
11538 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11544 static int egcm_u64sne(struct r600_shader_ctx
*ctx
)
11546 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
11547 struct r600_bytecode_alu alu
;
11549 int treg
= ctx
->temp_reg
;
11551 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11552 alu
.op
= ALU_OP2_SETNE_INT
;
11553 alu
.dst
.sel
= treg
;
11556 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
11557 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
11558 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11562 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11563 alu
.op
= ALU_OP2_SETNE_INT
;
11564 alu
.dst
.sel
= treg
;
11567 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
11568 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
11570 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11574 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11575 alu
.op
= ALU_OP2_OR_INT
;
11576 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
11577 alu
.src
[0].sel
= treg
;
11578 alu
.src
[0].chan
= 0;
11579 alu
.src
[1].sel
= treg
;
11580 alu
.src
[1].chan
= 1;
11582 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11588 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
11589 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
11590 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11591 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11593 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
11595 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
11596 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11597 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11598 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11599 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11600 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11601 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11602 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11603 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
11604 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11605 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11606 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11607 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11608 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11609 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11610 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11611 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
11612 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11613 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11614 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11615 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11616 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11617 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11618 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11619 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11620 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11621 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11622 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11623 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11624 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11625 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11626 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11627 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11628 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11629 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11630 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11631 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11632 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11633 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11634 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11635 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11636 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11637 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11638 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11639 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11640 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11641 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11642 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11643 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11644 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11645 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11646 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11647 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11648 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11649 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11650 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11651 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11652 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
11653 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11654 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11655 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11656 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11657 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11658 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11659 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11660 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11661 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11662 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11663 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11664 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11665 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11666 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11667 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11668 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11669 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11670 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11671 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11672 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
11673 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11674 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11675 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
11676 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11677 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11678 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
11679 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11680 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11681 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11682 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11683 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11684 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11685 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11686 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11687 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11688 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11689 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11690 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11691 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11692 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11693 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11694 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11695 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11696 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11697 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11698 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11699 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11700 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11701 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11702 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11703 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11704 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11705 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11706 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11707 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11708 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11709 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11710 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
11711 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11712 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11713 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11714 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11715 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11716 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
11717 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11718 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
11719 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
11720 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11721 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11722 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11723 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11724 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11725 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11726 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
11727 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11728 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11729 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
11730 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11731 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
11732 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11733 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11734 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11735 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11736 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11737 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11738 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11739 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11740 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11741 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11742 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11743 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11744 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11745 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11746 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11747 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11748 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
11749 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11750 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11751 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11752 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11753 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11754 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11755 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11756 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11757 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11758 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11759 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11760 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11761 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11762 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11763 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11764 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11765 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11766 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11767 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11768 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11769 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11770 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11771 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
11772 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11773 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
11774 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
11775 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
11776 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
11777 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11778 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
11779 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
11780 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
11781 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
11782 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
11783 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11784 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11785 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11786 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11789 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
11790 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11791 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11792 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11793 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
11794 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
11795 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11796 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11797 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11798 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11799 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11800 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11801 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11802 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11803 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11804 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11805 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11806 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11807 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11808 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
11809 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
11810 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11811 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11812 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11813 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11814 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11815 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11816 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11817 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11818 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11819 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11820 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11821 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11822 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
11823 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11824 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11825 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11826 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11827 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11828 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11829 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
11830 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11831 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11832 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11833 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11834 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11835 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11836 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11837 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11838 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11839 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11840 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11841 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11842 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11843 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11844 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
11845 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11846 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11847 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11848 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11849 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11850 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11851 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11852 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11853 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11854 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11855 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11856 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11857 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11858 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11859 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11860 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11861 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11862 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11863 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11864 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11865 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11866 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11867 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11868 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11869 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11870 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11871 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11872 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
11873 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11874 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11875 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
11876 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11877 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11878 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11879 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11880 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11881 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11882 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11883 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11884 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11885 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11886 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11887 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11888 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11889 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11890 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11891 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11892 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11893 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
11894 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11895 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11896 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11897 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11898 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11899 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11900 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11901 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11902 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11903 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11904 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11905 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11906 /* Refer below for TGSI_OPCODE_DFMA */
11907 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
11908 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11909 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11910 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11911 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11912 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11913 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
11914 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11915 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
11916 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
11917 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11918 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11919 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11920 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11921 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11922 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11923 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
11924 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11925 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11926 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
11927 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11928 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
11929 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11930 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11931 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11932 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11933 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11934 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11935 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11936 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11937 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11938 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11939 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11940 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11941 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11942 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11943 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11944 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11945 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
11946 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11947 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11948 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11949 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
11950 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
11951 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11952 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11953 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11954 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11955 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
11956 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
11957 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
11958 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
11959 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
11960 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
11961 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
11962 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
11963 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
11964 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
11965 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11966 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11967 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11968 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
11969 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11970 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
11971 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
11972 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
11973 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
11974 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
11975 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
11976 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
11977 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
11978 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
11979 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
11980 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11981 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11982 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11983 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
11984 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
11985 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
11986 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
11987 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
11988 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
11989 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
11990 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
11991 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
11992 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
11993 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
11994 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
11995 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
11996 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
11997 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
11998 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11999 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
12000 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
12001 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
12002 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
12003 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
12004 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
12005 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
12006 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
12007 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
12008 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
12009 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
12010 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
12011 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
12012 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12015 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
12016 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
12017 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
12018 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
12019 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
12020 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
12021 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
12022 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
12023 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
12024 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
12025 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
12026 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
12027 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
12028 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
12029 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
12030 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
12031 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
12032 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
12033 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
12034 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
12035 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
12036 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
12037 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
12038 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
12039 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
12040 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
12041 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
12042 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
12043 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
12044 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
12045 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
12046 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
12047 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
12048 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
12049 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
12050 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
12051 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
12052 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
12053 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
12054 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
12055 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
12056 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12057 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12058 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12059 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
12060 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
12061 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
12062 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
12063 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
12064 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
12065 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
12066 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
12067 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
12068 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
12069 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
12070 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
12071 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12072 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12073 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12074 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
12075 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
12076 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
12077 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
12078 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12079 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12080 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
12081 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
12082 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
12083 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
12084 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
12085 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12086 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
12087 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
12088 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
12089 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
12090 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
12091 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
12092 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
12093 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
12094 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
12095 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
12096 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
12097 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
12098 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
12099 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
12100 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
12101 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
12102 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
12103 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
12104 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
12105 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
12106 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
12107 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
12108 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
12109 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
12110 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
12111 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
12112 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
12113 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
12114 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12115 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
12116 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12117 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
12118 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
12119 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
12120 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
12121 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12122 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
12123 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
12124 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
12125 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
12126 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
12127 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
12128 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
12129 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
12130 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
12131 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
12132 /* Refer below for TGSI_OPCODE_DFMA */
12133 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
12134 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
12135 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
12136 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
12137 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
12138 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
12139 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
12140 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
12141 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
12142 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
12143 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
12144 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
12145 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
12146 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
12147 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
12148 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
12149 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
12150 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
12151 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
12152 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
12153 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
12154 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
12155 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12156 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12157 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12158 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
12159 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
12160 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
12161 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
12162 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
12163 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
12164 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
12165 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
12166 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
12167 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
12168 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
12169 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
12170 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
12171 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
12172 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
12173 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
12174 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
12175 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
12176 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
12177 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
12178 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
12179 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
12180 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
12181 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
12182 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
12183 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
12184 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
12185 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
12186 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
12187 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
12188 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
12189 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
12190 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
12191 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
12192 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
12193 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
12194 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
12195 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
12196 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
12197 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
12198 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
12199 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
12200 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
12201 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
12202 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
12203 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
12204 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
12205 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
12206 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
12207 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
12208 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
12209 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
12210 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
12211 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
12212 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
12213 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
12214 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
12215 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
12216 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
12217 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
12218 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
12219 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
12220 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
12221 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
12222 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
12223 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
12224 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
12225 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
12226 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
12227 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
12228 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
12229 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
12230 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
12231 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
12232 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
12233 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
12234 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
12235 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
12236 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
12237 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
12238 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},