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();
168 return full_declaration
;
172 tgsi_build_full_declaration(
173 const struct tgsi_full_declaration
*full_decl
,
174 struct tgsi_token
*tokens
,
175 struct tgsi_header
*header
,
179 struct tgsi_declaration
*declaration
;
180 struct tgsi_declaration_range
*dr
;
182 if( maxsize
<= size
)
184 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
187 *declaration
= tgsi_build_declaration(
188 full_decl
->Declaration
.File
,
189 full_decl
->Declaration
.UsageMask
,
190 full_decl
->Declaration
.Interpolate
,
191 full_decl
->Declaration
.Dimension
,
192 full_decl
->Declaration
.Semantic
,
193 full_decl
->Declaration
.Centroid
,
194 full_decl
->Declaration
.Invariant
,
195 full_decl
->Declaration
.CylindricalWrap
,
200 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
203 *dr
= tgsi_build_declaration_range(
204 full_decl
->Range
.First
,
205 full_decl
->Range
.Last
,
209 if (full_decl
->Declaration
.Dimension
) {
210 struct tgsi_declaration_dimension
*dd
;
212 if (maxsize
<= size
) {
215 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
218 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
223 if( full_decl
->Declaration
.Semantic
) {
224 struct tgsi_declaration_semantic
*ds
;
226 if( maxsize
<= size
)
228 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
231 *ds
= tgsi_build_declaration_semantic(
232 full_decl
->Semantic
.Name
,
233 full_decl
->Semantic
.Index
,
241 struct tgsi_declaration_range
242 tgsi_default_declaration_range( void )
244 struct tgsi_declaration_range dr
;
252 struct tgsi_declaration_range
253 tgsi_build_declaration_range(
256 struct tgsi_declaration
*declaration
,
257 struct tgsi_header
*header
)
259 struct tgsi_declaration_range declaration_range
;
261 assert( last
>= first
);
262 assert( last
<= 0xFFFF );
264 declaration_range
= tgsi_default_declaration_range();
265 declaration_range
.First
= first
;
266 declaration_range
.Last
= last
;
268 declaration_grow( declaration
, header
);
270 return declaration_range
;
273 struct tgsi_declaration_dimension
274 tgsi_default_declaration_dimension(void)
276 struct tgsi_declaration_dimension dd
;
284 struct tgsi_declaration_dimension
285 tgsi_build_declaration_dimension(unsigned index_2d
,
286 struct tgsi_declaration
*declaration
,
287 struct tgsi_header
*header
)
289 struct tgsi_declaration_dimension dd
;
291 assert(index_2d
<= 0xFFFF);
293 dd
= tgsi_default_declaration_dimension();
294 dd
.Index2D
= index_2d
;
296 declaration_grow(declaration
, header
);
301 struct tgsi_declaration_semantic
302 tgsi_default_declaration_semantic( void )
304 struct tgsi_declaration_semantic ds
;
306 ds
.Name
= TGSI_SEMANTIC_POSITION
;
313 struct tgsi_declaration_semantic
314 tgsi_build_declaration_semantic(
315 unsigned semantic_name
,
316 unsigned semantic_index
,
317 struct tgsi_declaration
*declaration
,
318 struct tgsi_header
*header
)
320 struct tgsi_declaration_semantic ds
;
322 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
323 assert( semantic_index
<= 0xFFFF );
325 ds
= tgsi_default_declaration_semantic();
326 ds
.Name
= semantic_name
;
327 ds
.Index
= semantic_index
;
329 declaration_grow( declaration
, header
);
338 struct tgsi_immediate
339 tgsi_default_immediate( void )
341 struct tgsi_immediate immediate
;
343 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
344 immediate
.NrTokens
= 1;
345 immediate
.DataType
= TGSI_IMM_FLOAT32
;
346 immediate
.Padding
= 0;
351 struct tgsi_immediate
352 tgsi_build_immediate(
353 struct tgsi_header
*header
)
355 struct tgsi_immediate immediate
;
357 immediate
= tgsi_default_immediate();
359 header_bodysize_grow( header
);
364 struct tgsi_full_immediate
365 tgsi_default_full_immediate( void )
367 struct tgsi_full_immediate fullimm
;
369 fullimm
.Immediate
= tgsi_default_immediate();
370 fullimm
.u
[0].Float
= 0.0f
;
371 fullimm
.u
[1].Float
= 0.0f
;
372 fullimm
.u
[2].Float
= 0.0f
;
373 fullimm
.u
[3].Float
= 0.0f
;
380 struct tgsi_immediate
*immediate
,
381 struct tgsi_header
*header
)
383 assert( immediate
->NrTokens
< 0xFF );
385 immediate
->NrTokens
++;
387 header_bodysize_grow( header
);
390 union tgsi_immediate_data
391 tgsi_build_immediate_float32(
393 struct tgsi_immediate
*immediate
,
394 struct tgsi_header
*header
)
396 union tgsi_immediate_data immediate_data
;
398 immediate_data
.Float
= value
;
400 immediate_grow( immediate
, header
);
402 return immediate_data
;
406 tgsi_build_full_immediate(
407 const struct tgsi_full_immediate
*full_imm
,
408 struct tgsi_token
*tokens
,
409 struct tgsi_header
*header
,
412 unsigned size
= 0, i
;
413 struct tgsi_immediate
*immediate
;
415 if( maxsize
<= size
)
417 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
420 *immediate
= tgsi_build_immediate( header
);
422 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
424 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
425 union tgsi_immediate_data
*data
;
427 if( maxsize
<= size
)
429 data
= (union tgsi_immediate_data
*) &tokens
[size
];
432 *data
= tgsi_build_immediate_float32(
433 full_imm
->u
[i
].Float
,
445 struct tgsi_instruction
446 tgsi_default_instruction( void )
448 struct tgsi_instruction instruction
;
450 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
451 instruction
.NrTokens
= 0;
452 instruction
.Opcode
= TGSI_OPCODE_MOV
;
453 instruction
.Saturate
= TGSI_SAT_NONE
;
454 instruction
.Predicate
= 0;
455 instruction
.NumDstRegs
= 1;
456 instruction
.NumSrcRegs
= 1;
457 instruction
.Label
= 0;
458 instruction
.Texture
= 0;
459 instruction
.Padding
= 0;
464 struct tgsi_instruction
465 tgsi_build_instruction(unsigned opcode
,
468 unsigned num_dst_regs
,
469 unsigned num_src_regs
,
470 struct tgsi_header
*header
)
472 struct tgsi_instruction instruction
;
474 assert (opcode
<= TGSI_OPCODE_LAST
);
475 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
476 assert (num_dst_regs
<= 3);
477 assert (num_src_regs
<= 15);
479 instruction
= tgsi_default_instruction();
480 instruction
.Opcode
= opcode
;
481 instruction
.Saturate
= saturate
;
482 instruction
.Predicate
= predicate
;
483 instruction
.NumDstRegs
= num_dst_regs
;
484 instruction
.NumSrcRegs
= num_src_regs
;
486 header_bodysize_grow( header
);
493 struct tgsi_instruction
*instruction
,
494 struct tgsi_header
*header
)
496 assert (instruction
->NrTokens
< 0xFF);
498 instruction
->NrTokens
++;
500 header_bodysize_grow( header
);
503 struct tgsi_full_instruction
504 tgsi_default_full_instruction( void )
506 struct tgsi_full_instruction full_instruction
;
509 full_instruction
.Instruction
= tgsi_default_instruction();
510 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
511 full_instruction
.Label
= tgsi_default_instruction_label();
512 full_instruction
.Texture
= tgsi_default_instruction_texture();
513 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
514 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
516 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
517 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
520 return full_instruction
;
524 tgsi_build_full_instruction(
525 const struct tgsi_full_instruction
*full_inst
,
526 struct tgsi_token
*tokens
,
527 struct tgsi_header
*header
,
532 struct tgsi_instruction
*instruction
;
533 struct tgsi_token
*prev_token
;
535 if( maxsize
<= size
)
537 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
540 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
541 full_inst
->Instruction
.Saturate
,
542 full_inst
->Instruction
.Predicate
,
543 full_inst
->Instruction
.NumDstRegs
,
544 full_inst
->Instruction
.NumSrcRegs
,
546 prev_token
= (struct tgsi_token
*) instruction
;
548 if (full_inst
->Instruction
.Predicate
) {
549 struct tgsi_instruction_predicate
*instruction_predicate
;
551 if (maxsize
<= size
) {
554 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
557 *instruction_predicate
=
558 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
559 full_inst
->Predicate
.Negate
,
560 full_inst
->Predicate
.SwizzleX
,
561 full_inst
->Predicate
.SwizzleY
,
562 full_inst
->Predicate
.SwizzleZ
,
563 full_inst
->Predicate
.SwizzleW
,
568 if (full_inst
->Instruction
.Label
) {
569 struct tgsi_instruction_label
*instruction_label
;
571 if( maxsize
<= size
)
574 (struct tgsi_instruction_label
*) &tokens
[size
];
577 *instruction_label
= tgsi_build_instruction_label(
578 full_inst
->Label
.Label
,
582 prev_token
= (struct tgsi_token
*) instruction_label
;
585 if (full_inst
->Instruction
.Texture
) {
586 struct tgsi_instruction_texture
*instruction_texture
;
588 if( maxsize
<= size
)
590 instruction_texture
=
591 (struct tgsi_instruction_texture
*) &tokens
[size
];
594 *instruction_texture
= tgsi_build_instruction_texture(
595 full_inst
->Texture
.Texture
,
599 prev_token
= (struct tgsi_token
*) instruction_texture
;
602 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
603 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
604 struct tgsi_dst_register
*dst_register
;
605 struct tgsi_token
*prev_token
;
607 if( maxsize
<= size
)
609 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
612 *dst_register
= tgsi_build_dst_register(
614 reg
->Register
.WriteMask
,
615 reg
->Register
.Indirect
,
619 prev_token
= (struct tgsi_token
*) dst_register
;
621 if( reg
->Register
.Indirect
) {
622 struct tgsi_src_register
*ind
;
624 if( maxsize
<= size
)
626 ind
= (struct tgsi_src_register
*) &tokens
[size
];
629 *ind
= tgsi_build_src_register(
631 reg
->Indirect
.SwizzleX
,
632 reg
->Indirect
.SwizzleY
,
633 reg
->Indirect
.SwizzleZ
,
634 reg
->Indirect
.SwizzleW
,
635 reg
->Indirect
.Negate
,
636 reg
->Indirect
.Absolute
,
637 reg
->Indirect
.Indirect
,
638 reg
->Indirect
.Dimension
,
645 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
646 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
647 struct tgsi_src_register
*src_register
;
648 struct tgsi_token
*prev_token
;
650 if( maxsize
<= size
)
652 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
655 *src_register
= tgsi_build_src_register(
657 reg
->Register
.SwizzleX
,
658 reg
->Register
.SwizzleY
,
659 reg
->Register
.SwizzleZ
,
660 reg
->Register
.SwizzleW
,
661 reg
->Register
.Negate
,
662 reg
->Register
.Absolute
,
663 reg
->Register
.Indirect
,
664 reg
->Register
.Dimension
,
668 prev_token
= (struct tgsi_token
*) src_register
;
670 if( reg
->Register
.Indirect
) {
671 struct tgsi_src_register
*ind
;
673 if( maxsize
<= size
)
675 ind
= (struct tgsi_src_register
*) &tokens
[size
];
678 *ind
= tgsi_build_src_register(
680 reg
->Indirect
.SwizzleX
,
681 reg
->Indirect
.SwizzleY
,
682 reg
->Indirect
.SwizzleZ
,
683 reg
->Indirect
.SwizzleW
,
684 reg
->Indirect
.Negate
,
685 reg
->Indirect
.Absolute
,
686 reg
->Indirect
.Indirect
,
687 reg
->Indirect
.Dimension
,
693 if( reg
->Register
.Dimension
) {
694 struct tgsi_dimension
*dim
;
696 assert( !reg
->Dimension
.Dimension
);
698 if( maxsize
<= size
)
700 dim
= (struct tgsi_dimension
*) &tokens
[size
];
703 *dim
= tgsi_build_dimension(
704 reg
->Dimension
.Indirect
,
705 reg
->Dimension
.Index
,
709 if( reg
->Dimension
.Indirect
) {
710 struct tgsi_src_register
*ind
;
712 if( maxsize
<= size
)
714 ind
= (struct tgsi_src_register
*) &tokens
[size
];
717 *ind
= tgsi_build_src_register(
718 reg
->DimIndirect
.File
,
719 reg
->DimIndirect
.SwizzleX
,
720 reg
->DimIndirect
.SwizzleY
,
721 reg
->DimIndirect
.SwizzleZ
,
722 reg
->DimIndirect
.SwizzleW
,
723 reg
->DimIndirect
.Negate
,
724 reg
->DimIndirect
.Absolute
,
725 reg
->DimIndirect
.Indirect
,
726 reg
->DimIndirect
.Dimension
,
727 reg
->DimIndirect
.Index
,
737 struct tgsi_instruction_predicate
738 tgsi_default_instruction_predicate(void)
740 struct tgsi_instruction_predicate instruction_predicate
;
742 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
743 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
744 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
745 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
746 instruction_predicate
.Negate
= 0;
747 instruction_predicate
.Index
= 0;
748 instruction_predicate
.Padding
= 0;
750 return instruction_predicate
;
753 struct tgsi_instruction_predicate
754 tgsi_build_instruction_predicate(int index
,
760 struct tgsi_instruction
*instruction
,
761 struct tgsi_header
*header
)
763 struct tgsi_instruction_predicate instruction_predicate
;
765 instruction_predicate
= tgsi_default_instruction_predicate();
766 instruction_predicate
.SwizzleX
= swizzleX
;
767 instruction_predicate
.SwizzleY
= swizzleY
;
768 instruction_predicate
.SwizzleZ
= swizzleZ
;
769 instruction_predicate
.SwizzleW
= swizzleW
;
770 instruction_predicate
.Negate
= negate
;
771 instruction_predicate
.Index
= index
;
773 instruction_grow(instruction
, header
);
775 return instruction_predicate
;
778 struct tgsi_instruction_label
779 tgsi_default_instruction_label( void )
781 struct tgsi_instruction_label instruction_label
;
783 instruction_label
.Label
= 0;
784 instruction_label
.Padding
= 0;
786 return instruction_label
;
789 struct tgsi_instruction_label
790 tgsi_build_instruction_label(
792 struct tgsi_token
*prev_token
,
793 struct tgsi_instruction
*instruction
,
794 struct tgsi_header
*header
)
796 struct tgsi_instruction_label instruction_label
;
798 instruction_label
= tgsi_default_instruction_label();
799 instruction_label
.Label
= label
;
800 instruction
->Label
= 1;
802 instruction_grow( instruction
, header
);
804 return instruction_label
;
807 struct tgsi_instruction_texture
808 tgsi_default_instruction_texture( void )
810 struct tgsi_instruction_texture instruction_texture
;
812 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
813 instruction_texture
.Padding
= 0;
815 return instruction_texture
;
818 struct tgsi_instruction_texture
819 tgsi_build_instruction_texture(
821 struct tgsi_token
*prev_token
,
822 struct tgsi_instruction
*instruction
,
823 struct tgsi_header
*header
)
825 struct tgsi_instruction_texture instruction_texture
;
827 instruction_texture
= tgsi_default_instruction_texture();
828 instruction_texture
.Texture
= texture
;
829 instruction
->Texture
= 1;
831 instruction_grow( instruction
, header
);
833 return instruction_texture
;
836 struct tgsi_src_register
837 tgsi_default_src_register( void )
839 struct tgsi_src_register src_register
;
841 src_register
.File
= TGSI_FILE_NULL
;
842 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
843 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
844 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
845 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
846 src_register
.Negate
= 0;
847 src_register
.Absolute
= 0;
848 src_register
.Indirect
= 0;
849 src_register
.Dimension
= 0;
850 src_register
.Index
= 0;
855 struct tgsi_src_register
856 tgsi_build_src_register(
867 struct tgsi_instruction
*instruction
,
868 struct tgsi_header
*header
)
870 struct tgsi_src_register src_register
;
872 assert( file
< TGSI_FILE_COUNT
);
873 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
874 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
875 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
876 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
877 assert( negate
<= 1 );
878 assert( index
>= -0x8000 && index
<= 0x7FFF );
880 src_register
= tgsi_default_src_register();
881 src_register
.File
= file
;
882 src_register
.SwizzleX
= swizzle_x
;
883 src_register
.SwizzleY
= swizzle_y
;
884 src_register
.SwizzleZ
= swizzle_z
;
885 src_register
.SwizzleW
= swizzle_w
;
886 src_register
.Negate
= negate
;
887 src_register
.Absolute
= absolute
;
888 src_register
.Indirect
= indirect
;
889 src_register
.Dimension
= dimension
;
890 src_register
.Index
= index
;
892 instruction_grow( instruction
, header
);
897 struct tgsi_full_src_register
898 tgsi_default_full_src_register( void )
900 struct tgsi_full_src_register full_src_register
;
902 full_src_register
.Register
= tgsi_default_src_register();
903 full_src_register
.Indirect
= tgsi_default_src_register();
904 full_src_register
.Dimension
= tgsi_default_dimension();
905 full_src_register
.DimIndirect
= tgsi_default_src_register();
907 return full_src_register
;
911 struct tgsi_dimension
912 tgsi_default_dimension( void )
914 struct tgsi_dimension dimension
;
916 dimension
.Indirect
= 0;
917 dimension
.Dimension
= 0;
918 dimension
.Padding
= 0;
924 struct tgsi_dimension
925 tgsi_build_dimension(
928 struct tgsi_instruction
*instruction
,
929 struct tgsi_header
*header
)
931 struct tgsi_dimension dimension
;
933 dimension
= tgsi_default_dimension();
934 dimension
.Indirect
= indirect
;
935 dimension
.Index
= index
;
937 instruction_grow( instruction
, header
);
942 struct tgsi_dst_register
943 tgsi_default_dst_register( void )
945 struct tgsi_dst_register dst_register
;
947 dst_register
.File
= TGSI_FILE_NULL
;
948 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
949 dst_register
.Indirect
= 0;
950 dst_register
.Dimension
= 0;
951 dst_register
.Index
= 0;
952 dst_register
.Padding
= 0;
957 struct tgsi_dst_register
958 tgsi_build_dst_register(
963 struct tgsi_instruction
*instruction
,
964 struct tgsi_header
*header
)
966 struct tgsi_dst_register dst_register
;
968 assert( file
< TGSI_FILE_COUNT
);
969 assert( mask
<= TGSI_WRITEMASK_XYZW
);
970 assert( index
>= -32768 && index
<= 32767 );
972 dst_register
= tgsi_default_dst_register();
973 dst_register
.File
= file
;
974 dst_register
.WriteMask
= mask
;
975 dst_register
.Index
= index
;
976 dst_register
.Indirect
= indirect
;
978 instruction_grow( instruction
, header
);
983 struct tgsi_full_dst_register
984 tgsi_default_full_dst_register( void )
986 struct tgsi_full_dst_register full_dst_register
;
988 full_dst_register
.Register
= tgsi_default_dst_register();
989 full_dst_register
.Indirect
= tgsi_default_src_register();
991 return full_dst_register
;
995 tgsi_default_property( void )
997 struct tgsi_property property
;
999 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1000 property
.NrTokens
= 1;
1001 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1002 property
.Padding
= 0;
1007 struct tgsi_property
1008 tgsi_build_property(unsigned property_name
,
1009 struct tgsi_header
*header
)
1011 struct tgsi_property property
;
1013 property
= tgsi_default_property();
1014 property
.PropertyName
= property_name
;
1016 header_bodysize_grow( header
);
1022 struct tgsi_full_property
1023 tgsi_default_full_property( void )
1025 struct tgsi_full_property full_property
;
1027 full_property
.Property
= tgsi_default_property();
1028 memset(full_property
.u
, 0,
1029 sizeof(struct tgsi_property_data
) * 8);
1031 return full_property
;
1036 struct tgsi_property
*property
,
1037 struct tgsi_header
*header
)
1039 assert( property
->NrTokens
< 0xFF );
1041 property
->NrTokens
++;
1043 header_bodysize_grow( header
);
1046 struct tgsi_property_data
1047 tgsi_build_property_data(
1049 struct tgsi_property
*property
,
1050 struct tgsi_header
*header
)
1052 struct tgsi_property_data property_data
;
1054 property_data
.Data
= value
;
1056 property_grow( property
, header
);
1058 return property_data
;
1062 tgsi_build_full_property(
1063 const struct tgsi_full_property
*full_prop
,
1064 struct tgsi_token
*tokens
,
1065 struct tgsi_header
*header
,
1068 unsigned size
= 0, i
;
1069 struct tgsi_property
*property
;
1071 if( maxsize
<= size
)
1073 property
= (struct tgsi_property
*) &tokens
[size
];
1076 *property
= tgsi_build_property(
1077 full_prop
->Property
.PropertyName
,
1080 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1082 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1083 struct tgsi_property_data
*data
;
1085 if( maxsize
<= size
)
1087 data
= (struct tgsi_property_data
*) &tokens
[size
];
1090 *data
= tgsi_build_property_data(
1091 full_prop
->u
[i
].Data
,