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_format.h"
30 #include "pipe/p_shader_tokens.h"
31 #include "tgsi_build.h"
32 #include "tgsi_parse.h"
40 tgsi_build_header( void )
42 struct tgsi_header header
;
44 header
.HeaderSize
= 1;
51 header_headersize_grow( struct tgsi_header
*header
)
53 assert( header
->HeaderSize
< 0xFF );
54 assert( header
->BodySize
== 0 );
60 header_bodysize_grow( struct tgsi_header
*header
)
62 assert( header
->BodySize
< 0xFFFFFF );
70 struct tgsi_header
*header
)
72 struct tgsi_processor processor
;
74 processor
.Processor
= type
;
75 processor
.Padding
= 0;
77 header_headersize_grow( header
);
88 struct tgsi_declaration
*declaration
,
89 struct tgsi_header
*header
)
91 assert( declaration
->NrTokens
< 0xFF );
93 declaration
->NrTokens
++;
95 header_bodysize_grow( header
);
98 static struct tgsi_declaration
99 tgsi_default_declaration( void )
101 struct tgsi_declaration declaration
;
103 declaration
.Type
= TGSI_TOKEN_TYPE_DECLARATION
;
104 declaration
.NrTokens
= 1;
105 declaration
.File
= TGSI_FILE_NULL
;
106 declaration
.UsageMask
= TGSI_WRITEMASK_XYZW
;
107 declaration
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
108 declaration
.Dimension
= 0;
109 declaration
.Semantic
= 0;
110 declaration
.Centroid
= 0;
111 declaration
.Invariant
= 0;
112 declaration
.CylindricalWrap
= 0;
117 static struct tgsi_declaration
118 tgsi_build_declaration(
121 unsigned interpolate
,
126 unsigned cylindrical_wrap
,
127 struct tgsi_header
*header
)
129 struct tgsi_declaration declaration
;
131 assert( file
< TGSI_FILE_COUNT
);
132 assert( interpolate
< TGSI_INTERPOLATE_COUNT
);
134 declaration
= tgsi_default_declaration();
135 declaration
.File
= file
;
136 declaration
.UsageMask
= usage_mask
;
137 declaration
.Interpolate
= interpolate
;
138 declaration
.Dimension
= dimension
;
139 declaration
.Semantic
= semantic
;
140 declaration
.Centroid
= centroid
;
141 declaration
.Invariant
= invariant
;
142 declaration
.CylindricalWrap
= cylindrical_wrap
;
144 header_bodysize_grow( header
);
149 static struct tgsi_declaration_range
150 tgsi_default_declaration_range( void )
152 struct tgsi_declaration_range dr
;
160 static struct tgsi_declaration_range
161 tgsi_build_declaration_range(
164 struct tgsi_declaration
*declaration
,
165 struct tgsi_header
*header
)
167 struct tgsi_declaration_range declaration_range
;
169 assert( last
>= first
);
170 assert( last
<= 0xFFFF );
172 declaration_range
.First
= first
;
173 declaration_range
.Last
= last
;
175 declaration_grow( declaration
, header
);
177 return declaration_range
;
180 static struct tgsi_declaration_dimension
181 tgsi_build_declaration_dimension(unsigned index_2d
,
182 struct tgsi_declaration
*declaration
,
183 struct tgsi_header
*header
)
185 struct tgsi_declaration_dimension dd
;
187 assert(index_2d
<= 0xFFFF);
189 dd
.Index2D
= index_2d
;
192 declaration_grow(declaration
, header
);
197 static struct tgsi_declaration_semantic
198 tgsi_default_declaration_semantic( void )
200 struct tgsi_declaration_semantic ds
;
202 ds
.Name
= TGSI_SEMANTIC_POSITION
;
209 static struct tgsi_declaration_semantic
210 tgsi_build_declaration_semantic(
211 unsigned semantic_name
,
212 unsigned semantic_index
,
213 struct tgsi_declaration
*declaration
,
214 struct tgsi_header
*header
)
216 struct tgsi_declaration_semantic ds
;
218 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
219 assert( semantic_index
<= 0xFFFF );
221 ds
.Name
= semantic_name
;
222 ds
.Index
= semantic_index
;
225 declaration_grow( declaration
, header
);
231 static struct tgsi_declaration_resource
232 tgsi_default_declaration_resource(void)
234 struct tgsi_declaration_resource declaration_resource
;
236 declaration_resource
.Resource
= TGSI_TEXTURE_UNKNOWN
;
237 declaration_resource
.ReturnTypeX
= PIPE_TYPE_UNORM
;
238 declaration_resource
.ReturnTypeY
= PIPE_TYPE_UNORM
;
239 declaration_resource
.ReturnTypeZ
= PIPE_TYPE_UNORM
;
240 declaration_resource
.ReturnTypeW
= PIPE_TYPE_UNORM
;
242 return declaration_resource
;
245 static struct tgsi_declaration_resource
246 tgsi_build_declaration_resource(unsigned texture
,
247 unsigned return_type_x
,
248 unsigned return_type_y
,
249 unsigned return_type_z
,
250 unsigned return_type_w
,
251 struct tgsi_declaration
*declaration
,
252 struct tgsi_header
*header
)
254 struct tgsi_declaration_resource declaration_resource
;
256 declaration_resource
= tgsi_default_declaration_resource();
257 declaration_resource
.Resource
= texture
;
258 declaration_resource
.ReturnTypeX
= return_type_x
;
259 declaration_resource
.ReturnTypeY
= return_type_y
;
260 declaration_resource
.ReturnTypeZ
= return_type_z
;
261 declaration_resource
.ReturnTypeW
= return_type_w
;
263 declaration_grow(declaration
, header
);
265 return declaration_resource
;
269 struct tgsi_full_declaration
270 tgsi_default_full_declaration( void )
272 struct tgsi_full_declaration full_declaration
;
274 full_declaration
.Declaration
= tgsi_default_declaration();
275 full_declaration
.Range
= tgsi_default_declaration_range();
276 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
277 full_declaration
.ImmediateData
.u
= NULL
;
278 full_declaration
.Resource
= tgsi_default_declaration_resource();
280 return full_declaration
;
284 tgsi_build_full_declaration(
285 const struct tgsi_full_declaration
*full_decl
,
286 struct tgsi_token
*tokens
,
287 struct tgsi_header
*header
,
291 struct tgsi_declaration
*declaration
;
292 struct tgsi_declaration_range
*dr
;
294 if( maxsize
<= size
)
296 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
299 *declaration
= tgsi_build_declaration(
300 full_decl
->Declaration
.File
,
301 full_decl
->Declaration
.UsageMask
,
302 full_decl
->Declaration
.Interpolate
,
303 full_decl
->Declaration
.Dimension
,
304 full_decl
->Declaration
.Semantic
,
305 full_decl
->Declaration
.Centroid
,
306 full_decl
->Declaration
.Invariant
,
307 full_decl
->Declaration
.CylindricalWrap
,
312 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
315 *dr
= tgsi_build_declaration_range(
316 full_decl
->Range
.First
,
317 full_decl
->Range
.Last
,
321 if (full_decl
->Declaration
.Dimension
) {
322 struct tgsi_declaration_dimension
*dd
;
324 if (maxsize
<= size
) {
327 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
330 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
335 if( full_decl
->Declaration
.Semantic
) {
336 struct tgsi_declaration_semantic
*ds
;
338 if( maxsize
<= size
)
340 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
343 *ds
= tgsi_build_declaration_semantic(
344 full_decl
->Semantic
.Name
,
345 full_decl
->Semantic
.Index
,
350 if (full_decl
->Declaration
.File
== TGSI_FILE_IMMEDIATE_ARRAY
) {
352 union tgsi_immediate_data
*data
;
354 for (i
= 0; i
<= dr
->Last
; ++i
) {
355 for (j
= 0; j
< 4; ++j
) {
356 unsigned idx
= i
*4 + j
;
359 data
= (union tgsi_immediate_data
*) &tokens
[size
];
362 *data
= full_decl
->ImmediateData
.u
[idx
];
363 declaration_grow( declaration
, header
);
368 if (full_decl
->Declaration
.File
== TGSI_FILE_RESOURCE
) {
369 struct tgsi_declaration_resource
*dr
;
371 if (maxsize
<= size
) {
374 dr
= (struct tgsi_declaration_resource
*)&tokens
[size
];
377 *dr
= tgsi_build_declaration_resource(full_decl
->Resource
.Resource
,
378 full_decl
->Resource
.ReturnTypeX
,
379 full_decl
->Resource
.ReturnTypeY
,
380 full_decl
->Resource
.ReturnTypeZ
,
381 full_decl
->Resource
.ReturnTypeW
,
393 static struct tgsi_immediate
394 tgsi_default_immediate( void )
396 struct tgsi_immediate immediate
;
398 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
399 immediate
.NrTokens
= 1;
400 immediate
.DataType
= TGSI_IMM_FLOAT32
;
401 immediate
.Padding
= 0;
406 static struct tgsi_immediate
407 tgsi_build_immediate(
408 struct tgsi_header
*header
)
410 struct tgsi_immediate immediate
;
412 immediate
= tgsi_default_immediate();
414 header_bodysize_grow( header
);
419 struct tgsi_full_immediate
420 tgsi_default_full_immediate( void )
422 struct tgsi_full_immediate fullimm
;
424 fullimm
.Immediate
= tgsi_default_immediate();
425 fullimm
.u
[0].Float
= 0.0f
;
426 fullimm
.u
[1].Float
= 0.0f
;
427 fullimm
.u
[2].Float
= 0.0f
;
428 fullimm
.u
[3].Float
= 0.0f
;
435 struct tgsi_immediate
*immediate
,
436 struct tgsi_header
*header
)
438 assert( immediate
->NrTokens
< 0xFF );
440 immediate
->NrTokens
++;
442 header_bodysize_grow( header
);
445 static union tgsi_immediate_data
446 tgsi_build_immediate_float32(
448 struct tgsi_immediate
*immediate
,
449 struct tgsi_header
*header
)
451 union tgsi_immediate_data immediate_data
;
453 immediate_data
.Float
= value
;
455 immediate_grow( immediate
, header
);
457 return immediate_data
;
461 tgsi_build_full_immediate(
462 const struct tgsi_full_immediate
*full_imm
,
463 struct tgsi_token
*tokens
,
464 struct tgsi_header
*header
,
467 unsigned size
= 0, i
;
468 struct tgsi_immediate
*immediate
;
470 if( maxsize
<= size
)
472 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
475 *immediate
= tgsi_build_immediate( header
);
477 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
479 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
480 union tgsi_immediate_data
*data
;
482 if( maxsize
<= size
)
484 data
= (union tgsi_immediate_data
*) &tokens
[size
];
487 *data
= tgsi_build_immediate_float32(
488 full_imm
->u
[i
].Float
,
500 struct tgsi_instruction
501 tgsi_default_instruction( void )
503 struct tgsi_instruction instruction
;
505 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
506 instruction
.NrTokens
= 0;
507 instruction
.Opcode
= TGSI_OPCODE_MOV
;
508 instruction
.Saturate
= TGSI_SAT_NONE
;
509 instruction
.Predicate
= 0;
510 instruction
.NumDstRegs
= 1;
511 instruction
.NumSrcRegs
= 1;
512 instruction
.Label
= 0;
513 instruction
.Texture
= 0;
514 instruction
.Padding
= 0;
519 static struct tgsi_instruction
520 tgsi_build_instruction(unsigned opcode
,
523 unsigned num_dst_regs
,
524 unsigned num_src_regs
,
525 struct tgsi_header
*header
)
527 struct tgsi_instruction instruction
;
529 assert (opcode
<= TGSI_OPCODE_LAST
);
530 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
531 assert (num_dst_regs
<= 3);
532 assert (num_src_regs
<= 15);
534 instruction
= tgsi_default_instruction();
535 instruction
.Opcode
= opcode
;
536 instruction
.Saturate
= saturate
;
537 instruction
.Predicate
= predicate
;
538 instruction
.NumDstRegs
= num_dst_regs
;
539 instruction
.NumSrcRegs
= num_src_regs
;
541 header_bodysize_grow( header
);
548 struct tgsi_instruction
*instruction
,
549 struct tgsi_header
*header
)
551 assert (instruction
->NrTokens
< 0xFF);
553 instruction
->NrTokens
++;
555 header_bodysize_grow( header
);
558 struct tgsi_instruction_predicate
559 tgsi_default_instruction_predicate(void)
561 struct tgsi_instruction_predicate instruction_predicate
;
563 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
564 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
565 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
566 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
567 instruction_predicate
.Negate
= 0;
568 instruction_predicate
.Index
= 0;
569 instruction_predicate
.Padding
= 0;
571 return instruction_predicate
;
574 static struct tgsi_instruction_predicate
575 tgsi_build_instruction_predicate(int index
,
581 struct tgsi_instruction
*instruction
,
582 struct tgsi_header
*header
)
584 struct tgsi_instruction_predicate instruction_predicate
;
586 instruction_predicate
= tgsi_default_instruction_predicate();
587 instruction_predicate
.SwizzleX
= swizzleX
;
588 instruction_predicate
.SwizzleY
= swizzleY
;
589 instruction_predicate
.SwizzleZ
= swizzleZ
;
590 instruction_predicate
.SwizzleW
= swizzleW
;
591 instruction_predicate
.Negate
= negate
;
592 instruction_predicate
.Index
= index
;
594 instruction_grow(instruction
, header
);
596 return instruction_predicate
;
599 static struct tgsi_instruction_label
600 tgsi_default_instruction_label( void )
602 struct tgsi_instruction_label instruction_label
;
604 instruction_label
.Label
= 0;
605 instruction_label
.Padding
= 0;
607 return instruction_label
;
610 static struct tgsi_instruction_label
611 tgsi_build_instruction_label(
613 struct tgsi_token
*prev_token
,
614 struct tgsi_instruction
*instruction
,
615 struct tgsi_header
*header
)
617 struct tgsi_instruction_label instruction_label
;
619 instruction_label
.Label
= label
;
620 instruction_label
.Padding
= 0;
621 instruction
->Label
= 1;
623 instruction_grow( instruction
, header
);
625 return instruction_label
;
628 static struct tgsi_instruction_texture
629 tgsi_default_instruction_texture( void )
631 struct tgsi_instruction_texture instruction_texture
;
633 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
634 instruction_texture
.NumOffsets
= 0;
635 instruction_texture
.Padding
= 0;
637 return instruction_texture
;
640 static struct tgsi_instruction_texture
641 tgsi_build_instruction_texture(
643 unsigned num_offsets
,
644 struct tgsi_token
*prev_token
,
645 struct tgsi_instruction
*instruction
,
646 struct tgsi_header
*header
)
648 struct tgsi_instruction_texture instruction_texture
;
650 instruction_texture
.Texture
= texture
;
651 instruction_texture
.NumOffsets
= num_offsets
;
652 instruction_texture
.Padding
= 0;
653 instruction
->Texture
= 1;
655 instruction_grow( instruction
, header
);
657 return instruction_texture
;
661 static struct tgsi_texture_offset
662 tgsi_default_texture_offset( void )
664 struct tgsi_texture_offset texture_offset
;
666 texture_offset
.Index
= 0;
667 texture_offset
.File
= 0;
668 texture_offset
.SwizzleX
= 0;
669 texture_offset
.SwizzleY
= 0;
670 texture_offset
.SwizzleZ
= 0;
671 texture_offset
.Padding
= 0;
673 return texture_offset
;
676 static struct tgsi_texture_offset
677 tgsi_build_texture_offset(
678 int index
, int file
, int swizzle_x
, int swizzle_y
, int swizzle_z
,
679 struct tgsi_token
*prev_token
,
680 struct tgsi_instruction
*instruction
,
681 struct tgsi_header
*header
)
683 struct tgsi_texture_offset texture_offset
;
685 texture_offset
.Index
= index
;
686 texture_offset
.File
= file
;
687 texture_offset
.SwizzleX
= swizzle_x
;
688 texture_offset
.SwizzleY
= swizzle_y
;
689 texture_offset
.SwizzleZ
= swizzle_z
;
690 texture_offset
.Padding
= 0;
692 instruction_grow( instruction
, header
);
694 return texture_offset
;
697 static struct tgsi_src_register
698 tgsi_default_src_register( void )
700 struct tgsi_src_register src_register
;
702 src_register
.File
= TGSI_FILE_NULL
;
703 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
704 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
705 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
706 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
707 src_register
.Negate
= 0;
708 src_register
.Absolute
= 0;
709 src_register
.Indirect
= 0;
710 src_register
.Dimension
= 0;
711 src_register
.Index
= 0;
716 static struct tgsi_src_register
717 tgsi_build_src_register(
728 struct tgsi_instruction
*instruction
,
729 struct tgsi_header
*header
)
731 struct tgsi_src_register src_register
;
733 assert( file
< TGSI_FILE_COUNT
);
734 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
735 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
736 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
737 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
738 assert( negate
<= 1 );
739 assert( index
>= -0x8000 && index
<= 0x7FFF );
741 src_register
.File
= file
;
742 src_register
.SwizzleX
= swizzle_x
;
743 src_register
.SwizzleY
= swizzle_y
;
744 src_register
.SwizzleZ
= swizzle_z
;
745 src_register
.SwizzleW
= swizzle_w
;
746 src_register
.Negate
= negate
;
747 src_register
.Absolute
= absolute
;
748 src_register
.Indirect
= indirect
;
749 src_register
.Dimension
= dimension
;
750 src_register
.Index
= index
;
752 instruction_grow( instruction
, header
);
757 static struct tgsi_dimension
758 tgsi_default_dimension( void )
760 struct tgsi_dimension dimension
;
762 dimension
.Indirect
= 0;
763 dimension
.Dimension
= 0;
764 dimension
.Padding
= 0;
770 static struct tgsi_full_src_register
771 tgsi_default_full_src_register( void )
773 struct tgsi_full_src_register full_src_register
;
775 full_src_register
.Register
= tgsi_default_src_register();
776 full_src_register
.Indirect
= tgsi_default_src_register();
777 full_src_register
.Dimension
= tgsi_default_dimension();
778 full_src_register
.DimIndirect
= tgsi_default_src_register();
780 return full_src_register
;
783 static struct tgsi_dimension
784 tgsi_build_dimension(
787 struct tgsi_instruction
*instruction
,
788 struct tgsi_header
*header
)
790 struct tgsi_dimension dimension
;
792 dimension
.Indirect
= indirect
;
793 dimension
.Dimension
= 0;
794 dimension
.Padding
= 0;
795 dimension
.Index
= index
;
797 instruction_grow( instruction
, header
);
802 static struct tgsi_dst_register
803 tgsi_default_dst_register( void )
805 struct tgsi_dst_register dst_register
;
807 dst_register
.File
= TGSI_FILE_NULL
;
808 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
809 dst_register
.Indirect
= 0;
810 dst_register
.Dimension
= 0;
811 dst_register
.Index
= 0;
812 dst_register
.Padding
= 0;
817 static struct tgsi_dst_register
818 tgsi_build_dst_register(
824 struct tgsi_instruction
*instruction
,
825 struct tgsi_header
*header
)
827 struct tgsi_dst_register dst_register
;
829 assert( file
< TGSI_FILE_COUNT
);
830 assert( mask
<= TGSI_WRITEMASK_XYZW
);
831 assert( index
>= -32768 && index
<= 32767 );
833 dst_register
.File
= file
;
834 dst_register
.WriteMask
= mask
;
835 dst_register
.Indirect
= indirect
;
836 dst_register
.Dimension
= dimension
;
837 dst_register
.Index
= index
;
838 dst_register
.Padding
= 0;
840 instruction_grow( instruction
, header
);
845 static struct tgsi_full_dst_register
846 tgsi_default_full_dst_register( void )
848 struct tgsi_full_dst_register full_dst_register
;
850 full_dst_register
.Register
= tgsi_default_dst_register();
851 full_dst_register
.Indirect
= tgsi_default_src_register();
852 full_dst_register
.Dimension
= tgsi_default_dimension();
853 full_dst_register
.DimIndirect
= tgsi_default_src_register();
855 return full_dst_register
;
858 struct tgsi_full_instruction
859 tgsi_default_full_instruction( void )
861 struct tgsi_full_instruction full_instruction
;
864 full_instruction
.Instruction
= tgsi_default_instruction();
865 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
866 full_instruction
.Label
= tgsi_default_instruction_label();
867 full_instruction
.Texture
= tgsi_default_instruction_texture();
868 for( i
= 0; i
< TGSI_FULL_MAX_TEX_OFFSETS
; i
++ ) {
869 full_instruction
.TexOffsets
[i
] = tgsi_default_texture_offset();
871 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
872 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
874 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
875 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
878 return full_instruction
;
882 tgsi_build_full_instruction(
883 const struct tgsi_full_instruction
*full_inst
,
884 struct tgsi_token
*tokens
,
885 struct tgsi_header
*header
,
890 struct tgsi_instruction
*instruction
;
891 struct tgsi_token
*prev_token
;
893 if( maxsize
<= size
)
895 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
898 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
899 full_inst
->Instruction
.Saturate
,
900 full_inst
->Instruction
.Predicate
,
901 full_inst
->Instruction
.NumDstRegs
,
902 full_inst
->Instruction
.NumSrcRegs
,
904 prev_token
= (struct tgsi_token
*) instruction
;
906 if (full_inst
->Instruction
.Predicate
) {
907 struct tgsi_instruction_predicate
*instruction_predicate
;
909 if (maxsize
<= size
) {
912 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
915 *instruction_predicate
=
916 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
917 full_inst
->Predicate
.Negate
,
918 full_inst
->Predicate
.SwizzleX
,
919 full_inst
->Predicate
.SwizzleY
,
920 full_inst
->Predicate
.SwizzleZ
,
921 full_inst
->Predicate
.SwizzleW
,
926 if (full_inst
->Instruction
.Label
) {
927 struct tgsi_instruction_label
*instruction_label
;
929 if( maxsize
<= size
)
932 (struct tgsi_instruction_label
*) &tokens
[size
];
935 *instruction_label
= tgsi_build_instruction_label(
936 full_inst
->Label
.Label
,
940 prev_token
= (struct tgsi_token
*) instruction_label
;
943 if (full_inst
->Instruction
.Texture
) {
944 struct tgsi_instruction_texture
*instruction_texture
;
946 if( maxsize
<= size
)
948 instruction_texture
=
949 (struct tgsi_instruction_texture
*) &tokens
[size
];
952 *instruction_texture
= tgsi_build_instruction_texture(
953 full_inst
->Texture
.Texture
,
954 full_inst
->Texture
.NumOffsets
,
958 prev_token
= (struct tgsi_token
*) instruction_texture
;
960 for (i
= 0; i
< full_inst
->Texture
.NumOffsets
; i
++) {
961 struct tgsi_texture_offset
*texture_offset
;
963 if ( maxsize
<= size
)
965 texture_offset
= (struct tgsi_texture_offset
*)&tokens
[size
];
967 *texture_offset
= tgsi_build_texture_offset(
968 full_inst
->TexOffsets
[i
].Index
,
969 full_inst
->TexOffsets
[i
].File
,
970 full_inst
->TexOffsets
[i
].SwizzleX
,
971 full_inst
->TexOffsets
[i
].SwizzleY
,
972 full_inst
->TexOffsets
[i
].SwizzleZ
,
976 prev_token
= (struct tgsi_token
*) texture_offset
;
979 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
980 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
981 struct tgsi_dst_register
*dst_register
;
983 if( maxsize
<= size
)
985 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
988 *dst_register
= tgsi_build_dst_register(
990 reg
->Register
.WriteMask
,
991 reg
->Register
.Indirect
,
992 reg
->Register
.Dimension
,
997 if( reg
->Register
.Indirect
) {
998 struct tgsi_src_register
*ind
;
1000 if( maxsize
<= size
)
1002 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1005 *ind
= tgsi_build_src_register(
1007 reg
->Indirect
.SwizzleX
,
1008 reg
->Indirect
.SwizzleY
,
1009 reg
->Indirect
.SwizzleZ
,
1010 reg
->Indirect
.SwizzleW
,
1011 reg
->Indirect
.Negate
,
1012 reg
->Indirect
.Absolute
,
1013 reg
->Indirect
.Indirect
,
1014 reg
->Indirect
.Dimension
,
1015 reg
->Indirect
.Index
,
1020 if( reg
->Register
.Dimension
) {
1021 struct tgsi_dimension
*dim
;
1023 assert( !reg
->Dimension
.Dimension
);
1025 if( maxsize
<= size
)
1027 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1030 *dim
= tgsi_build_dimension(
1031 reg
->Dimension
.Indirect
,
1032 reg
->Dimension
.Index
,
1036 if( reg
->Dimension
.Indirect
) {
1037 struct tgsi_src_register
*ind
;
1039 if( maxsize
<= size
)
1041 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1044 *ind
= tgsi_build_src_register(
1045 reg
->DimIndirect
.File
,
1046 reg
->DimIndirect
.SwizzleX
,
1047 reg
->DimIndirect
.SwizzleY
,
1048 reg
->DimIndirect
.SwizzleZ
,
1049 reg
->DimIndirect
.SwizzleW
,
1050 reg
->DimIndirect
.Negate
,
1051 reg
->DimIndirect
.Absolute
,
1052 reg
->DimIndirect
.Indirect
,
1053 reg
->DimIndirect
.Dimension
,
1054 reg
->DimIndirect
.Index
,
1061 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
1062 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
1063 struct tgsi_src_register
*src_register
;
1065 if( maxsize
<= size
)
1067 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
1070 *src_register
= tgsi_build_src_register(
1072 reg
->Register
.SwizzleX
,
1073 reg
->Register
.SwizzleY
,
1074 reg
->Register
.SwizzleZ
,
1075 reg
->Register
.SwizzleW
,
1076 reg
->Register
.Negate
,
1077 reg
->Register
.Absolute
,
1078 reg
->Register
.Indirect
,
1079 reg
->Register
.Dimension
,
1080 reg
->Register
.Index
,
1084 if( reg
->Register
.Indirect
) {
1085 struct tgsi_src_register
*ind
;
1087 if( maxsize
<= size
)
1089 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1092 *ind
= tgsi_build_src_register(
1094 reg
->Indirect
.SwizzleX
,
1095 reg
->Indirect
.SwizzleY
,
1096 reg
->Indirect
.SwizzleZ
,
1097 reg
->Indirect
.SwizzleW
,
1098 reg
->Indirect
.Negate
,
1099 reg
->Indirect
.Absolute
,
1100 reg
->Indirect
.Indirect
,
1101 reg
->Indirect
.Dimension
,
1102 reg
->Indirect
.Index
,
1107 if( reg
->Register
.Dimension
) {
1108 struct tgsi_dimension
*dim
;
1110 assert( !reg
->Dimension
.Dimension
);
1112 if( maxsize
<= size
)
1114 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1117 *dim
= tgsi_build_dimension(
1118 reg
->Dimension
.Indirect
,
1119 reg
->Dimension
.Index
,
1123 if( reg
->Dimension
.Indirect
) {
1124 struct tgsi_src_register
*ind
;
1126 if( maxsize
<= size
)
1128 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1131 *ind
= tgsi_build_src_register(
1132 reg
->DimIndirect
.File
,
1133 reg
->DimIndirect
.SwizzleX
,
1134 reg
->DimIndirect
.SwizzleY
,
1135 reg
->DimIndirect
.SwizzleZ
,
1136 reg
->DimIndirect
.SwizzleW
,
1137 reg
->DimIndirect
.Negate
,
1138 reg
->DimIndirect
.Absolute
,
1139 reg
->DimIndirect
.Indirect
,
1140 reg
->DimIndirect
.Dimension
,
1141 reg
->DimIndirect
.Index
,
1151 static struct tgsi_property
1152 tgsi_default_property( void )
1154 struct tgsi_property property
;
1156 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1157 property
.NrTokens
= 1;
1158 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1159 property
.Padding
= 0;
1164 static struct tgsi_property
1165 tgsi_build_property(unsigned property_name
,
1166 struct tgsi_header
*header
)
1168 struct tgsi_property property
;
1170 property
= tgsi_default_property();
1171 property
.PropertyName
= property_name
;
1173 header_bodysize_grow( header
);
1179 struct tgsi_full_property
1180 tgsi_default_full_property( void )
1182 struct tgsi_full_property full_property
;
1184 full_property
.Property
= tgsi_default_property();
1185 memset(full_property
.u
, 0,
1186 sizeof(struct tgsi_property_data
) * 8);
1188 return full_property
;
1193 struct tgsi_property
*property
,
1194 struct tgsi_header
*header
)
1196 assert( property
->NrTokens
< 0xFF );
1198 property
->NrTokens
++;
1200 header_bodysize_grow( header
);
1203 static struct tgsi_property_data
1204 tgsi_build_property_data(
1206 struct tgsi_property
*property
,
1207 struct tgsi_header
*header
)
1209 struct tgsi_property_data property_data
;
1211 property_data
.Data
= value
;
1213 property_grow( property
, header
);
1215 return property_data
;
1219 tgsi_build_full_property(
1220 const struct tgsi_full_property
*full_prop
,
1221 struct tgsi_token
*tokens
,
1222 struct tgsi_header
*header
,
1225 unsigned size
= 0, i
;
1226 struct tgsi_property
*property
;
1228 if( maxsize
<= size
)
1230 property
= (struct tgsi_property
*) &tokens
[size
];
1233 *property
= tgsi_build_property(
1234 full_prop
->Property
.PropertyName
,
1237 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1239 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1240 struct tgsi_property_data
*data
;
1242 if( maxsize
<= size
)
1244 data
= (struct tgsi_property_data
*) &tokens
[size
];
1247 *data
= tgsi_build_property_data(
1248 full_prop
->u
[i
].Data
,