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_shader_tokens.h"
30 #include "tgsi_build.h"
31 #include "tgsi_parse.h"
38 tgsi_build_version( void )
40 struct tgsi_version version
;
42 version
.MajorVersion
= 1;
43 version
.MinorVersion
= 1;
54 tgsi_build_header( void )
56 struct tgsi_header header
;
58 header
.HeaderSize
= 1;
65 header_headersize_grow( struct tgsi_header
*header
)
67 assert( header
->HeaderSize
< 0xFF );
68 assert( header
->BodySize
== 0 );
74 header_bodysize_grow( struct tgsi_header
*header
)
76 assert( header
->BodySize
< 0xFFFFFF );
82 tgsi_default_processor( void )
84 struct tgsi_processor processor
;
86 processor
.Processor
= TGSI_PROCESSOR_FRAGMENT
;
87 processor
.Padding
= 0;
95 struct tgsi_header
*header
)
97 struct tgsi_processor processor
;
99 processor
= tgsi_default_processor();
100 processor
.Processor
= type
;
102 header_headersize_grow( header
);
111 struct tgsi_declaration
112 tgsi_default_declaration( void )
114 struct tgsi_declaration declaration
;
116 declaration
.Type
= TGSI_TOKEN_TYPE_DECLARATION
;
117 declaration
.Size
= 1;
118 declaration
.File
= TGSI_FILE_NULL
;
119 declaration
.UsageMask
= TGSI_WRITEMASK_XYZW
;
120 declaration
.Interpolate
= TGSI_INTERPOLATE_CONSTANT
;
121 declaration
.Semantic
= 0;
122 declaration
.Centroid
= 0;
123 declaration
.Invariant
= 0;
124 declaration
.Padding
= 0;
125 declaration
.Extended
= 0;
130 struct tgsi_declaration
131 tgsi_build_declaration(
134 unsigned interpolate
,
138 struct tgsi_header
*header
)
140 struct tgsi_declaration declaration
;
142 assert( file
<= TGSI_FILE_IMMEDIATE
);
143 assert( interpolate
<= TGSI_INTERPOLATE_PERSPECTIVE
);
145 declaration
= tgsi_default_declaration();
146 declaration
.File
= file
;
147 declaration
.UsageMask
= usage_mask
;
148 declaration
.Interpolate
= interpolate
;
149 declaration
.Semantic
= semantic
;
150 declaration
.Centroid
= centroid
;
151 declaration
.Invariant
= invariant
;
153 header_bodysize_grow( header
);
160 struct tgsi_declaration
*declaration
,
161 struct tgsi_header
*header
)
163 assert( declaration
->Size
< 0xFF );
167 header_bodysize_grow( header
);
170 struct tgsi_full_declaration
171 tgsi_default_full_declaration( void )
173 struct tgsi_full_declaration full_declaration
;
175 full_declaration
.Declaration
= tgsi_default_declaration();
176 full_declaration
.DeclarationRange
= tgsi_default_declaration_range();
177 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
179 return full_declaration
;
183 tgsi_build_full_declaration(
184 const struct tgsi_full_declaration
*full_decl
,
185 struct tgsi_token
*tokens
,
186 struct tgsi_header
*header
,
190 struct tgsi_declaration
*declaration
;
191 struct tgsi_declaration_range
*dr
;
193 if( maxsize
<= size
)
195 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
198 *declaration
= tgsi_build_declaration(
199 full_decl
->Declaration
.File
,
200 full_decl
->Declaration
.UsageMask
,
201 full_decl
->Declaration
.Interpolate
,
202 full_decl
->Declaration
.Semantic
,
203 full_decl
->Declaration
.Centroid
,
204 full_decl
->Declaration
.Invariant
,
209 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
212 *dr
= tgsi_build_declaration_range(
213 full_decl
->DeclarationRange
.First
,
214 full_decl
->DeclarationRange
.Last
,
218 if( full_decl
->Declaration
.Semantic
) {
219 struct tgsi_declaration_semantic
*ds
;
221 if( maxsize
<= size
)
223 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
226 *ds
= tgsi_build_declaration_semantic(
227 full_decl
->Semantic
.SemanticName
,
228 full_decl
->Semantic
.SemanticIndex
,
236 struct tgsi_declaration_range
237 tgsi_default_declaration_range( void )
239 struct tgsi_declaration_range dr
;
247 struct tgsi_declaration_range
248 tgsi_build_declaration_range(
251 struct tgsi_declaration
*declaration
,
252 struct tgsi_header
*header
)
254 struct tgsi_declaration_range declaration_range
;
256 assert( last
>= first
);
257 assert( last
<= 0xFFFF );
259 declaration_range
= tgsi_default_declaration_range();
260 declaration_range
.First
= first
;
261 declaration_range
.Last
= last
;
263 declaration_grow( declaration
, header
);
265 return declaration_range
;
268 struct tgsi_declaration_semantic
269 tgsi_default_declaration_semantic( void )
271 struct tgsi_declaration_semantic ds
;
273 ds
.SemanticName
= TGSI_SEMANTIC_POSITION
;
274 ds
.SemanticIndex
= 0;
280 struct tgsi_declaration_semantic
281 tgsi_build_declaration_semantic(
282 unsigned semantic_name
,
283 unsigned semantic_index
,
284 struct tgsi_declaration
*declaration
,
285 struct tgsi_header
*header
)
287 struct tgsi_declaration_semantic ds
;
289 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
290 assert( semantic_index
<= 0xFFFF );
292 ds
= tgsi_default_declaration_semantic();
293 ds
.SemanticName
= semantic_name
;
294 ds
.SemanticIndex
= semantic_index
;
296 declaration_grow( declaration
, header
);
305 struct tgsi_immediate
306 tgsi_default_immediate( void )
308 struct tgsi_immediate immediate
;
310 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
312 immediate
.DataType
= TGSI_IMM_FLOAT32
;
313 immediate
.Padding
= 0;
314 immediate
.Extended
= 0;
319 struct tgsi_immediate
320 tgsi_build_immediate(
321 struct tgsi_header
*header
)
323 struct tgsi_immediate immediate
;
325 immediate
= tgsi_default_immediate();
327 header_bodysize_grow( header
);
332 struct tgsi_full_immediate
333 tgsi_default_full_immediate( void )
335 struct tgsi_full_immediate fullimm
;
337 fullimm
.Immediate
= tgsi_default_immediate();
338 fullimm
.u
.Pointer
= (void *) 0;
345 struct tgsi_immediate
*immediate
,
346 struct tgsi_header
*header
)
348 assert( immediate
->Size
< 0xFF );
352 header_bodysize_grow( header
);
355 struct tgsi_immediate_float32
356 tgsi_build_immediate_float32(
358 struct tgsi_immediate
*immediate
,
359 struct tgsi_header
*header
)
361 struct tgsi_immediate_float32 immediate_float32
;
363 immediate_float32
.Float
= value
;
365 immediate_grow( immediate
, header
);
367 return immediate_float32
;
371 tgsi_build_full_immediate(
372 const struct tgsi_full_immediate
*full_imm
,
373 struct tgsi_token
*tokens
,
374 struct tgsi_header
*header
,
377 unsigned size
= 0, i
;
378 struct tgsi_immediate
*immediate
;
380 if( maxsize
<= size
)
382 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
385 *immediate
= tgsi_build_immediate( header
);
387 for( i
= 0; i
< full_imm
->Immediate
.Size
- 1; i
++ ) {
388 struct tgsi_immediate_float32
*if32
;
390 if( maxsize
<= size
)
392 if32
= (struct tgsi_immediate_float32
*) &tokens
[size
];
395 *if32
= tgsi_build_immediate_float32(
396 full_imm
->u
.ImmediateFloat32
[i
].Float
,
408 struct tgsi_instruction
409 tgsi_default_instruction( void )
411 struct tgsi_instruction instruction
;
413 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
414 instruction
.Size
= 1;
415 instruction
.Opcode
= TGSI_OPCODE_MOV
;
416 instruction
.Saturate
= TGSI_SAT_NONE
;
417 instruction
.NumDstRegs
= 1;
418 instruction
.NumSrcRegs
= 1;
419 instruction
.Padding
= 0;
420 instruction
.Extended
= 0;
425 struct tgsi_instruction
426 tgsi_build_instruction(
429 unsigned num_dst_regs
,
430 unsigned num_src_regs
,
431 struct tgsi_header
*header
)
433 struct tgsi_instruction instruction
;
435 assert (opcode
<= TGSI_OPCODE_LAST
);
436 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
437 assert (num_dst_regs
<= 3);
438 assert (num_src_regs
<= 15);
440 instruction
= tgsi_default_instruction();
441 instruction
.Opcode
= opcode
;
442 instruction
.Saturate
= saturate
;
443 instruction
.NumDstRegs
= num_dst_regs
;
444 instruction
.NumSrcRegs
= num_src_regs
;
446 header_bodysize_grow( header
);
453 struct tgsi_instruction
*instruction
,
454 struct tgsi_header
*header
)
456 assert (instruction
->Size
< 0xFF);
460 header_bodysize_grow( header
);
463 struct tgsi_full_instruction
464 tgsi_default_full_instruction( void )
466 struct tgsi_full_instruction full_instruction
;
469 full_instruction
.Instruction
= tgsi_default_instruction();
470 full_instruction
.InstructionExtNv
= tgsi_default_instruction_ext_nv();
471 full_instruction
.InstructionExtLabel
= tgsi_default_instruction_ext_label();
472 full_instruction
.InstructionExtTexture
= tgsi_default_instruction_ext_texture();
473 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
474 full_instruction
.FullDstRegisters
[i
] = tgsi_default_full_dst_register();
476 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
477 full_instruction
.FullSrcRegisters
[i
] = tgsi_default_full_src_register();
480 return full_instruction
;
484 tgsi_build_full_instruction(
485 const struct tgsi_full_instruction
*full_inst
,
486 struct tgsi_token
*tokens
,
487 struct tgsi_header
*header
,
492 struct tgsi_instruction
*instruction
;
493 struct tgsi_token
*prev_token
;
495 if( maxsize
<= size
)
497 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
500 *instruction
= tgsi_build_instruction(
501 full_inst
->Instruction
.Opcode
,
502 full_inst
->Instruction
.Saturate
,
503 full_inst
->Instruction
.NumDstRegs
,
504 full_inst
->Instruction
.NumSrcRegs
,
506 prev_token
= (struct tgsi_token
*) instruction
;
508 if( tgsi_compare_instruction_ext_nv(
509 full_inst
->InstructionExtNv
,
510 tgsi_default_instruction_ext_nv() ) ) {
511 struct tgsi_instruction_ext_nv
*instruction_ext_nv
;
513 if( maxsize
<= size
)
516 (struct tgsi_instruction_ext_nv
*) &tokens
[size
];
519 *instruction_ext_nv
= tgsi_build_instruction_ext_nv(
520 full_inst
->InstructionExtNv
.Precision
,
521 full_inst
->InstructionExtNv
.CondDstIndex
,
522 full_inst
->InstructionExtNv
.CondFlowIndex
,
523 full_inst
->InstructionExtNv
.CondMask
,
524 full_inst
->InstructionExtNv
.CondSwizzleX
,
525 full_inst
->InstructionExtNv
.CondSwizzleY
,
526 full_inst
->InstructionExtNv
.CondSwizzleZ
,
527 full_inst
->InstructionExtNv
.CondSwizzleW
,
528 full_inst
->InstructionExtNv
.CondDstUpdate
,
529 full_inst
->InstructionExtNv
.CondFlowEnable
,
533 prev_token
= (struct tgsi_token
*) instruction_ext_nv
;
536 if( tgsi_compare_instruction_ext_label(
537 full_inst
->InstructionExtLabel
,
538 tgsi_default_instruction_ext_label() ) ) {
539 struct tgsi_instruction_ext_label
*instruction_ext_label
;
541 if( maxsize
<= size
)
543 instruction_ext_label
=
544 (struct tgsi_instruction_ext_label
*) &tokens
[size
];
547 *instruction_ext_label
= tgsi_build_instruction_ext_label(
548 full_inst
->InstructionExtLabel
.Label
,
552 prev_token
= (struct tgsi_token
*) instruction_ext_label
;
555 if( tgsi_compare_instruction_ext_texture(
556 full_inst
->InstructionExtTexture
,
557 tgsi_default_instruction_ext_texture() ) ) {
558 struct tgsi_instruction_ext_texture
*instruction_ext_texture
;
560 if( maxsize
<= size
)
562 instruction_ext_texture
=
563 (struct tgsi_instruction_ext_texture
*) &tokens
[size
];
566 *instruction_ext_texture
= tgsi_build_instruction_ext_texture(
567 full_inst
->InstructionExtTexture
.Texture
,
571 prev_token
= (struct tgsi_token
*) instruction_ext_texture
;
574 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
575 const struct tgsi_full_dst_register
*reg
= &full_inst
->FullDstRegisters
[i
];
576 struct tgsi_dst_register
*dst_register
;
577 struct tgsi_token
*prev_token
;
579 if( maxsize
<= size
)
581 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
584 *dst_register
= tgsi_build_dst_register(
585 reg
->DstRegister
.File
,
586 reg
->DstRegister
.WriteMask
,
587 reg
->DstRegister
.Index
,
590 prev_token
= (struct tgsi_token
*) dst_register
;
592 if( tgsi_compare_dst_register_ext_concode(
593 reg
->DstRegisterExtConcode
,
594 tgsi_default_dst_register_ext_concode() ) ) {
595 struct tgsi_dst_register_ext_concode
*dst_register_ext_concode
;
597 if( maxsize
<= size
)
599 dst_register_ext_concode
=
600 (struct tgsi_dst_register_ext_concode
*) &tokens
[size
];
603 *dst_register_ext_concode
= tgsi_build_dst_register_ext_concode(
604 reg
->DstRegisterExtConcode
.CondMask
,
605 reg
->DstRegisterExtConcode
.CondSwizzleX
,
606 reg
->DstRegisterExtConcode
.CondSwizzleY
,
607 reg
->DstRegisterExtConcode
.CondSwizzleZ
,
608 reg
->DstRegisterExtConcode
.CondSwizzleW
,
609 reg
->DstRegisterExtConcode
.CondSrcIndex
,
613 prev_token
= (struct tgsi_token
*) dst_register_ext_concode
;
616 if( tgsi_compare_dst_register_ext_modulate(
617 reg
->DstRegisterExtModulate
,
618 tgsi_default_dst_register_ext_modulate() ) ) {
619 struct tgsi_dst_register_ext_modulate
*dst_register_ext_modulate
;
621 if( maxsize
<= size
)
623 dst_register_ext_modulate
=
624 (struct tgsi_dst_register_ext_modulate
*) &tokens
[size
];
627 *dst_register_ext_modulate
= tgsi_build_dst_register_ext_modulate(
628 reg
->DstRegisterExtModulate
.Modulate
,
632 prev_token
= (struct tgsi_token
*) dst_register_ext_modulate
;
636 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
637 const struct tgsi_full_src_register
*reg
= &full_inst
->FullSrcRegisters
[i
];
638 struct tgsi_src_register
*src_register
;
639 struct tgsi_token
*prev_token
;
641 if( maxsize
<= size
)
643 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
646 *src_register
= tgsi_build_src_register(
647 reg
->SrcRegister
.File
,
648 reg
->SrcRegister
.SwizzleX
,
649 reg
->SrcRegister
.SwizzleY
,
650 reg
->SrcRegister
.SwizzleZ
,
651 reg
->SrcRegister
.SwizzleW
,
652 reg
->SrcRegister
.Negate
,
653 reg
->SrcRegister
.Indirect
,
654 reg
->SrcRegister
.Dimension
,
655 reg
->SrcRegister
.Index
,
658 prev_token
= (struct tgsi_token
*) src_register
;
660 if( tgsi_compare_src_register_ext_swz(
661 reg
->SrcRegisterExtSwz
,
662 tgsi_default_src_register_ext_swz() ) ) {
663 struct tgsi_src_register_ext_swz
*src_register_ext_swz
;
665 /* Use of the extended swizzle requires the simple swizzle to be identity.
667 assert( reg
->SrcRegister
.SwizzleX
== TGSI_SWIZZLE_X
);
668 assert( reg
->SrcRegister
.SwizzleY
== TGSI_SWIZZLE_Y
);
669 assert( reg
->SrcRegister
.SwizzleZ
== TGSI_SWIZZLE_Z
);
670 assert( reg
->SrcRegister
.SwizzleW
== TGSI_SWIZZLE_W
);
671 assert( reg
->SrcRegister
.Negate
== FALSE
);
673 if( maxsize
<= size
)
675 src_register_ext_swz
=
676 (struct tgsi_src_register_ext_swz
*) &tokens
[size
];
679 *src_register_ext_swz
= tgsi_build_src_register_ext_swz(
680 reg
->SrcRegisterExtSwz
.ExtSwizzleX
,
681 reg
->SrcRegisterExtSwz
.ExtSwizzleY
,
682 reg
->SrcRegisterExtSwz
.ExtSwizzleZ
,
683 reg
->SrcRegisterExtSwz
.ExtSwizzleW
,
684 reg
->SrcRegisterExtSwz
.NegateX
,
685 reg
->SrcRegisterExtSwz
.NegateY
,
686 reg
->SrcRegisterExtSwz
.NegateZ
,
687 reg
->SrcRegisterExtSwz
.NegateW
,
691 prev_token
= (struct tgsi_token
*) src_register_ext_swz
;
694 if( tgsi_compare_src_register_ext_mod(
695 reg
->SrcRegisterExtMod
,
696 tgsi_default_src_register_ext_mod() ) ) {
697 struct tgsi_src_register_ext_mod
*src_register_ext_mod
;
699 if( maxsize
<= size
)
701 src_register_ext_mod
=
702 (struct tgsi_src_register_ext_mod
*) &tokens
[size
];
705 *src_register_ext_mod
= tgsi_build_src_register_ext_mod(
706 reg
->SrcRegisterExtMod
.Complement
,
707 reg
->SrcRegisterExtMod
.Bias
,
708 reg
->SrcRegisterExtMod
.Scale2X
,
709 reg
->SrcRegisterExtMod
.Absolute
,
710 reg
->SrcRegisterExtMod
.Negate
,
714 prev_token
= (struct tgsi_token
*) src_register_ext_mod
;
717 if( reg
->SrcRegister
.Indirect
) {
718 struct tgsi_src_register
*ind
;
720 if( maxsize
<= size
)
722 ind
= (struct tgsi_src_register
*) &tokens
[size
];
725 *ind
= tgsi_build_src_register(
726 reg
->SrcRegisterInd
.File
,
727 reg
->SrcRegisterInd
.SwizzleX
,
728 reg
->SrcRegisterInd
.SwizzleY
,
729 reg
->SrcRegisterInd
.SwizzleZ
,
730 reg
->SrcRegisterInd
.SwizzleW
,
731 reg
->SrcRegisterInd
.Negate
,
732 reg
->SrcRegisterInd
.Indirect
,
733 reg
->SrcRegisterInd
.Dimension
,
734 reg
->SrcRegisterInd
.Index
,
739 if( reg
->SrcRegister
.Dimension
) {
740 struct tgsi_dimension
*dim
;
742 assert( !reg
->SrcRegisterDim
.Dimension
);
744 if( maxsize
<= size
)
746 dim
= (struct tgsi_dimension
*) &tokens
[size
];
749 *dim
= tgsi_build_dimension(
750 reg
->SrcRegisterDim
.Indirect
,
751 reg
->SrcRegisterDim
.Index
,
755 if( reg
->SrcRegisterDim
.Indirect
) {
756 struct tgsi_src_register
*ind
;
758 if( maxsize
<= size
)
760 ind
= (struct tgsi_src_register
*) &tokens
[size
];
763 *ind
= tgsi_build_src_register(
764 reg
->SrcRegisterDimInd
.File
,
765 reg
->SrcRegisterDimInd
.SwizzleX
,
766 reg
->SrcRegisterDimInd
.SwizzleY
,
767 reg
->SrcRegisterDimInd
.SwizzleZ
,
768 reg
->SrcRegisterDimInd
.SwizzleW
,
769 reg
->SrcRegisterDimInd
.Negate
,
770 reg
->SrcRegisterDimInd
.Indirect
,
771 reg
->SrcRegisterDimInd
.Dimension
,
772 reg
->SrcRegisterDimInd
.Index
,
782 struct tgsi_instruction_ext_nv
783 tgsi_default_instruction_ext_nv( void )
785 struct tgsi_instruction_ext_nv instruction_ext_nv
;
787 instruction_ext_nv
.Type
= TGSI_INSTRUCTION_EXT_TYPE_NV
;
788 instruction_ext_nv
.Precision
= TGSI_PRECISION_DEFAULT
;
789 instruction_ext_nv
.CondDstIndex
= 0;
790 instruction_ext_nv
.CondFlowIndex
= 0;
791 instruction_ext_nv
.CondMask
= TGSI_CC_TR
;
792 instruction_ext_nv
.CondSwizzleX
= TGSI_SWIZZLE_X
;
793 instruction_ext_nv
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
794 instruction_ext_nv
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
795 instruction_ext_nv
.CondSwizzleW
= TGSI_SWIZZLE_W
;
796 instruction_ext_nv
.CondDstUpdate
= 0;
797 instruction_ext_nv
.CondFlowEnable
= 0;
798 instruction_ext_nv
.Padding
= 0;
799 instruction_ext_nv
.Extended
= 0;
801 return instruction_ext_nv
;
805 /** test for inequality of 32-bit values pointed to by a and b */
806 static INLINE boolean
807 compare32(const void *a
, const void *b
)
809 return *((uint32_t *) a
) != *((uint32_t *) b
);
814 tgsi_compare_instruction_ext_nv(
815 struct tgsi_instruction_ext_nv a
,
816 struct tgsi_instruction_ext_nv b
)
818 a
.Padding
= b
.Padding
= 0;
819 a
.Extended
= b
.Extended
= 0;
820 return compare32(&a
, &b
);
823 struct tgsi_instruction_ext_nv
824 tgsi_build_instruction_ext_nv(
826 unsigned cond_dst_index
,
827 unsigned cond_flow_index
,
829 unsigned cond_swizzle_x
,
830 unsigned cond_swizzle_y
,
831 unsigned cond_swizzle_z
,
832 unsigned cond_swizzle_w
,
833 unsigned cond_dst_update
,
834 unsigned cond_flow_enable
,
835 struct tgsi_token
*prev_token
,
836 struct tgsi_instruction
*instruction
,
837 struct tgsi_header
*header
)
839 struct tgsi_instruction_ext_nv instruction_ext_nv
;
841 instruction_ext_nv
= tgsi_default_instruction_ext_nv();
842 instruction_ext_nv
.Precision
= precision
;
843 instruction_ext_nv
.CondDstIndex
= cond_dst_index
;
844 instruction_ext_nv
.CondFlowIndex
= cond_flow_index
;
845 instruction_ext_nv
.CondMask
= cond_mask
;
846 instruction_ext_nv
.CondSwizzleX
= cond_swizzle_x
;
847 instruction_ext_nv
.CondSwizzleY
= cond_swizzle_y
;
848 instruction_ext_nv
.CondSwizzleZ
= cond_swizzle_z
;
849 instruction_ext_nv
.CondSwizzleW
= cond_swizzle_w
;
850 instruction_ext_nv
.CondDstUpdate
= cond_dst_update
;
851 instruction_ext_nv
.CondFlowEnable
= cond_flow_enable
;
853 prev_token
->Extended
= 1;
854 instruction_grow( instruction
, header
);
856 return instruction_ext_nv
;
859 struct tgsi_instruction_ext_label
860 tgsi_default_instruction_ext_label( void )
862 struct tgsi_instruction_ext_label instruction_ext_label
;
864 instruction_ext_label
.Type
= TGSI_INSTRUCTION_EXT_TYPE_LABEL
;
865 instruction_ext_label
.Label
= 0;
866 instruction_ext_label
.Padding
= 0;
867 instruction_ext_label
.Extended
= 0;
869 return instruction_ext_label
;
873 tgsi_compare_instruction_ext_label(
874 struct tgsi_instruction_ext_label a
,
875 struct tgsi_instruction_ext_label b
)
877 a
.Padding
= b
.Padding
= 0;
878 a
.Extended
= b
.Extended
= 0;
879 return compare32(&a
, &b
);
882 struct tgsi_instruction_ext_label
883 tgsi_build_instruction_ext_label(
885 struct tgsi_token
*prev_token
,
886 struct tgsi_instruction
*instruction
,
887 struct tgsi_header
*header
)
889 struct tgsi_instruction_ext_label instruction_ext_label
;
891 instruction_ext_label
= tgsi_default_instruction_ext_label();
892 instruction_ext_label
.Label
= label
;
894 prev_token
->Extended
= 1;
895 instruction_grow( instruction
, header
);
897 return instruction_ext_label
;
900 struct tgsi_instruction_ext_texture
901 tgsi_default_instruction_ext_texture( void )
903 struct tgsi_instruction_ext_texture instruction_ext_texture
;
905 instruction_ext_texture
.Type
= TGSI_INSTRUCTION_EXT_TYPE_TEXTURE
;
906 instruction_ext_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
907 instruction_ext_texture
.Padding
= 0;
908 instruction_ext_texture
.Extended
= 0;
910 return instruction_ext_texture
;
914 tgsi_compare_instruction_ext_texture(
915 struct tgsi_instruction_ext_texture a
,
916 struct tgsi_instruction_ext_texture b
)
918 a
.Padding
= b
.Padding
= 0;
919 a
.Extended
= b
.Extended
= 0;
920 return compare32(&a
, &b
);
923 struct tgsi_instruction_ext_texture
924 tgsi_build_instruction_ext_texture(
926 struct tgsi_token
*prev_token
,
927 struct tgsi_instruction
*instruction
,
928 struct tgsi_header
*header
)
930 struct tgsi_instruction_ext_texture instruction_ext_texture
;
932 instruction_ext_texture
= tgsi_default_instruction_ext_texture();
933 instruction_ext_texture
.Texture
= texture
;
935 prev_token
->Extended
= 1;
936 instruction_grow( instruction
, header
);
938 return instruction_ext_texture
;
941 struct tgsi_src_register
942 tgsi_default_src_register( void )
944 struct tgsi_src_register src_register
;
946 src_register
.File
= TGSI_FILE_NULL
;
947 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
948 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
949 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
950 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
951 src_register
.Negate
= 0;
952 src_register
.Indirect
= 0;
953 src_register
.Dimension
= 0;
954 src_register
.Index
= 0;
955 src_register
.Extended
= 0;
960 struct tgsi_src_register
961 tgsi_build_src_register(
971 struct tgsi_instruction
*instruction
,
972 struct tgsi_header
*header
)
974 struct tgsi_src_register src_register
;
976 assert( file
<= TGSI_FILE_IMMEDIATE
);
977 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
978 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
979 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
980 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
981 assert( negate
<= 1 );
982 assert( index
>= -0x8000 && index
<= 0x7FFF );
984 src_register
= tgsi_default_src_register();
985 src_register
.File
= file
;
986 src_register
.SwizzleX
= swizzle_x
;
987 src_register
.SwizzleY
= swizzle_y
;
988 src_register
.SwizzleZ
= swizzle_z
;
989 src_register
.SwizzleW
= swizzle_w
;
990 src_register
.Negate
= negate
;
991 src_register
.Indirect
= indirect
;
992 src_register
.Dimension
= dimension
;
993 src_register
.Index
= index
;
995 instruction_grow( instruction
, header
);
1000 struct tgsi_full_src_register
1001 tgsi_default_full_src_register( void )
1003 struct tgsi_full_src_register full_src_register
;
1005 full_src_register
.SrcRegister
= tgsi_default_src_register();
1006 full_src_register
.SrcRegisterExtSwz
= tgsi_default_src_register_ext_swz();
1007 full_src_register
.SrcRegisterExtMod
= tgsi_default_src_register_ext_mod();
1008 full_src_register
.SrcRegisterInd
= tgsi_default_src_register();
1009 full_src_register
.SrcRegisterDim
= tgsi_default_dimension();
1010 full_src_register
.SrcRegisterDimInd
= tgsi_default_src_register();
1012 return full_src_register
;
1015 struct tgsi_src_register_ext_swz
1016 tgsi_default_src_register_ext_swz( void )
1018 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1020 src_register_ext_swz
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_SWZ
;
1021 src_register_ext_swz
.ExtSwizzleX
= TGSI_EXTSWIZZLE_X
;
1022 src_register_ext_swz
.ExtSwizzleY
= TGSI_EXTSWIZZLE_Y
;
1023 src_register_ext_swz
.ExtSwizzleZ
= TGSI_EXTSWIZZLE_Z
;
1024 src_register_ext_swz
.ExtSwizzleW
= TGSI_EXTSWIZZLE_W
;
1025 src_register_ext_swz
.NegateX
= 0;
1026 src_register_ext_swz
.NegateY
= 0;
1027 src_register_ext_swz
.NegateZ
= 0;
1028 src_register_ext_swz
.NegateW
= 0;
1029 src_register_ext_swz
.Padding
= 0;
1030 src_register_ext_swz
.Extended
= 0;
1032 return src_register_ext_swz
;
1036 tgsi_compare_src_register_ext_swz(
1037 struct tgsi_src_register_ext_swz a
,
1038 struct tgsi_src_register_ext_swz b
)
1040 a
.Padding
= b
.Padding
= 0;
1041 a
.Extended
= b
.Extended
= 0;
1042 return compare32(&a
, &b
);
1045 struct tgsi_src_register_ext_swz
1046 tgsi_build_src_register_ext_swz(
1047 unsigned ext_swizzle_x
,
1048 unsigned ext_swizzle_y
,
1049 unsigned ext_swizzle_z
,
1050 unsigned ext_swizzle_w
,
1055 struct tgsi_token
*prev_token
,
1056 struct tgsi_instruction
*instruction
,
1057 struct tgsi_header
*header
)
1059 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1061 assert( ext_swizzle_x
<= TGSI_EXTSWIZZLE_ONE
);
1062 assert( ext_swizzle_y
<= TGSI_EXTSWIZZLE_ONE
);
1063 assert( ext_swizzle_z
<= TGSI_EXTSWIZZLE_ONE
);
1064 assert( ext_swizzle_w
<= TGSI_EXTSWIZZLE_ONE
);
1065 assert( negate_x
<= 1 );
1066 assert( negate_y
<= 1 );
1067 assert( negate_z
<= 1 );
1068 assert( negate_w
<= 1 );
1070 src_register_ext_swz
= tgsi_default_src_register_ext_swz();
1071 src_register_ext_swz
.ExtSwizzleX
= ext_swizzle_x
;
1072 src_register_ext_swz
.ExtSwizzleY
= ext_swizzle_y
;
1073 src_register_ext_swz
.ExtSwizzleZ
= ext_swizzle_z
;
1074 src_register_ext_swz
.ExtSwizzleW
= ext_swizzle_w
;
1075 src_register_ext_swz
.NegateX
= negate_x
;
1076 src_register_ext_swz
.NegateY
= negate_y
;
1077 src_register_ext_swz
.NegateZ
= negate_z
;
1078 src_register_ext_swz
.NegateW
= negate_w
;
1080 prev_token
->Extended
= 1;
1081 instruction_grow( instruction
, header
);
1083 return src_register_ext_swz
;
1086 struct tgsi_src_register_ext_mod
1087 tgsi_default_src_register_ext_mod( void )
1089 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1091 src_register_ext_mod
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_MOD
;
1092 src_register_ext_mod
.Complement
= 0;
1093 src_register_ext_mod
.Bias
= 0;
1094 src_register_ext_mod
.Scale2X
= 0;
1095 src_register_ext_mod
.Absolute
= 0;
1096 src_register_ext_mod
.Negate
= 0;
1097 src_register_ext_mod
.Padding
= 0;
1098 src_register_ext_mod
.Extended
= 0;
1100 return src_register_ext_mod
;
1104 tgsi_compare_src_register_ext_mod(
1105 struct tgsi_src_register_ext_mod a
,
1106 struct tgsi_src_register_ext_mod b
)
1108 a
.Padding
= b
.Padding
= 0;
1109 a
.Extended
= b
.Extended
= 0;
1110 return compare32(&a
, &b
);
1113 struct tgsi_src_register_ext_mod
1114 tgsi_build_src_register_ext_mod(
1115 unsigned complement
,
1120 struct tgsi_token
*prev_token
,
1121 struct tgsi_instruction
*instruction
,
1122 struct tgsi_header
*header
)
1124 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1126 assert( complement
<= 1 );
1127 assert( bias
<= 1 );
1128 assert( scale_2x
<= 1 );
1129 assert( absolute
<= 1 );
1130 assert( negate
<= 1 );
1132 src_register_ext_mod
= tgsi_default_src_register_ext_mod();
1133 src_register_ext_mod
.Complement
= complement
;
1134 src_register_ext_mod
.Bias
= bias
;
1135 src_register_ext_mod
.Scale2X
= scale_2x
;
1136 src_register_ext_mod
.Absolute
= absolute
;
1137 src_register_ext_mod
.Negate
= negate
;
1139 prev_token
->Extended
= 1;
1140 instruction_grow( instruction
, header
);
1142 return src_register_ext_mod
;
1145 struct tgsi_dimension
1146 tgsi_default_dimension( void )
1148 struct tgsi_dimension dimension
;
1150 dimension
.Indirect
= 0;
1151 dimension
.Dimension
= 0;
1152 dimension
.Padding
= 0;
1153 dimension
.Index
= 0;
1154 dimension
.Extended
= 0;
1159 struct tgsi_dimension
1160 tgsi_build_dimension(
1163 struct tgsi_instruction
*instruction
,
1164 struct tgsi_header
*header
)
1166 struct tgsi_dimension dimension
;
1168 dimension
= tgsi_default_dimension();
1169 dimension
.Indirect
= indirect
;
1170 dimension
.Index
= index
;
1172 instruction_grow( instruction
, header
);
1177 struct tgsi_dst_register
1178 tgsi_default_dst_register( void )
1180 struct tgsi_dst_register dst_register
;
1182 dst_register
.File
= TGSI_FILE_NULL
;
1183 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1184 dst_register
.Indirect
= 0;
1185 dst_register
.Dimension
= 0;
1186 dst_register
.Index
= 0;
1187 dst_register
.Padding
= 0;
1188 dst_register
.Extended
= 0;
1190 return dst_register
;
1193 struct tgsi_dst_register
1194 tgsi_build_dst_register(
1198 struct tgsi_instruction
*instruction
,
1199 struct tgsi_header
*header
)
1201 struct tgsi_dst_register dst_register
;
1203 assert( file
<= TGSI_FILE_IMMEDIATE
);
1204 assert( mask
<= TGSI_WRITEMASK_XYZW
);
1205 assert( index
>= -32768 && index
<= 32767 );
1207 dst_register
= tgsi_default_dst_register();
1208 dst_register
.File
= file
;
1209 dst_register
.WriteMask
= mask
;
1210 dst_register
.Index
= index
;
1212 instruction_grow( instruction
, header
);
1214 return dst_register
;
1217 struct tgsi_full_dst_register
1218 tgsi_default_full_dst_register( void )
1220 struct tgsi_full_dst_register full_dst_register
;
1222 full_dst_register
.DstRegister
= tgsi_default_dst_register();
1223 full_dst_register
.DstRegisterExtConcode
=
1224 tgsi_default_dst_register_ext_concode();
1225 full_dst_register
.DstRegisterExtModulate
=
1226 tgsi_default_dst_register_ext_modulate();
1228 return full_dst_register
;
1231 struct tgsi_dst_register_ext_concode
1232 tgsi_default_dst_register_ext_concode( void )
1234 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1236 dst_register_ext_concode
.Type
= TGSI_DST_REGISTER_EXT_TYPE_CONDCODE
;
1237 dst_register_ext_concode
.CondMask
= TGSI_CC_TR
;
1238 dst_register_ext_concode
.CondSwizzleX
= TGSI_SWIZZLE_X
;
1239 dst_register_ext_concode
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
1240 dst_register_ext_concode
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
1241 dst_register_ext_concode
.CondSwizzleW
= TGSI_SWIZZLE_W
;
1242 dst_register_ext_concode
.CondSrcIndex
= 0;
1243 dst_register_ext_concode
.Padding
= 0;
1244 dst_register_ext_concode
.Extended
= 0;
1246 return dst_register_ext_concode
;
1250 tgsi_compare_dst_register_ext_concode(
1251 struct tgsi_dst_register_ext_concode a
,
1252 struct tgsi_dst_register_ext_concode b
)
1254 a
.Padding
= b
.Padding
= 0;
1255 a
.Extended
= b
.Extended
= 0;
1256 return compare32(&a
, &b
);
1259 struct tgsi_dst_register_ext_concode
1260 tgsi_build_dst_register_ext_concode(
1267 struct tgsi_token
*prev_token
,
1268 struct tgsi_instruction
*instruction
,
1269 struct tgsi_header
*header
)
1271 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1273 assert( cc
<= TGSI_CC_FL
);
1274 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
1275 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
1276 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
1277 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
1278 assert( index
>= -32768 && index
<= 32767 );
1280 dst_register_ext_concode
= tgsi_default_dst_register_ext_concode();
1281 dst_register_ext_concode
.CondMask
= cc
;
1282 dst_register_ext_concode
.CondSwizzleX
= swizzle_x
;
1283 dst_register_ext_concode
.CondSwizzleY
= swizzle_y
;
1284 dst_register_ext_concode
.CondSwizzleZ
= swizzle_z
;
1285 dst_register_ext_concode
.CondSwizzleW
= swizzle_w
;
1286 dst_register_ext_concode
.CondSrcIndex
= index
;
1288 prev_token
->Extended
= 1;
1289 instruction_grow( instruction
, header
);
1291 return dst_register_ext_concode
;
1294 struct tgsi_dst_register_ext_modulate
1295 tgsi_default_dst_register_ext_modulate( void )
1297 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1299 dst_register_ext_modulate
.Type
= TGSI_DST_REGISTER_EXT_TYPE_MODULATE
;
1300 dst_register_ext_modulate
.Modulate
= TGSI_MODULATE_1X
;
1301 dst_register_ext_modulate
.Padding
= 0;
1302 dst_register_ext_modulate
.Extended
= 0;
1304 return dst_register_ext_modulate
;
1308 tgsi_compare_dst_register_ext_modulate(
1309 struct tgsi_dst_register_ext_modulate a
,
1310 struct tgsi_dst_register_ext_modulate b
)
1312 a
.Padding
= b
.Padding
= 0;
1313 a
.Extended
= b
.Extended
= 0;
1314 return compare32(&a
, &b
);
1317 struct tgsi_dst_register_ext_modulate
1318 tgsi_build_dst_register_ext_modulate(
1320 struct tgsi_token
*prev_token
,
1321 struct tgsi_instruction
*instruction
,
1322 struct tgsi_header
*header
)
1324 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1326 assert( modulate
<= TGSI_MODULATE_EIGHTH
);
1328 dst_register_ext_modulate
= tgsi_default_dst_register_ext_modulate();
1329 dst_register_ext_modulate
.Modulate
= modulate
;
1331 prev_token
->Extended
= 1;
1332 instruction_grow( instruction
, header
);
1334 return dst_register_ext_modulate
;