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;
115 static struct tgsi_declaration
116 tgsi_build_declaration(
119 unsigned interpolate
,
123 struct tgsi_header
*header
)
125 struct tgsi_declaration declaration
;
127 assert( file
< TGSI_FILE_COUNT
);
128 assert( interpolate
< TGSI_INTERPOLATE_COUNT
);
130 declaration
= tgsi_default_declaration();
131 declaration
.File
= file
;
132 declaration
.UsageMask
= usage_mask
;
133 declaration
.Interpolate
= interpolate
;
134 declaration
.Dimension
= dimension
;
135 declaration
.Semantic
= semantic
;
136 declaration
.Invariant
= invariant
;
138 header_bodysize_grow( header
);
143 static struct tgsi_declaration_range
144 tgsi_default_declaration_range( void )
146 struct tgsi_declaration_range dr
;
154 static struct tgsi_declaration_range
155 tgsi_build_declaration_range(
158 struct tgsi_declaration
*declaration
,
159 struct tgsi_header
*header
)
161 struct tgsi_declaration_range declaration_range
;
163 assert( last
>= first
);
164 assert( last
<= 0xFFFF );
166 declaration_range
.First
= first
;
167 declaration_range
.Last
= last
;
169 declaration_grow( declaration
, header
);
171 return declaration_range
;
174 static struct tgsi_declaration_dimension
175 tgsi_build_declaration_dimension(unsigned index_2d
,
176 struct tgsi_declaration
*declaration
,
177 struct tgsi_header
*header
)
179 struct tgsi_declaration_dimension dd
;
181 assert(index_2d
<= 0xFFFF);
183 dd
.Index2D
= index_2d
;
186 declaration_grow(declaration
, header
);
191 static struct tgsi_declaration_interp
192 tgsi_default_declaration_interp( void )
194 struct tgsi_declaration_interp di
;
196 di
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
198 di
.CylindricalWrap
= 0;
203 static struct tgsi_declaration_interp
204 tgsi_build_declaration_interp(unsigned interpolate
,
206 unsigned cylindrical_wrap
,
207 struct tgsi_declaration
*declaration
,
208 struct tgsi_header
*header
)
210 struct tgsi_declaration_interp di
;
212 di
.Interpolate
= interpolate
;
213 di
.Centroid
= centroid
;
214 di
.CylindricalWrap
= cylindrical_wrap
;
216 declaration_grow(declaration
, header
);
221 static struct tgsi_declaration_semantic
222 tgsi_default_declaration_semantic( void )
224 struct tgsi_declaration_semantic ds
;
226 ds
.Name
= TGSI_SEMANTIC_POSITION
;
233 static struct tgsi_declaration_semantic
234 tgsi_build_declaration_semantic(
235 unsigned semantic_name
,
236 unsigned semantic_index
,
237 struct tgsi_declaration
*declaration
,
238 struct tgsi_header
*header
)
240 struct tgsi_declaration_semantic ds
;
242 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
243 assert( semantic_index
<= 0xFFFF );
245 ds
.Name
= semantic_name
;
246 ds
.Index
= semantic_index
;
249 declaration_grow( declaration
, header
);
254 static struct tgsi_declaration_resource
255 tgsi_default_declaration_resource(void)
257 struct tgsi_declaration_resource dr
;
259 dr
.Resource
= TGSI_BUFFER
;
264 static struct tgsi_declaration_resource
265 tgsi_build_declaration_resource(unsigned texture
,
266 struct tgsi_declaration
*declaration
,
267 struct tgsi_header
*header
)
269 struct tgsi_declaration_resource dr
;
271 dr
= tgsi_default_declaration_resource();
272 dr
.Resource
= texture
;
274 declaration_grow(declaration
, header
);
279 static struct tgsi_declaration_sampler_view
280 tgsi_default_declaration_sampler_view(void)
282 struct tgsi_declaration_sampler_view dsv
;
284 dsv
.Resource
= TGSI_BUFFER
;
285 dsv
.ReturnTypeX
= PIPE_TYPE_UNORM
;
286 dsv
.ReturnTypeY
= PIPE_TYPE_UNORM
;
287 dsv
.ReturnTypeZ
= PIPE_TYPE_UNORM
;
288 dsv
.ReturnTypeW
= PIPE_TYPE_UNORM
;
293 static struct tgsi_declaration_sampler_view
294 tgsi_build_declaration_sampler_view(unsigned texture
,
295 unsigned return_type_x
,
296 unsigned return_type_y
,
297 unsigned return_type_z
,
298 unsigned return_type_w
,
299 struct tgsi_declaration
*declaration
,
300 struct tgsi_header
*header
)
302 struct tgsi_declaration_sampler_view dsv
;
304 dsv
= tgsi_default_declaration_sampler_view();
305 dsv
.Resource
= texture
;
306 dsv
.ReturnTypeX
= return_type_x
;
307 dsv
.ReturnTypeY
= return_type_y
;
308 dsv
.ReturnTypeZ
= return_type_z
;
309 dsv
.ReturnTypeW
= return_type_w
;
311 declaration_grow(declaration
, header
);
317 struct tgsi_full_declaration
318 tgsi_default_full_declaration( void )
320 struct tgsi_full_declaration full_declaration
;
322 full_declaration
.Declaration
= tgsi_default_declaration();
323 full_declaration
.Range
= tgsi_default_declaration_range();
324 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
325 full_declaration
.Interp
= tgsi_default_declaration_interp();
326 full_declaration
.ImmediateData
.u
= NULL
;
327 full_declaration
.Resource
= tgsi_default_declaration_resource();
328 full_declaration
.SamplerView
= tgsi_default_declaration_sampler_view();
330 return full_declaration
;
334 tgsi_build_full_declaration(
335 const struct tgsi_full_declaration
*full_decl
,
336 struct tgsi_token
*tokens
,
337 struct tgsi_header
*header
,
341 struct tgsi_declaration
*declaration
;
342 struct tgsi_declaration_range
*dr
;
344 if( maxsize
<= size
)
346 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
349 *declaration
= tgsi_build_declaration(
350 full_decl
->Declaration
.File
,
351 full_decl
->Declaration
.UsageMask
,
352 full_decl
->Declaration
.Interpolate
,
353 full_decl
->Declaration
.Dimension
,
354 full_decl
->Declaration
.Semantic
,
355 full_decl
->Declaration
.Invariant
,
360 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
363 *dr
= tgsi_build_declaration_range(
364 full_decl
->Range
.First
,
365 full_decl
->Range
.Last
,
369 if (full_decl
->Declaration
.Dimension
) {
370 struct tgsi_declaration_dimension
*dd
;
372 if (maxsize
<= size
) {
375 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
378 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
383 if (full_decl
->Declaration
.Interpolate
) {
384 struct tgsi_declaration_interp
*di
;
386 if (maxsize
<= size
) {
389 di
= (struct tgsi_declaration_interp
*)&tokens
[size
];
392 *di
= tgsi_build_declaration_interp(full_decl
->Interp
.Interpolate
,
393 full_decl
->Interp
.Centroid
,
394 full_decl
->Interp
.CylindricalWrap
,
399 if( full_decl
->Declaration
.Semantic
) {
400 struct tgsi_declaration_semantic
*ds
;
402 if( maxsize
<= size
)
404 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
407 *ds
= tgsi_build_declaration_semantic(
408 full_decl
->Semantic
.Name
,
409 full_decl
->Semantic
.Index
,
414 if (full_decl
->Declaration
.File
== TGSI_FILE_IMMEDIATE_ARRAY
) {
416 union tgsi_immediate_data
*data
;
418 for (i
= 0; i
<= dr
->Last
; ++i
) {
419 for (j
= 0; j
< 4; ++j
) {
420 unsigned idx
= i
*4 + j
;
423 data
= (union tgsi_immediate_data
*) &tokens
[size
];
426 *data
= full_decl
->ImmediateData
.u
[idx
];
427 declaration_grow( declaration
, header
);
432 if (full_decl
->Declaration
.File
== TGSI_FILE_RESOURCE
) {
433 struct tgsi_declaration_resource
*dr
;
435 if (maxsize
<= size
) {
438 dr
= (struct tgsi_declaration_resource
*)&tokens
[size
];
441 *dr
= tgsi_build_declaration_resource(full_decl
->Resource
.Resource
,
446 if (full_decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
447 struct tgsi_declaration_sampler_view
*dsv
;
449 if (maxsize
<= size
) {
452 dsv
= (struct tgsi_declaration_sampler_view
*)&tokens
[size
];
455 *dsv
= tgsi_build_declaration_sampler_view(
456 full_decl
->SamplerView
.Resource
,
457 full_decl
->SamplerView
.ReturnTypeX
,
458 full_decl
->SamplerView
.ReturnTypeY
,
459 full_decl
->SamplerView
.ReturnTypeZ
,
460 full_decl
->SamplerView
.ReturnTypeW
,
472 static struct tgsi_immediate
473 tgsi_default_immediate( void )
475 struct tgsi_immediate immediate
;
477 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
478 immediate
.NrTokens
= 1;
479 immediate
.DataType
= TGSI_IMM_FLOAT32
;
480 immediate
.Padding
= 0;
485 static struct tgsi_immediate
486 tgsi_build_immediate(
487 struct tgsi_header
*header
)
489 struct tgsi_immediate immediate
;
491 immediate
= tgsi_default_immediate();
493 header_bodysize_grow( header
);
498 struct tgsi_full_immediate
499 tgsi_default_full_immediate( void )
501 struct tgsi_full_immediate fullimm
;
503 fullimm
.Immediate
= tgsi_default_immediate();
504 fullimm
.u
[0].Float
= 0.0f
;
505 fullimm
.u
[1].Float
= 0.0f
;
506 fullimm
.u
[2].Float
= 0.0f
;
507 fullimm
.u
[3].Float
= 0.0f
;
514 struct tgsi_immediate
*immediate
,
515 struct tgsi_header
*header
)
517 assert( immediate
->NrTokens
< 0xFF );
519 immediate
->NrTokens
++;
521 header_bodysize_grow( header
);
524 static union tgsi_immediate_data
525 tgsi_build_immediate_float32(
527 struct tgsi_immediate
*immediate
,
528 struct tgsi_header
*header
)
530 union tgsi_immediate_data immediate_data
;
532 immediate_data
.Float
= value
;
534 immediate_grow( immediate
, header
);
536 return immediate_data
;
540 tgsi_build_full_immediate(
541 const struct tgsi_full_immediate
*full_imm
,
542 struct tgsi_token
*tokens
,
543 struct tgsi_header
*header
,
546 unsigned size
= 0, i
;
547 struct tgsi_immediate
*immediate
;
549 if( maxsize
<= size
)
551 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
554 *immediate
= tgsi_build_immediate( header
);
556 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
558 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
559 union tgsi_immediate_data
*data
;
561 if( maxsize
<= size
)
563 data
= (union tgsi_immediate_data
*) &tokens
[size
];
566 *data
= tgsi_build_immediate_float32(
567 full_imm
->u
[i
].Float
,
579 struct tgsi_instruction
580 tgsi_default_instruction( void )
582 struct tgsi_instruction instruction
;
584 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
585 instruction
.NrTokens
= 0;
586 instruction
.Opcode
= TGSI_OPCODE_MOV
;
587 instruction
.Saturate
= TGSI_SAT_NONE
;
588 instruction
.Predicate
= 0;
589 instruction
.NumDstRegs
= 1;
590 instruction
.NumSrcRegs
= 1;
591 instruction
.Label
= 0;
592 instruction
.Texture
= 0;
593 instruction
.Padding
= 0;
598 static struct tgsi_instruction
599 tgsi_build_instruction(unsigned opcode
,
602 unsigned num_dst_regs
,
603 unsigned num_src_regs
,
604 struct tgsi_header
*header
)
606 struct tgsi_instruction instruction
;
608 assert (opcode
<= TGSI_OPCODE_LAST
);
609 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
610 assert (num_dst_regs
<= 3);
611 assert (num_src_regs
<= 15);
613 instruction
= tgsi_default_instruction();
614 instruction
.Opcode
= opcode
;
615 instruction
.Saturate
= saturate
;
616 instruction
.Predicate
= predicate
;
617 instruction
.NumDstRegs
= num_dst_regs
;
618 instruction
.NumSrcRegs
= num_src_regs
;
620 header_bodysize_grow( header
);
627 struct tgsi_instruction
*instruction
,
628 struct tgsi_header
*header
)
630 assert (instruction
->NrTokens
< 0xFF);
632 instruction
->NrTokens
++;
634 header_bodysize_grow( header
);
637 struct tgsi_instruction_predicate
638 tgsi_default_instruction_predicate(void)
640 struct tgsi_instruction_predicate instruction_predicate
;
642 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
643 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
644 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
645 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
646 instruction_predicate
.Negate
= 0;
647 instruction_predicate
.Index
= 0;
648 instruction_predicate
.Padding
= 0;
650 return instruction_predicate
;
653 static struct tgsi_instruction_predicate
654 tgsi_build_instruction_predicate(int index
,
660 struct tgsi_instruction
*instruction
,
661 struct tgsi_header
*header
)
663 struct tgsi_instruction_predicate instruction_predicate
;
665 instruction_predicate
= tgsi_default_instruction_predicate();
666 instruction_predicate
.SwizzleX
= swizzleX
;
667 instruction_predicate
.SwizzleY
= swizzleY
;
668 instruction_predicate
.SwizzleZ
= swizzleZ
;
669 instruction_predicate
.SwizzleW
= swizzleW
;
670 instruction_predicate
.Negate
= negate
;
671 instruction_predicate
.Index
= index
;
673 instruction_grow(instruction
, header
);
675 return instruction_predicate
;
678 static struct tgsi_instruction_label
679 tgsi_default_instruction_label( void )
681 struct tgsi_instruction_label instruction_label
;
683 instruction_label
.Label
= 0;
684 instruction_label
.Padding
= 0;
686 return instruction_label
;
689 static struct tgsi_instruction_label
690 tgsi_build_instruction_label(
692 struct tgsi_token
*prev_token
,
693 struct tgsi_instruction
*instruction
,
694 struct tgsi_header
*header
)
696 struct tgsi_instruction_label instruction_label
;
698 instruction_label
.Label
= label
;
699 instruction_label
.Padding
= 0;
700 instruction
->Label
= 1;
702 instruction_grow( instruction
, header
);
704 return instruction_label
;
707 static struct tgsi_instruction_texture
708 tgsi_default_instruction_texture( void )
710 struct tgsi_instruction_texture instruction_texture
;
712 instruction_texture
.Texture
= TGSI_BUFFER
;
713 instruction_texture
.NumOffsets
= 0;
714 instruction_texture
.Padding
= 0;
716 return instruction_texture
;
719 static struct tgsi_instruction_texture
720 tgsi_build_instruction_texture(
722 unsigned num_offsets
,
723 struct tgsi_token
*prev_token
,
724 struct tgsi_instruction
*instruction
,
725 struct tgsi_header
*header
)
727 struct tgsi_instruction_texture instruction_texture
;
729 instruction_texture
.Texture
= texture
;
730 instruction_texture
.NumOffsets
= num_offsets
;
731 instruction_texture
.Padding
= 0;
732 instruction
->Texture
= 1;
734 instruction_grow( instruction
, header
);
736 return instruction_texture
;
740 static struct tgsi_texture_offset
741 tgsi_default_texture_offset( void )
743 struct tgsi_texture_offset texture_offset
;
745 texture_offset
.Index
= 0;
746 texture_offset
.File
= 0;
747 texture_offset
.SwizzleX
= 0;
748 texture_offset
.SwizzleY
= 0;
749 texture_offset
.SwizzleZ
= 0;
750 texture_offset
.Padding
= 0;
752 return texture_offset
;
755 static struct tgsi_texture_offset
756 tgsi_build_texture_offset(
757 int index
, int file
, int swizzle_x
, int swizzle_y
, int swizzle_z
,
758 struct tgsi_token
*prev_token
,
759 struct tgsi_instruction
*instruction
,
760 struct tgsi_header
*header
)
762 struct tgsi_texture_offset texture_offset
;
764 texture_offset
.Index
= index
;
765 texture_offset
.File
= file
;
766 texture_offset
.SwizzleX
= swizzle_x
;
767 texture_offset
.SwizzleY
= swizzle_y
;
768 texture_offset
.SwizzleZ
= swizzle_z
;
769 texture_offset
.Padding
= 0;
771 instruction_grow( instruction
, header
);
773 return texture_offset
;
776 static struct tgsi_src_register
777 tgsi_default_src_register( void )
779 struct tgsi_src_register src_register
;
781 src_register
.File
= TGSI_FILE_NULL
;
782 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
783 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
784 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
785 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
786 src_register
.Negate
= 0;
787 src_register
.Absolute
= 0;
788 src_register
.Indirect
= 0;
789 src_register
.Dimension
= 0;
790 src_register
.Index
= 0;
795 static struct tgsi_src_register
796 tgsi_build_src_register(
807 struct tgsi_instruction
*instruction
,
808 struct tgsi_header
*header
)
810 struct tgsi_src_register src_register
;
812 assert( file
< TGSI_FILE_COUNT
);
813 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
814 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
815 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
816 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
817 assert( negate
<= 1 );
818 assert( index
>= -0x8000 && index
<= 0x7FFF );
820 src_register
.File
= file
;
821 src_register
.SwizzleX
= swizzle_x
;
822 src_register
.SwizzleY
= swizzle_y
;
823 src_register
.SwizzleZ
= swizzle_z
;
824 src_register
.SwizzleW
= swizzle_w
;
825 src_register
.Negate
= negate
;
826 src_register
.Absolute
= absolute
;
827 src_register
.Indirect
= indirect
;
828 src_register
.Dimension
= dimension
;
829 src_register
.Index
= index
;
831 instruction_grow( instruction
, header
);
836 static struct tgsi_dimension
837 tgsi_default_dimension( void )
839 struct tgsi_dimension dimension
;
841 dimension
.Indirect
= 0;
842 dimension
.Dimension
= 0;
843 dimension
.Padding
= 0;
849 static struct tgsi_full_src_register
850 tgsi_default_full_src_register( void )
852 struct tgsi_full_src_register full_src_register
;
854 full_src_register
.Register
= tgsi_default_src_register();
855 full_src_register
.Indirect
= tgsi_default_src_register();
856 full_src_register
.Dimension
= tgsi_default_dimension();
857 full_src_register
.DimIndirect
= tgsi_default_src_register();
859 return full_src_register
;
862 static struct tgsi_dimension
863 tgsi_build_dimension(
866 struct tgsi_instruction
*instruction
,
867 struct tgsi_header
*header
)
869 struct tgsi_dimension dimension
;
871 dimension
.Indirect
= indirect
;
872 dimension
.Dimension
= 0;
873 dimension
.Padding
= 0;
874 dimension
.Index
= index
;
876 instruction_grow( instruction
, header
);
881 static struct tgsi_dst_register
882 tgsi_default_dst_register( void )
884 struct tgsi_dst_register dst_register
;
886 dst_register
.File
= TGSI_FILE_NULL
;
887 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
888 dst_register
.Indirect
= 0;
889 dst_register
.Dimension
= 0;
890 dst_register
.Index
= 0;
891 dst_register
.Padding
= 0;
896 static struct tgsi_dst_register
897 tgsi_build_dst_register(
903 struct tgsi_instruction
*instruction
,
904 struct tgsi_header
*header
)
906 struct tgsi_dst_register dst_register
;
908 assert( file
< TGSI_FILE_COUNT
);
909 assert( mask
<= TGSI_WRITEMASK_XYZW
);
910 assert( index
>= -32768 && index
<= 32767 );
912 dst_register
.File
= file
;
913 dst_register
.WriteMask
= mask
;
914 dst_register
.Indirect
= indirect
;
915 dst_register
.Dimension
= dimension
;
916 dst_register
.Index
= index
;
917 dst_register
.Padding
= 0;
919 instruction_grow( instruction
, header
);
924 static struct tgsi_full_dst_register
925 tgsi_default_full_dst_register( void )
927 struct tgsi_full_dst_register full_dst_register
;
929 full_dst_register
.Register
= tgsi_default_dst_register();
930 full_dst_register
.Indirect
= tgsi_default_src_register();
931 full_dst_register
.Dimension
= tgsi_default_dimension();
932 full_dst_register
.DimIndirect
= tgsi_default_src_register();
934 return full_dst_register
;
937 struct tgsi_full_instruction
938 tgsi_default_full_instruction( void )
940 struct tgsi_full_instruction full_instruction
;
943 full_instruction
.Instruction
= tgsi_default_instruction();
944 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
945 full_instruction
.Label
= tgsi_default_instruction_label();
946 full_instruction
.Texture
= tgsi_default_instruction_texture();
947 for( i
= 0; i
< TGSI_FULL_MAX_TEX_OFFSETS
; i
++ ) {
948 full_instruction
.TexOffsets
[i
] = tgsi_default_texture_offset();
950 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
951 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
953 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
954 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
957 return full_instruction
;
961 tgsi_build_full_instruction(
962 const struct tgsi_full_instruction
*full_inst
,
963 struct tgsi_token
*tokens
,
964 struct tgsi_header
*header
,
969 struct tgsi_instruction
*instruction
;
970 struct tgsi_token
*prev_token
;
972 if( maxsize
<= size
)
974 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
977 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
978 full_inst
->Instruction
.Saturate
,
979 full_inst
->Instruction
.Predicate
,
980 full_inst
->Instruction
.NumDstRegs
,
981 full_inst
->Instruction
.NumSrcRegs
,
983 prev_token
= (struct tgsi_token
*) instruction
;
985 if (full_inst
->Instruction
.Predicate
) {
986 struct tgsi_instruction_predicate
*instruction_predicate
;
988 if (maxsize
<= size
) {
991 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
994 *instruction_predicate
=
995 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
996 full_inst
->Predicate
.Negate
,
997 full_inst
->Predicate
.SwizzleX
,
998 full_inst
->Predicate
.SwizzleY
,
999 full_inst
->Predicate
.SwizzleZ
,
1000 full_inst
->Predicate
.SwizzleW
,
1005 if (full_inst
->Instruction
.Label
) {
1006 struct tgsi_instruction_label
*instruction_label
;
1008 if( maxsize
<= size
)
1011 (struct tgsi_instruction_label
*) &tokens
[size
];
1014 *instruction_label
= tgsi_build_instruction_label(
1015 full_inst
->Label
.Label
,
1019 prev_token
= (struct tgsi_token
*) instruction_label
;
1022 if (full_inst
->Instruction
.Texture
) {
1023 struct tgsi_instruction_texture
*instruction_texture
;
1025 if( maxsize
<= size
)
1027 instruction_texture
=
1028 (struct tgsi_instruction_texture
*) &tokens
[size
];
1031 *instruction_texture
= tgsi_build_instruction_texture(
1032 full_inst
->Texture
.Texture
,
1033 full_inst
->Texture
.NumOffsets
,
1037 prev_token
= (struct tgsi_token
*) instruction_texture
;
1039 for (i
= 0; i
< full_inst
->Texture
.NumOffsets
; i
++) {
1040 struct tgsi_texture_offset
*texture_offset
;
1042 if ( maxsize
<= size
)
1044 texture_offset
= (struct tgsi_texture_offset
*)&tokens
[size
];
1046 *texture_offset
= tgsi_build_texture_offset(
1047 full_inst
->TexOffsets
[i
].Index
,
1048 full_inst
->TexOffsets
[i
].File
,
1049 full_inst
->TexOffsets
[i
].SwizzleX
,
1050 full_inst
->TexOffsets
[i
].SwizzleY
,
1051 full_inst
->TexOffsets
[i
].SwizzleZ
,
1055 prev_token
= (struct tgsi_token
*) texture_offset
;
1058 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
1059 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
1060 struct tgsi_dst_register
*dst_register
;
1062 if( maxsize
<= size
)
1064 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
1067 *dst_register
= tgsi_build_dst_register(
1069 reg
->Register
.WriteMask
,
1070 reg
->Register
.Indirect
,
1071 reg
->Register
.Dimension
,
1072 reg
->Register
.Index
,
1076 if( reg
->Register
.Indirect
) {
1077 struct tgsi_src_register
*ind
;
1079 if( maxsize
<= size
)
1081 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1084 *ind
= tgsi_build_src_register(
1086 reg
->Indirect
.SwizzleX
,
1087 reg
->Indirect
.SwizzleY
,
1088 reg
->Indirect
.SwizzleZ
,
1089 reg
->Indirect
.SwizzleW
,
1090 reg
->Indirect
.Negate
,
1091 reg
->Indirect
.Absolute
,
1092 reg
->Indirect
.Indirect
,
1093 reg
->Indirect
.Dimension
,
1094 reg
->Indirect
.Index
,
1099 if( reg
->Register
.Dimension
) {
1100 struct tgsi_dimension
*dim
;
1102 assert( !reg
->Dimension
.Dimension
);
1104 if( maxsize
<= size
)
1106 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1109 *dim
= tgsi_build_dimension(
1110 reg
->Dimension
.Indirect
,
1111 reg
->Dimension
.Index
,
1115 if( reg
->Dimension
.Indirect
) {
1116 struct tgsi_src_register
*ind
;
1118 if( maxsize
<= size
)
1120 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1123 *ind
= tgsi_build_src_register(
1124 reg
->DimIndirect
.File
,
1125 reg
->DimIndirect
.SwizzleX
,
1126 reg
->DimIndirect
.SwizzleY
,
1127 reg
->DimIndirect
.SwizzleZ
,
1128 reg
->DimIndirect
.SwizzleW
,
1129 reg
->DimIndirect
.Negate
,
1130 reg
->DimIndirect
.Absolute
,
1131 reg
->DimIndirect
.Indirect
,
1132 reg
->DimIndirect
.Dimension
,
1133 reg
->DimIndirect
.Index
,
1140 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
1141 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
1142 struct tgsi_src_register
*src_register
;
1144 if( maxsize
<= size
)
1146 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
1149 *src_register
= tgsi_build_src_register(
1151 reg
->Register
.SwizzleX
,
1152 reg
->Register
.SwizzleY
,
1153 reg
->Register
.SwizzleZ
,
1154 reg
->Register
.SwizzleW
,
1155 reg
->Register
.Negate
,
1156 reg
->Register
.Absolute
,
1157 reg
->Register
.Indirect
,
1158 reg
->Register
.Dimension
,
1159 reg
->Register
.Index
,
1163 if( reg
->Register
.Indirect
) {
1164 struct tgsi_src_register
*ind
;
1166 if( maxsize
<= size
)
1168 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1171 *ind
= tgsi_build_src_register(
1173 reg
->Indirect
.SwizzleX
,
1174 reg
->Indirect
.SwizzleY
,
1175 reg
->Indirect
.SwizzleZ
,
1176 reg
->Indirect
.SwizzleW
,
1177 reg
->Indirect
.Negate
,
1178 reg
->Indirect
.Absolute
,
1179 reg
->Indirect
.Indirect
,
1180 reg
->Indirect
.Dimension
,
1181 reg
->Indirect
.Index
,
1186 if( reg
->Register
.Dimension
) {
1187 struct tgsi_dimension
*dim
;
1189 assert( !reg
->Dimension
.Dimension
);
1191 if( maxsize
<= size
)
1193 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1196 *dim
= tgsi_build_dimension(
1197 reg
->Dimension
.Indirect
,
1198 reg
->Dimension
.Index
,
1202 if( reg
->Dimension
.Indirect
) {
1203 struct tgsi_src_register
*ind
;
1205 if( maxsize
<= size
)
1207 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1210 *ind
= tgsi_build_src_register(
1211 reg
->DimIndirect
.File
,
1212 reg
->DimIndirect
.SwizzleX
,
1213 reg
->DimIndirect
.SwizzleY
,
1214 reg
->DimIndirect
.SwizzleZ
,
1215 reg
->DimIndirect
.SwizzleW
,
1216 reg
->DimIndirect
.Negate
,
1217 reg
->DimIndirect
.Absolute
,
1218 reg
->DimIndirect
.Indirect
,
1219 reg
->DimIndirect
.Dimension
,
1220 reg
->DimIndirect
.Index
,
1230 static struct tgsi_property
1231 tgsi_default_property( void )
1233 struct tgsi_property property
;
1235 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1236 property
.NrTokens
= 1;
1237 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1238 property
.Padding
= 0;
1243 static struct tgsi_property
1244 tgsi_build_property(unsigned property_name
,
1245 struct tgsi_header
*header
)
1247 struct tgsi_property property
;
1249 property
= tgsi_default_property();
1250 property
.PropertyName
= property_name
;
1252 header_bodysize_grow( header
);
1258 struct tgsi_full_property
1259 tgsi_default_full_property( void )
1261 struct tgsi_full_property full_property
;
1263 full_property
.Property
= tgsi_default_property();
1264 memset(full_property
.u
, 0,
1265 sizeof(struct tgsi_property_data
) * 8);
1267 return full_property
;
1272 struct tgsi_property
*property
,
1273 struct tgsi_header
*header
)
1275 assert( property
->NrTokens
< 0xFF );
1277 property
->NrTokens
++;
1279 header_bodysize_grow( header
);
1282 static struct tgsi_property_data
1283 tgsi_build_property_data(
1285 struct tgsi_property
*property
,
1286 struct tgsi_header
*header
)
1288 struct tgsi_property_data property_data
;
1290 property_data
.Data
= value
;
1292 property_grow( property
, header
);
1294 return property_data
;
1298 tgsi_build_full_property(
1299 const struct tgsi_full_property
*full_prop
,
1300 struct tgsi_token
*tokens
,
1301 struct tgsi_header
*header
,
1304 unsigned size
= 0, i
;
1305 struct tgsi_property
*property
;
1307 if( maxsize
<= size
)
1309 property
= (struct tgsi_property
*) &tokens
[size
];
1312 *property
= tgsi_build_property(
1313 full_prop
->Property
.PropertyName
,
1316 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1318 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1319 struct tgsi_property_data
*data
;
1321 if( maxsize
<= size
)
1323 data
= (struct tgsi_property_data
*) &tokens
[size
];
1326 *data
= tgsi_build_property_data(
1327 full_prop
->u
[i
].Data
,