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_image
263 tgsi_default_declaration_image(void)
265 struct tgsi_declaration_image di
;
267 di
.Resource
= TGSI_TEXTURE_BUFFER
;
276 static struct tgsi_declaration_image
277 tgsi_build_declaration_image(unsigned texture
,
281 struct tgsi_declaration
*declaration
,
282 struct tgsi_header
*header
)
284 struct tgsi_declaration_image di
;
286 di
= tgsi_default_declaration_image();
287 di
.Resource
= texture
;
290 di
.Writable
= writable
;
292 declaration_grow(declaration
, header
);
297 static struct tgsi_declaration_sampler_view
298 tgsi_default_declaration_sampler_view(void)
300 struct tgsi_declaration_sampler_view dsv
;
302 dsv
.Resource
= TGSI_TEXTURE_BUFFER
;
303 dsv
.ReturnTypeX
= TGSI_RETURN_TYPE_UNORM
;
304 dsv
.ReturnTypeY
= TGSI_RETURN_TYPE_UNORM
;
305 dsv
.ReturnTypeZ
= TGSI_RETURN_TYPE_UNORM
;
306 dsv
.ReturnTypeW
= TGSI_RETURN_TYPE_UNORM
;
311 static struct tgsi_declaration_sampler_view
312 tgsi_build_declaration_sampler_view(unsigned texture
,
313 unsigned return_type_x
,
314 unsigned return_type_y
,
315 unsigned return_type_z
,
316 unsigned return_type_w
,
317 struct tgsi_declaration
*declaration
,
318 struct tgsi_header
*header
)
320 struct tgsi_declaration_sampler_view dsv
;
322 dsv
= tgsi_default_declaration_sampler_view();
323 dsv
.Resource
= texture
;
324 dsv
.ReturnTypeX
= return_type_x
;
325 dsv
.ReturnTypeY
= return_type_y
;
326 dsv
.ReturnTypeZ
= return_type_z
;
327 dsv
.ReturnTypeW
= return_type_w
;
329 declaration_grow(declaration
, header
);
335 static struct tgsi_declaration_array
336 tgsi_default_declaration_array( void )
338 struct tgsi_declaration_array a
;
346 static struct tgsi_declaration_array
347 tgsi_build_declaration_array(unsigned arrayid
,
348 struct tgsi_declaration
*declaration
,
349 struct tgsi_header
*header
)
351 struct tgsi_declaration_array da
;
353 da
= tgsi_default_declaration_array();
354 da
.ArrayID
= arrayid
;
356 declaration_grow(declaration
, header
);
361 struct tgsi_full_declaration
362 tgsi_default_full_declaration( void )
364 struct tgsi_full_declaration full_declaration
;
366 full_declaration
.Declaration
= tgsi_default_declaration();
367 full_declaration
.Range
= tgsi_default_declaration_range();
368 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
369 full_declaration
.Interp
= tgsi_default_declaration_interp();
370 full_declaration
.Image
= tgsi_default_declaration_image();
371 full_declaration
.SamplerView
= tgsi_default_declaration_sampler_view();
372 full_declaration
.Array
= tgsi_default_declaration_array();
374 return full_declaration
;
378 tgsi_build_full_declaration(
379 const struct tgsi_full_declaration
*full_decl
,
380 struct tgsi_token
*tokens
,
381 struct tgsi_header
*header
,
385 struct tgsi_declaration
*declaration
;
386 struct tgsi_declaration_range
*dr
;
388 if( maxsize
<= size
)
390 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
393 *declaration
= tgsi_build_declaration(
394 full_decl
->Declaration
.File
,
395 full_decl
->Declaration
.UsageMask
,
396 full_decl
->Declaration
.Interpolate
,
397 full_decl
->Declaration
.Dimension
,
398 full_decl
->Declaration
.Semantic
,
399 full_decl
->Declaration
.Invariant
,
400 full_decl
->Declaration
.Local
,
401 full_decl
->Declaration
.Array
,
406 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
409 *dr
= tgsi_build_declaration_range(
410 full_decl
->Range
.First
,
411 full_decl
->Range
.Last
,
415 if (full_decl
->Declaration
.Dimension
) {
416 struct tgsi_declaration_dimension
*dd
;
418 if (maxsize
<= size
) {
421 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
424 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
429 if (full_decl
->Declaration
.Interpolate
) {
430 struct tgsi_declaration_interp
*di
;
432 if (maxsize
<= size
) {
435 di
= (struct tgsi_declaration_interp
*)&tokens
[size
];
438 *di
= tgsi_build_declaration_interp(full_decl
->Interp
.Interpolate
,
439 full_decl
->Interp
.Location
,
440 full_decl
->Interp
.CylindricalWrap
,
445 if( full_decl
->Declaration
.Semantic
) {
446 struct tgsi_declaration_semantic
*ds
;
448 if( maxsize
<= size
)
450 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
453 *ds
= tgsi_build_declaration_semantic(
454 full_decl
->Semantic
.Name
,
455 full_decl
->Semantic
.Index
,
460 if (full_decl
->Declaration
.File
== TGSI_FILE_IMAGE
) {
461 struct tgsi_declaration_image
*di
;
463 if (maxsize
<= size
) {
466 di
= (struct tgsi_declaration_image
*)&tokens
[size
];
469 *di
= tgsi_build_declaration_image(full_decl
->Image
.Resource
,
470 full_decl
->Image
.Format
,
471 full_decl
->Image
.Raw
,
472 full_decl
->Image
.Writable
,
477 if (full_decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
478 struct tgsi_declaration_sampler_view
*dsv
;
480 if (maxsize
<= size
) {
483 dsv
= (struct tgsi_declaration_sampler_view
*)&tokens
[size
];
486 *dsv
= tgsi_build_declaration_sampler_view(
487 full_decl
->SamplerView
.Resource
,
488 full_decl
->SamplerView
.ReturnTypeX
,
489 full_decl
->SamplerView
.ReturnTypeY
,
490 full_decl
->SamplerView
.ReturnTypeZ
,
491 full_decl
->SamplerView
.ReturnTypeW
,
496 if (full_decl
->Declaration
.Array
) {
497 struct tgsi_declaration_array
*da
;
499 if (maxsize
<= size
) {
502 da
= (struct tgsi_declaration_array
*)&tokens
[size
];
504 *da
= tgsi_build_declaration_array(
505 full_decl
->Array
.ArrayID
,
516 static struct tgsi_immediate
517 tgsi_default_immediate( void )
519 struct tgsi_immediate immediate
;
521 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
522 immediate
.NrTokens
= 1;
523 immediate
.DataType
= TGSI_IMM_FLOAT32
;
524 immediate
.Padding
= 0;
529 static struct tgsi_immediate
530 tgsi_build_immediate(
531 struct tgsi_header
*header
,
534 struct tgsi_immediate immediate
;
536 immediate
= tgsi_default_immediate();
537 immediate
.DataType
= type
;
539 header_bodysize_grow( header
);
544 struct tgsi_full_immediate
545 tgsi_default_full_immediate( void )
547 struct tgsi_full_immediate fullimm
;
549 fullimm
.Immediate
= tgsi_default_immediate();
550 fullimm
.u
[0].Float
= 0.0f
;
551 fullimm
.u
[1].Float
= 0.0f
;
552 fullimm
.u
[2].Float
= 0.0f
;
553 fullimm
.u
[3].Float
= 0.0f
;
560 struct tgsi_immediate
*immediate
,
561 struct tgsi_header
*header
)
563 assert( immediate
->NrTokens
< 0xFF );
565 immediate
->NrTokens
++;
567 header_bodysize_grow( header
);
571 tgsi_build_full_immediate(
572 const struct tgsi_full_immediate
*full_imm
,
573 struct tgsi_token
*tokens
,
574 struct tgsi_header
*header
,
577 unsigned size
= 0, i
;
578 struct tgsi_immediate
*immediate
;
580 if( maxsize
<= size
)
582 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
585 *immediate
= tgsi_build_immediate( header
, full_imm
->Immediate
.DataType
);
587 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
589 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
590 union tgsi_immediate_data
*data
;
592 if( maxsize
<= size
)
595 data
= (union tgsi_immediate_data
*) &tokens
[size
];
596 *data
= full_imm
->u
[i
];
598 immediate_grow( immediate
, header
);
609 struct tgsi_instruction
610 tgsi_default_instruction( void )
612 struct tgsi_instruction instruction
;
614 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
615 instruction
.NrTokens
= 0;
616 instruction
.Opcode
= TGSI_OPCODE_MOV
;
617 instruction
.Saturate
= 0;
618 instruction
.Predicate
= 0;
619 instruction
.NumDstRegs
= 1;
620 instruction
.NumSrcRegs
= 1;
621 instruction
.Label
= 0;
622 instruction
.Texture
= 0;
623 instruction
.Memory
= 0;
624 instruction
.Padding
= 0;
629 static struct tgsi_instruction
630 tgsi_build_instruction(unsigned opcode
,
633 unsigned num_dst_regs
,
634 unsigned num_src_regs
,
635 struct tgsi_header
*header
)
637 struct tgsi_instruction instruction
;
639 assert (opcode
<= TGSI_OPCODE_LAST
);
640 assert (saturate
<= 1);
641 assert (num_dst_regs
<= 3);
642 assert (num_src_regs
<= 15);
644 instruction
= tgsi_default_instruction();
645 instruction
.Opcode
= opcode
;
646 instruction
.Saturate
= saturate
;
647 instruction
.Predicate
= predicate
;
648 instruction
.NumDstRegs
= num_dst_regs
;
649 instruction
.NumSrcRegs
= num_src_regs
;
651 header_bodysize_grow( header
);
658 struct tgsi_instruction
*instruction
,
659 struct tgsi_header
*header
)
661 assert (instruction
->NrTokens
< 0xFF);
663 instruction
->NrTokens
++;
665 header_bodysize_grow( header
);
668 struct tgsi_instruction_predicate
669 tgsi_default_instruction_predicate(void)
671 struct tgsi_instruction_predicate instruction_predicate
;
673 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
674 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
675 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
676 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
677 instruction_predicate
.Negate
= 0;
678 instruction_predicate
.Index
= 0;
679 instruction_predicate
.Padding
= 0;
681 return instruction_predicate
;
684 static struct tgsi_instruction_predicate
685 tgsi_build_instruction_predicate(int index
,
691 struct tgsi_instruction
*instruction
,
692 struct tgsi_header
*header
)
694 struct tgsi_instruction_predicate instruction_predicate
;
696 instruction_predicate
= tgsi_default_instruction_predicate();
697 instruction_predicate
.SwizzleX
= swizzleX
;
698 instruction_predicate
.SwizzleY
= swizzleY
;
699 instruction_predicate
.SwizzleZ
= swizzleZ
;
700 instruction_predicate
.SwizzleW
= swizzleW
;
701 instruction_predicate
.Negate
= negate
;
702 instruction_predicate
.Index
= index
;
704 instruction_grow(instruction
, header
);
706 return instruction_predicate
;
709 static struct tgsi_instruction_label
710 tgsi_default_instruction_label( void )
712 struct tgsi_instruction_label instruction_label
;
714 instruction_label
.Label
= 0;
715 instruction_label
.Padding
= 0;
717 return instruction_label
;
720 static struct tgsi_instruction_label
721 tgsi_build_instruction_label(
723 struct tgsi_token
*prev_token
,
724 struct tgsi_instruction
*instruction
,
725 struct tgsi_header
*header
)
727 struct tgsi_instruction_label instruction_label
;
729 instruction_label
.Label
= label
;
730 instruction_label
.Padding
= 0;
731 instruction
->Label
= 1;
733 instruction_grow( instruction
, header
);
735 return instruction_label
;
738 static struct tgsi_instruction_texture
739 tgsi_default_instruction_texture( void )
741 struct tgsi_instruction_texture instruction_texture
;
743 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
744 instruction_texture
.NumOffsets
= 0;
745 instruction_texture
.Padding
= 0;
747 return instruction_texture
;
750 static struct tgsi_instruction_texture
751 tgsi_build_instruction_texture(
753 unsigned num_offsets
,
754 struct tgsi_token
*prev_token
,
755 struct tgsi_instruction
*instruction
,
756 struct tgsi_header
*header
)
758 struct tgsi_instruction_texture instruction_texture
;
760 instruction_texture
.Texture
= texture
;
761 instruction_texture
.NumOffsets
= num_offsets
;
762 instruction_texture
.Padding
= 0;
763 instruction
->Texture
= 1;
765 instruction_grow( instruction
, header
);
767 return instruction_texture
;
770 static struct tgsi_instruction_memory
771 tgsi_default_instruction_memory( void )
773 struct tgsi_instruction_memory instruction_memory
;
775 instruction_memory
.Qualifier
= 0;
776 instruction_memory
.Padding
= 0;
778 return instruction_memory
;
781 static struct tgsi_instruction_memory
782 tgsi_build_instruction_memory(
784 struct tgsi_token
*prev_token
,
785 struct tgsi_instruction
*instruction
,
786 struct tgsi_header
*header
)
788 struct tgsi_instruction_memory instruction_memory
;
790 instruction_memory
.Qualifier
= qualifier
;
791 instruction_memory
.Padding
= 0;
792 instruction
->Memory
= 1;
794 instruction_grow( instruction
, header
);
796 return instruction_memory
;
799 static struct tgsi_texture_offset
800 tgsi_default_texture_offset( void )
802 struct tgsi_texture_offset texture_offset
;
804 texture_offset
.Index
= 0;
805 texture_offset
.File
= 0;
806 texture_offset
.SwizzleX
= 0;
807 texture_offset
.SwizzleY
= 0;
808 texture_offset
.SwizzleZ
= 0;
809 texture_offset
.Padding
= 0;
811 return texture_offset
;
814 static struct tgsi_texture_offset
815 tgsi_build_texture_offset(
816 int index
, int file
, int swizzle_x
, int swizzle_y
, int swizzle_z
,
817 struct tgsi_token
*prev_token
,
818 struct tgsi_instruction
*instruction
,
819 struct tgsi_header
*header
)
821 struct tgsi_texture_offset texture_offset
;
823 texture_offset
.Index
= index
;
824 texture_offset
.File
= file
;
825 texture_offset
.SwizzleX
= swizzle_x
;
826 texture_offset
.SwizzleY
= swizzle_y
;
827 texture_offset
.SwizzleZ
= swizzle_z
;
828 texture_offset
.Padding
= 0;
830 instruction_grow( instruction
, header
);
832 return texture_offset
;
835 static struct tgsi_src_register
836 tgsi_default_src_register( void )
838 struct tgsi_src_register src_register
;
840 src_register
.File
= TGSI_FILE_NULL
;
841 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
842 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
843 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
844 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
845 src_register
.Negate
= 0;
846 src_register
.Absolute
= 0;
847 src_register
.Indirect
= 0;
848 src_register
.Dimension
= 0;
849 src_register
.Index
= 0;
854 static struct tgsi_src_register
855 tgsi_build_src_register(
866 struct tgsi_instruction
*instruction
,
867 struct tgsi_header
*header
)
869 struct tgsi_src_register src_register
;
871 assert( file
< TGSI_FILE_COUNT
);
872 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
873 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
874 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
875 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
876 assert( negate
<= 1 );
877 assert( index
>= -0x8000 && index
<= 0x7FFF );
879 src_register
.File
= file
;
880 src_register
.SwizzleX
= swizzle_x
;
881 src_register
.SwizzleY
= swizzle_y
;
882 src_register
.SwizzleZ
= swizzle_z
;
883 src_register
.SwizzleW
= swizzle_w
;
884 src_register
.Negate
= negate
;
885 src_register
.Absolute
= absolute
;
886 src_register
.Indirect
= indirect
;
887 src_register
.Dimension
= dimension
;
888 src_register
.Index
= index
;
890 instruction_grow( instruction
, header
);
895 static struct tgsi_ind_register
896 tgsi_default_ind_register( void )
898 struct tgsi_ind_register ind_register
;
900 ind_register
.File
= TGSI_FILE_NULL
;
901 ind_register
.Index
= 0;
902 ind_register
.Swizzle
= TGSI_SWIZZLE_X
;
903 ind_register
.ArrayID
= 0;
908 static struct tgsi_ind_register
909 tgsi_build_ind_register(
914 struct tgsi_instruction
*instruction
,
915 struct tgsi_header
*header
)
917 struct tgsi_ind_register ind_register
;
919 assert( file
< TGSI_FILE_COUNT
);
920 assert( swizzle
<= TGSI_SWIZZLE_W
);
921 assert( index
>= -0x8000 && index
<= 0x7FFF );
923 ind_register
.File
= file
;
924 ind_register
.Swizzle
= swizzle
;
925 ind_register
.Index
= index
;
926 ind_register
.ArrayID
= arrayid
;
928 instruction_grow( instruction
, header
);
933 static struct tgsi_dimension
934 tgsi_default_dimension( void )
936 struct tgsi_dimension dimension
;
938 dimension
.Indirect
= 0;
939 dimension
.Dimension
= 0;
940 dimension
.Padding
= 0;
946 static struct tgsi_full_src_register
947 tgsi_default_full_src_register( void )
949 struct tgsi_full_src_register full_src_register
;
951 full_src_register
.Register
= tgsi_default_src_register();
952 full_src_register
.Indirect
= tgsi_default_ind_register();
953 full_src_register
.Dimension
= tgsi_default_dimension();
954 full_src_register
.DimIndirect
= tgsi_default_ind_register();
956 return full_src_register
;
959 static struct tgsi_dimension
960 tgsi_build_dimension(
963 struct tgsi_instruction
*instruction
,
964 struct tgsi_header
*header
)
966 struct tgsi_dimension dimension
;
968 dimension
.Indirect
= indirect
;
969 dimension
.Dimension
= 0;
970 dimension
.Padding
= 0;
971 dimension
.Index
= index
;
973 instruction_grow( instruction
, header
);
978 static struct tgsi_dst_register
979 tgsi_default_dst_register( void )
981 struct tgsi_dst_register dst_register
;
983 dst_register
.File
= TGSI_FILE_NULL
;
984 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
985 dst_register
.Indirect
= 0;
986 dst_register
.Dimension
= 0;
987 dst_register
.Index
= 0;
988 dst_register
.Padding
= 0;
993 static struct tgsi_dst_register
994 tgsi_build_dst_register(
1000 struct tgsi_instruction
*instruction
,
1001 struct tgsi_header
*header
)
1003 struct tgsi_dst_register dst_register
;
1005 assert( file
< TGSI_FILE_COUNT
);
1006 assert( mask
<= TGSI_WRITEMASK_XYZW
);
1007 assert( index
>= -32768 && index
<= 32767 );
1009 dst_register
.File
= file
;
1010 dst_register
.WriteMask
= mask
;
1011 dst_register
.Indirect
= indirect
;
1012 dst_register
.Dimension
= dimension
;
1013 dst_register
.Index
= index
;
1014 dst_register
.Padding
= 0;
1016 instruction_grow( instruction
, header
);
1018 return dst_register
;
1021 static struct tgsi_full_dst_register
1022 tgsi_default_full_dst_register( void )
1024 struct tgsi_full_dst_register full_dst_register
;
1026 full_dst_register
.Register
= tgsi_default_dst_register();
1027 full_dst_register
.Indirect
= tgsi_default_ind_register();
1028 full_dst_register
.Dimension
= tgsi_default_dimension();
1029 full_dst_register
.DimIndirect
= tgsi_default_ind_register();
1031 return full_dst_register
;
1034 struct tgsi_full_instruction
1035 tgsi_default_full_instruction( void )
1037 struct tgsi_full_instruction full_instruction
;
1040 full_instruction
.Instruction
= tgsi_default_instruction();
1041 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
1042 full_instruction
.Label
= tgsi_default_instruction_label();
1043 full_instruction
.Texture
= tgsi_default_instruction_texture();
1044 full_instruction
.Memory
= tgsi_default_instruction_memory();
1045 for( i
= 0; i
< TGSI_FULL_MAX_TEX_OFFSETS
; i
++ ) {
1046 full_instruction
.TexOffsets
[i
] = tgsi_default_texture_offset();
1048 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
1049 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
1051 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
1052 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
1055 return full_instruction
;
1059 tgsi_build_full_instruction(
1060 const struct tgsi_full_instruction
*full_inst
,
1061 struct tgsi_token
*tokens
,
1062 struct tgsi_header
*header
,
1067 struct tgsi_instruction
*instruction
;
1068 struct tgsi_token
*prev_token
;
1070 if( maxsize
<= size
)
1072 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
1075 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
1076 full_inst
->Instruction
.Saturate
,
1077 full_inst
->Instruction
.Predicate
,
1078 full_inst
->Instruction
.NumDstRegs
,
1079 full_inst
->Instruction
.NumSrcRegs
,
1081 prev_token
= (struct tgsi_token
*) instruction
;
1083 if (full_inst
->Instruction
.Predicate
) {
1084 struct tgsi_instruction_predicate
*instruction_predicate
;
1086 if (maxsize
<= size
) {
1089 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
1092 *instruction_predicate
=
1093 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
1094 full_inst
->Predicate
.Negate
,
1095 full_inst
->Predicate
.SwizzleX
,
1096 full_inst
->Predicate
.SwizzleY
,
1097 full_inst
->Predicate
.SwizzleZ
,
1098 full_inst
->Predicate
.SwizzleW
,
1103 if (full_inst
->Instruction
.Label
) {
1104 struct tgsi_instruction_label
*instruction_label
;
1106 if( maxsize
<= size
)
1109 (struct tgsi_instruction_label
*) &tokens
[size
];
1112 *instruction_label
= tgsi_build_instruction_label(
1113 full_inst
->Label
.Label
,
1117 prev_token
= (struct tgsi_token
*) instruction_label
;
1120 if (full_inst
->Instruction
.Texture
) {
1121 struct tgsi_instruction_texture
*instruction_texture
;
1123 if( maxsize
<= size
)
1125 instruction_texture
=
1126 (struct tgsi_instruction_texture
*) &tokens
[size
];
1129 *instruction_texture
= tgsi_build_instruction_texture(
1130 full_inst
->Texture
.Texture
,
1131 full_inst
->Texture
.NumOffsets
,
1135 prev_token
= (struct tgsi_token
*) instruction_texture
;
1137 for (i
= 0; i
< full_inst
->Texture
.NumOffsets
; i
++) {
1138 struct tgsi_texture_offset
*texture_offset
;
1140 if ( maxsize
<= size
)
1142 texture_offset
= (struct tgsi_texture_offset
*)&tokens
[size
];
1144 *texture_offset
= tgsi_build_texture_offset(
1145 full_inst
->TexOffsets
[i
].Index
,
1146 full_inst
->TexOffsets
[i
].File
,
1147 full_inst
->TexOffsets
[i
].SwizzleX
,
1148 full_inst
->TexOffsets
[i
].SwizzleY
,
1149 full_inst
->TexOffsets
[i
].SwizzleZ
,
1153 prev_token
= (struct tgsi_token
*) texture_offset
;
1157 if (full_inst
->Instruction
.Memory
) {
1158 struct tgsi_instruction_memory
*instruction_memory
;
1160 if( maxsize
<= size
)
1162 instruction_memory
=
1163 (struct tgsi_instruction_memory
*) &tokens
[size
];
1166 *instruction_memory
= tgsi_build_instruction_memory(
1167 full_inst
->Memory
.Qualifier
,
1171 prev_token
= (struct tgsi_token
*) instruction_memory
;
1174 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
1175 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
1176 struct tgsi_dst_register
*dst_register
;
1178 if( maxsize
<= size
)
1180 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
1183 *dst_register
= tgsi_build_dst_register(
1185 reg
->Register
.WriteMask
,
1186 reg
->Register
.Indirect
,
1187 reg
->Register
.Dimension
,
1188 reg
->Register
.Index
,
1192 if( reg
->Register
.Indirect
) {
1193 struct tgsi_ind_register
*ind
;
1195 if( maxsize
<= size
)
1197 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1200 *ind
= tgsi_build_ind_register(
1202 reg
->Indirect
.Swizzle
,
1203 reg
->Indirect
.Index
,
1204 reg
->Indirect
.ArrayID
,
1209 if( reg
->Register
.Dimension
) {
1210 struct tgsi_dimension
*dim
;
1212 assert( !reg
->Dimension
.Dimension
);
1214 if( maxsize
<= size
)
1216 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1219 *dim
= tgsi_build_dimension(
1220 reg
->Dimension
.Indirect
,
1221 reg
->Dimension
.Index
,
1225 if( reg
->Dimension
.Indirect
) {
1226 struct tgsi_ind_register
*ind
;
1228 if( maxsize
<= size
)
1230 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1233 *ind
= tgsi_build_ind_register(
1234 reg
->DimIndirect
.File
,
1235 reg
->DimIndirect
.Swizzle
,
1236 reg
->DimIndirect
.Index
,
1237 reg
->DimIndirect
.ArrayID
,
1244 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
1245 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
1246 struct tgsi_src_register
*src_register
;
1248 if( maxsize
<= size
)
1250 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
1253 *src_register
= tgsi_build_src_register(
1255 reg
->Register
.SwizzleX
,
1256 reg
->Register
.SwizzleY
,
1257 reg
->Register
.SwizzleZ
,
1258 reg
->Register
.SwizzleW
,
1259 reg
->Register
.Negate
,
1260 reg
->Register
.Absolute
,
1261 reg
->Register
.Indirect
,
1262 reg
->Register
.Dimension
,
1263 reg
->Register
.Index
,
1267 if( reg
->Register
.Indirect
) {
1268 struct tgsi_ind_register
*ind
;
1270 if( maxsize
<= size
)
1272 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1275 *ind
= tgsi_build_ind_register(
1277 reg
->Indirect
.Swizzle
,
1278 reg
->Indirect
.Index
,
1279 reg
->Indirect
.ArrayID
,
1284 if( reg
->Register
.Dimension
) {
1285 struct tgsi_dimension
*dim
;
1287 assert( !reg
->Dimension
.Dimension
);
1289 if( maxsize
<= size
)
1291 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1294 *dim
= tgsi_build_dimension(
1295 reg
->Dimension
.Indirect
,
1296 reg
->Dimension
.Index
,
1300 if( reg
->Dimension
.Indirect
) {
1301 struct tgsi_ind_register
*ind
;
1303 if( maxsize
<= size
)
1305 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1308 *ind
= tgsi_build_ind_register(
1309 reg
->DimIndirect
.File
,
1310 reg
->DimIndirect
.Swizzle
,
1311 reg
->DimIndirect
.Index
,
1312 reg
->DimIndirect
.ArrayID
,
1322 static struct tgsi_property
1323 tgsi_default_property( void )
1325 struct tgsi_property property
;
1327 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1328 property
.NrTokens
= 1;
1329 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1330 property
.Padding
= 0;
1335 static struct tgsi_property
1336 tgsi_build_property(unsigned property_name
,
1337 struct tgsi_header
*header
)
1339 struct tgsi_property property
;
1341 property
= tgsi_default_property();
1342 property
.PropertyName
= property_name
;
1344 header_bodysize_grow( header
);
1350 struct tgsi_full_property
1351 tgsi_default_full_property( void )
1353 struct tgsi_full_property full_property
;
1355 full_property
.Property
= tgsi_default_property();
1356 memset(full_property
.u
, 0,
1357 sizeof(struct tgsi_property_data
) * 8);
1359 return full_property
;
1364 struct tgsi_property
*property
,
1365 struct tgsi_header
*header
)
1367 assert( property
->NrTokens
< 0xFF );
1369 property
->NrTokens
++;
1371 header_bodysize_grow( header
);
1374 static struct tgsi_property_data
1375 tgsi_build_property_data(
1377 struct tgsi_property
*property
,
1378 struct tgsi_header
*header
)
1380 struct tgsi_property_data property_data
;
1382 property_data
.Data
= value
;
1384 property_grow( property
, header
);
1386 return property_data
;
1390 tgsi_build_full_property(
1391 const struct tgsi_full_property
*full_prop
,
1392 struct tgsi_token
*tokens
,
1393 struct tgsi_header
*header
,
1396 unsigned size
= 0, i
;
1397 struct tgsi_property
*property
;
1399 if( maxsize
<= size
)
1401 property
= (struct tgsi_property
*) &tokens
[size
];
1404 *property
= tgsi_build_property(
1405 full_prop
->Property
.PropertyName
,
1408 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1410 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1411 struct tgsi_property_data
*data
;
1413 if( maxsize
<= size
)
1415 data
= (struct tgsi_property_data
*) &tokens
[size
];
1418 *data
= tgsi_build_property_data(
1419 full_prop
->u
[i
].Data
,