1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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
,
128 struct tgsi_header
*header
)
130 struct tgsi_declaration declaration
;
132 assert( file
< TGSI_FILE_COUNT
);
133 assert( interpolate
< TGSI_INTERPOLATE_COUNT
);
135 declaration
= tgsi_default_declaration();
136 declaration
.File
= file
;
137 declaration
.UsageMask
= usage_mask
;
138 declaration
.Interpolate
= interpolate
;
139 declaration
.Dimension
= dimension
;
140 declaration
.Semantic
= semantic
;
141 declaration
.Invariant
= invariant
;
142 declaration
.Local
= local
;
143 declaration
.Array
= array
;
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_interp
198 tgsi_default_declaration_interp( void )
200 struct tgsi_declaration_interp di
;
202 di
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
203 di
.Location
= TGSI_INTERPOLATE_LOC_CENTER
;
204 di
.CylindricalWrap
= 0;
210 static struct tgsi_declaration_interp
211 tgsi_build_declaration_interp(unsigned interpolate
,
212 unsigned interpolate_location
,
213 unsigned cylindrical_wrap
,
214 struct tgsi_declaration
*declaration
,
215 struct tgsi_header
*header
)
217 struct tgsi_declaration_interp di
;
219 di
.Interpolate
= interpolate
;
220 di
.Location
= interpolate_location
;
221 di
.CylindricalWrap
= cylindrical_wrap
;
224 declaration_grow(declaration
, header
);
229 static struct tgsi_declaration_semantic
230 tgsi_default_declaration_semantic( void )
232 struct tgsi_declaration_semantic ds
;
234 ds
.Name
= TGSI_SEMANTIC_POSITION
;
241 static struct tgsi_declaration_semantic
242 tgsi_build_declaration_semantic(
243 unsigned semantic_name
,
244 unsigned semantic_index
,
245 struct tgsi_declaration
*declaration
,
246 struct tgsi_header
*header
)
248 struct tgsi_declaration_semantic ds
;
250 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
251 assert( semantic_index
<= 0xFFFF );
253 ds
.Name
= semantic_name
;
254 ds
.Index
= semantic_index
;
257 declaration_grow( declaration
, header
);
262 static struct tgsi_declaration_resource
263 tgsi_default_declaration_resource(void)
265 struct tgsi_declaration_resource dr
;
267 dr
.Resource
= TGSI_TEXTURE_BUFFER
;
275 static struct tgsi_declaration_resource
276 tgsi_build_declaration_resource(unsigned texture
,
279 struct tgsi_declaration
*declaration
,
280 struct tgsi_header
*header
)
282 struct tgsi_declaration_resource dr
;
284 dr
= tgsi_default_declaration_resource();
285 dr
.Resource
= texture
;
287 dr
.Writable
= writable
;
289 declaration_grow(declaration
, header
);
294 static struct tgsi_declaration_sampler_view
295 tgsi_default_declaration_sampler_view(void)
297 struct tgsi_declaration_sampler_view dsv
;
299 dsv
.Resource
= TGSI_TEXTURE_BUFFER
;
300 dsv
.ReturnTypeX
= TGSI_RETURN_TYPE_UNORM
;
301 dsv
.ReturnTypeY
= TGSI_RETURN_TYPE_UNORM
;
302 dsv
.ReturnTypeZ
= TGSI_RETURN_TYPE_UNORM
;
303 dsv
.ReturnTypeW
= TGSI_RETURN_TYPE_UNORM
;
308 static struct tgsi_declaration_sampler_view
309 tgsi_build_declaration_sampler_view(unsigned texture
,
310 unsigned return_type_x
,
311 unsigned return_type_y
,
312 unsigned return_type_z
,
313 unsigned return_type_w
,
314 struct tgsi_declaration
*declaration
,
315 struct tgsi_header
*header
)
317 struct tgsi_declaration_sampler_view dsv
;
319 dsv
= tgsi_default_declaration_sampler_view();
320 dsv
.Resource
= texture
;
321 dsv
.ReturnTypeX
= return_type_x
;
322 dsv
.ReturnTypeY
= return_type_y
;
323 dsv
.ReturnTypeZ
= return_type_z
;
324 dsv
.ReturnTypeW
= return_type_w
;
326 declaration_grow(declaration
, header
);
332 static struct tgsi_declaration_array
333 tgsi_default_declaration_array( void )
335 struct tgsi_declaration_array a
;
343 static struct tgsi_declaration_array
344 tgsi_build_declaration_array(unsigned arrayid
,
345 struct tgsi_declaration
*declaration
,
346 struct tgsi_header
*header
)
348 struct tgsi_declaration_array da
;
350 da
= tgsi_default_declaration_array();
351 da
.ArrayID
= arrayid
;
353 declaration_grow(declaration
, header
);
358 struct tgsi_full_declaration
359 tgsi_default_full_declaration( void )
361 struct tgsi_full_declaration full_declaration
;
363 full_declaration
.Declaration
= tgsi_default_declaration();
364 full_declaration
.Range
= tgsi_default_declaration_range();
365 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
366 full_declaration
.Interp
= tgsi_default_declaration_interp();
367 full_declaration
.Resource
= tgsi_default_declaration_resource();
368 full_declaration
.SamplerView
= tgsi_default_declaration_sampler_view();
369 full_declaration
.Array
= tgsi_default_declaration_array();
371 return full_declaration
;
375 tgsi_build_full_declaration(
376 const struct tgsi_full_declaration
*full_decl
,
377 struct tgsi_token
*tokens
,
378 struct tgsi_header
*header
,
382 struct tgsi_declaration
*declaration
;
383 struct tgsi_declaration_range
*dr
;
385 if( maxsize
<= size
)
387 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
390 *declaration
= tgsi_build_declaration(
391 full_decl
->Declaration
.File
,
392 full_decl
->Declaration
.UsageMask
,
393 full_decl
->Declaration
.Interpolate
,
394 full_decl
->Declaration
.Dimension
,
395 full_decl
->Declaration
.Semantic
,
396 full_decl
->Declaration
.Invariant
,
397 full_decl
->Declaration
.Local
,
398 full_decl
->Declaration
.Array
,
403 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
406 *dr
= tgsi_build_declaration_range(
407 full_decl
->Range
.First
,
408 full_decl
->Range
.Last
,
412 if (full_decl
->Declaration
.Dimension
) {
413 struct tgsi_declaration_dimension
*dd
;
415 if (maxsize
<= size
) {
418 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
421 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
426 if (full_decl
->Declaration
.Interpolate
) {
427 struct tgsi_declaration_interp
*di
;
429 if (maxsize
<= size
) {
432 di
= (struct tgsi_declaration_interp
*)&tokens
[size
];
435 *di
= tgsi_build_declaration_interp(full_decl
->Interp
.Interpolate
,
436 full_decl
->Interp
.Location
,
437 full_decl
->Interp
.CylindricalWrap
,
442 if( full_decl
->Declaration
.Semantic
) {
443 struct tgsi_declaration_semantic
*ds
;
445 if( maxsize
<= size
)
447 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
450 *ds
= tgsi_build_declaration_semantic(
451 full_decl
->Semantic
.Name
,
452 full_decl
->Semantic
.Index
,
457 if (full_decl
->Declaration
.File
== TGSI_FILE_RESOURCE
) {
458 struct tgsi_declaration_resource
*dr
;
460 if (maxsize
<= size
) {
463 dr
= (struct tgsi_declaration_resource
*)&tokens
[size
];
466 *dr
= tgsi_build_declaration_resource(full_decl
->Resource
.Resource
,
467 full_decl
->Resource
.Raw
,
468 full_decl
->Resource
.Writable
,
473 if (full_decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
474 struct tgsi_declaration_sampler_view
*dsv
;
476 if (maxsize
<= size
) {
479 dsv
= (struct tgsi_declaration_sampler_view
*)&tokens
[size
];
482 *dsv
= tgsi_build_declaration_sampler_view(
483 full_decl
->SamplerView
.Resource
,
484 full_decl
->SamplerView
.ReturnTypeX
,
485 full_decl
->SamplerView
.ReturnTypeY
,
486 full_decl
->SamplerView
.ReturnTypeZ
,
487 full_decl
->SamplerView
.ReturnTypeW
,
492 if (full_decl
->Declaration
.Array
) {
493 struct tgsi_declaration_array
*da
;
495 if (maxsize
<= size
) {
498 da
= (struct tgsi_declaration_array
*)&tokens
[size
];
500 *da
= tgsi_build_declaration_array(
501 full_decl
->Array
.ArrayID
,
512 static struct tgsi_immediate
513 tgsi_default_immediate( void )
515 struct tgsi_immediate immediate
;
517 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
518 immediate
.NrTokens
= 1;
519 immediate
.DataType
= TGSI_IMM_FLOAT32
;
520 immediate
.Padding
= 0;
525 static struct tgsi_immediate
526 tgsi_build_immediate(
527 struct tgsi_header
*header
,
530 struct tgsi_immediate immediate
;
532 immediate
= tgsi_default_immediate();
533 immediate
.DataType
= type
;
535 header_bodysize_grow( header
);
540 struct tgsi_full_immediate
541 tgsi_default_full_immediate( void )
543 struct tgsi_full_immediate fullimm
;
545 fullimm
.Immediate
= tgsi_default_immediate();
546 fullimm
.u
[0].Float
= 0.0f
;
547 fullimm
.u
[1].Float
= 0.0f
;
548 fullimm
.u
[2].Float
= 0.0f
;
549 fullimm
.u
[3].Float
= 0.0f
;
556 struct tgsi_immediate
*immediate
,
557 struct tgsi_header
*header
)
559 assert( immediate
->NrTokens
< 0xFF );
561 immediate
->NrTokens
++;
563 header_bodysize_grow( header
);
567 tgsi_build_full_immediate(
568 const struct tgsi_full_immediate
*full_imm
,
569 struct tgsi_token
*tokens
,
570 struct tgsi_header
*header
,
573 unsigned size
= 0, i
;
574 struct tgsi_immediate
*immediate
;
576 if( maxsize
<= size
)
578 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
581 *immediate
= tgsi_build_immediate( header
, full_imm
->Immediate
.DataType
);
583 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
585 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
586 union tgsi_immediate_data
*data
;
588 if( maxsize
<= size
)
591 data
= (union tgsi_immediate_data
*) &tokens
[size
];
592 *data
= full_imm
->u
[i
];
594 immediate_grow( immediate
, header
);
605 struct tgsi_instruction
606 tgsi_default_instruction( void )
608 struct tgsi_instruction instruction
;
610 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
611 instruction
.NrTokens
= 0;
612 instruction
.Opcode
= TGSI_OPCODE_MOV
;
613 instruction
.Saturate
= 0;
614 instruction
.Predicate
= 0;
615 instruction
.NumDstRegs
= 1;
616 instruction
.NumSrcRegs
= 1;
617 instruction
.Label
= 0;
618 instruction
.Texture
= 0;
619 instruction
.Padding
= 0;
624 static struct tgsi_instruction
625 tgsi_build_instruction(unsigned opcode
,
628 unsigned num_dst_regs
,
629 unsigned num_src_regs
,
630 struct tgsi_header
*header
)
632 struct tgsi_instruction instruction
;
634 assert (opcode
<= TGSI_OPCODE_LAST
);
635 assert (saturate
<= 1);
636 assert (num_dst_regs
<= 3);
637 assert (num_src_regs
<= 15);
639 instruction
= tgsi_default_instruction();
640 instruction
.Opcode
= opcode
;
641 instruction
.Saturate
= saturate
;
642 instruction
.Predicate
= predicate
;
643 instruction
.NumDstRegs
= num_dst_regs
;
644 instruction
.NumSrcRegs
= num_src_regs
;
646 header_bodysize_grow( header
);
653 struct tgsi_instruction
*instruction
,
654 struct tgsi_header
*header
)
656 assert (instruction
->NrTokens
< 0xFF);
658 instruction
->NrTokens
++;
660 header_bodysize_grow( header
);
663 struct tgsi_instruction_predicate
664 tgsi_default_instruction_predicate(void)
666 struct tgsi_instruction_predicate instruction_predicate
;
668 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
669 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
670 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
671 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
672 instruction_predicate
.Negate
= 0;
673 instruction_predicate
.Index
= 0;
674 instruction_predicate
.Padding
= 0;
676 return instruction_predicate
;
679 static struct tgsi_instruction_predicate
680 tgsi_build_instruction_predicate(int index
,
686 struct tgsi_instruction
*instruction
,
687 struct tgsi_header
*header
)
689 struct tgsi_instruction_predicate instruction_predicate
;
691 instruction_predicate
= tgsi_default_instruction_predicate();
692 instruction_predicate
.SwizzleX
= swizzleX
;
693 instruction_predicate
.SwizzleY
= swizzleY
;
694 instruction_predicate
.SwizzleZ
= swizzleZ
;
695 instruction_predicate
.SwizzleW
= swizzleW
;
696 instruction_predicate
.Negate
= negate
;
697 instruction_predicate
.Index
= index
;
699 instruction_grow(instruction
, header
);
701 return instruction_predicate
;
704 static struct tgsi_instruction_label
705 tgsi_default_instruction_label( void )
707 struct tgsi_instruction_label instruction_label
;
709 instruction_label
.Label
= 0;
710 instruction_label
.Padding
= 0;
712 return instruction_label
;
715 static struct tgsi_instruction_label
716 tgsi_build_instruction_label(
718 struct tgsi_token
*prev_token
,
719 struct tgsi_instruction
*instruction
,
720 struct tgsi_header
*header
)
722 struct tgsi_instruction_label instruction_label
;
724 instruction_label
.Label
= label
;
725 instruction_label
.Padding
= 0;
726 instruction
->Label
= 1;
728 instruction_grow( instruction
, header
);
730 return instruction_label
;
733 static struct tgsi_instruction_texture
734 tgsi_default_instruction_texture( void )
736 struct tgsi_instruction_texture instruction_texture
;
738 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
739 instruction_texture
.NumOffsets
= 0;
740 instruction_texture
.Padding
= 0;
742 return instruction_texture
;
745 static struct tgsi_instruction_texture
746 tgsi_build_instruction_texture(
748 unsigned num_offsets
,
749 struct tgsi_token
*prev_token
,
750 struct tgsi_instruction
*instruction
,
751 struct tgsi_header
*header
)
753 struct tgsi_instruction_texture instruction_texture
;
755 instruction_texture
.Texture
= texture
;
756 instruction_texture
.NumOffsets
= num_offsets
;
757 instruction_texture
.Padding
= 0;
758 instruction
->Texture
= 1;
760 instruction_grow( instruction
, header
);
762 return instruction_texture
;
766 static struct tgsi_texture_offset
767 tgsi_default_texture_offset( void )
769 struct tgsi_texture_offset texture_offset
;
771 texture_offset
.Index
= 0;
772 texture_offset
.File
= 0;
773 texture_offset
.SwizzleX
= 0;
774 texture_offset
.SwizzleY
= 0;
775 texture_offset
.SwizzleZ
= 0;
776 texture_offset
.Padding
= 0;
778 return texture_offset
;
781 static struct tgsi_texture_offset
782 tgsi_build_texture_offset(
783 int index
, int file
, int swizzle_x
, int swizzle_y
, int swizzle_z
,
784 struct tgsi_token
*prev_token
,
785 struct tgsi_instruction
*instruction
,
786 struct tgsi_header
*header
)
788 struct tgsi_texture_offset texture_offset
;
790 texture_offset
.Index
= index
;
791 texture_offset
.File
= file
;
792 texture_offset
.SwizzleX
= swizzle_x
;
793 texture_offset
.SwizzleY
= swizzle_y
;
794 texture_offset
.SwizzleZ
= swizzle_z
;
795 texture_offset
.Padding
= 0;
797 instruction_grow( instruction
, header
);
799 return texture_offset
;
802 static struct tgsi_src_register
803 tgsi_default_src_register( void )
805 struct tgsi_src_register src_register
;
807 src_register
.File
= TGSI_FILE_NULL
;
808 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
809 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
810 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
811 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
812 src_register
.Negate
= 0;
813 src_register
.Absolute
= 0;
814 src_register
.Indirect
= 0;
815 src_register
.Dimension
= 0;
816 src_register
.Index
= 0;
821 static struct tgsi_src_register
822 tgsi_build_src_register(
833 struct tgsi_instruction
*instruction
,
834 struct tgsi_header
*header
)
836 struct tgsi_src_register src_register
;
838 assert( file
< TGSI_FILE_COUNT
);
839 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
840 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
841 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
842 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
843 assert( negate
<= 1 );
844 assert( index
>= -0x8000 && index
<= 0x7FFF );
846 src_register
.File
= file
;
847 src_register
.SwizzleX
= swizzle_x
;
848 src_register
.SwizzleY
= swizzle_y
;
849 src_register
.SwizzleZ
= swizzle_z
;
850 src_register
.SwizzleW
= swizzle_w
;
851 src_register
.Negate
= negate
;
852 src_register
.Absolute
= absolute
;
853 src_register
.Indirect
= indirect
;
854 src_register
.Dimension
= dimension
;
855 src_register
.Index
= index
;
857 instruction_grow( instruction
, header
);
862 static struct tgsi_ind_register
863 tgsi_default_ind_register( void )
865 struct tgsi_ind_register ind_register
;
867 ind_register
.File
= TGSI_FILE_NULL
;
868 ind_register
.Index
= 0;
869 ind_register
.Swizzle
= TGSI_SWIZZLE_X
;
870 ind_register
.ArrayID
= 0;
875 static struct tgsi_ind_register
876 tgsi_build_ind_register(
881 struct tgsi_instruction
*instruction
,
882 struct tgsi_header
*header
)
884 struct tgsi_ind_register ind_register
;
886 assert( file
< TGSI_FILE_COUNT
);
887 assert( swizzle
<= TGSI_SWIZZLE_W
);
888 assert( index
>= -0x8000 && index
<= 0x7FFF );
890 ind_register
.File
= file
;
891 ind_register
.Swizzle
= swizzle
;
892 ind_register
.Index
= index
;
893 ind_register
.ArrayID
= arrayid
;
895 instruction_grow( instruction
, header
);
900 static struct tgsi_dimension
901 tgsi_default_dimension( void )
903 struct tgsi_dimension dimension
;
905 dimension
.Indirect
= 0;
906 dimension
.Dimension
= 0;
907 dimension
.Padding
= 0;
913 static struct tgsi_full_src_register
914 tgsi_default_full_src_register( void )
916 struct tgsi_full_src_register full_src_register
;
918 full_src_register
.Register
= tgsi_default_src_register();
919 full_src_register
.Indirect
= tgsi_default_ind_register();
920 full_src_register
.Dimension
= tgsi_default_dimension();
921 full_src_register
.DimIndirect
= tgsi_default_ind_register();
923 return full_src_register
;
926 static struct tgsi_dimension
927 tgsi_build_dimension(
930 struct tgsi_instruction
*instruction
,
931 struct tgsi_header
*header
)
933 struct tgsi_dimension dimension
;
935 dimension
.Indirect
= indirect
;
936 dimension
.Dimension
= 0;
937 dimension
.Padding
= 0;
938 dimension
.Index
= index
;
940 instruction_grow( instruction
, header
);
945 static struct tgsi_dst_register
946 tgsi_default_dst_register( void )
948 struct tgsi_dst_register dst_register
;
950 dst_register
.File
= TGSI_FILE_NULL
;
951 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
952 dst_register
.Indirect
= 0;
953 dst_register
.Dimension
= 0;
954 dst_register
.Index
= 0;
955 dst_register
.Padding
= 0;
960 static struct tgsi_dst_register
961 tgsi_build_dst_register(
967 struct tgsi_instruction
*instruction
,
968 struct tgsi_header
*header
)
970 struct tgsi_dst_register dst_register
;
972 assert( file
< TGSI_FILE_COUNT
);
973 assert( mask
<= TGSI_WRITEMASK_XYZW
);
974 assert( index
>= -32768 && index
<= 32767 );
976 dst_register
.File
= file
;
977 dst_register
.WriteMask
= mask
;
978 dst_register
.Indirect
= indirect
;
979 dst_register
.Dimension
= dimension
;
980 dst_register
.Index
= index
;
981 dst_register
.Padding
= 0;
983 instruction_grow( instruction
, header
);
988 static struct tgsi_full_dst_register
989 tgsi_default_full_dst_register( void )
991 struct tgsi_full_dst_register full_dst_register
;
993 full_dst_register
.Register
= tgsi_default_dst_register();
994 full_dst_register
.Indirect
= tgsi_default_ind_register();
995 full_dst_register
.Dimension
= tgsi_default_dimension();
996 full_dst_register
.DimIndirect
= tgsi_default_ind_register();
998 return full_dst_register
;
1001 struct tgsi_full_instruction
1002 tgsi_default_full_instruction( void )
1004 struct tgsi_full_instruction full_instruction
;
1007 full_instruction
.Instruction
= tgsi_default_instruction();
1008 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
1009 full_instruction
.Label
= tgsi_default_instruction_label();
1010 full_instruction
.Texture
= tgsi_default_instruction_texture();
1011 for( i
= 0; i
< TGSI_FULL_MAX_TEX_OFFSETS
; i
++ ) {
1012 full_instruction
.TexOffsets
[i
] = tgsi_default_texture_offset();
1014 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
1015 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
1017 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
1018 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
1021 return full_instruction
;
1025 tgsi_build_full_instruction(
1026 const struct tgsi_full_instruction
*full_inst
,
1027 struct tgsi_token
*tokens
,
1028 struct tgsi_header
*header
,
1033 struct tgsi_instruction
*instruction
;
1034 struct tgsi_token
*prev_token
;
1036 if( maxsize
<= size
)
1038 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
1041 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
1042 full_inst
->Instruction
.Saturate
,
1043 full_inst
->Instruction
.Predicate
,
1044 full_inst
->Instruction
.NumDstRegs
,
1045 full_inst
->Instruction
.NumSrcRegs
,
1047 prev_token
= (struct tgsi_token
*) instruction
;
1049 if (full_inst
->Instruction
.Predicate
) {
1050 struct tgsi_instruction_predicate
*instruction_predicate
;
1052 if (maxsize
<= size
) {
1055 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
1058 *instruction_predicate
=
1059 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
1060 full_inst
->Predicate
.Negate
,
1061 full_inst
->Predicate
.SwizzleX
,
1062 full_inst
->Predicate
.SwizzleY
,
1063 full_inst
->Predicate
.SwizzleZ
,
1064 full_inst
->Predicate
.SwizzleW
,
1069 if (full_inst
->Instruction
.Label
) {
1070 struct tgsi_instruction_label
*instruction_label
;
1072 if( maxsize
<= size
)
1075 (struct tgsi_instruction_label
*) &tokens
[size
];
1078 *instruction_label
= tgsi_build_instruction_label(
1079 full_inst
->Label
.Label
,
1083 prev_token
= (struct tgsi_token
*) instruction_label
;
1086 if (full_inst
->Instruction
.Texture
) {
1087 struct tgsi_instruction_texture
*instruction_texture
;
1089 if( maxsize
<= size
)
1091 instruction_texture
=
1092 (struct tgsi_instruction_texture
*) &tokens
[size
];
1095 *instruction_texture
= tgsi_build_instruction_texture(
1096 full_inst
->Texture
.Texture
,
1097 full_inst
->Texture
.NumOffsets
,
1101 prev_token
= (struct tgsi_token
*) instruction_texture
;
1103 for (i
= 0; i
< full_inst
->Texture
.NumOffsets
; i
++) {
1104 struct tgsi_texture_offset
*texture_offset
;
1106 if ( maxsize
<= size
)
1108 texture_offset
= (struct tgsi_texture_offset
*)&tokens
[size
];
1110 *texture_offset
= tgsi_build_texture_offset(
1111 full_inst
->TexOffsets
[i
].Index
,
1112 full_inst
->TexOffsets
[i
].File
,
1113 full_inst
->TexOffsets
[i
].SwizzleX
,
1114 full_inst
->TexOffsets
[i
].SwizzleY
,
1115 full_inst
->TexOffsets
[i
].SwizzleZ
,
1119 prev_token
= (struct tgsi_token
*) texture_offset
;
1122 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
1123 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
1124 struct tgsi_dst_register
*dst_register
;
1126 if( maxsize
<= size
)
1128 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
1131 *dst_register
= tgsi_build_dst_register(
1133 reg
->Register
.WriteMask
,
1134 reg
->Register
.Indirect
,
1135 reg
->Register
.Dimension
,
1136 reg
->Register
.Index
,
1140 if( reg
->Register
.Indirect
) {
1141 struct tgsi_ind_register
*ind
;
1143 if( maxsize
<= size
)
1145 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1148 *ind
= tgsi_build_ind_register(
1150 reg
->Indirect
.Swizzle
,
1151 reg
->Indirect
.Index
,
1152 reg
->Indirect
.ArrayID
,
1157 if( reg
->Register
.Dimension
) {
1158 struct tgsi_dimension
*dim
;
1160 assert( !reg
->Dimension
.Dimension
);
1162 if( maxsize
<= size
)
1164 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1167 *dim
= tgsi_build_dimension(
1168 reg
->Dimension
.Indirect
,
1169 reg
->Dimension
.Index
,
1173 if( reg
->Dimension
.Indirect
) {
1174 struct tgsi_ind_register
*ind
;
1176 if( maxsize
<= size
)
1178 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1181 *ind
= tgsi_build_ind_register(
1182 reg
->DimIndirect
.File
,
1183 reg
->DimIndirect
.Swizzle
,
1184 reg
->DimIndirect
.Index
,
1185 reg
->DimIndirect
.ArrayID
,
1192 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
1193 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
1194 struct tgsi_src_register
*src_register
;
1196 if( maxsize
<= size
)
1198 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
1201 *src_register
= tgsi_build_src_register(
1203 reg
->Register
.SwizzleX
,
1204 reg
->Register
.SwizzleY
,
1205 reg
->Register
.SwizzleZ
,
1206 reg
->Register
.SwizzleW
,
1207 reg
->Register
.Negate
,
1208 reg
->Register
.Absolute
,
1209 reg
->Register
.Indirect
,
1210 reg
->Register
.Dimension
,
1211 reg
->Register
.Index
,
1215 if( reg
->Register
.Indirect
) {
1216 struct tgsi_ind_register
*ind
;
1218 if( maxsize
<= size
)
1220 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1223 *ind
= tgsi_build_ind_register(
1225 reg
->Indirect
.Swizzle
,
1226 reg
->Indirect
.Index
,
1227 reg
->Indirect
.ArrayID
,
1232 if( reg
->Register
.Dimension
) {
1233 struct tgsi_dimension
*dim
;
1235 assert( !reg
->Dimension
.Dimension
);
1237 if( maxsize
<= size
)
1239 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1242 *dim
= tgsi_build_dimension(
1243 reg
->Dimension
.Indirect
,
1244 reg
->Dimension
.Index
,
1248 if( reg
->Dimension
.Indirect
) {
1249 struct tgsi_ind_register
*ind
;
1251 if( maxsize
<= size
)
1253 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1256 *ind
= tgsi_build_ind_register(
1257 reg
->DimIndirect
.File
,
1258 reg
->DimIndirect
.Swizzle
,
1259 reg
->DimIndirect
.Index
,
1260 reg
->DimIndirect
.ArrayID
,
1270 static struct tgsi_property
1271 tgsi_default_property( void )
1273 struct tgsi_property property
;
1275 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1276 property
.NrTokens
= 1;
1277 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1278 property
.Padding
= 0;
1283 static struct tgsi_property
1284 tgsi_build_property(unsigned property_name
,
1285 struct tgsi_header
*header
)
1287 struct tgsi_property property
;
1289 property
= tgsi_default_property();
1290 property
.PropertyName
= property_name
;
1292 header_bodysize_grow( header
);
1298 struct tgsi_full_property
1299 tgsi_default_full_property( void )
1301 struct tgsi_full_property full_property
;
1303 full_property
.Property
= tgsi_default_property();
1304 memset(full_property
.u
, 0,
1305 sizeof(struct tgsi_property_data
) * 8);
1307 return full_property
;
1312 struct tgsi_property
*property
,
1313 struct tgsi_header
*header
)
1315 assert( property
->NrTokens
< 0xFF );
1317 property
->NrTokens
++;
1319 header_bodysize_grow( header
);
1322 static struct tgsi_property_data
1323 tgsi_build_property_data(
1325 struct tgsi_property
*property
,
1326 struct tgsi_header
*header
)
1328 struct tgsi_property_data property_data
;
1330 property_data
.Data
= value
;
1332 property_grow( property
, header
);
1334 return property_data
;
1338 tgsi_build_full_property(
1339 const struct tgsi_full_property
*full_prop
,
1340 struct tgsi_token
*tokens
,
1341 struct tgsi_header
*header
,
1344 unsigned size
= 0, i
;
1345 struct tgsi_property
*property
;
1347 if( maxsize
<= size
)
1349 property
= (struct tgsi_property
*) &tokens
[size
];
1352 *property
= tgsi_build_property(
1353 full_prop
->Property
.PropertyName
,
1356 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1358 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1359 struct tgsi_property_data
*data
;
1361 if( maxsize
<= size
)
1363 data
= (struct tgsi_property_data
*) &tokens
[size
];
1366 *data
= tgsi_build_property_data(
1367 full_prop
->u
[i
].Data
,