39b0a0f0ba108de13eeaca43abc07f465ea63229
1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE, INC AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 #include "pipe/p_compiler.h"
32 #include "pipe/p_shader_tokens.h"
33 #include "util/u_debug.h"
41 struct pipe_stream_output_info
;
43 /* Almost a tgsi_src_register, but we need to pull in the Absolute
44 * flag from the _ext token. Indirect flag always implies ADDR[0].
48 unsigned File
: 4; /* TGSI_FILE_ */
49 unsigned SwizzleX
: 2; /* TGSI_SWIZZLE_ */
50 unsigned SwizzleY
: 2; /* TGSI_SWIZZLE_ */
51 unsigned SwizzleZ
: 2; /* TGSI_SWIZZLE_ */
52 unsigned SwizzleW
: 2; /* TGSI_SWIZZLE_ */
53 unsigned Indirect
: 1; /* BOOL */
54 unsigned DimIndirect
: 1; /* BOOL */
55 unsigned Dimension
: 1; /* BOOL */
56 unsigned Absolute
: 1; /* BOOL */
57 unsigned Negate
: 1; /* BOOL */
58 unsigned IndirectFile
: 4; /* TGSI_FILE_ */
59 unsigned IndirectSwizzle
: 2; /* TGSI_SWIZZLE_ */
60 unsigned DimIndFile
: 4; /* TGSI_FILE_ */
61 unsigned DimIndSwizzle
: 2; /* TGSI_SWIZZLE_ */
62 int Index
: 16; /* SINT */
63 int IndirectIndex
: 16; /* SINT */
64 int DimensionIndex
: 16; /* SINT */
65 int DimIndIndex
: 16; /* SINT */
66 unsigned ArrayID
: 10; /* UINT */
69 /* Very similar to a tgsi_dst_register, removing unsupported fields
70 * and adding a Saturate flag. It's easier to push saturate into the
71 * destination register than to try and create a _SAT variant of each
72 * instruction function.
76 unsigned File
: 4; /* TGSI_FILE_ */
77 unsigned WriteMask
: 4; /* TGSI_WRITEMASK_ */
78 unsigned Indirect
: 1; /* BOOL */
79 unsigned DimIndirect
: 1; /* BOOL */
80 unsigned Dimension
: 1; /* BOOL */
81 unsigned Saturate
: 1; /* BOOL */
82 unsigned Predicate
: 1;
83 unsigned PredNegate
: 1; /* BOOL */
84 unsigned PredSwizzleX
: 2; /* TGSI_SWIZZLE_ */
85 unsigned PredSwizzleY
: 2; /* TGSI_SWIZZLE_ */
86 unsigned PredSwizzleZ
: 2; /* TGSI_SWIZZLE_ */
87 unsigned PredSwizzleW
: 2; /* TGSI_SWIZZLE_ */
88 int Index
: 16; /* SINT */
89 int IndirectIndex
: 16; /* SINT */
90 unsigned IndirectFile
: 4; /* TGSI_FILE_ */
91 int IndirectSwizzle
: 2; /* TGSI_SWIZZLE_ */
92 unsigned DimIndFile
: 4; /* TGSI_FILE_ */
93 unsigned DimIndSwizzle
: 2; /* TGSI_SWIZZLE_ */
94 int DimensionIndex
: 16; /* SINT */
95 int DimIndIndex
: 16; /* SINT */
96 unsigned ArrayID
: 10; /* UINT */
101 struct ureg_program
*
102 ureg_create(unsigned processor
);
104 struct ureg_program
*
105 ureg_create_with_screen(unsigned processor
, struct pipe_screen
*screen
);
107 const struct tgsi_token
*
108 ureg_finalize( struct ureg_program
* );
110 /* Create and return a shader:
113 ureg_create_shader( struct ureg_program
*,
114 struct pipe_context
*pipe
,
115 const struct pipe_stream_output_info
*so
);
118 /* Alternately, return the built token stream and hand ownership of
119 * that memory to the caller:
121 const struct tgsi_token
*
122 ureg_get_tokens( struct ureg_program
*ureg
,
123 unsigned *nr_tokens
);
126 * Returns the number of currently declared outputs.
129 ureg_get_nr_outputs( const struct ureg_program
*ureg
);
132 /* Free the tokens created by ureg_get_tokens() */
133 void ureg_free_tokens( const struct tgsi_token
*tokens
);
137 ureg_destroy( struct ureg_program
* );
140 /***********************************************************************
141 * Convenience routine:
144 ureg_create_shader_with_so_and_destroy( struct ureg_program
*p
,
145 struct pipe_context
*pipe
,
146 const struct pipe_stream_output_info
*so
)
148 void *result
= ureg_create_shader( p
, pipe
, so
);
154 ureg_create_shader_and_destroy( struct ureg_program
*p
,
155 struct pipe_context
*pipe
)
157 return ureg_create_shader_with_so_and_destroy(p
, pipe
, NULL
);
161 /***********************************************************************
162 * Build shader properties:
166 ureg_property(struct ureg_program
*ureg
, unsigned name
, unsigned value
);
169 /***********************************************************************
170 * Build shader declarations:
174 ureg_DECL_fs_input_cyl_centroid(struct ureg_program
*,
175 unsigned semantic_name
,
176 unsigned semantic_index
,
177 unsigned interp_mode
,
178 unsigned cylindrical_wrap
,
179 unsigned interp_location
,
181 unsigned array_size
);
183 static inline struct ureg_src
184 ureg_DECL_fs_input_cyl(struct ureg_program
*ureg
,
185 unsigned semantic_name
,
186 unsigned semantic_index
,
187 unsigned interp_mode
,
188 unsigned cylindrical_wrap
)
190 return ureg_DECL_fs_input_cyl_centroid(ureg
,
198 static inline struct ureg_src
199 ureg_DECL_fs_input(struct ureg_program
*ureg
,
200 unsigned semantic_name
,
201 unsigned semantic_index
,
202 unsigned interp_mode
)
204 return ureg_DECL_fs_input_cyl_centroid(ureg
,
212 ureg_DECL_vs_input( struct ureg_program
*,
216 ureg_DECL_input(struct ureg_program
*,
217 unsigned semantic_name
,
218 unsigned semantic_index
,
220 unsigned array_size
);
223 ureg_DECL_system_value(struct ureg_program
*,
224 unsigned semantic_name
,
225 unsigned semantic_index
);
228 ureg_DECL_output_masked(struct ureg_program
*,
229 unsigned semantic_name
,
230 unsigned semantic_index
,
233 unsigned array_size
);
236 ureg_DECL_output(struct ureg_program
*,
237 unsigned semantic_name
,
238 unsigned semantic_index
);
241 ureg_DECL_output_array(struct ureg_program
*ureg
,
242 unsigned semantic_name
,
243 unsigned semantic_index
,
245 unsigned array_size
);
248 ureg_DECL_immediate( struct ureg_program
*,
253 ureg_DECL_immediate_f64( struct ureg_program
*,
258 ureg_DECL_immediate_uint( struct ureg_program
*,
263 ureg_DECL_immediate_block_uint( struct ureg_program
*,
268 ureg_DECL_immediate_int( struct ureg_program
*,
273 ureg_DECL_constant2D(struct ureg_program
*ureg
,
279 ureg_DECL_constant( struct ureg_program
*,
283 ureg_DECL_temporary( struct ureg_program
* );
286 * Emit a temporary with the LOCAL declaration flag set. For use when
287 * the register value is not required to be preserved across
288 * subroutine boundaries.
291 ureg_DECL_local_temporary( struct ureg_program
* );
294 * Declare "size" continuous temporary registers.
297 ureg_DECL_array_temporary( struct ureg_program
*,
302 ureg_release_temporary( struct ureg_program
*ureg
,
303 struct ureg_dst tmp
);
306 ureg_DECL_address( struct ureg_program
* );
309 ureg_DECL_predicate(struct ureg_program
*);
311 /* Supply an index to the sampler declaration as this is the hook to
312 * the external pipe_sampler state. Users of this function probably
313 * don't want just any sampler, but a specific one which they've set
314 * up state for in the context.
317 ureg_DECL_sampler( struct ureg_program
*,
321 ureg_DECL_sampler_view(struct ureg_program
*,
324 unsigned return_type_x
,
325 unsigned return_type_y
,
326 unsigned return_type_z
,
327 unsigned return_type_w
);
330 ureg_DECL_image(struct ureg_program
*ureg
,
337 static inline struct ureg_src
338 ureg_imm4f( struct ureg_program
*ureg
,
347 return ureg_DECL_immediate( ureg
, v
, 4 );
350 static inline struct ureg_src
351 ureg_imm3f( struct ureg_program
*ureg
,
359 return ureg_DECL_immediate( ureg
, v
, 3 );
362 static inline struct ureg_src
363 ureg_imm2f( struct ureg_program
*ureg
,
369 return ureg_DECL_immediate( ureg
, v
, 2 );
372 static inline struct ureg_src
373 ureg_imm1f( struct ureg_program
*ureg
,
378 return ureg_DECL_immediate( ureg
, v
, 1 );
381 static inline struct ureg_src
382 ureg_imm4u( struct ureg_program
*ureg
,
383 unsigned a
, unsigned b
,
384 unsigned c
, unsigned d
)
391 return ureg_DECL_immediate_uint( ureg
, v
, 4 );
394 static inline struct ureg_src
395 ureg_imm3u( struct ureg_program
*ureg
,
396 unsigned a
, unsigned b
,
403 return ureg_DECL_immediate_uint( ureg
, v
, 3 );
406 static inline struct ureg_src
407 ureg_imm2u( struct ureg_program
*ureg
,
408 unsigned a
, unsigned b
)
413 return ureg_DECL_immediate_uint( ureg
, v
, 2 );
416 static inline struct ureg_src
417 ureg_imm1u( struct ureg_program
*ureg
,
420 return ureg_DECL_immediate_uint( ureg
, &a
, 1 );
423 static inline struct ureg_src
424 ureg_imm4i( struct ureg_program
*ureg
,
433 return ureg_DECL_immediate_int( ureg
, v
, 4 );
436 static inline struct ureg_src
437 ureg_imm3i( struct ureg_program
*ureg
,
445 return ureg_DECL_immediate_int( ureg
, v
, 3 );
448 static inline struct ureg_src
449 ureg_imm2i( struct ureg_program
*ureg
,
455 return ureg_DECL_immediate_int( ureg
, v
, 2 );
458 static inline struct ureg_src
459 ureg_imm1i( struct ureg_program
*ureg
,
462 return ureg_DECL_immediate_int( ureg
, &a
, 1 );
465 /* Where the destination register has a valid file, but an empty
468 static inline boolean
469 ureg_dst_is_empty( struct ureg_dst dst
)
471 return dst
.File
!= TGSI_FILE_NULL
&&
475 /***********************************************************************
476 * Functions for patching up labels
480 /* Will return a number which can be used in a label to point to the
481 * next instruction to be emitted.
484 ureg_get_instruction_number( struct ureg_program
*ureg
);
487 /* Patch a given label (expressed as a token number) to point to a
488 * given instruction (expressed as an instruction number).
490 * Labels are obtained from instruction emitters, eg ureg_CAL().
491 * Instruction numbers are obtained from ureg_get_instruction_number(),
495 ureg_fixup_label(struct ureg_program
*ureg
,
496 unsigned label_token
,
497 unsigned instruction_number
);
500 /* Generic instruction emitter. Use if you need to pass the opcode as
501 * a parameter, rather than using the emit_OP() variants below.
504 ureg_insn(struct ureg_program
*ureg
,
506 const struct ureg_dst
*dst
,
508 const struct ureg_src
*src
,
513 ureg_tex_insn(struct ureg_program
*ureg
,
515 const struct ureg_dst
*dst
,
518 const struct tgsi_texture_offset
*texoffsets
,
520 const struct ureg_src
*src
,
525 ureg_label_insn(struct ureg_program
*ureg
,
527 const struct ureg_src
*src
,
532 /***********************************************************************
533 * Internal instruction helpers, don't call these directly:
536 struct ureg_emit_insn_result
{
537 unsigned insn_token
; /*< Used to fixup insn size. */
538 unsigned extended_token
; /*< Used to set the Extended bit, usually the same as insn_token. */
541 struct ureg_emit_insn_result
542 ureg_emit_insn(struct ureg_program
*ureg
,
547 unsigned pred_swizzle_x
,
548 unsigned pred_swizzle_y
,
549 unsigned pred_swizzle_z
,
550 unsigned pred_swizzle_w
,
555 ureg_emit_label(struct ureg_program
*ureg
,
557 unsigned *label_token
);
560 ureg_emit_texture(struct ureg_program
*ureg
,
562 unsigned target
, unsigned num_offsets
);
565 ureg_emit_texture_offset(struct ureg_program
*ureg
,
566 const struct tgsi_texture_offset
*offset
);
569 ureg_emit_dst( struct ureg_program
*ureg
,
570 struct ureg_dst dst
);
573 ureg_emit_src( struct ureg_program
*ureg
,
574 struct ureg_src src
);
577 ureg_fixup_insn_size(struct ureg_program
*ureg
,
582 static inline void ureg_##op( struct ureg_program *ureg ) \
584 unsigned opcode = TGSI_OPCODE_##op; \
585 struct ureg_emit_insn_result insn; \
586 insn = ureg_emit_insn(ureg, \
597 ureg_fixup_insn_size( ureg, insn.insn_token ); \
601 static inline void ureg_##op( struct ureg_program *ureg, \
602 struct ureg_src src ) \
604 unsigned opcode = TGSI_OPCODE_##op; \
605 struct ureg_emit_insn_result insn; \
606 insn = ureg_emit_insn(ureg, \
617 ureg_emit_src( ureg, src ); \
618 ureg_fixup_insn_size( ureg, insn.insn_token ); \
621 #define OP00_LBL( op ) \
622 static inline void ureg_##op( struct ureg_program *ureg, \
623 unsigned *label_token ) \
625 unsigned opcode = TGSI_OPCODE_##op; \
626 struct ureg_emit_insn_result insn; \
627 insn = ureg_emit_insn(ureg, \
638 ureg_emit_label( ureg, insn.extended_token, label_token ); \
639 ureg_fixup_insn_size( ureg, insn.insn_token ); \
642 #define OP01_LBL( op ) \
643 static inline void ureg_##op( struct ureg_program *ureg, \
644 struct ureg_src src, \
645 unsigned *label_token ) \
647 unsigned opcode = TGSI_OPCODE_##op; \
648 struct ureg_emit_insn_result insn; \
649 insn = ureg_emit_insn(ureg, \
660 ureg_emit_label( ureg, insn.extended_token, label_token ); \
661 ureg_emit_src( ureg, src ); \
662 ureg_fixup_insn_size( ureg, insn.insn_token ); \
666 static inline void ureg_##op( struct ureg_program *ureg, \
667 struct ureg_dst dst ) \
669 unsigned opcode = TGSI_OPCODE_##op; \
670 struct ureg_emit_insn_result insn; \
671 if (ureg_dst_is_empty(dst)) \
673 insn = ureg_emit_insn(ureg, \
684 ureg_emit_dst( ureg, dst ); \
685 ureg_fixup_insn_size( ureg, insn.insn_token ); \
690 static inline void ureg_##op( struct ureg_program *ureg, \
691 struct ureg_dst dst, \
692 struct ureg_src src ) \
694 unsigned opcode = TGSI_OPCODE_##op; \
695 struct ureg_emit_insn_result insn; \
696 if (ureg_dst_is_empty(dst)) \
698 insn = ureg_emit_insn(ureg, \
709 ureg_emit_dst( ureg, dst ); \
710 ureg_emit_src( ureg, src ); \
711 ureg_fixup_insn_size( ureg, insn.insn_token ); \
715 static inline void ureg_##op( struct ureg_program *ureg, \
716 struct ureg_dst dst, \
717 struct ureg_src src0, \
718 struct ureg_src src1 ) \
720 unsigned opcode = TGSI_OPCODE_##op; \
721 struct ureg_emit_insn_result insn; \
722 if (ureg_dst_is_empty(dst)) \
724 insn = ureg_emit_insn(ureg, \
735 ureg_emit_dst( ureg, dst ); \
736 ureg_emit_src( ureg, src0 ); \
737 ureg_emit_src( ureg, src1 ); \
738 ureg_fixup_insn_size( ureg, insn.insn_token ); \
741 #define OP12_TEX( op ) \
742 static inline void ureg_##op( struct ureg_program *ureg, \
743 struct ureg_dst dst, \
745 struct ureg_src src0, \
746 struct ureg_src src1 ) \
748 unsigned opcode = TGSI_OPCODE_##op; \
749 struct ureg_emit_insn_result insn; \
750 if (ureg_dst_is_empty(dst)) \
752 insn = ureg_emit_insn(ureg, \
763 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
764 ureg_emit_dst( ureg, dst ); \
765 ureg_emit_src( ureg, src0 ); \
766 ureg_emit_src( ureg, src1 ); \
767 ureg_fixup_insn_size( ureg, insn.insn_token ); \
770 #define OP12_SAMPLE( op ) \
771 static inline void ureg_##op( struct ureg_program *ureg, \
772 struct ureg_dst dst, \
773 struct ureg_src src0, \
774 struct ureg_src src1 ) \
776 unsigned opcode = TGSI_OPCODE_##op; \
777 unsigned target = TGSI_TEXTURE_UNKNOWN; \
778 struct ureg_emit_insn_result insn; \
779 if (ureg_dst_is_empty(dst)) \
781 insn = ureg_emit_insn(ureg, \
792 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
793 ureg_emit_dst( ureg, dst ); \
794 ureg_emit_src( ureg, src0 ); \
795 ureg_emit_src( ureg, src1 ); \
796 ureg_fixup_insn_size( ureg, insn.insn_token ); \
800 static inline void ureg_##op( struct ureg_program *ureg, \
801 struct ureg_dst dst, \
802 struct ureg_src src0, \
803 struct ureg_src src1, \
804 struct ureg_src src2 ) \
806 unsigned opcode = TGSI_OPCODE_##op; \
807 struct ureg_emit_insn_result insn; \
808 if (ureg_dst_is_empty(dst)) \
810 insn = ureg_emit_insn(ureg, \
821 ureg_emit_dst( ureg, dst ); \
822 ureg_emit_src( ureg, src0 ); \
823 ureg_emit_src( ureg, src1 ); \
824 ureg_emit_src( ureg, src2 ); \
825 ureg_fixup_insn_size( ureg, insn.insn_token ); \
828 #define OP13_SAMPLE( op ) \
829 static inline void ureg_##op( struct ureg_program *ureg, \
830 struct ureg_dst dst, \
831 struct ureg_src src0, \
832 struct ureg_src src1, \
833 struct ureg_src src2 ) \
835 unsigned opcode = TGSI_OPCODE_##op; \
836 unsigned target = TGSI_TEXTURE_UNKNOWN; \
837 struct ureg_emit_insn_result insn; \
838 if (ureg_dst_is_empty(dst)) \
840 insn = ureg_emit_insn(ureg, \
851 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
852 ureg_emit_dst( ureg, dst ); \
853 ureg_emit_src( ureg, src0 ); \
854 ureg_emit_src( ureg, src1 ); \
855 ureg_emit_src( ureg, src2 ); \
856 ureg_fixup_insn_size( ureg, insn.insn_token ); \
859 #define OP14_TEX( op ) \
860 static inline void ureg_##op( struct ureg_program *ureg, \
861 struct ureg_dst dst, \
863 struct ureg_src src0, \
864 struct ureg_src src1, \
865 struct ureg_src src2, \
866 struct ureg_src src3 ) \
868 unsigned opcode = TGSI_OPCODE_##op; \
869 struct ureg_emit_insn_result insn; \
870 if (ureg_dst_is_empty(dst)) \
872 insn = ureg_emit_insn(ureg, \
883 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
884 ureg_emit_dst( ureg, dst ); \
885 ureg_emit_src( ureg, src0 ); \
886 ureg_emit_src( ureg, src1 ); \
887 ureg_emit_src( ureg, src2 ); \
888 ureg_emit_src( ureg, src3 ); \
889 ureg_fixup_insn_size( ureg, insn.insn_token ); \
892 #define OP14_SAMPLE( op ) \
893 static inline void ureg_##op( struct ureg_program *ureg, \
894 struct ureg_dst dst, \
895 struct ureg_src src0, \
896 struct ureg_src src1, \
897 struct ureg_src src2, \
898 struct ureg_src src3 ) \
900 unsigned opcode = TGSI_OPCODE_##op; \
901 unsigned target = TGSI_TEXTURE_UNKNOWN; \
902 struct ureg_emit_insn_result insn; \
903 if (ureg_dst_is_empty(dst)) \
905 insn = ureg_emit_insn(ureg, \
916 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
917 ureg_emit_dst( ureg, dst ); \
918 ureg_emit_src( ureg, src0 ); \
919 ureg_emit_src( ureg, src1 ); \
920 ureg_emit_src( ureg, src2 ); \
921 ureg_emit_src( ureg, src3 ); \
922 ureg_fixup_insn_size( ureg, insn.insn_token ); \
927 static inline void ureg_##op( struct ureg_program *ureg, \
928 struct ureg_dst dst, \
929 struct ureg_src src0, \
930 struct ureg_src src1, \
931 struct ureg_src src2, \
932 struct ureg_src src3 ) \
934 unsigned opcode = TGSI_OPCODE_##op; \
935 struct ureg_emit_insn_result insn; \
936 if (ureg_dst_is_empty(dst)) \
938 insn = ureg_emit_insn(ureg, \
949 ureg_emit_dst( ureg, dst ); \
950 ureg_emit_src( ureg, src0 ); \
951 ureg_emit_src( ureg, src1 ); \
952 ureg_emit_src( ureg, src2 ); \
953 ureg_emit_src( ureg, src3 ); \
954 ureg_fixup_insn_size( ureg, insn.insn_token ); \
959 static inline void ureg_##op( struct ureg_program *ureg, \
960 struct ureg_dst dst, \
961 struct ureg_src src0, \
962 struct ureg_src src1, \
963 struct ureg_src src2, \
964 struct ureg_src src3, \
965 struct ureg_src src4 ) \
967 unsigned opcode = TGSI_OPCODE_##op; \
968 struct ureg_emit_insn_result insn; \
969 if (ureg_dst_is_empty(dst)) \
971 insn = ureg_emit_insn(ureg, \
982 ureg_emit_dst( ureg, dst ); \
983 ureg_emit_src( ureg, src0 ); \
984 ureg_emit_src( ureg, src1 ); \
985 ureg_emit_src( ureg, src2 ); \
986 ureg_emit_src( ureg, src3 ); \
987 ureg_emit_src( ureg, src4 ); \
988 ureg_fixup_insn_size( ureg, insn.insn_token ); \
991 #define OP15_SAMPLE( op ) \
992 static inline void ureg_##op( struct ureg_program *ureg, \
993 struct ureg_dst dst, \
994 struct ureg_src src0, \
995 struct ureg_src src1, \
996 struct ureg_src src2, \
997 struct ureg_src src3, \
998 struct ureg_src src4 ) \
1000 unsigned opcode = TGSI_OPCODE_##op; \
1001 unsigned target = TGSI_TEXTURE_UNKNOWN; \
1002 struct ureg_emit_insn_result insn; \
1003 if (ureg_dst_is_empty(dst)) \
1005 insn = ureg_emit_insn(ureg, \
1016 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
1017 ureg_emit_dst( ureg, dst ); \
1018 ureg_emit_src( ureg, src0 ); \
1019 ureg_emit_src( ureg, src1 ); \
1020 ureg_emit_src( ureg, src2 ); \
1021 ureg_emit_src( ureg, src3 ); \
1022 ureg_emit_src( ureg, src4 ); \
1023 ureg_fixup_insn_size( ureg, insn.insn_token ); \
1026 /* Use a template include to generate a correctly-typed ureg_OP()
1027 * function for each TGSI opcode:
1029 #include "tgsi_opcode_tmp.h"
1032 /***********************************************************************
1033 * Inline helpers for manipulating register structs:
1035 static inline struct ureg_src
1036 ureg_negate( struct ureg_src reg
)
1038 assert(reg
.File
!= TGSI_FILE_NULL
);
1043 static inline struct ureg_src
1044 ureg_abs( struct ureg_src reg
)
1046 assert(reg
.File
!= TGSI_FILE_NULL
);
1052 static inline struct ureg_src
1053 ureg_swizzle( struct ureg_src reg
,
1054 int x
, int y
, int z
, int w
)
1056 unsigned swz
= ( (reg
.SwizzleX
<< 0) |
1057 (reg
.SwizzleY
<< 2) |
1058 (reg
.SwizzleZ
<< 4) |
1059 (reg
.SwizzleW
<< 6));
1061 assert(reg
.File
!= TGSI_FILE_NULL
);
1067 reg
.SwizzleX
= (swz
>> (x
*2)) & 0x3;
1068 reg
.SwizzleY
= (swz
>> (y
*2)) & 0x3;
1069 reg
.SwizzleZ
= (swz
>> (z
*2)) & 0x3;
1070 reg
.SwizzleW
= (swz
>> (w
*2)) & 0x3;
1074 static inline struct ureg_src
1075 ureg_scalar( struct ureg_src reg
, int x
)
1077 return ureg_swizzle(reg
, x
, x
, x
, x
);
1080 static inline struct ureg_dst
1081 ureg_writemask( struct ureg_dst reg
,
1082 unsigned writemask
)
1084 assert(reg
.File
!= TGSI_FILE_NULL
);
1085 reg
.WriteMask
&= writemask
;
1089 static inline struct ureg_dst
1090 ureg_saturate( struct ureg_dst reg
)
1092 assert(reg
.File
!= TGSI_FILE_NULL
);
1097 static inline struct ureg_dst
1098 ureg_predicate(struct ureg_dst reg
,
1105 assert(reg
.File
!= TGSI_FILE_NULL
);
1107 reg
.PredNegate
= negate
;
1108 reg
.PredSwizzleX
= swizzle_x
;
1109 reg
.PredSwizzleY
= swizzle_y
;
1110 reg
.PredSwizzleZ
= swizzle_z
;
1111 reg
.PredSwizzleW
= swizzle_w
;
1115 static inline struct ureg_dst
1116 ureg_dst_indirect( struct ureg_dst reg
, struct ureg_src addr
)
1118 assert(reg
.File
!= TGSI_FILE_NULL
);
1119 assert(addr
.File
== TGSI_FILE_ADDRESS
|| addr
.File
== TGSI_FILE_TEMPORARY
);
1121 reg
.IndirectFile
= addr
.File
;
1122 reg
.IndirectIndex
= addr
.Index
;
1123 reg
.IndirectSwizzle
= addr
.SwizzleX
;
1127 static inline struct ureg_src
1128 ureg_src_indirect( struct ureg_src reg
, struct ureg_src addr
)
1130 assert(reg
.File
!= TGSI_FILE_NULL
);
1131 assert(addr
.File
== TGSI_FILE_ADDRESS
|| addr
.File
== TGSI_FILE_TEMPORARY
);
1133 reg
.IndirectFile
= addr
.File
;
1134 reg
.IndirectIndex
= addr
.Index
;
1135 reg
.IndirectSwizzle
= addr
.SwizzleX
;
1139 static inline struct ureg_dst
1140 ureg_dst_dimension( struct ureg_dst reg
, int index
)
1142 assert(reg
.File
!= TGSI_FILE_NULL
);
1144 reg
.DimIndirect
= 0;
1145 reg
.DimensionIndex
= index
;
1149 static inline struct ureg_src
1150 ureg_src_dimension( struct ureg_src reg
, int index
)
1152 assert(reg
.File
!= TGSI_FILE_NULL
);
1154 reg
.DimIndirect
= 0;
1155 reg
.DimensionIndex
= index
;
1159 static inline struct ureg_dst
1160 ureg_dst_dimension_indirect( struct ureg_dst reg
, struct ureg_src addr
,
1163 assert(reg
.File
!= TGSI_FILE_NULL
);
1165 reg
.DimIndirect
= 1;
1166 reg
.DimensionIndex
= index
;
1167 reg
.DimIndFile
= addr
.File
;
1168 reg
.DimIndIndex
= addr
.Index
;
1169 reg
.DimIndSwizzle
= addr
.SwizzleX
;
1173 static inline struct ureg_src
1174 ureg_src_dimension_indirect( struct ureg_src reg
, struct ureg_src addr
,
1177 assert(reg
.File
!= TGSI_FILE_NULL
);
1179 reg
.DimIndirect
= 1;
1180 reg
.DimensionIndex
= index
;
1181 reg
.DimIndFile
= addr
.File
;
1182 reg
.DimIndIndex
= addr
.Index
;
1183 reg
.DimIndSwizzle
= addr
.SwizzleX
;
1187 static inline struct ureg_src
1188 ureg_src_array_offset(struct ureg_src reg
, int offset
)
1190 reg
.Index
+= offset
;
1194 static inline struct ureg_dst
1195 ureg_dst_array_offset( struct ureg_dst reg
, int offset
)
1197 reg
.Index
+= offset
;
1201 static inline struct ureg_dst
1202 ureg_dst_array_register(unsigned file
,
1206 struct ureg_dst dst
;
1209 dst
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1211 dst
.IndirectFile
= TGSI_FILE_NULL
;
1212 dst
.IndirectIndex
= 0;
1213 dst
.IndirectSwizzle
= 0;
1217 dst
.PredSwizzleX
= TGSI_SWIZZLE_X
;
1218 dst
.PredSwizzleY
= TGSI_SWIZZLE_Y
;
1219 dst
.PredSwizzleZ
= TGSI_SWIZZLE_Z
;
1220 dst
.PredSwizzleW
= TGSI_SWIZZLE_W
;
1223 dst
.DimensionIndex
= 0;
1224 dst
.DimIndirect
= 0;
1225 dst
.DimIndFile
= TGSI_FILE_NULL
;
1226 dst
.DimIndIndex
= 0;
1227 dst
.DimIndSwizzle
= 0;
1228 dst
.ArrayID
= array_id
;
1233 static inline struct ureg_dst
1234 ureg_dst_register(unsigned file
,
1237 return ureg_dst_array_register(file
, index
, 0);
1240 static inline struct ureg_dst
1241 ureg_dst( struct ureg_src src
)
1243 struct ureg_dst dst
;
1245 assert(!src
.Indirect
||
1246 (src
.IndirectFile
== TGSI_FILE_ADDRESS
||
1247 src
.IndirectFile
== TGSI_FILE_TEMPORARY
));
1249 dst
.File
= src
.File
;
1250 dst
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1251 dst
.IndirectFile
= src
.IndirectFile
;
1252 dst
.Indirect
= src
.Indirect
;
1253 dst
.IndirectIndex
= src
.IndirectIndex
;
1254 dst
.IndirectSwizzle
= src
.IndirectSwizzle
;
1258 dst
.PredSwizzleX
= TGSI_SWIZZLE_X
;
1259 dst
.PredSwizzleY
= TGSI_SWIZZLE_Y
;
1260 dst
.PredSwizzleZ
= TGSI_SWIZZLE_Z
;
1261 dst
.PredSwizzleW
= TGSI_SWIZZLE_W
;
1262 dst
.Index
= src
.Index
;
1263 dst
.Dimension
= src
.Dimension
;
1264 dst
.DimensionIndex
= src
.DimensionIndex
;
1265 dst
.DimIndirect
= src
.DimIndirect
;
1266 dst
.DimIndFile
= src
.DimIndFile
;
1267 dst
.DimIndIndex
= src
.DimIndIndex
;
1268 dst
.DimIndSwizzle
= src
.DimIndSwizzle
;
1269 dst
.ArrayID
= src
.ArrayID
;
1274 static inline struct ureg_src
1275 ureg_src_array_register(unsigned file
,
1279 struct ureg_src src
;
1282 src
.SwizzleX
= TGSI_SWIZZLE_X
;
1283 src
.SwizzleY
= TGSI_SWIZZLE_Y
;
1284 src
.SwizzleZ
= TGSI_SWIZZLE_Z
;
1285 src
.SwizzleW
= TGSI_SWIZZLE_W
;
1287 src
.IndirectFile
= TGSI_FILE_NULL
;
1288 src
.IndirectIndex
= 0;
1289 src
.IndirectSwizzle
= 0;
1294 src
.DimensionIndex
= 0;
1295 src
.DimIndirect
= 0;
1296 src
.DimIndFile
= TGSI_FILE_NULL
;
1297 src
.DimIndIndex
= 0;
1298 src
.DimIndSwizzle
= 0;
1299 src
.ArrayID
= array_id
;
1304 static inline struct ureg_src
1305 ureg_src_register(unsigned file
,
1308 return ureg_src_array_register(file
, index
, 0);
1311 static inline struct ureg_src
1312 ureg_src( struct ureg_dst dst
)
1314 struct ureg_src src
;
1316 src
.File
= dst
.File
;
1317 src
.SwizzleX
= TGSI_SWIZZLE_X
;
1318 src
.SwizzleY
= TGSI_SWIZZLE_Y
;
1319 src
.SwizzleZ
= TGSI_SWIZZLE_Z
;
1320 src
.SwizzleW
= TGSI_SWIZZLE_W
;
1321 src
.Indirect
= dst
.Indirect
;
1322 src
.IndirectFile
= dst
.IndirectFile
;
1323 src
.IndirectIndex
= dst
.IndirectIndex
;
1324 src
.IndirectSwizzle
= dst
.IndirectSwizzle
;
1326 src
.Index
= dst
.Index
;
1328 src
.Dimension
= dst
.Dimension
;
1329 src
.DimensionIndex
= dst
.DimensionIndex
;
1330 src
.DimIndirect
= dst
.DimIndirect
;
1331 src
.DimIndFile
= dst
.DimIndFile
;
1332 src
.DimIndIndex
= dst
.DimIndIndex
;
1333 src
.DimIndSwizzle
= dst
.DimIndSwizzle
;
1334 src
.ArrayID
= dst
.ArrayID
;
1341 static inline struct ureg_dst
1342 ureg_dst_undef( void )
1344 struct ureg_dst dst
;
1346 dst
.File
= TGSI_FILE_NULL
;
1349 dst
.IndirectFile
= TGSI_FILE_NULL
;
1350 dst
.IndirectIndex
= 0;
1351 dst
.IndirectSwizzle
= 0;
1355 dst
.PredSwizzleX
= TGSI_SWIZZLE_X
;
1356 dst
.PredSwizzleY
= TGSI_SWIZZLE_Y
;
1357 dst
.PredSwizzleZ
= TGSI_SWIZZLE_Z
;
1358 dst
.PredSwizzleW
= TGSI_SWIZZLE_W
;
1361 dst
.DimensionIndex
= 0;
1362 dst
.DimIndirect
= 0;
1363 dst
.DimIndFile
= TGSI_FILE_NULL
;
1364 dst
.DimIndIndex
= 0;
1365 dst
.DimIndSwizzle
= 0;
1371 static inline struct ureg_src
1372 ureg_src_undef( void )
1374 struct ureg_src src
;
1376 src
.File
= TGSI_FILE_NULL
;
1382 src
.IndirectFile
= TGSI_FILE_NULL
;
1383 src
.IndirectIndex
= 0;
1384 src
.IndirectSwizzle
= 0;
1389 src
.DimensionIndex
= 0;
1390 src
.DimIndirect
= 0;
1391 src
.DimIndFile
= TGSI_FILE_NULL
;
1392 src
.DimIndIndex
= 0;
1393 src
.DimIndSwizzle
= 0;
1399 static inline boolean
1400 ureg_src_is_undef( struct ureg_src src
)
1402 return src
.File
== TGSI_FILE_NULL
;
1405 static inline boolean
1406 ureg_dst_is_undef( struct ureg_dst dst
)
1408 return dst
.File
== TGSI_FILE_NULL
;