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
.Padding
= 0;
115 struct tgsi_declaration
116 tgsi_build_declaration(
119 unsigned interpolate
,
124 struct tgsi_header
*header
)
126 struct tgsi_declaration declaration
;
128 assert( file
< TGSI_FILE_COUNT
);
129 assert( interpolate
< TGSI_INTERPOLATE_COUNT
);
131 declaration
= tgsi_default_declaration();
132 declaration
.File
= file
;
133 declaration
.UsageMask
= usage_mask
;
134 declaration
.Interpolate
= interpolate
;
135 declaration
.Dimension
= dimension
;
136 declaration
.Semantic
= semantic
;
137 declaration
.Centroid
= centroid
;
138 declaration
.Invariant
= invariant
;
140 header_bodysize_grow( header
);
147 struct tgsi_declaration
*declaration
,
148 struct tgsi_header
*header
)
150 assert( declaration
->NrTokens
< 0xFF );
152 declaration
->NrTokens
++;
154 header_bodysize_grow( header
);
157 struct tgsi_full_declaration
158 tgsi_default_full_declaration( void )
160 struct tgsi_full_declaration full_declaration
;
162 full_declaration
.Declaration
= tgsi_default_declaration();
163 full_declaration
.Range
= tgsi_default_declaration_range();
164 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
166 return full_declaration
;
170 tgsi_build_full_declaration(
171 const struct tgsi_full_declaration
*full_decl
,
172 struct tgsi_token
*tokens
,
173 struct tgsi_header
*header
,
177 struct tgsi_declaration
*declaration
;
178 struct tgsi_declaration_range
*dr
;
180 if( maxsize
<= size
)
182 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
185 *declaration
= tgsi_build_declaration(
186 full_decl
->Declaration
.File
,
187 full_decl
->Declaration
.UsageMask
,
188 full_decl
->Declaration
.Interpolate
,
189 full_decl
->Declaration
.Dimension
,
190 full_decl
->Declaration
.Semantic
,
191 full_decl
->Declaration
.Centroid
,
192 full_decl
->Declaration
.Invariant
,
197 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
200 *dr
= tgsi_build_declaration_range(
201 full_decl
->Range
.First
,
202 full_decl
->Range
.Last
,
206 if (full_decl
->Declaration
.Dimension
) {
207 struct tgsi_declaration_dimension
*dd
;
209 if (maxsize
<= size
) {
212 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
215 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
220 if( full_decl
->Declaration
.Semantic
) {
221 struct tgsi_declaration_semantic
*ds
;
223 if( maxsize
<= size
)
225 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
228 *ds
= tgsi_build_declaration_semantic(
229 full_decl
->Semantic
.Name
,
230 full_decl
->Semantic
.Index
,
238 struct tgsi_declaration_range
239 tgsi_default_declaration_range( void )
241 struct tgsi_declaration_range dr
;
249 struct tgsi_declaration_range
250 tgsi_build_declaration_range(
253 struct tgsi_declaration
*declaration
,
254 struct tgsi_header
*header
)
256 struct tgsi_declaration_range declaration_range
;
258 assert( last
>= first
);
259 assert( last
<= 0xFFFF );
261 declaration_range
= tgsi_default_declaration_range();
262 declaration_range
.First
= first
;
263 declaration_range
.Last
= last
;
265 declaration_grow( declaration
, header
);
267 return declaration_range
;
270 struct tgsi_declaration_dimension
271 tgsi_default_declaration_dimension(void)
273 struct tgsi_declaration_dimension dd
;
281 struct tgsi_declaration_dimension
282 tgsi_build_declaration_dimension(unsigned index_2d
,
283 struct tgsi_declaration
*declaration
,
284 struct tgsi_header
*header
)
286 struct tgsi_declaration_dimension dd
;
288 assert(index_2d
<= 0xFFFF);
290 dd
= tgsi_default_declaration_dimension();
291 dd
.Index2D
= index_2d
;
293 declaration_grow(declaration
, header
);
298 struct tgsi_declaration_semantic
299 tgsi_default_declaration_semantic( void )
301 struct tgsi_declaration_semantic ds
;
303 ds
.Name
= TGSI_SEMANTIC_POSITION
;
310 struct tgsi_declaration_semantic
311 tgsi_build_declaration_semantic(
312 unsigned semantic_name
,
313 unsigned semantic_index
,
314 struct tgsi_declaration
*declaration
,
315 struct tgsi_header
*header
)
317 struct tgsi_declaration_semantic ds
;
319 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
320 assert( semantic_index
<= 0xFFFF );
322 ds
= tgsi_default_declaration_semantic();
323 ds
.Name
= semantic_name
;
324 ds
.Index
= semantic_index
;
326 declaration_grow( declaration
, header
);
335 struct tgsi_immediate
336 tgsi_default_immediate( void )
338 struct tgsi_immediate immediate
;
340 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
341 immediate
.NrTokens
= 1;
342 immediate
.DataType
= TGSI_IMM_FLOAT32
;
343 immediate
.Padding
= 0;
348 struct tgsi_immediate
349 tgsi_build_immediate(
350 struct tgsi_header
*header
)
352 struct tgsi_immediate immediate
;
354 immediate
= tgsi_default_immediate();
356 header_bodysize_grow( header
);
361 struct tgsi_full_immediate
362 tgsi_default_full_immediate( void )
364 struct tgsi_full_immediate fullimm
;
366 fullimm
.Immediate
= tgsi_default_immediate();
367 fullimm
.u
[0].Float
= 0.0f
;
368 fullimm
.u
[1].Float
= 0.0f
;
369 fullimm
.u
[2].Float
= 0.0f
;
370 fullimm
.u
[3].Float
= 0.0f
;
377 struct tgsi_immediate
*immediate
,
378 struct tgsi_header
*header
)
380 assert( immediate
->NrTokens
< 0xFF );
382 immediate
->NrTokens
++;
384 header_bodysize_grow( header
);
387 union tgsi_immediate_data
388 tgsi_build_immediate_float32(
390 struct tgsi_immediate
*immediate
,
391 struct tgsi_header
*header
)
393 union tgsi_immediate_data immediate_data
;
395 immediate_data
.Float
= value
;
397 immediate_grow( immediate
, header
);
399 return immediate_data
;
403 tgsi_build_full_immediate(
404 const struct tgsi_full_immediate
*full_imm
,
405 struct tgsi_token
*tokens
,
406 struct tgsi_header
*header
,
409 unsigned size
= 0, i
;
410 struct tgsi_immediate
*immediate
;
412 if( maxsize
<= size
)
414 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
417 *immediate
= tgsi_build_immediate( header
);
419 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
421 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
422 union tgsi_immediate_data
*data
;
424 if( maxsize
<= size
)
426 data
= (union tgsi_immediate_data
*) &tokens
[size
];
429 *data
= tgsi_build_immediate_float32(
430 full_imm
->u
[i
].Float
,
442 struct tgsi_instruction
443 tgsi_default_instruction( void )
445 struct tgsi_instruction instruction
;
447 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
448 instruction
.NrTokens
= 0;
449 instruction
.Opcode
= TGSI_OPCODE_MOV
;
450 instruction
.Saturate
= TGSI_SAT_NONE
;
451 instruction
.Predicate
= 0;
452 instruction
.NumDstRegs
= 1;
453 instruction
.NumSrcRegs
= 1;
454 instruction
.Label
= 0;
455 instruction
.Texture
= 0;
456 instruction
.Padding
= 0;
461 struct tgsi_instruction
462 tgsi_build_instruction(unsigned opcode
,
465 unsigned num_dst_regs
,
466 unsigned num_src_regs
,
467 struct tgsi_header
*header
)
469 struct tgsi_instruction instruction
;
471 assert (opcode
<= TGSI_OPCODE_LAST
);
472 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
473 assert (num_dst_regs
<= 3);
474 assert (num_src_regs
<= 15);
476 instruction
= tgsi_default_instruction();
477 instruction
.Opcode
= opcode
;
478 instruction
.Saturate
= saturate
;
479 instruction
.Predicate
= predicate
;
480 instruction
.NumDstRegs
= num_dst_regs
;
481 instruction
.NumSrcRegs
= num_src_regs
;
483 header_bodysize_grow( header
);
490 struct tgsi_instruction
*instruction
,
491 struct tgsi_header
*header
)
493 assert (instruction
->NrTokens
< 0xFF);
495 instruction
->NrTokens
++;
497 header_bodysize_grow( header
);
500 struct tgsi_full_instruction
501 tgsi_default_full_instruction( void )
503 struct tgsi_full_instruction full_instruction
;
506 full_instruction
.Instruction
= tgsi_default_instruction();
507 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
508 full_instruction
.Label
= tgsi_default_instruction_label();
509 full_instruction
.Texture
= tgsi_default_instruction_texture();
510 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
511 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
513 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
514 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
517 return full_instruction
;
521 tgsi_build_full_instruction(
522 const struct tgsi_full_instruction
*full_inst
,
523 struct tgsi_token
*tokens
,
524 struct tgsi_header
*header
,
529 struct tgsi_instruction
*instruction
;
530 struct tgsi_token
*prev_token
;
532 if( maxsize
<= size
)
534 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
537 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
538 full_inst
->Instruction
.Saturate
,
539 full_inst
->Instruction
.Predicate
,
540 full_inst
->Instruction
.NumDstRegs
,
541 full_inst
->Instruction
.NumSrcRegs
,
543 prev_token
= (struct tgsi_token
*) instruction
;
545 if (full_inst
->Instruction
.Predicate
) {
546 struct tgsi_instruction_predicate
*instruction_predicate
;
548 if (maxsize
<= size
) {
551 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
554 *instruction_predicate
=
555 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
556 full_inst
->Predicate
.Negate
,
557 full_inst
->Predicate
.SwizzleX
,
558 full_inst
->Predicate
.SwizzleY
,
559 full_inst
->Predicate
.SwizzleZ
,
560 full_inst
->Predicate
.SwizzleW
,
565 if (full_inst
->Instruction
.Label
) {
566 struct tgsi_instruction_label
*instruction_label
;
568 if( maxsize
<= size
)
571 (struct tgsi_instruction_label
*) &tokens
[size
];
574 *instruction_label
= tgsi_build_instruction_label(
575 full_inst
->Label
.Label
,
579 prev_token
= (struct tgsi_token
*) instruction_label
;
582 if (full_inst
->Instruction
.Texture
) {
583 struct tgsi_instruction_texture
*instruction_texture
;
585 if( maxsize
<= size
)
587 instruction_texture
=
588 (struct tgsi_instruction_texture
*) &tokens
[size
];
591 *instruction_texture
= tgsi_build_instruction_texture(
592 full_inst
->Texture
.Texture
,
596 prev_token
= (struct tgsi_token
*) instruction_texture
;
599 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
600 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
601 struct tgsi_dst_register
*dst_register
;
602 struct tgsi_token
*prev_token
;
604 if( maxsize
<= size
)
606 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
609 *dst_register
= tgsi_build_dst_register(
611 reg
->Register
.WriteMask
,
612 reg
->Register
.Indirect
,
616 prev_token
= (struct tgsi_token
*) dst_register
;
618 if( reg
->Register
.Indirect
) {
619 struct tgsi_src_register
*ind
;
621 if( maxsize
<= size
)
623 ind
= (struct tgsi_src_register
*) &tokens
[size
];
626 *ind
= tgsi_build_src_register(
628 reg
->Indirect
.SwizzleX
,
629 reg
->Indirect
.SwizzleY
,
630 reg
->Indirect
.SwizzleZ
,
631 reg
->Indirect
.SwizzleW
,
632 reg
->Indirect
.Negate
,
633 reg
->Indirect
.Absolute
,
634 reg
->Indirect
.Indirect
,
635 reg
->Indirect
.Dimension
,
642 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
643 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
644 struct tgsi_src_register
*src_register
;
645 struct tgsi_token
*prev_token
;
647 if( maxsize
<= size
)
649 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
652 *src_register
= tgsi_build_src_register(
654 reg
->Register
.SwizzleX
,
655 reg
->Register
.SwizzleY
,
656 reg
->Register
.SwizzleZ
,
657 reg
->Register
.SwizzleW
,
658 reg
->Register
.Negate
,
659 reg
->Register
.Absolute
,
660 reg
->Register
.Indirect
,
661 reg
->Register
.Dimension
,
665 prev_token
= (struct tgsi_token
*) src_register
;
667 if( reg
->Register
.Indirect
) {
668 struct tgsi_src_register
*ind
;
670 if( maxsize
<= size
)
672 ind
= (struct tgsi_src_register
*) &tokens
[size
];
675 *ind
= tgsi_build_src_register(
677 reg
->Indirect
.SwizzleX
,
678 reg
->Indirect
.SwizzleY
,
679 reg
->Indirect
.SwizzleZ
,
680 reg
->Indirect
.SwizzleW
,
681 reg
->Indirect
.Negate
,
682 reg
->Indirect
.Absolute
,
683 reg
->Indirect
.Indirect
,
684 reg
->Indirect
.Dimension
,
690 if( reg
->Register
.Dimension
) {
691 struct tgsi_dimension
*dim
;
693 assert( !reg
->Dimension
.Dimension
);
695 if( maxsize
<= size
)
697 dim
= (struct tgsi_dimension
*) &tokens
[size
];
700 *dim
= tgsi_build_dimension(
701 reg
->Dimension
.Indirect
,
702 reg
->Dimension
.Index
,
706 if( reg
->Dimension
.Indirect
) {
707 struct tgsi_src_register
*ind
;
709 if( maxsize
<= size
)
711 ind
= (struct tgsi_src_register
*) &tokens
[size
];
714 *ind
= tgsi_build_src_register(
715 reg
->DimIndirect
.File
,
716 reg
->DimIndirect
.SwizzleX
,
717 reg
->DimIndirect
.SwizzleY
,
718 reg
->DimIndirect
.SwizzleZ
,
719 reg
->DimIndirect
.SwizzleW
,
720 reg
->DimIndirect
.Negate
,
721 reg
->DimIndirect
.Absolute
,
722 reg
->DimIndirect
.Indirect
,
723 reg
->DimIndirect
.Dimension
,
724 reg
->DimIndirect
.Index
,
734 struct tgsi_instruction_predicate
735 tgsi_default_instruction_predicate(void)
737 struct tgsi_instruction_predicate instruction_predicate
;
739 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
740 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
741 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
742 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
743 instruction_predicate
.Negate
= 0;
744 instruction_predicate
.Index
= 0;
745 instruction_predicate
.Padding
= 0;
747 return instruction_predicate
;
750 struct tgsi_instruction_predicate
751 tgsi_build_instruction_predicate(int index
,
757 struct tgsi_instruction
*instruction
,
758 struct tgsi_header
*header
)
760 struct tgsi_instruction_predicate instruction_predicate
;
762 instruction_predicate
= tgsi_default_instruction_predicate();
763 instruction_predicate
.SwizzleX
= swizzleX
;
764 instruction_predicate
.SwizzleY
= swizzleY
;
765 instruction_predicate
.SwizzleZ
= swizzleZ
;
766 instruction_predicate
.SwizzleW
= swizzleW
;
767 instruction_predicate
.Negate
= negate
;
768 instruction_predicate
.Index
= index
;
770 instruction_grow(instruction
, header
);
772 return instruction_predicate
;
775 struct tgsi_instruction_label
776 tgsi_default_instruction_label( void )
778 struct tgsi_instruction_label instruction_label
;
780 instruction_label
.Label
= 0;
781 instruction_label
.Padding
= 0;
783 return instruction_label
;
786 struct tgsi_instruction_label
787 tgsi_build_instruction_label(
789 struct tgsi_token
*prev_token
,
790 struct tgsi_instruction
*instruction
,
791 struct tgsi_header
*header
)
793 struct tgsi_instruction_label instruction_label
;
795 instruction_label
= tgsi_default_instruction_label();
796 instruction_label
.Label
= label
;
797 instruction
->Label
= 1;
799 instruction_grow( instruction
, header
);
801 return instruction_label
;
804 struct tgsi_instruction_texture
805 tgsi_default_instruction_texture( void )
807 struct tgsi_instruction_texture instruction_texture
;
809 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
810 instruction_texture
.Padding
= 0;
812 return instruction_texture
;
815 struct tgsi_instruction_texture
816 tgsi_build_instruction_texture(
818 struct tgsi_token
*prev_token
,
819 struct tgsi_instruction
*instruction
,
820 struct tgsi_header
*header
)
822 struct tgsi_instruction_texture instruction_texture
;
824 instruction_texture
= tgsi_default_instruction_texture();
825 instruction_texture
.Texture
= texture
;
826 instruction
->Texture
= 1;
828 instruction_grow( instruction
, header
);
830 return instruction_texture
;
833 struct tgsi_src_register
834 tgsi_default_src_register( void )
836 struct tgsi_src_register src_register
;
838 src_register
.File
= TGSI_FILE_NULL
;
839 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
840 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
841 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
842 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
843 src_register
.Negate
= 0;
844 src_register
.Absolute
= 0;
845 src_register
.Indirect
= 0;
846 src_register
.Dimension
= 0;
847 src_register
.Index
= 0;
852 struct tgsi_src_register
853 tgsi_build_src_register(
864 struct tgsi_instruction
*instruction
,
865 struct tgsi_header
*header
)
867 struct tgsi_src_register src_register
;
869 assert( file
< TGSI_FILE_COUNT
);
870 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
871 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
872 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
873 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
874 assert( negate
<= 1 );
875 assert( index
>= -0x8000 && index
<= 0x7FFF );
877 src_register
= tgsi_default_src_register();
878 src_register
.File
= file
;
879 src_register
.SwizzleX
= swizzle_x
;
880 src_register
.SwizzleY
= swizzle_y
;
881 src_register
.SwizzleZ
= swizzle_z
;
882 src_register
.SwizzleW
= swizzle_w
;
883 src_register
.Negate
= negate
;
884 src_register
.Absolute
= absolute
;
885 src_register
.Indirect
= indirect
;
886 src_register
.Dimension
= dimension
;
887 src_register
.Index
= index
;
889 instruction_grow( instruction
, header
);
894 struct tgsi_full_src_register
895 tgsi_default_full_src_register( void )
897 struct tgsi_full_src_register full_src_register
;
899 full_src_register
.Register
= tgsi_default_src_register();
900 full_src_register
.Indirect
= tgsi_default_src_register();
901 full_src_register
.Dimension
= tgsi_default_dimension();
902 full_src_register
.DimIndirect
= tgsi_default_src_register();
904 return full_src_register
;
908 struct tgsi_dimension
909 tgsi_default_dimension( void )
911 struct tgsi_dimension dimension
;
913 dimension
.Indirect
= 0;
914 dimension
.Dimension
= 0;
915 dimension
.Padding
= 0;
921 struct tgsi_dimension
922 tgsi_build_dimension(
925 struct tgsi_instruction
*instruction
,
926 struct tgsi_header
*header
)
928 struct tgsi_dimension dimension
;
930 dimension
= tgsi_default_dimension();
931 dimension
.Indirect
= indirect
;
932 dimension
.Index
= index
;
934 instruction_grow( instruction
, header
);
939 struct tgsi_dst_register
940 tgsi_default_dst_register( void )
942 struct tgsi_dst_register dst_register
;
944 dst_register
.File
= TGSI_FILE_NULL
;
945 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
946 dst_register
.Indirect
= 0;
947 dst_register
.Dimension
= 0;
948 dst_register
.Index
= 0;
949 dst_register
.Padding
= 0;
954 struct tgsi_dst_register
955 tgsi_build_dst_register(
960 struct tgsi_instruction
*instruction
,
961 struct tgsi_header
*header
)
963 struct tgsi_dst_register dst_register
;
965 assert( file
< TGSI_FILE_COUNT
);
966 assert( mask
<= TGSI_WRITEMASK_XYZW
);
967 assert( index
>= -32768 && index
<= 32767 );
969 dst_register
= tgsi_default_dst_register();
970 dst_register
.File
= file
;
971 dst_register
.WriteMask
= mask
;
972 dst_register
.Index
= index
;
973 dst_register
.Indirect
= indirect
;
975 instruction_grow( instruction
, header
);
980 struct tgsi_full_dst_register
981 tgsi_default_full_dst_register( void )
983 struct tgsi_full_dst_register full_dst_register
;
985 full_dst_register
.Register
= tgsi_default_dst_register();
986 full_dst_register
.Indirect
= tgsi_default_src_register();
988 return full_dst_register
;
992 tgsi_default_property( void )
994 struct tgsi_property property
;
996 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
997 property
.NrTokens
= 1;
998 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
999 property
.Padding
= 0;
1004 struct tgsi_property
1005 tgsi_build_property(unsigned property_name
,
1006 struct tgsi_header
*header
)
1008 struct tgsi_property property
;
1010 property
= tgsi_default_property();
1011 property
.PropertyName
= property_name
;
1013 header_bodysize_grow( header
);
1019 struct tgsi_full_property
1020 tgsi_default_full_property( void )
1022 struct tgsi_full_property full_property
;
1024 full_property
.Property
= tgsi_default_property();
1025 memset(full_property
.u
, 0,
1026 sizeof(struct tgsi_property_data
) * 8);
1028 return full_property
;
1033 struct tgsi_property
*property
,
1034 struct tgsi_header
*header
)
1036 assert( property
->NrTokens
< 0xFF );
1038 property
->NrTokens
++;
1040 header_bodysize_grow( header
);
1043 struct tgsi_property_data
1044 tgsi_build_property_data(
1046 struct tgsi_property
*property
,
1047 struct tgsi_header
*header
)
1049 struct tgsi_property_data property_data
;
1051 property_data
.Data
= value
;
1053 property_grow( property
, header
);
1055 return property_data
;
1059 tgsi_build_full_property(
1060 const struct tgsi_full_property
*full_prop
,
1061 struct tgsi_token
*tokens
,
1062 struct tgsi_header
*header
,
1065 unsigned size
= 0, i
;
1066 struct tgsi_property
*property
;
1068 if( maxsize
<= size
)
1070 property
= (struct tgsi_property
*) &tokens
[size
];
1073 *property
= tgsi_build_property(
1074 full_prop
->Property
.PropertyName
,
1077 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1079 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1080 struct tgsi_property_data
*data
;
1082 if( maxsize
<= size
)
1084 data
= (struct tgsi_property_data
*) &tokens
[size
];
1087 *data
= tgsi_build_property_data(
1088 full_prop
->u
[i
].Data
,