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
.Atomic
= 0;
114 declaration
.MemType
= TGSI_MEMORY_TYPE_GLOBAL
;
115 declaration
.Padding
= 0;
120 static struct tgsi_declaration
121 tgsi_build_declaration(
124 unsigned interpolate
,
132 struct tgsi_header
*header
)
134 struct tgsi_declaration declaration
;
136 assert( file
< TGSI_FILE_COUNT
);
137 assert( interpolate
< TGSI_INTERPOLATE_COUNT
);
139 declaration
= tgsi_default_declaration();
140 declaration
.File
= file
;
141 declaration
.UsageMask
= usage_mask
;
142 declaration
.Interpolate
= interpolate
;
143 declaration
.Dimension
= dimension
;
144 declaration
.Semantic
= semantic
;
145 declaration
.Invariant
= invariant
;
146 declaration
.Local
= local
;
147 declaration
.Array
= array
;
148 declaration
.Atomic
= atomic
;
149 declaration
.MemType
= mem_type
;
150 header_bodysize_grow( header
);
155 static struct tgsi_declaration_range
156 tgsi_default_declaration_range( void )
158 struct tgsi_declaration_range dr
;
166 static struct tgsi_declaration_dimension
167 tgsi_default_declaration_dimension()
169 struct tgsi_declaration_dimension dim
;
176 static struct tgsi_declaration_range
177 tgsi_build_declaration_range(
180 struct tgsi_declaration
*declaration
,
181 struct tgsi_header
*header
)
183 struct tgsi_declaration_range declaration_range
;
185 assert( last
>= first
);
186 assert( last
<= 0xFFFF );
188 declaration_range
.First
= first
;
189 declaration_range
.Last
= last
;
191 declaration_grow( declaration
, header
);
193 return declaration_range
;
196 static struct tgsi_declaration_dimension
197 tgsi_build_declaration_dimension(unsigned index_2d
,
198 struct tgsi_declaration
*declaration
,
199 struct tgsi_header
*header
)
201 struct tgsi_declaration_dimension dd
;
203 assert(index_2d
<= 0xFFFF);
205 dd
.Index2D
= index_2d
;
208 declaration_grow(declaration
, header
);
213 static struct tgsi_declaration_interp
214 tgsi_default_declaration_interp( void )
216 struct tgsi_declaration_interp di
;
218 di
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
219 di
.Location
= TGSI_INTERPOLATE_LOC_CENTER
;
220 di
.CylindricalWrap
= 0;
226 static struct tgsi_declaration_interp
227 tgsi_build_declaration_interp(unsigned interpolate
,
228 unsigned interpolate_location
,
229 unsigned cylindrical_wrap
,
230 struct tgsi_declaration
*declaration
,
231 struct tgsi_header
*header
)
233 struct tgsi_declaration_interp di
;
235 di
.Interpolate
= interpolate
;
236 di
.Location
= interpolate_location
;
237 di
.CylindricalWrap
= cylindrical_wrap
;
240 declaration_grow(declaration
, header
);
245 static struct tgsi_declaration_semantic
246 tgsi_default_declaration_semantic( void )
248 struct tgsi_declaration_semantic ds
;
250 ds
.Name
= TGSI_SEMANTIC_POSITION
;
260 static struct tgsi_declaration_semantic
261 tgsi_build_declaration_semantic(
262 unsigned semantic_name
,
263 unsigned semantic_index
,
268 struct tgsi_declaration
*declaration
,
269 struct tgsi_header
*header
)
271 struct tgsi_declaration_semantic ds
;
273 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
274 assert( semantic_index
<= 0xFFFF );
276 ds
.Name
= semantic_name
;
277 ds
.Index
= semantic_index
;
278 ds
.StreamX
= streamx
;
279 ds
.StreamY
= streamy
;
280 ds
.StreamZ
= streamz
;
281 ds
.StreamW
= streamw
;
283 declaration_grow( declaration
, header
);
288 static struct tgsi_declaration_image
289 tgsi_default_declaration_image(void)
291 struct tgsi_declaration_image di
;
293 di
.Resource
= TGSI_TEXTURE_BUFFER
;
302 static struct tgsi_declaration_image
303 tgsi_build_declaration_image(unsigned texture
,
307 struct tgsi_declaration
*declaration
,
308 struct tgsi_header
*header
)
310 struct tgsi_declaration_image di
;
312 di
= tgsi_default_declaration_image();
313 di
.Resource
= texture
;
316 di
.Writable
= writable
;
318 declaration_grow(declaration
, header
);
323 static struct tgsi_declaration_sampler_view
324 tgsi_default_declaration_sampler_view(void)
326 struct tgsi_declaration_sampler_view dsv
;
328 dsv
.Resource
= TGSI_TEXTURE_BUFFER
;
329 dsv
.ReturnTypeX
= TGSI_RETURN_TYPE_UNORM
;
330 dsv
.ReturnTypeY
= TGSI_RETURN_TYPE_UNORM
;
331 dsv
.ReturnTypeZ
= TGSI_RETURN_TYPE_UNORM
;
332 dsv
.ReturnTypeW
= TGSI_RETURN_TYPE_UNORM
;
337 static struct tgsi_declaration_sampler_view
338 tgsi_build_declaration_sampler_view(unsigned texture
,
339 unsigned return_type_x
,
340 unsigned return_type_y
,
341 unsigned return_type_z
,
342 unsigned return_type_w
,
343 struct tgsi_declaration
*declaration
,
344 struct tgsi_header
*header
)
346 struct tgsi_declaration_sampler_view dsv
;
348 dsv
= tgsi_default_declaration_sampler_view();
349 dsv
.Resource
= texture
;
350 dsv
.ReturnTypeX
= return_type_x
;
351 dsv
.ReturnTypeY
= return_type_y
;
352 dsv
.ReturnTypeZ
= return_type_z
;
353 dsv
.ReturnTypeW
= return_type_w
;
355 declaration_grow(declaration
, header
);
361 static struct tgsi_declaration_array
362 tgsi_default_declaration_array( void )
364 struct tgsi_declaration_array a
;
372 static struct tgsi_declaration_array
373 tgsi_build_declaration_array(unsigned arrayid
,
374 struct tgsi_declaration
*declaration
,
375 struct tgsi_header
*header
)
377 struct tgsi_declaration_array da
;
379 da
= tgsi_default_declaration_array();
380 da
.ArrayID
= arrayid
;
382 declaration_grow(declaration
, header
);
387 struct tgsi_full_declaration
388 tgsi_default_full_declaration( void )
390 struct tgsi_full_declaration full_declaration
;
392 full_declaration
.Declaration
= tgsi_default_declaration();
393 full_declaration
.Range
= tgsi_default_declaration_range();
394 full_declaration
.Dim
= tgsi_default_declaration_dimension();
395 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
396 full_declaration
.Interp
= tgsi_default_declaration_interp();
397 full_declaration
.Image
= tgsi_default_declaration_image();
398 full_declaration
.SamplerView
= tgsi_default_declaration_sampler_view();
399 full_declaration
.Array
= tgsi_default_declaration_array();
401 return full_declaration
;
405 tgsi_build_full_declaration(
406 const struct tgsi_full_declaration
*full_decl
,
407 struct tgsi_token
*tokens
,
408 struct tgsi_header
*header
,
412 struct tgsi_declaration
*declaration
;
413 struct tgsi_declaration_range
*dr
;
415 if( maxsize
<= size
)
417 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
420 *declaration
= tgsi_build_declaration(
421 full_decl
->Declaration
.File
,
422 full_decl
->Declaration
.UsageMask
,
423 full_decl
->Declaration
.Interpolate
,
424 full_decl
->Declaration
.Dimension
,
425 full_decl
->Declaration
.Semantic
,
426 full_decl
->Declaration
.Invariant
,
427 full_decl
->Declaration
.Local
,
428 full_decl
->Declaration
.Array
,
429 full_decl
->Declaration
.Atomic
,
430 full_decl
->Declaration
.MemType
,
435 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
438 *dr
= tgsi_build_declaration_range(
439 full_decl
->Range
.First
,
440 full_decl
->Range
.Last
,
444 if (full_decl
->Declaration
.Dimension
) {
445 struct tgsi_declaration_dimension
*dd
;
447 if (maxsize
<= size
) {
450 dd
= (struct tgsi_declaration_dimension
*)&tokens
[size
];
453 *dd
= tgsi_build_declaration_dimension(full_decl
->Dim
.Index2D
,
458 if (full_decl
->Declaration
.Interpolate
) {
459 struct tgsi_declaration_interp
*di
;
461 if (maxsize
<= size
) {
464 di
= (struct tgsi_declaration_interp
*)&tokens
[size
];
467 *di
= tgsi_build_declaration_interp(full_decl
->Interp
.Interpolate
,
468 full_decl
->Interp
.Location
,
469 full_decl
->Interp
.CylindricalWrap
,
474 if( full_decl
->Declaration
.Semantic
) {
475 struct tgsi_declaration_semantic
*ds
;
477 if( maxsize
<= size
)
479 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
482 *ds
= tgsi_build_declaration_semantic(
483 full_decl
->Semantic
.Name
,
484 full_decl
->Semantic
.Index
,
485 full_decl
->Semantic
.StreamX
,
486 full_decl
->Semantic
.StreamY
,
487 full_decl
->Semantic
.StreamZ
,
488 full_decl
->Semantic
.StreamW
,
493 if (full_decl
->Declaration
.File
== TGSI_FILE_IMAGE
) {
494 struct tgsi_declaration_image
*di
;
496 if (maxsize
<= size
) {
499 di
= (struct tgsi_declaration_image
*)&tokens
[size
];
502 *di
= tgsi_build_declaration_image(full_decl
->Image
.Resource
,
503 full_decl
->Image
.Format
,
504 full_decl
->Image
.Raw
,
505 full_decl
->Image
.Writable
,
510 if (full_decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
511 struct tgsi_declaration_sampler_view
*dsv
;
513 if (maxsize
<= size
) {
516 dsv
= (struct tgsi_declaration_sampler_view
*)&tokens
[size
];
519 *dsv
= tgsi_build_declaration_sampler_view(
520 full_decl
->SamplerView
.Resource
,
521 full_decl
->SamplerView
.ReturnTypeX
,
522 full_decl
->SamplerView
.ReturnTypeY
,
523 full_decl
->SamplerView
.ReturnTypeZ
,
524 full_decl
->SamplerView
.ReturnTypeW
,
529 if (full_decl
->Declaration
.Array
) {
530 struct tgsi_declaration_array
*da
;
532 if (maxsize
<= size
) {
535 da
= (struct tgsi_declaration_array
*)&tokens
[size
];
537 *da
= tgsi_build_declaration_array(
538 full_decl
->Array
.ArrayID
,
549 static struct tgsi_immediate
550 tgsi_default_immediate( void )
552 struct tgsi_immediate immediate
;
554 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
555 immediate
.NrTokens
= 1;
556 immediate
.DataType
= TGSI_IMM_FLOAT32
;
557 immediate
.Padding
= 0;
562 static struct tgsi_immediate
563 tgsi_build_immediate(
564 struct tgsi_header
*header
,
567 struct tgsi_immediate immediate
;
569 immediate
= tgsi_default_immediate();
570 immediate
.DataType
= type
;
572 header_bodysize_grow( header
);
577 struct tgsi_full_immediate
578 tgsi_default_full_immediate( void )
580 struct tgsi_full_immediate fullimm
;
582 fullimm
.Immediate
= tgsi_default_immediate();
583 fullimm
.u
[0].Float
= 0.0f
;
584 fullimm
.u
[1].Float
= 0.0f
;
585 fullimm
.u
[2].Float
= 0.0f
;
586 fullimm
.u
[3].Float
= 0.0f
;
593 struct tgsi_immediate
*immediate
,
594 struct tgsi_header
*header
)
596 assert( immediate
->NrTokens
< 0xFF );
598 immediate
->NrTokens
++;
600 header_bodysize_grow( header
);
604 tgsi_build_full_immediate(
605 const struct tgsi_full_immediate
*full_imm
,
606 struct tgsi_token
*tokens
,
607 struct tgsi_header
*header
,
610 unsigned size
= 0, i
;
611 struct tgsi_immediate
*immediate
;
613 if( maxsize
<= size
)
615 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
618 *immediate
= tgsi_build_immediate( header
, full_imm
->Immediate
.DataType
);
620 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
622 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
623 union tgsi_immediate_data
*data
;
625 if( maxsize
<= size
)
628 data
= (union tgsi_immediate_data
*) &tokens
[size
];
629 *data
= full_imm
->u
[i
];
631 immediate_grow( immediate
, header
);
642 struct tgsi_instruction
643 tgsi_default_instruction( void )
645 struct tgsi_instruction instruction
;
647 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
648 instruction
.NrTokens
= 0;
649 instruction
.Opcode
= TGSI_OPCODE_MOV
;
650 instruction
.Saturate
= 0;
651 instruction
.NumDstRegs
= 1;
652 instruction
.NumSrcRegs
= 1;
653 instruction
.Label
= 0;
654 instruction
.Texture
= 0;
655 instruction
.Memory
= 0;
656 instruction
.Precise
= 0;
657 instruction
.Padding
= 0;
662 static struct tgsi_instruction
663 tgsi_build_instruction(enum tgsi_opcode opcode
,
666 unsigned num_dst_regs
,
667 unsigned num_src_regs
,
668 struct tgsi_header
*header
)
670 struct tgsi_instruction instruction
;
672 assert (opcode
<= TGSI_OPCODE_LAST
);
673 assert (saturate
<= 1);
674 assert (num_dst_regs
<= 3);
675 assert (num_src_regs
<= 15);
677 instruction
= tgsi_default_instruction();
678 instruction
.Opcode
= opcode
;
679 instruction
.Saturate
= saturate
;
680 instruction
.Precise
= precise
;
681 instruction
.NumDstRegs
= num_dst_regs
;
682 instruction
.NumSrcRegs
= num_src_regs
;
684 header_bodysize_grow( header
);
691 struct tgsi_instruction
*instruction
,
692 struct tgsi_header
*header
)
694 assert (instruction
->NrTokens
< 0xFF);
696 instruction
->NrTokens
++;
698 header_bodysize_grow( header
);
701 static struct tgsi_instruction_label
702 tgsi_default_instruction_label( void )
704 struct tgsi_instruction_label instruction_label
;
706 instruction_label
.Label
= 0;
707 instruction_label
.Padding
= 0;
709 return instruction_label
;
712 static struct tgsi_instruction_label
713 tgsi_build_instruction_label(
715 struct tgsi_instruction
*instruction
,
716 struct tgsi_header
*header
)
718 struct tgsi_instruction_label instruction_label
;
720 instruction_label
.Label
= label
;
721 instruction_label
.Padding
= 0;
722 instruction
->Label
= 1;
724 instruction_grow( instruction
, header
);
726 return instruction_label
;
729 static struct tgsi_instruction_texture
730 tgsi_default_instruction_texture( void )
732 struct tgsi_instruction_texture instruction_texture
;
734 instruction_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
735 instruction_texture
.NumOffsets
= 0;
736 instruction_texture
.ReturnType
= TGSI_RETURN_TYPE_UNKNOWN
;
737 instruction_texture
.Padding
= 0;
739 return instruction_texture
;
742 static struct tgsi_instruction_texture
743 tgsi_build_instruction_texture(
745 unsigned num_offsets
,
746 unsigned return_type
,
747 struct tgsi_instruction
*instruction
,
748 struct tgsi_header
*header
)
750 struct tgsi_instruction_texture instruction_texture
;
752 instruction_texture
.Texture
= texture
;
753 instruction_texture
.NumOffsets
= num_offsets
;
754 instruction_texture
.ReturnType
= return_type
;
755 instruction_texture
.Padding
= 0;
756 instruction
->Texture
= 1;
758 instruction_grow( instruction
, header
);
760 return instruction_texture
;
763 static struct tgsi_instruction_memory
764 tgsi_default_instruction_memory( void )
766 struct tgsi_instruction_memory instruction_memory
;
768 instruction_memory
.Qualifier
= 0;
769 instruction_memory
.Texture
= 0;
770 instruction_memory
.Format
= 0;
771 instruction_memory
.Padding
= 0;
773 return instruction_memory
;
776 static struct tgsi_instruction_memory
777 tgsi_build_instruction_memory(
781 struct tgsi_instruction
*instruction
,
782 struct tgsi_header
*header
)
784 struct tgsi_instruction_memory instruction_memory
;
786 instruction_memory
.Qualifier
= qualifier
;
787 instruction_memory
.Texture
= texture
;
788 instruction_memory
.Format
= format
;
789 instruction_memory
.Padding
= 0;
790 instruction
->Memory
= 1;
792 instruction_grow( instruction
, header
);
794 return instruction_memory
;
797 static struct tgsi_texture_offset
798 tgsi_default_texture_offset( void )
800 struct tgsi_texture_offset texture_offset
;
802 texture_offset
.Index
= 0;
803 texture_offset
.File
= 0;
804 texture_offset
.SwizzleX
= 0;
805 texture_offset
.SwizzleY
= 0;
806 texture_offset
.SwizzleZ
= 0;
807 texture_offset
.Padding
= 0;
809 return texture_offset
;
812 static struct tgsi_texture_offset
813 tgsi_build_texture_offset(
814 int index
, int file
, int swizzle_x
, int swizzle_y
, int swizzle_z
,
815 struct tgsi_instruction
*instruction
,
816 struct tgsi_header
*header
)
818 struct tgsi_texture_offset texture_offset
;
820 texture_offset
.Index
= index
;
821 texture_offset
.File
= file
;
822 texture_offset
.SwizzleX
= swizzle_x
;
823 texture_offset
.SwizzleY
= swizzle_y
;
824 texture_offset
.SwizzleZ
= swizzle_z
;
825 texture_offset
.Padding
= 0;
827 instruction_grow( instruction
, header
);
829 return texture_offset
;
832 static struct tgsi_src_register
833 tgsi_default_src_register( void )
835 struct tgsi_src_register src_register
;
837 src_register
.File
= TGSI_FILE_NULL
;
838 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
839 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
840 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
841 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
842 src_register
.Negate
= 0;
843 src_register
.Absolute
= 0;
844 src_register
.Indirect
= 0;
845 src_register
.Dimension
= 0;
846 src_register
.Index
= 0;
851 static struct tgsi_src_register
852 tgsi_build_src_register(
863 struct tgsi_instruction
*instruction
,
864 struct tgsi_header
*header
)
866 struct tgsi_src_register src_register
;
868 assert( file
< TGSI_FILE_COUNT
);
869 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
870 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
871 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
872 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
873 assert( negate
<= 1 );
874 assert( index
>= -0x8000 && index
<= 0x7FFF );
876 src_register
.File
= file
;
877 src_register
.SwizzleX
= swizzle_x
;
878 src_register
.SwizzleY
= swizzle_y
;
879 src_register
.SwizzleZ
= swizzle_z
;
880 src_register
.SwizzleW
= swizzle_w
;
881 src_register
.Negate
= negate
;
882 src_register
.Absolute
= absolute
;
883 src_register
.Indirect
= indirect
;
884 src_register
.Dimension
= dimension
;
885 src_register
.Index
= index
;
887 instruction_grow( instruction
, header
);
892 static struct tgsi_ind_register
893 tgsi_default_ind_register( void )
895 struct tgsi_ind_register ind_register
;
897 ind_register
.File
= TGSI_FILE_NULL
;
898 ind_register
.Index
= 0;
899 ind_register
.Swizzle
= TGSI_SWIZZLE_X
;
900 ind_register
.ArrayID
= 0;
905 static struct tgsi_ind_register
906 tgsi_build_ind_register(
911 struct tgsi_instruction
*instruction
,
912 struct tgsi_header
*header
)
914 struct tgsi_ind_register ind_register
;
916 assert( file
< TGSI_FILE_COUNT
);
917 assert( swizzle
<= TGSI_SWIZZLE_W
);
918 assert( index
>= -0x8000 && index
<= 0x7FFF );
920 ind_register
.File
= file
;
921 ind_register
.Swizzle
= swizzle
;
922 ind_register
.Index
= index
;
923 ind_register
.ArrayID
= arrayid
;
925 instruction_grow( instruction
, header
);
930 static struct tgsi_dimension
931 tgsi_default_dimension( void )
933 struct tgsi_dimension dimension
;
935 dimension
.Indirect
= 0;
936 dimension
.Dimension
= 0;
937 dimension
.Padding
= 0;
943 static struct tgsi_full_src_register
944 tgsi_default_full_src_register( void )
946 struct tgsi_full_src_register full_src_register
;
948 full_src_register
.Register
= tgsi_default_src_register();
949 full_src_register
.Indirect
= tgsi_default_ind_register();
950 full_src_register
.Dimension
= tgsi_default_dimension();
951 full_src_register
.DimIndirect
= tgsi_default_ind_register();
953 return full_src_register
;
956 static struct tgsi_dimension
957 tgsi_build_dimension(
960 struct tgsi_instruction
*instruction
,
961 struct tgsi_header
*header
)
963 struct tgsi_dimension dimension
;
965 dimension
.Indirect
= indirect
;
966 dimension
.Dimension
= 0;
967 dimension
.Padding
= 0;
968 dimension
.Index
= index
;
970 instruction_grow( instruction
, header
);
975 static struct tgsi_dst_register
976 tgsi_default_dst_register( void )
978 struct tgsi_dst_register dst_register
;
980 dst_register
.File
= TGSI_FILE_NULL
;
981 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
982 dst_register
.Indirect
= 0;
983 dst_register
.Dimension
= 0;
984 dst_register
.Index
= 0;
985 dst_register
.Padding
= 0;
990 static struct tgsi_dst_register
991 tgsi_build_dst_register(
997 struct tgsi_instruction
*instruction
,
998 struct tgsi_header
*header
)
1000 struct tgsi_dst_register dst_register
;
1002 assert( file
< TGSI_FILE_COUNT
);
1003 assert( mask
<= TGSI_WRITEMASK_XYZW
);
1004 assert( index
>= -32768 && index
<= 32767 );
1006 dst_register
.File
= file
;
1007 dst_register
.WriteMask
= mask
;
1008 dst_register
.Indirect
= indirect
;
1009 dst_register
.Dimension
= dimension
;
1010 dst_register
.Index
= index
;
1011 dst_register
.Padding
= 0;
1013 instruction_grow( instruction
, header
);
1015 return dst_register
;
1018 static struct tgsi_full_dst_register
1019 tgsi_default_full_dst_register( void )
1021 struct tgsi_full_dst_register full_dst_register
;
1023 full_dst_register
.Register
= tgsi_default_dst_register();
1024 full_dst_register
.Indirect
= tgsi_default_ind_register();
1025 full_dst_register
.Dimension
= tgsi_default_dimension();
1026 full_dst_register
.DimIndirect
= tgsi_default_ind_register();
1028 return full_dst_register
;
1031 struct tgsi_full_instruction
1032 tgsi_default_full_instruction( void )
1034 struct tgsi_full_instruction full_instruction
;
1037 full_instruction
.Instruction
= tgsi_default_instruction();
1038 full_instruction
.Label
= tgsi_default_instruction_label();
1039 full_instruction
.Texture
= tgsi_default_instruction_texture();
1040 full_instruction
.Memory
= tgsi_default_instruction_memory();
1041 for( i
= 0; i
< TGSI_FULL_MAX_TEX_OFFSETS
; i
++ ) {
1042 full_instruction
.TexOffsets
[i
] = tgsi_default_texture_offset();
1044 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
1045 full_instruction
.Dst
[i
] = tgsi_default_full_dst_register();
1047 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
1048 full_instruction
.Src
[i
] = tgsi_default_full_src_register();
1051 return full_instruction
;
1055 tgsi_build_full_instruction(
1056 const struct tgsi_full_instruction
*full_inst
,
1057 struct tgsi_token
*tokens
,
1058 struct tgsi_header
*header
,
1063 struct tgsi_instruction
*instruction
;
1065 if( maxsize
<= size
)
1067 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
1070 *instruction
= tgsi_build_instruction(full_inst
->Instruction
.Opcode
,
1071 full_inst
->Instruction
.Saturate
,
1072 full_inst
->Instruction
.Precise
,
1073 full_inst
->Instruction
.NumDstRegs
,
1074 full_inst
->Instruction
.NumSrcRegs
,
1077 if (full_inst
->Instruction
.Label
) {
1078 struct tgsi_instruction_label
*instruction_label
;
1080 if( maxsize
<= size
)
1083 (struct tgsi_instruction_label
*) &tokens
[size
];
1086 *instruction_label
= tgsi_build_instruction_label(
1087 full_inst
->Label
.Label
,
1092 if (full_inst
->Instruction
.Texture
) {
1093 struct tgsi_instruction_texture
*instruction_texture
;
1095 if( maxsize
<= size
)
1097 instruction_texture
=
1098 (struct tgsi_instruction_texture
*) &tokens
[size
];
1101 *instruction_texture
= tgsi_build_instruction_texture(
1102 full_inst
->Texture
.Texture
,
1103 full_inst
->Texture
.NumOffsets
,
1104 full_inst
->Texture
.ReturnType
,
1108 for (i
= 0; i
< full_inst
->Texture
.NumOffsets
; i
++) {
1109 struct tgsi_texture_offset
*texture_offset
;
1111 if ( maxsize
<= size
)
1113 texture_offset
= (struct tgsi_texture_offset
*)&tokens
[size
];
1115 *texture_offset
= tgsi_build_texture_offset(
1116 full_inst
->TexOffsets
[i
].Index
,
1117 full_inst
->TexOffsets
[i
].File
,
1118 full_inst
->TexOffsets
[i
].SwizzleX
,
1119 full_inst
->TexOffsets
[i
].SwizzleY
,
1120 full_inst
->TexOffsets
[i
].SwizzleZ
,
1126 if (full_inst
->Instruction
.Memory
) {
1127 struct tgsi_instruction_memory
*instruction_memory
;
1129 if( maxsize
<= size
)
1131 instruction_memory
=
1132 (struct tgsi_instruction_memory
*) &tokens
[size
];
1135 *instruction_memory
= tgsi_build_instruction_memory(
1136 full_inst
->Memory
.Qualifier
,
1137 full_inst
->Memory
.Texture
,
1138 full_inst
->Memory
.Format
,
1143 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
1144 const struct tgsi_full_dst_register
*reg
= &full_inst
->Dst
[i
];
1145 struct tgsi_dst_register
*dst_register
;
1147 if( maxsize
<= size
)
1149 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
1152 *dst_register
= tgsi_build_dst_register(
1154 reg
->Register
.WriteMask
,
1155 reg
->Register
.Indirect
,
1156 reg
->Register
.Dimension
,
1157 reg
->Register
.Index
,
1161 if( reg
->Register
.Indirect
) {
1162 struct tgsi_ind_register
*ind
;
1164 if( maxsize
<= size
)
1166 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1169 *ind
= tgsi_build_ind_register(
1171 reg
->Indirect
.Swizzle
,
1172 reg
->Indirect
.Index
,
1173 reg
->Indirect
.ArrayID
,
1178 if( reg
->Register
.Dimension
) {
1179 struct tgsi_dimension
*dim
;
1181 assert( !reg
->Dimension
.Dimension
);
1183 if( maxsize
<= size
)
1185 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1188 *dim
= tgsi_build_dimension(
1189 reg
->Dimension
.Indirect
,
1190 reg
->Dimension
.Index
,
1194 if( reg
->Dimension
.Indirect
) {
1195 struct tgsi_ind_register
*ind
;
1197 if( maxsize
<= size
)
1199 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1202 *ind
= tgsi_build_ind_register(
1203 reg
->DimIndirect
.File
,
1204 reg
->DimIndirect
.Swizzle
,
1205 reg
->DimIndirect
.Index
,
1206 reg
->DimIndirect
.ArrayID
,
1213 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
1214 const struct tgsi_full_src_register
*reg
= &full_inst
->Src
[i
];
1215 struct tgsi_src_register
*src_register
;
1217 if( maxsize
<= size
)
1219 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
1222 *src_register
= tgsi_build_src_register(
1224 reg
->Register
.SwizzleX
,
1225 reg
->Register
.SwizzleY
,
1226 reg
->Register
.SwizzleZ
,
1227 reg
->Register
.SwizzleW
,
1228 reg
->Register
.Negate
,
1229 reg
->Register
.Absolute
,
1230 reg
->Register
.Indirect
,
1231 reg
->Register
.Dimension
,
1232 reg
->Register
.Index
,
1236 if( reg
->Register
.Indirect
) {
1237 struct tgsi_ind_register
*ind
;
1239 if( maxsize
<= size
)
1241 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1244 *ind
= tgsi_build_ind_register(
1246 reg
->Indirect
.Swizzle
,
1247 reg
->Indirect
.Index
,
1248 reg
->Indirect
.ArrayID
,
1253 if( reg
->Register
.Dimension
) {
1254 struct tgsi_dimension
*dim
;
1256 assert( !reg
->Dimension
.Dimension
);
1258 if( maxsize
<= size
)
1260 dim
= (struct tgsi_dimension
*) &tokens
[size
];
1263 *dim
= tgsi_build_dimension(
1264 reg
->Dimension
.Indirect
,
1265 reg
->Dimension
.Index
,
1269 if( reg
->Dimension
.Indirect
) {
1270 struct tgsi_ind_register
*ind
;
1272 if( maxsize
<= size
)
1274 ind
= (struct tgsi_ind_register
*) &tokens
[size
];
1277 *ind
= tgsi_build_ind_register(
1278 reg
->DimIndirect
.File
,
1279 reg
->DimIndirect
.Swizzle
,
1280 reg
->DimIndirect
.Index
,
1281 reg
->DimIndirect
.ArrayID
,
1291 static struct tgsi_property
1292 tgsi_default_property( void )
1294 struct tgsi_property property
;
1296 property
.Type
= TGSI_TOKEN_TYPE_PROPERTY
;
1297 property
.NrTokens
= 1;
1298 property
.PropertyName
= TGSI_PROPERTY_GS_INPUT_PRIM
;
1299 property
.Padding
= 0;
1304 static struct tgsi_property
1305 tgsi_build_property(unsigned property_name
,
1306 struct tgsi_header
*header
)
1308 struct tgsi_property property
;
1310 property
= tgsi_default_property();
1311 property
.PropertyName
= property_name
;
1313 header_bodysize_grow( header
);
1319 struct tgsi_full_property
1320 tgsi_default_full_property( void )
1322 struct tgsi_full_property full_property
;
1324 full_property
.Property
= tgsi_default_property();
1325 memset(full_property
.u
, 0,
1326 sizeof(struct tgsi_property_data
) * 8);
1328 return full_property
;
1333 struct tgsi_property
*property
,
1334 struct tgsi_header
*header
)
1336 assert( property
->NrTokens
< 0xFF );
1338 property
->NrTokens
++;
1340 header_bodysize_grow( header
);
1343 static struct tgsi_property_data
1344 tgsi_build_property_data(
1346 struct tgsi_property
*property
,
1347 struct tgsi_header
*header
)
1349 struct tgsi_property_data property_data
;
1351 property_data
.Data
= value
;
1353 property_grow( property
, header
);
1355 return property_data
;
1359 tgsi_build_full_property(
1360 const struct tgsi_full_property
*full_prop
,
1361 struct tgsi_token
*tokens
,
1362 struct tgsi_header
*header
,
1365 unsigned size
= 0, i
;
1366 struct tgsi_property
*property
;
1368 if( maxsize
<= size
)
1370 property
= (struct tgsi_property
*) &tokens
[size
];
1373 *property
= tgsi_build_property(
1374 full_prop
->Property
.PropertyName
,
1377 assert( full_prop
->Property
.NrTokens
<= 8 + 1 );
1379 for( i
= 0; i
< full_prop
->Property
.NrTokens
- 1; i
++ ) {
1380 struct tgsi_property_data
*data
;
1382 if( maxsize
<= size
)
1384 data
= (struct tgsi_property_data
*) &tokens
[size
];
1387 *data
= tgsi_build_property_data(
1388 full_prop
->u
[i
].Data
,
1396 struct tgsi_full_src_register
1397 tgsi_full_src_register_from_dst(const struct tgsi_full_dst_register
*dst
)
1399 struct tgsi_full_src_register src
;
1400 src
.Register
= tgsi_default_src_register();
1401 src
.Register
.File
= dst
->Register
.File
;
1402 src
.Register
.Indirect
= dst
->Register
.Indirect
;
1403 src
.Register
.Dimension
= dst
->Register
.Dimension
;
1404 src
.Register
.Index
= dst
->Register
.Index
;
1405 src
.Indirect
= dst
->Indirect
;
1406 src
.Dimension
= dst
->Dimension
;
1407 src
.DimIndirect
= dst
->DimIndirect
;