b3f47ef63de3f38c0b67d462251b524de101cf9e
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"
40 struct pipe_stream_output_info
;
42 /* Almost a tgsi_src_register, but we need to pull in the Absolute
43 * flag from the _ext token. Indirect flag always implies ADDR[0].
47 unsigned File
: 4; /* TGSI_FILE_ */
48 unsigned SwizzleX
: 2; /* TGSI_SWIZZLE_ */
49 unsigned SwizzleY
: 2; /* TGSI_SWIZZLE_ */
50 unsigned SwizzleZ
: 2; /* TGSI_SWIZZLE_ */
51 unsigned SwizzleW
: 2; /* TGSI_SWIZZLE_ */
52 unsigned Indirect
: 1; /* BOOL */
53 unsigned DimIndirect
: 1; /* BOOL */
54 unsigned Dimension
: 1; /* BOOL */
55 unsigned Absolute
: 1; /* BOOL */
56 unsigned Negate
: 1; /* BOOL */
57 unsigned IndirectFile
: 4; /* TGSI_FILE_ */
58 unsigned IndirectSwizzle
: 2; /* TGSI_SWIZZLE_ */
59 unsigned DimIndFile
: 4; /* TGSI_FILE_ */
60 unsigned DimIndSwizzle
: 2; /* TGSI_SWIZZLE_ */
61 int Index
: 16; /* SINT */
62 int IndirectIndex
: 16; /* SINT */
63 int DimensionIndex
: 16; /* SINT */
64 int DimIndIndex
: 16; /* SINT */
65 unsigned ArrayID
: 10; /* UINT */
68 /* Very similar to a tgsi_dst_register, removing unsupported fields
69 * and adding a Saturate flag. It's easier to push saturate into the
70 * destination register than to try and create a _SAT variant of each
71 * instruction function.
75 unsigned File
: 4; /* TGSI_FILE_ */
76 unsigned WriteMask
: 4; /* TGSI_WRITEMASK_ */
77 unsigned Indirect
: 1; /* BOOL */
78 unsigned Saturate
: 1; /* BOOL */
79 unsigned Predicate
: 1;
80 unsigned PredNegate
: 1; /* BOOL */
81 unsigned PredSwizzleX
: 2; /* TGSI_SWIZZLE_ */
82 unsigned PredSwizzleY
: 2; /* TGSI_SWIZZLE_ */
83 unsigned PredSwizzleZ
: 2; /* TGSI_SWIZZLE_ */
84 unsigned PredSwizzleW
: 2; /* TGSI_SWIZZLE_ */
85 int Index
: 16; /* SINT */
86 int IndirectIndex
: 16; /* SINT */
87 unsigned IndirectFile
: 4; /* TGSI_FILE_ */
88 int IndirectSwizzle
: 2; /* TGSI_SWIZZLE_ */
89 unsigned ArrayID
: 10; /* UINT */
95 ureg_create( unsigned processor
);
97 const struct tgsi_token
*
98 ureg_finalize( struct ureg_program
* );
100 /* Create and return a shader:
103 ureg_create_shader( struct ureg_program
*,
104 struct pipe_context
*pipe
,
105 const struct pipe_stream_output_info
*so
);
108 /* Alternately, return the built token stream and hand ownership of
109 * that memory to the caller:
111 const struct tgsi_token
*
112 ureg_get_tokens( struct ureg_program
*ureg
,
113 unsigned *nr_tokens
);
116 * Returns the number of currently declared outputs.
119 ureg_get_nr_outputs( const struct ureg_program
*ureg
);
122 /* Free the tokens created by ureg_get_tokens() */
123 void ureg_free_tokens( const struct tgsi_token
*tokens
);
127 ureg_destroy( struct ureg_program
* );
130 /***********************************************************************
131 * Convenience routine:
134 ureg_create_shader_with_so_and_destroy( struct ureg_program
*p
,
135 struct pipe_context
*pipe
,
136 const struct pipe_stream_output_info
*so
)
138 void *result
= ureg_create_shader( p
, pipe
, so
);
144 ureg_create_shader_and_destroy( struct ureg_program
*p
,
145 struct pipe_context
*pipe
)
147 return ureg_create_shader_with_so_and_destroy(p
, pipe
, NULL
);
151 /***********************************************************************
152 * Build shader properties:
156 ureg_property(struct ureg_program
*ureg
, unsigned name
, unsigned value
);
159 /***********************************************************************
160 * Build shader declarations:
164 ureg_DECL_fs_input_cyl_centroid(struct ureg_program
*,
165 unsigned semantic_name
,
166 unsigned semantic_index
,
167 unsigned interp_mode
,
168 unsigned cylindrical_wrap
,
169 unsigned interp_location
);
171 static INLINE
struct ureg_src
172 ureg_DECL_fs_input_cyl(struct ureg_program
*ureg
,
173 unsigned semantic_name
,
174 unsigned semantic_index
,
175 unsigned interp_mode
,
176 unsigned cylindrical_wrap
)
178 return ureg_DECL_fs_input_cyl_centroid(ureg
,
186 static INLINE
struct ureg_src
187 ureg_DECL_fs_input(struct ureg_program
*ureg
,
188 unsigned semantic_name
,
189 unsigned semantic_index
,
190 unsigned interp_mode
)
192 return ureg_DECL_fs_input_cyl_centroid(ureg
,
200 ureg_DECL_vs_input( struct ureg_program
*,
204 ureg_DECL_gs_input(struct ureg_program
*,
206 unsigned semantic_name
,
207 unsigned semantic_index
);
210 ureg_DECL_system_value(struct ureg_program
*,
212 unsigned semantic_name
,
213 unsigned semantic_index
);
216 ureg_DECL_output_masked( struct ureg_program
*,
217 unsigned semantic_name
,
218 unsigned semantic_index
,
219 unsigned usage_mask
);
222 ureg_DECL_output( struct ureg_program
*,
223 unsigned semantic_name
,
224 unsigned semantic_index
);
227 ureg_DECL_immediate( struct ureg_program
*,
232 ureg_DECL_immediate_uint( struct ureg_program
*,
237 ureg_DECL_immediate_block_uint( struct ureg_program
*,
242 ureg_DECL_immediate_int( struct ureg_program
*,
247 ureg_DECL_constant2D(struct ureg_program
*ureg
,
253 ureg_DECL_constant( struct ureg_program
*,
257 ureg_DECL_temporary( struct ureg_program
* );
260 * Emit a temporary with the LOCAL declaration flag set. For use when
261 * the register value is not required to be preserved across
262 * subroutine boundaries.
265 ureg_DECL_local_temporary( struct ureg_program
* );
268 * Declare "size" continuous temporary registers.
271 ureg_DECL_array_temporary( struct ureg_program
*,
276 ureg_release_temporary( struct ureg_program
*ureg
,
277 struct ureg_dst tmp
);
280 ureg_DECL_address( struct ureg_program
* );
283 ureg_DECL_predicate(struct ureg_program
*);
285 /* Supply an index to the sampler declaration as this is the hook to
286 * the external pipe_sampler state. Users of this function probably
287 * don't want just any sampler, but a specific one which they've set
288 * up state for in the context.
291 ureg_DECL_sampler( struct ureg_program
*,
295 ureg_DECL_sampler_view(struct ureg_program
*,
298 unsigned return_type_x
,
299 unsigned return_type_y
,
300 unsigned return_type_z
,
301 unsigned return_type_w
);
304 static INLINE
struct ureg_src
305 ureg_imm4f( struct ureg_program
*ureg
,
314 return ureg_DECL_immediate( ureg
, v
, 4 );
317 static INLINE
struct ureg_src
318 ureg_imm3f( struct ureg_program
*ureg
,
326 return ureg_DECL_immediate( ureg
, v
, 3 );
329 static INLINE
struct ureg_src
330 ureg_imm2f( struct ureg_program
*ureg
,
336 return ureg_DECL_immediate( ureg
, v
, 2 );
339 static INLINE
struct ureg_src
340 ureg_imm1f( struct ureg_program
*ureg
,
345 return ureg_DECL_immediate( ureg
, v
, 1 );
348 static INLINE
struct ureg_src
349 ureg_imm4u( struct ureg_program
*ureg
,
350 unsigned a
, unsigned b
,
351 unsigned c
, unsigned d
)
358 return ureg_DECL_immediate_uint( ureg
, v
, 4 );
361 static INLINE
struct ureg_src
362 ureg_imm3u( struct ureg_program
*ureg
,
363 unsigned a
, unsigned b
,
370 return ureg_DECL_immediate_uint( ureg
, v
, 3 );
373 static INLINE
struct ureg_src
374 ureg_imm2u( struct ureg_program
*ureg
,
375 unsigned a
, unsigned b
)
380 return ureg_DECL_immediate_uint( ureg
, v
, 2 );
383 static INLINE
struct ureg_src
384 ureg_imm1u( struct ureg_program
*ureg
,
387 return ureg_DECL_immediate_uint( ureg
, &a
, 1 );
390 static INLINE
struct ureg_src
391 ureg_imm4i( struct ureg_program
*ureg
,
400 return ureg_DECL_immediate_int( ureg
, v
, 4 );
403 static INLINE
struct ureg_src
404 ureg_imm3i( struct ureg_program
*ureg
,
412 return ureg_DECL_immediate_int( ureg
, v
, 3 );
415 static INLINE
struct ureg_src
416 ureg_imm2i( struct ureg_program
*ureg
,
422 return ureg_DECL_immediate_int( ureg
, v
, 2 );
425 static INLINE
struct ureg_src
426 ureg_imm1i( struct ureg_program
*ureg
,
429 return ureg_DECL_immediate_int( ureg
, &a
, 1 );
432 /* Where the destination register has a valid file, but an empty
435 static INLINE boolean
436 ureg_dst_is_empty( struct ureg_dst dst
)
438 return dst
.File
!= TGSI_FILE_NULL
&&
442 /***********************************************************************
443 * Functions for patching up labels
447 /* Will return a number which can be used in a label to point to the
448 * next instruction to be emitted.
451 ureg_get_instruction_number( struct ureg_program
*ureg
);
454 /* Patch a given label (expressed as a token number) to point to a
455 * given instruction (expressed as an instruction number).
457 * Labels are obtained from instruction emitters, eg ureg_CAL().
458 * Instruction numbers are obtained from ureg_get_instruction_number(),
462 ureg_fixup_label(struct ureg_program
*ureg
,
463 unsigned label_token
,
464 unsigned instruction_number
);
467 /* Generic instruction emitter. Use if you need to pass the opcode as
468 * a parameter, rather than using the emit_OP() variants below.
471 ureg_insn(struct ureg_program
*ureg
,
473 const struct ureg_dst
*dst
,
475 const struct ureg_src
*src
,
480 ureg_tex_insn(struct ureg_program
*ureg
,
482 const struct ureg_dst
*dst
,
485 const struct tgsi_texture_offset
*texoffsets
,
487 const struct ureg_src
*src
,
492 ureg_label_insn(struct ureg_program
*ureg
,
494 const struct ureg_src
*src
,
499 /***********************************************************************
500 * Internal instruction helpers, don't call these directly:
503 struct ureg_emit_insn_result
{
504 unsigned insn_token
; /*< Used to fixup insn size. */
505 unsigned extended_token
; /*< Used to set the Extended bit, usually the same as insn_token. */
508 struct ureg_emit_insn_result
509 ureg_emit_insn(struct ureg_program
*ureg
,
514 unsigned pred_swizzle_x
,
515 unsigned pred_swizzle_y
,
516 unsigned pred_swizzle_z
,
517 unsigned pred_swizzle_w
,
522 ureg_emit_label(struct ureg_program
*ureg
,
524 unsigned *label_token
);
527 ureg_emit_texture(struct ureg_program
*ureg
,
529 unsigned target
, unsigned num_offsets
);
532 ureg_emit_texture_offset(struct ureg_program
*ureg
,
533 const struct tgsi_texture_offset
*offset
);
536 ureg_emit_dst( struct ureg_program
*ureg
,
537 struct ureg_dst dst
);
540 ureg_emit_src( struct ureg_program
*ureg
,
541 struct ureg_src src
);
544 ureg_fixup_insn_size(struct ureg_program
*ureg
,
549 static INLINE void ureg_##op( struct ureg_program *ureg ) \
551 unsigned opcode = TGSI_OPCODE_##op; \
552 struct ureg_emit_insn_result insn; \
553 insn = ureg_emit_insn(ureg, \
564 ureg_fixup_insn_size( ureg, insn.insn_token ); \
568 static INLINE void ureg_##op( struct ureg_program *ureg, \
569 struct ureg_src src ) \
571 unsigned opcode = TGSI_OPCODE_##op; \
572 struct ureg_emit_insn_result insn; \
573 insn = ureg_emit_insn(ureg, \
584 ureg_emit_src( ureg, src ); \
585 ureg_fixup_insn_size( ureg, insn.insn_token ); \
588 #define OP00_LBL( op ) \
589 static INLINE void ureg_##op( struct ureg_program *ureg, \
590 unsigned *label_token ) \
592 unsigned opcode = TGSI_OPCODE_##op; \
593 struct ureg_emit_insn_result insn; \
594 insn = ureg_emit_insn(ureg, \
605 ureg_emit_label( ureg, insn.extended_token, label_token ); \
606 ureg_fixup_insn_size( ureg, insn.insn_token ); \
609 #define OP01_LBL( op ) \
610 static INLINE void ureg_##op( struct ureg_program *ureg, \
611 struct ureg_src src, \
612 unsigned *label_token ) \
614 unsigned opcode = TGSI_OPCODE_##op; \
615 struct ureg_emit_insn_result insn; \
616 insn = ureg_emit_insn(ureg, \
627 ureg_emit_label( ureg, insn.extended_token, label_token ); \
628 ureg_emit_src( ureg, src ); \
629 ureg_fixup_insn_size( ureg, insn.insn_token ); \
633 static INLINE void ureg_##op( struct ureg_program *ureg, \
634 struct ureg_dst dst ) \
636 unsigned opcode = TGSI_OPCODE_##op; \
637 struct ureg_emit_insn_result insn; \
638 if (ureg_dst_is_empty(dst)) \
640 insn = ureg_emit_insn(ureg, \
651 ureg_emit_dst( ureg, dst ); \
652 ureg_fixup_insn_size( ureg, insn.insn_token ); \
657 static INLINE void ureg_##op( struct ureg_program *ureg, \
658 struct ureg_dst dst, \
659 struct ureg_src src ) \
661 unsigned opcode = TGSI_OPCODE_##op; \
662 struct ureg_emit_insn_result insn; \
663 if (ureg_dst_is_empty(dst)) \
665 insn = ureg_emit_insn(ureg, \
676 ureg_emit_dst( ureg, dst ); \
677 ureg_emit_src( ureg, src ); \
678 ureg_fixup_insn_size( ureg, insn.insn_token ); \
682 static INLINE void ureg_##op( struct ureg_program *ureg, \
683 struct ureg_dst dst, \
684 struct ureg_src src0, \
685 struct ureg_src src1 ) \
687 unsigned opcode = TGSI_OPCODE_##op; \
688 struct ureg_emit_insn_result insn; \
689 if (ureg_dst_is_empty(dst)) \
691 insn = ureg_emit_insn(ureg, \
702 ureg_emit_dst( ureg, dst ); \
703 ureg_emit_src( ureg, src0 ); \
704 ureg_emit_src( ureg, src1 ); \
705 ureg_fixup_insn_size( ureg, insn.insn_token ); \
708 #define OP12_TEX( op ) \
709 static INLINE void ureg_##op( struct ureg_program *ureg, \
710 struct ureg_dst dst, \
712 struct ureg_src src0, \
713 struct ureg_src src1 ) \
715 unsigned opcode = TGSI_OPCODE_##op; \
716 struct ureg_emit_insn_result insn; \
717 if (ureg_dst_is_empty(dst)) \
719 insn = ureg_emit_insn(ureg, \
730 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
731 ureg_emit_dst( ureg, dst ); \
732 ureg_emit_src( ureg, src0 ); \
733 ureg_emit_src( ureg, src1 ); \
734 ureg_fixup_insn_size( ureg, insn.insn_token ); \
737 #define OP12_SAMPLE( op ) \
738 static INLINE void ureg_##op( struct ureg_program *ureg, \
739 struct ureg_dst dst, \
740 struct ureg_src src0, \
741 struct ureg_src src1 ) \
743 unsigned opcode = TGSI_OPCODE_##op; \
744 unsigned target = TGSI_TEXTURE_UNKNOWN; \
745 struct ureg_emit_insn_result insn; \
746 if (ureg_dst_is_empty(dst)) \
748 insn = ureg_emit_insn(ureg, \
759 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
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 ); \
767 static INLINE void ureg_##op( struct ureg_program *ureg, \
768 struct ureg_dst dst, \
769 struct ureg_src src0, \
770 struct ureg_src src1, \
771 struct ureg_src src2 ) \
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_dst( ureg, dst ); \
789 ureg_emit_src( ureg, src0 ); \
790 ureg_emit_src( ureg, src1 ); \
791 ureg_emit_src( ureg, src2 ); \
792 ureg_fixup_insn_size( ureg, insn.insn_token ); \
795 #define OP13_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, \
800 struct ureg_src src2 ) \
802 unsigned opcode = TGSI_OPCODE_##op; \
803 unsigned target = TGSI_TEXTURE_UNKNOWN; \
804 struct ureg_emit_insn_result insn; \
805 if (ureg_dst_is_empty(dst)) \
807 insn = ureg_emit_insn(ureg, \
818 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
819 ureg_emit_dst( ureg, dst ); \
820 ureg_emit_src( ureg, src0 ); \
821 ureg_emit_src( ureg, src1 ); \
822 ureg_emit_src( ureg, src2 ); \
823 ureg_fixup_insn_size( ureg, insn.insn_token ); \
826 #define OP14_TEX( op ) \
827 static INLINE void ureg_##op( struct ureg_program *ureg, \
828 struct ureg_dst dst, \
830 struct ureg_src src0, \
831 struct ureg_src src1, \
832 struct ureg_src src2, \
833 struct ureg_src src3 ) \
835 unsigned opcode = TGSI_OPCODE_##op; \
836 struct ureg_emit_insn_result insn; \
837 if (ureg_dst_is_empty(dst)) \
839 insn = ureg_emit_insn(ureg, \
850 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
851 ureg_emit_dst( ureg, dst ); \
852 ureg_emit_src( ureg, src0 ); \
853 ureg_emit_src( ureg, src1 ); \
854 ureg_emit_src( ureg, src2 ); \
855 ureg_emit_src( ureg, src3 ); \
856 ureg_fixup_insn_size( ureg, insn.insn_token ); \
859 #define OP14_SAMPLE( op ) \
860 static INLINE void ureg_##op( struct ureg_program *ureg, \
861 struct ureg_dst dst, \
862 struct ureg_src src0, \
863 struct ureg_src src1, \
864 struct ureg_src src2, \
865 struct ureg_src src3 ) \
867 unsigned opcode = TGSI_OPCODE_##op; \
868 unsigned target = TGSI_TEXTURE_UNKNOWN; \
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 ); \
894 static INLINE void ureg_##op( struct ureg_program *ureg, \
895 struct ureg_dst dst, \
896 struct ureg_src src0, \
897 struct ureg_src src1, \
898 struct ureg_src src2, \
899 struct ureg_src src3 ) \
901 unsigned opcode = TGSI_OPCODE_##op; \
902 struct ureg_emit_insn_result insn; \
903 if (ureg_dst_is_empty(dst)) \
905 insn = ureg_emit_insn(ureg, \
916 ureg_emit_dst( ureg, dst ); \
917 ureg_emit_src( ureg, src0 ); \
918 ureg_emit_src( ureg, src1 ); \
919 ureg_emit_src( ureg, src2 ); \
920 ureg_emit_src( ureg, src3 ); \
921 ureg_fixup_insn_size( ureg, insn.insn_token ); \
926 static INLINE void ureg_##op( struct ureg_program *ureg, \
927 struct ureg_dst dst, \
928 struct ureg_src src0, \
929 struct ureg_src src1, \
930 struct ureg_src src2, \
931 struct ureg_src src3, \
932 struct ureg_src src4 ) \
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_emit_src( ureg, src4 ); \
955 ureg_fixup_insn_size( ureg, insn.insn_token ); \
958 #define OP15_SAMPLE( op ) \
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 unsigned target = TGSI_TEXTURE_UNKNOWN; \
969 struct ureg_emit_insn_result insn; \
970 if (ureg_dst_is_empty(dst)) \
972 insn = ureg_emit_insn(ureg, \
983 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
984 ureg_emit_dst( ureg, dst ); \
985 ureg_emit_src( ureg, src0 ); \
986 ureg_emit_src( ureg, src1 ); \
987 ureg_emit_src( ureg, src2 ); \
988 ureg_emit_src( ureg, src3 ); \
989 ureg_emit_src( ureg, src4 ); \
990 ureg_fixup_insn_size( ureg, insn.insn_token ); \
993 /* Use a template include to generate a correctly-typed ureg_OP()
994 * function for each TGSI opcode:
996 #include "tgsi_opcode_tmp.h"
999 /***********************************************************************
1000 * Inline helpers for manipulating register structs:
1002 static INLINE
struct ureg_src
1003 ureg_negate( struct ureg_src reg
)
1005 assert(reg
.File
!= TGSI_FILE_NULL
);
1010 static INLINE
struct ureg_src
1011 ureg_abs( struct ureg_src reg
)
1013 assert(reg
.File
!= TGSI_FILE_NULL
);
1019 static INLINE
struct ureg_src
1020 ureg_swizzle( struct ureg_src reg
,
1021 int x
, int y
, int z
, int w
)
1023 unsigned swz
= ( (reg
.SwizzleX
<< 0) |
1024 (reg
.SwizzleY
<< 2) |
1025 (reg
.SwizzleZ
<< 4) |
1026 (reg
.SwizzleW
<< 6));
1028 assert(reg
.File
!= TGSI_FILE_NULL
);
1034 reg
.SwizzleX
= (swz
>> (x
*2)) & 0x3;
1035 reg
.SwizzleY
= (swz
>> (y
*2)) & 0x3;
1036 reg
.SwizzleZ
= (swz
>> (z
*2)) & 0x3;
1037 reg
.SwizzleW
= (swz
>> (w
*2)) & 0x3;
1041 static INLINE
struct ureg_src
1042 ureg_scalar( struct ureg_src reg
, int x
)
1044 return ureg_swizzle(reg
, x
, x
, x
, x
);
1047 static INLINE
struct ureg_dst
1048 ureg_writemask( struct ureg_dst reg
,
1049 unsigned writemask
)
1051 assert(reg
.File
!= TGSI_FILE_NULL
);
1052 reg
.WriteMask
&= writemask
;
1056 static INLINE
struct ureg_dst
1057 ureg_saturate( struct ureg_dst reg
)
1059 assert(reg
.File
!= TGSI_FILE_NULL
);
1064 static INLINE
struct ureg_dst
1065 ureg_predicate(struct ureg_dst reg
,
1072 assert(reg
.File
!= TGSI_FILE_NULL
);
1074 reg
.PredNegate
= negate
;
1075 reg
.PredSwizzleX
= swizzle_x
;
1076 reg
.PredSwizzleY
= swizzle_y
;
1077 reg
.PredSwizzleZ
= swizzle_z
;
1078 reg
.PredSwizzleW
= swizzle_w
;
1082 static INLINE
struct ureg_dst
1083 ureg_dst_indirect( struct ureg_dst reg
, struct ureg_src addr
)
1085 assert(reg
.File
!= TGSI_FILE_NULL
);
1086 assert(addr
.File
== TGSI_FILE_ADDRESS
|| addr
.File
== TGSI_FILE_TEMPORARY
);
1088 reg
.IndirectFile
= addr
.File
;
1089 reg
.IndirectIndex
= addr
.Index
;
1090 reg
.IndirectSwizzle
= addr
.SwizzleX
;
1094 static INLINE
struct ureg_src
1095 ureg_src_indirect( struct ureg_src reg
, struct ureg_src addr
)
1097 assert(reg
.File
!= TGSI_FILE_NULL
);
1098 assert(addr
.File
== TGSI_FILE_ADDRESS
|| addr
.File
== TGSI_FILE_TEMPORARY
);
1100 reg
.IndirectFile
= addr
.File
;
1101 reg
.IndirectIndex
= addr
.Index
;
1102 reg
.IndirectSwizzle
= addr
.SwizzleX
;
1106 static INLINE
struct ureg_src
1107 ureg_src_dimension( struct ureg_src reg
, int index
)
1109 assert(reg
.File
!= TGSI_FILE_NULL
);
1111 reg
.DimIndirect
= 0;
1112 reg
.DimensionIndex
= index
;
1117 static INLINE
struct ureg_src
1118 ureg_src_dimension_indirect( struct ureg_src reg
, struct ureg_src addr
,
1121 assert(reg
.File
!= TGSI_FILE_NULL
);
1123 reg
.DimIndirect
= 1;
1124 reg
.DimensionIndex
= index
;
1125 reg
.DimIndFile
= addr
.File
;
1126 reg
.DimIndIndex
= addr
.Index
;
1127 reg
.DimIndSwizzle
= addr
.SwizzleX
;
1131 static INLINE
struct ureg_dst
1132 ureg_dst_array_offset( struct ureg_dst reg
, int offset
)
1134 assert(reg
.File
== TGSI_FILE_TEMPORARY
);
1135 reg
.Index
+= offset
;
1139 static INLINE
struct ureg_dst
1140 ureg_dst_register( unsigned file
,
1143 struct ureg_dst dst
;
1146 dst
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1148 dst
.IndirectFile
= TGSI_FILE_NULL
;
1149 dst
.IndirectIndex
= 0;
1150 dst
.IndirectSwizzle
= 0;
1154 dst
.PredSwizzleX
= TGSI_SWIZZLE_X
;
1155 dst
.PredSwizzleY
= TGSI_SWIZZLE_Y
;
1156 dst
.PredSwizzleZ
= TGSI_SWIZZLE_Z
;
1157 dst
.PredSwizzleW
= TGSI_SWIZZLE_W
;
1164 static INLINE
struct ureg_dst
1165 ureg_dst( struct ureg_src src
)
1167 struct ureg_dst dst
;
1169 assert(!src
.Indirect
||
1170 (src
.IndirectFile
== TGSI_FILE_ADDRESS
||
1171 src
.IndirectFile
== TGSI_FILE_TEMPORARY
));
1173 dst
.File
= src
.File
;
1174 dst
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1175 dst
.IndirectFile
= src
.IndirectFile
;
1176 dst
.Indirect
= src
.Indirect
;
1177 dst
.IndirectIndex
= src
.IndirectIndex
;
1178 dst
.IndirectSwizzle
= src
.IndirectSwizzle
;
1182 dst
.PredSwizzleX
= TGSI_SWIZZLE_X
;
1183 dst
.PredSwizzleY
= TGSI_SWIZZLE_Y
;
1184 dst
.PredSwizzleZ
= TGSI_SWIZZLE_Z
;
1185 dst
.PredSwizzleW
= TGSI_SWIZZLE_W
;
1186 dst
.Index
= src
.Index
;
1187 dst
.ArrayID
= src
.ArrayID
;
1192 static INLINE
struct ureg_src
1193 ureg_src_register(unsigned file
,
1196 struct ureg_src src
;
1199 src
.SwizzleX
= TGSI_SWIZZLE_X
;
1200 src
.SwizzleY
= TGSI_SWIZZLE_Y
;
1201 src
.SwizzleZ
= TGSI_SWIZZLE_Z
;
1202 src
.SwizzleW
= TGSI_SWIZZLE_W
;
1204 src
.IndirectFile
= TGSI_FILE_NULL
;
1205 src
.IndirectIndex
= 0;
1206 src
.IndirectSwizzle
= 0;
1211 src
.DimensionIndex
= 0;
1212 src
.DimIndirect
= 0;
1213 src
.DimIndFile
= TGSI_FILE_NULL
;
1214 src
.DimIndIndex
= 0;
1215 src
.DimIndSwizzle
= 0;
1221 static INLINE
struct ureg_src
1222 ureg_src( struct ureg_dst dst
)
1224 struct ureg_src src
;
1226 src
.File
= dst
.File
;
1227 src
.SwizzleX
= TGSI_SWIZZLE_X
;
1228 src
.SwizzleY
= TGSI_SWIZZLE_Y
;
1229 src
.SwizzleZ
= TGSI_SWIZZLE_Z
;
1230 src
.SwizzleW
= TGSI_SWIZZLE_W
;
1231 src
.Indirect
= dst
.Indirect
;
1232 src
.IndirectFile
= dst
.IndirectFile
;
1233 src
.IndirectIndex
= dst
.IndirectIndex
;
1234 src
.IndirectSwizzle
= dst
.IndirectSwizzle
;
1236 src
.Index
= dst
.Index
;
1239 src
.DimensionIndex
= 0;
1240 src
.DimIndirect
= 0;
1241 src
.DimIndFile
= TGSI_FILE_NULL
;
1242 src
.DimIndIndex
= 0;
1243 src
.DimIndSwizzle
= 0;
1244 src
.ArrayID
= dst
.ArrayID
;
1251 static INLINE
struct ureg_dst
1252 ureg_dst_undef( void )
1254 struct ureg_dst dst
;
1256 dst
.File
= TGSI_FILE_NULL
;
1259 dst
.IndirectFile
= TGSI_FILE_NULL
;
1260 dst
.IndirectIndex
= 0;
1261 dst
.IndirectSwizzle
= 0;
1265 dst
.PredSwizzleX
= TGSI_SWIZZLE_X
;
1266 dst
.PredSwizzleY
= TGSI_SWIZZLE_Y
;
1267 dst
.PredSwizzleZ
= TGSI_SWIZZLE_Z
;
1268 dst
.PredSwizzleW
= TGSI_SWIZZLE_W
;
1275 static INLINE
struct ureg_src
1276 ureg_src_undef( void )
1278 struct ureg_src src
;
1280 src
.File
= TGSI_FILE_NULL
;
1286 src
.IndirectFile
= TGSI_FILE_NULL
;
1287 src
.IndirectIndex
= 0;
1288 src
.IndirectSwizzle
= 0;
1293 src
.DimensionIndex
= 0;
1294 src
.DimIndirect
= 0;
1295 src
.DimIndFile
= TGSI_FILE_NULL
;
1296 src
.DimIndIndex
= 0;
1297 src
.DimIndSwizzle
= 0;
1303 static INLINE boolean
1304 ureg_src_is_undef( struct ureg_src src
)
1306 return src
.File
== TGSI_FILE_NULL
;
1309 static INLINE boolean
1310 ureg_dst_is_undef( struct ureg_dst dst
)
1312 return dst
.File
== TGSI_FILE_NULL
;