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 );
69 struct tgsi_header
*header
)
71 struct tgsi_processor processor
;
73 processor
.Processor
= type
;
74 processor
.Padding
= 0;
76 header_headersize_grow( header
);
87 struct tgsi_declaration
*declaration
,
88 struct tgsi_header
*header
)
90 assert( declaration
->NrTokens
< 0xFF );
92 declaration
->NrTokens
++;
94 header_bodysize_grow( header
);
97 static struct tgsi_declaration
98 tgsi_default_declaration( void )
100 struct tgsi_declaration declaration
;
102 declaration
.Type
= TGSI_TOKEN_TYPE_DECLARATION
;
103 declaration
.NrTokens
= 1;
104 declaration
.File
= TGSI_FILE_NULL
;
105 declaration
.UsageMask
= TGSI_WRITEMASK_XYZW
;
106 declaration
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
107 declaration
.Dimension
= 0;
108 declaration
.Semantic
= 0;
109 declaration
.Centroid
= 0;
110 declaration
.Invariant
= 0;
111 declaration
.CylindricalWrap
= 0;
116 static struct tgsi_declaration
117 tgsi_build_declaration(
120 unsigned interpolate
,
125 unsigned cylindrical_wrap
,
126 struct tgsi_header
*header
)
128 struct tgsi_declaration declaration
;
130 assert( file
< TGSI_FILE_COUNT
);
131 assert( interpolate
< TGSI_INTERPOLATE_COUNT
);
133 declaration
= tgsi_default_declaration();
134 declaration
.File
= file
;
135 declaration
.UsageMask
= usage_mask
;
136 declaration
.Interpolate
= interpolate
;
137 declaration
.Dimension
= dimension
;
138 declaration
.Semantic
= semantic
;
139 declaration
.Centroid
= centroid
;
140 declaration
.Invariant
= invariant
;
141 declaration
.CylindricalWrap
= cylindrical_wrap
;
143 header_bodysize_grow( header
);
148 static struct tgsi_declaration_range
149 tgsi_default_declaration_range( void )
151 struct tgsi_declaration_range dr
;
159 static struct tgsi_declaration_range
160 tgsi_build_declaration_range(
163 struct tgsi_declaration
*declaration
,
164 struct tgsi_header
*header
)
166 struct tgsi_declaration_range declaration_range
;
168 assert( last
>= first
);
169 assert( last
<= 0xFFFF );
171 declaration_range
.First
= first
;
172 declaration_range
.Last
= last
;
174 declaration_grow( declaration
, header
);
176 return declaration_range
;
179 static struct tgsi_declaration_dimension
180 tgsi_default_declaration_dimension(void)
182 struct tgsi_declaration_dimension dd
;
190 static struct tgsi_declaration_dimension
191 tgsi_build_declaration_dimension(unsigned index_2d
,
192 struct tgsi_declaration
*declaration
,
193 struct tgsi_header
*header
)
195 struct tgsi_declaration_dimension dd
;
197 assert(index_2d
<= 0xFFFF);
199 dd
.Index2D
= index_2d
;
202 declaration_grow(declaration
, header
);
207 static struct tgsi_declaration_semantic
208 tgsi_default_declaration_semantic( void )
210 struct tgsi_declaration_semantic ds
;
212 ds
.Name
= TGSI_SEMANTIC_POSITION
;
219 static struct tgsi_declaration_semantic
220 tgsi_build_declaration_semantic(
221 unsigned semantic_name
,
222 unsigned semantic_index
,
223 struct tgsi_declaration
*declaration
,
224 struct tgsi_header
*header
)
226 struct tgsi_declaration_semantic ds
;
228 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
229 assert( semantic_index
<= 0xFFFF );
231 ds
.Name
= semantic_name
;
232 ds
.Index
= semantic_index
;
235 declaration_grow( declaration
, header
);
240 struct tgsi_full_declaration
241 tgsi_default_full_declaration( void )
243 struct tgsi_full_declaration full_declaration
;
245 full_declaration
.Declaration
= tgsi_default_declaration();
246 full_declaration
.Range
= tgsi_default_declaration_range();
247 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
248 full_declaration
.ImmediateData
.u
= NULL
;
250 return full_declaration
;
254 tgsi_build_full_declaration(
255 const struct tgsi_full_declaration
*full_decl
,
256 struct tgsi_token
*tokens
,
257 struct tgsi_header
*header
,
261 struct tgsi_declaration
*declaration
;
262 struct tgsi_declaration_range
*dr
;
264 if( maxsize
<= size
)
266 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
269 *declaration
= tgsi_build_declaration(
270 full_decl
->Declaration
.File
,
271 full_decl
->Declaration
.UsageMask
,
272 full_decl
->Declaration
.Interpolate
,
273 full_decl
->Declaration
.Dimension
,
274 full_decl
->Declaration
.Semantic
,
275 full_decl
->Declaration
.Centroid
,
276 full_decl
->Declaration
.Invariant
,
277 full_decl
->Declaration
.CylindricalWrap
,
282 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
285 *dr
= tgsi_build_declaration_range(
286 full_decl
->Range
.First
,
287 full_decl
->Range
.Last
,
291 if (full_decl
->Declaration
.Dimension
) {
292 struct tgsi_declaration_dimension
*dd
;
294 if (maxsize
<= size
) {
297 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
300 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
305 if( full_decl
->Declaration
.Semantic
) {
306 struct tgsi_declaration_semantic
*ds
;
308 if( maxsize
<= size
)
310 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
313 *ds
= tgsi_build_declaration_semantic(
314 full_decl
->Semantic
.Name
,
315 full_decl
->Semantic
.Index
,
320 if (full_decl
->Declaration
.File
== TGSI_FILE_IMMEDIATE_ARRAY
) {
322 union tgsi_immediate_data
*data
;
324 for (i
= 0; i
<= dr
->Last
; ++i
) {
325 for (j
= 0; j
< 4; ++j
) {
326 unsigned idx
= i
*4 + j
;
329 data
= (union tgsi_immediate_data
*) &tokens
[size
];
332 *data
= full_decl
->ImmediateData
.u
[idx
];
333 declaration_grow( declaration
, header
);
345 static struct tgsi_immediate
346 tgsi_default_immediate( void )
348 struct tgsi_immediate immediate
;
350 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
351 immediate
.NrTokens
= 1;
352 immediate
.DataType
= TGSI_IMM_FLOAT32
;
353 immediate
.Padding
= 0;
358 static struct tgsi_immediate
359 tgsi_build_immediate(
360 struct tgsi_header
*header
)
362 struct tgsi_immediate immediate
;
364 immediate
= tgsi_default_immediate();
366 header_bodysize_grow( header
);
371 struct tgsi_full_immediate
372 tgsi_default_full_immediate( void )
374 struct tgsi_full_immediate fullimm
;
376 fullimm
.Immediate
= tgsi_default_immediate();
377 fullimm
.u
[0].Float
= 0.0f
;
378 fullimm
.u
[1].Float
= 0.0f
;
379 fullimm
.u
[2].Float
= 0.0f
;
380 fullimm
.u
[3].Float
= 0.0f
;
387 struct tgsi_immediate
*immediate
,
388 struct tgsi_header
*header
)
390 assert( immediate
->NrTokens
< 0xFF );
392 immediate
->NrTokens
++;
394 header_bodysize_grow( header
);
397 static union tgsi_immediate_data
398 tgsi_build_immediate_float32(
400 struct tgsi_immediate
*immediate
,
401 struct tgsi_header
*header
)
403 union tgsi_immediate_data immediate_data
;
405 immediate_data
.Float
= value
;
407 immediate_grow( immediate
, header
);
409 return immediate_data
;
413 tgsi_build_full_immediate(
414 const struct tgsi_full_immediate
*full_imm
,
415 struct tgsi_token
*tokens
,
416 struct tgsi_header
*header
,
419 unsigned size
= 0, i
;
420 struct tgsi_immediate
*immediate
;
422 if( maxsize
<= size
)
424 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
427 *immediate
= tgsi_build_immediate( header
);
429 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
431 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
432 union tgsi_immediate_data
*data
;
434 if( maxsize
<= size
)
436 data
= (union tgsi_immediate_data
*) &tokens
[size
];
439 *data
= tgsi_build_immediate_float32(
440 full_imm
->u
[i
].Float
,
452 struct tgsi_instruction
453 tgsi_default_instruction( void )
455 struct tgsi_instruction instruction
;
457 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
458 instruction
.NrTokens
= 0;
459 instruction
.Opcode
= TGSI_OPCODE_MOV
;
460 instruction
.Saturate
= TGSI_SAT_NONE
;
461 instruction
.Predicate
= 0;
462 instruction
.NumDstRegs
= 1;
463 instruction
.NumSrcRegs
= 1;
464 instruction
.Label
= 0;
465 instruction
.Texture
= 0;
466 instruction
.Padding
= 0;
471 static struct tgsi_instruction
472 tgsi_build_instruction(unsigned opcode
,
475 unsigned num_dst_regs
,
476 unsigned num_src_regs
,
477 struct tgsi_header
*header
)
479 struct tgsi_instruction instruction
;
481 assert (opcode
<= TGSI_OPCODE_LAST
);
482 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
483 assert (num_dst_regs
<= 3);
484 assert (num_src_regs
<= 15);
486 instruction
= tgsi_default_instruction();
487 instruction
.Opcode
= opcode
;
488 instruction
.Saturate
= saturate
;
489 instruction
.Predicate
= predicate
;
490 instruction
.NumDstRegs
= num_dst_regs
;
491 instruction
.NumSrcRegs
= num_src_regs
;
493 header_bodysize_grow( header
);
500 struct tgsi_instruction
*instruction
,
501 struct tgsi_header
*header
)
503 assert (instruction
->NrTokens
< 0xFF);
505 instruction
->NrTokens
++;
507 header_bodysize_grow( header
);
510 struct tgsi_instruction_predicate
511 tgsi_default_instruction_predicate(void)
513 struct tgsi_instruction_predicate instruction_predicate
;
515 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
516 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
517 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
518 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
519 instruction_predicate
.Negate
= 0;
520 instruction_predicate
.Index
= 0;
521 instruction_predicate
.Padding
= 0;
523 return instruction_predicate
;
526 static struct tgsi_instruction_predicate
527 tgsi_build_instruction_predicate(int index
,
533 struct tgsi_instruction
*instruction
,
534 struct tgsi_header
*header
)
536 struct tgsi_instruction_predicate instruction_predicate
;
538 instruction_predicate
= tgsi_default_instruction_predicate();
539 instruction_predicate
.SwizzleX
= swizzleX
;
540 instruction_predicate
.SwizzleY
= swizzleY
;
541 instruction_predicate
.SwizzleZ
= swizzleZ
;
542 instruction_predicate
.SwizzleW
= swizzleW
;
543 instruction_predicate
.Negate
= negate
;
544 instruction_predicate
.Index
= index
;
546 instruction_grow(instruction
, header
);
548 return instruction_predicate
;
551 static struct tgsi_instruction_label
552 tgsi_default_instruction_label( void )
554 struct tgsi_instruction_label instruction_label
;
556 instruction_label
.Label
= 0;
557 instruction_label
.Padding
= 0;
559 return instruction_label
;
562 static struct tgsi_instruction_label
563 tgsi_build_instruction_label(
565 struct tgsi_token
*prev_token
,
566 struct tgsi_instruction
*instruction
,
567 struct tgsi_header
*header
)
569 struct tgsi_instruction_label instruction_label
;
571 instruction_label
.Label
= label
;
572 instruction_label
.Padding
= 0;
573 instruction
->Label
= 1;
575 instruction_grow( instruction
, header
);
577 return instruction_label
;
580 static struct tgsi_instruction_texture
581 tgsi_default_instruction_texture( void )
583 struct tgsi_instruction_texture instruction_texture
;
585 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
586 instruction_texture
.Padding
= 0;
588 return instruction_texture
;
591 static struct tgsi_instruction_texture
592 tgsi_build_instruction_texture(
594 struct tgsi_token
*prev_token
,
595 struct tgsi_instruction
*instruction
,
596 struct tgsi_header
*header
)
598 struct tgsi_instruction_texture instruction_texture
;
600 instruction_texture
.Texture
= texture
;
601 instruction_texture
.Padding
= 0;
602 instruction
->Texture
= 1;
604 instruction_grow( instruction
, header
);
606 return instruction_texture
;
609 static struct tgsi_src_register
610 tgsi_default_src_register( void )
612 struct tgsi_src_register src_register
;
614 src_register
.File
= TGSI_FILE_NULL
;
615 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
616 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
617 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
618 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
619 src_register
.Negate
= 0;
620 src_register
.Absolute
= 0;
621 src_register
.Indirect
= 0;
622 src_register
.Dimension
= 0;
623 src_register
.Index
= 0;
628 static struct tgsi_src_register
629 tgsi_build_src_register(
640 struct tgsi_instruction
*instruction
,
641 struct tgsi_header
*header
)
643 struct tgsi_src_register src_register
;
645 assert( file
< TGSI_FILE_COUNT
);
646 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
647 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
648 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
649 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
650 assert( negate
<= 1 );
651 assert( index
>= -0x8000 && index
<= 0x7FFF );
653 src_register
.File
= file
;
654 src_register
.SwizzleX
= swizzle_x
;
655 src_register
.SwizzleY
= swizzle_y
;
656 src_register
.SwizzleZ
= swizzle_z
;
657 src_register
.SwizzleW
= swizzle_w
;
658 src_register
.Negate
= negate
;
659 src_register
.Absolute
= absolute
;
660 src_register
.Indirect
= indirect
;
661 src_register
.Dimension
= dimension
;
662 src_register
.Index
= index
;
664 instruction_grow( instruction
, header
);
669 static struct tgsi_dimension
670 tgsi_default_dimension( void )
672 struct tgsi_dimension dimension
;
674 dimension
.Indirect
= 0;
675 dimension
.Dimension
= 0;
676 dimension
.Padding
= 0;
682 static struct tgsi_full_src_register
683 tgsi_default_full_src_register( void )
685 struct tgsi_full_src_register full_src_register
;
687 full_src_register
.Register
= tgsi_default_src_register();
688 full_src_register
.Indirect
= tgsi_default_src_register();
689 full_src_register
.Dimension
= tgsi_default_dimension();
690 full_src_register
.DimIndirect
= tgsi_default_src_register();
692 return full_src_register
;
695 static struct tgsi_dimension
696 tgsi_build_dimension(
699 struct tgsi_instruction
*instruction
,
700 struct tgsi_header
*header
)
702 struct tgsi_dimension dimension
;
704 dimension
.Indirect
= indirect
;
705 dimension
.Dimension
= 0;
706 dimension
.Padding
= 0;
707 dimension
.Index
= index
;
709 instruction_grow( instruction
, header
);
714 static struct tgsi_dst_register
715 tgsi_default_dst_register( void )
717 struct tgsi_dst_register dst_register
;
719 dst_register
.File
= TGSI_FILE_NULL
;
720 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
721 dst_register
.Indirect
= 0;
722 dst_register
.Dimension
= 0;
723 dst_register
.Index
= 0;
724 dst_register
.Padding
= 0;
729 static struct tgsi_dst_register
730 tgsi_build_dst_register(
736 struct tgsi_instruction
*instruction
,
737 struct tgsi_header
*header
)
739 struct tgsi_dst_register dst_register
;
741 assert( file
< TGSI_FILE_COUNT
);
742 assert( mask
<= TGSI_WRITEMASK_XYZW
);
743 assert( index
>= -32768 && index
<= 32767 );
745 dst_register
.File
= file
;
746 dst_register
.WriteMask
= mask
;
747 dst_register
.Indirect
= indirect
;
748 dst_register
.Dimension
= dimension
;
749 dst_register
.Index
= index
;
750 dst_register
.Padding
= 0;
752 instruction_grow( instruction
, header
);
757 static struct tgsi_full_dst_register
758 tgsi_default_full_dst_register( void )
760 struct tgsi_full_dst_register full_dst_register
;
762 full_dst_register
.Register
= tgsi_default_dst_register();
763 full_dst_register
.Indirect
= tgsi_default_src_register();
764 full_dst_register
.Dimension
= tgsi_default_dimension();
765 full_dst_register
.DimIndirect
= tgsi_default_src_register();
767 return full_dst_register
;
770 struct tgsi_full_instruction
771 tgsi_default_full_instruction( void )
773 struct tgsi_full_instruction full_instruction
;
776 full_instruction
.Instruction
= tgsi_default_instruction();
777 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
778 full_instruction
.Label
= tgsi_default_instruction_label();
779 full_instruction
.Texture
= tgsi_default_instruction_texture();
780 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
781 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
783 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
784 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
787 return full_instruction
;
791 tgsi_build_full_instruction(
792 const struct tgsi_full_instruction
*full_inst
,
793 struct tgsi_token
*tokens
,
794 struct tgsi_header
*header
,
799 struct tgsi_instruction
*instruction
;
800 struct tgsi_token
*prev_token
;
802 if( maxsize
<= size
)
804 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
807 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
808 full_inst
->Instruction
.Saturate
,
809 full_inst
->Instruction
.Predicate
,
810 full_inst
->Instruction
.NumDstRegs
,
811 full_inst
->Instruction
.NumSrcRegs
,
813 prev_token
= (struct tgsi_token
*) instruction
;
815 if (full_inst
->Instruction
.Predicate
) {
816 struct tgsi_instruction_predicate
*instruction_predicate
;
818 if (maxsize
<= size
) {
821 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
824 *instruction_predicate
=
825 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
826 full_inst
->Predicate
.Negate
,
827 full_inst
->Predicate
.SwizzleX
,
828 full_inst
->Predicate
.SwizzleY
,
829 full_inst
->Predicate
.SwizzleZ
,
830 full_inst
->Predicate
.SwizzleW
,
835 if (full_inst
->Instruction
.Label
) {
836 struct tgsi_instruction_label
*instruction_label
;
838 if( maxsize
<= size
)
841 (struct tgsi_instruction_label
*) &tokens
[size
];
844 *instruction_label
= tgsi_build_instruction_label(
845 full_inst
->Label
.Label
,
849 prev_token
= (struct tgsi_token
*) instruction_label
;
852 if (full_inst
->Instruction
.Texture
) {
853 struct tgsi_instruction_texture
*instruction_texture
;
855 if( maxsize
<= size
)
857 instruction_texture
=
858 (struct tgsi_instruction_texture
*) &tokens
[size
];
861 *instruction_texture
= tgsi_build_instruction_texture(
862 full_inst
->Texture
.Texture
,
866 prev_token
= (struct tgsi_token
*) instruction_texture
;
869 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
870 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
871 struct tgsi_dst_register
*dst_register
;
872 struct tgsi_token
*prev_token
;
874 if( maxsize
<= size
)
876 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
879 *dst_register
= tgsi_build_dst_register(
881 reg
->Register
.WriteMask
,
882 reg
->Register
.Indirect
,
883 reg
->Register
.Dimension
,
887 prev_token
= (struct tgsi_token
*) dst_register
;
889 if( reg
->Register
.Indirect
) {
890 struct tgsi_src_register
*ind
;
892 if( maxsize
<= size
)
894 ind
= (struct tgsi_src_register
*) &tokens
[size
];
897 *ind
= tgsi_build_src_register(
899 reg
->Indirect
.SwizzleX
,
900 reg
->Indirect
.SwizzleY
,
901 reg
->Indirect
.SwizzleZ
,
902 reg
->Indirect
.SwizzleW
,
903 reg
->Indirect
.Negate
,
904 reg
->Indirect
.Absolute
,
905 reg
->Indirect
.Indirect
,
906 reg
->Indirect
.Dimension
,
912 if( reg
->Register
.Dimension
) {
913 struct tgsi_dimension
*dim
;
915 assert( !reg
->Dimension
.Dimension
);
917 if( maxsize
<= size
)
919 dim
= (struct tgsi_dimension
*) &tokens
[size
];
922 *dim
= tgsi_build_dimension(
923 reg
->Dimension
.Indirect
,
924 reg
->Dimension
.Index
,
928 if( reg
->Dimension
.Indirect
) {
929 struct tgsi_src_register
*ind
;
931 if( maxsize
<= size
)
933 ind
= (struct tgsi_src_register
*) &tokens
[size
];
936 *ind
= tgsi_build_src_register(
937 reg
->DimIndirect
.File
,
938 reg
->DimIndirect
.SwizzleX
,
939 reg
->DimIndirect
.SwizzleY
,
940 reg
->DimIndirect
.SwizzleZ
,
941 reg
->DimIndirect
.SwizzleW
,
942 reg
->DimIndirect
.Negate
,
943 reg
->DimIndirect
.Absolute
,
944 reg
->DimIndirect
.Indirect
,
945 reg
->DimIndirect
.Dimension
,
946 reg
->DimIndirect
.Index
,
953 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
954 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
955 struct tgsi_src_register
*src_register
;
956 struct tgsi_token
*prev_token
;
958 if( maxsize
<= size
)
960 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
963 *src_register
= tgsi_build_src_register(
965 reg
->Register
.SwizzleX
,
966 reg
->Register
.SwizzleY
,
967 reg
->Register
.SwizzleZ
,
968 reg
->Register
.SwizzleW
,
969 reg
->Register
.Negate
,
970 reg
->Register
.Absolute
,
971 reg
->Register
.Indirect
,
972 reg
->Register
.Dimension
,
976 prev_token
= (struct tgsi_token
*) src_register
;
978 if( reg
->Register
.Indirect
) {
979 struct tgsi_src_register
*ind
;
981 if( maxsize
<= size
)
983 ind
= (struct tgsi_src_register
*) &tokens
[size
];
986 *ind
= tgsi_build_src_register(
988 reg
->Indirect
.SwizzleX
,
989 reg
->Indirect
.SwizzleY
,
990 reg
->Indirect
.SwizzleZ
,
991 reg
->Indirect
.SwizzleW
,
992 reg
->Indirect
.Negate
,
993 reg
->Indirect
.Absolute
,
994 reg
->Indirect
.Indirect
,
995 reg
->Indirect
.Dimension
,
1001 if( reg
->Register
.Dimension
) {
1002 struct tgsi_dimension
*dim
;
1004 assert( !reg
->Dimension
.Dimension
);
1006 if( maxsize
<= size
)
1008 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1011 *dim
= tgsi_build_dimension(
1012 reg
->Dimension
.Indirect
,
1013 reg
->Dimension
.Index
,
1017 if( reg
->Dimension
.Indirect
) {
1018 struct tgsi_src_register
*ind
;
1020 if( maxsize
<= size
)
1022 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1025 *ind
= tgsi_build_src_register(
1026 reg
->DimIndirect
.File
,
1027 reg
->DimIndirect
.SwizzleX
,
1028 reg
->DimIndirect
.SwizzleY
,
1029 reg
->DimIndirect
.SwizzleZ
,
1030 reg
->DimIndirect
.SwizzleW
,
1031 reg
->DimIndirect
.Negate
,
1032 reg
->DimIndirect
.Absolute
,
1033 reg
->DimIndirect
.Indirect
,
1034 reg
->DimIndirect
.Dimension
,
1035 reg
->DimIndirect
.Index
,
1045 static struct tgsi_property
1046 tgsi_default_property( void )
1048 struct tgsi_property property
;
1050 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1051 property
.NrTokens
= 1;
1052 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1053 property
.Padding
= 0;
1058 static struct tgsi_property
1059 tgsi_build_property(unsigned property_name
,
1060 struct tgsi_header
*header
)
1062 struct tgsi_property property
;
1064 property
= tgsi_default_property();
1065 property
.PropertyName
= property_name
;
1067 header_bodysize_grow( header
);
1073 struct tgsi_full_property
1074 tgsi_default_full_property( void )
1076 struct tgsi_full_property full_property
;
1078 full_property
.Property
= tgsi_default_property();
1079 memset(full_property
.u
, 0,
1080 sizeof(struct tgsi_property_data
) * 8);
1082 return full_property
;
1087 struct tgsi_property
*property
,
1088 struct tgsi_header
*header
)
1090 assert( property
->NrTokens
< 0xFF );
1092 property
->NrTokens
++;
1094 header_bodysize_grow( header
);
1097 static struct tgsi_property_data
1098 tgsi_build_property_data(
1100 struct tgsi_property
*property
,
1101 struct tgsi_header
*header
)
1103 struct tgsi_property_data property_data
;
1105 property_data
.Data
= value
;
1107 property_grow( property
, header
);
1109 return property_data
;
1113 tgsi_build_full_property(
1114 const struct tgsi_full_property
*full_prop
,
1115 struct tgsi_token
*tokens
,
1116 struct tgsi_header
*header
,
1119 unsigned size
= 0, i
;
1120 struct tgsi_property
*property
;
1122 if( maxsize
<= size
)
1124 property
= (struct tgsi_property
*) &tokens
[size
];
1127 *property
= tgsi_build_property(
1128 full_prop
->Property
.PropertyName
,
1131 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1133 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1134 struct tgsi_property_data
*data
;
1136 if( maxsize
<= size
)
1138 data
= (struct tgsi_property_data
*) &tokens
[size
];
1141 *data
= tgsi_build_property_data(
1142 full_prop
->u
[i
].Data
,