1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 **************************************************************************/
28 #include "util/u_debug.h"
29 #include "pipe/p_shader_tokens.h"
30 #include "tgsi_build.h"
31 #include "tgsi_parse.h"
39 tgsi_build_header( void )
41 struct tgsi_header header
;
43 header
.HeaderSize
= 1;
50 header_headersize_grow( struct tgsi_header
*header
)
52 assert( header
->HeaderSize
< 0xFF );
53 assert( header
->BodySize
== 0 );
59 header_bodysize_grow( struct tgsi_header
*header
)
61 assert( header
->BodySize
< 0xFFFFFF );
67 tgsi_default_processor( void )
69 struct tgsi_processor processor
;
71 processor
.Processor
= TGSI_PROCESSOR_FRAGMENT
;
72 processor
.Padding
= 0;
80 struct tgsi_header
*header
)
82 struct tgsi_processor processor
;
84 processor
= tgsi_default_processor();
85 processor
.Processor
= type
;
87 header_headersize_grow( header
);
96 struct tgsi_declaration
97 tgsi_default_declaration( void )
99 struct tgsi_declaration declaration
;
101 declaration
.Type
= TGSI_TOKEN_TYPE_DECLARATION
;
102 declaration
.NrTokens
= 1;
103 declaration
.File
= TGSI_FILE_NULL
;
104 declaration
.UsageMask
= TGSI_WRITEMASK_XYZW
;
105 declaration
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
106 declaration
.Dimension
= 0;
107 declaration
.Semantic
= 0;
108 declaration
.Centroid
= 0;
109 declaration
.Invariant
= 0;
110 declaration
.CylindricalWrap
= 0;
115 struct tgsi_declaration
116 tgsi_build_declaration(
119 unsigned interpolate
,
124 unsigned cylindrical_wrap
,
125 struct tgsi_header
*header
)
127 struct tgsi_declaration declaration
;
129 assert( file
< TGSI_FILE_COUNT
);
130 assert( interpolate
< TGSI_INTERPOLATE_COUNT
);
132 declaration
= tgsi_default_declaration();
133 declaration
.File
= file
;
134 declaration
.UsageMask
= usage_mask
;
135 declaration
.Interpolate
= interpolate
;
136 declaration
.Dimension
= dimension
;
137 declaration
.Semantic
= semantic
;
138 declaration
.Centroid
= centroid
;
139 declaration
.Invariant
= invariant
;
140 declaration
.CylindricalWrap
= cylindrical_wrap
;
142 header_bodysize_grow( header
);
149 struct tgsi_declaration
*declaration
,
150 struct tgsi_header
*header
)
152 assert( declaration
->NrTokens
< 0xFF );
154 declaration
->NrTokens
++;
156 header_bodysize_grow( header
);
159 struct tgsi_full_declaration
160 tgsi_default_full_declaration( void )
162 struct tgsi_full_declaration full_declaration
;
164 full_declaration
.Declaration
= tgsi_default_declaration();
165 full_declaration
.Range
= tgsi_default_declaration_range();
166 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
167 full_declaration
.ImmediateData
.u
= NULL
;
169 return full_declaration
;
173 tgsi_build_full_declaration(
174 const struct tgsi_full_declaration
*full_decl
,
175 struct tgsi_token
*tokens
,
176 struct tgsi_header
*header
,
180 struct tgsi_declaration
*declaration
;
181 struct tgsi_declaration_range
*dr
;
183 if( maxsize
<= size
)
185 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
188 *declaration
= tgsi_build_declaration(
189 full_decl
->Declaration
.File
,
190 full_decl
->Declaration
.UsageMask
,
191 full_decl
->Declaration
.Interpolate
,
192 full_decl
->Declaration
.Dimension
,
193 full_decl
->Declaration
.Semantic
,
194 full_decl
->Declaration
.Centroid
,
195 full_decl
->Declaration
.Invariant
,
196 full_decl
->Declaration
.CylindricalWrap
,
201 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
204 *dr
= tgsi_build_declaration_range(
205 full_decl
->Range
.First
,
206 full_decl
->Range
.Last
,
210 if (full_decl
->Declaration
.Dimension
) {
211 struct tgsi_declaration_dimension
*dd
;
213 if (maxsize
<= size
) {
216 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
219 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
224 if( full_decl
->Declaration
.Semantic
) {
225 struct tgsi_declaration_semantic
*ds
;
227 if( maxsize
<= size
)
229 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
232 *ds
= tgsi_build_declaration_semantic(
233 full_decl
->Semantic
.Name
,
234 full_decl
->Semantic
.Index
,
239 if (full_decl
->Declaration
.File
== TGSI_FILE_IMMEDIATE_ARRAY
) {
241 union tgsi_immediate_data
*data
;
243 for (i
= 0; i
<= dr
->Last
; ++i
) {
244 for (j
= 0; j
< 4; ++j
) {
245 unsigned idx
= i
*4 + j
;
248 data
= (union tgsi_immediate_data
*) &tokens
[size
];
251 *data
= full_decl
->ImmediateData
.u
[idx
];
252 declaration_grow( declaration
, header
);
260 struct tgsi_declaration_range
261 tgsi_default_declaration_range( void )
263 struct tgsi_declaration_range dr
;
271 struct tgsi_declaration_range
272 tgsi_build_declaration_range(
275 struct tgsi_declaration
*declaration
,
276 struct tgsi_header
*header
)
278 struct tgsi_declaration_range declaration_range
;
280 assert( last
>= first
);
281 assert( last
<= 0xFFFF );
283 declaration_range
= tgsi_default_declaration_range();
284 declaration_range
.First
= first
;
285 declaration_range
.Last
= last
;
287 declaration_grow( declaration
, header
);
289 return declaration_range
;
292 struct tgsi_declaration_dimension
293 tgsi_default_declaration_dimension(void)
295 struct tgsi_declaration_dimension dd
;
303 struct tgsi_declaration_dimension
304 tgsi_build_declaration_dimension(unsigned index_2d
,
305 struct tgsi_declaration
*declaration
,
306 struct tgsi_header
*header
)
308 struct tgsi_declaration_dimension dd
;
310 assert(index_2d
<= 0xFFFF);
312 dd
= tgsi_default_declaration_dimension();
313 dd
.Index2D
= index_2d
;
315 declaration_grow(declaration
, header
);
320 struct tgsi_declaration_semantic
321 tgsi_default_declaration_semantic( void )
323 struct tgsi_declaration_semantic ds
;
325 ds
.Name
= TGSI_SEMANTIC_POSITION
;
332 struct tgsi_declaration_semantic
333 tgsi_build_declaration_semantic(
334 unsigned semantic_name
,
335 unsigned semantic_index
,
336 struct tgsi_declaration
*declaration
,
337 struct tgsi_header
*header
)
339 struct tgsi_declaration_semantic ds
;
341 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
342 assert( semantic_index
<= 0xFFFF );
344 ds
= tgsi_default_declaration_semantic();
345 ds
.Name
= semantic_name
;
346 ds
.Index
= semantic_index
;
348 declaration_grow( declaration
, header
);
357 struct tgsi_immediate
358 tgsi_default_immediate( void )
360 struct tgsi_immediate immediate
;
362 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
363 immediate
.NrTokens
= 1;
364 immediate
.DataType
= TGSI_IMM_FLOAT32
;
365 immediate
.Padding
= 0;
370 struct tgsi_immediate
371 tgsi_build_immediate(
372 struct tgsi_header
*header
)
374 struct tgsi_immediate immediate
;
376 immediate
= tgsi_default_immediate();
378 header_bodysize_grow( header
);
383 struct tgsi_full_immediate
384 tgsi_default_full_immediate( void )
386 struct tgsi_full_immediate fullimm
;
388 fullimm
.Immediate
= tgsi_default_immediate();
389 fullimm
.u
[0].Float
= 0.0f
;
390 fullimm
.u
[1].Float
= 0.0f
;
391 fullimm
.u
[2].Float
= 0.0f
;
392 fullimm
.u
[3].Float
= 0.0f
;
399 struct tgsi_immediate
*immediate
,
400 struct tgsi_header
*header
)
402 assert( immediate
->NrTokens
< 0xFF );
404 immediate
->NrTokens
++;
406 header_bodysize_grow( header
);
409 union tgsi_immediate_data
410 tgsi_build_immediate_float32(
412 struct tgsi_immediate
*immediate
,
413 struct tgsi_header
*header
)
415 union tgsi_immediate_data immediate_data
;
417 immediate_data
.Float
= value
;
419 immediate_grow( immediate
, header
);
421 return immediate_data
;
425 tgsi_build_full_immediate(
426 const struct tgsi_full_immediate
*full_imm
,
427 struct tgsi_token
*tokens
,
428 struct tgsi_header
*header
,
431 unsigned size
= 0, i
;
432 struct tgsi_immediate
*immediate
;
434 if( maxsize
<= size
)
436 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
439 *immediate
= tgsi_build_immediate( header
);
441 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
443 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
444 union tgsi_immediate_data
*data
;
446 if( maxsize
<= size
)
448 data
= (union tgsi_immediate_data
*) &tokens
[size
];
451 *data
= tgsi_build_immediate_float32(
452 full_imm
->u
[i
].Float
,
464 struct tgsi_instruction
465 tgsi_default_instruction( void )
467 struct tgsi_instruction instruction
;
469 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
470 instruction
.NrTokens
= 0;
471 instruction
.Opcode
= TGSI_OPCODE_MOV
;
472 instruction
.Saturate
= TGSI_SAT_NONE
;
473 instruction
.Predicate
= 0;
474 instruction
.NumDstRegs
= 1;
475 instruction
.NumSrcRegs
= 1;
476 instruction
.Label
= 0;
477 instruction
.Texture
= 0;
478 instruction
.Padding
= 0;
483 struct tgsi_instruction
484 tgsi_build_instruction(unsigned opcode
,
487 unsigned num_dst_regs
,
488 unsigned num_src_regs
,
489 struct tgsi_header
*header
)
491 struct tgsi_instruction instruction
;
493 assert (opcode
<= TGSI_OPCODE_LAST
);
494 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
495 assert (num_dst_regs
<= 3);
496 assert (num_src_regs
<= 15);
498 instruction
= tgsi_default_instruction();
499 instruction
.Opcode
= opcode
;
500 instruction
.Saturate
= saturate
;
501 instruction
.Predicate
= predicate
;
502 instruction
.NumDstRegs
= num_dst_regs
;
503 instruction
.NumSrcRegs
= num_src_regs
;
505 header_bodysize_grow( header
);
512 struct tgsi_instruction
*instruction
,
513 struct tgsi_header
*header
)
515 assert (instruction
->NrTokens
< 0xFF);
517 instruction
->NrTokens
++;
519 header_bodysize_grow( header
);
522 struct tgsi_full_instruction
523 tgsi_default_full_instruction( void )
525 struct tgsi_full_instruction full_instruction
;
528 full_instruction
.Instruction
= tgsi_default_instruction();
529 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
530 full_instruction
.Label
= tgsi_default_instruction_label();
531 full_instruction
.Texture
= tgsi_default_instruction_texture();
532 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
533 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
535 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
536 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
539 return full_instruction
;
543 tgsi_build_full_instruction(
544 const struct tgsi_full_instruction
*full_inst
,
545 struct tgsi_token
*tokens
,
546 struct tgsi_header
*header
,
551 struct tgsi_instruction
*instruction
;
552 struct tgsi_token
*prev_token
;
554 if( maxsize
<= size
)
556 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
559 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
560 full_inst
->Instruction
.Saturate
,
561 full_inst
->Instruction
.Predicate
,
562 full_inst
->Instruction
.NumDstRegs
,
563 full_inst
->Instruction
.NumSrcRegs
,
565 prev_token
= (struct tgsi_token
*) instruction
;
567 if (full_inst
->Instruction
.Predicate
) {
568 struct tgsi_instruction_predicate
*instruction_predicate
;
570 if (maxsize
<= size
) {
573 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
576 *instruction_predicate
=
577 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
578 full_inst
->Predicate
.Negate
,
579 full_inst
->Predicate
.SwizzleX
,
580 full_inst
->Predicate
.SwizzleY
,
581 full_inst
->Predicate
.SwizzleZ
,
582 full_inst
->Predicate
.SwizzleW
,
587 if (full_inst
->Instruction
.Label
) {
588 struct tgsi_instruction_label
*instruction_label
;
590 if( maxsize
<= size
)
593 (struct tgsi_instruction_label
*) &tokens
[size
];
596 *instruction_label
= tgsi_build_instruction_label(
597 full_inst
->Label
.Label
,
601 prev_token
= (struct tgsi_token
*) instruction_label
;
604 if (full_inst
->Instruction
.Texture
) {
605 struct tgsi_instruction_texture
*instruction_texture
;
607 if( maxsize
<= size
)
609 instruction_texture
=
610 (struct tgsi_instruction_texture
*) &tokens
[size
];
613 *instruction_texture
= tgsi_build_instruction_texture(
614 full_inst
->Texture
.Texture
,
618 prev_token
= (struct tgsi_token
*) instruction_texture
;
621 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
622 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
623 struct tgsi_dst_register
*dst_register
;
624 struct tgsi_token
*prev_token
;
626 if( maxsize
<= size
)
628 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
631 *dst_register
= tgsi_build_dst_register(
633 reg
->Register
.WriteMask
,
634 reg
->Register
.Indirect
,
635 reg
->Register
.Dimension
,
639 prev_token
= (struct tgsi_token
*) dst_register
;
641 if( reg
->Register
.Indirect
) {
642 struct tgsi_src_register
*ind
;
644 if( maxsize
<= size
)
646 ind
= (struct tgsi_src_register
*) &tokens
[size
];
649 *ind
= tgsi_build_src_register(
651 reg
->Indirect
.SwizzleX
,
652 reg
->Indirect
.SwizzleY
,
653 reg
->Indirect
.SwizzleZ
,
654 reg
->Indirect
.SwizzleW
,
655 reg
->Indirect
.Negate
,
656 reg
->Indirect
.Absolute
,
657 reg
->Indirect
.Indirect
,
658 reg
->Indirect
.Dimension
,
664 if( reg
->Register
.Dimension
) {
665 struct tgsi_dimension
*dim
;
667 assert( !reg
->Dimension
.Dimension
);
669 if( maxsize
<= size
)
671 dim
= (struct tgsi_dimension
*) &tokens
[size
];
674 *dim
= tgsi_build_dimension(
675 reg
->Dimension
.Indirect
,
676 reg
->Dimension
.Index
,
680 if( reg
->Dimension
.Indirect
) {
681 struct tgsi_src_register
*ind
;
683 if( maxsize
<= size
)
685 ind
= (struct tgsi_src_register
*) &tokens
[size
];
688 *ind
= tgsi_build_src_register(
689 reg
->DimIndirect
.File
,
690 reg
->DimIndirect
.SwizzleX
,
691 reg
->DimIndirect
.SwizzleY
,
692 reg
->DimIndirect
.SwizzleZ
,
693 reg
->DimIndirect
.SwizzleW
,
694 reg
->DimIndirect
.Negate
,
695 reg
->DimIndirect
.Absolute
,
696 reg
->DimIndirect
.Indirect
,
697 reg
->DimIndirect
.Dimension
,
698 reg
->DimIndirect
.Index
,
705 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
706 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
707 struct tgsi_src_register
*src_register
;
708 struct tgsi_token
*prev_token
;
710 if( maxsize
<= size
)
712 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
715 *src_register
= tgsi_build_src_register(
717 reg
->Register
.SwizzleX
,
718 reg
->Register
.SwizzleY
,
719 reg
->Register
.SwizzleZ
,
720 reg
->Register
.SwizzleW
,
721 reg
->Register
.Negate
,
722 reg
->Register
.Absolute
,
723 reg
->Register
.Indirect
,
724 reg
->Register
.Dimension
,
728 prev_token
= (struct tgsi_token
*) src_register
;
730 if( reg
->Register
.Indirect
) {
731 struct tgsi_src_register
*ind
;
733 if( maxsize
<= size
)
735 ind
= (struct tgsi_src_register
*) &tokens
[size
];
738 *ind
= tgsi_build_src_register(
740 reg
->Indirect
.SwizzleX
,
741 reg
->Indirect
.SwizzleY
,
742 reg
->Indirect
.SwizzleZ
,
743 reg
->Indirect
.SwizzleW
,
744 reg
->Indirect
.Negate
,
745 reg
->Indirect
.Absolute
,
746 reg
->Indirect
.Indirect
,
747 reg
->Indirect
.Dimension
,
753 if( reg
->Register
.Dimension
) {
754 struct tgsi_dimension
*dim
;
756 assert( !reg
->Dimension
.Dimension
);
758 if( maxsize
<= size
)
760 dim
= (struct tgsi_dimension
*) &tokens
[size
];
763 *dim
= tgsi_build_dimension(
764 reg
->Dimension
.Indirect
,
765 reg
->Dimension
.Index
,
769 if( reg
->Dimension
.Indirect
) {
770 struct tgsi_src_register
*ind
;
772 if( maxsize
<= size
)
774 ind
= (struct tgsi_src_register
*) &tokens
[size
];
777 *ind
= tgsi_build_src_register(
778 reg
->DimIndirect
.File
,
779 reg
->DimIndirect
.SwizzleX
,
780 reg
->DimIndirect
.SwizzleY
,
781 reg
->DimIndirect
.SwizzleZ
,
782 reg
->DimIndirect
.SwizzleW
,
783 reg
->DimIndirect
.Negate
,
784 reg
->DimIndirect
.Absolute
,
785 reg
->DimIndirect
.Indirect
,
786 reg
->DimIndirect
.Dimension
,
787 reg
->DimIndirect
.Index
,
797 struct tgsi_instruction_predicate
798 tgsi_default_instruction_predicate(void)
800 struct tgsi_instruction_predicate instruction_predicate
;
802 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
803 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
804 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
805 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
806 instruction_predicate
.Negate
= 0;
807 instruction_predicate
.Index
= 0;
808 instruction_predicate
.Padding
= 0;
810 return instruction_predicate
;
813 struct tgsi_instruction_predicate
814 tgsi_build_instruction_predicate(int index
,
820 struct tgsi_instruction
*instruction
,
821 struct tgsi_header
*header
)
823 struct tgsi_instruction_predicate instruction_predicate
;
825 instruction_predicate
= tgsi_default_instruction_predicate();
826 instruction_predicate
.SwizzleX
= swizzleX
;
827 instruction_predicate
.SwizzleY
= swizzleY
;
828 instruction_predicate
.SwizzleZ
= swizzleZ
;
829 instruction_predicate
.SwizzleW
= swizzleW
;
830 instruction_predicate
.Negate
= negate
;
831 instruction_predicate
.Index
= index
;
833 instruction_grow(instruction
, header
);
835 return instruction_predicate
;
838 struct tgsi_instruction_label
839 tgsi_default_instruction_label( void )
841 struct tgsi_instruction_label instruction_label
;
843 instruction_label
.Label
= 0;
844 instruction_label
.Padding
= 0;
846 return instruction_label
;
849 struct tgsi_instruction_label
850 tgsi_build_instruction_label(
852 struct tgsi_token
*prev_token
,
853 struct tgsi_instruction
*instruction
,
854 struct tgsi_header
*header
)
856 struct tgsi_instruction_label instruction_label
;
858 instruction_label
= tgsi_default_instruction_label();
859 instruction_label
.Label
= label
;
860 instruction
->Label
= 1;
862 instruction_grow( instruction
, header
);
864 return instruction_label
;
867 struct tgsi_instruction_texture
868 tgsi_default_instruction_texture( void )
870 struct tgsi_instruction_texture instruction_texture
;
872 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
873 instruction_texture
.Padding
= 0;
875 return instruction_texture
;
878 struct tgsi_instruction_texture
879 tgsi_build_instruction_texture(
881 struct tgsi_token
*prev_token
,
882 struct tgsi_instruction
*instruction
,
883 struct tgsi_header
*header
)
885 struct tgsi_instruction_texture instruction_texture
;
887 instruction_texture
= tgsi_default_instruction_texture();
888 instruction_texture
.Texture
= texture
;
889 instruction
->Texture
= 1;
891 instruction_grow( instruction
, header
);
893 return instruction_texture
;
896 struct tgsi_src_register
897 tgsi_default_src_register( void )
899 struct tgsi_src_register src_register
;
901 src_register
.File
= TGSI_FILE_NULL
;
902 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
903 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
904 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
905 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
906 src_register
.Negate
= 0;
907 src_register
.Absolute
= 0;
908 src_register
.Indirect
= 0;
909 src_register
.Dimension
= 0;
910 src_register
.Index
= 0;
915 struct tgsi_src_register
916 tgsi_build_src_register(
927 struct tgsi_instruction
*instruction
,
928 struct tgsi_header
*header
)
930 struct tgsi_src_register src_register
;
932 assert( file
< TGSI_FILE_COUNT
);
933 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
934 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
935 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
936 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
937 assert( negate
<= 1 );
938 assert( index
>= -0x8000 && index
<= 0x7FFF );
940 src_register
= tgsi_default_src_register();
941 src_register
.File
= file
;
942 src_register
.SwizzleX
= swizzle_x
;
943 src_register
.SwizzleY
= swizzle_y
;
944 src_register
.SwizzleZ
= swizzle_z
;
945 src_register
.SwizzleW
= swizzle_w
;
946 src_register
.Negate
= negate
;
947 src_register
.Absolute
= absolute
;
948 src_register
.Indirect
= indirect
;
949 src_register
.Dimension
= dimension
;
950 src_register
.Index
= index
;
952 instruction_grow( instruction
, header
);
957 struct tgsi_full_src_register
958 tgsi_default_full_src_register( void )
960 struct tgsi_full_src_register full_src_register
;
962 full_src_register
.Register
= tgsi_default_src_register();
963 full_src_register
.Indirect
= tgsi_default_src_register();
964 full_src_register
.Dimension
= tgsi_default_dimension();
965 full_src_register
.DimIndirect
= tgsi_default_src_register();
967 return full_src_register
;
971 struct tgsi_dimension
972 tgsi_default_dimension( void )
974 struct tgsi_dimension dimension
;
976 dimension
.Indirect
= 0;
977 dimension
.Dimension
= 0;
978 dimension
.Padding
= 0;
984 struct tgsi_dimension
985 tgsi_build_dimension(
988 struct tgsi_instruction
*instruction
,
989 struct tgsi_header
*header
)
991 struct tgsi_dimension dimension
;
993 dimension
= tgsi_default_dimension();
994 dimension
.Indirect
= indirect
;
995 dimension
.Index
= index
;
997 instruction_grow( instruction
, header
);
1002 struct tgsi_dst_register
1003 tgsi_default_dst_register( void )
1005 struct tgsi_dst_register dst_register
;
1007 dst_register
.File
= TGSI_FILE_NULL
;
1008 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1009 dst_register
.Indirect
= 0;
1010 dst_register
.Dimension
= 0;
1011 dst_register
.Index
= 0;
1012 dst_register
.Padding
= 0;
1014 return dst_register
;
1017 struct tgsi_dst_register
1018 tgsi_build_dst_register(
1024 struct tgsi_instruction
*instruction
,
1025 struct tgsi_header
*header
)
1027 struct tgsi_dst_register dst_register
;
1029 assert( file
< TGSI_FILE_COUNT
);
1030 assert( mask
<= TGSI_WRITEMASK_XYZW
);
1031 assert( index
>= -32768 && index
<= 32767 );
1033 dst_register
= tgsi_default_dst_register();
1034 dst_register
.File
= file
;
1035 dst_register
.WriteMask
= mask
;
1036 dst_register
.Index
= index
;
1037 dst_register
.Indirect
= indirect
;
1038 dst_register
.Dimension
= dimension
;
1040 instruction_grow( instruction
, header
);
1042 return dst_register
;
1045 struct tgsi_full_dst_register
1046 tgsi_default_full_dst_register( void )
1048 struct tgsi_full_dst_register full_dst_register
;
1050 full_dst_register
.Register
= tgsi_default_dst_register();
1051 full_dst_register
.Indirect
= tgsi_default_src_register();
1052 full_dst_register
.Dimension
= tgsi_default_dimension();
1053 full_dst_register
.DimIndirect
= tgsi_default_src_register();
1055 return full_dst_register
;
1058 struct tgsi_property
1059 tgsi_default_property( void )
1061 struct tgsi_property property
;
1063 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1064 property
.NrTokens
= 1;
1065 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1066 property
.Padding
= 0;
1071 struct tgsi_property
1072 tgsi_build_property(unsigned property_name
,
1073 struct tgsi_header
*header
)
1075 struct tgsi_property property
;
1077 property
= tgsi_default_property();
1078 property
.PropertyName
= property_name
;
1080 header_bodysize_grow( header
);
1086 struct tgsi_full_property
1087 tgsi_default_full_property( void )
1089 struct tgsi_full_property full_property
;
1091 full_property
.Property
= tgsi_default_property();
1092 memset(full_property
.u
, 0,
1093 sizeof(struct tgsi_property_data
) * 8);
1095 return full_property
;
1100 struct tgsi_property
*property
,
1101 struct tgsi_header
*header
)
1103 assert( property
->NrTokens
< 0xFF );
1105 property
->NrTokens
++;
1107 header_bodysize_grow( header
);
1110 struct tgsi_property_data
1111 tgsi_build_property_data(
1113 struct tgsi_property
*property
,
1114 struct tgsi_header
*header
)
1116 struct tgsi_property_data property_data
;
1118 property_data
.Data
= value
;
1120 property_grow( property
, header
);
1122 return property_data
;
1126 tgsi_build_full_property(
1127 const struct tgsi_full_property
*full_prop
,
1128 struct tgsi_token
*tokens
,
1129 struct tgsi_header
*header
,
1132 unsigned size
= 0, i
;
1133 struct tgsi_property
*property
;
1135 if( maxsize
<= size
)
1137 property
= (struct tgsi_property
*) &tokens
[size
];
1140 *property
= tgsi_build_property(
1141 full_prop
->Property
.PropertyName
,
1144 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1146 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1147 struct tgsi_property_data
*data
;
1149 if( maxsize
<= size
)
1151 data
= (struct tgsi_property_data
*) &tokens
[size
];
1154 *data
= tgsi_build_property_data(
1155 full_prop
->u
[i
].Data
,