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 "pipe/p_debug.h"
29 #include "pipe/p_util.h"
30 #include "pipe/p_shader_tokens.h"
31 #include "tgsi_build.h"
32 #include "tgsi_parse.h"
39 tgsi_build_version( void )
41 struct tgsi_version version
;
43 version
.MajorVersion
= 1;
44 version
.MinorVersion
= 1;
55 tgsi_build_header( void )
57 struct tgsi_header header
;
59 header
.HeaderSize
= 1;
66 header_headersize_grow( struct tgsi_header
*header
)
68 assert( header
->HeaderSize
< 0xFF );
69 assert( header
->BodySize
== 0 );
75 header_bodysize_grow( struct tgsi_header
*header
)
77 assert( header
->BodySize
< 0xFFFFFF );
83 tgsi_default_processor( void )
85 struct tgsi_processor processor
;
87 processor
.Processor
= TGSI_PROCESSOR_FRAGMENT
;
88 processor
.Padding
= 0;
96 struct tgsi_header
*header
)
98 struct tgsi_processor processor
;
100 processor
= tgsi_default_processor();
101 processor
.Processor
= type
;
103 header_headersize_grow( header
);
112 struct tgsi_declaration
113 tgsi_default_declaration( void )
115 struct tgsi_declaration declaration
;
117 declaration
.Type
= TGSI_TOKEN_TYPE_DECLARATION
;
118 declaration
.Size
= 1;
119 declaration
.File
= TGSI_FILE_NULL
;
120 declaration
.UsageMask
= TGSI_WRITEMASK_XYZW
;
121 declaration
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
122 declaration
.Semantic
= 0;
123 declaration
.Padding
= 0;
124 declaration
.Extended
= 0;
129 struct tgsi_declaration
130 tgsi_build_declaration(
133 unsigned interpolate
,
135 struct tgsi_header
*header
)
137 struct tgsi_declaration declaration
;
139 assert( file
<= TGSI_FILE_IMMEDIATE
);
140 assert( interpolate
<= TGSI_INTERPOLATE_PERSPECTIVE
);
142 declaration
= tgsi_default_declaration();
143 declaration
.File
= file
;
144 declaration
.UsageMask
= usage_mask
;
145 declaration
.Interpolate
= interpolate
;
146 declaration
.Semantic
= semantic
;
148 header_bodysize_grow( header
);
155 struct tgsi_declaration
*declaration
,
156 struct tgsi_header
*header
)
158 assert( declaration
->Size
< 0xFF );
162 header_bodysize_grow( header
);
165 struct tgsi_full_declaration
166 tgsi_default_full_declaration( void )
168 struct tgsi_full_declaration full_declaration
;
170 full_declaration
.Declaration
= tgsi_default_declaration();
171 full_declaration
.DeclarationRange
= tgsi_default_declaration_range();
172 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
174 return full_declaration
;
178 tgsi_build_full_declaration(
179 const struct tgsi_full_declaration
*full_decl
,
180 struct tgsi_token
*tokens
,
181 struct tgsi_header
*header
,
185 struct tgsi_declaration
*declaration
;
186 struct tgsi_declaration_range
*dr
;
188 if( maxsize
<= size
)
190 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
193 *declaration
= tgsi_build_declaration(
194 full_decl
->Declaration
.File
,
195 full_decl
->Declaration
.UsageMask
,
196 full_decl
->Declaration
.Interpolate
,
197 full_decl
->Declaration
.Semantic
,
202 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
205 *dr
= tgsi_build_declaration_range(
206 full_decl
->DeclarationRange
.First
,
207 full_decl
->DeclarationRange
.Last
,
211 if( full_decl
->Declaration
.Semantic
) {
212 struct tgsi_declaration_semantic
*ds
;
214 if( maxsize
<= size
)
216 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
219 *ds
= tgsi_build_declaration_semantic(
220 full_decl
->Semantic
.SemanticName
,
221 full_decl
->Semantic
.SemanticIndex
,
229 struct tgsi_declaration_range
230 tgsi_default_declaration_range( void )
232 struct tgsi_declaration_range dr
;
240 struct tgsi_declaration_range
241 tgsi_build_declaration_range(
244 struct tgsi_declaration
*declaration
,
245 struct tgsi_header
*header
)
247 struct tgsi_declaration_range declaration_range
;
249 assert( last
>= first
);
250 assert( last
<= 0xFFFF );
252 declaration_range
= tgsi_default_declaration_range();
253 declaration_range
.First
= first
;
254 declaration_range
.Last
= last
;
256 declaration_grow( declaration
, header
);
258 return declaration_range
;
261 struct tgsi_declaration_semantic
262 tgsi_default_declaration_semantic( void )
264 struct tgsi_declaration_semantic ds
;
266 ds
.SemanticName
= TGSI_SEMANTIC_POSITION
;
267 ds
.SemanticIndex
= 0;
273 struct tgsi_declaration_semantic
274 tgsi_build_declaration_semantic(
275 unsigned semantic_name
,
276 unsigned semantic_index
,
277 struct tgsi_declaration
*declaration
,
278 struct tgsi_header
*header
)
280 struct tgsi_declaration_semantic ds
;
282 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
283 assert( semantic_index
<= 0xFFFF );
285 ds
= tgsi_default_declaration_semantic();
286 ds
.SemanticName
= semantic_name
;
287 ds
.SemanticIndex
= semantic_index
;
289 declaration_grow( declaration
, header
);
298 struct tgsi_immediate
299 tgsi_default_immediate( void )
301 struct tgsi_immediate immediate
;
303 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
305 immediate
.DataType
= TGSI_IMM_FLOAT32
;
306 immediate
.Padding
= 0;
307 immediate
.Extended
= 0;
312 struct tgsi_immediate
313 tgsi_build_immediate(
314 struct tgsi_header
*header
)
316 struct tgsi_immediate immediate
;
318 immediate
= tgsi_default_immediate();
320 header_bodysize_grow( header
);
325 struct tgsi_full_immediate
326 tgsi_default_full_immediate( void )
328 struct tgsi_full_immediate fullimm
;
330 fullimm
.Immediate
= tgsi_default_immediate();
331 fullimm
.u
.Pointer
= (void *) 0;
338 struct tgsi_immediate
*immediate
,
339 struct tgsi_header
*header
)
341 assert( immediate
->Size
< 0xFF );
345 header_bodysize_grow( header
);
348 struct tgsi_immediate_float32
349 tgsi_build_immediate_float32(
351 struct tgsi_immediate
*immediate
,
352 struct tgsi_header
*header
)
354 struct tgsi_immediate_float32 immediate_float32
;
356 immediate_float32
.Float
= value
;
358 immediate_grow( immediate
, header
);
360 return immediate_float32
;
364 tgsi_build_full_immediate(
365 const struct tgsi_full_immediate
*full_imm
,
366 struct tgsi_token
*tokens
,
367 struct tgsi_header
*header
,
370 unsigned size
= 0, i
;
371 struct tgsi_immediate
*immediate
;
373 if( maxsize
<= size
)
375 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
378 *immediate
= tgsi_build_immediate( header
);
380 for( i
= 0; i
< full_imm
->Immediate
.Size
- 1; i
++ ) {
381 struct tgsi_immediate_float32
*if32
;
383 if( maxsize
<= size
)
385 if32
= (struct tgsi_immediate_float32
*) &tokens
[size
];
388 *if32
= tgsi_build_immediate_float32(
389 full_imm
->u
.ImmediateFloat32
[i
].Float
,
401 struct tgsi_instruction
402 tgsi_default_instruction( void )
404 struct tgsi_instruction instruction
;
406 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
407 instruction
.Size
= 1;
408 instruction
.Opcode
= TGSI_OPCODE_MOV
;
409 instruction
.Saturate
= TGSI_SAT_NONE
;
410 instruction
.NumDstRegs
= 1;
411 instruction
.NumSrcRegs
= 1;
412 instruction
.Padding
= 0;
413 instruction
.Extended
= 0;
418 struct tgsi_instruction
419 tgsi_build_instruction(
422 unsigned num_dst_regs
,
423 unsigned num_src_regs
,
424 struct tgsi_header
*header
)
426 struct tgsi_instruction instruction
;
428 assert (opcode
<= TGSI_OPCODE_LAST
);
429 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
430 assert (num_dst_regs
<= 3);
431 assert (num_src_regs
<= 15);
433 instruction
= tgsi_default_instruction();
434 instruction
.Opcode
= opcode
;
435 instruction
.Saturate
= saturate
;
436 instruction
.NumDstRegs
= num_dst_regs
;
437 instruction
.NumSrcRegs
= num_src_regs
;
439 header_bodysize_grow( header
);
446 struct tgsi_instruction
*instruction
,
447 struct tgsi_header
*header
)
449 assert (instruction
->Size
< 0xFF);
453 header_bodysize_grow( header
);
456 struct tgsi_full_instruction
457 tgsi_default_full_instruction( void )
459 struct tgsi_full_instruction full_instruction
;
462 full_instruction
.Instruction
= tgsi_default_instruction();
463 full_instruction
.InstructionExtNv
= tgsi_default_instruction_ext_nv();
464 full_instruction
.InstructionExtLabel
= tgsi_default_instruction_ext_label();
465 full_instruction
.InstructionExtTexture
= tgsi_default_instruction_ext_texture();
466 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
467 full_instruction
.FullDstRegisters
[i
] = tgsi_default_full_dst_register();
469 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
470 full_instruction
.FullSrcRegisters
[i
] = tgsi_default_full_src_register();
473 return full_instruction
;
477 tgsi_build_full_instruction(
478 const struct tgsi_full_instruction
*full_inst
,
479 struct tgsi_token
*tokens
,
480 struct tgsi_header
*header
,
485 struct tgsi_instruction
*instruction
;
486 struct tgsi_token
*prev_token
;
488 if( maxsize
<= size
)
490 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
493 *instruction
= tgsi_build_instruction(
494 full_inst
->Instruction
.Opcode
,
495 full_inst
->Instruction
.Saturate
,
496 full_inst
->Instruction
.NumDstRegs
,
497 full_inst
->Instruction
.NumSrcRegs
,
499 prev_token
= (struct tgsi_token
*) instruction
;
501 if( tgsi_compare_instruction_ext_nv(
502 full_inst
->InstructionExtNv
,
503 tgsi_default_instruction_ext_nv() ) ) {
504 struct tgsi_instruction_ext_nv
*instruction_ext_nv
;
506 if( maxsize
<= size
)
509 (struct tgsi_instruction_ext_nv
*) &tokens
[size
];
512 *instruction_ext_nv
= tgsi_build_instruction_ext_nv(
513 full_inst
->InstructionExtNv
.Precision
,
514 full_inst
->InstructionExtNv
.CondDstIndex
,
515 full_inst
->InstructionExtNv
.CondFlowIndex
,
516 full_inst
->InstructionExtNv
.CondMask
,
517 full_inst
->InstructionExtNv
.CondSwizzleX
,
518 full_inst
->InstructionExtNv
.CondSwizzleY
,
519 full_inst
->InstructionExtNv
.CondSwizzleZ
,
520 full_inst
->InstructionExtNv
.CondSwizzleW
,
521 full_inst
->InstructionExtNv
.CondDstUpdate
,
522 full_inst
->InstructionExtNv
.CondFlowEnable
,
526 prev_token
= (struct tgsi_token
*) instruction_ext_nv
;
529 if( tgsi_compare_instruction_ext_label(
530 full_inst
->InstructionExtLabel
,
531 tgsi_default_instruction_ext_label() ) ) {
532 struct tgsi_instruction_ext_label
*instruction_ext_label
;
534 if( maxsize
<= size
)
536 instruction_ext_label
=
537 (struct tgsi_instruction_ext_label
*) &tokens
[size
];
540 *instruction_ext_label
= tgsi_build_instruction_ext_label(
541 full_inst
->InstructionExtLabel
.Label
,
545 prev_token
= (struct tgsi_token
*) instruction_ext_label
;
548 if( tgsi_compare_instruction_ext_texture(
549 full_inst
->InstructionExtTexture
,
550 tgsi_default_instruction_ext_texture() ) ) {
551 struct tgsi_instruction_ext_texture
*instruction_ext_texture
;
553 if( maxsize
<= size
)
555 instruction_ext_texture
=
556 (struct tgsi_instruction_ext_texture
*) &tokens
[size
];
559 *instruction_ext_texture
= tgsi_build_instruction_ext_texture(
560 full_inst
->InstructionExtTexture
.Texture
,
564 prev_token
= (struct tgsi_token
*) instruction_ext_texture
;
567 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
568 const struct tgsi_full_dst_register
*reg
= &full_inst
->FullDstRegisters
[i
];
569 struct tgsi_dst_register
*dst_register
;
570 struct tgsi_token
*prev_token
;
572 if( maxsize
<= size
)
574 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
577 *dst_register
= tgsi_build_dst_register(
578 reg
->DstRegister
.File
,
579 reg
->DstRegister
.WriteMask
,
580 reg
->DstRegister
.Index
,
583 prev_token
= (struct tgsi_token
*) dst_register
;
585 if( tgsi_compare_dst_register_ext_concode(
586 reg
->DstRegisterExtConcode
,
587 tgsi_default_dst_register_ext_concode() ) ) {
588 struct tgsi_dst_register_ext_concode
*dst_register_ext_concode
;
590 if( maxsize
<= size
)
592 dst_register_ext_concode
=
593 (struct tgsi_dst_register_ext_concode
*) &tokens
[size
];
596 *dst_register_ext_concode
= tgsi_build_dst_register_ext_concode(
597 reg
->DstRegisterExtConcode
.CondMask
,
598 reg
->DstRegisterExtConcode
.CondSwizzleX
,
599 reg
->DstRegisterExtConcode
.CondSwizzleY
,
600 reg
->DstRegisterExtConcode
.CondSwizzleZ
,
601 reg
->DstRegisterExtConcode
.CondSwizzleW
,
602 reg
->DstRegisterExtConcode
.CondSrcIndex
,
606 prev_token
= (struct tgsi_token
*) dst_register_ext_concode
;
609 if( tgsi_compare_dst_register_ext_modulate(
610 reg
->DstRegisterExtModulate
,
611 tgsi_default_dst_register_ext_modulate() ) ) {
612 struct tgsi_dst_register_ext_modulate
*dst_register_ext_modulate
;
614 if( maxsize
<= size
)
616 dst_register_ext_modulate
=
617 (struct tgsi_dst_register_ext_modulate
*) &tokens
[size
];
620 *dst_register_ext_modulate
= tgsi_build_dst_register_ext_modulate(
621 reg
->DstRegisterExtModulate
.Modulate
,
625 prev_token
= (struct tgsi_token
*) dst_register_ext_modulate
;
629 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
630 const struct tgsi_full_src_register
*reg
= &full_inst
->FullSrcRegisters
[i
];
631 struct tgsi_src_register
*src_register
;
632 struct tgsi_token
*prev_token
;
634 if( maxsize
<= size
)
636 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
639 *src_register
= tgsi_build_src_register(
640 reg
->SrcRegister
.File
,
641 reg
->SrcRegister
.SwizzleX
,
642 reg
->SrcRegister
.SwizzleY
,
643 reg
->SrcRegister
.SwizzleZ
,
644 reg
->SrcRegister
.SwizzleW
,
645 reg
->SrcRegister
.Negate
,
646 reg
->SrcRegister
.Indirect
,
647 reg
->SrcRegister
.Dimension
,
648 reg
->SrcRegister
.Index
,
651 prev_token
= (struct tgsi_token
*) src_register
;
653 if( tgsi_compare_src_register_ext_swz(
654 reg
->SrcRegisterExtSwz
,
655 tgsi_default_src_register_ext_swz() ) ) {
656 struct tgsi_src_register_ext_swz
*src_register_ext_swz
;
658 /* Use of the extended swizzle requires the simple swizzle to be identity.
660 assert( reg
->SrcRegister
.SwizzleX
== TGSI_SWIZZLE_X
);
661 assert( reg
->SrcRegister
.SwizzleY
== TGSI_SWIZZLE_Y
);
662 assert( reg
->SrcRegister
.SwizzleZ
== TGSI_SWIZZLE_Z
);
663 assert( reg
->SrcRegister
.SwizzleW
== TGSI_SWIZZLE_W
);
664 assert( reg
->SrcRegister
.Negate
== FALSE
);
666 if( maxsize
<= size
)
668 src_register_ext_swz
=
669 (struct tgsi_src_register_ext_swz
*) &tokens
[size
];
672 *src_register_ext_swz
= tgsi_build_src_register_ext_swz(
673 reg
->SrcRegisterExtSwz
.ExtSwizzleX
,
674 reg
->SrcRegisterExtSwz
.ExtSwizzleY
,
675 reg
->SrcRegisterExtSwz
.ExtSwizzleZ
,
676 reg
->SrcRegisterExtSwz
.ExtSwizzleW
,
677 reg
->SrcRegisterExtSwz
.NegateX
,
678 reg
->SrcRegisterExtSwz
.NegateY
,
679 reg
->SrcRegisterExtSwz
.NegateZ
,
680 reg
->SrcRegisterExtSwz
.NegateW
,
684 prev_token
= (struct tgsi_token
*) src_register_ext_swz
;
687 if( tgsi_compare_src_register_ext_mod(
688 reg
->SrcRegisterExtMod
,
689 tgsi_default_src_register_ext_mod() ) ) {
690 struct tgsi_src_register_ext_mod
*src_register_ext_mod
;
692 if( maxsize
<= size
)
694 src_register_ext_mod
=
695 (struct tgsi_src_register_ext_mod
*) &tokens
[size
];
698 *src_register_ext_mod
= tgsi_build_src_register_ext_mod(
699 reg
->SrcRegisterExtMod
.Complement
,
700 reg
->SrcRegisterExtMod
.Bias
,
701 reg
->SrcRegisterExtMod
.Scale2X
,
702 reg
->SrcRegisterExtMod
.Absolute
,
703 reg
->SrcRegisterExtMod
.Negate
,
707 prev_token
= (struct tgsi_token
*) src_register_ext_mod
;
710 if( reg
->SrcRegister
.Indirect
) {
711 struct tgsi_src_register
*ind
;
713 if( maxsize
<= size
)
715 ind
= (struct tgsi_src_register
*) &tokens
[size
];
718 *ind
= tgsi_build_src_register(
719 reg
->SrcRegisterInd
.File
,
720 reg
->SrcRegisterInd
.SwizzleX
,
721 reg
->SrcRegisterInd
.SwizzleY
,
722 reg
->SrcRegisterInd
.SwizzleZ
,
723 reg
->SrcRegisterInd
.SwizzleW
,
724 reg
->SrcRegisterInd
.Negate
,
725 reg
->SrcRegisterInd
.Indirect
,
726 reg
->SrcRegisterInd
.Dimension
,
727 reg
->SrcRegisterInd
.Index
,
732 if( reg
->SrcRegister
.Dimension
) {
733 struct tgsi_dimension
*dim
;
735 assert( !reg
->SrcRegisterDim
.Dimension
);
737 if( maxsize
<= size
)
739 dim
= (struct tgsi_dimension
*) &tokens
[size
];
742 *dim
= tgsi_build_dimension(
743 reg
->SrcRegisterDim
.Indirect
,
744 reg
->SrcRegisterDim
.Index
,
748 if( reg
->SrcRegisterDim
.Indirect
) {
749 struct tgsi_src_register
*ind
;
751 if( maxsize
<= size
)
753 ind
= (struct tgsi_src_register
*) &tokens
[size
];
756 *ind
= tgsi_build_src_register(
757 reg
->SrcRegisterDimInd
.File
,
758 reg
->SrcRegisterDimInd
.SwizzleX
,
759 reg
->SrcRegisterDimInd
.SwizzleY
,
760 reg
->SrcRegisterDimInd
.SwizzleZ
,
761 reg
->SrcRegisterDimInd
.SwizzleW
,
762 reg
->SrcRegisterDimInd
.Negate
,
763 reg
->SrcRegisterDimInd
.Indirect
,
764 reg
->SrcRegisterDimInd
.Dimension
,
765 reg
->SrcRegisterDimInd
.Index
,
775 struct tgsi_instruction_ext_nv
776 tgsi_default_instruction_ext_nv( void )
778 struct tgsi_instruction_ext_nv instruction_ext_nv
;
780 instruction_ext_nv
.Type
= TGSI_INSTRUCTION_EXT_TYPE_NV
;
781 instruction_ext_nv
.Precision
= TGSI_PRECISION_DEFAULT
;
782 instruction_ext_nv
.CondDstIndex
= 0;
783 instruction_ext_nv
.CondFlowIndex
= 0;
784 instruction_ext_nv
.CondMask
= TGSI_CC_TR
;
785 instruction_ext_nv
.CondSwizzleX
= TGSI_SWIZZLE_X
;
786 instruction_ext_nv
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
787 instruction_ext_nv
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
788 instruction_ext_nv
.CondSwizzleW
= TGSI_SWIZZLE_W
;
789 instruction_ext_nv
.CondDstUpdate
= 0;
790 instruction_ext_nv
.CondFlowEnable
= 0;
791 instruction_ext_nv
.Padding
= 0;
792 instruction_ext_nv
.Extended
= 0;
794 return instruction_ext_nv
;
803 tgsi_compare_instruction_ext_nv(
804 struct tgsi_instruction_ext_nv a
,
805 struct tgsi_instruction_ext_nv b
)
807 a
.Padding
= b
.Padding
= 0;
808 a
.Extended
= b
.Extended
= 0;
809 return ((union token_u32
*) &a
)->u32
!= ((union token_u32
*) &b
)->u32
;
812 struct tgsi_instruction_ext_nv
813 tgsi_build_instruction_ext_nv(
815 unsigned cond_dst_index
,
816 unsigned cond_flow_index
,
818 unsigned cond_swizzle_x
,
819 unsigned cond_swizzle_y
,
820 unsigned cond_swizzle_z
,
821 unsigned cond_swizzle_w
,
822 unsigned cond_dst_update
,
823 unsigned cond_flow_update
,
824 struct tgsi_token
*prev_token
,
825 struct tgsi_instruction
*instruction
,
826 struct tgsi_header
*header
)
828 struct tgsi_instruction_ext_nv instruction_ext_nv
;
830 instruction_ext_nv
= tgsi_default_instruction_ext_nv();
831 instruction_ext_nv
.Precision
= precision
;
832 instruction_ext_nv
.CondDstIndex
= cond_dst_index
;
833 instruction_ext_nv
.CondFlowIndex
= cond_flow_index
;
834 instruction_ext_nv
.CondMask
= cond_mask
;
835 instruction_ext_nv
.CondSwizzleX
= cond_swizzle_x
;
836 instruction_ext_nv
.CondSwizzleY
= cond_swizzle_y
;
837 instruction_ext_nv
.CondSwizzleZ
= cond_swizzle_z
;
838 instruction_ext_nv
.CondSwizzleW
= cond_swizzle_w
;
839 instruction_ext_nv
.CondDstUpdate
= cond_dst_update
;
840 instruction_ext_nv
.CondFlowEnable
= cond_flow_update
;
842 prev_token
->Extended
= 1;
843 instruction_grow( instruction
, header
);
845 return instruction_ext_nv
;
848 struct tgsi_instruction_ext_label
849 tgsi_default_instruction_ext_label( void )
851 struct tgsi_instruction_ext_label instruction_ext_label
;
853 instruction_ext_label
.Type
= TGSI_INSTRUCTION_EXT_TYPE_LABEL
;
854 instruction_ext_label
.Label
= 0;
855 instruction_ext_label
.Padding
= 0;
856 instruction_ext_label
.Extended
= 0;
858 return instruction_ext_label
;
862 tgsi_compare_instruction_ext_label(
863 struct tgsi_instruction_ext_label a
,
864 struct tgsi_instruction_ext_label b
)
866 a
.Padding
= b
.Padding
= 0;
867 a
.Extended
= b
.Extended
= 0;
868 return ((union token_u32
*) &a
)->u32
!= ((union token_u32
*) &b
)->u32
;
871 struct tgsi_instruction_ext_label
872 tgsi_build_instruction_ext_label(
874 struct tgsi_token
*prev_token
,
875 struct tgsi_instruction
*instruction
,
876 struct tgsi_header
*header
)
878 struct tgsi_instruction_ext_label instruction_ext_label
;
880 instruction_ext_label
= tgsi_default_instruction_ext_label();
881 instruction_ext_label
.Label
= label
;
883 prev_token
->Extended
= 1;
884 instruction_grow( instruction
, header
);
886 return instruction_ext_label
;
889 struct tgsi_instruction_ext_texture
890 tgsi_default_instruction_ext_texture( void )
892 struct tgsi_instruction_ext_texture instruction_ext_texture
;
894 instruction_ext_texture
.Type
= TGSI_INSTRUCTION_EXT_TYPE_TEXTURE
;
895 instruction_ext_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
896 instruction_ext_texture
.Padding
= 0;
897 instruction_ext_texture
.Extended
= 0;
899 return instruction_ext_texture
;
903 tgsi_compare_instruction_ext_texture(
904 struct tgsi_instruction_ext_texture a
,
905 struct tgsi_instruction_ext_texture b
)
907 a
.Padding
= b
.Padding
= 0;
908 a
.Extended
= b
.Extended
= 0;
909 return ((union token_u32
*) &a
)->u32
!= ((union token_u32
*) &b
)->u32
;
912 struct tgsi_instruction_ext_texture
913 tgsi_build_instruction_ext_texture(
915 struct tgsi_token
*prev_token
,
916 struct tgsi_instruction
*instruction
,
917 struct tgsi_header
*header
)
919 struct tgsi_instruction_ext_texture instruction_ext_texture
;
921 instruction_ext_texture
= tgsi_default_instruction_ext_texture();
922 instruction_ext_texture
.Texture
= texture
;
924 prev_token
->Extended
= 1;
925 instruction_grow( instruction
, header
);
927 return instruction_ext_texture
;
930 struct tgsi_src_register
931 tgsi_default_src_register( void )
933 struct tgsi_src_register src_register
;
935 src_register
.File
= TGSI_FILE_NULL
;
936 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
937 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
938 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
939 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
940 src_register
.Negate
= 0;
941 src_register
.Indirect
= 0;
942 src_register
.Dimension
= 0;
943 src_register
.Index
= 0;
944 src_register
.Extended
= 0;
949 struct tgsi_src_register
950 tgsi_build_src_register(
960 struct tgsi_instruction
*instruction
,
961 struct tgsi_header
*header
)
963 struct tgsi_src_register src_register
;
965 assert( file
<= TGSI_FILE_IMMEDIATE
);
966 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
967 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
968 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
969 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
970 assert( negate
<= 1 );
971 assert( index
>= -0x8000 && index
<= 0x7FFF );
973 src_register
= tgsi_default_src_register();
974 src_register
.File
= file
;
975 src_register
.SwizzleX
= swizzle_x
;
976 src_register
.SwizzleY
= swizzle_y
;
977 src_register
.SwizzleZ
= swizzle_z
;
978 src_register
.SwizzleW
= swizzle_w
;
979 src_register
.Negate
= negate
;
980 src_register
.Indirect
= indirect
;
981 src_register
.Dimension
= dimension
;
982 src_register
.Index
= index
;
984 instruction_grow( instruction
, header
);
989 struct tgsi_full_src_register
990 tgsi_default_full_src_register( void )
992 struct tgsi_full_src_register full_src_register
;
994 full_src_register
.SrcRegister
= tgsi_default_src_register();
995 full_src_register
.SrcRegisterExtSwz
= tgsi_default_src_register_ext_swz();
996 full_src_register
.SrcRegisterExtMod
= tgsi_default_src_register_ext_mod();
997 full_src_register
.SrcRegisterInd
= tgsi_default_src_register();
998 full_src_register
.SrcRegisterDim
= tgsi_default_dimension();
999 full_src_register
.SrcRegisterDimInd
= tgsi_default_src_register();
1001 return full_src_register
;
1004 struct tgsi_src_register_ext_swz
1005 tgsi_default_src_register_ext_swz( void )
1007 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1009 src_register_ext_swz
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_SWZ
;
1010 src_register_ext_swz
.ExtSwizzleX
= TGSI_EXTSWIZZLE_X
;
1011 src_register_ext_swz
.ExtSwizzleY
= TGSI_EXTSWIZZLE_Y
;
1012 src_register_ext_swz
.ExtSwizzleZ
= TGSI_EXTSWIZZLE_Z
;
1013 src_register_ext_swz
.ExtSwizzleW
= TGSI_EXTSWIZZLE_W
;
1014 src_register_ext_swz
.NegateX
= 0;
1015 src_register_ext_swz
.NegateY
= 0;
1016 src_register_ext_swz
.NegateZ
= 0;
1017 src_register_ext_swz
.NegateW
= 0;
1018 src_register_ext_swz
.Padding
= 0;
1019 src_register_ext_swz
.Extended
= 0;
1021 return src_register_ext_swz
;
1025 tgsi_compare_src_register_ext_swz(
1026 struct tgsi_src_register_ext_swz a
,
1027 struct tgsi_src_register_ext_swz b
)
1029 a
.Padding
= b
.Padding
= 0;
1030 a
.Extended
= b
.Extended
= 0;
1031 return ((union token_u32
*) &a
)->u32
!= ((union token_u32
*) &b
)->u32
;
1034 struct tgsi_src_register_ext_swz
1035 tgsi_build_src_register_ext_swz(
1036 unsigned ext_swizzle_x
,
1037 unsigned ext_swizzle_y
,
1038 unsigned ext_swizzle_z
,
1039 unsigned ext_swizzle_w
,
1044 struct tgsi_token
*prev_token
,
1045 struct tgsi_instruction
*instruction
,
1046 struct tgsi_header
*header
)
1048 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1050 assert( ext_swizzle_x
<= TGSI_EXTSWIZZLE_ONE
);
1051 assert( ext_swizzle_y
<= TGSI_EXTSWIZZLE_ONE
);
1052 assert( ext_swizzle_z
<= TGSI_EXTSWIZZLE_ONE
);
1053 assert( ext_swizzle_w
<= TGSI_EXTSWIZZLE_ONE
);
1054 assert( negate_x
<= 1 );
1055 assert( negate_y
<= 1 );
1056 assert( negate_z
<= 1 );
1057 assert( negate_w
<= 1 );
1059 src_register_ext_swz
= tgsi_default_src_register_ext_swz();
1060 src_register_ext_swz
.ExtSwizzleX
= ext_swizzle_x
;
1061 src_register_ext_swz
.ExtSwizzleY
= ext_swizzle_y
;
1062 src_register_ext_swz
.ExtSwizzleZ
= ext_swizzle_z
;
1063 src_register_ext_swz
.ExtSwizzleW
= ext_swizzle_w
;
1064 src_register_ext_swz
.NegateX
= negate_x
;
1065 src_register_ext_swz
.NegateY
= negate_y
;
1066 src_register_ext_swz
.NegateZ
= negate_z
;
1067 src_register_ext_swz
.NegateW
= negate_w
;
1069 prev_token
->Extended
= 1;
1070 instruction_grow( instruction
, header
);
1072 return src_register_ext_swz
;
1075 struct tgsi_src_register_ext_mod
1076 tgsi_default_src_register_ext_mod( void )
1078 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1080 src_register_ext_mod
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_MOD
;
1081 src_register_ext_mod
.Complement
= 0;
1082 src_register_ext_mod
.Bias
= 0;
1083 src_register_ext_mod
.Scale2X
= 0;
1084 src_register_ext_mod
.Absolute
= 0;
1085 src_register_ext_mod
.Negate
= 0;
1086 src_register_ext_mod
.Padding
= 0;
1087 src_register_ext_mod
.Extended
= 0;
1089 return src_register_ext_mod
;
1093 tgsi_compare_src_register_ext_mod(
1094 struct tgsi_src_register_ext_mod a
,
1095 struct tgsi_src_register_ext_mod b
)
1097 a
.Padding
= b
.Padding
= 0;
1098 a
.Extended
= b
.Extended
= 0;
1099 return ((union token_u32
*) &a
)->u32
!= ((union token_u32
*) &b
)->u32
;
1102 struct tgsi_src_register_ext_mod
1103 tgsi_build_src_register_ext_mod(
1104 unsigned complement
,
1109 struct tgsi_token
*prev_token
,
1110 struct tgsi_instruction
*instruction
,
1111 struct tgsi_header
*header
)
1113 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1115 assert( complement
<= 1 );
1116 assert( bias
<= 1 );
1117 assert( scale_2x
<= 1 );
1118 assert( absolute
<= 1 );
1119 assert( negate
<= 1 );
1121 src_register_ext_mod
= tgsi_default_src_register_ext_mod();
1122 src_register_ext_mod
.Complement
= complement
;
1123 src_register_ext_mod
.Bias
= bias
;
1124 src_register_ext_mod
.Scale2X
= scale_2x
;
1125 src_register_ext_mod
.Absolute
= absolute
;
1126 src_register_ext_mod
.Negate
= negate
;
1128 prev_token
->Extended
= 1;
1129 instruction_grow( instruction
, header
);
1131 return src_register_ext_mod
;
1134 struct tgsi_dimension
1135 tgsi_default_dimension( void )
1137 struct tgsi_dimension dimension
;
1139 dimension
.Indirect
= 0;
1140 dimension
.Dimension
= 0;
1141 dimension
.Padding
= 0;
1142 dimension
.Index
= 0;
1143 dimension
.Extended
= 0;
1148 struct tgsi_dimension
1149 tgsi_build_dimension(
1152 struct tgsi_instruction
*instruction
,
1153 struct tgsi_header
*header
)
1155 struct tgsi_dimension dimension
;
1157 dimension
= tgsi_default_dimension();
1158 dimension
.Indirect
= indirect
;
1159 dimension
.Index
= index
;
1161 instruction_grow( instruction
, header
);
1166 struct tgsi_dst_register
1167 tgsi_default_dst_register( void )
1169 struct tgsi_dst_register dst_register
;
1171 dst_register
.File
= TGSI_FILE_NULL
;
1172 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1173 dst_register
.Indirect
= 0;
1174 dst_register
.Dimension
= 0;
1175 dst_register
.Index
= 0;
1176 dst_register
.Padding
= 0;
1177 dst_register
.Extended
= 0;
1179 return dst_register
;
1182 struct tgsi_dst_register
1183 tgsi_build_dst_register(
1187 struct tgsi_instruction
*instruction
,
1188 struct tgsi_header
*header
)
1190 struct tgsi_dst_register dst_register
;
1192 assert( file
<= TGSI_FILE_IMMEDIATE
);
1193 assert( mask
<= TGSI_WRITEMASK_XYZW
);
1194 assert( index
>= -32768 && index
<= 32767 );
1196 dst_register
= tgsi_default_dst_register();
1197 dst_register
.File
= file
;
1198 dst_register
.WriteMask
= mask
;
1199 dst_register
.Index
= index
;
1201 instruction_grow( instruction
, header
);
1203 return dst_register
;
1206 struct tgsi_full_dst_register
1207 tgsi_default_full_dst_register( void )
1209 struct tgsi_full_dst_register full_dst_register
;
1211 full_dst_register
.DstRegister
= tgsi_default_dst_register();
1212 full_dst_register
.DstRegisterExtConcode
=
1213 tgsi_default_dst_register_ext_concode();
1214 full_dst_register
.DstRegisterExtModulate
=
1215 tgsi_default_dst_register_ext_modulate();
1217 return full_dst_register
;
1220 struct tgsi_dst_register_ext_concode
1221 tgsi_default_dst_register_ext_concode( void )
1223 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1225 dst_register_ext_concode
.Type
= TGSI_DST_REGISTER_EXT_TYPE_CONDCODE
;
1226 dst_register_ext_concode
.CondMask
= TGSI_CC_TR
;
1227 dst_register_ext_concode
.CondSwizzleX
= TGSI_SWIZZLE_X
;
1228 dst_register_ext_concode
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
1229 dst_register_ext_concode
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
1230 dst_register_ext_concode
.CondSwizzleW
= TGSI_SWIZZLE_W
;
1231 dst_register_ext_concode
.CondSrcIndex
= 0;
1232 dst_register_ext_concode
.Padding
= 0;
1233 dst_register_ext_concode
.Extended
= 0;
1235 return dst_register_ext_concode
;
1239 tgsi_compare_dst_register_ext_concode(
1240 struct tgsi_dst_register_ext_concode a
,
1241 struct tgsi_dst_register_ext_concode b
)
1243 a
.Padding
= b
.Padding
= 0;
1244 a
.Extended
= b
.Extended
= 0;
1245 return ((union token_u32
*) &a
)->u32
!= ((union token_u32
*) &b
)->u32
;
1248 struct tgsi_dst_register_ext_concode
1249 tgsi_build_dst_register_ext_concode(
1256 struct tgsi_token
*prev_token
,
1257 struct tgsi_instruction
*instruction
,
1258 struct tgsi_header
*header
)
1260 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1262 assert( cc
<= TGSI_CC_FL
);
1263 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
1264 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
1265 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
1266 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
1267 assert( index
>= -32768 && index
<= 32767 );
1269 dst_register_ext_concode
= tgsi_default_dst_register_ext_concode();
1270 dst_register_ext_concode
.CondMask
= cc
;
1271 dst_register_ext_concode
.CondSwizzleX
= swizzle_x
;
1272 dst_register_ext_concode
.CondSwizzleY
= swizzle_y
;
1273 dst_register_ext_concode
.CondSwizzleZ
= swizzle_z
;
1274 dst_register_ext_concode
.CondSwizzleW
= swizzle_w
;
1275 dst_register_ext_concode
.CondSrcIndex
= index
;
1277 prev_token
->Extended
= 1;
1278 instruction_grow( instruction
, header
);
1280 return dst_register_ext_concode
;
1283 struct tgsi_dst_register_ext_modulate
1284 tgsi_default_dst_register_ext_modulate( void )
1286 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1288 dst_register_ext_modulate
.Type
= TGSI_DST_REGISTER_EXT_TYPE_MODULATE
;
1289 dst_register_ext_modulate
.Modulate
= TGSI_MODULATE_1X
;
1290 dst_register_ext_modulate
.Padding
= 0;
1291 dst_register_ext_modulate
.Extended
= 0;
1293 return dst_register_ext_modulate
;
1297 tgsi_compare_dst_register_ext_modulate(
1298 struct tgsi_dst_register_ext_modulate a
,
1299 struct tgsi_dst_register_ext_modulate b
)
1301 a
.Padding
= b
.Padding
= 0;
1302 a
.Extended
= b
.Extended
= 0;
1303 return ((union token_u32
*) &a
)->u32
!= ((union token_u32
*) &b
)->u32
;
1306 struct tgsi_dst_register_ext_modulate
1307 tgsi_build_dst_register_ext_modulate(
1309 struct tgsi_token
*prev_token
,
1310 struct tgsi_instruction
*instruction
,
1311 struct tgsi_header
*header
)
1313 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1315 assert( modulate
<= TGSI_MODULATE_EIGHTH
);
1317 dst_register_ext_modulate
= tgsi_default_dst_register_ext_modulate();
1318 dst_register_ext_modulate
.Modulate
= modulate
;
1320 prev_token
->Extended
= 1;
1321 instruction_grow( instruction
, header
);
1323 return dst_register_ext_modulate
;