2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "r600_formats.h"
25 #include "r600_opcodes.h"
26 #include "r600_shader.h"
29 #include "sb/sb_public.h"
31 #include "pipe/p_shader_tokens.h"
32 #include "tgsi/tgsi_info.h"
33 #include "tgsi/tgsi_parse.h"
34 #include "tgsi/tgsi_scan.h"
35 #include "tgsi/tgsi_dump.h"
36 #include "util/u_bitcast.h"
37 #include "util/u_memory.h"
38 #include "util/u_math.h"
43 Why CAYMAN got loops for lots of instructions is explained here.
45 -These 8xx t-slot only ops are implemented in all vector slots.
46 MUL_LIT, FLT_TO_UINT, INT_TO_FLT, UINT_TO_FLT
47 These 8xx t-slot only opcodes become vector ops, with all four
48 slots expecting the arguments on sources a and b. Result is
49 broadcast to all channels.
50 MULLO_INT, MULHI_INT, MULLO_UINT, MULHI_UINT, MUL_64
51 These 8xx t-slot only opcodes become vector ops in the z, y, and
53 EXP_IEEE, LOG_IEEE/CLAMPED, RECIP_IEEE/CLAMPED/FF/INT/UINT/_64/CLAMPED_64
54 RECIPSQRT_IEEE/CLAMPED/FF/_64/CLAMPED_64
57 The w slot may have an independent co-issued operation, or if the
58 result is required to be in the w slot, the opcode above may be
59 issued in the w slot as well.
60 The compiler must issue the source argument to slots z, y, and x
63 /* Contents of r0 on entry to various shaders
69 GS - r0.xyw, r1.xyz = per-vertex offsets
75 .w = tess factor base.
77 TES - .x = TessCoord.x
79 - .z = RelPatchID (??)
82 PS - face_gpr.z = SampleMask
85 #define R600_SHADER_BUFFER_INFO_SEL (512 + R600_BUFFER_INFO_OFFSET / 16)
86 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
87 struct r600_pipe_shader
*pipeshader
,
88 union r600_shader_key key
);
90 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
91 int size
, unsigned comp_mask
) {
96 if (ps
->num_arrays
== ps
->max_arrays
) {
98 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
99 sizeof(struct r600_shader_array
));
102 int n
= ps
->num_arrays
;
105 ps
->arrays
[n
].comp_mask
= comp_mask
;
106 ps
->arrays
[n
].gpr_start
= start_gpr
;
107 ps
->arrays
[n
].gpr_count
= size
;
110 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
114 fprintf(stderr
, "STREAMOUT\n");
115 for (i
= 0; i
< so
->num_outputs
; i
++) {
116 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
117 so
->output
[i
].start_component
;
118 fprintf(stderr
, " %i: MEM_STREAM%d_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
120 so
->output
[i
].stream
,
121 so
->output
[i
].output_buffer
,
122 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
123 so
->output
[i
].register_index
,
128 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
132 static int store_shader(struct pipe_context
*ctx
,
133 struct r600_pipe_shader
*shader
)
135 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
138 if (shader
->bo
== NULL
) {
139 shader
->bo
= (struct r600_resource
*)
140 pipe_buffer_create(ctx
->screen
, 0, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
141 if (shader
->bo
== NULL
) {
144 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
145 if (R600_BIG_ENDIAN
) {
146 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
147 ptr
[i
] = util_cpu_to_le32(shader
->shader
.bc
.bytecode
[i
]);
150 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
152 rctx
->b
.ws
->buffer_unmap(shader
->bo
->buf
);
158 int r600_pipe_shader_create(struct pipe_context
*ctx
,
159 struct r600_pipe_shader
*shader
,
160 union r600_shader_key key
)
162 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
163 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
165 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
,
166 tgsi_get_processor_type(sel
->tokens
));
167 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
168 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
169 unsigned export_shader
;
171 shader
->shader
.bc
.isa
= rctx
->isa
;
174 fprintf(stderr
, "--------------------------------------------------------------\n");
175 tgsi_dump(sel
->tokens
, 0);
177 if (sel
->so
.num_outputs
) {
178 r600_dump_streamout(&sel
->so
);
181 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
183 R600_ERR("translation from TGSI failed !\n");
186 if (shader
->shader
.processor_type
== PIPE_SHADER_VERTEX
) {
187 /* only disable for vertex shaders in tess paths */
191 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_CTRL
);
192 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_EVAL
);
193 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_COMPUTE
);
195 /* disable SB for shaders using doubles */
196 use_sb
&= !shader
->shader
.uses_doubles
;
198 use_sb
&= !shader
->shader
.uses_atomics
;
199 use_sb
&= !shader
->shader
.uses_images
;
201 /* Check if the bytecode has already been built. */
202 if (!shader
->shader
.bc
.bytecode
) {
203 r
= r600_bytecode_build(&shader
->shader
.bc
);
205 R600_ERR("building bytecode failed !\n");
210 if (dump
&& !sb_disasm
) {
211 fprintf(stderr
, "--------------------------------------------------------------\n");
212 r600_bytecode_disasm(&shader
->shader
.bc
);
213 fprintf(stderr
, "______________________________________________________________\n");
214 } else if ((dump
&& sb_disasm
) || use_sb
) {
215 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
218 R600_ERR("r600_sb_bytecode_process failed !\n");
223 if (shader
->gs_copy_shader
) {
226 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
227 &shader
->gs_copy_shader
->shader
, dump
, 0);
232 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
236 /* Store the shader in a buffer. */
237 if ((r
= store_shader(ctx
, shader
)))
241 switch (shader
->shader
.processor_type
) {
242 case PIPE_SHADER_TESS_CTRL
:
243 evergreen_update_hs_state(ctx
, shader
);
245 case PIPE_SHADER_TESS_EVAL
:
247 evergreen_update_es_state(ctx
, shader
);
249 evergreen_update_vs_state(ctx
, shader
);
251 case PIPE_SHADER_GEOMETRY
:
252 if (rctx
->b
.chip_class
>= EVERGREEN
) {
253 evergreen_update_gs_state(ctx
, shader
);
254 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
256 r600_update_gs_state(ctx
, shader
);
257 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
260 case PIPE_SHADER_VERTEX
:
261 export_shader
= key
.vs
.as_es
;
262 if (rctx
->b
.chip_class
>= EVERGREEN
) {
264 evergreen_update_ls_state(ctx
, shader
);
265 else if (key
.vs
.as_es
)
266 evergreen_update_es_state(ctx
, shader
);
268 evergreen_update_vs_state(ctx
, shader
);
271 r600_update_es_state(ctx
, shader
);
273 r600_update_vs_state(ctx
, shader
);
276 case PIPE_SHADER_FRAGMENT
:
277 if (rctx
->b
.chip_class
>= EVERGREEN
) {
278 evergreen_update_ps_state(ctx
, shader
);
280 r600_update_ps_state(ctx
, shader
);
283 case PIPE_SHADER_COMPUTE
:
284 evergreen_update_ls_state(ctx
, shader
);
293 r600_pipe_shader_destroy(ctx
, shader
);
297 void r600_pipe_shader_destroy(struct pipe_context
*ctx UNUSED
, struct r600_pipe_shader
*shader
)
299 r600_resource_reference(&shader
->bo
, NULL
);
300 r600_bytecode_clear(&shader
->shader
.bc
);
301 r600_release_command_buffer(&shader
->command_buffer
);
305 * tgsi -> r600 shader
307 struct r600_shader_tgsi_instruction
;
309 struct r600_shader_src
{
316 boolean kc_rel
; /* true if cache bank is indexed */
325 struct r600_shader_ctx
{
326 struct tgsi_shader_info info
;
327 struct tgsi_parse_context parse
;
328 const struct tgsi_token
*tokens
;
330 unsigned file_offset
[TGSI_FILE_COUNT
];
332 const struct r600_shader_tgsi_instruction
*inst_info
;
333 struct r600_bytecode
*bc
;
334 struct r600_shader
*shader
;
335 struct r600_shader_src src
[4];
338 uint32_t max_driver_temp_used
;
339 /* needed for evergreen interpolation */
340 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
341 /* evergreen/cayman also store sample mask in face register */
343 /* sample id is .w component stored in fixed point position register */
344 int fixed_pt_position_gpr
;
346 boolean clip_vertex_write
;
348 unsigned edgeflag_output
;
349 int cs_block_size_reg
;
350 int cs_grid_size_reg
;
351 bool cs_block_size_loaded
, cs_grid_size_loaded
;
354 int next_ring_offset
;
355 int gs_out_ring_offset
;
357 struct r600_shader
*gs_for_vs
;
358 int gs_export_gpr_tregs
[4];
359 int gs_rotated_input
[2];
360 const struct pipe_stream_output_info
*gs_stream_output_info
;
361 unsigned enabled_stream_buffers_mask
;
362 unsigned tess_input_info
; /* temp with tess input offsets */
363 unsigned tess_output_info
; /* temp with tess input offsets */
364 unsigned thread_id_gpr
; /* temp with thread id calculated for images */
365 bool thread_id_gpr_loaded
;
368 struct r600_shader_tgsi_instruction
{
370 int (*process
)(struct r600_shader_ctx
*ctx
);
373 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
374 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
375 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
376 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
377 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
378 static int tgsi_else(struct r600_shader_ctx
*ctx
);
379 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
380 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
381 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
382 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
383 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
384 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
385 unsigned int dst_reg
);
386 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
387 const struct r600_shader_src
*shader_src
,
389 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
390 unsigned dst_reg
, unsigned mask
);
392 static int tgsi_last_instruction(unsigned writemask
)
396 for (i
= 0; i
< 4; i
++) {
397 if (writemask
& (1 << i
)) {
404 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
406 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
409 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
410 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
414 if (i
->Instruction
.Label
) {
415 R600_ERR("label unsupported\n");
419 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
420 if (i
->Src
[j
].Register
.Dimension
) {
421 switch (i
->Src
[j
].Register
.File
) {
422 case TGSI_FILE_CONSTANT
:
423 case TGSI_FILE_HW_ATOMIC
:
425 case TGSI_FILE_INPUT
:
426 if (ctx
->type
== PIPE_SHADER_GEOMETRY
||
427 ctx
->type
== PIPE_SHADER_TESS_CTRL
||
428 ctx
->type
== PIPE_SHADER_TESS_EVAL
)
430 case TGSI_FILE_OUTPUT
:
431 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
434 R600_ERR("unsupported src %d (file %d, dimension %d)\n", j
,
435 i
->Src
[j
].Register
.File
,
436 i
->Src
[j
].Register
.Dimension
);
441 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
442 if (i
->Dst
[j
].Register
.Dimension
) {
443 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
445 R600_ERR("unsupported dst (dimension)\n");
452 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
454 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
455 interpolate
== TGSI_INTERPOLATE_LINEAR
||
456 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
458 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
462 case TGSI_INTERPOLATE_LOC_CENTER
:
465 case TGSI_INTERPOLATE_LOC_CENTROID
:
468 case TGSI_INTERPOLATE_LOC_SAMPLE
:
473 return is_linear
* 3 + loc
;
479 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
482 int i
= eg_get_interpolator_index(
483 ctx
->shader
->input
[input
].interpolate
,
484 ctx
->shader
->input
[input
].interpolate_location
);
486 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
489 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
492 struct r600_bytecode_alu alu
;
493 int gpr
= 0, base_chan
= 0;
494 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
496 /* work out gpr and base_chan from index */
498 base_chan
= (2 * (ij_index
% 2)) + 1;
500 for (i
= 0; i
< 8; i
++) {
501 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
504 alu
.op
= ALU_OP2_INTERP_ZW
;
506 alu
.op
= ALU_OP2_INTERP_XY
;
508 if ((i
> 1) && (i
< 6)) {
509 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
513 alu
.dst
.chan
= i
% 4;
515 alu
.src
[0].sel
= gpr
;
516 alu
.src
[0].chan
= (base_chan
- (i
% 2));
518 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
520 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
523 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
530 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
533 struct r600_bytecode_alu alu
;
535 for (i
= 0; i
< 4; i
++) {
536 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
538 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
540 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
545 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
550 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
558 * Special export handling in shaders
560 * shader export ARRAY_BASE for EXPORT_POS:
563 * 62, 63 are clip distance vectors
565 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
566 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
567 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
568 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
569 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
570 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
571 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
572 * exclusive from render target index)
573 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
576 * shader export ARRAY_BASE for EXPORT_PIXEL:
578 * 61 computed Z vector
580 * The use of the values exported in the computed Z vector are controlled
581 * by DB_SHADER_CONTROL:
582 * Z_EXPORT_ENABLE - Z as a float in RED
583 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
584 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
585 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
586 * DB_SOURCE_FORMAT - export control restrictions
591 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
592 static int r600_spi_sid(struct r600_shader_io
* io
)
594 int index
, name
= io
->name
;
596 /* These params are handled differently, they don't need
597 * semantic indices, so we'll use 0 for them.
599 if (name
== TGSI_SEMANTIC_POSITION
||
600 name
== TGSI_SEMANTIC_PSIZE
||
601 name
== TGSI_SEMANTIC_EDGEFLAG
||
602 name
== TGSI_SEMANTIC_FACE
||
603 name
== TGSI_SEMANTIC_SAMPLEMASK
)
606 if (name
== TGSI_SEMANTIC_GENERIC
) {
607 /* For generic params simply use sid from tgsi */
610 /* For non-generic params - pack name and sid into 8 bits */
611 index
= 0x80 | (name
<<3) | (io
->sid
);
614 /* Make sure that all really used indices have nonzero value, so
615 * we can just compare it to 0 later instead of comparing the name
616 * with different values to detect special cases. */
623 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
624 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
626 switch (semantic_name
) {
627 case TGSI_SEMANTIC_POSITION
:
629 case TGSI_SEMANTIC_PSIZE
:
631 case TGSI_SEMANTIC_CLIPDIST
:
634 case TGSI_SEMANTIC_GENERIC
:
636 return 4 + index
- 9;
638 /* same explanation as in the default statement,
639 * the only user hitting this is st/nine.
643 /* patch indices are completely separate and thus start from 0 */
644 case TGSI_SEMANTIC_TESSOUTER
:
646 case TGSI_SEMANTIC_TESSINNER
:
648 case TGSI_SEMANTIC_PATCH
:
652 /* Don't fail here. The result of this function is only used
653 * for LS, TCS, TES, and GS, where legacy GL semantics can't
654 * occur, but this function is called for all vertex shaders
655 * before it's known whether LS will be compiled or not.
661 /* turn input into interpolate on EG */
662 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
666 if (ctx
->shader
->input
[index
].spi_sid
) {
667 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
668 if (ctx
->shader
->input
[index
].interpolate
> 0) {
669 evergreen_interp_assign_ij_index(ctx
, index
);
670 r
= evergreen_interp_alu(ctx
, index
);
672 r
= evergreen_interp_flat(ctx
, index
);
678 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
680 struct r600_bytecode_alu alu
;
682 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
683 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
685 for (i
= 0; i
< 4; i
++) {
686 memset(&alu
, 0, sizeof(alu
));
687 alu
.op
= ALU_OP3_CNDGT
;
690 alu
.dst
.sel
= gpr_front
;
691 alu
.src
[0].sel
= ctx
->face_gpr
;
692 alu
.src
[1].sel
= gpr_front
;
693 alu
.src
[2].sel
= gpr_back
;
700 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
707 /* execute a single slot ALU calculation */
708 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
709 int dst_sel
, int dst_chan
,
710 int src0_sel
, unsigned src0_chan_val
,
711 int src1_sel
, unsigned src1_chan_val
)
713 struct r600_bytecode_alu alu
;
716 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
717 for (i
= 0; i
< 4; i
++) {
718 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
720 alu
.src
[0].sel
= src0_sel
;
721 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
722 alu
.src
[0].value
= src0_chan_val
;
724 alu
.src
[0].chan
= src0_chan_val
;
725 alu
.src
[1].sel
= src1_sel
;
726 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
727 alu
.src
[1].value
= src1_chan_val
;
729 alu
.src
[1].chan
= src1_chan_val
;
730 alu
.dst
.sel
= dst_sel
;
732 alu
.dst
.write
= i
== dst_chan
;
734 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
741 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
743 alu
.src
[0].sel
= src0_sel
;
744 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
745 alu
.src
[0].value
= src0_chan_val
;
747 alu
.src
[0].chan
= src0_chan_val
;
748 alu
.src
[1].sel
= src1_sel
;
749 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
750 alu
.src
[1].value
= src1_chan_val
;
752 alu
.src
[1].chan
= src1_chan_val
;
753 alu
.dst
.sel
= dst_sel
;
754 alu
.dst
.chan
= dst_chan
;
757 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
763 /* execute a single slot ALU calculation */
764 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
765 int dst_sel
, int dst_chan
,
766 int src0_sel
, unsigned src0_chan_val
,
767 int src1_sel
, unsigned src1_chan_val
,
768 int src2_sel
, unsigned src2_chan_val
)
770 struct r600_bytecode_alu alu
;
773 /* validate this for other ops */
774 assert(op
== ALU_OP3_MULADD_UINT24
|| op
== ALU_OP3_CNDE_INT
);
775 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
777 alu
.src
[0].sel
= src0_sel
;
778 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
779 alu
.src
[0].value
= src0_chan_val
;
781 alu
.src
[0].chan
= src0_chan_val
;
782 alu
.src
[1].sel
= src1_sel
;
783 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
784 alu
.src
[1].value
= src1_chan_val
;
786 alu
.src
[1].chan
= src1_chan_val
;
787 alu
.src
[2].sel
= src2_sel
;
788 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
789 alu
.src
[2].value
= src2_chan_val
;
791 alu
.src
[2].chan
= src2_chan_val
;
792 alu
.dst
.sel
= dst_sel
;
793 alu
.dst
.chan
= dst_chan
;
796 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
802 /* put it in temp_reg.x */
803 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
805 int temp_reg
, bool is_patch_var
)
809 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
811 Dimension - patch0_offset (input_vals.z),
812 Non-dim - patch0_data_offset (input_vals.w)
814 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
816 ctx
->tess_output_info
, 0,
818 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
824 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
826 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
829 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
831 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
834 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
837 i
= ctx
->shader
->noutput
++;
838 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
839 ctx
->shader
->output
[i
].sid
= 0;
840 ctx
->shader
->output
[i
].gpr
= 0;
841 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
842 ctx
->shader
->output
[i
].write_mask
= 0x4;
843 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
848 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
850 struct r600_bytecode_alu alu
;
853 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
854 alu
.op
= ctx
->inst_info
->op
;
857 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
863 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
865 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
866 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
868 switch (d
->Declaration
.File
) {
869 case TGSI_FILE_INPUT
:
870 for (j
= 0; j
< count
; j
++) {
871 i
= ctx
->shader
->ninput
+ j
;
872 assert(i
< ARRAY_SIZE(ctx
->shader
->input
));
873 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
874 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
875 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
876 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
877 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
878 if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
879 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
880 switch (ctx
->shader
->input
[i
].name
) {
881 case TGSI_SEMANTIC_FACE
:
882 if (ctx
->face_gpr
!= -1)
883 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
885 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
887 case TGSI_SEMANTIC_COLOR
:
890 case TGSI_SEMANTIC_POSITION
:
891 ctx
->fragcoord_input
= i
;
893 case TGSI_SEMANTIC_PRIMID
:
894 /* set this for now */
895 ctx
->shader
->gs_prim_id_input
= true;
896 ctx
->shader
->ps_prim_id_input
= i
;
899 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
900 if ((r
= evergreen_interp_input(ctx
, i
)))
903 } else if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
904 /* FIXME probably skip inputs if they aren't passed in the ring */
905 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
906 ctx
->next_ring_offset
+= 16;
907 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
908 ctx
->shader
->gs_prim_id_input
= true;
911 ctx
->shader
->ninput
+= count
;
913 case TGSI_FILE_OUTPUT
:
914 for (j
= 0; j
< count
; j
++) {
915 i
= ctx
->shader
->noutput
+ j
;
916 assert(i
< ARRAY_SIZE(ctx
->shader
->output
));
917 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
918 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
919 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
920 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
921 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
922 if (ctx
->type
== PIPE_SHADER_VERTEX
||
923 ctx
->type
== PIPE_SHADER_GEOMETRY
||
924 ctx
->type
== PIPE_SHADER_TESS_EVAL
) {
925 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
926 switch (d
->Semantic
.Name
) {
927 case TGSI_SEMANTIC_CLIPDIST
:
929 case TGSI_SEMANTIC_PSIZE
:
930 ctx
->shader
->vs_out_misc_write
= 1;
931 ctx
->shader
->vs_out_point_size
= 1;
933 case TGSI_SEMANTIC_EDGEFLAG
:
934 ctx
->shader
->vs_out_misc_write
= 1;
935 ctx
->shader
->vs_out_edgeflag
= 1;
936 ctx
->edgeflag_output
= i
;
938 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
939 ctx
->shader
->vs_out_misc_write
= 1;
940 ctx
->shader
->vs_out_viewport
= 1;
942 case TGSI_SEMANTIC_LAYER
:
943 ctx
->shader
->vs_out_misc_write
= 1;
944 ctx
->shader
->vs_out_layer
= 1;
946 case TGSI_SEMANTIC_CLIPVERTEX
:
947 ctx
->clip_vertex_write
= TRUE
;
951 if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
952 ctx
->gs_out_ring_offset
+= 16;
954 } else if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
955 switch (d
->Semantic
.Name
) {
956 case TGSI_SEMANTIC_COLOR
:
957 ctx
->shader
->nr_ps_max_color_exports
++;
962 ctx
->shader
->noutput
+= count
;
964 case TGSI_FILE_TEMPORARY
:
965 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
966 if (d
->Array
.ArrayID
) {
967 r600_add_gpr_array(ctx
->shader
,
968 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
970 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
975 case TGSI_FILE_CONSTANT
:
976 case TGSI_FILE_SAMPLER
:
977 case TGSI_FILE_SAMPLER_VIEW
:
978 case TGSI_FILE_ADDRESS
:
979 case TGSI_FILE_BUFFER
:
980 case TGSI_FILE_IMAGE
:
981 case TGSI_FILE_MEMORY
:
984 case TGSI_FILE_HW_ATOMIC
:
985 i
= ctx
->shader
->nhwatomic_ranges
;
986 ctx
->shader
->atomics
[i
].start
= d
->Range
.First
;
987 ctx
->shader
->atomics
[i
].end
= d
->Range
.Last
;
988 ctx
->shader
->atomics
[i
].hw_idx
= ctx
->shader
->atomic_base
+ ctx
->shader
->nhwatomic
;
989 ctx
->shader
->atomics
[i
].array_id
= d
->Array
.ArrayID
;
990 ctx
->shader
->atomics
[i
].buffer_id
= d
->Dim
.Index2D
;
991 ctx
->shader
->nhwatomic_ranges
++;
992 ctx
->shader
->nhwatomic
+= count
;
995 case TGSI_FILE_SYSTEM_VALUE
:
996 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
997 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
998 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
999 break; /* Already handled from allocate_system_value_inputs */
1000 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
1001 if (!ctx
->native_integers
) {
1002 struct r600_bytecode_alu alu
;
1003 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1005 alu
.op
= ALU_OP1_INT_TO_FLT
;
1007 alu
.src
[0].chan
= 3;
1014 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1018 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1020 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
1022 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
||
1023 d
->Semantic
.Name
== TGSI_SEMANTIC_TESSOUTER
) {
1024 int param
= r600_get_lds_unique_index(d
->Semantic
.Name
, 0);
1025 int dreg
= d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
? 3 : 2;
1026 unsigned temp_reg
= r600_get_temp(ctx
);
1028 r
= get_lds_offset0(ctx
, 2, temp_reg
, true);
1032 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1035 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1039 do_lds_fetch_values(ctx
, temp_reg
, dreg
, 0xf);
1041 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSCOORD
) {
1045 for (i
= 0; i
< 2; i
++) {
1046 struct r600_bytecode_alu alu
;
1047 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1048 alu
.op
= ALU_OP1_MOV
;
1050 alu
.src
[0].chan
= 0 + i
;
1052 alu
.dst
.chan
= 0 + i
;
1054 alu
.last
= (i
== 1) ? 1 : 0;
1055 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1058 /* ADD r1.z, 1.0f, -r0.x */
1059 struct r600_bytecode_alu alu
;
1060 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1061 alu
.op
= ALU_OP2_ADD
;
1062 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
1064 alu
.src
[1].chan
= 0;
1070 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1073 /* ADD r1.z, r1.z, -r1.y */
1074 alu
.op
= ALU_OP2_ADD
;
1076 alu
.src
[0].chan
= 2;
1078 alu
.src
[1].chan
= 1;
1084 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1090 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1096 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
1098 struct tgsi_parse_context parse
;
1102 unsigned name
, alternate_name
;
1104 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
1106 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
1111 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1115 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1116 while (!tgsi_parse_end_of_tokens(&parse
)) {
1117 tgsi_parse_token(&parse
);
1119 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1120 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1121 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1122 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1123 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1125 int interpolate
, location
, k
;
1127 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1128 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1129 inputs
[1].enabled
= true; /* needs SAMPLEID */
1130 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1131 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1132 /* Needs sample positions, currently those are always available */
1134 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1137 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1138 k
= eg_get_interpolator_index(interpolate
, location
);
1140 ctx
->eg_interpolators
[k
].enabled
= true;
1142 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1143 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1144 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1145 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1146 if (d
->Semantic
.Name
== inputs
[k
].name
||
1147 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1148 inputs
[k
].enabled
= true;
1155 tgsi_parse_free(&parse
);
1157 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1158 boolean enabled
= inputs
[i
].enabled
;
1159 int *reg
= inputs
[i
].reg
;
1160 unsigned name
= inputs
[i
].name
;
1163 int gpr
= gpr_offset
+ num_regs
++;
1164 ctx
->shader
->nsys_inputs
++;
1166 // add to inputs, allocate a gpr
1167 k
= ctx
->shader
->ninput
++;
1168 ctx
->shader
->input
[k
].name
= name
;
1169 ctx
->shader
->input
[k
].sid
= 0;
1170 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1171 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1172 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1176 return gpr_offset
+ num_regs
;
1180 * for evergreen we need to scan the shader to find the number of GPRs we need to
1181 * reserve for interpolation and system values
1183 * we need to know if we are going to emit
1184 * any sample or centroid inputs
1185 * if perspective and linear are required
1187 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1191 struct tgsi_parse_context parse
;
1193 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1195 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1197 /* skip position/face/mask/sampleid */
1198 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1199 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1200 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1201 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1204 k
= eg_get_interpolator_index(
1205 ctx
->info
.input_interpolate
[i
],
1206 ctx
->info
.input_interpolate_loc
[i
]);
1208 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1211 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1215 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1216 while (!tgsi_parse_end_of_tokens(&parse
)) {
1217 tgsi_parse_token(&parse
);
1219 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1220 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1221 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1222 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1223 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1225 int interpolate
, location
, k
;
1227 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1228 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1229 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1230 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1232 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1235 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1236 k
= eg_get_interpolator_index(interpolate
, location
);
1238 ctx
->eg_interpolators
[k
].enabled
= true;
1243 tgsi_parse_free(&parse
);
1245 /* assign gpr to each interpolator according to priority */
1247 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1248 if (ctx
->eg_interpolators
[i
].enabled
) {
1249 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1254 /* XXX PULL MODEL and LINE STIPPLE */
1256 num_baryc
= (num_baryc
+ 1) >> 1;
1257 return allocate_system_value_inputs(ctx
, num_baryc
);
1260 /* sample_id_sel == NULL means fetch for current sample */
1261 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1263 struct r600_bytecode_vtx vtx
;
1266 assert(ctx
->fixed_pt_position_gpr
!= -1);
1268 t1
= r600_get_temp(ctx
);
1270 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1271 vtx
.op
= FETCH_OP_VFETCH
;
1272 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1273 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1274 if (sample_id
== NULL
) {
1275 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1279 struct r600_bytecode_alu alu
;
1281 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1282 alu
.op
= ALU_OP1_MOV
;
1283 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1287 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1294 vtx
.mega_fetch_count
= 16;
1300 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1301 vtx
.num_format_all
= 2;
1302 vtx
.format_comp_all
= 1;
1303 vtx
.use_const_fields
= 0;
1304 vtx
.offset
= 1; // first element is size of buffer
1305 vtx
.endian
= r600_endian_swap(32);
1306 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1308 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1315 static int load_block_grid_size(struct r600_shader_ctx
*ctx
, bool load_block
)
1317 struct r600_bytecode_vtx vtx
;
1320 if (ctx
->cs_block_size_loaded
)
1321 return ctx
->cs_block_size_reg
;
1322 if (ctx
->cs_grid_size_loaded
)
1323 return ctx
->cs_grid_size_reg
;
1325 t1
= load_block
? ctx
->cs_block_size_reg
: ctx
->cs_grid_size_reg
;
1326 struct r600_bytecode_alu alu
;
1327 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1328 alu
.op
= ALU_OP1_MOV
;
1329 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1333 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
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
;
1344 vtx
.mega_fetch_count
= 16;
1350 vtx
.data_format
= FMT_32_32_32_32
;
1351 vtx
.num_format_all
= 1;
1352 vtx
.format_comp_all
= 0;
1353 vtx
.use_const_fields
= 0;
1354 vtx
.offset
= load_block
? 0 : 16; // first element is size of buffer
1355 vtx
.endian
= r600_endian_swap(32);
1356 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1358 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1363 ctx
->cs_block_size_loaded
= true;
1365 ctx
->cs_grid_size_loaded
= true;
1369 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1370 const struct tgsi_full_src_register
*tgsi_src
,
1371 struct r600_shader_src
*r600_src
)
1373 memset(r600_src
, 0, sizeof(*r600_src
));
1374 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1375 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1376 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1377 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1378 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1379 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1381 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1383 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1384 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1385 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1387 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1388 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1389 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1392 index
= tgsi_src
->Register
.Index
;
1393 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1394 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1395 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1396 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1397 r600_src
->swizzle
[0] = 2; // Z value
1398 r600_src
->swizzle
[1] = 2;
1399 r600_src
->swizzle
[2] = 2;
1400 r600_src
->swizzle
[3] = 2;
1401 r600_src
->sel
= ctx
->face_gpr
;
1402 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1403 r600_src
->swizzle
[0] = 3; // W value
1404 r600_src
->swizzle
[1] = 3;
1405 r600_src
->swizzle
[2] = 3;
1406 r600_src
->swizzle
[3] = 3;
1407 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1408 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1409 r600_src
->swizzle
[0] = 0;
1410 r600_src
->swizzle
[1] = 1;
1411 r600_src
->swizzle
[2] = 4;
1412 r600_src
->swizzle
[3] = 4;
1413 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1414 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1415 r600_src
->swizzle
[0] = 3;
1416 r600_src
->swizzle
[1] = 3;
1417 r600_src
->swizzle
[2] = 3;
1418 r600_src
->swizzle
[3] = 3;
1420 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1421 r600_src
->swizzle
[0] = 0;
1422 r600_src
->swizzle
[1] = 0;
1423 r600_src
->swizzle
[2] = 0;
1424 r600_src
->swizzle
[3] = 0;
1426 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_THREAD_ID
) {
1428 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_ID
) {
1430 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1431 r600_src
->swizzle
[0] = 3;
1432 r600_src
->swizzle
[1] = 3;
1433 r600_src
->swizzle
[2] = 3;
1434 r600_src
->swizzle
[3] = 3;
1436 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1437 r600_src
->swizzle
[0] = 2;
1438 r600_src
->swizzle
[1] = 2;
1439 r600_src
->swizzle
[2] = 2;
1440 r600_src
->swizzle
[3] = 2;
1442 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1444 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1446 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1448 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1449 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1450 r600_src
->sel
= ctx
->tess_input_info
;
1451 r600_src
->swizzle
[0] = 2;
1452 r600_src
->swizzle
[1] = 2;
1453 r600_src
->swizzle
[2] = 2;
1454 r600_src
->swizzle
[3] = 2;
1456 r600_src
->sel
= ctx
->tess_input_info
;
1457 r600_src
->swizzle
[0] = 3;
1458 r600_src
->swizzle
[1] = 3;
1459 r600_src
->swizzle
[2] = 3;
1460 r600_src
->swizzle
[3] = 3;
1462 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1464 r600_src
->swizzle
[0] = 0;
1465 r600_src
->swizzle
[1] = 0;
1466 r600_src
->swizzle
[2] = 0;
1467 r600_src
->swizzle
[3] = 0;
1468 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1470 r600_src
->swizzle
[0] = 3;
1471 r600_src
->swizzle
[1] = 3;
1472 r600_src
->swizzle
[2] = 3;
1473 r600_src
->swizzle
[3] = 3;
1474 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_GRID_SIZE
) {
1475 r600_src
->sel
= load_block_grid_size(ctx
, false);
1476 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_SIZE
) {
1477 r600_src
->sel
= load_block_grid_size(ctx
, true);
1480 if (tgsi_src
->Register
.Indirect
)
1481 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1482 r600_src
->sel
= tgsi_src
->Register
.Index
;
1483 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1485 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1486 if (tgsi_src
->Register
.Dimension
) {
1487 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1488 if (tgsi_src
->Dimension
.Indirect
) {
1489 r600_src
->kc_rel
= 1;
1495 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1496 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1497 unsigned int dst_reg
)
1499 struct r600_bytecode_vtx vtx
;
1500 unsigned int ar_reg
;
1504 struct r600_bytecode_alu alu
;
1506 memset(&alu
, 0, sizeof(alu
));
1508 alu
.op
= ALU_OP2_ADD_INT
;
1509 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1510 alu
.src
[0].chan
= ar_chan
;
1512 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1513 alu
.src
[1].value
= offset
;
1515 alu
.dst
.sel
= dst_reg
;
1516 alu
.dst
.chan
= ar_chan
;
1520 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1525 ar_reg
= ctx
->bc
->ar_reg
;
1528 memset(&vtx
, 0, sizeof(vtx
));
1529 vtx
.buffer_id
= cb_idx
;
1530 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1531 vtx
.src_gpr
= ar_reg
;
1532 vtx
.src_sel_x
= ar_chan
;
1533 vtx
.mega_fetch_count
= 16;
1534 vtx
.dst_gpr
= dst_reg
;
1535 vtx
.dst_sel_x
= 0; /* SEL_X */
1536 vtx
.dst_sel_y
= 1; /* SEL_Y */
1537 vtx
.dst_sel_z
= 2; /* SEL_Z */
1538 vtx
.dst_sel_w
= 3; /* SEL_W */
1539 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1540 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1541 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1542 vtx
.endian
= r600_endian_swap(32);
1543 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1545 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1551 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1553 struct r600_bytecode_vtx vtx
;
1555 unsigned index
= src
->Register
.Index
;
1556 unsigned vtx_id
= src
->Dimension
.Index
;
1557 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1558 int offset_chan
= vtx_id
% 3;
1561 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1562 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1564 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1567 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1568 t2
= r600_get_temp(ctx
);
1570 if (src
->Dimension
.Indirect
) {
1572 struct r600_bytecode_alu alu
;
1575 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1576 if (src
->DimIndirect
.Index
> 0) {
1577 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1585 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1586 at least this is what fglrx seems to do. */
1587 for (i
= 0; i
< 3; i
++) {
1588 treg
[i
] = r600_get_temp(ctx
);
1590 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1592 for (i
= 0; i
< 3; i
++) {
1593 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1594 alu
.op
= ALU_OP1_MOV
;
1595 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1596 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1597 alu
.dst
.sel
= treg
[i
];
1601 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1605 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1606 alu
.op
= ALU_OP1_MOV
;
1607 alu
.src
[0].sel
= treg
[0];
1612 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1619 if (src
->Register
.Indirect
) {
1621 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1623 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1625 /* pull the value from index_reg */
1626 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1629 V_SQ_ALU_SRC_LITERAL
, first
);
1632 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1635 V_SQ_ALU_SRC_LITERAL
, 4,
1636 offset_reg
, offset_chan
);
1641 index
= src
->Register
.Index
- first
;
1644 memset(&vtx
, 0, sizeof(vtx
));
1645 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1646 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1647 vtx
.src_gpr
= offset_reg
;
1648 vtx
.src_sel_x
= offset_chan
;
1649 vtx
.offset
= index
* 16; /*bytes*/
1650 vtx
.mega_fetch_count
= 16;
1651 vtx
.dst_gpr
= dst_reg
;
1652 vtx
.dst_sel_x
= 0; /* SEL_X */
1653 vtx
.dst_sel_y
= 1; /* SEL_Y */
1654 vtx
.dst_sel_z
= 2; /* SEL_Z */
1655 vtx
.dst_sel_w
= 3; /* SEL_W */
1656 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1657 vtx
.use_const_fields
= 1;
1659 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1662 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1668 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1670 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1673 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1674 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1676 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1677 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1678 /* primitive id is in R0.z */
1679 ctx
->src
[i
].sel
= 0;
1680 ctx
->src
[i
].swizzle
[0] = 2;
1683 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1684 int treg
= r600_get_temp(ctx
);
1686 fetch_gs_input(ctx
, src
, treg
);
1687 ctx
->src
[i
].sel
= treg
;
1688 ctx
->src
[i
].rel
= 0;
1695 /* Tessellation shaders pass outputs to the next shader using LDS.
1697 * LS outputs = TCS(HS) inputs
1698 * TCS(HS) outputs = TES(DS) inputs
1700 * The LDS layout is:
1701 * - TCS inputs for patch 0
1702 * - TCS inputs for patch 1
1703 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1705 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1706 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1707 * - TCS outputs for patch 1
1708 * - Per-patch TCS outputs for patch 1
1709 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1710 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1713 * All three shaders VS(LS), TCS, TES share the same LDS space.
1715 /* this will return with the dw address in temp_reg.x */
1716 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1717 const struct tgsi_full_dst_register
*dst
,
1718 const struct tgsi_full_src_register
*src
,
1719 int stride_bytes_reg
, int stride_bytes_chan
)
1721 struct tgsi_full_dst_register reg
;
1722 ubyte
*name
, *index
, *array_first
;
1725 struct tgsi_shader_info
*info
= &ctx
->info
;
1726 /* Set the register description. The address computation is the same
1727 * for sources and destinations. */
1729 reg
.Register
.File
= src
->Register
.File
;
1730 reg
.Register
.Index
= src
->Register
.Index
;
1731 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1732 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1733 reg
.Indirect
= src
->Indirect
;
1734 reg
.Dimension
= src
->Dimension
;
1735 reg
.DimIndirect
= src
->DimIndirect
;
1739 /* If the register is 2-dimensional (e.g. an array of vertices
1740 * in a primitive), calculate the base address of the vertex. */
1741 if (reg
.Register
.Dimension
) {
1743 if (reg
.Dimension
.Indirect
) {
1745 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1747 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1748 /* pull the value from index_reg */
1752 sel
= V_SQ_ALU_SRC_LITERAL
;
1753 chan
= reg
.Dimension
.Index
;
1756 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1758 stride_bytes_reg
, stride_bytes_chan
,
1765 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1766 name
= info
->input_semantic_name
;
1767 index
= info
->input_semantic_index
;
1768 array_first
= info
->input_array_first
;
1769 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1770 name
= info
->output_semantic_name
;
1771 index
= info
->output_semantic_index
;
1772 array_first
= info
->output_array_first
;
1777 if (reg
.Register
.Indirect
) {
1780 /* Add the relative address of the element. */
1781 if (reg
.Indirect
.ArrayID
)
1782 first
= array_first
[reg
.Indirect
.ArrayID
];
1784 first
= reg
.Register
.Index
;
1786 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
1788 /* pull the value from index_reg */
1789 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1791 V_SQ_ALU_SRC_LITERAL
, 16,
1797 param
= r600_get_lds_unique_index(name
[first
],
1801 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
1802 index
[reg
.Register
.Index
]);
1805 /* add to base_addr - passed in temp_reg.x */
1807 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1810 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1818 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
1819 unsigned dst_reg
, unsigned mask
)
1821 struct r600_bytecode_alu alu
;
1824 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
1825 ctx
->bc
->force_add_cf
= 1;
1827 lasti
= tgsi_last_instruction(mask
);
1828 for (i
= 1; i
<= lasti
; i
++) {
1829 if (!(mask
& (1 << i
)))
1832 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1835 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
1839 for (i
= 0; i
<= lasti
; i
++) {
1840 if (!(mask
& (1 << i
)))
1843 /* emit an LDS_READ_RET */
1844 memset(&alu
, 0, sizeof(alu
));
1845 alu
.op
= LDS_OP1_LDS_READ_RET
;
1846 alu
.src
[0].sel
= temp_reg
;
1847 alu
.src
[0].chan
= i
;
1848 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1849 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
1851 alu
.is_lds_idx_op
= true;
1853 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1857 for (i
= 0; i
<= lasti
; i
++) {
1858 if (!(mask
& (1 << i
)))
1861 /* then read from LDS_OQ_A_POP */
1862 memset(&alu
, 0, sizeof(alu
));
1864 alu
.op
= ALU_OP1_MOV
;
1865 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
1866 alu
.src
[0].chan
= 0;
1867 alu
.dst
.sel
= dst_reg
;
1871 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1878 static int fetch_mask(struct tgsi_src_register
*reg
)
1881 mask
|= 1 << reg
->SwizzleX
;
1882 mask
|= 1 << reg
->SwizzleY
;
1883 mask
|= 1 << reg
->SwizzleZ
;
1884 mask
|= 1 << reg
->SwizzleW
;
1888 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1891 unsigned temp_reg
= r600_get_temp(ctx
);
1893 r
= get_lds_offset0(ctx
, 2, temp_reg
,
1894 src
->Register
.Dimension
? false : true);
1898 /* the base address is now in temp.x */
1899 r
= r600_get_byte_address(ctx
, temp_reg
,
1900 NULL
, src
, ctx
->tess_output_info
, 1);
1904 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1910 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1913 unsigned temp_reg
= r600_get_temp(ctx
);
1915 /* t.x = ips * r0.y */
1916 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
1918 ctx
->tess_input_info
, 0,
1924 /* the base address is now in temp.x */
1925 r
= r600_get_byte_address(ctx
, temp_reg
,
1926 NULL
, src
, ctx
->tess_input_info
, 1);
1930 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1936 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1939 unsigned temp_reg
= r600_get_temp(ctx
);
1941 r
= get_lds_offset0(ctx
, 1, temp_reg
,
1942 src
->Register
.Dimension
? false : true);
1945 /* the base address is now in temp.x */
1946 r
= r600_get_byte_address(ctx
, temp_reg
,
1948 ctx
->tess_output_info
, 1);
1952 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1958 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
1960 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1963 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1964 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1966 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1967 int treg
= r600_get_temp(ctx
);
1968 fetch_tes_input(ctx
, src
, treg
);
1969 ctx
->src
[i
].sel
= treg
;
1970 ctx
->src
[i
].rel
= 0;
1972 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1973 int treg
= r600_get_temp(ctx
);
1974 fetch_tcs_input(ctx
, src
, treg
);
1975 ctx
->src
[i
].sel
= treg
;
1976 ctx
->src
[i
].rel
= 0;
1978 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
1979 int treg
= r600_get_temp(ctx
);
1980 fetch_tcs_output(ctx
, src
, treg
);
1981 ctx
->src
[i
].sel
= treg
;
1982 ctx
->src
[i
].rel
= 0;
1988 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1990 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1991 struct r600_bytecode_alu alu
;
1992 int i
, j
, k
, nconst
, r
;
1994 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1995 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1998 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
2000 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2001 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
2005 if (ctx
->src
[i
].rel
) {
2006 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
2007 int treg
= r600_get_temp(ctx
);
2008 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
2011 ctx
->src
[i
].kc_bank
= 0;
2012 ctx
->src
[i
].kc_rel
= 0;
2013 ctx
->src
[i
].sel
= treg
;
2014 ctx
->src
[i
].rel
= 0;
2017 int treg
= r600_get_temp(ctx
);
2018 for (k
= 0; k
< 4; k
++) {
2019 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2020 alu
.op
= ALU_OP1_MOV
;
2021 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2022 alu
.src
[0].chan
= k
;
2023 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
2024 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
2025 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
2031 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2035 ctx
->src
[i
].sel
= treg
;
2043 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
2044 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
2046 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2047 struct r600_bytecode_alu alu
;
2048 int i
, j
, k
, nliteral
, r
;
2050 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2051 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2055 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2056 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2057 int treg
= r600_get_temp(ctx
);
2058 for (k
= 0; k
< 4; k
++) {
2059 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2060 alu
.op
= ALU_OP1_MOV
;
2061 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2062 alu
.src
[0].chan
= k
;
2063 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
2069 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2073 ctx
->src
[i
].sel
= treg
;
2080 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
2082 int i
, r
, count
= ctx
->shader
->ninput
;
2084 for (i
= 0; i
< count
; i
++) {
2085 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2086 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
2094 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2095 int stream
, unsigned *stream_item_size UNUSED
)
2097 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2098 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2102 /* Sanity checking. */
2103 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2104 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2108 for (i
= 0; i
< so
->num_outputs
; i
++) {
2109 if (so
->output
[i
].output_buffer
>= 4) {
2110 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2111 so
->output
[i
].output_buffer
);
2117 /* Initialize locations where the outputs are stored. */
2118 for (i
= 0; i
< so
->num_outputs
; i
++) {
2120 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2121 start_comp
[i
] = so
->output
[i
].start_component
;
2122 /* Lower outputs with dst_offset < start_component.
2124 * We can only output 4D vectors with a write mask, e.g. we can
2125 * only output the W component at offset 3, etc. If we want
2126 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2127 * to move it to X and output X. */
2128 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2129 unsigned tmp
= r600_get_temp(ctx
);
2131 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2132 struct r600_bytecode_alu alu
;
2133 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2134 alu
.op
= ALU_OP1_MOV
;
2135 alu
.src
[0].sel
= so_gpr
[i
];
2136 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2141 if (j
== so
->output
[i
].num_components
- 1)
2143 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2152 /* Write outputs to buffers. */
2153 for (i
= 0; i
< so
->num_outputs
; i
++) {
2154 struct r600_bytecode_output output
;
2156 if (stream
!= -1 && stream
!= so
->output
[i
].output_buffer
)
2159 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2160 output
.gpr
= so_gpr
[i
];
2161 output
.elem_size
= so
->output
[i
].num_components
- 1;
2162 if (output
.elem_size
== 2)
2163 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2164 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2165 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2166 output
.burst_count
= 1;
2167 /* array_size is an upper limit for the burst_count
2168 * with MEM_STREAM instructions */
2169 output
.array_size
= 0xFFF;
2170 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2172 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2173 switch (so
->output
[i
].output_buffer
) {
2175 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2178 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2181 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2184 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2187 output
.op
+= so
->output
[i
].stream
* 4;
2188 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2189 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2191 switch (so
->output
[i
].output_buffer
) {
2193 output
.op
= CF_OP_MEM_STREAM0
;
2196 output
.op
= CF_OP_MEM_STREAM1
;
2199 output
.op
= CF_OP_MEM_STREAM2
;
2202 output
.op
= CF_OP_MEM_STREAM3
;
2205 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2207 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2216 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2218 struct r600_bytecode_alu alu
;
2221 if (!ctx
->shader
->vs_out_edgeflag
)
2224 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2226 /* clamp(x, 0, 1) */
2227 memset(&alu
, 0, sizeof(alu
));
2228 alu
.op
= ALU_OP1_MOV
;
2229 alu
.src
[0].sel
= reg
;
2234 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2236 memset(&alu
, 0, sizeof(alu
));
2237 alu
.op
= ALU_OP1_FLT_TO_INT
;
2238 alu
.src
[0].sel
= reg
;
2242 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2245 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2246 struct r600_pipe_shader
*gs
,
2247 struct pipe_stream_output_info
*so
)
2249 struct r600_shader_ctx ctx
= {};
2250 struct r600_shader
*gs_shader
= &gs
->shader
;
2251 struct r600_pipe_shader
*cshader
;
2252 unsigned ocnt
= gs_shader
->noutput
;
2253 struct r600_bytecode_alu alu
;
2254 struct r600_bytecode_vtx vtx
;
2255 struct r600_bytecode_output output
;
2256 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2257 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2258 int next_clip_pos
= 61, next_param
= 0;
2261 bool only_ring_0
= true;
2262 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2266 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2267 sizeof(struct r600_shader_io
));
2269 cshader
->shader
.noutput
= ocnt
;
2271 ctx
.shader
= &cshader
->shader
;
2272 ctx
.bc
= &ctx
.shader
->bc
;
2273 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2275 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2276 rctx
->screen
->has_compressed_msaa_texturing
);
2278 ctx
.bc
->isa
= rctx
->isa
;
2281 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2283 /* R0.x = R0.x & 0x3fffffff */
2284 memset(&alu
, 0, sizeof(alu
));
2285 alu
.op
= ALU_OP2_AND_INT
;
2286 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2287 alu
.src
[1].value
= 0x3fffffff;
2289 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2291 /* R0.y = R0.x >> 30 */
2292 memset(&alu
, 0, sizeof(alu
));
2293 alu
.op
= ALU_OP2_LSHR_INT
;
2294 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2295 alu
.src
[1].value
= 0x1e;
2299 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2301 /* fetch vertex data from GSVS ring */
2302 for (i
= 0; i
< ocnt
; ++i
) {
2303 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2306 out
->ring_offset
= i
* 16;
2308 memset(&vtx
, 0, sizeof(vtx
));
2309 vtx
.op
= FETCH_OP_VFETCH
;
2310 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2311 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2312 vtx
.mega_fetch_count
= 16;
2313 vtx
.offset
= out
->ring_offset
;
2314 vtx
.dst_gpr
= out
->gpr
;
2320 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2321 vtx
.use_const_fields
= 1;
2323 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2326 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2328 ctx
.temp_reg
= i
+ 1;
2329 for (ring
= 3; ring
>= 0; --ring
) {
2330 bool enabled
= false;
2331 for (i
= 0; i
< so
->num_outputs
; i
++) {
2332 if (so
->output
[i
].stream
== ring
) {
2335 only_ring_0
= false;
2339 if (ring
!= 0 && !enabled
) {
2340 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2345 // Patch up jump label
2346 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2347 cf_pop
= ctx
.bc
->cf_last
;
2349 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2350 cf_jump
->pop_count
= 1;
2351 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2352 cf_pop
->pop_count
= 1;
2355 /* PRED_SETE_INT __, R0.y, ring */
2356 memset(&alu
, 0, sizeof(alu
));
2357 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2358 alu
.src
[0].chan
= 1;
2359 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2360 alu
.src
[1].value
= ring
;
2361 alu
.execute_mask
= 1;
2362 alu
.update_pred
= 1;
2364 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2366 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2367 cf_jump
= ctx
.bc
->cf_last
;
2370 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2371 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2374 /* bc adds nops - copy it */
2375 if (ctx
.bc
->chip_class
== R600
) {
2376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2377 alu
.op
= ALU_OP0_NOP
;
2379 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2381 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2384 /* export vertex data */
2385 /* XXX factor out common code with r600_shader_from_tgsi ? */
2386 for (i
= 0; i
< ocnt
; ++i
) {
2387 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2388 bool instream0
= true;
2389 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2392 for (j
= 0; j
< so
->num_outputs
; j
++) {
2393 if (so
->output
[j
].register_index
== i
) {
2394 if (so
->output
[j
].stream
== 0)
2396 if (so
->output
[j
].stream
> 0)
2402 memset(&output
, 0, sizeof(output
));
2403 output
.gpr
= out
->gpr
;
2404 output
.elem_size
= 3;
2405 output
.swizzle_x
= 0;
2406 output
.swizzle_y
= 1;
2407 output
.swizzle_z
= 2;
2408 output
.swizzle_w
= 3;
2409 output
.burst_count
= 1;
2410 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2411 output
.op
= CF_OP_EXPORT
;
2412 switch (out
->name
) {
2413 case TGSI_SEMANTIC_POSITION
:
2414 output
.array_base
= 60;
2415 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2418 case TGSI_SEMANTIC_PSIZE
:
2419 output
.array_base
= 61;
2420 if (next_clip_pos
== 61)
2422 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2423 output
.swizzle_y
= 7;
2424 output
.swizzle_z
= 7;
2425 output
.swizzle_w
= 7;
2426 ctx
.shader
->vs_out_misc_write
= 1;
2427 ctx
.shader
->vs_out_point_size
= 1;
2429 case TGSI_SEMANTIC_LAYER
:
2431 /* duplicate it as PARAM to pass to the pixel shader */
2432 output
.array_base
= next_param
++;
2433 r600_bytecode_add_output(ctx
.bc
, &output
);
2434 last_exp_param
= ctx
.bc
->cf_last
;
2436 output
.array_base
= 61;
2437 if (next_clip_pos
== 61)
2439 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2440 output
.swizzle_x
= 7;
2441 output
.swizzle_y
= 7;
2442 output
.swizzle_z
= 0;
2443 output
.swizzle_w
= 7;
2444 ctx
.shader
->vs_out_misc_write
= 1;
2445 ctx
.shader
->vs_out_layer
= 1;
2447 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2449 /* duplicate it as PARAM to pass to the pixel shader */
2450 output
.array_base
= next_param
++;
2451 r600_bytecode_add_output(ctx
.bc
, &output
);
2452 last_exp_param
= ctx
.bc
->cf_last
;
2454 output
.array_base
= 61;
2455 if (next_clip_pos
== 61)
2457 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2458 ctx
.shader
->vs_out_misc_write
= 1;
2459 ctx
.shader
->vs_out_viewport
= 1;
2460 output
.swizzle_x
= 7;
2461 output
.swizzle_y
= 7;
2462 output
.swizzle_z
= 7;
2463 output
.swizzle_w
= 0;
2465 case TGSI_SEMANTIC_CLIPDIST
:
2466 /* spi_sid is 0 for clipdistance outputs that were generated
2467 * for clipvertex - we don't need to pass them to PS */
2468 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2469 ctx
.shader
->cull_dist_write
= gs
->shader
.cull_dist_write
;
2470 ctx
.shader
->cc_dist_mask
= gs
->shader
.cc_dist_mask
;
2472 /* duplicate it as PARAM to pass to the pixel shader */
2473 output
.array_base
= next_param
++;
2474 r600_bytecode_add_output(ctx
.bc
, &output
);
2475 last_exp_param
= ctx
.bc
->cf_last
;
2477 output
.array_base
= next_clip_pos
++;
2478 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2480 case TGSI_SEMANTIC_FOG
:
2481 output
.swizzle_y
= 4; /* 0 */
2482 output
.swizzle_z
= 4; /* 0 */
2483 output
.swizzle_w
= 5; /* 1 */
2486 output
.array_base
= next_param
++;
2489 r600_bytecode_add_output(ctx
.bc
, &output
);
2490 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2491 last_exp_param
= ctx
.bc
->cf_last
;
2493 last_exp_pos
= ctx
.bc
->cf_last
;
2496 if (!last_exp_pos
) {
2497 memset(&output
, 0, sizeof(output
));
2499 output
.elem_size
= 3;
2500 output
.swizzle_x
= 7;
2501 output
.swizzle_y
= 7;
2502 output
.swizzle_z
= 7;
2503 output
.swizzle_w
= 7;
2504 output
.burst_count
= 1;
2506 output
.op
= CF_OP_EXPORT
;
2507 output
.array_base
= 60;
2508 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2509 r600_bytecode_add_output(ctx
.bc
, &output
);
2510 last_exp_pos
= ctx
.bc
->cf_last
;
2513 if (!last_exp_param
) {
2514 memset(&output
, 0, sizeof(output
));
2516 output
.elem_size
= 3;
2517 output
.swizzle_x
= 7;
2518 output
.swizzle_y
= 7;
2519 output
.swizzle_z
= 7;
2520 output
.swizzle_w
= 7;
2521 output
.burst_count
= 1;
2523 output
.op
= CF_OP_EXPORT
;
2524 output
.array_base
= next_param
++;
2525 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2526 r600_bytecode_add_output(ctx
.bc
, &output
);
2527 last_exp_param
= ctx
.bc
->cf_last
;
2530 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2531 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2533 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2534 cf_pop
= ctx
.bc
->cf_last
;
2536 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2537 cf_jump
->pop_count
= 1;
2538 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2539 cf_pop
->pop_count
= 1;
2541 if (ctx
.bc
->chip_class
== CAYMAN
)
2542 cm_bytecode_add_cf_end(ctx
.bc
);
2544 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2545 ctx
.bc
->cf_last
->end_of_program
= 1;
2548 gs
->gs_copy_shader
= cshader
;
2549 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2553 return r600_bytecode_build(ctx
.bc
);
2556 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2559 struct r600_bytecode_alu alu
;
2562 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2563 alu
.op
= ALU_OP2_ADD_INT
;
2564 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2565 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2566 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2567 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2570 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2577 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so UNUSED
, int stream
, bool ind
)
2579 struct r600_bytecode_output output
;
2582 int effective_stream
= stream
== -1 ? 0 : stream
;
2585 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2586 if (ctx
->gs_for_vs
) {
2587 /* for ES we need to lookup corresponding ring offset expected by GS
2588 * (map this output to GS input by name and sid) */
2589 /* FIXME precompute offsets */
2591 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2592 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2593 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2594 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2595 ring_offset
= in
->ring_offset
;
2598 if (ring_offset
== -1)
2601 ring_offset
= idx
* 16;
2605 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2607 /* next_ring_offset after parsing input decls contains total size of
2608 * single vertex data, gs_next_vertex - current vertex index */
2610 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2612 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2613 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2614 output
.elem_size
= 3;
2615 output
.comp_mask
= 0xF;
2616 output
.burst_count
= 1;
2619 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2621 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2626 output
.op
= CF_OP_MEM_RING
; break;
2628 output
.op
= CF_OP_MEM_RING1
; break;
2630 output
.op
= CF_OP_MEM_RING2
; break;
2632 output
.op
= CF_OP_MEM_RING3
; break;
2636 output
.array_base
= ring_offset
>> 2; /* in dwords */
2637 output
.array_size
= 0xfff;
2638 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2640 output
.array_base
= ring_offset
>> 2; /* in dwords */
2641 r600_bytecode_add_output(ctx
->bc
, &output
);
2644 ++ctx
->gs_next_vertex
;
2649 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2652 struct r600_bytecode_vtx vtx
;
2653 int temp_val
= ctx
->temp_reg
;
2654 /* need to store the TCS output somewhere */
2655 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2657 V_SQ_ALU_SRC_LITERAL
, 0,
2662 /* used by VS/TCS */
2663 if (ctx
->tess_input_info
) {
2664 /* fetch tcs input values into resv space */
2665 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2666 vtx
.op
= FETCH_OP_VFETCH
;
2667 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2668 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2669 vtx
.mega_fetch_count
= 16;
2670 vtx
.data_format
= FMT_32_32_32_32
;
2671 vtx
.num_format_all
= 2;
2672 vtx
.format_comp_all
= 1;
2673 vtx
.use_const_fields
= 0;
2674 vtx
.endian
= r600_endian_swap(32);
2675 vtx
.srf_mode_all
= 1;
2677 vtx
.dst_gpr
= ctx
->tess_input_info
;
2682 vtx
.src_gpr
= temp_val
;
2685 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2690 /* used by TCS/TES */
2691 if (ctx
->tess_output_info
) {
2692 /* fetch tcs output values into resv space */
2693 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2694 vtx
.op
= FETCH_OP_VFETCH
;
2695 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2696 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2697 vtx
.mega_fetch_count
= 16;
2698 vtx
.data_format
= FMT_32_32_32_32
;
2699 vtx
.num_format_all
= 2;
2700 vtx
.format_comp_all
= 1;
2701 vtx
.use_const_fields
= 0;
2702 vtx
.endian
= r600_endian_swap(32);
2703 vtx
.srf_mode_all
= 1;
2705 vtx
.dst_gpr
= ctx
->tess_output_info
;
2710 vtx
.src_gpr
= temp_val
;
2713 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2720 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2726 /* fetch tcs input values into input_vals */
2727 ctx
->tess_input_info
= r600_get_temp(ctx
);
2728 ctx
->tess_output_info
= 0;
2729 r
= r600_fetch_tess_io_info(ctx
);
2733 temp_reg
= r600_get_temp(ctx
);
2734 /* dst reg contains LDS address stride * idx */
2735 /* MUL vertexID, vertex_dw_stride */
2736 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2738 ctx
->tess_input_info
, 1,
2739 0, 1); /* rel id in r0.y? */
2743 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2744 struct r600_bytecode_alu alu
;
2745 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2748 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2751 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2756 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2758 temp_reg
, param
? 1 : 0,
2759 V_SQ_ALU_SRC_LITERAL
, 8);
2764 for (j
= 0; j
< 2; j
++) {
2765 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2766 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2767 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2768 alu
.src
[0].sel
= temp_reg
;
2769 alu
.src
[0].chan
= chan
;
2770 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2771 alu
.src
[1].chan
= j
* 2;
2772 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2773 alu
.src
[2].chan
= (j
* 2) + 1;
2777 alu
.is_lds_idx_op
= true;
2778 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2786 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
2788 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2789 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
2791 int temp_reg
= r600_get_temp(ctx
);
2792 struct r600_bytecode_alu alu
;
2793 unsigned write_mask
= dst
->Register
.WriteMask
;
2795 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
2798 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
2802 /* the base address is now in temp.x */
2803 r
= r600_get_byte_address(ctx
, temp_reg
,
2804 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
2809 lasti
= tgsi_last_instruction(write_mask
);
2810 for (i
= 1; i
<= lasti
; i
++) {
2812 if (!(write_mask
& (1 << i
)))
2814 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2817 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2822 for (i
= 0; i
<= lasti
; i
++) {
2823 if (!(write_mask
& (1 << i
)))
2826 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
2827 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
2828 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2829 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2830 alu
.src
[0].sel
= temp_reg
;
2831 alu
.src
[0].chan
= i
;
2833 alu
.src
[1].sel
= dst
->Register
.Index
;
2834 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2835 alu
.src
[1].chan
= i
;
2837 alu
.src
[2].sel
= dst
->Register
.Index
;
2838 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2839 alu
.src
[2].chan
= i
+ 1;
2843 alu
.is_lds_idx_op
= true;
2844 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2850 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2851 alu
.op
= LDS_OP2_LDS_WRITE
;
2852 alu
.src
[0].sel
= temp_reg
;
2853 alu
.src
[0].chan
= i
;
2855 alu
.src
[1].sel
= dst
->Register
.Index
;
2856 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2857 alu
.src
[1].chan
= i
;
2859 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2862 alu
.is_lds_idx_op
= true;
2863 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2870 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
2874 unsigned temp_reg
= r600_get_temp(ctx
);
2875 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
2876 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
2879 param
= r600_get_lds_unique_index(name
, 0);
2880 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
2884 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2887 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2891 do_lds_fetch_values(ctx
, temp_reg
, dreg
, 0xf);
2895 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
2897 int stride
, outer_comps
, inner_comps
;
2898 int tessinner_idx
= -1, tessouter_idx
= -1;
2901 int temp_reg
= r600_get_temp(ctx
);
2902 int treg
[3] = {-1, -1, -1};
2903 struct r600_bytecode_alu alu
;
2904 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
2906 /* only execute factor emission for invocation 0 */
2907 /* PRED_SETE_INT __, R0.x, 0 */
2908 memset(&alu
, 0, sizeof(alu
));
2909 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2910 alu
.src
[0].chan
= 2;
2911 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2912 alu
.execute_mask
= 1;
2913 alu
.update_pred
= 1;
2915 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2917 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
2918 cf_jump
= ctx
->bc
->cf_last
;
2920 treg
[0] = r600_get_temp(ctx
);
2921 switch (ctx
->shader
->tcs_prim_mode
) {
2922 case PIPE_PRIM_LINES
:
2923 stride
= 8; /* 2 dwords, 1 vec2 store */
2927 case PIPE_PRIM_TRIANGLES
:
2928 stride
= 16; /* 4 dwords, 1 vec4 store */
2931 treg
[1] = r600_get_temp(ctx
);
2933 case PIPE_PRIM_QUADS
:
2934 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
2937 treg
[1] = r600_get_temp(ctx
);
2938 treg
[2] = r600_get_temp(ctx
);
2945 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
2946 /* TF_WRITE takes index in R.x, value in R.y */
2947 for (j
= 0; j
< ctx
->shader
->noutput
; j
++) {
2948 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSINNER
)
2950 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSOUTER
)
2954 if (tessouter_idx
== -1)
2957 if (tessinner_idx
== -1 && inner_comps
)
2960 if (tessouter_idx
!= -1) {
2961 r
= r600_tess_factor_read(ctx
, tessouter_idx
);
2966 if (tessinner_idx
!= -1) {
2967 r
= r600_tess_factor_read(ctx
, tessinner_idx
);
2972 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
2973 /* r.x = relpatchid(r0.y) * tf_stride */
2975 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
2976 /* add incoming r0.w to it: t.x = t.x + r0.w */
2977 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2980 V_SQ_ALU_SRC_LITERAL
, stride
,
2985 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2986 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
2987 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
2989 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
2992 else if (out_comp
== 0)
2996 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2997 treg
[i
/ 2], (2 * (i
% 2)),
2999 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
3002 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
3003 treg
[i
/ 2], 1 + (2 * (i
%2)),
3004 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
3009 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
3010 struct r600_bytecode_gds gds
;
3012 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
3013 gds
.src_gpr
= treg
[i
/ 2];
3014 gds
.src_sel_x
= 2 * (i
% 2);
3015 gds
.src_sel_y
= 1 + (2 * (i
% 2));
3021 gds
.op
= FETCH_OP_TF_WRITE
;
3022 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
3027 // Patch up jump label
3028 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
3029 cf_pop
= ctx
->bc
->cf_last
;
3031 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
3032 cf_jump
->pop_count
= 1;
3033 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
3034 cf_pop
->pop_count
= 1;
3040 * We have to work out the thread ID for load and atomic
3041 * operations, which store the returned value to an index
3042 * in an intermediate buffer.
3043 * The index is calculated by taking the thread id,
3044 * calculated from the MBCNT instructions.
3045 * Then the shader engine ID is multiplied by 256,
3046 * and the wave id is added.
3047 * Then the result is multipled by 64 and thread id is
3050 static int load_thread_id_gpr(struct r600_shader_ctx
*ctx
)
3052 struct r600_bytecode_alu alu
;
3055 if (ctx
->thread_id_gpr_loaded
)
3058 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3059 alu
.op
= ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT
;
3060 alu
.dst
.sel
= ctx
->temp_reg
;
3062 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3063 alu
.src
[0].value
= 0xffffffff;
3065 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3069 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3070 alu
.op
= ALU_OP1_MBCNT_32HI_INT
;
3071 alu
.dst
.sel
= ctx
->temp_reg
;
3073 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3074 alu
.src
[0].value
= 0xffffffff;
3076 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3080 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3081 alu
.op
= ALU_OP3_MULADD_UINT24
;
3082 alu
.dst
.sel
= ctx
->temp_reg
;
3084 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_SE_ID
;
3085 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3086 alu
.src
[1].value
= 256;
3087 alu
.src
[2].sel
= EG_V_SQ_ALU_SRC_HW_WAVE_ID
;
3091 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3095 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3096 ctx
->thread_id_gpr
, 1,
3098 V_SQ_ALU_SRC_LITERAL
, 0x40,
3102 ctx
->thread_id_gpr_loaded
= true;
3106 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
3107 struct r600_pipe_shader
*pipeshader
,
3108 union r600_shader_key key
)
3110 struct r600_screen
*rscreen
= rctx
->screen
;
3111 struct r600_shader
*shader
= &pipeshader
->shader
;
3112 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
3113 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
3114 struct tgsi_full_immediate
*immediate
;
3115 struct r600_shader_ctx ctx
;
3116 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
3117 unsigned output_done
, noutput
;
3121 int next_param_base
= 0, next_clip_base
;
3122 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
3124 bool ring_outputs
= false;
3125 bool lds_outputs
= false;
3126 bool lds_inputs
= false;
3127 bool pos_emitted
= false;
3129 ctx
.bc
= &shader
->bc
;
3130 ctx
.shader
= shader
;
3131 ctx
.native_integers
= true;
3133 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
3134 rscreen
->has_compressed_msaa_texturing
);
3135 ctx
.tokens
= tokens
;
3136 tgsi_scan_shader(tokens
, &ctx
.info
);
3137 shader
->indirect_files
= ctx
.info
.indirect_files
;
3139 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
3140 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
3141 shader
->nsys_inputs
= 0;
3143 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0 ||
3144 ctx
.info
.file_count
[TGSI_FILE_BUFFER
] > 0;
3145 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
3146 tgsi_parse_init(&ctx
.parse
, tokens
);
3147 ctx
.type
= ctx
.info
.processor
;
3148 shader
->processor_type
= ctx
.type
;
3149 ctx
.bc
->type
= shader
->processor_type
;
3152 case PIPE_SHADER_VERTEX
:
3153 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
3154 shader
->vs_as_es
= key
.vs
.as_es
;
3155 shader
->vs_as_ls
= key
.vs
.as_ls
;
3156 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
3157 if (shader
->vs_as_es
)
3158 ring_outputs
= true;
3159 if (shader
->vs_as_ls
)
3162 case PIPE_SHADER_GEOMETRY
:
3163 ring_outputs
= true;
3164 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
3165 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
3167 case PIPE_SHADER_TESS_CTRL
:
3168 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
3169 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3173 case PIPE_SHADER_TESS_EVAL
:
3174 shader
->tes_as_es
= key
.tes
.as_es
;
3175 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3177 if (shader
->tes_as_es
)
3178 ring_outputs
= true;
3180 case PIPE_SHADER_FRAGMENT
:
3181 shader
->two_side
= key
.ps
.color_two_side
;
3182 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3183 shader
->rat_base
= key
.ps
.nr_cbufs
;
3184 shader
->image_size_const_offset
= key
.ps
.image_size_const_offset
;
3186 case PIPE_SHADER_COMPUTE
:
3187 shader
->rat_base
= 0;
3188 shader
->image_size_const_offset
= 0;
3194 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3195 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3197 ctx
.gs_for_vs
= NULL
;
3200 ctx
.next_ring_offset
= 0;
3201 ctx
.gs_out_ring_offset
= 0;
3202 ctx
.gs_next_vertex
= 0;
3203 ctx
.gs_stream_output_info
= &so
;
3206 ctx
.fixed_pt_position_gpr
= -1;
3207 ctx
.fragcoord_input
= -1;
3208 ctx
.colors_used
= 0;
3209 ctx
.clip_vertex_write
= 0;
3210 ctx
.thread_id_gpr_loaded
= false;
3212 ctx
.cs_block_size_reg
= -1;
3213 ctx
.cs_grid_size_reg
= -1;
3214 ctx
.cs_block_size_loaded
= false;
3215 ctx
.cs_grid_size_loaded
= false;
3217 shader
->nr_ps_color_exports
= 0;
3218 shader
->nr_ps_max_color_exports
= 0;
3221 /* register allocations */
3222 /* Values [0,127] correspond to GPR[0..127].
3223 * Values [128,159] correspond to constant buffer bank 0
3224 * Values [160,191] correspond to constant buffer bank 1
3225 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3226 * Values [256,287] correspond to constant buffer bank 2 (EG)
3227 * Values [288,319] correspond to constant buffer bank 3 (EG)
3228 * Other special values are shown in the list below.
3229 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3230 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3231 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3232 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3233 * 248 SQ_ALU_SRC_0: special constant 0.0.
3234 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3235 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3236 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3237 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3238 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3239 * 254 SQ_ALU_SRC_PV: previous vector result.
3240 * 255 SQ_ALU_SRC_PS: previous scalar result.
3242 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3243 ctx
.file_offset
[i
] = 0;
3246 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3248 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3249 if (ctx
.info
.num_inputs
)
3250 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3252 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3253 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3254 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3256 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3258 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3259 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3260 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3262 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3263 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3264 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3265 bool add_tesscoord
= false, add_tess_inout
= false;
3266 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3267 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3268 /* if we have tesscoord save one reg */
3269 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3270 add_tesscoord
= true;
3271 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3272 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3273 add_tess_inout
= true;
3275 if (add_tesscoord
|| add_tess_inout
)
3276 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3278 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3280 if (ctx
.type
== PIPE_SHADER_COMPUTE
) {
3281 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3282 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3283 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_GRID_SIZE
)
3284 ctx
.cs_grid_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3285 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_BLOCK_SIZE
)
3286 ctx
.cs_block_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3290 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3291 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3292 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3293 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3294 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3296 /* Outside the GPR range. This will be translated to one of the
3297 * kcache banks later. */
3298 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3300 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3301 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3302 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
3303 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
3304 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
3306 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3307 ctx
.tess_input_info
= ctx
.bc
->ar_reg
+ 3;
3308 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 4;
3309 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 5;
3310 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3311 ctx
.tess_input_info
= 0;
3312 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 3;
3313 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 4;
3314 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3315 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
3316 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
3317 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
3318 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
3319 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
3320 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3321 ctx
.gs_rotated_input
[0] = ctx
.bc
->ar_reg
+ 7;
3322 ctx
.gs_rotated_input
[1] = ctx
.bc
->ar_reg
+ 8;
3325 ctx
.gs_rotated_input
[0] = 0;
3326 ctx
.gs_rotated_input
[1] = 1;
3329 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
3332 if (shader
->uses_images
) {
3333 ctx
.thread_id_gpr
= ctx
.temp_reg
++;
3334 ctx
.thread_id_gpr_loaded
= false;
3337 shader
->max_arrays
= 0;
3338 shader
->num_arrays
= 0;
3339 if (indirect_gprs
) {
3341 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3342 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3343 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3344 ctx
.file_offset
[TGSI_FILE_INPUT
],
3347 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3348 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3349 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3350 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3356 ctx
.literals
= NULL
;
3358 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3359 ctx
.info
.colors_written
== 1;
3360 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3361 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3363 if (ctx
.type
== PIPE_SHADER_VERTEX
||
3364 ctx
.type
== PIPE_SHADER_GEOMETRY
||
3365 ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3366 shader
->cc_dist_mask
= (1 << (ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
] +
3367 ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
])) - 1;
3368 shader
->clip_dist_write
= (1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
]) - 1;
3369 shader
->cull_dist_write
= ((1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
]) - 1) << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
];
3372 if (shader
->vs_as_gs_a
)
3373 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3375 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3376 r600_fetch_tess_io_info(&ctx
);
3378 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3379 tgsi_parse_token(&ctx
.parse
);
3380 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3381 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3382 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3383 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3384 if(ctx
.literals
== NULL
) {
3388 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3389 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3390 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3391 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3394 case TGSI_TOKEN_TYPE_DECLARATION
:
3395 r
= tgsi_declaration(&ctx
);
3399 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3400 case TGSI_TOKEN_TYPE_PROPERTY
:
3403 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3409 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3410 shader
->ring_item_sizes
[1] = 0;
3411 shader
->ring_item_sizes
[2] = 0;
3412 shader
->ring_item_sizes
[3] = 0;
3414 /* Process two side if needed */
3415 if (shader
->two_side
&& ctx
.colors_used
) {
3416 int i
, count
= ctx
.shader
->ninput
;
3417 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3419 /* additional inputs will be allocated right after the existing inputs,
3420 * we won't need them after the color selection, so we don't need to
3421 * reserve these gprs for the rest of the shader code and to adjust
3422 * output offsets etc. */
3423 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3424 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3426 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3427 if (ctx
.face_gpr
== -1) {
3428 i
= ctx
.shader
->ninput
++;
3429 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3430 ctx
.shader
->input
[i
].spi_sid
= 0;
3431 ctx
.shader
->input
[i
].gpr
= gpr
++;
3432 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3435 for (i
= 0; i
< count
; i
++) {
3436 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3437 int ni
= ctx
.shader
->ninput
++;
3438 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3439 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3440 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3441 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3442 // TGSI to LLVM needs to know the lds position of inputs.
3443 // Non LLVM path computes it later (in process_twoside_color)
3444 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3445 ctx
.shader
->input
[i
].back_color_input
= ni
;
3446 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3447 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3454 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3455 shader
->nr_ps_max_color_exports
= 8;
3457 if (ctx
.fragcoord_input
>= 0) {
3458 if (ctx
.bc
->chip_class
== CAYMAN
) {
3459 for (j
= 0 ; j
< 4; j
++) {
3460 struct r600_bytecode_alu alu
;
3461 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3462 alu
.op
= ALU_OP1_RECIP_IEEE
;
3463 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3464 alu
.src
[0].chan
= 3;
3466 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3468 alu
.dst
.write
= (j
== 3);
3470 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3474 struct r600_bytecode_alu alu
;
3475 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3476 alu
.op
= ALU_OP1_RECIP_IEEE
;
3477 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3478 alu
.src
[0].chan
= 3;
3480 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3484 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3489 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3490 struct r600_bytecode_alu alu
;
3493 /* GS thread with no output workaround - emit a cut at start of GS */
3494 if (ctx
.bc
->chip_class
== R600
)
3495 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3497 for (j
= 0; j
< 4; j
++) {
3498 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3499 alu
.op
= ALU_OP1_MOV
;
3500 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3501 alu
.src
[0].value
= 0;
3502 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3505 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3510 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3511 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3512 ctx
.gs_rotated_input
[0], 2,
3514 V_SQ_ALU_SRC_LITERAL
, 1);
3518 for (i
= 0; i
< 6; i
++) {
3519 int rotated
= (i
+ 4) % 6;
3520 int offset_reg
= i
/ 3;
3521 int offset_chan
= i
% 3;
3522 int rotated_offset_reg
= rotated
/ 3;
3523 int rotated_offset_chan
= rotated
% 3;
3525 if (offset_reg
== 0 && offset_chan
== 2)
3527 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3528 rotated_offset_chan
= 3;
3530 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3531 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3532 ctx
.gs_rotated_input
[0], 2,
3533 offset_reg
, offset_chan
,
3534 rotated_offset_reg
, rotated_offset_chan
);
3541 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3542 r600_fetch_tess_io_info(&ctx
);
3544 if (shader
->two_side
&& ctx
.colors_used
) {
3545 if ((r
= process_twoside_color_inputs(&ctx
)))
3549 tgsi_parse_init(&ctx
.parse
, tokens
);
3550 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3551 tgsi_parse_token(&ctx
.parse
);
3552 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3553 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3554 r
= tgsi_is_supported(&ctx
);
3557 ctx
.max_driver_temp_used
= 0;
3558 /* reserve first tmp for everyone */
3559 r600_get_temp(&ctx
);
3561 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3562 if ((r
= tgsi_split_constant(&ctx
)))
3564 if ((r
= tgsi_split_literal_constant(&ctx
)))
3566 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3567 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3569 } else if (lds_inputs
) {
3570 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3573 if (ctx
.bc
->chip_class
== CAYMAN
)
3574 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3575 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3576 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3578 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3579 r
= ctx
.inst_info
->process(&ctx
);
3583 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3584 r
= r600_store_tcs_output(&ctx
);
3594 /* Reset the temporary register counter. */
3595 ctx
.max_driver_temp_used
= 0;
3597 noutput
= shader
->noutput
;
3599 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3600 unsigned clipdist_temp
[2];
3602 clipdist_temp
[0] = r600_get_temp(&ctx
);
3603 clipdist_temp
[1] = r600_get_temp(&ctx
);
3605 /* need to convert a clipvertex write into clipdistance writes and not export
3606 the clip vertex anymore */
3608 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3609 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3610 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3612 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3613 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3616 /* reset spi_sid for clipvertex output to avoid confusing spi */
3617 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3619 shader
->clip_dist_write
= 0xFF;
3620 shader
->cc_dist_mask
= 0xFF;
3622 for (i
= 0; i
< 8; i
++) {
3626 for (j
= 0; j
< 4; j
++) {
3627 struct r600_bytecode_alu alu
;
3628 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3629 alu
.op
= ALU_OP2_DOT4
;
3630 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3631 alu
.src
[0].chan
= j
;
3633 alu
.src
[1].sel
= 512 + i
;
3634 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3635 alu
.src
[1].chan
= j
;
3637 alu
.dst
.sel
= clipdist_temp
[oreg
];
3639 alu
.dst
.write
= (j
== ochan
);
3642 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3649 /* Add stream outputs. */
3650 if (so
.num_outputs
) {
3652 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3654 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3657 emit_streamout(&ctx
, &so
, -1, NULL
);
3659 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3660 convert_edgeflag_to_int(&ctx
);
3662 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3663 r600_emit_tess_factor(&ctx
);
3666 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3667 if (ctx
.shader
->noutput
)
3668 emit_lds_vs_writes(&ctx
);
3670 } else if (ring_outputs
) {
3671 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3672 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3673 ctx
.gs_export_gpr_tregs
[1] = -1;
3674 ctx
.gs_export_gpr_tregs
[2] = -1;
3675 ctx
.gs_export_gpr_tregs
[3] = -1;
3677 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3681 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3683 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3684 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3685 output
[j
].gpr
= shader
->output
[i
].gpr
;
3686 output
[j
].elem_size
= 3;
3687 output
[j
].swizzle_x
= 0;
3688 output
[j
].swizzle_y
= 1;
3689 output
[j
].swizzle_z
= 2;
3690 output
[j
].swizzle_w
= 3;
3691 output
[j
].burst_count
= 1;
3692 output
[j
].type
= 0xffffffff;
3693 output
[j
].op
= CF_OP_EXPORT
;
3695 case PIPE_SHADER_VERTEX
:
3696 case PIPE_SHADER_TESS_EVAL
:
3697 switch (shader
->output
[i
].name
) {
3698 case TGSI_SEMANTIC_POSITION
:
3699 output
[j
].array_base
= 60;
3700 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3704 case TGSI_SEMANTIC_PSIZE
:
3705 output
[j
].array_base
= 61;
3706 output
[j
].swizzle_y
= 7;
3707 output
[j
].swizzle_z
= 7;
3708 output
[j
].swizzle_w
= 7;
3709 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3712 case TGSI_SEMANTIC_EDGEFLAG
:
3713 output
[j
].array_base
= 61;
3714 output
[j
].swizzle_x
= 7;
3715 output
[j
].swizzle_y
= 0;
3716 output
[j
].swizzle_z
= 7;
3717 output
[j
].swizzle_w
= 7;
3718 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3721 case TGSI_SEMANTIC_LAYER
:
3722 /* spi_sid is 0 for outputs that are
3723 * not consumed by PS */
3724 if (shader
->output
[i
].spi_sid
) {
3725 output
[j
].array_base
= next_param_base
++;
3726 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3728 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3730 output
[j
].array_base
= 61;
3731 output
[j
].swizzle_x
= 7;
3732 output
[j
].swizzle_y
= 7;
3733 output
[j
].swizzle_z
= 0;
3734 output
[j
].swizzle_w
= 7;
3735 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3738 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3739 /* spi_sid is 0 for outputs that are
3740 * not consumed by PS */
3741 if (shader
->output
[i
].spi_sid
) {
3742 output
[j
].array_base
= next_param_base
++;
3743 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3745 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3747 output
[j
].array_base
= 61;
3748 output
[j
].swizzle_x
= 7;
3749 output
[j
].swizzle_y
= 7;
3750 output
[j
].swizzle_z
= 7;
3751 output
[j
].swizzle_w
= 0;
3752 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3755 case TGSI_SEMANTIC_CLIPVERTEX
:
3758 case TGSI_SEMANTIC_CLIPDIST
:
3759 output
[j
].array_base
= next_clip_base
++;
3760 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3762 /* spi_sid is 0 for clipdistance outputs that were generated
3763 * for clipvertex - we don't need to pass them to PS */
3764 if (shader
->output
[i
].spi_sid
) {
3766 /* duplicate it as PARAM to pass to the pixel shader */
3767 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3768 output
[j
].array_base
= next_param_base
++;
3769 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3772 case TGSI_SEMANTIC_FOG
:
3773 output
[j
].swizzle_y
= 4; /* 0 */
3774 output
[j
].swizzle_z
= 4; /* 0 */
3775 output
[j
].swizzle_w
= 5; /* 1 */
3777 case TGSI_SEMANTIC_PRIMID
:
3778 output
[j
].swizzle_x
= 2;
3779 output
[j
].swizzle_y
= 4; /* 0 */
3780 output
[j
].swizzle_z
= 4; /* 0 */
3781 output
[j
].swizzle_w
= 4; /* 0 */
3786 case PIPE_SHADER_FRAGMENT
:
3787 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3788 /* never export more colors than the number of CBs */
3789 if (shader
->output
[i
].sid
>= max_color_exports
) {
3794 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3795 output
[j
].array_base
= shader
->output
[i
].sid
;
3796 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3797 shader
->nr_ps_color_exports
++;
3798 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3799 for (k
= 1; k
< max_color_exports
; k
++) {
3801 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3802 output
[j
].gpr
= shader
->output
[i
].gpr
;
3803 output
[j
].elem_size
= 3;
3804 output
[j
].swizzle_x
= 0;
3805 output
[j
].swizzle_y
= 1;
3806 output
[j
].swizzle_z
= 2;
3807 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3808 output
[j
].burst_count
= 1;
3809 output
[j
].array_base
= k
;
3810 output
[j
].op
= CF_OP_EXPORT
;
3811 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3812 shader
->nr_ps_color_exports
++;
3815 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3816 output
[j
].array_base
= 61;
3817 output
[j
].swizzle_x
= 2;
3818 output
[j
].swizzle_y
= 7;
3819 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3820 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3821 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3822 output
[j
].array_base
= 61;
3823 output
[j
].swizzle_x
= 7;
3824 output
[j
].swizzle_y
= 1;
3825 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3826 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3827 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3828 output
[j
].array_base
= 61;
3829 output
[j
].swizzle_x
= 7;
3830 output
[j
].swizzle_y
= 7;
3831 output
[j
].swizzle_z
= 0;
3832 output
[j
].swizzle_w
= 7;
3833 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3835 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3840 case PIPE_SHADER_TESS_CTRL
:
3843 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3848 if (output
[j
].type
== 0xffffffff) {
3849 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3850 output
[j
].array_base
= next_param_base
++;
3854 /* add fake position export */
3855 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
3856 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3858 output
[j
].elem_size
= 3;
3859 output
[j
].swizzle_x
= 7;
3860 output
[j
].swizzle_y
= 7;
3861 output
[j
].swizzle_z
= 7;
3862 output
[j
].swizzle_w
= 7;
3863 output
[j
].burst_count
= 1;
3864 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3865 output
[j
].array_base
= 60;
3866 output
[j
].op
= CF_OP_EXPORT
;
3870 /* add fake param output for vertex shader if no param is exported */
3871 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
3872 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3874 output
[j
].elem_size
= 3;
3875 output
[j
].swizzle_x
= 7;
3876 output
[j
].swizzle_y
= 7;
3877 output
[j
].swizzle_z
= 7;
3878 output
[j
].swizzle_w
= 7;
3879 output
[j
].burst_count
= 1;
3880 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3881 output
[j
].array_base
= 0;
3882 output
[j
].op
= CF_OP_EXPORT
;
3886 /* add fake pixel export */
3887 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
3888 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3890 output
[j
].elem_size
= 3;
3891 output
[j
].swizzle_x
= 7;
3892 output
[j
].swizzle_y
= 7;
3893 output
[j
].swizzle_z
= 7;
3894 output
[j
].swizzle_w
= 7;
3895 output
[j
].burst_count
= 1;
3896 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3897 output
[j
].array_base
= 0;
3898 output
[j
].op
= CF_OP_EXPORT
;
3900 shader
->nr_ps_color_exports
++;
3905 /* set export done on last export of each type */
3906 for (k
= noutput
- 1, output_done
= 0; k
>= 0; k
--) {
3907 if (!(output_done
& (1 << output
[k
].type
))) {
3908 output_done
|= (1 << output
[k
].type
);
3909 output
[k
].op
= CF_OP_EXPORT_DONE
;
3912 /* add output to bytecode */
3913 for (i
= 0; i
< noutput
; i
++) {
3914 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
3920 /* add program end */
3921 if (ctx
.bc
->chip_class
== CAYMAN
)
3922 cm_bytecode_add_cf_end(ctx
.bc
);
3924 const struct cf_op_info
*last
= NULL
;
3926 if (ctx
.bc
->cf_last
)
3927 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
3929 /* alu clause instructions don't have EOP bit, so add NOP */
3930 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
)
3931 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
3933 ctx
.bc
->cf_last
->end_of_program
= 1;
3936 /* check GPR limit - we have 124 = 128 - 4
3937 * (4 are reserved as alu clause temporary registers) */
3938 if (ctx
.bc
->ngpr
> 124) {
3939 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
3944 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3945 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
3950 tgsi_parse_free(&ctx
.parse
);
3954 tgsi_parse_free(&ctx
.parse
);
3958 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
3960 const unsigned tgsi_opcode
=
3961 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3962 R600_ERR("%s tgsi opcode unsupported\n",
3963 tgsi_get_opcode_name(tgsi_opcode
));
3967 static int tgsi_end(struct r600_shader_ctx
*ctx UNUSED
)
3972 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
3973 const struct r600_shader_src
*shader_src
,
3976 bc_src
->sel
= shader_src
->sel
;
3977 bc_src
->chan
= shader_src
->swizzle
[chan
];
3978 bc_src
->neg
= shader_src
->neg
;
3979 bc_src
->abs
= shader_src
->abs
;
3980 bc_src
->rel
= shader_src
->rel
;
3981 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
3982 bc_src
->kc_bank
= shader_src
->kc_bank
;
3983 bc_src
->kc_rel
= shader_src
->kc_rel
;
3986 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
3992 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
3994 bc_src
->neg
= !bc_src
->neg
;
3997 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
3998 const struct tgsi_full_dst_register
*tgsi_dst
,
4000 struct r600_bytecode_alu_dst
*r600_dst
)
4002 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4004 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
4005 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
4006 r600_dst
->chan
= swizzle
;
4007 r600_dst
->write
= 1;
4008 if (inst
->Instruction
.Saturate
) {
4009 r600_dst
->clamp
= 1;
4011 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
4012 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
4016 if (tgsi_dst
->Register
.Indirect
)
4017 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
4021 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
, int dest_temp
, int op_override
)
4023 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4024 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4025 struct r600_bytecode_alu alu
;
4026 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4028 int swizzle_x
= inst
->Src
[0].Register
.SwizzleX
;
4031 switch (write_mask
) {
4033 if (swizzle_x
== 2) {
4040 if (swizzle_x
== 2) {
4049 if (swizzle_x
== 0) {
4056 if (swizzle_x
== 0) {
4067 lasti
= tgsi_last_instruction(write_mask
);
4068 for (i
= 0; i
<= lasti
; i
++) {
4070 if (!(write_mask
& (1 << i
)))
4073 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4076 if (use_tmp
|| dest_temp
) {
4077 alu
.dst
.sel
= use_tmp
? ctx
->temp_reg
: dest_temp
;
4081 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4083 if (i
== 1 || i
== 3)
4086 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4088 alu
.op
= op_override
? op_override
: ctx
->inst_info
->op
;
4089 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
4090 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4092 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4093 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4096 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
4097 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
4100 /* handle some special cases */
4101 if (i
== 1 || i
== 3) {
4102 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
4103 case TGSI_OPCODE_DABS
:
4104 r600_bytecode_src_set_abs(&alu
.src
[0]);
4113 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4119 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4121 lasti
= tgsi_last_instruction(write_mask
);
4122 /* move result from temp to dst */
4123 for (i
= 0; i
<= lasti
; i
++) {
4124 if (!(write_mask
& (1 << i
)))
4127 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4128 alu
.op
= ALU_OP1_MOV
;
4131 alu
.dst
.sel
= dest_temp
;
4135 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4136 alu
.src
[0].sel
= ctx
->temp_reg
;
4137 alu
.src
[0].chan
= use_tmp
- 1;
4138 alu
.last
= (i
== lasti
);
4140 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4148 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
4150 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4151 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4152 /* confirm writemasking */
4153 if ((write_mask
& 0x3) != 0x3 &&
4154 (write_mask
& 0xc) != 0xc) {
4155 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
4158 return tgsi_op2_64_params(ctx
, false, false, 0, 0);
4161 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4163 return tgsi_op2_64_params(ctx
, true, false, 0, 0);
4166 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4168 return tgsi_op2_64_params(ctx
, true, true, 0, 0);
4171 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4173 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4174 struct r600_bytecode_alu alu
;
4177 int tmp
= r600_get_temp(ctx
);
4179 for (i
= 0; i
< lasti
+ 1; i
++) {
4181 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4182 alu
.op
= ctx
->inst_info
->op
;
4183 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4184 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4187 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4188 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4197 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4204 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4206 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4207 struct r600_bytecode_alu alu
;
4208 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4209 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4210 /* use temp register if trans_only and more than one dst component */
4211 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4212 unsigned op
= ctx
->inst_info
->op
;
4214 if (op
== ALU_OP2_MUL_IEEE
&&
4215 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4218 for (i
= 0; i
<= lasti
; i
++) {
4219 if (!(write_mask
& (1 << i
)))
4222 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4224 alu
.dst
.sel
= ctx
->temp_reg
;
4228 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4232 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4233 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4236 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4237 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4239 if (i
== lasti
|| trans_only
) {
4242 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4248 /* move result from temp to dst */
4249 for (i
= 0; i
<= lasti
; i
++) {
4250 if (!(write_mask
& (1 << i
)))
4253 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4254 alu
.op
= ALU_OP1_MOV
;
4255 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4256 alu
.src
[0].sel
= ctx
->temp_reg
;
4257 alu
.src
[0].chan
= i
;
4258 alu
.last
= (i
== lasti
);
4260 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4268 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4270 return tgsi_op2_s(ctx
, 0, 0);
4273 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4275 return tgsi_op2_s(ctx
, 1, 0);
4278 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4280 return tgsi_op2_s(ctx
, 0, 1);
4283 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4285 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4286 struct r600_bytecode_alu alu
;
4288 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4290 for (i
= 0; i
< lasti
+ 1; i
++) {
4292 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4294 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4295 alu
.op
= ctx
->inst_info
->op
;
4297 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4299 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4301 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4306 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4314 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4316 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4317 struct r600_bytecode_alu alu
;
4319 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4321 for (i
= 0; i
< lasti
+ 1; i
++) {
4323 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4325 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4326 alu
.op
= ALU_OP1_MOV
;
4328 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4330 if (i
== 1 || i
== 3)
4331 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4332 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4337 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4345 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4347 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4348 struct r600_bytecode_alu alu
;
4349 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4352 for (i
= 0; i
<= 3; i
++) {
4353 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4354 alu
.op
= ctx
->inst_info
->op
;
4356 alu
.dst
.sel
= ctx
->temp_reg
;
4359 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4360 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4366 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4371 /* Replicate significand result across channels. */
4372 for (i
= 0; i
<= 3; i
++) {
4373 if (!(write_mask
& (1 << i
)))
4376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4377 alu
.op
= ALU_OP1_MOV
;
4378 alu
.src
[0].chan
= (i
& 1) + 2;
4379 alu
.src
[0].sel
= ctx
->temp_reg
;
4381 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4384 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4389 for (i
= 0; i
<= 3; i
++) {
4390 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4391 /* MOV third channels to writemask dst1 */
4392 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4393 alu
.op
= ALU_OP1_MOV
;
4394 alu
.src
[0].chan
= 1;
4395 alu
.src
[0].sel
= ctx
->temp_reg
;
4397 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4399 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4409 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4411 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4412 struct r600_bytecode_alu alu
;
4414 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4416 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4417 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4419 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4420 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4421 alu
.op
= ctx
->inst_info
->op
;
4423 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4424 alu
.dst
.sel
= ctx
->temp_reg
;
4429 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4434 for (i
= 0; i
<= lasti
; i
++) {
4435 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4436 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4438 alu
.src
[0].chan
= i
/2;
4440 alu
.src
[0].sel
= ctx
->temp_reg
;
4442 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4443 alu
.src
[0].value
= 0x0;
4445 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4446 alu
.last
= i
== lasti
;
4448 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4456 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4458 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4459 struct r600_bytecode_alu alu
;
4461 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4462 int treg
= r600_get_temp(ctx
);
4463 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4464 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4466 /* do a 64->32 into a temp register */
4467 r
= tgsi_op2_64_params(ctx
, true, false, treg
, ALU_OP1_FLT64_TO_FLT32
);
4471 for (i
= 0; i
<= lasti
; i
++) {
4472 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4474 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4475 alu
.op
= ctx
->inst_info
->op
;
4477 alu
.src
[0].chan
= i
;
4478 alu
.src
[0].sel
= treg
;
4479 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4480 alu
.last
= (i
== lasti
);
4482 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4490 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4493 struct r600_shader_src
*src
,
4496 struct r600_bytecode_alu alu
;
4497 const int last_slot
= 3;
4500 /* these have to write the result to X/Y by the looks of it */
4501 for (int i
= 0 ; i
< last_slot
; i
++) {
4502 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4505 r600_bytecode_src(&alu
.src
[0], src
, 1);
4506 r600_bytecode_src(&alu
.src
[1], src
, 0);
4509 r600_bytecode_src_set_abs(&alu
.src
[1]);
4511 alu
.dst
.sel
= dst_reg
;
4513 alu
.dst
.write
= (i
== 0 || i
== 1);
4515 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4517 r
= r600_bytecode_add_alu(bc
, &alu
);
4525 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4527 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4529 struct r600_bytecode_alu alu
;
4530 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4531 int t1
= ctx
->temp_reg
;
4533 /* should only be one src regs */
4534 assert(inst
->Instruction
.NumSrcRegs
== 1);
4536 /* only support one double at a time */
4537 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4538 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4540 r
= cayman_emit_unary_double_raw(
4541 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4543 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4544 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4548 for (i
= 0 ; i
<= lasti
; i
++) {
4549 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4551 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4552 alu
.op
= ALU_OP1_MOV
;
4553 alu
.src
[0].sel
= t1
;
4554 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4555 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4559 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4566 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4568 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4570 struct r600_bytecode_alu alu
;
4571 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4573 for (i
= 0 ; i
< last_slot
; i
++) {
4574 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4575 alu
.op
= ctx
->inst_info
->op
;
4576 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4577 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4579 /* RSQ should take the absolute value of src */
4580 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4581 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4584 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4585 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4587 if (i
== last_slot
- 1)
4589 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4596 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4598 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4600 struct r600_bytecode_alu alu
;
4601 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4602 int t1
= ctx
->temp_reg
;
4604 for (k
= 0; k
<= lasti
; k
++) {
4605 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4608 for (i
= 0 ; i
< 4; i
++) {
4609 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4610 alu
.op
= ctx
->inst_info
->op
;
4611 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4612 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4616 alu
.dst
.write
= (i
== k
);
4619 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4625 for (i
= 0 ; i
<= lasti
; i
++) {
4626 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4628 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4629 alu
.op
= ALU_OP1_MOV
;
4630 alu
.src
[0].sel
= t1
;
4631 alu
.src
[0].chan
= i
;
4632 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4636 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4645 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4647 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4649 struct r600_bytecode_alu alu
;
4650 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4651 int t1
= ctx
->temp_reg
;
4653 /* t1 would get overwritten below if we actually tried to
4654 * multiply two pairs of doubles at a time. */
4655 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4656 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4658 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4660 for (i
= 0; i
< 4; i
++) {
4661 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4662 alu
.op
= ctx
->inst_info
->op
;
4663 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4664 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
4671 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4676 for (i
= 0; i
<= lasti
; i
++) {
4677 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4679 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4680 alu
.op
= ALU_OP1_MOV
;
4681 alu
.src
[0].sel
= t1
;
4682 alu
.src
[0].chan
= i
;
4683 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4687 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4696 * Emit RECIP_64 + MUL_64 to implement division.
4698 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
4700 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4702 struct r600_bytecode_alu alu
;
4703 int t1
= ctx
->temp_reg
;
4706 /* Only support one double at a time. This is the same constraint as
4707 * in DMUL lowering. */
4708 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4709 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4711 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4713 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
4717 for (int i
= 0; i
< 4; i
++) {
4718 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4719 alu
.op
= ALU_OP2_MUL_64
;
4721 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
4723 alu
.src
[1].sel
= t1
;
4724 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
4731 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4736 for (int i
= 0; i
< 2; i
++) {
4737 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4738 alu
.op
= ALU_OP1_MOV
;
4739 alu
.src
[0].sel
= t1
;
4740 alu
.src
[0].chan
= i
;
4741 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
4745 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4753 * r600 - trunc to -PI..PI range
4754 * r700 - normalize by dividing by 2PI
4757 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4760 struct r600_bytecode_alu alu
;
4762 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4763 alu
.op
= ALU_OP3_MULADD
;
4767 alu
.dst
.sel
= ctx
->temp_reg
;
4770 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4772 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4773 alu
.src
[1].chan
= 0;
4774 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
4775 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4776 alu
.src
[2].chan
= 0;
4778 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4782 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4783 alu
.op
= ALU_OP1_FRACT
;
4786 alu
.dst
.sel
= ctx
->temp_reg
;
4789 alu
.src
[0].sel
= ctx
->temp_reg
;
4790 alu
.src
[0].chan
= 0;
4792 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4796 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4797 alu
.op
= ALU_OP3_MULADD
;
4801 alu
.dst
.sel
= ctx
->temp_reg
;
4804 alu
.src
[0].sel
= ctx
->temp_reg
;
4805 alu
.src
[0].chan
= 0;
4807 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4808 alu
.src
[1].chan
= 0;
4809 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4810 alu
.src
[2].chan
= 0;
4812 if (ctx
->bc
->chip_class
== R600
) {
4813 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
4814 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
4816 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4817 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4822 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4828 static int cayman_trig(struct r600_shader_ctx
*ctx
)
4830 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4831 struct r600_bytecode_alu alu
;
4832 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4835 r
= tgsi_setup_trig(ctx
);
4840 for (i
= 0; i
< last_slot
; i
++) {
4841 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4842 alu
.op
= ctx
->inst_info
->op
;
4845 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4846 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4848 alu
.src
[0].sel
= ctx
->temp_reg
;
4849 alu
.src
[0].chan
= 0;
4850 if (i
== last_slot
- 1)
4852 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4859 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
4861 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4862 struct r600_bytecode_alu alu
;
4864 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4866 r
= tgsi_setup_trig(ctx
);
4870 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4871 alu
.op
= ctx
->inst_info
->op
;
4873 alu
.dst
.sel
= ctx
->temp_reg
;
4876 alu
.src
[0].sel
= ctx
->temp_reg
;
4877 alu
.src
[0].chan
= 0;
4879 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4883 /* replicate result */
4884 for (i
= 0; i
< lasti
+ 1; i
++) {
4885 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4888 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4889 alu
.op
= ALU_OP1_MOV
;
4891 alu
.src
[0].sel
= ctx
->temp_reg
;
4892 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4895 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4902 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
4904 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4905 struct r600_bytecode_alu alu
;
4908 for (i
= 0; i
< 4; i
++) {
4909 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4910 alu
.op
= ctx
->inst_info
->op
;
4914 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4916 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
4917 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4920 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4925 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4930 /* kill must be last in ALU */
4931 ctx
->bc
->force_add_cf
= 1;
4932 ctx
->shader
->uses_kill
= TRUE
;
4936 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
4938 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4939 struct r600_bytecode_alu alu
;
4942 /* tmp.x = max(src.y, 0.0) */
4943 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4944 alu
.op
= ALU_OP2_MAX
;
4945 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
4946 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4947 alu
.src
[1].chan
= 1;
4949 alu
.dst
.sel
= ctx
->temp_reg
;
4954 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4958 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
4964 if (ctx
->bc
->chip_class
== CAYMAN
) {
4965 for (i
= 0; i
< 3; i
++) {
4966 /* tmp.z = log(tmp.x) */
4967 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4968 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4969 alu
.src
[0].sel
= ctx
->temp_reg
;
4970 alu
.src
[0].chan
= 0;
4971 alu
.dst
.sel
= ctx
->temp_reg
;
4979 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4984 /* tmp.z = log(tmp.x) */
4985 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4986 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4987 alu
.src
[0].sel
= ctx
->temp_reg
;
4988 alu
.src
[0].chan
= 0;
4989 alu
.dst
.sel
= ctx
->temp_reg
;
4993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4998 chan
= alu
.dst
.chan
;
5001 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
5002 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5003 alu
.op
= ALU_OP3_MUL_LIT
;
5004 alu
.src
[0].sel
= sel
;
5005 alu
.src
[0].chan
= chan
;
5006 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
5007 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
5008 alu
.dst
.sel
= ctx
->temp_reg
;
5013 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5017 if (ctx
->bc
->chip_class
== CAYMAN
) {
5018 for (i
= 0; i
< 3; i
++) {
5019 /* dst.z = exp(tmp.x) */
5020 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5021 alu
.op
= ALU_OP1_EXP_IEEE
;
5022 alu
.src
[0].sel
= ctx
->temp_reg
;
5023 alu
.src
[0].chan
= 0;
5024 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5030 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5035 /* dst.z = exp(tmp.x) */
5036 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5037 alu
.op
= ALU_OP1_EXP_IEEE
;
5038 alu
.src
[0].sel
= ctx
->temp_reg
;
5039 alu
.src
[0].chan
= 0;
5040 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
5042 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5049 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5050 alu
.op
= ALU_OP1_MOV
;
5051 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
5052 alu
.src
[0].chan
= 0;
5053 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
5054 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
5055 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5059 /* dst.y = max(src.x, 0.0) */
5060 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5061 alu
.op
= ALU_OP2_MAX
;
5062 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5063 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5064 alu
.src
[1].chan
= 0;
5065 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
5066 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
5067 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5072 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5073 alu
.op
= ALU_OP1_MOV
;
5074 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5075 alu
.src
[0].chan
= 0;
5076 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
5077 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
5079 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5086 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
5088 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5089 struct r600_bytecode_alu alu
;
5092 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5094 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
5096 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5097 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5098 r600_bytecode_src_set_abs(&alu
.src
[i
]);
5100 alu
.dst
.sel
= ctx
->temp_reg
;
5103 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5106 /* replicate result */
5107 return tgsi_helper_tempx_replicate(ctx
);
5110 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
5112 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5113 struct r600_bytecode_alu alu
;
5116 for (i
= 0; i
< 4; i
++) {
5117 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5118 alu
.src
[0].sel
= ctx
->temp_reg
;
5119 alu
.op
= ALU_OP1_MOV
;
5121 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5122 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5125 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5132 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
5134 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5135 struct r600_bytecode_alu alu
;
5138 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5139 alu
.op
= ctx
->inst_info
->op
;
5140 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5141 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5143 alu
.dst
.sel
= ctx
->temp_reg
;
5146 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5149 /* replicate result */
5150 return tgsi_helper_tempx_replicate(ctx
);
5153 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5155 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5157 struct r600_bytecode_alu alu
;
5158 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5160 for (i
= 0; i
< 3; i
++) {
5161 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5162 alu
.op
= ALU_OP1_LOG_IEEE
;
5163 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5164 alu
.dst
.sel
= ctx
->temp_reg
;
5169 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5175 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5176 alu
.op
= ALU_OP2_MUL
;
5177 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5178 alu
.src
[1].sel
= ctx
->temp_reg
;
5179 alu
.dst
.sel
= ctx
->temp_reg
;
5182 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5186 for (i
= 0; i
< last_slot
; i
++) {
5187 /* POW(a,b) = EXP2(b * LOG2(a))*/
5188 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5189 alu
.op
= ALU_OP1_EXP_IEEE
;
5190 alu
.src
[0].sel
= ctx
->temp_reg
;
5192 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5193 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5194 if (i
== last_slot
- 1)
5196 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5203 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5205 struct r600_bytecode_alu alu
;
5209 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5210 alu
.op
= ALU_OP1_LOG_IEEE
;
5211 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5212 alu
.dst
.sel
= ctx
->temp_reg
;
5215 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5219 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5220 alu
.op
= ALU_OP2_MUL
;
5221 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5222 alu
.src
[1].sel
= ctx
->temp_reg
;
5223 alu
.dst
.sel
= ctx
->temp_reg
;
5226 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5229 /* POW(a,b) = EXP2(b * LOG2(a))*/
5230 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5231 alu
.op
= ALU_OP1_EXP_IEEE
;
5232 alu
.src
[0].sel
= ctx
->temp_reg
;
5233 alu
.dst
.sel
= ctx
->temp_reg
;
5236 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5239 return tgsi_helper_tempx_replicate(ctx
);
5242 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5244 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5245 struct r600_bytecode_alu alu
;
5247 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5248 int tmp0
= ctx
->temp_reg
;
5249 int tmp1
= r600_get_temp(ctx
);
5250 int tmp2
= r600_get_temp(ctx
);
5251 int tmp3
= r600_get_temp(ctx
);
5254 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5256 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5257 * 2. tmp0.z = lo (tmp0.x * src2)
5258 * 3. tmp0.w = -tmp0.z
5259 * 4. tmp0.y = hi (tmp0.x * src2)
5260 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5261 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5262 * 7. tmp1.x = tmp0.x - tmp0.w
5263 * 8. tmp1.y = tmp0.x + tmp0.w
5264 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5265 * 10. tmp0.z = hi(tmp0.x * src1) = q
5266 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5268 * 12. tmp0.w = src1 - tmp0.y = r
5269 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5270 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5274 * 15. tmp1.z = tmp0.z + 1 = q + 1
5275 * 16. tmp1.w = tmp0.z - 1 = q - 1
5279 * 15. tmp1.z = tmp0.w - src2 = r - src2
5280 * 16. tmp1.w = tmp0.w + src2 = r + src2
5284 * 17. tmp1.x = tmp1.x & tmp1.y
5286 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5287 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5289 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5290 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5294 * Same as unsigned, using abs values of the operands,
5295 * and fixing the sign of the result in the end.
5298 for (i
= 0; i
< 4; i
++) {
5299 if (!(write_mask
& (1<<i
)))
5304 /* tmp2.x = -src0 */
5305 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5306 alu
.op
= ALU_OP2_SUB_INT
;
5312 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5314 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5317 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5320 /* tmp2.y = -src1 */
5321 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5322 alu
.op
= ALU_OP2_SUB_INT
;
5328 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5330 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5333 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5336 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5337 /* it will be a sign of the quotient */
5340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5341 alu
.op
= ALU_OP2_XOR_INT
;
5347 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5348 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5351 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5355 /* tmp2.x = |src0| */
5356 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5357 alu
.op
= ALU_OP3_CNDGE_INT
;
5364 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5365 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5366 alu
.src
[2].sel
= tmp2
;
5367 alu
.src
[2].chan
= 0;
5370 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5373 /* tmp2.y = |src1| */
5374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5375 alu
.op
= ALU_OP3_CNDGE_INT
;
5382 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5383 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5384 alu
.src
[2].sel
= tmp2
;
5385 alu
.src
[2].chan
= 1;
5388 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5393 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5394 if (ctx
->bc
->chip_class
== CAYMAN
) {
5395 /* tmp3.x = u2f(src2) */
5396 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5397 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5404 alu
.src
[0].sel
= tmp2
;
5405 alu
.src
[0].chan
= 1;
5407 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5411 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5414 /* tmp0.x = recip(tmp3.x) */
5415 for (j
= 0 ; j
< 3; j
++) {
5416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5417 alu
.op
= ALU_OP1_RECIP_IEEE
;
5421 alu
.dst
.write
= (j
== 0);
5423 alu
.src
[0].sel
= tmp3
;
5424 alu
.src
[0].chan
= 0;
5428 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5432 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5433 alu
.op
= ALU_OP2_MUL
;
5435 alu
.src
[0].sel
= tmp0
;
5436 alu
.src
[0].chan
= 0;
5438 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5439 alu
.src
[1].value
= 0x4f800000;
5444 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5448 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5449 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5455 alu
.src
[0].sel
= tmp3
;
5456 alu
.src
[0].chan
= 0;
5459 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5463 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5464 alu
.op
= ALU_OP1_RECIP_UINT
;
5471 alu
.src
[0].sel
= tmp2
;
5472 alu
.src
[0].chan
= 1;
5474 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5478 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5482 /* 2. tmp0.z = lo (tmp0.x * src2) */
5483 if (ctx
->bc
->chip_class
== CAYMAN
) {
5484 for (j
= 0 ; j
< 4; j
++) {
5485 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5486 alu
.op
= ALU_OP2_MULLO_UINT
;
5490 alu
.dst
.write
= (j
== 2);
5492 alu
.src
[0].sel
= tmp0
;
5493 alu
.src
[0].chan
= 0;
5495 alu
.src
[1].sel
= tmp2
;
5496 alu
.src
[1].chan
= 1;
5498 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5501 alu
.last
= (j
== 3);
5502 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5507 alu
.op
= ALU_OP2_MULLO_UINT
;
5513 alu
.src
[0].sel
= tmp0
;
5514 alu
.src
[0].chan
= 0;
5516 alu
.src
[1].sel
= tmp2
;
5517 alu
.src
[1].chan
= 1;
5519 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5523 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5527 /* 3. tmp0.w = -tmp0.z */
5528 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5529 alu
.op
= ALU_OP2_SUB_INT
;
5535 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5536 alu
.src
[1].sel
= tmp0
;
5537 alu
.src
[1].chan
= 2;
5540 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5543 /* 4. tmp0.y = hi (tmp0.x * src2) */
5544 if (ctx
->bc
->chip_class
== CAYMAN
) {
5545 for (j
= 0 ; j
< 4; j
++) {
5546 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5547 alu
.op
= ALU_OP2_MULHI_UINT
;
5551 alu
.dst
.write
= (j
== 1);
5553 alu
.src
[0].sel
= tmp0
;
5554 alu
.src
[0].chan
= 0;
5557 alu
.src
[1].sel
= tmp2
;
5558 alu
.src
[1].chan
= 1;
5560 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5562 alu
.last
= (j
== 3);
5563 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5568 alu
.op
= ALU_OP2_MULHI_UINT
;
5574 alu
.src
[0].sel
= tmp0
;
5575 alu
.src
[0].chan
= 0;
5578 alu
.src
[1].sel
= tmp2
;
5579 alu
.src
[1].chan
= 1;
5581 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5585 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5589 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5590 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5591 alu
.op
= ALU_OP3_CNDE_INT
;
5598 alu
.src
[0].sel
= tmp0
;
5599 alu
.src
[0].chan
= 1;
5600 alu
.src
[1].sel
= tmp0
;
5601 alu
.src
[1].chan
= 3;
5602 alu
.src
[2].sel
= tmp0
;
5603 alu
.src
[2].chan
= 2;
5606 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5609 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5610 if (ctx
->bc
->chip_class
== CAYMAN
) {
5611 for (j
= 0 ; j
< 4; j
++) {
5612 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5613 alu
.op
= ALU_OP2_MULHI_UINT
;
5617 alu
.dst
.write
= (j
== 3);
5619 alu
.src
[0].sel
= tmp0
;
5620 alu
.src
[0].chan
= 2;
5622 alu
.src
[1].sel
= tmp0
;
5623 alu
.src
[1].chan
= 0;
5625 alu
.last
= (j
== 3);
5626 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5630 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5631 alu
.op
= ALU_OP2_MULHI_UINT
;
5637 alu
.src
[0].sel
= tmp0
;
5638 alu
.src
[0].chan
= 2;
5640 alu
.src
[1].sel
= tmp0
;
5641 alu
.src
[1].chan
= 0;
5644 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5648 /* 7. tmp1.x = tmp0.x - tmp0.w */
5649 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5650 alu
.op
= ALU_OP2_SUB_INT
;
5656 alu
.src
[0].sel
= tmp0
;
5657 alu
.src
[0].chan
= 0;
5658 alu
.src
[1].sel
= tmp0
;
5659 alu
.src
[1].chan
= 3;
5662 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5665 /* 8. tmp1.y = tmp0.x + tmp0.w */
5666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5667 alu
.op
= ALU_OP2_ADD_INT
;
5673 alu
.src
[0].sel
= tmp0
;
5674 alu
.src
[0].chan
= 0;
5675 alu
.src
[1].sel
= tmp0
;
5676 alu
.src
[1].chan
= 3;
5679 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5682 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5683 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5684 alu
.op
= ALU_OP3_CNDE_INT
;
5691 alu
.src
[0].sel
= tmp0
;
5692 alu
.src
[0].chan
= 1;
5693 alu
.src
[1].sel
= tmp1
;
5694 alu
.src
[1].chan
= 1;
5695 alu
.src
[2].sel
= tmp1
;
5696 alu
.src
[2].chan
= 0;
5699 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5702 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5703 if (ctx
->bc
->chip_class
== CAYMAN
) {
5704 for (j
= 0 ; j
< 4; j
++) {
5705 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5706 alu
.op
= ALU_OP2_MULHI_UINT
;
5710 alu
.dst
.write
= (j
== 2);
5712 alu
.src
[0].sel
= tmp0
;
5713 alu
.src
[0].chan
= 0;
5716 alu
.src
[1].sel
= tmp2
;
5717 alu
.src
[1].chan
= 0;
5719 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5722 alu
.last
= (j
== 3);
5723 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5727 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5728 alu
.op
= ALU_OP2_MULHI_UINT
;
5734 alu
.src
[0].sel
= tmp0
;
5735 alu
.src
[0].chan
= 0;
5738 alu
.src
[1].sel
= tmp2
;
5739 alu
.src
[1].chan
= 0;
5741 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5745 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5749 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5750 if (ctx
->bc
->chip_class
== CAYMAN
) {
5751 for (j
= 0 ; j
< 4; j
++) {
5752 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5753 alu
.op
= ALU_OP2_MULLO_UINT
;
5757 alu
.dst
.write
= (j
== 1);
5760 alu
.src
[0].sel
= tmp2
;
5761 alu
.src
[0].chan
= 1;
5763 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5766 alu
.src
[1].sel
= tmp0
;
5767 alu
.src
[1].chan
= 2;
5769 alu
.last
= (j
== 3);
5770 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5774 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5775 alu
.op
= ALU_OP2_MULLO_UINT
;
5782 alu
.src
[0].sel
= tmp2
;
5783 alu
.src
[0].chan
= 1;
5785 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5788 alu
.src
[1].sel
= tmp0
;
5789 alu
.src
[1].chan
= 2;
5792 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5796 /* 12. tmp0.w = src1 - tmp0.y = r */
5797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5798 alu
.op
= ALU_OP2_SUB_INT
;
5805 alu
.src
[0].sel
= tmp2
;
5806 alu
.src
[0].chan
= 0;
5808 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5811 alu
.src
[1].sel
= tmp0
;
5812 alu
.src
[1].chan
= 1;
5815 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5818 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5819 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5820 alu
.op
= ALU_OP2_SETGE_UINT
;
5826 alu
.src
[0].sel
= tmp0
;
5827 alu
.src
[0].chan
= 3;
5829 alu
.src
[1].sel
= tmp2
;
5830 alu
.src
[1].chan
= 1;
5832 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5836 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5839 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5840 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5841 alu
.op
= ALU_OP2_SETGE_UINT
;
5848 alu
.src
[0].sel
= tmp2
;
5849 alu
.src
[0].chan
= 0;
5851 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5854 alu
.src
[1].sel
= tmp0
;
5855 alu
.src
[1].chan
= 1;
5858 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5861 if (mod
) { /* UMOD */
5863 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5864 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5865 alu
.op
= ALU_OP2_SUB_INT
;
5871 alu
.src
[0].sel
= tmp0
;
5872 alu
.src
[0].chan
= 3;
5875 alu
.src
[1].sel
= tmp2
;
5876 alu
.src
[1].chan
= 1;
5878 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5882 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5885 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
5886 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5887 alu
.op
= ALU_OP2_ADD_INT
;
5893 alu
.src
[0].sel
= tmp0
;
5894 alu
.src
[0].chan
= 3;
5896 alu
.src
[1].sel
= tmp2
;
5897 alu
.src
[1].chan
= 1;
5899 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5903 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5908 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5909 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5910 alu
.op
= ALU_OP2_ADD_INT
;
5916 alu
.src
[0].sel
= tmp0
;
5917 alu
.src
[0].chan
= 2;
5918 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
5921 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5924 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
5925 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5926 alu
.op
= ALU_OP2_ADD_INT
;
5932 alu
.src
[0].sel
= tmp0
;
5933 alu
.src
[0].chan
= 2;
5934 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
5937 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5942 /* 17. tmp1.x = tmp1.x & tmp1.y */
5943 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5944 alu
.op
= ALU_OP2_AND_INT
;
5950 alu
.src
[0].sel
= tmp1
;
5951 alu
.src
[0].chan
= 0;
5952 alu
.src
[1].sel
= tmp1
;
5953 alu
.src
[1].chan
= 1;
5956 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5959 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
5960 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
5961 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5962 alu
.op
= ALU_OP3_CNDE_INT
;
5969 alu
.src
[0].sel
= tmp1
;
5970 alu
.src
[0].chan
= 0;
5971 alu
.src
[1].sel
= tmp0
;
5972 alu
.src
[1].chan
= mod
? 3 : 2;
5973 alu
.src
[2].sel
= tmp1
;
5974 alu
.src
[2].chan
= 2;
5977 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5980 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
5981 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5982 alu
.op
= ALU_OP3_CNDE_INT
;
5990 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5993 alu
.src
[0].sel
= tmp1
;
5994 alu
.src
[0].chan
= 1;
5995 alu
.src
[1].sel
= tmp1
;
5996 alu
.src
[1].chan
= 3;
5997 alu
.src
[2].sel
= tmp0
;
5998 alu
.src
[2].chan
= 2;
6001 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6006 /* fix the sign of the result */
6010 /* tmp0.x = -tmp0.z */
6011 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6012 alu
.op
= ALU_OP2_SUB_INT
;
6018 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6019 alu
.src
[1].sel
= tmp0
;
6020 alu
.src
[1].chan
= 2;
6023 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6026 /* sign of the remainder is the same as the sign of src0 */
6027 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
6028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6029 alu
.op
= ALU_OP3_CNDGE_INT
;
6032 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6034 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6035 alu
.src
[1].sel
= tmp0
;
6036 alu
.src
[1].chan
= 2;
6037 alu
.src
[2].sel
= tmp0
;
6038 alu
.src
[2].chan
= 0;
6041 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6046 /* tmp0.x = -tmp0.z */
6047 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6048 alu
.op
= ALU_OP2_SUB_INT
;
6054 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6055 alu
.src
[1].sel
= tmp0
;
6056 alu
.src
[1].chan
= 2;
6059 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6062 /* fix the quotient sign (same as the sign of src0*src1) */
6063 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
6064 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6065 alu
.op
= ALU_OP3_CNDGE_INT
;
6068 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6070 alu
.src
[0].sel
= tmp2
;
6071 alu
.src
[0].chan
= 2;
6072 alu
.src
[1].sel
= tmp0
;
6073 alu
.src
[1].chan
= 2;
6074 alu
.src
[2].sel
= tmp0
;
6075 alu
.src
[2].chan
= 0;
6078 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6086 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
6088 return tgsi_divmod(ctx
, 0, 0);
6091 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
6093 return tgsi_divmod(ctx
, 1, 0);
6096 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
6098 return tgsi_divmod(ctx
, 0, 1);
6101 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
6103 return tgsi_divmod(ctx
, 1, 1);
6107 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
6109 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6110 struct r600_bytecode_alu alu
;
6112 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6113 int last_inst
= tgsi_last_instruction(write_mask
);
6115 for (i
= 0; i
< 4; i
++) {
6116 if (!(write_mask
& (1<<i
)))
6119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6120 alu
.op
= ALU_OP1_TRUNC
;
6122 alu
.dst
.sel
= ctx
->temp_reg
;
6126 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6129 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6134 for (i
= 0; i
< 4; i
++) {
6135 if (!(write_mask
& (1<<i
)))
6138 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6139 alu
.op
= ctx
->inst_info
->op
;
6141 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6143 alu
.src
[0].sel
= ctx
->temp_reg
;
6144 alu
.src
[0].chan
= i
;
6146 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
6148 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6156 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6158 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6159 struct r600_bytecode_alu alu
;
6161 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6162 int last_inst
= tgsi_last_instruction(write_mask
);
6165 for (i
= 0; i
< 4; i
++) {
6166 if (!(write_mask
& (1<<i
)))
6169 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6170 alu
.op
= ALU_OP2_SUB_INT
;
6172 alu
.dst
.sel
= ctx
->temp_reg
;
6176 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6177 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6181 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6186 /* dst = (src >= 0 ? src : tmp) */
6187 for (i
= 0; i
< 4; i
++) {
6188 if (!(write_mask
& (1<<i
)))
6191 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6192 alu
.op
= ALU_OP3_CNDGE_INT
;
6196 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6198 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6199 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6200 alu
.src
[2].sel
= ctx
->temp_reg
;
6201 alu
.src
[2].chan
= i
;
6205 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6212 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6214 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6215 struct r600_bytecode_alu alu
;
6217 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6218 int last_inst
= tgsi_last_instruction(write_mask
);
6220 /* tmp = (src >= 0 ? src : -1) */
6221 for (i
= 0; i
< 4; i
++) {
6222 if (!(write_mask
& (1<<i
)))
6225 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6226 alu
.op
= ALU_OP3_CNDGE_INT
;
6229 alu
.dst
.sel
= ctx
->temp_reg
;
6233 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6234 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6235 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6239 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6244 /* dst = (tmp > 0 ? 1 : tmp) */
6245 for (i
= 0; i
< 4; i
++) {
6246 if (!(write_mask
& (1<<i
)))
6249 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6250 alu
.op
= ALU_OP3_CNDGT_INT
;
6254 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6256 alu
.src
[0].sel
= ctx
->temp_reg
;
6257 alu
.src
[0].chan
= i
;
6259 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6261 alu
.src
[2].sel
= ctx
->temp_reg
;
6262 alu
.src
[2].chan
= i
;
6266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6275 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6277 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6278 struct r600_bytecode_alu alu
;
6281 /* tmp = (src > 0 ? 1 : src) */
6282 for (i
= 0; i
< 4; i
++) {
6283 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6284 alu
.op
= ALU_OP3_CNDGT
;
6287 alu
.dst
.sel
= ctx
->temp_reg
;
6290 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6291 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6292 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6296 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6301 /* dst = (-tmp > 0 ? -1 : tmp) */
6302 for (i
= 0; i
< 4; i
++) {
6303 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6304 alu
.op
= ALU_OP3_CNDGT
;
6306 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6308 alu
.src
[0].sel
= ctx
->temp_reg
;
6309 alu
.src
[0].chan
= i
;
6312 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6315 alu
.src
[2].sel
= ctx
->temp_reg
;
6316 alu
.src
[2].chan
= i
;
6320 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6327 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6329 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6330 struct r600_bytecode_alu alu
;
6333 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6334 int last_inst
= tgsi_last_instruction(write_mask
);
6336 t1
= r600_get_temp(ctx
);
6338 for (i
= 0; i
< 4; i
++) {
6339 if (!(write_mask
& (1<<i
)))
6342 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6343 alu
.op
= ALU_OP2_SETGE_INT
;
6344 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6345 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6346 alu
.src
[1].value
= 32;
6347 alu
.dst
.sel
= ctx
->temp_reg
;
6350 alu
.last
= i
== last_inst
;
6351 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6356 for (i
= 0; i
< 4; i
++) {
6357 if (!(write_mask
& (1<<i
)))
6360 /* create mask tmp */
6361 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6362 alu
.op
= ALU_OP2_BFM_INT
;
6366 alu
.last
= i
== last_inst
;
6368 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6369 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6371 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6376 t2
= r600_get_temp(ctx
);
6378 for (i
= 0; i
< 4; i
++) {
6379 if (!(write_mask
& (1<<i
)))
6382 /* shift insert left */
6383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6384 alu
.op
= ALU_OP2_LSHL_INT
;
6388 alu
.last
= i
== last_inst
;
6390 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6391 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6393 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6398 for (i
= 0; i
< 4; i
++) {
6399 if (!(write_mask
& (1<<i
)))
6402 /* actual bitfield insert */
6403 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6404 alu
.op
= ALU_OP3_BFI_INT
;
6406 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6409 alu
.last
= i
== last_inst
;
6411 alu
.src
[0].sel
= t1
;
6412 alu
.src
[0].chan
= i
;
6413 alu
.src
[1].sel
= t2
;
6414 alu
.src
[1].chan
= i
;
6415 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6417 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6422 for (i
= 0; i
< 4; i
++) {
6423 if (!(write_mask
& (1<<i
)))
6425 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6426 alu
.op
= ALU_OP3_CNDE_INT
;
6428 alu
.src
[0].sel
= ctx
->temp_reg
;
6429 alu
.src
[0].chan
= i
;
6430 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6432 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6434 alu
.src
[1].sel
= alu
.dst
.sel
;
6435 alu
.src
[1].chan
= i
;
6437 alu
.last
= i
== last_inst
;
6438 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6445 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6447 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6448 struct r600_bytecode_alu alu
;
6451 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6452 int last_inst
= tgsi_last_instruction(write_mask
);
6454 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6455 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6459 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6460 for (i
= 0; i
< 4; i
++) {
6461 if (!(write_mask
& (1<<i
)))
6464 /* t1 = FFBH_INT / FFBH_UINT */
6465 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6466 alu
.op
= ctx
->inst_info
->op
;
6470 alu
.last
= i
== last_inst
;
6472 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6474 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6479 t2
= r600_get_temp(ctx
);
6481 for (i
= 0; i
< 4; i
++) {
6482 if (!(write_mask
& (1<<i
)))
6486 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6487 alu
.op
= ALU_OP2_SUB_INT
;
6491 alu
.last
= i
== last_inst
;
6493 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6494 alu
.src
[0].value
= 31;
6495 alu
.src
[1].sel
= t1
;
6496 alu
.src
[1].chan
= i
;
6498 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6503 for (i
= 0; i
< 4; i
++) {
6504 if (!(write_mask
& (1<<i
)))
6507 /* result = t1 >= 0 ? t2 : t1 */
6508 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6509 alu
.op
= ALU_OP3_CNDGE_INT
;
6511 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6514 alu
.last
= i
== last_inst
;
6516 alu
.src
[0].sel
= t1
;
6517 alu
.src
[0].chan
= i
;
6518 alu
.src
[1].sel
= t2
;
6519 alu
.src
[1].chan
= i
;
6520 alu
.src
[2].sel
= t1
;
6521 alu
.src
[2].chan
= i
;
6523 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6531 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6533 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6534 struct r600_bytecode_alu alu
;
6535 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6537 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6539 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6541 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6542 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6543 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6544 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6547 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6550 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6553 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6554 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6556 /* NOTE: currently offset is not perspective correct */
6557 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6558 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6559 int sample_gpr
= -1;
6560 int gradientsH
, gradientsV
;
6561 struct r600_bytecode_tex tex
;
6563 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6564 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6567 gradientsH
= r600_get_temp(ctx
);
6568 gradientsV
= r600_get_temp(ctx
);
6569 for (i
= 0; i
< 2; i
++) {
6570 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6571 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6572 tex
.src_gpr
= interp_gpr
;
6573 tex
.src_sel_x
= interp_base_chan
+ 0;
6574 tex
.src_sel_y
= interp_base_chan
+ 1;
6577 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6582 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6584 tex
.resource_id
= tex
.sampler_id
;
6585 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6590 for (i
= 0; i
< 2; i
++) {
6591 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6592 alu
.op
= ALU_OP3_MULADD
;
6594 alu
.src
[0].sel
= gradientsH
;
6595 alu
.src
[0].chan
= i
;
6596 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6597 alu
.src
[1].sel
= sample_gpr
;
6598 alu
.src
[1].chan
= 2;
6601 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6603 alu
.src
[2].sel
= interp_gpr
;
6604 alu
.src
[2].chan
= interp_base_chan
+ i
;
6605 alu
.dst
.sel
= ctx
->temp_reg
;
6609 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6614 for (i
= 0; i
< 2; i
++) {
6615 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6616 alu
.op
= ALU_OP3_MULADD
;
6618 alu
.src
[0].sel
= gradientsV
;
6619 alu
.src
[0].chan
= i
;
6620 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6621 alu
.src
[1].sel
= sample_gpr
;
6622 alu
.src
[1].chan
= 3;
6625 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6627 alu
.src
[2].sel
= ctx
->temp_reg
;
6628 alu
.src
[2].chan
= i
;
6629 alu
.dst
.sel
= ctx
->temp_reg
;
6633 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6639 tmp
= r600_get_temp(ctx
);
6640 for (i
= 0; i
< 8; i
++) {
6641 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6642 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6645 if ((i
> 1 && i
< 6)) {
6651 alu
.dst
.chan
= i
% 4;
6653 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6654 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6655 alu
.src
[0].sel
= ctx
->temp_reg
;
6656 alu
.src
[0].chan
= 1 - (i
% 2);
6658 alu
.src
[0].sel
= interp_gpr
;
6659 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6661 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6662 alu
.src
[1].chan
= 0;
6664 alu
.last
= i
% 4 == 3;
6665 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6667 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6672 // INTERP can't swizzle dst
6673 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6674 for (i
= 0; i
<= lasti
; i
++) {
6675 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6678 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6679 alu
.op
= ALU_OP1_MOV
;
6680 alu
.src
[0].sel
= tmp
;
6681 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6682 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6684 alu
.last
= i
== lasti
;
6685 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6694 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6696 struct r600_bytecode_alu alu
;
6699 for (i
= 0; i
< 4; i
++) {
6700 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6701 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6702 alu
.op
= ALU_OP0_NOP
;
6705 alu
.op
= ALU_OP1_MOV
;
6706 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6707 alu
.src
[0].sel
= ctx
->temp_reg
;
6708 alu
.src
[0].chan
= i
;
6713 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6720 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6721 unsigned temp
, int chan
,
6722 struct r600_bytecode_alu_src
*bc_src
,
6723 const struct r600_shader_src
*shader_src
)
6725 struct r600_bytecode_alu alu
;
6728 r600_bytecode_src(bc_src
, shader_src
, chan
);
6730 /* op3 operands don't support abs modifier */
6732 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6733 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6734 alu
.op
= ALU_OP1_MOV
;
6736 alu
.dst
.chan
= chan
;
6739 alu
.src
[0] = *bc_src
;
6740 alu
.last
= true; // sufficient?
6741 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6745 memset(bc_src
, 0, sizeof(*bc_src
));
6747 bc_src
->chan
= chan
;
6752 static int tgsi_op3_dst(struct r600_shader_ctx
*ctx
, int dst
)
6754 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6755 struct r600_bytecode_alu alu
;
6757 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6759 unsigned op
= ctx
->inst_info
->op
;
6761 if (op
== ALU_OP3_MULADD_IEEE
&&
6762 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6763 op
= ALU_OP3_MULADD
;
6765 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6767 if (ctx
->src
[j
].abs
)
6768 temp_regs
[j
] = r600_get_temp(ctx
);
6770 for (i
= 0; i
< lasti
+ 1; i
++) {
6771 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6774 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6776 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6777 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6783 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6793 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6800 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6802 return tgsi_op3_dst(ctx
, -1);
6805 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6807 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6808 struct r600_bytecode_alu alu
;
6810 unsigned op
= ctx
->inst_info
->op
;
6811 if (op
== ALU_OP2_DOT4_IEEE
&&
6812 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6815 for (i
= 0; i
< 4; i
++) {
6816 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6818 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6819 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6822 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6824 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6825 /* handle some special cases */
6826 switch (inst
->Instruction
.Opcode
) {
6827 case TGSI_OPCODE_DP2
:
6829 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6830 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6833 case TGSI_OPCODE_DP3
:
6835 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6836 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6845 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6852 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6855 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6856 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6857 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6858 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6859 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6860 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
6863 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6866 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6867 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6870 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6872 struct r600_bytecode_vtx vtx
;
6873 struct r600_bytecode_alu alu
;
6874 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6876 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6878 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6879 if (src_requires_loading
) {
6880 for (i
= 0; i
< 4; i
++) {
6881 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6882 alu
.op
= ALU_OP1_MOV
;
6883 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6884 alu
.dst
.sel
= ctx
->temp_reg
;
6889 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6893 src_gpr
= ctx
->temp_reg
;
6896 memset(&vtx
, 0, sizeof(vtx
));
6897 vtx
.op
= FETCH_OP_VFETCH
;
6898 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6899 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6900 vtx
.src_gpr
= src_gpr
;
6901 vtx
.mega_fetch_count
= 16;
6902 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6903 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6904 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6905 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6906 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6907 vtx
.use_const_fields
= 1;
6909 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6912 if (ctx
->bc
->chip_class
>= EVERGREEN
)
6915 for (i
= 0; i
< 4; i
++) {
6916 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6917 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6920 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6921 alu
.op
= ALU_OP2_AND_INT
;
6924 alu
.dst
.sel
= vtx
.dst_gpr
;
6927 alu
.src
[0].sel
= vtx
.dst_gpr
;
6928 alu
.src
[0].chan
= i
;
6930 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6931 alu
.src
[1].sel
+= (id
* 2);
6932 alu
.src
[1].chan
= i
% 4;
6933 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6937 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6942 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
6943 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6944 alu
.op
= ALU_OP2_OR_INT
;
6947 alu
.dst
.sel
= vtx
.dst_gpr
;
6950 alu
.src
[0].sel
= vtx
.dst_gpr
;
6951 alu
.src
[0].chan
= 3;
6953 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
6954 alu
.src
[1].chan
= 0;
6955 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6958 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6965 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
, int reg_idx
, int offset
)
6967 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6968 struct r600_bytecode_alu alu
;
6970 int id
= tgsi_tex_get_src_gpr(ctx
, reg_idx
) + offset
;
6972 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6973 alu
.op
= ALU_OP1_MOV
;
6974 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6975 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
6976 /* channel 0 or 2 of each word */
6977 alu
.src
[0].sel
+= (id
/ 2);
6978 alu
.src
[0].chan
= (id
% 2) * 2;
6980 /* r600 we have them at channel 2 of the second dword */
6981 alu
.src
[0].sel
+= (id
* 2) + 1;
6982 alu
.src
[0].chan
= 1;
6984 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6985 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
6987 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6993 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
6995 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6996 struct r600_bytecode_tex tex
;
6997 struct r600_bytecode_alu alu
;
7001 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
7002 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7003 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
7004 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
7006 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
7007 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7008 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
7010 /* Texture fetch instructions can only use gprs as source.
7011 * Also they cannot negate the source or take the absolute value */
7012 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
7013 tgsi_tex_src_requires_loading(ctx
, 0)) ||
7014 read_compressed_msaa
|| txf_add_offsets
;
7016 boolean src_loaded
= FALSE
;
7017 unsigned sampler_src_reg
= 1;
7018 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
7019 boolean has_txq_cube_array_z
= false;
7020 unsigned sampler_index_mode
;
7022 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
7023 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7024 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
7025 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
7026 ctx
->shader
->has_txq_cube_array_z_comp
= true;
7027 has_txq_cube_array_z
= true;
7030 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
7031 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7032 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
7033 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
7034 sampler_src_reg
= 2;
7036 /* TGSI moves the sampler to src reg 3 for TXD */
7037 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
7038 sampler_src_reg
= 3;
7040 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7042 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
7044 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
7045 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
7046 ctx
->shader
->uses_tex_buffers
= true;
7047 return r600_do_buffer_txq(ctx
, 1, 0);
7049 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
7050 if (ctx
->bc
->chip_class
< EVERGREEN
)
7051 ctx
->shader
->uses_tex_buffers
= true;
7052 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
7056 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
7058 /* Add perspective divide */
7059 if (ctx
->bc
->chip_class
== CAYMAN
) {
7061 for (i
= 0; i
< 3; i
++) {
7062 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7063 alu
.op
= ALU_OP1_RECIP_IEEE
;
7064 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7066 alu
.dst
.sel
= ctx
->temp_reg
;
7072 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7079 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7080 alu
.op
= ALU_OP1_RECIP_IEEE
;
7081 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7083 alu
.dst
.sel
= ctx
->temp_reg
;
7084 alu
.dst
.chan
= out_chan
;
7087 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7092 for (i
= 0; i
< 3; i
++) {
7093 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7094 alu
.op
= ALU_OP2_MUL
;
7095 alu
.src
[0].sel
= ctx
->temp_reg
;
7096 alu
.src
[0].chan
= out_chan
;
7097 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7098 alu
.dst
.sel
= ctx
->temp_reg
;
7101 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7105 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7106 alu
.op
= ALU_OP1_MOV
;
7107 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7108 alu
.src
[0].chan
= 0;
7109 alu
.dst
.sel
= ctx
->temp_reg
;
7113 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7117 src_gpr
= ctx
->temp_reg
;
7121 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7122 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7123 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7124 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7125 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
7127 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
7128 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
7130 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
7131 for (i
= 0; i
< 4; i
++) {
7132 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7133 alu
.op
= ALU_OP2_CUBE
;
7134 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7135 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
7136 alu
.dst
.sel
= ctx
->temp_reg
;
7141 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7146 /* tmp1.z = RCP_e(|tmp1.z|) */
7147 if (ctx
->bc
->chip_class
== CAYMAN
) {
7148 for (i
= 0; i
< 3; i
++) {
7149 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7150 alu
.op
= ALU_OP1_RECIP_IEEE
;
7151 alu
.src
[0].sel
= ctx
->temp_reg
;
7152 alu
.src
[0].chan
= 2;
7154 alu
.dst
.sel
= ctx
->temp_reg
;
7160 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7165 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7166 alu
.op
= ALU_OP1_RECIP_IEEE
;
7167 alu
.src
[0].sel
= ctx
->temp_reg
;
7168 alu
.src
[0].chan
= 2;
7170 alu
.dst
.sel
= ctx
->temp_reg
;
7174 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7179 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7180 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7181 * muladd has no writemask, have to use another temp
7183 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7184 alu
.op
= ALU_OP3_MULADD
;
7187 alu
.src
[0].sel
= ctx
->temp_reg
;
7188 alu
.src
[0].chan
= 0;
7189 alu
.src
[1].sel
= ctx
->temp_reg
;
7190 alu
.src
[1].chan
= 2;
7192 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7193 alu
.src
[2].chan
= 0;
7194 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7196 alu
.dst
.sel
= ctx
->temp_reg
;
7200 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7204 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7205 alu
.op
= ALU_OP3_MULADD
;
7208 alu
.src
[0].sel
= ctx
->temp_reg
;
7209 alu
.src
[0].chan
= 1;
7210 alu
.src
[1].sel
= ctx
->temp_reg
;
7211 alu
.src
[1].chan
= 2;
7213 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7214 alu
.src
[2].chan
= 0;
7215 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7217 alu
.dst
.sel
= ctx
->temp_reg
;
7222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7225 /* write initial compare value into Z component
7226 - W src 0 for shadow cube
7227 - X src 1 for shadow cube array */
7228 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7229 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7230 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7231 alu
.op
= ALU_OP1_MOV
;
7232 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7233 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7235 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7236 alu
.dst
.sel
= ctx
->temp_reg
;
7240 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7245 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7246 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7247 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7248 int mytmp
= r600_get_temp(ctx
);
7249 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7250 alu
.op
= ALU_OP1_MOV
;
7251 alu
.src
[0].sel
= ctx
->temp_reg
;
7252 alu
.src
[0].chan
= 3;
7253 alu
.dst
.sel
= mytmp
;
7257 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7261 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7262 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7263 alu
.op
= ALU_OP3_MULADD
;
7265 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7266 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7267 alu
.src
[1].chan
= 0;
7268 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7269 alu
.src
[2].sel
= mytmp
;
7270 alu
.src
[2].chan
= 0;
7271 alu
.dst
.sel
= ctx
->temp_reg
;
7275 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7278 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7279 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7280 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7281 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7282 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7283 tex
.src_gpr
= r600_get_temp(ctx
);
7288 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7289 tex
.coord_type_x
= 1;
7290 tex
.coord_type_y
= 1;
7291 tex
.coord_type_z
= 1;
7292 tex
.coord_type_w
= 1;
7293 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7294 alu
.op
= ALU_OP1_MOV
;
7295 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7296 alu
.dst
.sel
= tex
.src_gpr
;
7300 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7304 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7311 /* for cube forms of lod and bias we need to route things */
7312 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7313 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7314 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7315 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7316 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7317 alu
.op
= ALU_OP1_MOV
;
7318 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7319 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7320 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7322 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7323 alu
.dst
.sel
= ctx
->temp_reg
;
7327 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7333 src_gpr
= ctx
->temp_reg
;
7336 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7337 int temp_h
= 0, temp_v
= 0;
7340 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7341 if (src_loaded
== TRUE
)
7345 for (i
= start_val
; i
< 3; i
++) {
7346 int treg
= r600_get_temp(ctx
);
7355 for (j
= 0; j
< 4; j
++) {
7356 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7357 alu
.op
= ALU_OP1_MOV
;
7358 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7364 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7369 for (i
= 1; i
< 3; i
++) {
7370 /* set gradients h/v */
7371 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7372 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7373 FETCH_OP_SET_GRADIENTS_V
;
7374 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7375 tex
.sampler_index_mode
= sampler_index_mode
;
7376 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7377 tex
.resource_index_mode
= sampler_index_mode
;
7379 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7385 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7386 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7387 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7388 tex
.coord_type_x
= 1;
7389 tex
.coord_type_y
= 1;
7390 tex
.coord_type_z
= 1;
7391 tex
.coord_type_w
= 1;
7393 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7399 if (src_requires_loading
&& !src_loaded
) {
7400 for (i
= 0; i
< 4; i
++) {
7401 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7402 alu
.op
= ALU_OP1_MOV
;
7403 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7404 alu
.dst
.sel
= ctx
->temp_reg
;
7409 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7414 src_gpr
= ctx
->temp_reg
;
7417 /* get offset values */
7418 if (inst
->Texture
.NumOffsets
) {
7419 assert(inst
->Texture
.NumOffsets
== 1);
7421 /* The texture offset feature doesn't work with the TXF instruction
7422 * and must be emulated by adding the offset to the texture coordinates. */
7423 if (txf_add_offsets
) {
7424 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7426 switch (inst
->Texture
.Texture
) {
7427 case TGSI_TEXTURE_3D
:
7428 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7429 alu
.op
= ALU_OP2_ADD_INT
;
7430 alu
.src
[0].sel
= src_gpr
;
7431 alu
.src
[0].chan
= 2;
7432 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7433 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7434 alu
.dst
.sel
= src_gpr
;
7438 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7443 case TGSI_TEXTURE_2D
:
7444 case TGSI_TEXTURE_SHADOW2D
:
7445 case TGSI_TEXTURE_RECT
:
7446 case TGSI_TEXTURE_SHADOWRECT
:
7447 case TGSI_TEXTURE_2D_ARRAY
:
7448 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7449 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7450 alu
.op
= ALU_OP2_ADD_INT
;
7451 alu
.src
[0].sel
= src_gpr
;
7452 alu
.src
[0].chan
= 1;
7453 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7454 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7455 alu
.dst
.sel
= src_gpr
;
7459 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7464 case TGSI_TEXTURE_1D
:
7465 case TGSI_TEXTURE_SHADOW1D
:
7466 case TGSI_TEXTURE_1D_ARRAY
:
7467 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7469 alu
.op
= ALU_OP2_ADD_INT
;
7470 alu
.src
[0].sel
= src_gpr
;
7471 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7472 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7473 alu
.dst
.sel
= src_gpr
;
7476 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7480 /* texture offsets do not apply to other texture targets */
7483 switch (inst
->Texture
.Texture
) {
7484 case TGSI_TEXTURE_3D
:
7485 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7487 case TGSI_TEXTURE_2D
:
7488 case TGSI_TEXTURE_SHADOW2D
:
7489 case TGSI_TEXTURE_RECT
:
7490 case TGSI_TEXTURE_SHADOWRECT
:
7491 case TGSI_TEXTURE_2D_ARRAY
:
7492 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7493 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7495 case TGSI_TEXTURE_1D
:
7496 case TGSI_TEXTURE_SHADOW1D
:
7497 case TGSI_TEXTURE_1D_ARRAY
:
7498 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7499 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7504 /* Obtain the sample index for reading a compressed MSAA color texture.
7505 * To read the FMASK, we use the ldfptr instruction, which tells us
7506 * where the samples are stored.
7507 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7508 * which is the identity mapping. Each nibble says which physical sample
7509 * should be fetched to get that sample.
7511 * Assume src.z contains the sample index. It should be modified like this:
7512 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7513 * Then fetch the texel with src.
7515 if (read_compressed_msaa
) {
7516 unsigned sample_chan
= 3;
7517 unsigned temp
= r600_get_temp(ctx
);
7520 /* temp.w = ldfptr() */
7521 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7522 tex
.op
= FETCH_OP_LD
;
7523 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7524 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7525 tex
.sampler_index_mode
= sampler_index_mode
;
7526 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7527 tex
.resource_index_mode
= sampler_index_mode
;
7528 tex
.src_gpr
= src_gpr
;
7530 tex
.dst_sel_x
= 7; /* mask out these components */
7533 tex
.dst_sel_w
= 0; /* store X */
7538 tex
.offset_x
= offset_x
;
7539 tex
.offset_y
= offset_y
;
7540 tex
.offset_z
= offset_z
;
7541 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7545 /* temp.x = sample_index*4 */
7546 if (ctx
->bc
->chip_class
== CAYMAN
) {
7547 for (i
= 0 ; i
< 4; i
++) {
7548 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7549 alu
.op
= ALU_OP2_MULLO_INT
;
7550 alu
.src
[0].sel
= src_gpr
;
7551 alu
.src
[0].chan
= sample_chan
;
7552 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7553 alu
.src
[1].value
= 4;
7556 alu
.dst
.write
= i
== 0;
7559 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7564 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7565 alu
.op
= ALU_OP2_MULLO_INT
;
7566 alu
.src
[0].sel
= src_gpr
;
7567 alu
.src
[0].chan
= sample_chan
;
7568 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7569 alu
.src
[1].value
= 4;
7574 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7579 /* sample_index = temp.w >> temp.x */
7580 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7581 alu
.op
= ALU_OP2_LSHR_INT
;
7582 alu
.src
[0].sel
= temp
;
7583 alu
.src
[0].chan
= 3;
7584 alu
.src
[1].sel
= temp
;
7585 alu
.src
[1].chan
= 0;
7586 alu
.dst
.sel
= src_gpr
;
7587 alu
.dst
.chan
= sample_chan
;
7590 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7594 /* sample_index & 0xF */
7595 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7596 alu
.op
= ALU_OP2_AND_INT
;
7597 alu
.src
[0].sel
= src_gpr
;
7598 alu
.src
[0].chan
= sample_chan
;
7599 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7600 alu
.src
[1].value
= 0xF;
7601 alu
.dst
.sel
= src_gpr
;
7602 alu
.dst
.chan
= sample_chan
;
7605 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7609 /* visualize the FMASK */
7610 for (i
= 0; i
< 4; i
++) {
7611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7612 alu
.op
= ALU_OP1_INT_TO_FLT
;
7613 alu
.src
[0].sel
= src_gpr
;
7614 alu
.src
[0].chan
= sample_chan
;
7615 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7619 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7627 /* does this shader want a num layers from TXQ for a cube array? */
7628 if (has_txq_cube_array_z
) {
7629 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7631 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7632 alu
.op
= ALU_OP1_MOV
;
7634 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7635 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7636 /* channel 1 or 3 of each word */
7637 alu
.src
[0].sel
+= (id
/ 2);
7638 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
7640 /* r600 we have them at channel 2 of the second dword */
7641 alu
.src
[0].sel
+= (id
* 2) + 1;
7642 alu
.src
[0].chan
= 2;
7644 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7645 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7647 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7650 /* disable writemask from texture instruction */
7651 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7654 opcode
= ctx
->inst_info
->op
;
7655 if (opcode
== FETCH_OP_GATHER4
&&
7656 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7657 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7658 opcode
= FETCH_OP_GATHER4_O
;
7660 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7661 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7662 encoded in the instruction are ignored. */
7663 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7664 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7665 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7666 tex
.sampler_index_mode
= sampler_index_mode
;
7667 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7668 tex
.resource_index_mode
= sampler_index_mode
;
7670 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7671 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7672 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7673 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7681 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7686 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7687 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7688 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7689 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7690 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7691 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7692 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7694 case FETCH_OP_SAMPLE
:
7695 opcode
= FETCH_OP_SAMPLE_C
;
7697 case FETCH_OP_SAMPLE_L
:
7698 opcode
= FETCH_OP_SAMPLE_C_L
;
7700 case FETCH_OP_SAMPLE_LB
:
7701 opcode
= FETCH_OP_SAMPLE_C_LB
;
7703 case FETCH_OP_SAMPLE_G
:
7704 opcode
= FETCH_OP_SAMPLE_C_G
;
7706 /* Texture gather variants */
7707 case FETCH_OP_GATHER4
:
7708 opcode
= FETCH_OP_GATHER4_C
;
7710 case FETCH_OP_GATHER4_O
:
7711 opcode
= FETCH_OP_GATHER4_C_O
;
7716 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7719 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7720 tex
.sampler_index_mode
= sampler_index_mode
;
7721 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7722 tex
.resource_index_mode
= sampler_index_mode
;
7723 tex
.src_gpr
= src_gpr
;
7724 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7726 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7727 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7728 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7731 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7732 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7733 tex
.inst_mod
= texture_component_select
;
7735 if (ctx
->bc
->chip_class
== CAYMAN
) {
7736 /* GATHER4 result order is different from TGSI TG4 */
7737 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7738 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7739 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7740 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7742 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7743 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7744 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7745 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7748 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7749 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7750 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7754 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7761 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7762 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7763 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7764 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7768 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7773 } else if (src_loaded
) {
7779 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
7780 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
7781 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
7782 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
7783 tex
.src_rel
= ctx
->src
[0].rel
;
7786 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7787 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7788 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7789 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7793 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
7796 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
7797 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
7798 tex
.coord_type_x
= 1;
7799 tex
.coord_type_y
= 1;
7801 tex
.coord_type_z
= 1;
7802 tex
.coord_type_w
= 1;
7804 tex
.offset_x
= offset_x
;
7805 tex
.offset_y
= offset_y
;
7806 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
7807 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7808 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
7812 tex
.offset_z
= offset_z
;
7815 /* Put the depth for comparison in W.
7816 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
7817 * Some instructions expect the depth in Z. */
7818 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7819 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7820 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7821 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
7822 opcode
!= FETCH_OP_SAMPLE_C_L
&&
7823 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
7824 tex
.src_sel_w
= tex
.src_sel_z
;
7827 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
7828 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
7829 if (opcode
== FETCH_OP_SAMPLE_C_L
||
7830 opcode
== FETCH_OP_SAMPLE_C_LB
) {
7831 /* the array index is read from Y */
7832 tex
.coord_type_y
= 0;
7834 /* the array index is read from Z */
7835 tex
.coord_type_z
= 0;
7836 tex
.src_sel_z
= tex
.src_sel_y
;
7838 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7839 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7840 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7841 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7842 (ctx
->bc
->chip_class
>= EVERGREEN
)))
7843 /* the array index is read from Z */
7844 tex
.coord_type_z
= 0;
7846 /* mask unused source components */
7847 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
7848 switch (inst
->Texture
.Texture
) {
7849 case TGSI_TEXTURE_2D
:
7850 case TGSI_TEXTURE_RECT
:
7854 case TGSI_TEXTURE_1D_ARRAY
:
7858 case TGSI_TEXTURE_1D
:
7866 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7870 /* add shadow ambient support - gallium doesn't do it yet */
7874 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
7875 struct tgsi_full_src_register
*src
)
7879 if (src
->Register
.Indirect
) {
7880 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7881 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
7882 return ctx
->shader
->atomics
[i
].hw_idx
;
7885 uint32_t index
= src
->Register
.Index
;
7886 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7887 if (ctx
->shader
->atomics
[i
].buffer_id
!= (unsigned)src
->Dimension
.Index
)
7889 if (index
> ctx
->shader
->atomics
[i
].end
)
7891 if (index
< ctx
->shader
->atomics
[i
].start
)
7893 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
7894 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
7901 static int tgsi_set_gds_temp(struct r600_shader_ctx
*ctx
,
7902 int *uav_id_p
, int *uav_index_mode_p
)
7904 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7905 int uav_id
, uav_index_mode
= 0;
7907 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
7909 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7911 if (inst
->Src
[0].Register
.Indirect
) {
7913 struct r600_bytecode_alu alu
;
7914 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7915 alu
.op
= ALU_OP2_LSHL_INT
;
7916 alu
.src
[0].sel
= get_address_file_reg(ctx
, inst
->Src
[0].Indirect
.Index
);
7917 alu
.src
[0].chan
= 0;
7918 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7919 alu
.src
[1].value
= 2;
7920 alu
.dst
.sel
= ctx
->temp_reg
;
7924 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7928 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
7931 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4);
7937 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
7939 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4,
7945 *uav_index_mode_p
= uav_index_mode
;
7949 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
7951 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7953 struct r600_bytecode_gds gds
;
7955 int uav_index_mode
= 0;
7956 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
7958 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
7962 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
7963 gds
.op
= FETCH_OP_GDS_READ_RET
;
7964 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7965 gds
.uav_id
= is_cm
? 0 : uav_id
;
7966 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
7967 gds
.src_gpr
= ctx
->temp_reg
;
7968 gds
.src_sel_x
= (is_cm
) ? 0 : 4;
7976 gds
.alloc_consume
= !is_cm
;
7977 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
7981 ctx
->bc
->cf_last
->vpm
= 1;
7985 /* this fixes up 1D arrays properly */
7986 static int load_index_src(struct r600_shader_ctx
*ctx
, int src_index
, int *idx_gpr
)
7988 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7990 struct r600_bytecode_alu alu
;
7991 int temp_reg
= r600_get_temp(ctx
);
7993 for (i
= 0; i
< 4; i
++) {
7994 bool def_val
= true, write_zero
= false;
7995 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7996 alu
.op
= ALU_OP1_MOV
;
7997 alu
.dst
.sel
= temp_reg
;
8000 switch (inst
->Memory
.Texture
) {
8001 case TGSI_TEXTURE_BUFFER
:
8002 case TGSI_TEXTURE_1D
:
8003 if (i
== 1 || i
== 2 || i
== 3) {
8007 case TGSI_TEXTURE_1D_ARRAY
:
8008 if (i
== 1 || i
== 3)
8011 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], 1);
8015 case TGSI_TEXTURE_2D
:
8016 if (i
== 2 || i
== 3)
8026 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8027 alu
.src
[0].value
= 0;
8028 } else if (def_val
) {
8029 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], i
);
8035 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8039 *idx_gpr
= temp_reg
;
8043 static int load_buffer_coord(struct r600_shader_ctx
*ctx
, int src_idx
,
8046 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8048 if (inst
->Src
[src_idx
].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8049 int value
= (ctx
->literals
[4 * inst
->Src
[src_idx
].Register
.Index
+ inst
->Src
[src_idx
].Register
.SwizzleX
]);
8050 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8052 V_SQ_ALU_SRC_LITERAL
, value
>> 2,
8057 struct r600_bytecode_alu alu
;
8058 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8059 alu
.op
= ALU_OP2_LSHR_INT
;
8060 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_idx
], 0);
8061 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8062 alu
.src
[1].value
= 2;
8063 alu
.dst
.sel
= temp_reg
;
8066 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8073 static int tgsi_load_buffer(struct r600_shader_ctx
*ctx
)
8075 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8076 /* have to work out the offset into the RAT immediate return buffer */
8077 struct r600_bytecode_vtx vtx
;
8078 struct r600_bytecode_cf
*cf
;
8080 int temp_reg
= r600_get_temp(ctx
);
8081 unsigned rat_index_mode
;
8084 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8085 base
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8087 r
= load_buffer_coord(ctx
, 1, temp_reg
);
8090 ctx
->bc
->cf_last
->barrier
= 1;
8091 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8092 vtx
.op
= FETCH_OP_VFETCH
;
8093 vtx
.buffer_id
= inst
->Src
[0].Register
.Index
+ base
;
8094 vtx
.buffer_index_mode
= rat_index_mode
;
8095 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8096 vtx
.src_gpr
= temp_reg
;
8098 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8099 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
8100 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
8101 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
8102 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
8103 vtx
.num_format_all
= 1;
8104 vtx
.format_comp_all
= 1;
8105 vtx
.srf_mode_all
= 0;
8107 if (inst
->Dst
[0].Register
.WriteMask
& 8) {
8108 vtx
.data_format
= FMT_32_32_32_32
;
8109 vtx
.use_const_fields
= 0;
8110 } else if (inst
->Dst
[0].Register
.WriteMask
& 4) {
8111 vtx
.data_format
= FMT_32_32_32
;
8112 vtx
.use_const_fields
= 0;
8113 } else if (inst
->Dst
[0].Register
.WriteMask
& 2) {
8114 vtx
.data_format
= FMT_32_32
;
8115 vtx
.use_const_fields
= 0;
8117 vtx
.data_format
= FMT_32
;
8118 vtx
.use_const_fields
= 0;
8121 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8124 cf
= ctx
->bc
->cf_last
;
8129 static int tgsi_load_rat(struct r600_shader_ctx
*ctx
)
8131 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8132 /* have to work out the offset into the RAT immediate return buffer */
8133 struct r600_bytecode_vtx vtx
;
8134 struct r600_bytecode_cf
*cf
;
8137 unsigned format
, num_format
, format_comp
, endian
;
8138 const struct util_format_description
*desc
;
8139 unsigned rat_index_mode
;
8140 unsigned immed_base
;
8142 r
= load_thread_id_gpr(ctx
);
8146 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8148 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8149 r
= load_index_src(ctx
, 1, &idx_gpr
);
8154 egcm_load_index_reg(ctx
->bc
, 1, false);
8156 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8157 cf
= ctx
->bc
->cf_last
;
8159 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
8160 cf
->rat
.inst
= V_RAT_INST_NOP_RTN
;
8161 cf
->rat
.index_mode
= rat_index_mode
;
8162 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8163 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8164 cf
->output
.index_gpr
= idx_gpr
;
8165 cf
->output
.comp_mask
= 0xf;
8166 cf
->output
.burst_count
= 1;
8170 cf
->output
.elem_size
= 0;
8172 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8173 cf
= ctx
->bc
->cf_last
;
8176 desc
= util_format_description(inst
->Memory
.Format
);
8177 r600_vertex_data_type(inst
->Memory
.Format
,
8178 &format
, &num_format
, &format_comp
, &endian
);
8179 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8180 vtx
.op
= FETCH_OP_VFETCH
;
8181 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8182 vtx
.buffer_index_mode
= rat_index_mode
;
8183 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8184 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8186 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8187 vtx
.dst_sel_x
= desc
->swizzle
[0];
8188 vtx
.dst_sel_y
= desc
->swizzle
[1];
8189 vtx
.dst_sel_z
= desc
->swizzle
[2];
8190 vtx
.dst_sel_w
= desc
->swizzle
[3];
8191 vtx
.srf_mode_all
= 1;
8192 vtx
.data_format
= format
;
8193 vtx
.num_format_all
= num_format
;
8194 vtx
.format_comp_all
= format_comp
;
8195 vtx
.endian
= endian
;
8197 vtx
.mega_fetch_count
= 3;
8198 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8201 cf
= ctx
->bc
->cf_last
;
8206 static int tgsi_load_lds(struct r600_shader_ctx
*ctx
)
8208 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8209 struct r600_bytecode_alu alu
;
8211 int temp_reg
= r600_get_temp(ctx
);
8213 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8214 alu
.op
= ALU_OP1_MOV
;
8215 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8216 alu
.dst
.sel
= temp_reg
;
8219 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8223 r
= do_lds_fetch_values(ctx
, temp_reg
,
8224 ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
, inst
->Dst
[0].Register
.WriteMask
);
8230 static int tgsi_load(struct r600_shader_ctx
*ctx
)
8232 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8233 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8234 return tgsi_load_rat(ctx
);
8235 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8236 return tgsi_load_gds(ctx
);
8237 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8238 return tgsi_load_buffer(ctx
);
8239 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8240 return tgsi_load_lds(ctx
);
8244 static int tgsi_store_buffer_rat(struct r600_shader_ctx
*ctx
)
8246 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8247 struct r600_bytecode_cf
*cf
;
8249 unsigned rat_index_mode
;
8251 int temp_reg
= r600_get_temp(ctx
), treg2
= r600_get_temp(ctx
);
8253 r
= load_buffer_coord(ctx
, 0, treg2
);
8257 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8259 egcm_load_index_reg(ctx
->bc
, 1, false);
8261 for (i
= 0; i
<= 3; i
++) {
8262 struct r600_bytecode_alu alu
;
8263 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8264 alu
.op
= ALU_OP1_MOV
;
8265 alu
.dst
.sel
= temp_reg
;
8267 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
8268 alu
.last
= (i
== 3);
8270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8275 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8276 for (i
= 0; i
<= lasti
; i
++) {
8277 struct r600_bytecode_alu alu
;
8278 if (!((1 << i
) & inst
->Dst
[0].Register
.WriteMask
))
8281 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8284 V_SQ_ALU_SRC_LITERAL
, i
);
8288 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8289 alu
.op
= ALU_OP1_MOV
;
8290 alu
.dst
.sel
= ctx
->temp_reg
;
8293 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8296 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8300 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8301 cf
= ctx
->bc
->cf_last
;
8303 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8304 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8305 cf
->rat
.index_mode
= rat_index_mode
;
8306 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8307 cf
->output
.gpr
= ctx
->temp_reg
;
8308 cf
->output
.index_gpr
= temp_reg
;
8309 cf
->output
.comp_mask
= 1;
8310 cf
->output
.burst_count
= 1;
8313 cf
->output
.elem_size
= 0;
8318 static int tgsi_store_rat(struct r600_shader_ctx
*ctx
)
8320 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8321 struct r600_bytecode_cf
*cf
;
8322 bool src_requires_loading
= false;
8323 int val_gpr
, idx_gpr
;
8325 unsigned rat_index_mode
;
8327 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8329 r
= load_index_src(ctx
, 0, &idx_gpr
);
8333 if (inst
->Src
[1].Register
.File
!= TGSI_FILE_TEMPORARY
)
8334 src_requires_loading
= true;
8336 if (src_requires_loading
) {
8337 struct r600_bytecode_alu alu
;
8338 for (i
= 0; i
< 4; i
++) {
8339 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8340 alu
.op
= ALU_OP1_MOV
;
8341 alu
.dst
.sel
= ctx
->temp_reg
;
8344 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8348 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8352 val_gpr
= ctx
->temp_reg
;
8354 val_gpr
= tgsi_tex_get_src_gpr(ctx
, 1);
8356 egcm_load_index_reg(ctx
->bc
, 1, false);
8358 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8359 cf
= ctx
->bc
->cf_last
;
8361 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
;
8362 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8363 cf
->rat
.index_mode
= rat_index_mode
;
8364 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8365 cf
->output
.gpr
= val_gpr
;
8366 cf
->output
.index_gpr
= idx_gpr
;
8367 cf
->output
.comp_mask
= 0xf;
8368 cf
->output
.burst_count
= 1;
8371 cf
->output
.elem_size
= 0;
8375 static int tgsi_store_lds(struct r600_shader_ctx
*ctx
)
8377 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8378 struct r600_bytecode_alu alu
;
8380 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
8381 int temp_reg
= r600_get_temp(ctx
);
8384 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8385 alu
.op
= ALU_OP1_MOV
;
8386 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8387 alu
.dst
.sel
= temp_reg
;
8390 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8394 lasti
= tgsi_last_instruction(write_mask
);
8395 for (i
= 1; i
<= lasti
; i
++) {
8396 if (!(write_mask
& (1 << i
)))
8398 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8401 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
8405 for (i
= 0; i
<= lasti
; i
++) {
8406 if (!(write_mask
& (1 << i
)))
8409 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
8410 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
8411 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8412 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
8414 alu
.src
[0].sel
= temp_reg
;
8415 alu
.src
[0].chan
= i
;
8416 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8417 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
+ 1);
8419 alu
.is_lds_idx_op
= true;
8421 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8427 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8428 alu
.op
= LDS_OP2_LDS_WRITE
;
8430 alu
.src
[0].sel
= temp_reg
;
8431 alu
.src
[0].chan
= i
;
8432 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8435 alu
.is_lds_idx_op
= true;
8437 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8444 static int tgsi_store(struct r600_shader_ctx
*ctx
)
8446 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8447 if (inst
->Dst
[0].Register
.File
== TGSI_FILE_BUFFER
)
8448 return tgsi_store_buffer_rat(ctx
);
8449 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_MEMORY
)
8450 return tgsi_store_lds(ctx
);
8452 return tgsi_store_rat(ctx
);
8455 static int tgsi_atomic_op_rat(struct r600_shader_ctx
*ctx
)
8457 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8458 /* have to work out the offset into the RAT immediate return buffer */
8459 struct r600_bytecode_alu alu
;
8460 struct r600_bytecode_vtx vtx
;
8461 struct r600_bytecode_cf
*cf
;
8464 unsigned format
, num_format
, format_comp
, endian
;
8465 const struct util_format_description
*desc
;
8466 unsigned rat_index_mode
;
8467 unsigned immed_base
;
8470 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8471 rat_base
= ctx
->shader
->rat_base
;
8473 r
= load_thread_id_gpr(ctx
);
8477 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
) {
8478 immed_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8479 rat_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8481 r
= load_buffer_coord(ctx
, 1, ctx
->temp_reg
);
8484 idx_gpr
= ctx
->temp_reg
;
8486 r
= load_index_src(ctx
, 1, &idx_gpr
);
8491 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8493 if (ctx
->inst_info
->op
== V_RAT_INST_CMPXCHG_INT_RTN
) {
8494 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8495 alu
.op
= ALU_OP1_MOV
;
8496 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8499 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8501 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8505 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8506 alu
.op
= ALU_OP1_MOV
;
8507 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8508 if (ctx
->bc
->chip_class
== CAYMAN
)
8513 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8515 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8519 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8520 alu
.op
= ALU_OP1_MOV
;
8521 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8524 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8526 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8532 egcm_load_index_reg(ctx
->bc
, 1, false);
8533 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8534 cf
= ctx
->bc
->cf_last
;
8536 cf
->rat
.id
= rat_base
+ inst
->Src
[0].Register
.Index
;
8537 cf
->rat
.inst
= ctx
->inst_info
->op
;
8538 cf
->rat
.index_mode
= rat_index_mode
;
8539 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8540 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8541 cf
->output
.index_gpr
= idx_gpr
;
8542 cf
->output
.comp_mask
= 0xf;
8543 cf
->output
.burst_count
= 1;
8547 cf
->output
.elem_size
= 0;
8548 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8549 cf
= ctx
->bc
->cf_last
;
8553 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8554 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
) {
8555 desc
= util_format_description(inst
->Memory
.Format
);
8556 r600_vertex_data_type(inst
->Memory
.Format
,
8557 &format
, &num_format
, &format_comp
, &endian
);
8558 vtx
.dst_sel_x
= desc
->swizzle
[0];
8566 vtx
.op
= FETCH_OP_VFETCH
;
8567 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8568 vtx
.buffer_index_mode
= rat_index_mode
;
8569 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8570 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8572 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8576 vtx
.use_const_fields
= 0;
8577 vtx
.srf_mode_all
= 1;
8578 vtx
.data_format
= format
;
8579 vtx
.num_format_all
= num_format
;
8580 vtx
.format_comp_all
= format_comp
;
8581 vtx
.endian
= endian
;
8583 vtx
.mega_fetch_count
= 0xf;
8584 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8587 cf
= ctx
->bc
->cf_last
;
8593 static int get_gds_op(int opcode
)
8596 case TGSI_OPCODE_ATOMUADD
:
8597 return FETCH_OP_GDS_ADD_RET
;
8598 case TGSI_OPCODE_ATOMAND
:
8599 return FETCH_OP_GDS_AND_RET
;
8600 case TGSI_OPCODE_ATOMOR
:
8601 return FETCH_OP_GDS_OR_RET
;
8602 case TGSI_OPCODE_ATOMXOR
:
8603 return FETCH_OP_GDS_XOR_RET
;
8604 case TGSI_OPCODE_ATOMUMIN
:
8605 return FETCH_OP_GDS_MIN_UINT_RET
;
8606 case TGSI_OPCODE_ATOMUMAX
:
8607 return FETCH_OP_GDS_MAX_UINT_RET
;
8608 case TGSI_OPCODE_ATOMXCHG
:
8609 return FETCH_OP_GDS_XCHG_RET
;
8610 case TGSI_OPCODE_ATOMCAS
:
8611 return FETCH_OP_GDS_CMP_XCHG_RET
;
8617 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
8619 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8620 struct r600_bytecode_gds gds
;
8621 struct r600_bytecode_alu alu
;
8622 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
8625 int uav_index_mode
= 0;
8626 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8629 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
8633 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8637 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8638 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
8639 int abs_value
= abs(value
);
8640 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
8641 gds_op
= FETCH_OP_GDS_SUB_RET
;
8642 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8643 alu
.op
= ALU_OP1_MOV
;
8644 alu
.dst
.sel
= ctx
->temp_reg
;
8645 alu
.dst
.chan
= is_cm
? 1 : 0;
8646 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8647 alu
.src
[0].value
= abs_value
;
8650 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8654 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8655 alu
.op
= ALU_OP1_MOV
;
8656 alu
.dst
.sel
= ctx
->temp_reg
;
8657 alu
.dst
.chan
= is_cm
? 1 : 0;
8658 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8661 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8667 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8669 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8670 gds
.uav_id
= is_cm
? 0 : uav_id
;
8671 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8672 gds
.src_gpr
= ctx
->temp_reg
;
8674 gds
.src_sel_x
= is_cm
? 0 : 4;
8675 gds
.src_sel_y
= is_cm
? 1 : 0;
8681 gds
.alloc_consume
= !is_cm
;
8683 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8686 ctx
->bc
->cf_last
->vpm
= 1;
8690 static int get_lds_op(int opcode
)
8693 case TGSI_OPCODE_ATOMUADD
:
8694 return LDS_OP2_LDS_ADD_RET
;
8695 case TGSI_OPCODE_ATOMAND
:
8696 return LDS_OP2_LDS_AND_RET
;
8697 case TGSI_OPCODE_ATOMOR
:
8698 return LDS_OP2_LDS_OR_RET
;
8699 case TGSI_OPCODE_ATOMXOR
:
8700 return LDS_OP2_LDS_XOR_RET
;
8701 case TGSI_OPCODE_ATOMUMIN
:
8702 return LDS_OP2_LDS_MIN_UINT_RET
;
8703 case TGSI_OPCODE_ATOMUMAX
:
8704 return LDS_OP2_LDS_MAX_UINT_RET
;
8705 case TGSI_OPCODE_ATOMIMIN
:
8706 return LDS_OP2_LDS_MIN_INT_RET
;
8707 case TGSI_OPCODE_ATOMIMAX
:
8708 return LDS_OP2_LDS_MAX_INT_RET
;
8709 case TGSI_OPCODE_ATOMXCHG
:
8710 return LDS_OP2_LDS_XCHG_RET
;
8711 case TGSI_OPCODE_ATOMCAS
:
8712 return LDS_OP3_LDS_CMP_XCHG_RET
;
8718 static int tgsi_atomic_op_lds(struct r600_shader_ctx
*ctx
)
8720 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8721 int lds_op
= get_lds_op(inst
->Instruction
.Opcode
);
8724 struct r600_bytecode_alu alu
;
8725 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8727 alu
.is_lds_idx_op
= true;
8729 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8730 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], 0);
8731 if (lds_op
== LDS_OP3_LDS_CMP_XCHG_RET
)
8732 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[3], 0);
8734 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
8735 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8739 /* then read from LDS_OQ_A_POP */
8740 memset(&alu
, 0, sizeof(alu
));
8742 alu
.op
= ALU_OP1_MOV
;
8743 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
8744 alu
.src
[0].chan
= 0;
8745 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
8748 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8755 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
8757 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8758 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8759 return tgsi_atomic_op_rat(ctx
);
8760 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8761 return tgsi_atomic_op_gds(ctx
);
8762 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8763 return tgsi_atomic_op_rat(ctx
);
8764 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8765 return tgsi_atomic_op_lds(ctx
);
8769 static int tgsi_resq(struct r600_shader_ctx
*ctx
)
8771 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8772 unsigned sampler_index_mode
;
8773 struct r600_bytecode_tex tex
;
8775 boolean has_txq_cube_array_z
= false;
8777 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
||
8778 (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
&& inst
->Memory
.Texture
== TGSI_TEXTURE_BUFFER
)) {
8779 ctx
->shader
->uses_tex_buffers
= true;
8780 return r600_do_buffer_txq(ctx
, 0, ctx
->shader
->image_size_const_offset
);
8783 if (inst
->Memory
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
&&
8784 inst
->Dst
[0].Register
.WriteMask
& 4) {
8785 ctx
->shader
->has_txq_cube_array_z_comp
= true;
8786 has_txq_cube_array_z
= true;
8789 sampler_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8790 if (sampler_index_mode
)
8791 egcm_load_index_reg(ctx
->bc
, 1, false);
8794 /* does this shader want a num layers from TXQ for a cube array? */
8795 if (has_txq_cube_array_z
) {
8796 int id
= tgsi_tex_get_src_gpr(ctx
, 0) + ctx
->shader
->image_size_const_offset
;
8797 struct r600_bytecode_alu alu
;
8799 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8800 alu
.op
= ALU_OP1_MOV
;
8802 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
8803 /* channel 1 or 3 of each word */
8804 alu
.src
[0].sel
+= (id
/ 2);
8805 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
8806 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
8807 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
8809 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8812 /* disable writemask from texture instruction */
8813 inst
->Dst
[0].Register
.WriteMask
&= ~4;
8815 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8816 tex
.op
= ctx
->inst_info
->op
;
8817 tex
.sampler_id
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ inst
->Src
[0].Register
.Index
;
8818 tex
.sampler_index_mode
= sampler_index_mode
;
8819 tex
.resource_id
= tex
.sampler_id
;
8820 tex
.resource_index_mode
= sampler_index_mode
;
8825 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8826 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8827 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8828 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8829 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8830 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8837 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
8839 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8840 struct r600_bytecode_alu alu
;
8841 unsigned lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8842 unsigned i
, temp_regs
[2];
8845 /* optimize if it's just an equal balance */
8846 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
8847 for (i
= 0; i
< lasti
+ 1; i
++) {
8848 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8852 alu
.op
= ALU_OP2_ADD
;
8853 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8854 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8856 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8861 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8869 for (i
= 0; i
< lasti
+ 1; i
++) {
8870 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8873 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8874 alu
.op
= ALU_OP2_ADD
;
8875 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8876 alu
.src
[0].chan
= 0;
8877 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
8878 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
8879 alu
.dst
.sel
= ctx
->temp_reg
;
8885 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8890 /* (1 - src0) * src2 */
8891 for (i
= 0; i
< lasti
+ 1; i
++) {
8892 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8895 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8896 alu
.op
= ALU_OP2_MUL
;
8897 alu
.src
[0].sel
= ctx
->temp_reg
;
8898 alu
.src
[0].chan
= i
;
8899 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8900 alu
.dst
.sel
= ctx
->temp_reg
;
8906 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8911 /* src0 * src1 + (1 - src0) * src2 */
8912 if (ctx
->src
[0].abs
)
8913 temp_regs
[0] = r600_get_temp(ctx
);
8916 if (ctx
->src
[1].abs
)
8917 temp_regs
[1] = r600_get_temp(ctx
);
8921 for (i
= 0; i
< lasti
+ 1; i
++) {
8922 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8925 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8926 alu
.op
= ALU_OP3_MULADD
;
8928 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
8931 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
8934 alu
.src
[2].sel
= ctx
->temp_reg
;
8935 alu
.src
[2].chan
= i
;
8937 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8942 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8949 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
8951 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8952 struct r600_bytecode_alu alu
;
8954 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8958 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
8960 ctx
->src
[0].abs
= 0;
8961 ctx
->src
[0].neg
= 0;
8966 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
8968 if (ctx
->src
[j
].abs
)
8969 temp_regs
[j
] = r600_get_temp(ctx
);
8972 for (i
= 0; i
< lasti
+ 1; i
++) {
8973 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8976 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8978 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
8981 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
8984 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
8987 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9000 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
9002 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9003 struct r600_bytecode_alu alu
;
9005 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9007 for (i
= 0; i
< lasti
+ 1; i
++) {
9008 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9011 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9012 alu
.op
= ALU_OP3_CNDE_INT
;
9013 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9014 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9015 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
9016 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9022 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9029 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
9031 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9032 struct r600_bytecode_alu alu
;
9036 /* result.x = 2^floor(src); */
9037 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9038 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9040 alu
.op
= ALU_OP1_FLOOR
;
9041 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9043 alu
.dst
.sel
= ctx
->temp_reg
;
9047 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9051 if (ctx
->bc
->chip_class
== CAYMAN
) {
9052 for (i
= 0; i
< 3; i
++) {
9053 alu
.op
= ALU_OP1_EXP_IEEE
;
9054 alu
.src
[0].sel
= ctx
->temp_reg
;
9055 alu
.src
[0].chan
= 0;
9057 alu
.dst
.sel
= ctx
->temp_reg
;
9059 alu
.dst
.write
= i
== 0;
9061 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9066 alu
.op
= ALU_OP1_EXP_IEEE
;
9067 alu
.src
[0].sel
= ctx
->temp_reg
;
9068 alu
.src
[0].chan
= 0;
9070 alu
.dst
.sel
= ctx
->temp_reg
;
9074 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9080 /* result.y = tmp - floor(tmp); */
9081 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9082 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9084 alu
.op
= ALU_OP1_FRACT
;
9085 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9087 alu
.dst
.sel
= ctx
->temp_reg
;
9089 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9098 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9103 /* result.z = RoughApprox2ToX(tmp);*/
9104 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
9105 if (ctx
->bc
->chip_class
== CAYMAN
) {
9106 for (i
= 0; i
< 3; i
++) {
9107 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9108 alu
.op
= ALU_OP1_EXP_IEEE
;
9109 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9111 alu
.dst
.sel
= ctx
->temp_reg
;
9118 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9123 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9124 alu
.op
= ALU_OP1_EXP_IEEE
;
9125 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9127 alu
.dst
.sel
= ctx
->temp_reg
;
9133 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9139 /* result.w = 1.0;*/
9140 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
9141 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9143 alu
.op
= ALU_OP1_MOV
;
9144 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9145 alu
.src
[0].chan
= 0;
9147 alu
.dst
.sel
= ctx
->temp_reg
;
9151 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9155 return tgsi_helper_copy(ctx
, inst
);
9158 static int tgsi_log(struct r600_shader_ctx
*ctx
)
9160 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9161 struct r600_bytecode_alu alu
;
9165 /* result.x = floor(log2(|src|)); */
9166 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9167 if (ctx
->bc
->chip_class
== CAYMAN
) {
9168 for (i
= 0; i
< 3; i
++) {
9169 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9171 alu
.op
= ALU_OP1_LOG_IEEE
;
9172 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9173 r600_bytecode_src_set_abs(&alu
.src
[0]);
9175 alu
.dst
.sel
= ctx
->temp_reg
;
9181 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9187 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9189 alu
.op
= ALU_OP1_LOG_IEEE
;
9190 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9191 r600_bytecode_src_set_abs(&alu
.src
[0]);
9193 alu
.dst
.sel
= ctx
->temp_reg
;
9197 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9202 alu
.op
= ALU_OP1_FLOOR
;
9203 alu
.src
[0].sel
= ctx
->temp_reg
;
9204 alu
.src
[0].chan
= 0;
9206 alu
.dst
.sel
= ctx
->temp_reg
;
9211 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9216 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
9217 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9219 if (ctx
->bc
->chip_class
== CAYMAN
) {
9220 for (i
= 0; i
< 3; i
++) {
9221 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9223 alu
.op
= ALU_OP1_LOG_IEEE
;
9224 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9225 r600_bytecode_src_set_abs(&alu
.src
[0]);
9227 alu
.dst
.sel
= ctx
->temp_reg
;
9234 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9239 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9241 alu
.op
= ALU_OP1_LOG_IEEE
;
9242 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9243 r600_bytecode_src_set_abs(&alu
.src
[0]);
9245 alu
.dst
.sel
= ctx
->temp_reg
;
9250 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9255 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9257 alu
.op
= ALU_OP1_FLOOR
;
9258 alu
.src
[0].sel
= ctx
->temp_reg
;
9259 alu
.src
[0].chan
= 1;
9261 alu
.dst
.sel
= ctx
->temp_reg
;
9266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9270 if (ctx
->bc
->chip_class
== CAYMAN
) {
9271 for (i
= 0; i
< 3; i
++) {
9272 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9273 alu
.op
= ALU_OP1_EXP_IEEE
;
9274 alu
.src
[0].sel
= ctx
->temp_reg
;
9275 alu
.src
[0].chan
= 1;
9277 alu
.dst
.sel
= ctx
->temp_reg
;
9284 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9289 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9290 alu
.op
= ALU_OP1_EXP_IEEE
;
9291 alu
.src
[0].sel
= ctx
->temp_reg
;
9292 alu
.src
[0].chan
= 1;
9294 alu
.dst
.sel
= ctx
->temp_reg
;
9299 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9304 if (ctx
->bc
->chip_class
== CAYMAN
) {
9305 for (i
= 0; i
< 3; i
++) {
9306 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9307 alu
.op
= ALU_OP1_RECIP_IEEE
;
9308 alu
.src
[0].sel
= ctx
->temp_reg
;
9309 alu
.src
[0].chan
= 1;
9311 alu
.dst
.sel
= ctx
->temp_reg
;
9318 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9323 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9324 alu
.op
= ALU_OP1_RECIP_IEEE
;
9325 alu
.src
[0].sel
= ctx
->temp_reg
;
9326 alu
.src
[0].chan
= 1;
9328 alu
.dst
.sel
= ctx
->temp_reg
;
9333 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9338 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9340 alu
.op
= ALU_OP2_MUL
;
9342 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9343 r600_bytecode_src_set_abs(&alu
.src
[0]);
9345 alu
.src
[1].sel
= ctx
->temp_reg
;
9346 alu
.src
[1].chan
= 1;
9348 alu
.dst
.sel
= ctx
->temp_reg
;
9353 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9358 /* result.z = log2(|src|);*/
9359 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
9360 if (ctx
->bc
->chip_class
== CAYMAN
) {
9361 for (i
= 0; i
< 3; i
++) {
9362 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9364 alu
.op
= ALU_OP1_LOG_IEEE
;
9365 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9366 r600_bytecode_src_set_abs(&alu
.src
[0]);
9368 alu
.dst
.sel
= ctx
->temp_reg
;
9375 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9380 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9382 alu
.op
= ALU_OP1_LOG_IEEE
;
9383 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9384 r600_bytecode_src_set_abs(&alu
.src
[0]);
9386 alu
.dst
.sel
= ctx
->temp_reg
;
9391 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9397 /* result.w = 1.0; */
9398 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
9399 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9401 alu
.op
= ALU_OP1_MOV
;
9402 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9403 alu
.src
[0].chan
= 0;
9405 alu
.dst
.sel
= ctx
->temp_reg
;
9410 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9415 return tgsi_helper_copy(ctx
, inst
);
9418 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
9420 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9421 struct r600_bytecode_alu alu
;
9423 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9424 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
9426 assert(inst
->Dst
[0].Register
.Index
< 3);
9427 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9429 switch (inst
->Instruction
.Opcode
) {
9430 case TGSI_OPCODE_ARL
:
9431 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
9433 case TGSI_OPCODE_ARR
:
9434 alu
.op
= ALU_OP1_FLT_TO_INT
;
9436 case TGSI_OPCODE_UARL
:
9437 alu
.op
= ALU_OP1_MOV
;
9444 for (i
= 0; i
<= lasti
; ++i
) {
9445 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9447 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9448 alu
.last
= i
== lasti
;
9452 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9457 if (inst
->Dst
[0].Register
.Index
> 0)
9458 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
9460 ctx
->bc
->ar_loaded
= 0;
9464 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
9466 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9467 struct r600_bytecode_alu alu
;
9469 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9471 switch (inst
->Instruction
.Opcode
) {
9472 case TGSI_OPCODE_ARL
:
9473 memset(&alu
, 0, sizeof(alu
));
9474 alu
.op
= ALU_OP1_FLOOR
;
9475 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9477 for (i
= 0; i
<= lasti
; ++i
) {
9478 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9480 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9481 alu
.last
= i
== lasti
;
9482 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9487 memset(&alu
, 0, sizeof(alu
));
9488 alu
.op
= ALU_OP1_FLT_TO_INT
;
9489 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
9490 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9492 /* FLT_TO_INT is trans-only on r600/r700 */
9494 for (i
= 0; i
<= lasti
; ++i
) {
9496 alu
.src
[0].chan
= i
;
9497 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9501 case TGSI_OPCODE_ARR
:
9502 memset(&alu
, 0, sizeof(alu
));
9503 alu
.op
= ALU_OP1_FLT_TO_INT
;
9504 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9506 /* FLT_TO_INT is trans-only on r600/r700 */
9508 for (i
= 0; i
<= lasti
; ++i
) {
9509 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9511 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9512 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9517 case TGSI_OPCODE_UARL
:
9518 memset(&alu
, 0, sizeof(alu
));
9519 alu
.op
= ALU_OP1_MOV
;
9520 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9522 for (i
= 0; i
<= lasti
; ++i
) {
9523 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9525 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9526 alu
.last
= i
== lasti
;
9527 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9537 ctx
->bc
->ar_loaded
= 0;
9541 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
9543 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9544 struct r600_bytecode_alu alu
;
9547 for (i
= 0; i
< 4; i
++) {
9548 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9550 alu
.op
= ALU_OP2_MUL
;
9551 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9553 if (i
== 0 || i
== 3) {
9554 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9556 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9559 if (i
== 0 || i
== 2) {
9560 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
9562 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
9566 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9573 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
9575 struct r600_bytecode_alu alu
;
9578 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9580 alu
.execute_mask
= 1;
9581 alu
.update_pred
= 1;
9583 alu
.dst
.sel
= ctx
->temp_reg
;
9587 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9588 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
9589 alu
.src
[1].chan
= 0;
9593 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
9599 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
9601 unsigned force_pop
= ctx
->bc
->force_add_cf
;
9605 if (ctx
->bc
->cf_last
) {
9606 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
9608 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
9613 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
9614 ctx
->bc
->force_add_cf
= 1;
9615 } else if (alu_pop
== 2) {
9616 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
9617 ctx
->bc
->force_add_cf
= 1;
9624 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
9625 ctx
->bc
->cf_last
->pop_count
= pops
;
9626 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9632 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
9635 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
9639 unsigned entry_size
= stack
->entry_size
;
9641 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
9642 elements
+= stack
->push
;
9644 switch (ctx
->bc
->chip_class
) {
9647 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
9648 * the stack must be reserved to hold the current active/continue
9650 if (reason
== FC_PUSH_VPM
) {
9656 /* r9xx: any stack operation on empty stack consumes 2 additional
9661 /* FIXME: do the two elements added above cover the cases for the
9665 /* r8xx+: 2 extra elements are not always required, but one extra
9666 * element must be added for each of the following cases:
9667 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
9669 * (Currently we don't use ALU_ELSE_AFTER.)
9670 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
9671 * PUSH instruction executed.
9673 * NOTE: it seems we also need to reserve additional element in some
9674 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
9675 * then STACK_SIZE should be 2 instead of 1 */
9676 if (reason
== FC_PUSH_VPM
) {
9686 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
9687 * for all chips, so we use 4 in the final formula, not the real entry_size
9691 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
9693 if (entries
> stack
->max_entries
)
9694 stack
->max_entries
= entries
;
9697 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
9701 --ctx
->bc
->stack
.push
;
9702 assert(ctx
->bc
->stack
.push
>= 0);
9705 --ctx
->bc
->stack
.push_wqm
;
9706 assert(ctx
->bc
->stack
.push_wqm
>= 0);
9709 --ctx
->bc
->stack
.loop
;
9710 assert(ctx
->bc
->stack
.loop
>= 0);
9718 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
9722 ++ctx
->bc
->stack
.push
;
9725 ++ctx
->bc
->stack
.push_wqm
;
9727 ++ctx
->bc
->stack
.loop
;
9733 callstack_update_max_depth(ctx
, reason
);
9736 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
9738 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
9740 sp
->mid
= realloc((void *)sp
->mid
,
9741 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
9742 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
9746 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
9748 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
9749 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
9750 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
9754 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
9756 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
9766 static int emit_return(struct r600_shader_ctx
*ctx
)
9768 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
9772 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
9775 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
9776 ctx
->bc
->cf_last
->pop_count
= pops
;
9777 /* XXX work out offset */
9781 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
9786 static void emit_testflag(struct r600_shader_ctx
*ctx
)
9791 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
9794 emit_jump_to_offset(ctx
, 1, 4);
9795 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
9796 pops(ctx
, ifidx
+ 1);
9800 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
9804 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9805 ctx
->bc
->cf_last
->pop_count
= 1;
9807 fc_set_mid(ctx
, fc_sp
);
9813 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
9815 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
9817 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
9818 * LOOP_STARTxxx for nested loops may put the branch stack into a state
9819 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
9820 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
9821 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
9822 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
9823 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9824 alu_type
= CF_OP_ALU
;
9827 emit_logic_pred(ctx
, opcode
, alu_type
);
9829 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
9831 fc_pushlevel(ctx
, FC_IF
);
9833 callstack_push(ctx
, FC_PUSH_VPM
);
9837 static int tgsi_if(struct r600_shader_ctx
*ctx
)
9839 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
9842 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
9844 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
9847 static int tgsi_else(struct r600_shader_ctx
*ctx
)
9849 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
9850 ctx
->bc
->cf_last
->pop_count
= 1;
9852 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
9853 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
9857 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
9860 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
9861 R600_ERR("if/endif unbalanced in shader\n");
9865 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
9866 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9867 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
9869 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9873 callstack_pop(ctx
, FC_PUSH_VPM
);
9877 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
9879 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
9880 * limited to 4096 iterations, like the other LOOP_* instructions. */
9881 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
9883 fc_pushlevel(ctx
, FC_LOOP
);
9885 /* check stack depth */
9886 callstack_push(ctx
, FC_LOOP
);
9890 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
9894 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
9896 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
9897 R600_ERR("loop/endloop in shader code are not paired.\n");
9901 /* fixup loop pointers - from r600isa
9902 LOOP END points to CF after LOOP START,
9903 LOOP START point to CF after LOOP END
9904 BRK/CONT point to LOOP END CF
9906 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
9908 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9910 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
9911 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
9913 /* XXX add LOOPRET support */
9915 callstack_pop(ctx
, FC_LOOP
);
9919 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
9923 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
9925 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
9930 R600_ERR("Break not inside loop/endloop pair\n");
9934 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9936 fc_set_mid(ctx
, fscp
- 1);
9941 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
9943 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9944 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
9947 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
9948 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
9950 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9952 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
9953 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
9954 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
9959 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
9961 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9962 struct r600_bytecode_alu alu
;
9964 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9967 for (i
= 0; i
< lasti
+ 1; i
++) {
9968 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9971 if (ctx
->bc
->chip_class
== CAYMAN
) {
9972 for (j
= 0 ; j
< 4; j
++) {
9973 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9975 alu
.op
= ALU_OP2_MULLO_UINT
;
9976 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
9977 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
9980 alu
.dst
.sel
= ctx
->temp_reg
;
9981 alu
.dst
.write
= (j
== i
);
9984 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9989 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9992 alu
.dst
.sel
= ctx
->temp_reg
;
9995 alu
.op
= ALU_OP2_MULLO_UINT
;
9996 for (j
= 0; j
< 2; j
++) {
9997 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
10001 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10008 for (i
= 0; i
< lasti
+ 1; i
++) {
10009 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10012 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10013 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10015 alu
.op
= ALU_OP2_ADD_INT
;
10017 alu
.src
[0].sel
= ctx
->temp_reg
;
10018 alu
.src
[0].chan
= i
;
10020 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
10024 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10031 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
10033 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10034 struct r600_bytecode_alu alu
;
10036 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10038 /* temp.xy = f32_to_f16(src) */
10039 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10040 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
10042 alu
.dst
.sel
= ctx
->temp_reg
;
10044 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10045 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10049 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10051 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10055 /* dst.x = temp.y * 0x10000 + temp.x */
10056 for (i
= 0; i
< lasti
+ 1; i
++) {
10057 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10060 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10061 alu
.op
= ALU_OP3_MULADD_UINT24
;
10063 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10064 alu
.last
= i
== lasti
;
10065 alu
.src
[0].sel
= ctx
->temp_reg
;
10066 alu
.src
[0].chan
= 1;
10067 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10068 alu
.src
[1].value
= 0x10000;
10069 alu
.src
[2].sel
= ctx
->temp_reg
;
10070 alu
.src
[2].chan
= 0;
10071 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10079 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
10081 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10082 struct r600_bytecode_alu alu
;
10084 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10086 /* temp.x = src.x */
10087 /* note: no need to mask out the high bits */
10088 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10089 alu
.op
= ALU_OP1_MOV
;
10091 alu
.dst
.sel
= ctx
->temp_reg
;
10093 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10094 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10098 /* temp.y = src.x >> 16 */
10099 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10100 alu
.op
= ALU_OP2_LSHR_INT
;
10102 alu
.dst
.sel
= ctx
->temp_reg
;
10104 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10105 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10106 alu
.src
[1].value
= 16;
10108 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10112 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
10113 for (i
= 0; i
< lasti
+ 1; i
++) {
10114 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10116 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10117 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10118 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
10119 alu
.src
[0].sel
= ctx
->temp_reg
;
10120 alu
.src
[0].chan
= i
% 2;
10121 alu
.last
= i
== lasti
;
10122 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10130 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
10132 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10133 struct r600_bytecode_alu alu
;
10134 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10138 if ((inst
->Src
[0].Register
.File
== inst
->Dst
[0].Register
.File
&&
10139 inst
->Src
[0].Register
.Index
== inst
->Dst
[0].Register
.Index
) ||
10140 (inst
->Src
[2].Register
.File
== inst
->Dst
[0].Register
.File
&&
10141 inst
->Src
[2].Register
.Index
== inst
->Dst
[0].Register
.Index
))
10142 dst
= r600_get_temp(ctx
);
10144 r
= tgsi_op3_dst(ctx
, dst
);
10148 for (i
= 0; i
< lasti
+ 1; i
++) {
10149 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10150 alu
.op
= ALU_OP2_SETGE_INT
;
10151 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
10152 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10153 alu
.src
[1].value
= 32;
10154 alu
.dst
.sel
= ctx
->temp_reg
;
10159 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10164 for (i
= 0; i
< lasti
+ 1; i
++) {
10165 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10166 alu
.op
= ALU_OP3_CNDE_INT
;
10168 alu
.src
[0].sel
= ctx
->temp_reg
;
10169 alu
.src
[0].chan
= i
;
10171 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10173 alu
.src
[1].sel
= dst
;
10175 alu
.src
[1].sel
= alu
.dst
.sel
;
10176 alu
.src
[1].chan
= i
;
10177 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
10181 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10189 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
10190 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
10191 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10192 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10194 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
10196 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
10197 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10198 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10199 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10200 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10201 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10202 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10203 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10204 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
10205 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10206 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10207 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10208 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10209 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10210 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10211 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10212 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
10213 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10214 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10215 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10216 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10217 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10218 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10219 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10220 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
10221 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
10222 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
10223 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10224 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10225 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10226 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10227 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10228 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
10229 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10230 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10231 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10232 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10233 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10234 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10235 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10236 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10237 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10238 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10239 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10240 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
10241 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10242 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10243 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10244 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10245 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10246 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10247 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10248 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10249 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10250 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10251 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10252 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10253 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
10254 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10255 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10256 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10257 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10258 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10259 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10260 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10261 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10262 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10263 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10264 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10265 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10266 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10267 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10268 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10269 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10270 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10271 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10272 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10273 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
10274 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10275 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10276 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
10277 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10278 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10279 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
10280 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10281 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10282 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10283 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10284 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10285 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10286 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10287 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10288 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10289 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10290 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10291 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10292 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10293 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10294 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10295 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10296 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10297 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10298 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10299 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10300 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10301 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10302 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10303 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10304 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10305 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10306 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10307 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10308 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10309 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10310 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10311 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
10312 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10313 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10314 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10315 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10316 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10317 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
10318 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10319 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
10320 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
10321 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10322 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10323 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10324 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10325 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10326 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10327 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
10328 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10329 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10330 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
10331 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10332 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
10333 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10334 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10335 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10336 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10337 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10338 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10339 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10340 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10341 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10342 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10343 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10344 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10345 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10346 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10347 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10348 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10349 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
10350 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10351 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10352 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10353 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10354 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10355 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10356 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10357 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10358 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10359 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10360 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10361 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10362 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10363 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10364 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10365 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10366 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10367 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10368 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10369 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10370 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10371 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10372 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
10373 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
10374 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
10375 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
10376 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
10377 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
10378 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10379 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
10380 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
10381 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
10382 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
10383 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
10384 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10385 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10386 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10387 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10390 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
10391 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10392 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10393 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10394 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
10395 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
10396 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10397 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10398 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10399 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10400 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10401 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10402 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10403 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10404 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10405 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10406 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10407 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10408 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10409 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
10410 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
10411 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10412 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10413 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10414 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10415 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10416 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10417 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10418 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
10419 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
10420 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
10421 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10422 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10423 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10424 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10425 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10426 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
10427 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10428 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10429 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10430 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
10431 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10432 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10433 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10434 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10435 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10436 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10437 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10438 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
10439 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10440 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10441 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10442 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10443 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10444 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10445 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
10446 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10447 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10448 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10449 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10450 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10451 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10452 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10453 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10454 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10455 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10456 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10457 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10458 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10459 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10460 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10461 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10462 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10463 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10464 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10465 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10466 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10467 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10468 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10469 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10470 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10471 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10472 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10473 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
10474 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10475 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10476 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
10477 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10478 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10479 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10480 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10481 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10482 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10483 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10484 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10485 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10486 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10487 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10488 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10489 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10490 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10491 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10492 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10493 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10494 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
10495 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10496 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10497 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10498 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10499 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10500 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10501 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10502 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10503 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10504 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10505 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10506 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10507 /* Refer below for TGSI_OPCODE_DFMA */
10508 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
10509 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10510 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10511 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10512 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10513 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10514 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
10515 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10516 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
10517 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
10518 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10519 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10520 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10521 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10522 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10523 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10524 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
10525 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10526 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10527 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
10528 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10529 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
10530 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10531 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10532 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10533 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10534 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10535 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10536 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10537 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10538 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10539 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10540 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10541 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10542 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10543 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10544 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10545 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10546 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
10547 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10548 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10549 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10550 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
10551 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
10552 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10553 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10554 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10555 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10556 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
10557 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
10558 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
10559 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
10560 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
10561 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
10562 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
10563 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
10564 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
10565 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
10566 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10567 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10568 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10569 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
10570 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
10571 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
10572 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
10573 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
10574 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
10575 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
10576 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
10577 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
10578 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
10579 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
10580 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
10581 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10582 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10583 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10584 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
10585 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
10586 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
10587 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
10588 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
10589 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
10590 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
10591 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
10592 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
10593 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
10594 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
10595 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
10596 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
10597 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
10598 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
10599 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10600 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10601 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
10602 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
10603 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
10604 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
10605 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
10606 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
10607 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
10608 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
10609 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10612 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
10613 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10614 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10615 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10616 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
10617 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
10618 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10619 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10620 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10621 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10622 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10623 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10624 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10625 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10626 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10627 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10628 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10629 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10630 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10631 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
10632 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
10633 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10634 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10635 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10636 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10637 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10638 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10639 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10640 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
10641 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
10642 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
10643 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10644 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10645 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10646 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10647 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10648 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
10649 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10650 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10651 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10652 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
10653 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10654 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10655 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10656 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10657 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10658 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10659 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10660 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
10661 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10662 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10663 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10664 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10665 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10666 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10667 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
10668 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10669 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10670 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10671 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10672 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10673 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10674 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10675 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10676 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10677 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10678 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10679 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10680 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10681 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10682 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10683 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10684 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10685 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10686 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10687 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10688 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10689 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10690 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10691 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10692 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10693 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10694 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10695 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
10696 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10697 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10698 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
10699 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10700 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10701 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10702 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10703 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10704 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10705 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10706 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10707 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10708 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10709 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10710 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10711 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10712 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10713 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10714 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10715 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10716 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
10717 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10718 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10719 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10720 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10721 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10722 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10723 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10724 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10725 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10726 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10727 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10728 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10729 /* Refer below for TGSI_OPCODE_DFMA */
10730 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
10731 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10732 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10733 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10734 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10735 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10736 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
10737 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10738 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
10739 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
10740 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10741 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10742 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10743 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10744 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10745 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10746 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
10747 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10748 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10749 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
10750 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10751 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
10752 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10753 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10754 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10755 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10756 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10757 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10758 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10759 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10760 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10761 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10762 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10763 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10764 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10765 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10766 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10767 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10768 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
10769 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10770 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10771 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10772 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
10773 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
10774 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10775 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10776 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10777 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10778 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
10779 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
10780 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
10781 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
10782 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
10783 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
10784 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
10785 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
10786 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
10787 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
10788 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10789 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10790 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10791 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
10792 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
10793 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
10794 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
10795 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
10796 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
10797 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
10798 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
10799 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
10800 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
10801 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
10802 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
10803 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10804 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10805 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10806 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
10807 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
10808 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
10809 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
10810 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
10811 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
10812 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
10813 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
10814 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
10815 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
10816 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
10817 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
10818 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
10819 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
10820 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
10821 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10822 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10823 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
10824 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
10825 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
10826 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
10827 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
10828 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
10829 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
10830 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
10831 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},