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
.Padding
= 0;
123 declaration
.Extended
= 0;
128 struct tgsi_declaration
129 tgsi_build_declaration(
132 unsigned interpolate
,
134 struct tgsi_header
*header
)
136 struct tgsi_declaration declaration
;
138 assert( file
<= TGSI_FILE_IMMEDIATE
);
139 assert( interpolate
<= TGSI_INTERPOLATE_PERSPECTIVE
);
141 declaration
= tgsi_default_declaration();
142 declaration
.File
= file
;
143 declaration
.UsageMask
= usage_mask
;
144 declaration
.Interpolate
= interpolate
;
145 declaration
.Semantic
= semantic
;
147 header_bodysize_grow( header
);
154 struct tgsi_declaration
*declaration
,
155 struct tgsi_header
*header
)
157 assert( declaration
->Size
< 0xFF );
161 header_bodysize_grow( header
);
164 struct tgsi_full_declaration
165 tgsi_default_full_declaration( void )
167 struct tgsi_full_declaration full_declaration
;
169 full_declaration
.Declaration
= tgsi_default_declaration();
170 full_declaration
.DeclarationRange
= tgsi_default_declaration_range();
171 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
173 return full_declaration
;
177 tgsi_build_full_declaration(
178 const struct tgsi_full_declaration
*full_decl
,
179 struct tgsi_token
*tokens
,
180 struct tgsi_header
*header
,
184 struct tgsi_declaration
*declaration
;
185 struct tgsi_declaration_range
*dr
;
187 if( maxsize
<= size
)
189 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
192 *declaration
= tgsi_build_declaration(
193 full_decl
->Declaration
.File
,
194 full_decl
->Declaration
.UsageMask
,
195 full_decl
->Declaration
.Interpolate
,
196 full_decl
->Declaration
.Semantic
,
201 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
204 *dr
= tgsi_build_declaration_range(
205 full_decl
->DeclarationRange
.First
,
206 full_decl
->DeclarationRange
.Last
,
210 if( full_decl
->Declaration
.Semantic
) {
211 struct tgsi_declaration_semantic
*ds
;
213 if( maxsize
<= size
)
215 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
218 *ds
= tgsi_build_declaration_semantic(
219 full_decl
->Semantic
.SemanticName
,
220 full_decl
->Semantic
.SemanticIndex
,
228 struct tgsi_declaration_range
229 tgsi_default_declaration_range( void )
231 struct tgsi_declaration_range dr
;
239 struct tgsi_declaration_range
240 tgsi_build_declaration_range(
243 struct tgsi_declaration
*declaration
,
244 struct tgsi_header
*header
)
246 struct tgsi_declaration_range declaration_range
;
248 assert( last
>= first
);
249 assert( last
<= 0xFFFF );
251 declaration_range
= tgsi_default_declaration_range();
252 declaration_range
.First
= first
;
253 declaration_range
.Last
= last
;
255 declaration_grow( declaration
, header
);
257 return declaration_range
;
260 struct tgsi_declaration_semantic
261 tgsi_default_declaration_semantic( void )
263 struct tgsi_declaration_semantic ds
;
265 ds
.SemanticName
= TGSI_SEMANTIC_POSITION
;
266 ds
.SemanticIndex
= 0;
272 struct tgsi_declaration_semantic
273 tgsi_build_declaration_semantic(
274 unsigned semantic_name
,
275 unsigned semantic_index
,
276 struct tgsi_declaration
*declaration
,
277 struct tgsi_header
*header
)
279 struct tgsi_declaration_semantic ds
;
281 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
282 assert( semantic_index
<= 0xFFFF );
284 ds
= tgsi_default_declaration_semantic();
285 ds
.SemanticName
= semantic_name
;
286 ds
.SemanticIndex
= semantic_index
;
288 declaration_grow( declaration
, header
);
297 struct tgsi_immediate
298 tgsi_default_immediate( void )
300 struct tgsi_immediate immediate
;
302 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
304 immediate
.DataType
= TGSI_IMM_FLOAT32
;
305 immediate
.Padding
= 0;
306 immediate
.Extended
= 0;
311 struct tgsi_immediate
312 tgsi_build_immediate(
313 struct tgsi_header
*header
)
315 struct tgsi_immediate immediate
;
317 immediate
= tgsi_default_immediate();
319 header_bodysize_grow( header
);
324 struct tgsi_full_immediate
325 tgsi_default_full_immediate( void )
327 struct tgsi_full_immediate fullimm
;
329 fullimm
.Immediate
= tgsi_default_immediate();
330 fullimm
.u
.Pointer
= (void *) 0;
337 struct tgsi_immediate
*immediate
,
338 struct tgsi_header
*header
)
340 assert( immediate
->Size
< 0xFF );
344 header_bodysize_grow( header
);
347 struct tgsi_immediate_float32
348 tgsi_build_immediate_float32(
350 struct tgsi_immediate
*immediate
,
351 struct tgsi_header
*header
)
353 struct tgsi_immediate_float32 immediate_float32
;
355 immediate_float32
.Float
= value
;
357 immediate_grow( immediate
, header
);
359 return immediate_float32
;
363 tgsi_build_full_immediate(
364 const struct tgsi_full_immediate
*full_imm
,
365 struct tgsi_token
*tokens
,
366 struct tgsi_header
*header
,
369 unsigned size
= 0, i
;
370 struct tgsi_immediate
*immediate
;
372 if( maxsize
<= size
)
374 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
377 *immediate
= tgsi_build_immediate( header
);
379 for( i
= 0; i
< full_imm
->Immediate
.Size
- 1; i
++ ) {
380 struct tgsi_immediate_float32
*if32
;
382 if( maxsize
<= size
)
384 if32
= (struct tgsi_immediate_float32
*) &tokens
[size
];
387 *if32
= tgsi_build_immediate_float32(
388 full_imm
->u
.ImmediateFloat32
[i
].Float
,
400 struct tgsi_instruction
401 tgsi_default_instruction( void )
403 struct tgsi_instruction instruction
;
405 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
406 instruction
.Size
= 1;
407 instruction
.Opcode
= TGSI_OPCODE_MOV
;
408 instruction
.Saturate
= TGSI_SAT_NONE
;
409 instruction
.NumDstRegs
= 1;
410 instruction
.NumSrcRegs
= 1;
411 instruction
.Padding
= 0;
412 instruction
.Extended
= 0;
417 struct tgsi_instruction
418 tgsi_build_instruction(
421 unsigned num_dst_regs
,
422 unsigned num_src_regs
,
423 struct tgsi_header
*header
)
425 struct tgsi_instruction instruction
;
427 assert (opcode
<= TGSI_OPCODE_LAST
);
428 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
429 assert (num_dst_regs
<= 3);
430 assert (num_src_regs
<= 15);
432 instruction
= tgsi_default_instruction();
433 instruction
.Opcode
= opcode
;
434 instruction
.Saturate
= saturate
;
435 instruction
.NumDstRegs
= num_dst_regs
;
436 instruction
.NumSrcRegs
= num_src_regs
;
438 header_bodysize_grow( header
);
445 struct tgsi_instruction
*instruction
,
446 struct tgsi_header
*header
)
448 assert (instruction
->Size
< 0xFF);
452 header_bodysize_grow( header
);
455 struct tgsi_full_instruction
456 tgsi_default_full_instruction( void )
458 struct tgsi_full_instruction full_instruction
;
461 full_instruction
.Instruction
= tgsi_default_instruction();
462 full_instruction
.InstructionExtNv
= tgsi_default_instruction_ext_nv();
463 full_instruction
.InstructionExtLabel
= tgsi_default_instruction_ext_label();
464 full_instruction
.InstructionExtTexture
= tgsi_default_instruction_ext_texture();
465 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
466 full_instruction
.FullDstRegisters
[i
] = tgsi_default_full_dst_register();
468 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
469 full_instruction
.FullSrcRegisters
[i
] = tgsi_default_full_src_register();
472 return full_instruction
;
476 tgsi_build_full_instruction(
477 const struct tgsi_full_instruction
*full_inst
,
478 struct tgsi_token
*tokens
,
479 struct tgsi_header
*header
,
484 struct tgsi_instruction
*instruction
;
485 struct tgsi_token
*prev_token
;
487 if( maxsize
<= size
)
489 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
492 *instruction
= tgsi_build_instruction(
493 full_inst
->Instruction
.Opcode
,
494 full_inst
->Instruction
.Saturate
,
495 full_inst
->Instruction
.NumDstRegs
,
496 full_inst
->Instruction
.NumSrcRegs
,
498 prev_token
= (struct tgsi_token
*) instruction
;
500 if( tgsi_compare_instruction_ext_nv(
501 full_inst
->InstructionExtNv
,
502 tgsi_default_instruction_ext_nv() ) ) {
503 struct tgsi_instruction_ext_nv
*instruction_ext_nv
;
505 if( maxsize
<= size
)
508 (struct tgsi_instruction_ext_nv
*) &tokens
[size
];
511 *instruction_ext_nv
= tgsi_build_instruction_ext_nv(
512 full_inst
->InstructionExtNv
.Precision
,
513 full_inst
->InstructionExtNv
.CondDstIndex
,
514 full_inst
->InstructionExtNv
.CondFlowIndex
,
515 full_inst
->InstructionExtNv
.CondMask
,
516 full_inst
->InstructionExtNv
.CondSwizzleX
,
517 full_inst
->InstructionExtNv
.CondSwizzleY
,
518 full_inst
->InstructionExtNv
.CondSwizzleZ
,
519 full_inst
->InstructionExtNv
.CondSwizzleW
,
520 full_inst
->InstructionExtNv
.CondDstUpdate
,
521 full_inst
->InstructionExtNv
.CondFlowEnable
,
525 prev_token
= (struct tgsi_token
*) instruction_ext_nv
;
528 if( tgsi_compare_instruction_ext_label(
529 full_inst
->InstructionExtLabel
,
530 tgsi_default_instruction_ext_label() ) ) {
531 struct tgsi_instruction_ext_label
*instruction_ext_label
;
533 if( maxsize
<= size
)
535 instruction_ext_label
=
536 (struct tgsi_instruction_ext_label
*) &tokens
[size
];
539 *instruction_ext_label
= tgsi_build_instruction_ext_label(
540 full_inst
->InstructionExtLabel
.Label
,
544 prev_token
= (struct tgsi_token
*) instruction_ext_label
;
547 if( tgsi_compare_instruction_ext_texture(
548 full_inst
->InstructionExtTexture
,
549 tgsi_default_instruction_ext_texture() ) ) {
550 struct tgsi_instruction_ext_texture
*instruction_ext_texture
;
552 if( maxsize
<= size
)
554 instruction_ext_texture
=
555 (struct tgsi_instruction_ext_texture
*) &tokens
[size
];
558 *instruction_ext_texture
= tgsi_build_instruction_ext_texture(
559 full_inst
->InstructionExtTexture
.Texture
,
563 prev_token
= (struct tgsi_token
*) instruction_ext_texture
;
566 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
567 const struct tgsi_full_dst_register
*reg
= &full_inst
->FullDstRegisters
[i
];
568 struct tgsi_dst_register
*dst_register
;
569 struct tgsi_token
*prev_token
;
571 if( maxsize
<= size
)
573 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
576 *dst_register
= tgsi_build_dst_register(
577 reg
->DstRegister
.File
,
578 reg
->DstRegister
.WriteMask
,
579 reg
->DstRegister
.Index
,
582 prev_token
= (struct tgsi_token
*) dst_register
;
584 if( tgsi_compare_dst_register_ext_concode(
585 reg
->DstRegisterExtConcode
,
586 tgsi_default_dst_register_ext_concode() ) ) {
587 struct tgsi_dst_register_ext_concode
*dst_register_ext_concode
;
589 if( maxsize
<= size
)
591 dst_register_ext_concode
=
592 (struct tgsi_dst_register_ext_concode
*) &tokens
[size
];
595 *dst_register_ext_concode
= tgsi_build_dst_register_ext_concode(
596 reg
->DstRegisterExtConcode
.CondMask
,
597 reg
->DstRegisterExtConcode
.CondSwizzleX
,
598 reg
->DstRegisterExtConcode
.CondSwizzleY
,
599 reg
->DstRegisterExtConcode
.CondSwizzleZ
,
600 reg
->DstRegisterExtConcode
.CondSwizzleW
,
601 reg
->DstRegisterExtConcode
.CondSrcIndex
,
605 prev_token
= (struct tgsi_token
*) dst_register_ext_concode
;
608 if( tgsi_compare_dst_register_ext_modulate(
609 reg
->DstRegisterExtModulate
,
610 tgsi_default_dst_register_ext_modulate() ) ) {
611 struct tgsi_dst_register_ext_modulate
*dst_register_ext_modulate
;
613 if( maxsize
<= size
)
615 dst_register_ext_modulate
=
616 (struct tgsi_dst_register_ext_modulate
*) &tokens
[size
];
619 *dst_register_ext_modulate
= tgsi_build_dst_register_ext_modulate(
620 reg
->DstRegisterExtModulate
.Modulate
,
624 prev_token
= (struct tgsi_token
*) dst_register_ext_modulate
;
628 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
629 const struct tgsi_full_src_register
*reg
= &full_inst
->FullSrcRegisters
[i
];
630 struct tgsi_src_register
*src_register
;
631 struct tgsi_token
*prev_token
;
633 if( maxsize
<= size
)
635 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
638 *src_register
= tgsi_build_src_register(
639 reg
->SrcRegister
.File
,
640 reg
->SrcRegister
.SwizzleX
,
641 reg
->SrcRegister
.SwizzleY
,
642 reg
->SrcRegister
.SwizzleZ
,
643 reg
->SrcRegister
.SwizzleW
,
644 reg
->SrcRegister
.Negate
,
645 reg
->SrcRegister
.Indirect
,
646 reg
->SrcRegister
.Dimension
,
647 reg
->SrcRegister
.Index
,
650 prev_token
= (struct tgsi_token
*) src_register
;
652 if( tgsi_compare_src_register_ext_swz(
653 reg
->SrcRegisterExtSwz
,
654 tgsi_default_src_register_ext_swz() ) ) {
655 struct tgsi_src_register_ext_swz
*src_register_ext_swz
;
657 /* Use of the extended swizzle requires the simple swizzle to be identity.
659 assert( reg
->SrcRegister
.SwizzleX
== TGSI_SWIZZLE_X
);
660 assert( reg
->SrcRegister
.SwizzleY
== TGSI_SWIZZLE_Y
);
661 assert( reg
->SrcRegister
.SwizzleZ
== TGSI_SWIZZLE_Z
);
662 assert( reg
->SrcRegister
.SwizzleW
== TGSI_SWIZZLE_W
);
663 assert( reg
->SrcRegister
.Negate
== FALSE
);
665 if( maxsize
<= size
)
667 src_register_ext_swz
=
668 (struct tgsi_src_register_ext_swz
*) &tokens
[size
];
671 *src_register_ext_swz
= tgsi_build_src_register_ext_swz(
672 reg
->SrcRegisterExtSwz
.ExtSwizzleX
,
673 reg
->SrcRegisterExtSwz
.ExtSwizzleY
,
674 reg
->SrcRegisterExtSwz
.ExtSwizzleZ
,
675 reg
->SrcRegisterExtSwz
.ExtSwizzleW
,
676 reg
->SrcRegisterExtSwz
.NegateX
,
677 reg
->SrcRegisterExtSwz
.NegateY
,
678 reg
->SrcRegisterExtSwz
.NegateZ
,
679 reg
->SrcRegisterExtSwz
.NegateW
,
683 prev_token
= (struct tgsi_token
*) src_register_ext_swz
;
686 if( tgsi_compare_src_register_ext_mod(
687 reg
->SrcRegisterExtMod
,
688 tgsi_default_src_register_ext_mod() ) ) {
689 struct tgsi_src_register_ext_mod
*src_register_ext_mod
;
691 if( maxsize
<= size
)
693 src_register_ext_mod
=
694 (struct tgsi_src_register_ext_mod
*) &tokens
[size
];
697 *src_register_ext_mod
= tgsi_build_src_register_ext_mod(
698 reg
->SrcRegisterExtMod
.Complement
,
699 reg
->SrcRegisterExtMod
.Bias
,
700 reg
->SrcRegisterExtMod
.Scale2X
,
701 reg
->SrcRegisterExtMod
.Absolute
,
702 reg
->SrcRegisterExtMod
.Negate
,
706 prev_token
= (struct tgsi_token
*) src_register_ext_mod
;
709 if( reg
->SrcRegister
.Indirect
) {
710 struct tgsi_src_register
*ind
;
712 if( maxsize
<= size
)
714 ind
= (struct tgsi_src_register
*) &tokens
[size
];
717 *ind
= tgsi_build_src_register(
718 reg
->SrcRegisterInd
.File
,
719 reg
->SrcRegisterInd
.SwizzleX
,
720 reg
->SrcRegisterInd
.SwizzleY
,
721 reg
->SrcRegisterInd
.SwizzleZ
,
722 reg
->SrcRegisterInd
.SwizzleW
,
723 reg
->SrcRegisterInd
.Negate
,
724 reg
->SrcRegisterInd
.Indirect
,
725 reg
->SrcRegisterInd
.Dimension
,
726 reg
->SrcRegisterInd
.Index
,
731 if( reg
->SrcRegister
.Dimension
) {
732 struct tgsi_dimension
*dim
;
734 assert( !reg
->SrcRegisterDim
.Dimension
);
736 if( maxsize
<= size
)
738 dim
= (struct tgsi_dimension
*) &tokens
[size
];
741 *dim
= tgsi_build_dimension(
742 reg
->SrcRegisterDim
.Indirect
,
743 reg
->SrcRegisterDim
.Index
,
747 if( reg
->SrcRegisterDim
.Indirect
) {
748 struct tgsi_src_register
*ind
;
750 if( maxsize
<= size
)
752 ind
= (struct tgsi_src_register
*) &tokens
[size
];
755 *ind
= tgsi_build_src_register(
756 reg
->SrcRegisterDimInd
.File
,
757 reg
->SrcRegisterDimInd
.SwizzleX
,
758 reg
->SrcRegisterDimInd
.SwizzleY
,
759 reg
->SrcRegisterDimInd
.SwizzleZ
,
760 reg
->SrcRegisterDimInd
.SwizzleW
,
761 reg
->SrcRegisterDimInd
.Negate
,
762 reg
->SrcRegisterDimInd
.Indirect
,
763 reg
->SrcRegisterDimInd
.Dimension
,
764 reg
->SrcRegisterDimInd
.Index
,
774 struct tgsi_instruction_ext_nv
775 tgsi_default_instruction_ext_nv( void )
777 struct tgsi_instruction_ext_nv instruction_ext_nv
;
779 instruction_ext_nv
.Type
= TGSI_INSTRUCTION_EXT_TYPE_NV
;
780 instruction_ext_nv
.Precision
= TGSI_PRECISION_DEFAULT
;
781 instruction_ext_nv
.CondDstIndex
= 0;
782 instruction_ext_nv
.CondFlowIndex
= 0;
783 instruction_ext_nv
.CondMask
= TGSI_CC_TR
;
784 instruction_ext_nv
.CondSwizzleX
= TGSI_SWIZZLE_X
;
785 instruction_ext_nv
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
786 instruction_ext_nv
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
787 instruction_ext_nv
.CondSwizzleW
= TGSI_SWIZZLE_W
;
788 instruction_ext_nv
.CondDstUpdate
= 0;
789 instruction_ext_nv
.CondFlowEnable
= 0;
790 instruction_ext_nv
.Padding
= 0;
791 instruction_ext_nv
.Extended
= 0;
793 return instruction_ext_nv
;
797 /** test for inequality of 32-bit values pointed to by a and b */
798 static INLINE boolean
799 compare32(const void *a
, const void *b
)
801 return *((uint32_t *) a
) != *((uint32_t *) b
);
806 tgsi_compare_instruction_ext_nv(
807 struct tgsi_instruction_ext_nv a
,
808 struct tgsi_instruction_ext_nv b
)
810 a
.Padding
= b
.Padding
= 0;
811 a
.Extended
= b
.Extended
= 0;
812 return compare32(&a
, &b
);
815 struct tgsi_instruction_ext_nv
816 tgsi_build_instruction_ext_nv(
818 unsigned cond_dst_index
,
819 unsigned cond_flow_index
,
821 unsigned cond_swizzle_x
,
822 unsigned cond_swizzle_y
,
823 unsigned cond_swizzle_z
,
824 unsigned cond_swizzle_w
,
825 unsigned cond_dst_update
,
826 unsigned cond_flow_enable
,
827 struct tgsi_token
*prev_token
,
828 struct tgsi_instruction
*instruction
,
829 struct tgsi_header
*header
)
831 struct tgsi_instruction_ext_nv instruction_ext_nv
;
833 instruction_ext_nv
= tgsi_default_instruction_ext_nv();
834 instruction_ext_nv
.Precision
= precision
;
835 instruction_ext_nv
.CondDstIndex
= cond_dst_index
;
836 instruction_ext_nv
.CondFlowIndex
= cond_flow_index
;
837 instruction_ext_nv
.CondMask
= cond_mask
;
838 instruction_ext_nv
.CondSwizzleX
= cond_swizzle_x
;
839 instruction_ext_nv
.CondSwizzleY
= cond_swizzle_y
;
840 instruction_ext_nv
.CondSwizzleZ
= cond_swizzle_z
;
841 instruction_ext_nv
.CondSwizzleW
= cond_swizzle_w
;
842 instruction_ext_nv
.CondDstUpdate
= cond_dst_update
;
843 instruction_ext_nv
.CondFlowEnable
= cond_flow_enable
;
845 prev_token
->Extended
= 1;
846 instruction_grow( instruction
, header
);
848 return instruction_ext_nv
;
851 struct tgsi_instruction_ext_label
852 tgsi_default_instruction_ext_label( void )
854 struct tgsi_instruction_ext_label instruction_ext_label
;
856 instruction_ext_label
.Type
= TGSI_INSTRUCTION_EXT_TYPE_LABEL
;
857 instruction_ext_label
.Label
= 0;
858 instruction_ext_label
.Padding
= 0;
859 instruction_ext_label
.Extended
= 0;
861 return instruction_ext_label
;
865 tgsi_compare_instruction_ext_label(
866 struct tgsi_instruction_ext_label a
,
867 struct tgsi_instruction_ext_label b
)
869 a
.Padding
= b
.Padding
= 0;
870 a
.Extended
= b
.Extended
= 0;
871 return compare32(&a
, &b
);
874 struct tgsi_instruction_ext_label
875 tgsi_build_instruction_ext_label(
877 struct tgsi_token
*prev_token
,
878 struct tgsi_instruction
*instruction
,
879 struct tgsi_header
*header
)
881 struct tgsi_instruction_ext_label instruction_ext_label
;
883 instruction_ext_label
= tgsi_default_instruction_ext_label();
884 instruction_ext_label
.Label
= label
;
886 prev_token
->Extended
= 1;
887 instruction_grow( instruction
, header
);
889 return instruction_ext_label
;
892 struct tgsi_instruction_ext_texture
893 tgsi_default_instruction_ext_texture( void )
895 struct tgsi_instruction_ext_texture instruction_ext_texture
;
897 instruction_ext_texture
.Type
= TGSI_INSTRUCTION_EXT_TYPE_TEXTURE
;
898 instruction_ext_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
899 instruction_ext_texture
.Padding
= 0;
900 instruction_ext_texture
.Extended
= 0;
902 return instruction_ext_texture
;
906 tgsi_compare_instruction_ext_texture(
907 struct tgsi_instruction_ext_texture a
,
908 struct tgsi_instruction_ext_texture b
)
910 a
.Padding
= b
.Padding
= 0;
911 a
.Extended
= b
.Extended
= 0;
912 return compare32(&a
, &b
);
915 struct tgsi_instruction_ext_texture
916 tgsi_build_instruction_ext_texture(
918 struct tgsi_token
*prev_token
,
919 struct tgsi_instruction
*instruction
,
920 struct tgsi_header
*header
)
922 struct tgsi_instruction_ext_texture instruction_ext_texture
;
924 instruction_ext_texture
= tgsi_default_instruction_ext_texture();
925 instruction_ext_texture
.Texture
= texture
;
927 prev_token
->Extended
= 1;
928 instruction_grow( instruction
, header
);
930 return instruction_ext_texture
;
933 struct tgsi_src_register
934 tgsi_default_src_register( void )
936 struct tgsi_src_register src_register
;
938 src_register
.File
= TGSI_FILE_NULL
;
939 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
940 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
941 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
942 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
943 src_register
.Negate
= 0;
944 src_register
.Indirect
= 0;
945 src_register
.Dimension
= 0;
946 src_register
.Index
= 0;
947 src_register
.Extended
= 0;
952 struct tgsi_src_register
953 tgsi_build_src_register(
963 struct tgsi_instruction
*instruction
,
964 struct tgsi_header
*header
)
966 struct tgsi_src_register src_register
;
968 assert( file
<= TGSI_FILE_IMMEDIATE
);
969 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
970 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
971 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
972 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
973 assert( negate
<= 1 );
974 assert( index
>= -0x8000 && index
<= 0x7FFF );
976 src_register
= tgsi_default_src_register();
977 src_register
.File
= file
;
978 src_register
.SwizzleX
= swizzle_x
;
979 src_register
.SwizzleY
= swizzle_y
;
980 src_register
.SwizzleZ
= swizzle_z
;
981 src_register
.SwizzleW
= swizzle_w
;
982 src_register
.Negate
= negate
;
983 src_register
.Indirect
= indirect
;
984 src_register
.Dimension
= dimension
;
985 src_register
.Index
= index
;
987 instruction_grow( instruction
, header
);
992 struct tgsi_full_src_register
993 tgsi_default_full_src_register( void )
995 struct tgsi_full_src_register full_src_register
;
997 full_src_register
.SrcRegister
= tgsi_default_src_register();
998 full_src_register
.SrcRegisterExtSwz
= tgsi_default_src_register_ext_swz();
999 full_src_register
.SrcRegisterExtMod
= tgsi_default_src_register_ext_mod();
1000 full_src_register
.SrcRegisterInd
= tgsi_default_src_register();
1001 full_src_register
.SrcRegisterDim
= tgsi_default_dimension();
1002 full_src_register
.SrcRegisterDimInd
= tgsi_default_src_register();
1004 return full_src_register
;
1007 struct tgsi_src_register_ext_swz
1008 tgsi_default_src_register_ext_swz( void )
1010 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1012 src_register_ext_swz
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_SWZ
;
1013 src_register_ext_swz
.ExtSwizzleX
= TGSI_EXTSWIZZLE_X
;
1014 src_register_ext_swz
.ExtSwizzleY
= TGSI_EXTSWIZZLE_Y
;
1015 src_register_ext_swz
.ExtSwizzleZ
= TGSI_EXTSWIZZLE_Z
;
1016 src_register_ext_swz
.ExtSwizzleW
= TGSI_EXTSWIZZLE_W
;
1017 src_register_ext_swz
.NegateX
= 0;
1018 src_register_ext_swz
.NegateY
= 0;
1019 src_register_ext_swz
.NegateZ
= 0;
1020 src_register_ext_swz
.NegateW
= 0;
1021 src_register_ext_swz
.Padding
= 0;
1022 src_register_ext_swz
.Extended
= 0;
1024 return src_register_ext_swz
;
1028 tgsi_compare_src_register_ext_swz(
1029 struct tgsi_src_register_ext_swz a
,
1030 struct tgsi_src_register_ext_swz b
)
1032 a
.Padding
= b
.Padding
= 0;
1033 a
.Extended
= b
.Extended
= 0;
1034 return compare32(&a
, &b
);
1037 struct tgsi_src_register_ext_swz
1038 tgsi_build_src_register_ext_swz(
1039 unsigned ext_swizzle_x
,
1040 unsigned ext_swizzle_y
,
1041 unsigned ext_swizzle_z
,
1042 unsigned ext_swizzle_w
,
1047 struct tgsi_token
*prev_token
,
1048 struct tgsi_instruction
*instruction
,
1049 struct tgsi_header
*header
)
1051 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1053 assert( ext_swizzle_x
<= TGSI_EXTSWIZZLE_ONE
);
1054 assert( ext_swizzle_y
<= TGSI_EXTSWIZZLE_ONE
);
1055 assert( ext_swizzle_z
<= TGSI_EXTSWIZZLE_ONE
);
1056 assert( ext_swizzle_w
<= TGSI_EXTSWIZZLE_ONE
);
1057 assert( negate_x
<= 1 );
1058 assert( negate_y
<= 1 );
1059 assert( negate_z
<= 1 );
1060 assert( negate_w
<= 1 );
1062 src_register_ext_swz
= tgsi_default_src_register_ext_swz();
1063 src_register_ext_swz
.ExtSwizzleX
= ext_swizzle_x
;
1064 src_register_ext_swz
.ExtSwizzleY
= ext_swizzle_y
;
1065 src_register_ext_swz
.ExtSwizzleZ
= ext_swizzle_z
;
1066 src_register_ext_swz
.ExtSwizzleW
= ext_swizzle_w
;
1067 src_register_ext_swz
.NegateX
= negate_x
;
1068 src_register_ext_swz
.NegateY
= negate_y
;
1069 src_register_ext_swz
.NegateZ
= negate_z
;
1070 src_register_ext_swz
.NegateW
= negate_w
;
1072 prev_token
->Extended
= 1;
1073 instruction_grow( instruction
, header
);
1075 return src_register_ext_swz
;
1078 struct tgsi_src_register_ext_mod
1079 tgsi_default_src_register_ext_mod( void )
1081 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1083 src_register_ext_mod
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_MOD
;
1084 src_register_ext_mod
.Complement
= 0;
1085 src_register_ext_mod
.Bias
= 0;
1086 src_register_ext_mod
.Scale2X
= 0;
1087 src_register_ext_mod
.Absolute
= 0;
1088 src_register_ext_mod
.Negate
= 0;
1089 src_register_ext_mod
.Padding
= 0;
1090 src_register_ext_mod
.Extended
= 0;
1092 return src_register_ext_mod
;
1096 tgsi_compare_src_register_ext_mod(
1097 struct tgsi_src_register_ext_mod a
,
1098 struct tgsi_src_register_ext_mod b
)
1100 a
.Padding
= b
.Padding
= 0;
1101 a
.Extended
= b
.Extended
= 0;
1102 return compare32(&a
, &b
);
1105 struct tgsi_src_register_ext_mod
1106 tgsi_build_src_register_ext_mod(
1107 unsigned complement
,
1112 struct tgsi_token
*prev_token
,
1113 struct tgsi_instruction
*instruction
,
1114 struct tgsi_header
*header
)
1116 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1118 assert( complement
<= 1 );
1119 assert( bias
<= 1 );
1120 assert( scale_2x
<= 1 );
1121 assert( absolute
<= 1 );
1122 assert( negate
<= 1 );
1124 src_register_ext_mod
= tgsi_default_src_register_ext_mod();
1125 src_register_ext_mod
.Complement
= complement
;
1126 src_register_ext_mod
.Bias
= bias
;
1127 src_register_ext_mod
.Scale2X
= scale_2x
;
1128 src_register_ext_mod
.Absolute
= absolute
;
1129 src_register_ext_mod
.Negate
= negate
;
1131 prev_token
->Extended
= 1;
1132 instruction_grow( instruction
, header
);
1134 return src_register_ext_mod
;
1137 struct tgsi_dimension
1138 tgsi_default_dimension( void )
1140 struct tgsi_dimension dimension
;
1142 dimension
.Indirect
= 0;
1143 dimension
.Dimension
= 0;
1144 dimension
.Padding
= 0;
1145 dimension
.Index
= 0;
1146 dimension
.Extended
= 0;
1151 struct tgsi_dimension
1152 tgsi_build_dimension(
1155 struct tgsi_instruction
*instruction
,
1156 struct tgsi_header
*header
)
1158 struct tgsi_dimension dimension
;
1160 dimension
= tgsi_default_dimension();
1161 dimension
.Indirect
= indirect
;
1162 dimension
.Index
= index
;
1164 instruction_grow( instruction
, header
);
1169 struct tgsi_dst_register
1170 tgsi_default_dst_register( void )
1172 struct tgsi_dst_register dst_register
;
1174 dst_register
.File
= TGSI_FILE_NULL
;
1175 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1176 dst_register
.Indirect
= 0;
1177 dst_register
.Dimension
= 0;
1178 dst_register
.Index
= 0;
1179 dst_register
.Padding
= 0;
1180 dst_register
.Extended
= 0;
1182 return dst_register
;
1185 struct tgsi_dst_register
1186 tgsi_build_dst_register(
1190 struct tgsi_instruction
*instruction
,
1191 struct tgsi_header
*header
)
1193 struct tgsi_dst_register dst_register
;
1195 assert( file
<= TGSI_FILE_IMMEDIATE
);
1196 assert( mask
<= TGSI_WRITEMASK_XYZW
);
1197 assert( index
>= -32768 && index
<= 32767 );
1199 dst_register
= tgsi_default_dst_register();
1200 dst_register
.File
= file
;
1201 dst_register
.WriteMask
= mask
;
1202 dst_register
.Index
= index
;
1204 instruction_grow( instruction
, header
);
1206 return dst_register
;
1209 struct tgsi_full_dst_register
1210 tgsi_default_full_dst_register( void )
1212 struct tgsi_full_dst_register full_dst_register
;
1214 full_dst_register
.DstRegister
= tgsi_default_dst_register();
1215 full_dst_register
.DstRegisterExtConcode
=
1216 tgsi_default_dst_register_ext_concode();
1217 full_dst_register
.DstRegisterExtModulate
=
1218 tgsi_default_dst_register_ext_modulate();
1220 return full_dst_register
;
1223 struct tgsi_dst_register_ext_concode
1224 tgsi_default_dst_register_ext_concode( void )
1226 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1228 dst_register_ext_concode
.Type
= TGSI_DST_REGISTER_EXT_TYPE_CONDCODE
;
1229 dst_register_ext_concode
.CondMask
= TGSI_CC_TR
;
1230 dst_register_ext_concode
.CondSwizzleX
= TGSI_SWIZZLE_X
;
1231 dst_register_ext_concode
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
1232 dst_register_ext_concode
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
1233 dst_register_ext_concode
.CondSwizzleW
= TGSI_SWIZZLE_W
;
1234 dst_register_ext_concode
.CondSrcIndex
= 0;
1235 dst_register_ext_concode
.Padding
= 0;
1236 dst_register_ext_concode
.Extended
= 0;
1238 return dst_register_ext_concode
;
1242 tgsi_compare_dst_register_ext_concode(
1243 struct tgsi_dst_register_ext_concode a
,
1244 struct tgsi_dst_register_ext_concode b
)
1246 a
.Padding
= b
.Padding
= 0;
1247 a
.Extended
= b
.Extended
= 0;
1248 return compare32(&a
, &b
);
1251 struct tgsi_dst_register_ext_concode
1252 tgsi_build_dst_register_ext_concode(
1259 struct tgsi_token
*prev_token
,
1260 struct tgsi_instruction
*instruction
,
1261 struct tgsi_header
*header
)
1263 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1265 assert( cc
<= TGSI_CC_FL
);
1266 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
1267 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
1268 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
1269 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
1270 assert( index
>= -32768 && index
<= 32767 );
1272 dst_register_ext_concode
= tgsi_default_dst_register_ext_concode();
1273 dst_register_ext_concode
.CondMask
= cc
;
1274 dst_register_ext_concode
.CondSwizzleX
= swizzle_x
;
1275 dst_register_ext_concode
.CondSwizzleY
= swizzle_y
;
1276 dst_register_ext_concode
.CondSwizzleZ
= swizzle_z
;
1277 dst_register_ext_concode
.CondSwizzleW
= swizzle_w
;
1278 dst_register_ext_concode
.CondSrcIndex
= index
;
1280 prev_token
->Extended
= 1;
1281 instruction_grow( instruction
, header
);
1283 return dst_register_ext_concode
;
1286 struct tgsi_dst_register_ext_modulate
1287 tgsi_default_dst_register_ext_modulate( void )
1289 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1291 dst_register_ext_modulate
.Type
= TGSI_DST_REGISTER_EXT_TYPE_MODULATE
;
1292 dst_register_ext_modulate
.Modulate
= TGSI_MODULATE_1X
;
1293 dst_register_ext_modulate
.Padding
= 0;
1294 dst_register_ext_modulate
.Extended
= 0;
1296 return dst_register_ext_modulate
;
1300 tgsi_compare_dst_register_ext_modulate(
1301 struct tgsi_dst_register_ext_modulate a
,
1302 struct tgsi_dst_register_ext_modulate b
)
1304 a
.Padding
= b
.Padding
= 0;
1305 a
.Extended
= b
.Extended
= 0;
1306 return compare32(&a
, &b
);
1309 struct tgsi_dst_register_ext_modulate
1310 tgsi_build_dst_register_ext_modulate(
1312 struct tgsi_token
*prev_token
,
1313 struct tgsi_instruction
*instruction
,
1314 struct tgsi_header
*header
)
1316 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1318 assert( modulate
<= TGSI_MODULATE_EIGHTH
);
1320 dst_register_ext_modulate
= tgsi_default_dst_register_ext_modulate();
1321 dst_register_ext_modulate
.Modulate
= modulate
;
1323 prev_token
->Extended
= 1;
1324 instruction_grow( instruction
, header
);
1326 return dst_register_ext_modulate
;