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
.Padding
= 0;
117 static struct tgsi_declaration
118 tgsi_build_declaration(
121 unsigned interpolate
,
126 struct tgsi_header
*header
)
128 struct tgsi_declaration declaration
;
130 assert( file
< TGSI_FILE_COUNT
);
131 assert( interpolate
< TGSI_INTERPOLATE_COUNT
);
133 declaration
= tgsi_default_declaration();
134 declaration
.File
= file
;
135 declaration
.UsageMask
= usage_mask
;
136 declaration
.Interpolate
= interpolate
;
137 declaration
.Dimension
= dimension
;
138 declaration
.Semantic
= semantic
;
139 declaration
.Invariant
= invariant
;
140 declaration
.Local
= local
;
142 header_bodysize_grow( header
);
147 static struct tgsi_declaration_range
148 tgsi_default_declaration_range( void )
150 struct tgsi_declaration_range dr
;
158 static struct tgsi_declaration_range
159 tgsi_build_declaration_range(
162 struct tgsi_declaration
*declaration
,
163 struct tgsi_header
*header
)
165 struct tgsi_declaration_range declaration_range
;
167 assert( last
>= first
);
168 assert( last
<= 0xFFFF );
170 declaration_range
.First
= first
;
171 declaration_range
.Last
= last
;
173 declaration_grow( declaration
, header
);
175 return declaration_range
;
178 static struct tgsi_declaration_dimension
179 tgsi_build_declaration_dimension(unsigned index_2d
,
180 struct tgsi_declaration
*declaration
,
181 struct tgsi_header
*header
)
183 struct tgsi_declaration_dimension dd
;
185 assert(index_2d
<= 0xFFFF);
187 dd
.Index2D
= index_2d
;
190 declaration_grow(declaration
, header
);
195 static struct tgsi_declaration_interp
196 tgsi_default_declaration_interp( void )
198 struct tgsi_declaration_interp di
;
200 di
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
202 di
.CylindricalWrap
= 0;
208 static struct tgsi_declaration_interp
209 tgsi_build_declaration_interp(unsigned interpolate
,
211 unsigned cylindrical_wrap
,
212 struct tgsi_declaration
*declaration
,
213 struct tgsi_header
*header
)
215 struct tgsi_declaration_interp di
;
217 di
.Interpolate
= interpolate
;
218 di
.Centroid
= centroid
;
219 di
.CylindricalWrap
= cylindrical_wrap
;
222 declaration_grow(declaration
, header
);
227 static struct tgsi_declaration_semantic
228 tgsi_default_declaration_semantic( void )
230 struct tgsi_declaration_semantic ds
;
232 ds
.Name
= TGSI_SEMANTIC_POSITION
;
239 static struct tgsi_declaration_semantic
240 tgsi_build_declaration_semantic(
241 unsigned semantic_name
,
242 unsigned semantic_index
,
243 struct tgsi_declaration
*declaration
,
244 struct tgsi_header
*header
)
246 struct tgsi_declaration_semantic ds
;
248 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
249 assert( semantic_index
<= 0xFFFF );
251 ds
.Name
= semantic_name
;
252 ds
.Index
= semantic_index
;
255 declaration_grow( declaration
, header
);
260 static struct tgsi_declaration_resource
261 tgsi_default_declaration_resource(void)
263 struct tgsi_declaration_resource dr
;
265 dr
.Resource
= TGSI_TEXTURE_BUFFER
;
273 static struct tgsi_declaration_resource
274 tgsi_build_declaration_resource(unsigned texture
,
277 struct tgsi_declaration
*declaration
,
278 struct tgsi_header
*header
)
280 struct tgsi_declaration_resource dr
;
282 dr
= tgsi_default_declaration_resource();
283 dr
.Resource
= texture
;
285 dr
.Writable
= writable
;
287 declaration_grow(declaration
, header
);
292 static struct tgsi_declaration_sampler_view
293 tgsi_default_declaration_sampler_view(void)
295 struct tgsi_declaration_sampler_view dsv
;
297 dsv
.Resource
= TGSI_TEXTURE_BUFFER
;
298 dsv
.ReturnTypeX
= PIPE_TYPE_UNORM
;
299 dsv
.ReturnTypeY
= PIPE_TYPE_UNORM
;
300 dsv
.ReturnTypeZ
= PIPE_TYPE_UNORM
;
301 dsv
.ReturnTypeW
= PIPE_TYPE_UNORM
;
306 static struct tgsi_declaration_sampler_view
307 tgsi_build_declaration_sampler_view(unsigned texture
,
308 unsigned return_type_x
,
309 unsigned return_type_y
,
310 unsigned return_type_z
,
311 unsigned return_type_w
,
312 struct tgsi_declaration
*declaration
,
313 struct tgsi_header
*header
)
315 struct tgsi_declaration_sampler_view dsv
;
317 dsv
= tgsi_default_declaration_sampler_view();
318 dsv
.Resource
= texture
;
319 dsv
.ReturnTypeX
= return_type_x
;
320 dsv
.ReturnTypeY
= return_type_y
;
321 dsv
.ReturnTypeZ
= return_type_z
;
322 dsv
.ReturnTypeW
= return_type_w
;
324 declaration_grow(declaration
, header
);
330 struct tgsi_full_declaration
331 tgsi_default_full_declaration( void )
333 struct tgsi_full_declaration full_declaration
;
335 full_declaration
.Declaration
= tgsi_default_declaration();
336 full_declaration
.Range
= tgsi_default_declaration_range();
337 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
338 full_declaration
.Interp
= tgsi_default_declaration_interp();
339 full_declaration
.Resource
= tgsi_default_declaration_resource();
340 full_declaration
.SamplerView
= tgsi_default_declaration_sampler_view();
342 return full_declaration
;
346 tgsi_build_full_declaration(
347 const struct tgsi_full_declaration
*full_decl
,
348 struct tgsi_token
*tokens
,
349 struct tgsi_header
*header
,
353 struct tgsi_declaration
*declaration
;
354 struct tgsi_declaration_range
*dr
;
356 if( maxsize
<= size
)
358 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
361 *declaration
= tgsi_build_declaration(
362 full_decl
->Declaration
.File
,
363 full_decl
->Declaration
.UsageMask
,
364 full_decl
->Declaration
.Interpolate
,
365 full_decl
->Declaration
.Dimension
,
366 full_decl
->Declaration
.Semantic
,
367 full_decl
->Declaration
.Invariant
,
368 full_decl
->Declaration
.Local
,
373 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
376 *dr
= tgsi_build_declaration_range(
377 full_decl
->Range
.First
,
378 full_decl
->Range
.Last
,
382 if (full_decl
->Declaration
.Dimension
) {
383 struct tgsi_declaration_dimension
*dd
;
385 if (maxsize
<= size
) {
388 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
391 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
396 if (full_decl
->Declaration
.Interpolate
) {
397 struct tgsi_declaration_interp
*di
;
399 if (maxsize
<= size
) {
402 di
= (struct tgsi_declaration_interp
*)&tokens
[size
];
405 *di
= tgsi_build_declaration_interp(full_decl
->Interp
.Interpolate
,
406 full_decl
->Interp
.Centroid
,
407 full_decl
->Interp
.CylindricalWrap
,
412 if( full_decl
->Declaration
.Semantic
) {
413 struct tgsi_declaration_semantic
*ds
;
415 if( maxsize
<= size
)
417 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
420 *ds
= tgsi_build_declaration_semantic(
421 full_decl
->Semantic
.Name
,
422 full_decl
->Semantic
.Index
,
427 if (full_decl
->Declaration
.File
== TGSI_FILE_RESOURCE
) {
428 struct tgsi_declaration_resource
*dr
;
430 if (maxsize
<= size
) {
433 dr
= (struct tgsi_declaration_resource
*)&tokens
[size
];
436 *dr
= tgsi_build_declaration_resource(full_decl
->Resource
.Resource
,
437 full_decl
->Resource
.Raw
,
438 full_decl
->Resource
.Writable
,
443 if (full_decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
444 struct tgsi_declaration_sampler_view
*dsv
;
446 if (maxsize
<= size
) {
449 dsv
= (struct tgsi_declaration_sampler_view
*)&tokens
[size
];
452 *dsv
= tgsi_build_declaration_sampler_view(
453 full_decl
->SamplerView
.Resource
,
454 full_decl
->SamplerView
.ReturnTypeX
,
455 full_decl
->SamplerView
.ReturnTypeY
,
456 full_decl
->SamplerView
.ReturnTypeZ
,
457 full_decl
->SamplerView
.ReturnTypeW
,
469 static struct tgsi_immediate
470 tgsi_default_immediate( void )
472 struct tgsi_immediate immediate
;
474 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
475 immediate
.NrTokens
= 1;
476 immediate
.DataType
= TGSI_IMM_FLOAT32
;
477 immediate
.Padding
= 0;
482 static struct tgsi_immediate
483 tgsi_build_immediate(
484 struct tgsi_header
*header
,
487 struct tgsi_immediate immediate
;
489 immediate
= tgsi_default_immediate();
490 immediate
.DataType
= type
;
492 header_bodysize_grow( header
);
497 struct tgsi_full_immediate
498 tgsi_default_full_immediate( void )
500 struct tgsi_full_immediate fullimm
;
502 fullimm
.Immediate
= tgsi_default_immediate();
503 fullimm
.u
[0].Float
= 0.0f
;
504 fullimm
.u
[1].Float
= 0.0f
;
505 fullimm
.u
[2].Float
= 0.0f
;
506 fullimm
.u
[3].Float
= 0.0f
;
513 struct tgsi_immediate
*immediate
,
514 struct tgsi_header
*header
)
516 assert( immediate
->NrTokens
< 0xFF );
518 immediate
->NrTokens
++;
520 header_bodysize_grow( header
);
524 tgsi_build_full_immediate(
525 const struct tgsi_full_immediate
*full_imm
,
526 struct tgsi_token
*tokens
,
527 struct tgsi_header
*header
,
530 unsigned size
= 0, i
;
531 struct tgsi_immediate
*immediate
;
533 if( maxsize
<= size
)
535 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
538 *immediate
= tgsi_build_immediate( header
, full_imm
->Immediate
.DataType
);
540 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
542 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
543 union tgsi_immediate_data
*data
;
545 if( maxsize
<= size
)
548 data
= (union tgsi_immediate_data
*) &tokens
[size
];
549 *data
= full_imm
->u
[i
];
551 immediate_grow( immediate
, header
);
562 struct tgsi_instruction
563 tgsi_default_instruction( void )
565 struct tgsi_instruction instruction
;
567 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
568 instruction
.NrTokens
= 0;
569 instruction
.Opcode
= TGSI_OPCODE_MOV
;
570 instruction
.Saturate
= TGSI_SAT_NONE
;
571 instruction
.Predicate
= 0;
572 instruction
.NumDstRegs
= 1;
573 instruction
.NumSrcRegs
= 1;
574 instruction
.Label
= 0;
575 instruction
.Texture
= 0;
576 instruction
.Padding
= 0;
581 static struct tgsi_instruction
582 tgsi_build_instruction(unsigned opcode
,
585 unsigned num_dst_regs
,
586 unsigned num_src_regs
,
587 struct tgsi_header
*header
)
589 struct tgsi_instruction instruction
;
591 assert (opcode
<= TGSI_OPCODE_LAST
);
592 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
593 assert (num_dst_regs
<= 3);
594 assert (num_src_regs
<= 15);
596 instruction
= tgsi_default_instruction();
597 instruction
.Opcode
= opcode
;
598 instruction
.Saturate
= saturate
;
599 instruction
.Predicate
= predicate
;
600 instruction
.NumDstRegs
= num_dst_regs
;
601 instruction
.NumSrcRegs
= num_src_regs
;
603 header_bodysize_grow( header
);
610 struct tgsi_instruction
*instruction
,
611 struct tgsi_header
*header
)
613 assert (instruction
->NrTokens
< 0xFF);
615 instruction
->NrTokens
++;
617 header_bodysize_grow( header
);
620 struct tgsi_instruction_predicate
621 tgsi_default_instruction_predicate(void)
623 struct tgsi_instruction_predicate instruction_predicate
;
625 instruction_predicate
.SwizzleX
= TGSI_SWIZZLE_X
;
626 instruction_predicate
.SwizzleY
= TGSI_SWIZZLE_Y
;
627 instruction_predicate
.SwizzleZ
= TGSI_SWIZZLE_Z
;
628 instruction_predicate
.SwizzleW
= TGSI_SWIZZLE_W
;
629 instruction_predicate
.Negate
= 0;
630 instruction_predicate
.Index
= 0;
631 instruction_predicate
.Padding
= 0;
633 return instruction_predicate
;
636 static struct tgsi_instruction_predicate
637 tgsi_build_instruction_predicate(int index
,
643 struct tgsi_instruction
*instruction
,
644 struct tgsi_header
*header
)
646 struct tgsi_instruction_predicate instruction_predicate
;
648 instruction_predicate
= tgsi_default_instruction_predicate();
649 instruction_predicate
.SwizzleX
= swizzleX
;
650 instruction_predicate
.SwizzleY
= swizzleY
;
651 instruction_predicate
.SwizzleZ
= swizzleZ
;
652 instruction_predicate
.SwizzleW
= swizzleW
;
653 instruction_predicate
.Negate
= negate
;
654 instruction_predicate
.Index
= index
;
656 instruction_grow(instruction
, header
);
658 return instruction_predicate
;
661 static struct tgsi_instruction_label
662 tgsi_default_instruction_label( void )
664 struct tgsi_instruction_label instruction_label
;
666 instruction_label
.Label
= 0;
667 instruction_label
.Padding
= 0;
669 return instruction_label
;
672 static struct tgsi_instruction_label
673 tgsi_build_instruction_label(
675 struct tgsi_token
*prev_token
,
676 struct tgsi_instruction
*instruction
,
677 struct tgsi_header
*header
)
679 struct tgsi_instruction_label instruction_label
;
681 instruction_label
.Label
= label
;
682 instruction_label
.Padding
= 0;
683 instruction
->Label
= 1;
685 instruction_grow( instruction
, header
);
687 return instruction_label
;
690 static struct tgsi_instruction_texture
691 tgsi_default_instruction_texture( void )
693 struct tgsi_instruction_texture instruction_texture
;
695 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
696 instruction_texture
.NumOffsets
= 0;
697 instruction_texture
.Padding
= 0;
699 return instruction_texture
;
702 static struct tgsi_instruction_texture
703 tgsi_build_instruction_texture(
705 unsigned num_offsets
,
706 struct tgsi_token
*prev_token
,
707 struct tgsi_instruction
*instruction
,
708 struct tgsi_header
*header
)
710 struct tgsi_instruction_texture instruction_texture
;
712 instruction_texture
.Texture
= texture
;
713 instruction_texture
.NumOffsets
= num_offsets
;
714 instruction_texture
.Padding
= 0;
715 instruction
->Texture
= 1;
717 instruction_grow( instruction
, header
);
719 return instruction_texture
;
723 static struct tgsi_texture_offset
724 tgsi_default_texture_offset( void )
726 struct tgsi_texture_offset texture_offset
;
728 texture_offset
.Index
= 0;
729 texture_offset
.File
= 0;
730 texture_offset
.SwizzleX
= 0;
731 texture_offset
.SwizzleY
= 0;
732 texture_offset
.SwizzleZ
= 0;
733 texture_offset
.Padding
= 0;
735 return texture_offset
;
738 static struct tgsi_texture_offset
739 tgsi_build_texture_offset(
740 int index
, int file
, int swizzle_x
, int swizzle_y
, int swizzle_z
,
741 struct tgsi_token
*prev_token
,
742 struct tgsi_instruction
*instruction
,
743 struct tgsi_header
*header
)
745 struct tgsi_texture_offset texture_offset
;
747 texture_offset
.Index
= index
;
748 texture_offset
.File
= file
;
749 texture_offset
.SwizzleX
= swizzle_x
;
750 texture_offset
.SwizzleY
= swizzle_y
;
751 texture_offset
.SwizzleZ
= swizzle_z
;
752 texture_offset
.Padding
= 0;
754 instruction_grow( instruction
, header
);
756 return texture_offset
;
759 static struct tgsi_src_register
760 tgsi_default_src_register( void )
762 struct tgsi_src_register src_register
;
764 src_register
.File
= TGSI_FILE_NULL
;
765 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
766 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
767 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
768 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
769 src_register
.Negate
= 0;
770 src_register
.Absolute
= 0;
771 src_register
.Indirect
= 0;
772 src_register
.Dimension
= 0;
773 src_register
.Index
= 0;
778 static struct tgsi_src_register
779 tgsi_build_src_register(
790 struct tgsi_instruction
*instruction
,
791 struct tgsi_header
*header
)
793 struct tgsi_src_register src_register
;
795 assert( file
< TGSI_FILE_COUNT
);
796 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
797 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
798 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
799 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
800 assert( negate
<= 1 );
801 assert( index
>= -0x8000 && index
<= 0x7FFF );
803 src_register
.File
= file
;
804 src_register
.SwizzleX
= swizzle_x
;
805 src_register
.SwizzleY
= swizzle_y
;
806 src_register
.SwizzleZ
= swizzle_z
;
807 src_register
.SwizzleW
= swizzle_w
;
808 src_register
.Negate
= negate
;
809 src_register
.Absolute
= absolute
;
810 src_register
.Indirect
= indirect
;
811 src_register
.Dimension
= dimension
;
812 src_register
.Index
= index
;
814 instruction_grow( instruction
, header
);
819 static struct tgsi_dimension
820 tgsi_default_dimension( void )
822 struct tgsi_dimension dimension
;
824 dimension
.Indirect
= 0;
825 dimension
.Dimension
= 0;
826 dimension
.Padding
= 0;
832 static struct tgsi_full_src_register
833 tgsi_default_full_src_register( void )
835 struct tgsi_full_src_register full_src_register
;
837 full_src_register
.Register
= tgsi_default_src_register();
838 full_src_register
.Indirect
= tgsi_default_src_register();
839 full_src_register
.Dimension
= tgsi_default_dimension();
840 full_src_register
.DimIndirect
= tgsi_default_src_register();
842 return full_src_register
;
845 static struct tgsi_dimension
846 tgsi_build_dimension(
849 struct tgsi_instruction
*instruction
,
850 struct tgsi_header
*header
)
852 struct tgsi_dimension dimension
;
854 dimension
.Indirect
= indirect
;
855 dimension
.Dimension
= 0;
856 dimension
.Padding
= 0;
857 dimension
.Index
= index
;
859 instruction_grow( instruction
, header
);
864 static struct tgsi_dst_register
865 tgsi_default_dst_register( void )
867 struct tgsi_dst_register dst_register
;
869 dst_register
.File
= TGSI_FILE_NULL
;
870 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
871 dst_register
.Indirect
= 0;
872 dst_register
.Dimension
= 0;
873 dst_register
.Index
= 0;
874 dst_register
.Padding
= 0;
879 static struct tgsi_dst_register
880 tgsi_build_dst_register(
886 struct tgsi_instruction
*instruction
,
887 struct tgsi_header
*header
)
889 struct tgsi_dst_register dst_register
;
891 assert( file
< TGSI_FILE_COUNT
);
892 assert( mask
<= TGSI_WRITEMASK_XYZW
);
893 assert( index
>= -32768 && index
<= 32767 );
895 dst_register
.File
= file
;
896 dst_register
.WriteMask
= mask
;
897 dst_register
.Indirect
= indirect
;
898 dst_register
.Dimension
= dimension
;
899 dst_register
.Index
= index
;
900 dst_register
.Padding
= 0;
902 instruction_grow( instruction
, header
);
907 static struct tgsi_full_dst_register
908 tgsi_default_full_dst_register( void )
910 struct tgsi_full_dst_register full_dst_register
;
912 full_dst_register
.Register
= tgsi_default_dst_register();
913 full_dst_register
.Indirect
= tgsi_default_src_register();
914 full_dst_register
.Dimension
= tgsi_default_dimension();
915 full_dst_register
.DimIndirect
= tgsi_default_src_register();
917 return full_dst_register
;
920 struct tgsi_full_instruction
921 tgsi_default_full_instruction( void )
923 struct tgsi_full_instruction full_instruction
;
926 full_instruction
.Instruction
= tgsi_default_instruction();
927 full_instruction
.Predicate
= tgsi_default_instruction_predicate();
928 full_instruction
.Label
= tgsi_default_instruction_label();
929 full_instruction
.Texture
= tgsi_default_instruction_texture();
930 for( i
= 0; i
< TGSI_FULL_MAX_TEX_OFFSETS
; i
++ ) {
931 full_instruction
.TexOffsets
[i
] = tgsi_default_texture_offset();
933 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
934 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
936 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
937 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
940 return full_instruction
;
944 tgsi_build_full_instruction(
945 const struct tgsi_full_instruction
*full_inst
,
946 struct tgsi_token
*tokens
,
947 struct tgsi_header
*header
,
952 struct tgsi_instruction
*instruction
;
953 struct tgsi_token
*prev_token
;
955 if( maxsize
<= size
)
957 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
960 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
961 full_inst
->Instruction
.Saturate
,
962 full_inst
->Instruction
.Predicate
,
963 full_inst
->Instruction
.NumDstRegs
,
964 full_inst
->Instruction
.NumSrcRegs
,
966 prev_token
= (struct tgsi_token
*) instruction
;
968 if (full_inst
->Instruction
.Predicate
) {
969 struct tgsi_instruction_predicate
*instruction_predicate
;
971 if (maxsize
<= size
) {
974 instruction_predicate
= (struct tgsi_instruction_predicate
*)&tokens
[size
];
977 *instruction_predicate
=
978 tgsi_build_instruction_predicate(full_inst
->Predicate
.Index
,
979 full_inst
->Predicate
.Negate
,
980 full_inst
->Predicate
.SwizzleX
,
981 full_inst
->Predicate
.SwizzleY
,
982 full_inst
->Predicate
.SwizzleZ
,
983 full_inst
->Predicate
.SwizzleW
,
988 if (full_inst
->Instruction
.Label
) {
989 struct tgsi_instruction_label
*instruction_label
;
991 if( maxsize
<= size
)
994 (struct tgsi_instruction_label
*) &tokens
[size
];
997 *instruction_label
= tgsi_build_instruction_label(
998 full_inst
->Label
.Label
,
1002 prev_token
= (struct tgsi_token
*) instruction_label
;
1005 if (full_inst
->Instruction
.Texture
) {
1006 struct tgsi_instruction_texture
*instruction_texture
;
1008 if( maxsize
<= size
)
1010 instruction_texture
=
1011 (struct tgsi_instruction_texture
*) &tokens
[size
];
1014 *instruction_texture
= tgsi_build_instruction_texture(
1015 full_inst
->Texture
.Texture
,
1016 full_inst
->Texture
.NumOffsets
,
1020 prev_token
= (struct tgsi_token
*) instruction_texture
;
1022 for (i
= 0; i
< full_inst
->Texture
.NumOffsets
; i
++) {
1023 struct tgsi_texture_offset
*texture_offset
;
1025 if ( maxsize
<= size
)
1027 texture_offset
= (struct tgsi_texture_offset
*)&tokens
[size
];
1029 *texture_offset
= tgsi_build_texture_offset(
1030 full_inst
->TexOffsets
[i
].Index
,
1031 full_inst
->TexOffsets
[i
].File
,
1032 full_inst
->TexOffsets
[i
].SwizzleX
,
1033 full_inst
->TexOffsets
[i
].SwizzleY
,
1034 full_inst
->TexOffsets
[i
].SwizzleZ
,
1038 prev_token
= (struct tgsi_token
*) texture_offset
;
1041 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
1042 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
1043 struct tgsi_dst_register
*dst_register
;
1045 if( maxsize
<= size
)
1047 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
1050 *dst_register
= tgsi_build_dst_register(
1052 reg
->Register
.WriteMask
,
1053 reg
->Register
.Indirect
,
1054 reg
->Register
.Dimension
,
1055 reg
->Register
.Index
,
1059 if( reg
->Register
.Indirect
) {
1060 struct tgsi_src_register
*ind
;
1062 if( maxsize
<= size
)
1064 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1067 *ind
= tgsi_build_src_register(
1069 reg
->Indirect
.SwizzleX
,
1070 reg
->Indirect
.SwizzleY
,
1071 reg
->Indirect
.SwizzleZ
,
1072 reg
->Indirect
.SwizzleW
,
1073 reg
->Indirect
.Negate
,
1074 reg
->Indirect
.Absolute
,
1075 reg
->Indirect
.Indirect
,
1076 reg
->Indirect
.Dimension
,
1077 reg
->Indirect
.Index
,
1082 if( reg
->Register
.Dimension
) {
1083 struct tgsi_dimension
*dim
;
1085 assert( !reg
->Dimension
.Dimension
);
1087 if( maxsize
<= size
)
1089 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1092 *dim
= tgsi_build_dimension(
1093 reg
->Dimension
.Indirect
,
1094 reg
->Dimension
.Index
,
1098 if( reg
->Dimension
.Indirect
) {
1099 struct tgsi_src_register
*ind
;
1101 if( maxsize
<= size
)
1103 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1106 *ind
= tgsi_build_src_register(
1107 reg
->DimIndirect
.File
,
1108 reg
->DimIndirect
.SwizzleX
,
1109 reg
->DimIndirect
.SwizzleY
,
1110 reg
->DimIndirect
.SwizzleZ
,
1111 reg
->DimIndirect
.SwizzleW
,
1112 reg
->DimIndirect
.Negate
,
1113 reg
->DimIndirect
.Absolute
,
1114 reg
->DimIndirect
.Indirect
,
1115 reg
->DimIndirect
.Dimension
,
1116 reg
->DimIndirect
.Index
,
1123 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
1124 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
1125 struct tgsi_src_register
*src_register
;
1127 if( maxsize
<= size
)
1129 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
1132 *src_register
= tgsi_build_src_register(
1134 reg
->Register
.SwizzleX
,
1135 reg
->Register
.SwizzleY
,
1136 reg
->Register
.SwizzleZ
,
1137 reg
->Register
.SwizzleW
,
1138 reg
->Register
.Negate
,
1139 reg
->Register
.Absolute
,
1140 reg
->Register
.Indirect
,
1141 reg
->Register
.Dimension
,
1142 reg
->Register
.Index
,
1146 if( reg
->Register
.Indirect
) {
1147 struct tgsi_src_register
*ind
;
1149 if( maxsize
<= size
)
1151 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1154 *ind
= tgsi_build_src_register(
1156 reg
->Indirect
.SwizzleX
,
1157 reg
->Indirect
.SwizzleY
,
1158 reg
->Indirect
.SwizzleZ
,
1159 reg
->Indirect
.SwizzleW
,
1160 reg
->Indirect
.Negate
,
1161 reg
->Indirect
.Absolute
,
1162 reg
->Indirect
.Indirect
,
1163 reg
->Indirect
.Dimension
,
1164 reg
->Indirect
.Index
,
1169 if( reg
->Register
.Dimension
) {
1170 struct tgsi_dimension
*dim
;
1172 assert( !reg
->Dimension
.Dimension
);
1174 if( maxsize
<= size
)
1176 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1179 *dim
= tgsi_build_dimension(
1180 reg
->Dimension
.Indirect
,
1181 reg
->Dimension
.Index
,
1185 if( reg
->Dimension
.Indirect
) {
1186 struct tgsi_src_register
*ind
;
1188 if( maxsize
<= size
)
1190 ind
= (struct tgsi_src_register
*) &tokens
[size
];
1193 *ind
= tgsi_build_src_register(
1194 reg
->DimIndirect
.File
,
1195 reg
->DimIndirect
.SwizzleX
,
1196 reg
->DimIndirect
.SwizzleY
,
1197 reg
->DimIndirect
.SwizzleZ
,
1198 reg
->DimIndirect
.SwizzleW
,
1199 reg
->DimIndirect
.Negate
,
1200 reg
->DimIndirect
.Absolute
,
1201 reg
->DimIndirect
.Indirect
,
1202 reg
->DimIndirect
.Dimension
,
1203 reg
->DimIndirect
.Index
,
1213 static struct tgsi_property
1214 tgsi_default_property( void )
1216 struct tgsi_property property
;
1218 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1219 property
.NrTokens
= 1;
1220 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1221 property
.Padding
= 0;
1226 static struct tgsi_property
1227 tgsi_build_property(unsigned property_name
,
1228 struct tgsi_header
*header
)
1230 struct tgsi_property property
;
1232 property
= tgsi_default_property();
1233 property
.PropertyName
= property_name
;
1235 header_bodysize_grow( header
);
1241 struct tgsi_full_property
1242 tgsi_default_full_property( void )
1244 struct tgsi_full_property full_property
;
1246 full_property
.Property
= tgsi_default_property();
1247 memset(full_property
.u
, 0,
1248 sizeof(struct tgsi_property_data
) * 8);
1250 return full_property
;
1255 struct tgsi_property
*property
,
1256 struct tgsi_header
*header
)
1258 assert( property
->NrTokens
< 0xFF );
1260 property
->NrTokens
++;
1262 header_bodysize_grow( header
);
1265 static struct tgsi_property_data
1266 tgsi_build_property_data(
1268 struct tgsi_property
*property
,
1269 struct tgsi_header
*header
)
1271 struct tgsi_property_data property_data
;
1273 property_data
.Data
= value
;
1275 property_grow( property
, header
);
1277 return property_data
;
1281 tgsi_build_full_property(
1282 const struct tgsi_full_property
*full_prop
,
1283 struct tgsi_token
*tokens
,
1284 struct tgsi_header
*header
,
1287 unsigned size
= 0, i
;
1288 struct tgsi_property
*property
;
1290 if( maxsize
<= size
)
1292 property
= (struct tgsi_property
*) &tokens
[size
];
1295 *property
= tgsi_build_property(
1296 full_prop
->Property
.PropertyName
,
1299 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1301 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1302 struct tgsi_property_data
*data
;
1304 if( maxsize
<= size
)
1306 data
= (struct tgsi_property_data
*) &tokens
[size
];
1309 *data
= tgsi_build_property_data(
1310 full_prop
->u
[i
].Data
,