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
= 0;
108 declaration
.Dimension
= 0;
109 declaration
.Semantic
= 0;
110 declaration
.Invariant
= 0;
111 declaration
.Local
= 0;
112 declaration
.Array
= 0;
113 declaration
.Padding
= 0;
118 static struct tgsi_declaration
119 tgsi_build_declaration(
122 unsigned interpolate
,
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
.Invariant
= invariant
;
141 declaration
.Local
= local
;
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_interp
197 tgsi_default_declaration_interp( void )
199 struct tgsi_declaration_interp di
;
201 di
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
203 di
.CylindricalWrap
= 0;
209 static struct tgsi_declaration_interp
210 tgsi_build_declaration_interp(unsigned interpolate
,
212 unsigned cylindrical_wrap
,
213 struct tgsi_declaration
*declaration
,
214 struct tgsi_header
*header
)
216 struct tgsi_declaration_interp di
;
218 di
.Interpolate
= interpolate
;
219 di
.Centroid
= centroid
;
220 di
.CylindricalWrap
= cylindrical_wrap
;
223 declaration_grow(declaration
, header
);
228 static struct tgsi_declaration_semantic
229 tgsi_default_declaration_semantic( void )
231 struct tgsi_declaration_semantic ds
;
233 ds
.Name
= TGSI_SEMANTIC_POSITION
;
240 static struct tgsi_declaration_semantic
241 tgsi_build_declaration_semantic(
242 unsigned semantic_name
,
243 unsigned semantic_index
,
244 struct tgsi_declaration
*declaration
,
245 struct tgsi_header
*header
)
247 struct tgsi_declaration_semantic ds
;
249 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
250 assert( semantic_index
<= 0xFFFF );
252 ds
.Name
= semantic_name
;
253 ds
.Index
= semantic_index
;
256 declaration_grow( declaration
, header
);
261 static struct tgsi_declaration_resource
262 tgsi_default_declaration_resource(void)
264 struct tgsi_declaration_resource dr
;
266 dr
.Resource
= TGSI_TEXTURE_BUFFER
;
274 static struct tgsi_declaration_resource
275 tgsi_build_declaration_resource(unsigned texture
,
278 struct tgsi_declaration
*declaration
,
279 struct tgsi_header
*header
)
281 struct tgsi_declaration_resource dr
;
283 dr
= tgsi_default_declaration_resource();
284 dr
.Resource
= texture
;
286 dr
.Writable
= writable
;
288 declaration_grow(declaration
, header
);
293 static struct tgsi_declaration_sampler_view
294 tgsi_default_declaration_sampler_view(void)
296 struct tgsi_declaration_sampler_view dsv
;
298 dsv
.Resource
= TGSI_TEXTURE_BUFFER
;
299 dsv
.ReturnTypeX
= PIPE_TYPE_UNORM
;
300 dsv
.ReturnTypeY
= PIPE_TYPE_UNORM
;
301 dsv
.ReturnTypeZ
= PIPE_TYPE_UNORM
;
302 dsv
.ReturnTypeW
= PIPE_TYPE_UNORM
;
307 static struct tgsi_declaration_sampler_view
308 tgsi_build_declaration_sampler_view(unsigned texture
,
309 unsigned return_type_x
,
310 unsigned return_type_y
,
311 unsigned return_type_z
,
312 unsigned return_type_w
,
313 struct tgsi_declaration
*declaration
,
314 struct tgsi_header
*header
)
316 struct tgsi_declaration_sampler_view dsv
;
318 dsv
= tgsi_default_declaration_sampler_view();
319 dsv
.Resource
= texture
;
320 dsv
.ReturnTypeX
= return_type_x
;
321 dsv
.ReturnTypeY
= return_type_y
;
322 dsv
.ReturnTypeZ
= return_type_z
;
323 dsv
.ReturnTypeW
= return_type_w
;
325 declaration_grow(declaration
, header
);
331 static struct tgsi_declaration_array
332 tgsi_default_declaration_array( void )
334 struct tgsi_declaration_array a
;
342 struct tgsi_full_declaration
343 tgsi_default_full_declaration( void )
345 struct tgsi_full_declaration full_declaration
;
347 full_declaration
.Declaration
= tgsi_default_declaration();
348 full_declaration
.Range
= tgsi_default_declaration_range();
349 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
350 full_declaration
.Interp
= tgsi_default_declaration_interp();
351 full_declaration
.Resource
= tgsi_default_declaration_resource();
352 full_declaration
.SamplerView
= tgsi_default_declaration_sampler_view();
353 full_declaration
.Array
= tgsi_default_declaration_array();
355 return full_declaration
;
359 tgsi_build_full_declaration(
360 const struct tgsi_full_declaration
*full_decl
,
361 struct tgsi_token
*tokens
,
362 struct tgsi_header
*header
,
366 struct tgsi_declaration
*declaration
;
367 struct tgsi_declaration_range
*dr
;
369 if( maxsize
<= size
)
371 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
374 *declaration
= tgsi_build_declaration(
375 full_decl
->Declaration
.File
,
376 full_decl
->Declaration
.UsageMask
,
377 full_decl
->Declaration
.Interpolate
,
378 full_decl
->Declaration
.Dimension
,
379 full_decl
->Declaration
.Semantic
,
380 full_decl
->Declaration
.Invariant
,
381 full_decl
->Declaration
.Local
,
386 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
389 *dr
= tgsi_build_declaration_range(
390 full_decl
->Range
.First
,
391 full_decl
->Range
.Last
,
395 if (full_decl
->Declaration
.Dimension
) {
396 struct tgsi_declaration_dimension
*dd
;
398 if (maxsize
<= size
) {
401 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
404 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
409 if (full_decl
->Declaration
.Interpolate
) {
410 struct tgsi_declaration_interp
*di
;
412 if (maxsize
<= size
) {
415 di
= (struct tgsi_declaration_interp
*)&tokens
[size
];
418 *di
= tgsi_build_declaration_interp(full_decl
->Interp
.Interpolate
,
419 full_decl
->Interp
.Centroid
,
420 full_decl
->Interp
.CylindricalWrap
,
425 if( full_decl
->Declaration
.Semantic
) {
426 struct tgsi_declaration_semantic
*ds
;
428 if( maxsize
<= size
)
430 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
433 *ds
= tgsi_build_declaration_semantic(
434 full_decl
->Semantic
.Name
,
435 full_decl
->Semantic
.Index
,
440 if (full_decl
->Declaration
.File
== TGSI_FILE_RESOURCE
) {
441 struct tgsi_declaration_resource
*dr
;
443 if (maxsize
<= size
) {
446 dr
= (struct tgsi_declaration_resource
*)&tokens
[size
];
449 *dr
= tgsi_build_declaration_resource(full_decl
->Resource
.Resource
,
450 full_decl
->Resource
.Raw
,
451 full_decl
->Resource
.Writable
,
456 if (full_decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
457 struct tgsi_declaration_sampler_view
*dsv
;
459 if (maxsize
<= size
) {
462 dsv
= (struct tgsi_declaration_sampler_view
*)&tokens
[size
];
465 *dsv
= tgsi_build_declaration_sampler_view(
466 full_decl
->SamplerView
.Resource
,
467 full_decl
->SamplerView
.ReturnTypeX
,
468 full_decl
->SamplerView
.ReturnTypeY
,
469 full_decl
->SamplerView
.ReturnTypeZ
,
470 full_decl
->SamplerView
.ReturnTypeW
,
482 static struct tgsi_immediate
483 tgsi_default_immediate( void )
485 struct tgsi_immediate immediate
;
487 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
488 immediate
.NrTokens
= 1;
489 immediate
.DataType
= TGSI_IMM_FLOAT32
;
490 immediate
.Padding
= 0;
495 static struct tgsi_immediate
496 tgsi_build_immediate(
497 struct tgsi_header
*header
,
500 struct tgsi_immediate immediate
;
502 immediate
= tgsi_default_immediate();
503 immediate
.DataType
= type
;
505 header_bodysize_grow( header
);
510 struct tgsi_full_immediate
511 tgsi_default_full_immediate( void )
513 struct tgsi_full_immediate fullimm
;
515 fullimm
.Immediate
= tgsi_default_immediate();
516 fullimm
.u
[0].Float
= 0.0f
;
517 fullimm
.u
[1].Float
= 0.0f
;
518 fullimm
.u
[2].Float
= 0.0f
;
519 fullimm
.u
[3].Float
= 0.0f
;
526 struct tgsi_immediate
*immediate
,
527 struct tgsi_header
*header
)
529 assert( immediate
->NrTokens
< 0xFF );
531 immediate
->NrTokens
++;
533 header_bodysize_grow( header
);
537 tgsi_build_full_immediate(
538 const struct tgsi_full_immediate
*full_imm
,
539 struct tgsi_token
*tokens
,
540 struct tgsi_header
*header
,
543 unsigned size
= 0, i
;
544 struct tgsi_immediate
*immediate
;
546 if( maxsize
<= size
)
548 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
551 *immediate
= tgsi_build_immediate( header
, full_imm
->Immediate
.DataType
);
553 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
555 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
556 union tgsi_immediate_data
*data
;
558 if( maxsize
<= size
)
561 data
= (union tgsi_immediate_data
*) &tokens
[size
];
562 *data
= full_imm
->u
[i
];
564 immediate_grow( immediate
, header
);
575 struct tgsi_instruction
576 tgsi_default_instruction( void )
578 struct tgsi_instruction instruction
;
580 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
581 instruction
.NrTokens
= 0;
582 instruction
.Opcode
= TGSI_OPCODE_MOV
;
583 instruction
.Saturate
= TGSI_SAT_NONE
;
584 instruction
.Predicate
= 0;
585 instruction
.NumDstRegs
= 1;
586 instruction
.NumSrcRegs
= 1;
587 instruction
.Label
= 0;
588 instruction
.Texture
= 0;
589 instruction
.Padding
= 0;
594 static struct tgsi_instruction
595 tgsi_build_instruction(unsigned opcode
,
598 unsigned num_dst_regs
,
599 unsigned num_src_regs
,
600 struct tgsi_header
*header
)
602 struct tgsi_instruction instruction
;
604 assert (opcode
<= TGSI_OPCODE_LAST
);
605 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
606 assert (num_dst_regs
<= 3);
607 assert (num_src_regs
<= 15);
609 instruction
= tgsi_default_instruction();
610 instruction
.Opcode
= opcode
;
611 instruction
.Saturate
= saturate
;
612 instruction
.Predicate
= predicate
;
613 instruction
.NumDstRegs
= num_dst_regs
;
614 instruction
.NumSrcRegs
= num_src_regs
;
616 header_bodysize_grow( header
);
623 struct tgsi_instruction
*instruction
,
624 struct tgsi_header
*header
)
626 assert (instruction
->NrTokens
< 0xFF);
628 instruction
->NrTokens
++;
630 header_bodysize_grow( header
);
633 struct tgsi_instruction_predicate
634 tgsi_default_instruction_predicate(void)
636 struct tgsi_instruction_predicate instruction_predicate
;
638 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
639 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
640 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
641 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
642 instruction_predicate
.Negate
= 0;
643 instruction_predicate
.Index
= 0;
644 instruction_predicate
.Padding
= 0;
646 return instruction_predicate
;
649 static struct tgsi_instruction_predicate
650 tgsi_build_instruction_predicate(int index
,
656 struct tgsi_instruction
*instruction
,
657 struct tgsi_header
*header
)
659 struct tgsi_instruction_predicate instruction_predicate
;
661 instruction_predicate
= tgsi_default_instruction_predicate();
662 instruction_predicate
.SwizzleX
= swizzleX
;
663 instruction_predicate
.SwizzleY
= swizzleY
;
664 instruction_predicate
.SwizzleZ
= swizzleZ
;
665 instruction_predicate
.SwizzleW
= swizzleW
;
666 instruction_predicate
.Negate
= negate
;
667 instruction_predicate
.Index
= index
;
669 instruction_grow(instruction
, header
);
671 return instruction_predicate
;
674 static struct tgsi_instruction_label
675 tgsi_default_instruction_label( void )
677 struct tgsi_instruction_label instruction_label
;
679 instruction_label
.Label
= 0;
680 instruction_label
.Padding
= 0;
682 return instruction_label
;
685 static struct tgsi_instruction_label
686 tgsi_build_instruction_label(
688 struct tgsi_token
*prev_token
,
689 struct tgsi_instruction
*instruction
,
690 struct tgsi_header
*header
)
692 struct tgsi_instruction_label instruction_label
;
694 instruction_label
.Label
= label
;
695 instruction_label
.Padding
= 0;
696 instruction
->Label
= 1;
698 instruction_grow( instruction
, header
);
700 return instruction_label
;
703 static struct tgsi_instruction_texture
704 tgsi_default_instruction_texture( void )
706 struct tgsi_instruction_texture instruction_texture
;
708 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
709 instruction_texture
.NumOffsets
= 0;
710 instruction_texture
.Padding
= 0;
712 return instruction_texture
;
715 static struct tgsi_instruction_texture
716 tgsi_build_instruction_texture(
718 unsigned num_offsets
,
719 struct tgsi_token
*prev_token
,
720 struct tgsi_instruction
*instruction
,
721 struct tgsi_header
*header
)
723 struct tgsi_instruction_texture instruction_texture
;
725 instruction_texture
.Texture
= texture
;
726 instruction_texture
.NumOffsets
= num_offsets
;
727 instruction_texture
.Padding
= 0;
728 instruction
->Texture
= 1;
730 instruction_grow( instruction
, header
);
732 return instruction_texture
;
736 static struct tgsi_texture_offset
737 tgsi_default_texture_offset( void )
739 struct tgsi_texture_offset texture_offset
;
741 texture_offset
.Index
= 0;
742 texture_offset
.File
= 0;
743 texture_offset
.SwizzleX
= 0;
744 texture_offset
.SwizzleY
= 0;
745 texture_offset
.SwizzleZ
= 0;
746 texture_offset
.Padding
= 0;
748 return texture_offset
;
751 static struct tgsi_texture_offset
752 tgsi_build_texture_offset(
753 int index
, int file
, int swizzle_x
, int swizzle_y
, int swizzle_z
,
754 struct tgsi_token
*prev_token
,
755 struct tgsi_instruction
*instruction
,
756 struct tgsi_header
*header
)
758 struct tgsi_texture_offset texture_offset
;
760 texture_offset
.Index
= index
;
761 texture_offset
.File
= file
;
762 texture_offset
.SwizzleX
= swizzle_x
;
763 texture_offset
.SwizzleY
= swizzle_y
;
764 texture_offset
.SwizzleZ
= swizzle_z
;
765 texture_offset
.Padding
= 0;
767 instruction_grow( instruction
, header
);
769 return texture_offset
;
772 static struct tgsi_src_register
773 tgsi_default_src_register( void )
775 struct tgsi_src_register src_register
;
777 src_register
.File
= TGSI_FILE_NULL
;
778 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
779 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
780 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
781 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
782 src_register
.Negate
= 0;
783 src_register
.Absolute
= 0;
784 src_register
.Indirect
= 0;
785 src_register
.Dimension
= 0;
786 src_register
.Index
= 0;
791 static struct tgsi_src_register
792 tgsi_build_src_register(
803 struct tgsi_instruction
*instruction
,
804 struct tgsi_header
*header
)
806 struct tgsi_src_register src_register
;
808 assert( file
< TGSI_FILE_COUNT
);
809 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
810 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
811 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
812 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
813 assert( negate
<= 1 );
814 assert( index
>= -0x8000 && index
<= 0x7FFF );
816 src_register
.File
= file
;
817 src_register
.SwizzleX
= swizzle_x
;
818 src_register
.SwizzleY
= swizzle_y
;
819 src_register
.SwizzleZ
= swizzle_z
;
820 src_register
.SwizzleW
= swizzle_w
;
821 src_register
.Negate
= negate
;
822 src_register
.Absolute
= absolute
;
823 src_register
.Indirect
= indirect
;
824 src_register
.Dimension
= dimension
;
825 src_register
.Index
= index
;
827 instruction_grow( instruction
, header
);
832 static struct tgsi_ind_register
833 tgsi_default_ind_register( void )
835 struct tgsi_ind_register ind_register
;
837 ind_register
.File
= TGSI_FILE_NULL
;
838 ind_register
.Index
= 0;
839 ind_register
.Swizzle
= TGSI_SWIZZLE_X
;
840 ind_register
.ArrayID
= 0;
845 static struct tgsi_ind_register
846 tgsi_build_ind_register(
851 struct tgsi_instruction
*instruction
,
852 struct tgsi_header
*header
)
854 struct tgsi_ind_register ind_register
;
856 assert( file
< TGSI_FILE_COUNT
);
857 assert( swizzle
<= TGSI_SWIZZLE_W
);
858 assert( index
>= -0x8000 && index
<= 0x7FFF );
860 ind_register
.File
= file
;
861 ind_register
.Swizzle
= swizzle
;
862 ind_register
.Index
= index
;
863 ind_register
.ArrayID
= arrayid
;
865 instruction_grow( instruction
, header
);
870 static struct tgsi_dimension
871 tgsi_default_dimension( void )
873 struct tgsi_dimension dimension
;
875 dimension
.Indirect
= 0;
876 dimension
.Dimension
= 0;
877 dimension
.Padding
= 0;
883 static struct tgsi_full_src_register
884 tgsi_default_full_src_register( void )
886 struct tgsi_full_src_register full_src_register
;
888 full_src_register
.Register
= tgsi_default_src_register();
889 full_src_register
.Indirect
= tgsi_default_ind_register();
890 full_src_register
.Dimension
= tgsi_default_dimension();
891 full_src_register
.DimIndirect
= tgsi_default_ind_register();
893 return full_src_register
;
896 static struct tgsi_dimension
897 tgsi_build_dimension(
900 struct tgsi_instruction
*instruction
,
901 struct tgsi_header
*header
)
903 struct tgsi_dimension dimension
;
905 dimension
.Indirect
= indirect
;
906 dimension
.Dimension
= 0;
907 dimension
.Padding
= 0;
908 dimension
.Index
= index
;
910 instruction_grow( instruction
, header
);
915 static struct tgsi_dst_register
916 tgsi_default_dst_register( void )
918 struct tgsi_dst_register dst_register
;
920 dst_register
.File
= TGSI_FILE_NULL
;
921 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
922 dst_register
.Indirect
= 0;
923 dst_register
.Dimension
= 0;
924 dst_register
.Index
= 0;
925 dst_register
.Padding
= 0;
930 static struct tgsi_dst_register
931 tgsi_build_dst_register(
937 struct tgsi_instruction
*instruction
,
938 struct tgsi_header
*header
)
940 struct tgsi_dst_register dst_register
;
942 assert( file
< TGSI_FILE_COUNT
);
943 assert( mask
<= TGSI_WRITEMASK_XYZW
);
944 assert( index
>= -32768 && index
<= 32767 );
946 dst_register
.File
= file
;
947 dst_register
.WriteMask
= mask
;
948 dst_register
.Indirect
= indirect
;
949 dst_register
.Dimension
= dimension
;
950 dst_register
.Index
= index
;
951 dst_register
.Padding
= 0;
953 instruction_grow( instruction
, header
);
958 static struct tgsi_full_dst_register
959 tgsi_default_full_dst_register( void )
961 struct tgsi_full_dst_register full_dst_register
;
963 full_dst_register
.Register
= tgsi_default_dst_register();
964 full_dst_register
.Indirect
= tgsi_default_ind_register();
965 full_dst_register
.Dimension
= tgsi_default_dimension();
966 full_dst_register
.DimIndirect
= tgsi_default_ind_register();
968 return full_dst_register
;
971 struct tgsi_full_instruction
972 tgsi_default_full_instruction( void )
974 struct tgsi_full_instruction full_instruction
;
977 full_instruction
.Instruction
= tgsi_default_instruction();
978 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
979 full_instruction
.Label
= tgsi_default_instruction_label();
980 full_instruction
.Texture
= tgsi_default_instruction_texture();
981 for( i
= 0; i
< TGSI_FULL_MAX_TEX_OFFSETS
; i
++ ) {
982 full_instruction
.TexOffsets
[i
] = tgsi_default_texture_offset();
984 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
985 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
987 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
988 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
991 return full_instruction
;
995 tgsi_build_full_instruction(
996 const struct tgsi_full_instruction
*full_inst
,
997 struct tgsi_token
*tokens
,
998 struct tgsi_header
*header
,
1003 struct tgsi_instruction
*instruction
;
1004 struct tgsi_token
*prev_token
;
1006 if( maxsize
<= size
)
1008 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
1011 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
1012 full_inst
->Instruction
.Saturate
,
1013 full_inst
->Instruction
.Predicate
,
1014 full_inst
->Instruction
.NumDstRegs
,
1015 full_inst
->Instruction
.NumSrcRegs
,
1017 prev_token
= (struct tgsi_token
*) instruction
;
1019 if (full_inst
->Instruction
.Predicate
) {
1020 struct tgsi_instruction_predicate
*instruction_predicate
;
1022 if (maxsize
<= size
) {
1025 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
1028 *instruction_predicate
=
1029 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
1030 full_inst
->Predicate
.Negate
,
1031 full_inst
->Predicate
.SwizzleX
,
1032 full_inst
->Predicate
.SwizzleY
,
1033 full_inst
->Predicate
.SwizzleZ
,
1034 full_inst
->Predicate
.SwizzleW
,
1039 if (full_inst
->Instruction
.Label
) {
1040 struct tgsi_instruction_label
*instruction_label
;
1042 if( maxsize
<= size
)
1045 (struct tgsi_instruction_label
*) &tokens
[size
];
1048 *instruction_label
= tgsi_build_instruction_label(
1049 full_inst
->Label
.Label
,
1053 prev_token
= (struct tgsi_token
*) instruction_label
;
1056 if (full_inst
->Instruction
.Texture
) {
1057 struct tgsi_instruction_texture
*instruction_texture
;
1059 if( maxsize
<= size
)
1061 instruction_texture
=
1062 (struct tgsi_instruction_texture
*) &tokens
[size
];
1065 *instruction_texture
= tgsi_build_instruction_texture(
1066 full_inst
->Texture
.Texture
,
1067 full_inst
->Texture
.NumOffsets
,
1071 prev_token
= (struct tgsi_token
*) instruction_texture
;
1073 for (i
= 0; i
< full_inst
->Texture
.NumOffsets
; i
++) {
1074 struct tgsi_texture_offset
*texture_offset
;
1076 if ( maxsize
<= size
)
1078 texture_offset
= (struct tgsi_texture_offset
*)&tokens
[size
];
1080 *texture_offset
= tgsi_build_texture_offset(
1081 full_inst
->TexOffsets
[i
].Index
,
1082 full_inst
->TexOffsets
[i
].File
,
1083 full_inst
->TexOffsets
[i
].SwizzleX
,
1084 full_inst
->TexOffsets
[i
].SwizzleY
,
1085 full_inst
->TexOffsets
[i
].SwizzleZ
,
1089 prev_token
= (struct tgsi_token
*) texture_offset
;
1092 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
1093 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
1094 struct tgsi_dst_register
*dst_register
;
1096 if( maxsize
<= size
)
1098 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
1101 *dst_register
= tgsi_build_dst_register(
1103 reg
->Register
.WriteMask
,
1104 reg
->Register
.Indirect
,
1105 reg
->Register
.Dimension
,
1106 reg
->Register
.Index
,
1110 if( reg
->Register
.Indirect
) {
1111 struct tgsi_ind_register
*ind
;
1113 if( maxsize
<= size
)
1115 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1118 *ind
= tgsi_build_ind_register(
1120 reg
->Indirect
.Swizzle
,
1121 reg
->Indirect
.Index
,
1122 reg
->Indirect
.ArrayID
,
1127 if( reg
->Register
.Dimension
) {
1128 struct tgsi_dimension
*dim
;
1130 assert( !reg
->Dimension
.Dimension
);
1132 if( maxsize
<= size
)
1134 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1137 *dim
= tgsi_build_dimension(
1138 reg
->Dimension
.Indirect
,
1139 reg
->Dimension
.Index
,
1143 if( reg
->Dimension
.Indirect
) {
1144 struct tgsi_ind_register
*ind
;
1146 if( maxsize
<= size
)
1148 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1151 *ind
= tgsi_build_ind_register(
1152 reg
->DimIndirect
.File
,
1153 reg
->DimIndirect
.Swizzle
,
1154 reg
->DimIndirect
.Index
,
1155 reg
->DimIndirect
.ArrayID
,
1162 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
1163 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
1164 struct tgsi_src_register
*src_register
;
1166 if( maxsize
<= size
)
1168 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
1171 *src_register
= tgsi_build_src_register(
1173 reg
->Register
.SwizzleX
,
1174 reg
->Register
.SwizzleY
,
1175 reg
->Register
.SwizzleZ
,
1176 reg
->Register
.SwizzleW
,
1177 reg
->Register
.Negate
,
1178 reg
->Register
.Absolute
,
1179 reg
->Register
.Indirect
,
1180 reg
->Register
.Dimension
,
1181 reg
->Register
.Index
,
1185 if( reg
->Register
.Indirect
) {
1186 struct tgsi_ind_register
*ind
;
1188 if( maxsize
<= size
)
1190 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1193 *ind
= tgsi_build_ind_register(
1195 reg
->Indirect
.Swizzle
,
1196 reg
->Indirect
.Index
,
1197 reg
->Indirect
.ArrayID
,
1202 if( reg
->Register
.Dimension
) {
1203 struct tgsi_dimension
*dim
;
1205 assert( !reg
->Dimension
.Dimension
);
1207 if( maxsize
<= size
)
1209 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1212 *dim
= tgsi_build_dimension(
1213 reg
->Dimension
.Indirect
,
1214 reg
->Dimension
.Index
,
1218 if( reg
->Dimension
.Indirect
) {
1219 struct tgsi_ind_register
*ind
;
1221 if( maxsize
<= size
)
1223 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1226 *ind
= tgsi_build_ind_register(
1227 reg
->DimIndirect
.File
,
1228 reg
->DimIndirect
.Swizzle
,
1229 reg
->DimIndirect
.Index
,
1230 reg
->DimIndirect
.ArrayID
,
1240 static struct tgsi_property
1241 tgsi_default_property( void )
1243 struct tgsi_property property
;
1245 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1246 property
.NrTokens
= 1;
1247 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1248 property
.Padding
= 0;
1253 static struct tgsi_property
1254 tgsi_build_property(unsigned property_name
,
1255 struct tgsi_header
*header
)
1257 struct tgsi_property property
;
1259 property
= tgsi_default_property();
1260 property
.PropertyName
= property_name
;
1262 header_bodysize_grow( header
);
1268 struct tgsi_full_property
1269 tgsi_default_full_property( void )
1271 struct tgsi_full_property full_property
;
1273 full_property
.Property
= tgsi_default_property();
1274 memset(full_property
.u
, 0,
1275 sizeof(struct tgsi_property_data
) * 8);
1277 return full_property
;
1282 struct tgsi_property
*property
,
1283 struct tgsi_header
*header
)
1285 assert( property
->NrTokens
< 0xFF );
1287 property
->NrTokens
++;
1289 header_bodysize_grow( header
);
1292 static struct tgsi_property_data
1293 tgsi_build_property_data(
1295 struct tgsi_property
*property
,
1296 struct tgsi_header
*header
)
1298 struct tgsi_property_data property_data
;
1300 property_data
.Data
= value
;
1302 property_grow( property
, header
);
1304 return property_data
;
1308 tgsi_build_full_property(
1309 const struct tgsi_full_property
*full_prop
,
1310 struct tgsi_token
*tokens
,
1311 struct tgsi_header
*header
,
1314 unsigned size
= 0, i
;
1315 struct tgsi_property
*property
;
1317 if( maxsize
<= size
)
1319 property
= (struct tgsi_property
*) &tokens
[size
];
1322 *property
= tgsi_build_property(
1323 full_prop
->Property
.PropertyName
,
1326 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1328 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1329 struct tgsi_property_data
*data
;
1331 if( maxsize
<= size
)
1333 data
= (struct tgsi_property_data
*) &tokens
[size
];
1336 *data
= tgsi_build_property_data(
1337 full_prop
->u
[i
].Data
,