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 ureg_set_next_shader_processor(struct ureg_program
*ureg
, unsigned processor
);
120 /* Alternately, return the built token stream and hand ownership of
121 * that memory to the caller:
123 const struct tgsi_token
*
124 ureg_get_tokens( struct ureg_program
*ureg
,
125 unsigned *nr_tokens
);
128 * Returns the number of currently declared outputs.
131 ureg_get_nr_outputs( const struct ureg_program
*ureg
);
134 /* Free the tokens created by ureg_get_tokens() */
135 void ureg_free_tokens( const struct tgsi_token
*tokens
);
139 ureg_destroy( struct ureg_program
* );
142 /***********************************************************************
143 * Convenience routine:
146 ureg_create_shader_with_so_and_destroy( struct ureg_program
*p
,
147 struct pipe_context
*pipe
,
148 const struct pipe_stream_output_info
*so
)
150 void *result
= ureg_create_shader( p
, pipe
, so
);
156 ureg_create_shader_and_destroy( struct ureg_program
*p
,
157 struct pipe_context
*pipe
)
159 return ureg_create_shader_with_so_and_destroy(p
, pipe
, NULL
);
163 /***********************************************************************
164 * Build shader properties:
168 ureg_property(struct ureg_program
*ureg
, unsigned name
, unsigned value
);
171 /***********************************************************************
172 * Build shader declarations:
176 ureg_DECL_fs_input_cyl_centroid(struct ureg_program
*,
177 unsigned semantic_name
,
178 unsigned semantic_index
,
179 unsigned interp_mode
,
180 unsigned cylindrical_wrap
,
181 unsigned interp_location
,
183 unsigned array_size
);
185 static inline struct ureg_src
186 ureg_DECL_fs_input_cyl(struct ureg_program
*ureg
,
187 unsigned semantic_name
,
188 unsigned semantic_index
,
189 unsigned interp_mode
,
190 unsigned cylindrical_wrap
)
192 return ureg_DECL_fs_input_cyl_centroid(ureg
,
200 static inline struct ureg_src
201 ureg_DECL_fs_input(struct ureg_program
*ureg
,
202 unsigned semantic_name
,
203 unsigned semantic_index
,
204 unsigned interp_mode
)
206 return ureg_DECL_fs_input_cyl_centroid(ureg
,
214 ureg_DECL_vs_input( struct ureg_program
*,
218 ureg_DECL_input(struct ureg_program
*,
219 unsigned semantic_name
,
220 unsigned semantic_index
,
222 unsigned array_size
);
225 ureg_DECL_system_value(struct ureg_program
*,
226 unsigned semantic_name
,
227 unsigned semantic_index
);
230 ureg_DECL_output_masked(struct ureg_program
*,
231 unsigned semantic_name
,
232 unsigned semantic_index
,
235 unsigned array_size
);
238 ureg_DECL_output(struct ureg_program
*,
239 unsigned semantic_name
,
240 unsigned semantic_index
);
243 ureg_DECL_output_array(struct ureg_program
*ureg
,
244 unsigned semantic_name
,
245 unsigned semantic_index
,
247 unsigned array_size
);
250 ureg_DECL_immediate( struct ureg_program
*,
255 ureg_DECL_immediate_f64( struct ureg_program
*,
260 ureg_DECL_immediate_uint( struct ureg_program
*,
265 ureg_DECL_immediate_block_uint( struct ureg_program
*,
270 ureg_DECL_immediate_int( struct ureg_program
*,
275 ureg_DECL_constant2D(struct ureg_program
*ureg
,
281 ureg_DECL_constant( struct ureg_program
*,
285 ureg_DECL_temporary( struct ureg_program
* );
288 * Emit a temporary with the LOCAL declaration flag set. For use when
289 * the register value is not required to be preserved across
290 * subroutine boundaries.
293 ureg_DECL_local_temporary( struct ureg_program
* );
296 * Declare "size" continuous temporary registers.
299 ureg_DECL_array_temporary( struct ureg_program
*,
304 ureg_release_temporary( struct ureg_program
*ureg
,
305 struct ureg_dst tmp
);
308 ureg_DECL_address( struct ureg_program
* );
311 ureg_DECL_predicate(struct ureg_program
*);
313 /* Supply an index to the sampler declaration as this is the hook to
314 * the external pipe_sampler state. Users of this function probably
315 * don't want just any sampler, but a specific one which they've set
316 * up state for in the context.
319 ureg_DECL_sampler( struct ureg_program
*,
323 ureg_DECL_sampler_view(struct ureg_program
*,
326 unsigned return_type_x
,
327 unsigned return_type_y
,
328 unsigned return_type_z
,
329 unsigned return_type_w
);
332 ureg_DECL_image(struct ureg_program
*ureg
,
340 ureg_DECL_buffer(struct ureg_program
*ureg
, unsigned nr
, bool atomic
);
343 ureg_DECL_memory(struct ureg_program
*ureg
, unsigned memory_type
);
345 static inline struct ureg_src
346 ureg_imm4f( struct ureg_program
*ureg
,
355 return ureg_DECL_immediate( ureg
, v
, 4 );
358 static inline struct ureg_src
359 ureg_imm3f( struct ureg_program
*ureg
,
367 return ureg_DECL_immediate( ureg
, v
, 3 );
370 static inline struct ureg_src
371 ureg_imm2f( struct ureg_program
*ureg
,
377 return ureg_DECL_immediate( ureg
, v
, 2 );
380 static inline struct ureg_src
381 ureg_imm1f( struct ureg_program
*ureg
,
386 return ureg_DECL_immediate( ureg
, v
, 1 );
389 static inline struct ureg_src
390 ureg_imm4u( struct ureg_program
*ureg
,
391 unsigned a
, unsigned b
,
392 unsigned c
, unsigned d
)
399 return ureg_DECL_immediate_uint( ureg
, v
, 4 );
402 static inline struct ureg_src
403 ureg_imm3u( struct ureg_program
*ureg
,
404 unsigned a
, unsigned b
,
411 return ureg_DECL_immediate_uint( ureg
, v
, 3 );
414 static inline struct ureg_src
415 ureg_imm2u( struct ureg_program
*ureg
,
416 unsigned a
, unsigned b
)
421 return ureg_DECL_immediate_uint( ureg
, v
, 2 );
424 static inline struct ureg_src
425 ureg_imm1u( struct ureg_program
*ureg
,
428 return ureg_DECL_immediate_uint( ureg
, &a
, 1 );
431 static inline struct ureg_src
432 ureg_imm4i( struct ureg_program
*ureg
,
441 return ureg_DECL_immediate_int( ureg
, v
, 4 );
444 static inline struct ureg_src
445 ureg_imm3i( struct ureg_program
*ureg
,
453 return ureg_DECL_immediate_int( ureg
, v
, 3 );
456 static inline struct ureg_src
457 ureg_imm2i( struct ureg_program
*ureg
,
463 return ureg_DECL_immediate_int( ureg
, v
, 2 );
466 static inline struct ureg_src
467 ureg_imm1i( struct ureg_program
*ureg
,
470 return ureg_DECL_immediate_int( ureg
, &a
, 1 );
473 /* Where the destination register has a valid file, but an empty
476 static inline boolean
477 ureg_dst_is_empty( struct ureg_dst dst
)
479 return dst
.File
!= TGSI_FILE_NULL
&&
483 /***********************************************************************
484 * Functions for patching up labels
488 /* Will return a number which can be used in a label to point to the
489 * next instruction to be emitted.
492 ureg_get_instruction_number( struct ureg_program
*ureg
);
495 /* Patch a given label (expressed as a token number) to point to a
496 * given instruction (expressed as an instruction number).
498 * Labels are obtained from instruction emitters, eg ureg_CAL().
499 * Instruction numbers are obtained from ureg_get_instruction_number(),
503 ureg_fixup_label(struct ureg_program
*ureg
,
504 unsigned label_token
,
505 unsigned instruction_number
);
508 /* Generic instruction emitter. Use if you need to pass the opcode as
509 * a parameter, rather than using the emit_OP() variants below.
512 ureg_insn(struct ureg_program
*ureg
,
514 const struct ureg_dst
*dst
,
516 const struct ureg_src
*src
,
521 ureg_tex_insn(struct ureg_program
*ureg
,
523 const struct ureg_dst
*dst
,
526 const struct tgsi_texture_offset
*texoffsets
,
528 const struct ureg_src
*src
,
533 ureg_label_insn(struct ureg_program
*ureg
,
535 const struct ureg_src
*src
,
540 ureg_memory_insn(struct ureg_program
*ureg
,
542 const struct ureg_dst
*dst
,
544 const struct ureg_src
*src
,
550 /***********************************************************************
551 * Internal instruction helpers, don't call these directly:
554 struct ureg_emit_insn_result
{
555 unsigned insn_token
; /*< Used to fixup insn size. */
556 unsigned extended_token
; /*< Used to set the Extended bit, usually the same as insn_token. */
559 struct ureg_emit_insn_result
560 ureg_emit_insn(struct ureg_program
*ureg
,
565 unsigned pred_swizzle_x
,
566 unsigned pred_swizzle_y
,
567 unsigned pred_swizzle_z
,
568 unsigned pred_swizzle_w
,
573 ureg_emit_label(struct ureg_program
*ureg
,
575 unsigned *label_token
);
578 ureg_emit_texture(struct ureg_program
*ureg
,
580 unsigned target
, unsigned num_offsets
);
583 ureg_emit_texture_offset(struct ureg_program
*ureg
,
584 const struct tgsi_texture_offset
*offset
);
587 ureg_emit_memory(struct ureg_program
*ureg
,
594 ureg_emit_dst( struct ureg_program
*ureg
,
595 struct ureg_dst dst
);
598 ureg_emit_src( struct ureg_program
*ureg
,
599 struct ureg_src src
);
602 ureg_fixup_insn_size(struct ureg_program
*ureg
,
607 static inline void ureg_##op( struct ureg_program *ureg ) \
609 unsigned opcode = TGSI_OPCODE_##op; \
610 struct ureg_emit_insn_result insn; \
611 insn = ureg_emit_insn(ureg, \
622 ureg_fixup_insn_size( ureg, insn.insn_token ); \
626 static inline void ureg_##op( struct ureg_program *ureg, \
627 struct ureg_src src ) \
629 unsigned opcode = TGSI_OPCODE_##op; \
630 struct ureg_emit_insn_result insn; \
631 insn = ureg_emit_insn(ureg, \
642 ureg_emit_src( ureg, src ); \
643 ureg_fixup_insn_size( ureg, insn.insn_token ); \
646 #define OP00_LBL( op ) \
647 static inline void ureg_##op( struct ureg_program *ureg, \
648 unsigned *label_token ) \
650 unsigned opcode = TGSI_OPCODE_##op; \
651 struct ureg_emit_insn_result insn; \
652 insn = ureg_emit_insn(ureg, \
663 ureg_emit_label( ureg, insn.extended_token, label_token ); \
664 ureg_fixup_insn_size( ureg, insn.insn_token ); \
667 #define OP01_LBL( op ) \
668 static inline void ureg_##op( struct ureg_program *ureg, \
669 struct ureg_src src, \
670 unsigned *label_token ) \
672 unsigned opcode = TGSI_OPCODE_##op; \
673 struct ureg_emit_insn_result insn; \
674 insn = ureg_emit_insn(ureg, \
685 ureg_emit_label( ureg, insn.extended_token, label_token ); \
686 ureg_emit_src( ureg, src ); \
687 ureg_fixup_insn_size( ureg, insn.insn_token ); \
691 static inline void ureg_##op( struct ureg_program *ureg, \
692 struct ureg_dst dst ) \
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_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 src ) \
719 unsigned opcode = TGSI_OPCODE_##op; \
720 struct ureg_emit_insn_result insn; \
721 if (ureg_dst_is_empty(dst)) \
723 insn = ureg_emit_insn(ureg, \
734 ureg_emit_dst( ureg, dst ); \
735 ureg_emit_src( ureg, src ); \
736 ureg_fixup_insn_size( ureg, insn.insn_token ); \
740 static inline void ureg_##op( struct ureg_program *ureg, \
741 struct ureg_dst dst, \
742 struct ureg_src src0, \
743 struct ureg_src src1 ) \
745 unsigned opcode = TGSI_OPCODE_##op; \
746 struct ureg_emit_insn_result insn; \
747 if (ureg_dst_is_empty(dst)) \
749 insn = ureg_emit_insn(ureg, \
760 ureg_emit_dst( ureg, dst ); \
761 ureg_emit_src( ureg, src0 ); \
762 ureg_emit_src( ureg, src1 ); \
763 ureg_fixup_insn_size( ureg, insn.insn_token ); \
766 #define OP12_TEX( op ) \
767 static inline void ureg_##op( struct ureg_program *ureg, \
768 struct ureg_dst dst, \
770 struct ureg_src src0, \
771 struct ureg_src src1 ) \
773 unsigned opcode = TGSI_OPCODE_##op; \
774 struct ureg_emit_insn_result insn; \
775 if (ureg_dst_is_empty(dst)) \
777 insn = ureg_emit_insn(ureg, \
788 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
789 ureg_emit_dst( ureg, dst ); \
790 ureg_emit_src( ureg, src0 ); \
791 ureg_emit_src( ureg, src1 ); \
792 ureg_fixup_insn_size( ureg, insn.insn_token ); \
795 #define OP12_SAMPLE( op ) \
796 static inline void ureg_##op( struct ureg_program *ureg, \
797 struct ureg_dst dst, \
798 struct ureg_src src0, \
799 struct ureg_src src1 ) \
801 unsigned opcode = TGSI_OPCODE_##op; \
802 unsigned target = TGSI_TEXTURE_UNKNOWN; \
803 struct ureg_emit_insn_result insn; \
804 if (ureg_dst_is_empty(dst)) \
806 insn = ureg_emit_insn(ureg, \
817 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
818 ureg_emit_dst( ureg, dst ); \
819 ureg_emit_src( ureg, src0 ); \
820 ureg_emit_src( ureg, src1 ); \
821 ureg_fixup_insn_size( ureg, insn.insn_token ); \
825 static inline void ureg_##op( struct ureg_program *ureg, \
826 struct ureg_dst dst, \
827 struct ureg_src src0, \
828 struct ureg_src src1, \
829 struct ureg_src src2 ) \
831 unsigned opcode = TGSI_OPCODE_##op; \
832 struct ureg_emit_insn_result insn; \
833 if (ureg_dst_is_empty(dst)) \
835 insn = ureg_emit_insn(ureg, \
846 ureg_emit_dst( ureg, dst ); \
847 ureg_emit_src( ureg, src0 ); \
848 ureg_emit_src( ureg, src1 ); \
849 ureg_emit_src( ureg, src2 ); \
850 ureg_fixup_insn_size( ureg, insn.insn_token ); \
853 #define OP13_SAMPLE( op ) \
854 static inline void ureg_##op( struct ureg_program *ureg, \
855 struct ureg_dst dst, \
856 struct ureg_src src0, \
857 struct ureg_src src1, \
858 struct ureg_src src2 ) \
860 unsigned opcode = TGSI_OPCODE_##op; \
861 unsigned target = TGSI_TEXTURE_UNKNOWN; \
862 struct ureg_emit_insn_result insn; \
863 if (ureg_dst_is_empty(dst)) \
865 insn = ureg_emit_insn(ureg, \
876 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
877 ureg_emit_dst( ureg, dst ); \
878 ureg_emit_src( ureg, src0 ); \
879 ureg_emit_src( ureg, src1 ); \
880 ureg_emit_src( ureg, src2 ); \
881 ureg_fixup_insn_size( ureg, insn.insn_token ); \
884 #define OP14_TEX( op ) \
885 static inline void ureg_##op( struct ureg_program *ureg, \
886 struct ureg_dst dst, \
888 struct ureg_src src0, \
889 struct ureg_src src1, \
890 struct ureg_src src2, \
891 struct ureg_src src3 ) \
893 unsigned opcode = TGSI_OPCODE_##op; \
894 struct ureg_emit_insn_result insn; \
895 if (ureg_dst_is_empty(dst)) \
897 insn = ureg_emit_insn(ureg, \
908 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
909 ureg_emit_dst( ureg, dst ); \
910 ureg_emit_src( ureg, src0 ); \
911 ureg_emit_src( ureg, src1 ); \
912 ureg_emit_src( ureg, src2 ); \
913 ureg_emit_src( ureg, src3 ); \
914 ureg_fixup_insn_size( ureg, insn.insn_token ); \
917 #define OP14_SAMPLE( op ) \
918 static inline void ureg_##op( struct ureg_program *ureg, \
919 struct ureg_dst dst, \
920 struct ureg_src src0, \
921 struct ureg_src src1, \
922 struct ureg_src src2, \
923 struct ureg_src src3 ) \
925 unsigned opcode = TGSI_OPCODE_##op; \
926 unsigned target = TGSI_TEXTURE_UNKNOWN; \
927 struct ureg_emit_insn_result insn; \
928 if (ureg_dst_is_empty(dst)) \
930 insn = ureg_emit_insn(ureg, \
941 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
942 ureg_emit_dst( ureg, dst ); \
943 ureg_emit_src( ureg, src0 ); \
944 ureg_emit_src( ureg, src1 ); \
945 ureg_emit_src( ureg, src2 ); \
946 ureg_emit_src( ureg, src3 ); \
947 ureg_fixup_insn_size( ureg, insn.insn_token ); \
952 static inline void ureg_##op( struct ureg_program *ureg, \
953 struct ureg_dst dst, \
954 struct ureg_src src0, \
955 struct ureg_src src1, \
956 struct ureg_src src2, \
957 struct ureg_src src3 ) \
959 unsigned opcode = TGSI_OPCODE_##op; \
960 struct ureg_emit_insn_result insn; \
961 if (ureg_dst_is_empty(dst)) \
963 insn = ureg_emit_insn(ureg, \
974 ureg_emit_dst( ureg, dst ); \
975 ureg_emit_src( ureg, src0 ); \
976 ureg_emit_src( ureg, src1 ); \
977 ureg_emit_src( ureg, src2 ); \
978 ureg_emit_src( ureg, src3 ); \
979 ureg_fixup_insn_size( ureg, insn.insn_token ); \
984 static inline void ureg_##op( struct ureg_program *ureg, \
985 struct ureg_dst dst, \
986 struct ureg_src src0, \
987 struct ureg_src src1, \
988 struct ureg_src src2, \
989 struct ureg_src src3, \
990 struct ureg_src src4 ) \
992 unsigned opcode = TGSI_OPCODE_##op; \
993 struct ureg_emit_insn_result insn; \
994 if (ureg_dst_is_empty(dst)) \
996 insn = ureg_emit_insn(ureg, \
1007 ureg_emit_dst( ureg, dst ); \
1008 ureg_emit_src( ureg, src0 ); \
1009 ureg_emit_src( ureg, src1 ); \
1010 ureg_emit_src( ureg, src2 ); \
1011 ureg_emit_src( ureg, src3 ); \
1012 ureg_emit_src( ureg, src4 ); \
1013 ureg_fixup_insn_size( ureg, insn.insn_token ); \
1016 #define OP15_SAMPLE( op ) \
1017 static inline void ureg_##op( struct ureg_program *ureg, \
1018 struct ureg_dst dst, \
1019 struct ureg_src src0, \
1020 struct ureg_src src1, \
1021 struct ureg_src src2, \
1022 struct ureg_src src3, \
1023 struct ureg_src src4 ) \
1025 unsigned opcode = TGSI_OPCODE_##op; \
1026 unsigned target = TGSI_TEXTURE_UNKNOWN; \
1027 struct ureg_emit_insn_result insn; \
1028 if (ureg_dst_is_empty(dst)) \
1030 insn = ureg_emit_insn(ureg, \
1041 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
1042 ureg_emit_dst( ureg, dst ); \
1043 ureg_emit_src( ureg, src0 ); \
1044 ureg_emit_src( ureg, src1 ); \
1045 ureg_emit_src( ureg, src2 ); \
1046 ureg_emit_src( ureg, src3 ); \
1047 ureg_emit_src( ureg, src4 ); \
1048 ureg_fixup_insn_size( ureg, insn.insn_token ); \
1051 /* Use a template include to generate a correctly-typed ureg_OP()
1052 * function for each TGSI opcode:
1054 #include "tgsi_opcode_tmp.h"
1057 /***********************************************************************
1058 * Inline helpers for manipulating register structs:
1060 static inline struct ureg_src
1061 ureg_negate( struct ureg_src reg
)
1063 assert(reg
.File
!= TGSI_FILE_NULL
);
1068 static inline struct ureg_src
1069 ureg_abs( struct ureg_src reg
)
1071 assert(reg
.File
!= TGSI_FILE_NULL
);
1077 static inline struct ureg_src
1078 ureg_swizzle( struct ureg_src reg
,
1079 int x
, int y
, int z
, int w
)
1081 unsigned swz
= ( (reg
.SwizzleX
<< 0) |
1082 (reg
.SwizzleY
<< 2) |
1083 (reg
.SwizzleZ
<< 4) |
1084 (reg
.SwizzleW
<< 6));
1086 assert(reg
.File
!= TGSI_FILE_NULL
);
1092 reg
.SwizzleX
= (swz
>> (x
*2)) & 0x3;
1093 reg
.SwizzleY
= (swz
>> (y
*2)) & 0x3;
1094 reg
.SwizzleZ
= (swz
>> (z
*2)) & 0x3;
1095 reg
.SwizzleW
= (swz
>> (w
*2)) & 0x3;
1099 static inline struct ureg_src
1100 ureg_scalar( struct ureg_src reg
, int x
)
1102 return ureg_swizzle(reg
, x
, x
, x
, x
);
1105 static inline struct ureg_dst
1106 ureg_writemask( struct ureg_dst reg
,
1107 unsigned writemask
)
1109 assert(reg
.File
!= TGSI_FILE_NULL
);
1110 reg
.WriteMask
&= writemask
;
1114 static inline struct ureg_dst
1115 ureg_saturate( struct ureg_dst reg
)
1117 assert(reg
.File
!= TGSI_FILE_NULL
);
1122 static inline struct ureg_dst
1123 ureg_predicate(struct ureg_dst reg
,
1130 assert(reg
.File
!= TGSI_FILE_NULL
);
1132 reg
.PredNegate
= negate
;
1133 reg
.PredSwizzleX
= swizzle_x
;
1134 reg
.PredSwizzleY
= swizzle_y
;
1135 reg
.PredSwizzleZ
= swizzle_z
;
1136 reg
.PredSwizzleW
= swizzle_w
;
1140 static inline struct ureg_dst
1141 ureg_dst_indirect( struct ureg_dst reg
, struct ureg_src addr
)
1143 assert(reg
.File
!= TGSI_FILE_NULL
);
1144 assert(addr
.File
== TGSI_FILE_ADDRESS
|| addr
.File
== TGSI_FILE_TEMPORARY
);
1146 reg
.IndirectFile
= addr
.File
;
1147 reg
.IndirectIndex
= addr
.Index
;
1148 reg
.IndirectSwizzle
= addr
.SwizzleX
;
1152 static inline struct ureg_src
1153 ureg_src_indirect( struct ureg_src reg
, struct ureg_src addr
)
1155 assert(reg
.File
!= TGSI_FILE_NULL
);
1156 assert(addr
.File
== TGSI_FILE_ADDRESS
|| addr
.File
== TGSI_FILE_TEMPORARY
);
1158 reg
.IndirectFile
= addr
.File
;
1159 reg
.IndirectIndex
= addr
.Index
;
1160 reg
.IndirectSwizzle
= addr
.SwizzleX
;
1164 static inline struct ureg_dst
1165 ureg_dst_dimension( struct ureg_dst reg
, int index
)
1167 assert(reg
.File
!= TGSI_FILE_NULL
);
1169 reg
.DimIndirect
= 0;
1170 reg
.DimensionIndex
= index
;
1174 static inline struct ureg_src
1175 ureg_src_dimension( struct ureg_src reg
, int index
)
1177 assert(reg
.File
!= TGSI_FILE_NULL
);
1179 reg
.DimIndirect
= 0;
1180 reg
.DimensionIndex
= index
;
1184 static inline struct ureg_dst
1185 ureg_dst_dimension_indirect( struct ureg_dst reg
, struct ureg_src addr
,
1188 assert(reg
.File
!= TGSI_FILE_NULL
);
1190 reg
.DimIndirect
= 1;
1191 reg
.DimensionIndex
= index
;
1192 reg
.DimIndFile
= addr
.File
;
1193 reg
.DimIndIndex
= addr
.Index
;
1194 reg
.DimIndSwizzle
= addr
.SwizzleX
;
1198 static inline struct ureg_src
1199 ureg_src_dimension_indirect( struct ureg_src reg
, struct ureg_src addr
,
1202 assert(reg
.File
!= TGSI_FILE_NULL
);
1204 reg
.DimIndirect
= 1;
1205 reg
.DimensionIndex
= index
;
1206 reg
.DimIndFile
= addr
.File
;
1207 reg
.DimIndIndex
= addr
.Index
;
1208 reg
.DimIndSwizzle
= addr
.SwizzleX
;
1212 static inline struct ureg_src
1213 ureg_src_array_offset(struct ureg_src reg
, int offset
)
1215 reg
.Index
+= offset
;
1219 static inline struct ureg_dst
1220 ureg_dst_array_offset( struct ureg_dst reg
, int offset
)
1222 reg
.Index
+= offset
;
1226 static inline struct ureg_dst
1227 ureg_dst_array_register(unsigned file
,
1231 struct ureg_dst dst
;
1234 dst
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1236 dst
.IndirectFile
= TGSI_FILE_NULL
;
1237 dst
.IndirectIndex
= 0;
1238 dst
.IndirectSwizzle
= 0;
1242 dst
.PredSwizzleX
= TGSI_SWIZZLE_X
;
1243 dst
.PredSwizzleY
= TGSI_SWIZZLE_Y
;
1244 dst
.PredSwizzleZ
= TGSI_SWIZZLE_Z
;
1245 dst
.PredSwizzleW
= TGSI_SWIZZLE_W
;
1248 dst
.DimensionIndex
= 0;
1249 dst
.DimIndirect
= 0;
1250 dst
.DimIndFile
= TGSI_FILE_NULL
;
1251 dst
.DimIndIndex
= 0;
1252 dst
.DimIndSwizzle
= 0;
1253 dst
.ArrayID
= array_id
;
1258 static inline struct ureg_dst
1259 ureg_dst_register(unsigned file
,
1262 return ureg_dst_array_register(file
, index
, 0);
1265 static inline struct ureg_dst
1266 ureg_dst( struct ureg_src src
)
1268 struct ureg_dst dst
;
1270 assert(!src
.Indirect
||
1271 (src
.IndirectFile
== TGSI_FILE_ADDRESS
||
1272 src
.IndirectFile
== TGSI_FILE_TEMPORARY
));
1274 dst
.File
= src
.File
;
1275 dst
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1276 dst
.IndirectFile
= src
.IndirectFile
;
1277 dst
.Indirect
= src
.Indirect
;
1278 dst
.IndirectIndex
= src
.IndirectIndex
;
1279 dst
.IndirectSwizzle
= src
.IndirectSwizzle
;
1283 dst
.PredSwizzleX
= TGSI_SWIZZLE_X
;
1284 dst
.PredSwizzleY
= TGSI_SWIZZLE_Y
;
1285 dst
.PredSwizzleZ
= TGSI_SWIZZLE_Z
;
1286 dst
.PredSwizzleW
= TGSI_SWIZZLE_W
;
1287 dst
.Index
= src
.Index
;
1288 dst
.Dimension
= src
.Dimension
;
1289 dst
.DimensionIndex
= src
.DimensionIndex
;
1290 dst
.DimIndirect
= src
.DimIndirect
;
1291 dst
.DimIndFile
= src
.DimIndFile
;
1292 dst
.DimIndIndex
= src
.DimIndIndex
;
1293 dst
.DimIndSwizzle
= src
.DimIndSwizzle
;
1294 dst
.ArrayID
= src
.ArrayID
;
1299 static inline struct ureg_src
1300 ureg_src_array_register(unsigned file
,
1304 struct ureg_src src
;
1307 src
.SwizzleX
= TGSI_SWIZZLE_X
;
1308 src
.SwizzleY
= TGSI_SWIZZLE_Y
;
1309 src
.SwizzleZ
= TGSI_SWIZZLE_Z
;
1310 src
.SwizzleW
= TGSI_SWIZZLE_W
;
1312 src
.IndirectFile
= TGSI_FILE_NULL
;
1313 src
.IndirectIndex
= 0;
1314 src
.IndirectSwizzle
= 0;
1319 src
.DimensionIndex
= 0;
1320 src
.DimIndirect
= 0;
1321 src
.DimIndFile
= TGSI_FILE_NULL
;
1322 src
.DimIndIndex
= 0;
1323 src
.DimIndSwizzle
= 0;
1324 src
.ArrayID
= array_id
;
1329 static inline struct ureg_src
1330 ureg_src_register(unsigned file
,
1333 return ureg_src_array_register(file
, index
, 0);
1336 static inline struct ureg_src
1337 ureg_src( struct ureg_dst dst
)
1339 struct ureg_src src
;
1341 src
.File
= dst
.File
;
1342 src
.SwizzleX
= TGSI_SWIZZLE_X
;
1343 src
.SwizzleY
= TGSI_SWIZZLE_Y
;
1344 src
.SwizzleZ
= TGSI_SWIZZLE_Z
;
1345 src
.SwizzleW
= TGSI_SWIZZLE_W
;
1346 src
.Indirect
= dst
.Indirect
;
1347 src
.IndirectFile
= dst
.IndirectFile
;
1348 src
.IndirectIndex
= dst
.IndirectIndex
;
1349 src
.IndirectSwizzle
= dst
.IndirectSwizzle
;
1351 src
.Index
= dst
.Index
;
1353 src
.Dimension
= dst
.Dimension
;
1354 src
.DimensionIndex
= dst
.DimensionIndex
;
1355 src
.DimIndirect
= dst
.DimIndirect
;
1356 src
.DimIndFile
= dst
.DimIndFile
;
1357 src
.DimIndIndex
= dst
.DimIndIndex
;
1358 src
.DimIndSwizzle
= dst
.DimIndSwizzle
;
1359 src
.ArrayID
= dst
.ArrayID
;
1366 static inline struct ureg_dst
1367 ureg_dst_undef( void )
1369 struct ureg_dst dst
;
1371 dst
.File
= TGSI_FILE_NULL
;
1374 dst
.IndirectFile
= TGSI_FILE_NULL
;
1375 dst
.IndirectIndex
= 0;
1376 dst
.IndirectSwizzle
= 0;
1380 dst
.PredSwizzleX
= TGSI_SWIZZLE_X
;
1381 dst
.PredSwizzleY
= TGSI_SWIZZLE_Y
;
1382 dst
.PredSwizzleZ
= TGSI_SWIZZLE_Z
;
1383 dst
.PredSwizzleW
= TGSI_SWIZZLE_W
;
1386 dst
.DimensionIndex
= 0;
1387 dst
.DimIndirect
= 0;
1388 dst
.DimIndFile
= TGSI_FILE_NULL
;
1389 dst
.DimIndIndex
= 0;
1390 dst
.DimIndSwizzle
= 0;
1396 static inline struct ureg_src
1397 ureg_src_undef( void )
1399 struct ureg_src src
;
1401 src
.File
= TGSI_FILE_NULL
;
1407 src
.IndirectFile
= TGSI_FILE_NULL
;
1408 src
.IndirectIndex
= 0;
1409 src
.IndirectSwizzle
= 0;
1414 src
.DimensionIndex
= 0;
1415 src
.DimIndirect
= 0;
1416 src
.DimIndFile
= TGSI_FILE_NULL
;
1417 src
.DimIndIndex
= 0;
1418 src
.DimIndSwizzle
= 0;
1424 static inline boolean
1425 ureg_src_is_undef( struct ureg_src src
)
1427 return src
.File
== TGSI_FILE_NULL
;
1430 static inline boolean
1431 ureg_dst_is_undef( struct ureg_dst dst
)
1433 return dst
.File
== TGSI_FILE_NULL
;