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_build_declaration_dimension(unsigned index_2d
,
181 struct tgsi_declaration
*declaration
,
182 struct tgsi_header
*header
)
184 struct tgsi_declaration_dimension dd
;
186 assert(index_2d
<= 0xFFFF);
188 dd
.Index2D
= index_2d
;
191 declaration_grow(declaration
, header
);
196 static struct tgsi_declaration_semantic
197 tgsi_default_declaration_semantic( void )
199 struct tgsi_declaration_semantic ds
;
201 ds
.Name
= TGSI_SEMANTIC_POSITION
;
208 static struct tgsi_declaration_semantic
209 tgsi_build_declaration_semantic(
210 unsigned semantic_name
,
211 unsigned semantic_index
,
212 struct tgsi_declaration
*declaration
,
213 struct tgsi_header
*header
)
215 struct tgsi_declaration_semantic ds
;
217 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
218 assert( semantic_index
<= 0xFFFF );
220 ds
.Name
= semantic_name
;
221 ds
.Index
= semantic_index
;
224 declaration_grow( declaration
, header
);
229 struct tgsi_full_declaration
230 tgsi_default_full_declaration( void )
232 struct tgsi_full_declaration full_declaration
;
234 full_declaration
.Declaration
= tgsi_default_declaration();
235 full_declaration
.Range
= tgsi_default_declaration_range();
236 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
237 full_declaration
.ImmediateData
.u
= NULL
;
239 return full_declaration
;
243 tgsi_build_full_declaration(
244 const struct tgsi_full_declaration
*full_decl
,
245 struct tgsi_token
*tokens
,
246 struct tgsi_header
*header
,
250 struct tgsi_declaration
*declaration
;
251 struct tgsi_declaration_range
*dr
;
253 if( maxsize
<= size
)
255 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
258 *declaration
= tgsi_build_declaration(
259 full_decl
->Declaration
.File
,
260 full_decl
->Declaration
.UsageMask
,
261 full_decl
->Declaration
.Interpolate
,
262 full_decl
->Declaration
.Dimension
,
263 full_decl
->Declaration
.Semantic
,
264 full_decl
->Declaration
.Centroid
,
265 full_decl
->Declaration
.Invariant
,
266 full_decl
->Declaration
.CylindricalWrap
,
271 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
274 *dr
= tgsi_build_declaration_range(
275 full_decl
->Range
.First
,
276 full_decl
->Range
.Last
,
280 if (full_decl
->Declaration
.Dimension
) {
281 struct tgsi_declaration_dimension
*dd
;
283 if (maxsize
<= size
) {
286 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
289 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
294 if( full_decl
->Declaration
.Semantic
) {
295 struct tgsi_declaration_semantic
*ds
;
297 if( maxsize
<= size
)
299 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
302 *ds
= tgsi_build_declaration_semantic(
303 full_decl
->Semantic
.Name
,
304 full_decl
->Semantic
.Index
,
309 if (full_decl
->Declaration
.File
== TGSI_FILE_IMMEDIATE_ARRAY
) {
311 union tgsi_immediate_data
*data
;
313 for (i
= 0; i
<= dr
->Last
; ++i
) {
314 for (j
= 0; j
< 4; ++j
) {
315 unsigned idx
= i
*4 + j
;
318 data
= (union tgsi_immediate_data
*) &tokens
[size
];
321 *data
= full_decl
->ImmediateData
.u
[idx
];
322 declaration_grow( declaration
, header
);
334 static struct tgsi_immediate
335 tgsi_default_immediate( void )
337 struct tgsi_immediate immediate
;
339 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
340 immediate
.NrTokens
= 1;
341 immediate
.DataType
= TGSI_IMM_FLOAT32
;
342 immediate
.Padding
= 0;
347 static struct tgsi_immediate
348 tgsi_build_immediate(
349 struct tgsi_header
*header
)
351 struct tgsi_immediate immediate
;
353 immediate
= tgsi_default_immediate();
355 header_bodysize_grow( header
);
360 struct tgsi_full_immediate
361 tgsi_default_full_immediate( void )
363 struct tgsi_full_immediate fullimm
;
365 fullimm
.Immediate
= tgsi_default_immediate();
366 fullimm
.u
[0].Float
= 0.0f
;
367 fullimm
.u
[1].Float
= 0.0f
;
368 fullimm
.u
[2].Float
= 0.0f
;
369 fullimm
.u
[3].Float
= 0.0f
;
376 struct tgsi_immediate
*immediate
,
377 struct tgsi_header
*header
)
379 assert( immediate
->NrTokens
< 0xFF );
381 immediate
->NrTokens
++;
383 header_bodysize_grow( header
);
386 static union tgsi_immediate_data
387 tgsi_build_immediate_float32(
389 struct tgsi_immediate
*immediate
,
390 struct tgsi_header
*header
)
392 union tgsi_immediate_data immediate_data
;
394 immediate_data
.Float
= value
;
396 immediate_grow( immediate
, header
);
398 return immediate_data
;
402 tgsi_build_full_immediate(
403 const struct tgsi_full_immediate
*full_imm
,
404 struct tgsi_token
*tokens
,
405 struct tgsi_header
*header
,
408 unsigned size
= 0, i
;
409 struct tgsi_immediate
*immediate
;
411 if( maxsize
<= size
)
413 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
416 *immediate
= tgsi_build_immediate( header
);
418 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
420 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
421 union tgsi_immediate_data
*data
;
423 if( maxsize
<= size
)
425 data
= (union tgsi_immediate_data
*) &tokens
[size
];
428 *data
= tgsi_build_immediate_float32(
429 full_imm
->u
[i
].Float
,
441 struct tgsi_instruction
442 tgsi_default_instruction( void )
444 struct tgsi_instruction instruction
;
446 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
447 instruction
.NrTokens
= 0;
448 instruction
.Opcode
= TGSI_OPCODE_MOV
;
449 instruction
.Saturate
= TGSI_SAT_NONE
;
450 instruction
.Predicate
= 0;
451 instruction
.NumDstRegs
= 1;
452 instruction
.NumSrcRegs
= 1;
453 instruction
.Label
= 0;
454 instruction
.Texture
= 0;
455 instruction
.Padding
= 0;
460 static struct tgsi_instruction
461 tgsi_build_instruction(unsigned opcode
,
464 unsigned num_dst_regs
,
465 unsigned num_src_regs
,
466 struct tgsi_header
*header
)
468 struct tgsi_instruction instruction
;
470 assert (opcode
<= TGSI_OPCODE_LAST
);
471 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
472 assert (num_dst_regs
<= 3);
473 assert (num_src_regs
<= 15);
475 instruction
= tgsi_default_instruction();
476 instruction
.Opcode
= opcode
;
477 instruction
.Saturate
= saturate
;
478 instruction
.Predicate
= predicate
;
479 instruction
.NumDstRegs
= num_dst_regs
;
480 instruction
.NumSrcRegs
= num_src_regs
;
482 header_bodysize_grow( header
);
489 struct tgsi_instruction
*instruction
,
490 struct tgsi_header
*header
)
492 assert (instruction
->NrTokens
< 0xFF);
494 instruction
->NrTokens
++;
496 header_bodysize_grow( header
);
499 struct tgsi_instruction_predicate
500 tgsi_default_instruction_predicate(void)
502 struct tgsi_instruction_predicate instruction_predicate
;
504 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
505 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
506 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
507 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
508 instruction_predicate
.Negate
= 0;
509 instruction_predicate
.Index
= 0;
510 instruction_predicate
.Padding
= 0;
512 return instruction_predicate
;
515 static struct tgsi_instruction_predicate
516 tgsi_build_instruction_predicate(int index
,
522 struct tgsi_instruction
*instruction
,
523 struct tgsi_header
*header
)
525 struct tgsi_instruction_predicate instruction_predicate
;
527 instruction_predicate
= tgsi_default_instruction_predicate();
528 instruction_predicate
.SwizzleX
= swizzleX
;
529 instruction_predicate
.SwizzleY
= swizzleY
;
530 instruction_predicate
.SwizzleZ
= swizzleZ
;
531 instruction_predicate
.SwizzleW
= swizzleW
;
532 instruction_predicate
.Negate
= negate
;
533 instruction_predicate
.Index
= index
;
535 instruction_grow(instruction
, header
);
537 return instruction_predicate
;
540 static struct tgsi_instruction_label
541 tgsi_default_instruction_label( void )
543 struct tgsi_instruction_label instruction_label
;
545 instruction_label
.Label
= 0;
546 instruction_label
.Padding
= 0;
548 return instruction_label
;
551 static struct tgsi_instruction_label
552 tgsi_build_instruction_label(
554 struct tgsi_token
*prev_token
,
555 struct tgsi_instruction
*instruction
,
556 struct tgsi_header
*header
)
558 struct tgsi_instruction_label instruction_label
;
560 instruction_label
.Label
= label
;
561 instruction_label
.Padding
= 0;
562 instruction
->Label
= 1;
564 instruction_grow( instruction
, header
);
566 return instruction_label
;
569 static struct tgsi_instruction_texture
570 tgsi_default_instruction_texture( void )
572 struct tgsi_instruction_texture instruction_texture
;
574 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
575 instruction_texture
.Padding
= 0;
577 return instruction_texture
;
580 static struct tgsi_instruction_texture
581 tgsi_build_instruction_texture(
583 struct tgsi_token
*prev_token
,
584 struct tgsi_instruction
*instruction
,
585 struct tgsi_header
*header
)
587 struct tgsi_instruction_texture instruction_texture
;
589 instruction_texture
.Texture
= texture
;
590 instruction_texture
.Padding
= 0;
591 instruction
->Texture
= 1;
593 instruction_grow( instruction
, header
);
595 return instruction_texture
;
598 static struct tgsi_src_register
599 tgsi_default_src_register( void )
601 struct tgsi_src_register src_register
;
603 src_register
.File
= TGSI_FILE_NULL
;
604 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
605 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
606 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
607 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
608 src_register
.Negate
= 0;
609 src_register
.Absolute
= 0;
610 src_register
.Indirect
= 0;
611 src_register
.Dimension
= 0;
612 src_register
.Index
= 0;
617 static struct tgsi_src_register
618 tgsi_build_src_register(
629 struct tgsi_instruction
*instruction
,
630 struct tgsi_header
*header
)
632 struct tgsi_src_register src_register
;
634 assert( file
< TGSI_FILE_COUNT
);
635 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
636 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
637 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
638 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
639 assert( negate
<= 1 );
640 assert( index
>= -0x8000 && index
<= 0x7FFF );
642 src_register
.File
= file
;
643 src_register
.SwizzleX
= swizzle_x
;
644 src_register
.SwizzleY
= swizzle_y
;
645 src_register
.SwizzleZ
= swizzle_z
;
646 src_register
.SwizzleW
= swizzle_w
;
647 src_register
.Negate
= negate
;
648 src_register
.Absolute
= absolute
;
649 src_register
.Indirect
= indirect
;
650 src_register
.Dimension
= dimension
;
651 src_register
.Index
= index
;
653 instruction_grow( instruction
, header
);
658 static struct tgsi_dimension
659 tgsi_default_dimension( void )
661 struct tgsi_dimension dimension
;
663 dimension
.Indirect
= 0;
664 dimension
.Dimension
= 0;
665 dimension
.Padding
= 0;
671 static struct tgsi_full_src_register
672 tgsi_default_full_src_register( void )
674 struct tgsi_full_src_register full_src_register
;
676 full_src_register
.Register
= tgsi_default_src_register();
677 full_src_register
.Indirect
= tgsi_default_src_register();
678 full_src_register
.Dimension
= tgsi_default_dimension();
679 full_src_register
.DimIndirect
= tgsi_default_src_register();
681 return full_src_register
;
684 static struct tgsi_dimension
685 tgsi_build_dimension(
688 struct tgsi_instruction
*instruction
,
689 struct tgsi_header
*header
)
691 struct tgsi_dimension dimension
;
693 dimension
.Indirect
= indirect
;
694 dimension
.Dimension
= 0;
695 dimension
.Padding
= 0;
696 dimension
.Index
= index
;
698 instruction_grow( instruction
, header
);
703 static struct tgsi_dst_register
704 tgsi_default_dst_register( void )
706 struct tgsi_dst_register dst_register
;
708 dst_register
.File
= TGSI_FILE_NULL
;
709 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
710 dst_register
.Indirect
= 0;
711 dst_register
.Dimension
= 0;
712 dst_register
.Index
= 0;
713 dst_register
.Padding
= 0;
718 static struct tgsi_dst_register
719 tgsi_build_dst_register(
725 struct tgsi_instruction
*instruction
,
726 struct tgsi_header
*header
)
728 struct tgsi_dst_register dst_register
;
730 assert( file
< TGSI_FILE_COUNT
);
731 assert( mask
<= TGSI_WRITEMASK_XYZW
);
732 assert( index
>= -32768 && index
<= 32767 );
734 dst_register
.File
= file
;
735 dst_register
.WriteMask
= mask
;
736 dst_register
.Indirect
= indirect
;
737 dst_register
.Dimension
= dimension
;
738 dst_register
.Index
= index
;
739 dst_register
.Padding
= 0;
741 instruction_grow( instruction
, header
);
746 static struct tgsi_full_dst_register
747 tgsi_default_full_dst_register( void )
749 struct tgsi_full_dst_register full_dst_register
;
751 full_dst_register
.Register
= tgsi_default_dst_register();
752 full_dst_register
.Indirect
= tgsi_default_src_register();
753 full_dst_register
.Dimension
= tgsi_default_dimension();
754 full_dst_register
.DimIndirect
= tgsi_default_src_register();
756 return full_dst_register
;
759 struct tgsi_full_instruction
760 tgsi_default_full_instruction( void )
762 struct tgsi_full_instruction full_instruction
;
765 full_instruction
.Instruction
= tgsi_default_instruction();
766 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
767 full_instruction
.Label
= tgsi_default_instruction_label();
768 full_instruction
.Texture
= tgsi_default_instruction_texture();
769 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
770 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
772 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
773 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
776 return full_instruction
;
780 tgsi_build_full_instruction(
781 const struct tgsi_full_instruction
*full_inst
,
782 struct tgsi_token
*tokens
,
783 struct tgsi_header
*header
,
788 struct tgsi_instruction
*instruction
;
789 struct tgsi_token
*prev_token
;
791 if( maxsize
<= size
)
793 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
796 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
797 full_inst
->Instruction
.Saturate
,
798 full_inst
->Instruction
.Predicate
,
799 full_inst
->Instruction
.NumDstRegs
,
800 full_inst
->Instruction
.NumSrcRegs
,
802 prev_token
= (struct tgsi_token
*) instruction
;
804 if (full_inst
->Instruction
.Predicate
) {
805 struct tgsi_instruction_predicate
*instruction_predicate
;
807 if (maxsize
<= size
) {
810 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
813 *instruction_predicate
=
814 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
815 full_inst
->Predicate
.Negate
,
816 full_inst
->Predicate
.SwizzleX
,
817 full_inst
->Predicate
.SwizzleY
,
818 full_inst
->Predicate
.SwizzleZ
,
819 full_inst
->Predicate
.SwizzleW
,
824 if (full_inst
->Instruction
.Label
) {
825 struct tgsi_instruction_label
*instruction_label
;
827 if( maxsize
<= size
)
830 (struct tgsi_instruction_label
*) &tokens
[size
];
833 *instruction_label
= tgsi_build_instruction_label(
834 full_inst
->Label
.Label
,
838 prev_token
= (struct tgsi_token
*) instruction_label
;
841 if (full_inst
->Instruction
.Texture
) {
842 struct tgsi_instruction_texture
*instruction_texture
;
844 if( maxsize
<= size
)
846 instruction_texture
=
847 (struct tgsi_instruction_texture
*) &tokens
[size
];
850 *instruction_texture
= tgsi_build_instruction_texture(
851 full_inst
->Texture
.Texture
,
855 prev_token
= (struct tgsi_token
*) instruction_texture
;
858 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
859 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
860 struct tgsi_dst_register
*dst_register
;
861 struct tgsi_token
*prev_token
;
863 if( maxsize
<= size
)
865 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
868 *dst_register
= tgsi_build_dst_register(
870 reg
->Register
.WriteMask
,
871 reg
->Register
.Indirect
,
872 reg
->Register
.Dimension
,
876 prev_token
= (struct tgsi_token
*) dst_register
;
878 if( reg
->Register
.Indirect
) {
879 struct tgsi_src_register
*ind
;
881 if( maxsize
<= size
)
883 ind
= (struct tgsi_src_register
*) &tokens
[size
];
886 *ind
= tgsi_build_src_register(
888 reg
->Indirect
.SwizzleX
,
889 reg
->Indirect
.SwizzleY
,
890 reg
->Indirect
.SwizzleZ
,
891 reg
->Indirect
.SwizzleW
,
892 reg
->Indirect
.Negate
,
893 reg
->Indirect
.Absolute
,
894 reg
->Indirect
.Indirect
,
895 reg
->Indirect
.Dimension
,
901 if( reg
->Register
.Dimension
) {
902 struct tgsi_dimension
*dim
;
904 assert( !reg
->Dimension
.Dimension
);
906 if( maxsize
<= size
)
908 dim
= (struct tgsi_dimension
*) &tokens
[size
];
911 *dim
= tgsi_build_dimension(
912 reg
->Dimension
.Indirect
,
913 reg
->Dimension
.Index
,
917 if( reg
->Dimension
.Indirect
) {
918 struct tgsi_src_register
*ind
;
920 if( maxsize
<= size
)
922 ind
= (struct tgsi_src_register
*) &tokens
[size
];
925 *ind
= tgsi_build_src_register(
926 reg
->DimIndirect
.File
,
927 reg
->DimIndirect
.SwizzleX
,
928 reg
->DimIndirect
.SwizzleY
,
929 reg
->DimIndirect
.SwizzleZ
,
930 reg
->DimIndirect
.SwizzleW
,
931 reg
->DimIndirect
.Negate
,
932 reg
->DimIndirect
.Absolute
,
933 reg
->DimIndirect
.Indirect
,
934 reg
->DimIndirect
.Dimension
,
935 reg
->DimIndirect
.Index
,
942 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
943 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
944 struct tgsi_src_register
*src_register
;
945 struct tgsi_token
*prev_token
;
947 if( maxsize
<= size
)
949 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
952 *src_register
= tgsi_build_src_register(
954 reg
->Register
.SwizzleX
,
955 reg
->Register
.SwizzleY
,
956 reg
->Register
.SwizzleZ
,
957 reg
->Register
.SwizzleW
,
958 reg
->Register
.Negate
,
959 reg
->Register
.Absolute
,
960 reg
->Register
.Indirect
,
961 reg
->Register
.Dimension
,
965 prev_token
= (struct tgsi_token
*) src_register
;
967 if( reg
->Register
.Indirect
) {
968 struct tgsi_src_register
*ind
;
970 if( maxsize
<= size
)
972 ind
= (struct tgsi_src_register
*) &tokens
[size
];
975 *ind
= tgsi_build_src_register(
977 reg
->Indirect
.SwizzleX
,
978 reg
->Indirect
.SwizzleY
,
979 reg
->Indirect
.SwizzleZ
,
980 reg
->Indirect
.SwizzleW
,
981 reg
->Indirect
.Negate
,
982 reg
->Indirect
.Absolute
,
983 reg
->Indirect
.Indirect
,
984 reg
->Indirect
.Dimension
,
990 if( reg
->Register
.Dimension
) {
991 struct tgsi_dimension
*dim
;
993 assert( !reg
->Dimension
.Dimension
);
995 if( maxsize
<= size
)
997 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1000 *dim
= tgsi_build_dimension(
1001 reg
->Dimension
.Indirect
,
1002 reg
->Dimension
.Index
,
1006 if( reg
->Dimension
.Indirect
) {
1007 struct tgsi_src_register
*ind
;
1009 if( maxsize
<= size
)
1011 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1014 *ind
= tgsi_build_src_register(
1015 reg
->DimIndirect
.File
,
1016 reg
->DimIndirect
.SwizzleX
,
1017 reg
->DimIndirect
.SwizzleY
,
1018 reg
->DimIndirect
.SwizzleZ
,
1019 reg
->DimIndirect
.SwizzleW
,
1020 reg
->DimIndirect
.Negate
,
1021 reg
->DimIndirect
.Absolute
,
1022 reg
->DimIndirect
.Indirect
,
1023 reg
->DimIndirect
.Dimension
,
1024 reg
->DimIndirect
.Index
,
1034 static struct tgsi_property
1035 tgsi_default_property( void )
1037 struct tgsi_property property
;
1039 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1040 property
.NrTokens
= 1;
1041 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1042 property
.Padding
= 0;
1047 static struct tgsi_property
1048 tgsi_build_property(unsigned property_name
,
1049 struct tgsi_header
*header
)
1051 struct tgsi_property property
;
1053 property
= tgsi_default_property();
1054 property
.PropertyName
= property_name
;
1056 header_bodysize_grow( header
);
1062 struct tgsi_full_property
1063 tgsi_default_full_property( void )
1065 struct tgsi_full_property full_property
;
1067 full_property
.Property
= tgsi_default_property();
1068 memset(full_property
.u
, 0,
1069 sizeof(struct tgsi_property_data
) * 8);
1071 return full_property
;
1076 struct tgsi_property
*property
,
1077 struct tgsi_header
*header
)
1079 assert( property
->NrTokens
< 0xFF );
1081 property
->NrTokens
++;
1083 header_bodysize_grow( header
);
1086 static struct tgsi_property_data
1087 tgsi_build_property_data(
1089 struct tgsi_property
*property
,
1090 struct tgsi_header
*header
)
1092 struct tgsi_property_data property_data
;
1094 property_data
.Data
= value
;
1096 property_grow( property
, header
);
1098 return property_data
;
1102 tgsi_build_full_property(
1103 const struct tgsi_full_property
*full_prop
,
1104 struct tgsi_token
*tokens
,
1105 struct tgsi_header
*header
,
1108 unsigned size
= 0, i
;
1109 struct tgsi_property
*property
;
1111 if( maxsize
<= size
)
1113 property
= (struct tgsi_property
*) &tokens
[size
];
1116 *property
= tgsi_build_property(
1117 full_prop
->Property
.PropertyName
,
1120 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1122 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1123 struct tgsi_property_data
*data
;
1125 if( maxsize
<= size
)
1127 data
= (struct tgsi_property_data
*) &tokens
[size
];
1130 *data
= tgsi_build_property_data(
1131 full_prop
->u
[i
].Data
,