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
,
136 struct tgsi_header
*header
)
138 struct tgsi_declaration declaration
;
140 assert( file
<= TGSI_FILE_IMMEDIATE
);
141 assert( interpolate
<= TGSI_INTERPOLATE_PERSPECTIVE
);
143 declaration
= tgsi_default_declaration();
144 declaration
.File
= file
;
145 declaration
.UsageMask
= usage_mask
;
146 declaration
.Interpolate
= interpolate
;
147 declaration
.Semantic
= semantic
;
149 header_bodysize_grow( header
);
156 struct tgsi_declaration
*declaration
,
157 struct tgsi_header
*header
)
159 assert( declaration
->Size
< 0xFF );
163 header_bodysize_grow( header
);
166 struct tgsi_full_declaration
167 tgsi_default_full_declaration( void )
169 struct tgsi_full_declaration full_declaration
;
171 full_declaration
.Declaration
= tgsi_default_declaration();
172 full_declaration
.DeclarationRange
= tgsi_default_declaration_range();
173 full_declaration
.Semantic
= tgsi_default_declaration_semantic();
175 return full_declaration
;
179 tgsi_build_full_declaration(
180 const struct tgsi_full_declaration
*full_decl
,
181 struct tgsi_token
*tokens
,
182 struct tgsi_header
*header
,
186 struct tgsi_declaration
*declaration
;
187 struct tgsi_declaration_range
*dr
;
189 if( maxsize
<= size
)
191 declaration
= (struct tgsi_declaration
*) &tokens
[size
];
194 *declaration
= tgsi_build_declaration(
195 full_decl
->Declaration
.File
,
196 full_decl
->Declaration
.UsageMask
,
197 full_decl
->Declaration
.Interpolate
,
198 full_decl
->Declaration
.Semantic
,
203 dr
= (struct tgsi_declaration_range
*) &tokens
[size
];
206 *dr
= tgsi_build_declaration_range(
207 full_decl
->DeclarationRange
.First
,
208 full_decl
->DeclarationRange
.Last
,
212 if( full_decl
->Declaration
.Semantic
) {
213 struct tgsi_declaration_semantic
*ds
;
215 if( maxsize
<= size
)
217 ds
= (struct tgsi_declaration_semantic
*) &tokens
[size
];
220 *ds
= tgsi_build_declaration_semantic(
221 full_decl
->Semantic
.SemanticName
,
222 full_decl
->Semantic
.SemanticIndex
,
230 struct tgsi_declaration_range
231 tgsi_default_declaration_range( void )
233 struct tgsi_declaration_range dr
;
241 struct tgsi_declaration_range
242 tgsi_build_declaration_range(
245 struct tgsi_declaration
*declaration
,
246 struct tgsi_header
*header
)
248 struct tgsi_declaration_range declaration_range
;
250 assert( last
>= first
);
251 assert( last
<= 0xFFFF );
253 declaration_range
= tgsi_default_declaration_range();
254 declaration_range
.First
= first
;
255 declaration_range
.Last
= last
;
257 declaration_grow( declaration
, header
);
259 return declaration_range
;
262 struct tgsi_declaration_semantic
263 tgsi_default_declaration_semantic( void )
265 struct tgsi_declaration_semantic ds
;
267 ds
.SemanticName
= TGSI_SEMANTIC_POSITION
;
268 ds
.SemanticIndex
= 0;
274 struct tgsi_declaration_semantic
275 tgsi_build_declaration_semantic(
276 unsigned semantic_name
,
277 unsigned semantic_index
,
278 struct tgsi_declaration
*declaration
,
279 struct tgsi_header
*header
)
281 struct tgsi_declaration_semantic ds
;
283 assert( semantic_name
<= TGSI_SEMANTIC_COUNT
);
284 assert( semantic_index
<= 0xFFFF );
286 ds
= tgsi_default_declaration_semantic();
287 ds
.SemanticName
= semantic_name
;
288 ds
.SemanticIndex
= semantic_index
;
290 declaration_grow( declaration
, header
);
299 struct tgsi_immediate
300 tgsi_default_immediate( void )
302 struct tgsi_immediate immediate
;
304 immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
306 immediate
.DataType
= TGSI_IMM_FLOAT32
;
307 immediate
.Padding
= 0;
308 immediate
.Extended
= 0;
313 struct tgsi_immediate
314 tgsi_build_immediate(
315 struct tgsi_header
*header
)
317 struct tgsi_immediate immediate
;
319 immediate
= tgsi_default_immediate();
321 header_bodysize_grow( header
);
326 struct tgsi_full_immediate
327 tgsi_default_full_immediate( void )
329 struct tgsi_full_immediate fullimm
;
331 fullimm
.Immediate
= tgsi_default_immediate();
332 fullimm
.u
.Pointer
= (void *) 0;
339 struct tgsi_immediate
*immediate
,
340 struct tgsi_header
*header
)
342 assert( immediate
->Size
< 0xFF );
346 header_bodysize_grow( header
);
349 struct tgsi_immediate_float32
350 tgsi_build_immediate_float32(
352 struct tgsi_immediate
*immediate
,
353 struct tgsi_header
*header
)
355 struct tgsi_immediate_float32 immediate_float32
;
357 immediate_float32
.Float
= value
;
359 immediate_grow( immediate
, header
);
361 return immediate_float32
;
365 tgsi_build_full_immediate(
366 const struct tgsi_full_immediate
*full_imm
,
367 struct tgsi_token
*tokens
,
368 struct tgsi_header
*header
,
371 unsigned size
= 0, i
;
372 struct tgsi_immediate
*immediate
;
374 if( maxsize
<= size
)
376 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
379 *immediate
= tgsi_build_immediate( header
);
381 for( i
= 0; i
< full_imm
->Immediate
.Size
- 1; i
++ ) {
382 struct tgsi_immediate_float32
*if32
;
384 if( maxsize
<= size
)
386 if32
= (struct tgsi_immediate_float32
*) &tokens
[size
];
389 *if32
= tgsi_build_immediate_float32(
390 full_imm
->u
.ImmediateFloat32
[i
].Float
,
402 struct tgsi_instruction
403 tgsi_default_instruction( void )
405 struct tgsi_instruction instruction
;
407 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
408 instruction
.Size
= 1;
409 instruction
.Opcode
= TGSI_OPCODE_MOV
;
410 instruction
.Saturate
= TGSI_SAT_NONE
;
411 instruction
.NumDstRegs
= 1;
412 instruction
.NumSrcRegs
= 1;
413 instruction
.Padding
= 0;
414 instruction
.Extended
= 0;
419 struct tgsi_instruction
420 tgsi_build_instruction(
423 unsigned num_dst_regs
,
424 unsigned num_src_regs
,
425 struct tgsi_header
*header
)
427 struct tgsi_instruction instruction
;
429 assert (opcode
<= TGSI_OPCODE_LAST
);
430 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
431 assert (num_dst_regs
<= 3);
432 assert (num_src_regs
<= 15);
434 instruction
= tgsi_default_instruction();
435 instruction
.Opcode
= opcode
;
436 instruction
.Saturate
= saturate
;
437 instruction
.NumDstRegs
= num_dst_regs
;
438 instruction
.NumSrcRegs
= num_src_regs
;
440 header_bodysize_grow( header
);
447 struct tgsi_instruction
*instruction
,
448 struct tgsi_header
*header
)
450 assert (instruction
->Size
< 0xFF);
454 header_bodysize_grow( header
);
457 struct tgsi_full_instruction
458 tgsi_default_full_instruction( void )
460 struct tgsi_full_instruction full_instruction
;
463 full_instruction
.Instruction
= tgsi_default_instruction();
464 full_instruction
.InstructionExtNv
= tgsi_default_instruction_ext_nv();
465 full_instruction
.InstructionExtLabel
= tgsi_default_instruction_ext_label();
466 full_instruction
.InstructionExtTexture
= tgsi_default_instruction_ext_texture();
467 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
468 full_instruction
.FullDstRegisters
[i
] = tgsi_default_full_dst_register();
470 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
471 full_instruction
.FullSrcRegisters
[i
] = tgsi_default_full_src_register();
474 return full_instruction
;
478 tgsi_build_full_instruction(
479 const struct tgsi_full_instruction
*full_inst
,
480 struct tgsi_token
*tokens
,
481 struct tgsi_header
*header
,
486 struct tgsi_instruction
*instruction
;
487 struct tgsi_token
*prev_token
;
489 if( maxsize
<= size
)
491 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
494 *instruction
= tgsi_build_instruction(
495 full_inst
->Instruction
.Opcode
,
496 full_inst
->Instruction
.Saturate
,
497 full_inst
->Instruction
.NumDstRegs
,
498 full_inst
->Instruction
.NumSrcRegs
,
500 prev_token
= (struct tgsi_token
*) instruction
;
502 if( tgsi_compare_instruction_ext_nv(
503 full_inst
->InstructionExtNv
,
504 tgsi_default_instruction_ext_nv() ) ) {
505 struct tgsi_instruction_ext_nv
*instruction_ext_nv
;
507 if( maxsize
<= size
)
510 (struct tgsi_instruction_ext_nv
*) &tokens
[size
];
513 *instruction_ext_nv
= tgsi_build_instruction_ext_nv(
514 full_inst
->InstructionExtNv
.Precision
,
515 full_inst
->InstructionExtNv
.CondDstIndex
,
516 full_inst
->InstructionExtNv
.CondFlowIndex
,
517 full_inst
->InstructionExtNv
.CondMask
,
518 full_inst
->InstructionExtNv
.CondSwizzleX
,
519 full_inst
->InstructionExtNv
.CondSwizzleY
,
520 full_inst
->InstructionExtNv
.CondSwizzleZ
,
521 full_inst
->InstructionExtNv
.CondSwizzleW
,
522 full_inst
->InstructionExtNv
.CondDstUpdate
,
523 full_inst
->InstructionExtNv
.CondFlowEnable
,
527 prev_token
= (struct tgsi_token
*) instruction_ext_nv
;
530 if( tgsi_compare_instruction_ext_label(
531 full_inst
->InstructionExtLabel
,
532 tgsi_default_instruction_ext_label() ) ) {
533 struct tgsi_instruction_ext_label
*instruction_ext_label
;
535 if( maxsize
<= size
)
537 instruction_ext_label
=
538 (struct tgsi_instruction_ext_label
*) &tokens
[size
];
541 *instruction_ext_label
= tgsi_build_instruction_ext_label(
542 full_inst
->InstructionExtLabel
.Label
,
546 prev_token
= (struct tgsi_token
*) instruction_ext_label
;
549 if( tgsi_compare_instruction_ext_texture(
550 full_inst
->InstructionExtTexture
,
551 tgsi_default_instruction_ext_texture() ) ) {
552 struct tgsi_instruction_ext_texture
*instruction_ext_texture
;
554 if( maxsize
<= size
)
556 instruction_ext_texture
=
557 (struct tgsi_instruction_ext_texture
*) &tokens
[size
];
560 *instruction_ext_texture
= tgsi_build_instruction_ext_texture(
561 full_inst
->InstructionExtTexture
.Texture
,
565 prev_token
= (struct tgsi_token
*) instruction_ext_texture
;
568 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
569 const struct tgsi_full_dst_register
*reg
= &full_inst
->FullDstRegisters
[i
];
570 struct tgsi_dst_register
*dst_register
;
571 struct tgsi_token
*prev_token
;
573 if( maxsize
<= size
)
575 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
578 *dst_register
= tgsi_build_dst_register(
579 reg
->DstRegister
.File
,
580 reg
->DstRegister
.WriteMask
,
581 reg
->DstRegister
.Index
,
584 prev_token
= (struct tgsi_token
*) dst_register
;
586 if( tgsi_compare_dst_register_ext_concode(
587 reg
->DstRegisterExtConcode
,
588 tgsi_default_dst_register_ext_concode() ) ) {
589 struct tgsi_dst_register_ext_concode
*dst_register_ext_concode
;
591 if( maxsize
<= size
)
593 dst_register_ext_concode
=
594 (struct tgsi_dst_register_ext_concode
*) &tokens
[size
];
597 *dst_register_ext_concode
= tgsi_build_dst_register_ext_concode(
598 reg
->DstRegisterExtConcode
.CondMask
,
599 reg
->DstRegisterExtConcode
.CondSwizzleX
,
600 reg
->DstRegisterExtConcode
.CondSwizzleY
,
601 reg
->DstRegisterExtConcode
.CondSwizzleZ
,
602 reg
->DstRegisterExtConcode
.CondSwizzleW
,
603 reg
->DstRegisterExtConcode
.CondSrcIndex
,
607 prev_token
= (struct tgsi_token
*) dst_register_ext_concode
;
610 if( tgsi_compare_dst_register_ext_modulate(
611 reg
->DstRegisterExtModulate
,
612 tgsi_default_dst_register_ext_modulate() ) ) {
613 struct tgsi_dst_register_ext_modulate
*dst_register_ext_modulate
;
615 if( maxsize
<= size
)
617 dst_register_ext_modulate
=
618 (struct tgsi_dst_register_ext_modulate
*) &tokens
[size
];
621 *dst_register_ext_modulate
= tgsi_build_dst_register_ext_modulate(
622 reg
->DstRegisterExtModulate
.Modulate
,
626 prev_token
= (struct tgsi_token
*) dst_register_ext_modulate
;
630 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
631 const struct tgsi_full_src_register
*reg
= &full_inst
->FullSrcRegisters
[i
];
632 struct tgsi_src_register
*src_register
;
633 struct tgsi_token
*prev_token
;
635 if( maxsize
<= size
)
637 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
640 *src_register
= tgsi_build_src_register(
641 reg
->SrcRegister
.File
,
642 reg
->SrcRegister
.SwizzleX
,
643 reg
->SrcRegister
.SwizzleY
,
644 reg
->SrcRegister
.SwizzleZ
,
645 reg
->SrcRegister
.SwizzleW
,
646 reg
->SrcRegister
.Negate
,
647 reg
->SrcRegister
.Indirect
,
648 reg
->SrcRegister
.Dimension
,
649 reg
->SrcRegister
.Index
,
652 prev_token
= (struct tgsi_token
*) src_register
;
654 if( tgsi_compare_src_register_ext_swz(
655 reg
->SrcRegisterExtSwz
,
656 tgsi_default_src_register_ext_swz() ) ) {
657 struct tgsi_src_register_ext_swz
*src_register_ext_swz
;
659 /* Use of the extended swizzle requires the simple swizzle to be identity.
661 assert( reg
->SrcRegister
.SwizzleX
== TGSI_SWIZZLE_X
);
662 assert( reg
->SrcRegister
.SwizzleY
== TGSI_SWIZZLE_Y
);
663 assert( reg
->SrcRegister
.SwizzleZ
== TGSI_SWIZZLE_Z
);
664 assert( reg
->SrcRegister
.SwizzleW
== TGSI_SWIZZLE_W
);
665 assert( reg
->SrcRegister
.Negate
== FALSE
);
667 if( maxsize
<= size
)
669 src_register_ext_swz
=
670 (struct tgsi_src_register_ext_swz
*) &tokens
[size
];
673 *src_register_ext_swz
= tgsi_build_src_register_ext_swz(
674 reg
->SrcRegisterExtSwz
.ExtSwizzleX
,
675 reg
->SrcRegisterExtSwz
.ExtSwizzleY
,
676 reg
->SrcRegisterExtSwz
.ExtSwizzleZ
,
677 reg
->SrcRegisterExtSwz
.ExtSwizzleW
,
678 reg
->SrcRegisterExtSwz
.NegateX
,
679 reg
->SrcRegisterExtSwz
.NegateY
,
680 reg
->SrcRegisterExtSwz
.NegateZ
,
681 reg
->SrcRegisterExtSwz
.NegateW
,
685 prev_token
= (struct tgsi_token
*) src_register_ext_swz
;
688 if( tgsi_compare_src_register_ext_mod(
689 reg
->SrcRegisterExtMod
,
690 tgsi_default_src_register_ext_mod() ) ) {
691 struct tgsi_src_register_ext_mod
*src_register_ext_mod
;
693 if( maxsize
<= size
)
695 src_register_ext_mod
=
696 (struct tgsi_src_register_ext_mod
*) &tokens
[size
];
699 *src_register_ext_mod
= tgsi_build_src_register_ext_mod(
700 reg
->SrcRegisterExtMod
.Complement
,
701 reg
->SrcRegisterExtMod
.Bias
,
702 reg
->SrcRegisterExtMod
.Scale2X
,
703 reg
->SrcRegisterExtMod
.Absolute
,
704 reg
->SrcRegisterExtMod
.Negate
,
708 prev_token
= (struct tgsi_token
*) src_register_ext_mod
;
711 if( reg
->SrcRegister
.Indirect
) {
712 struct tgsi_src_register
*ind
;
714 if( maxsize
<= size
)
716 ind
= (struct tgsi_src_register
*) &tokens
[size
];
719 *ind
= tgsi_build_src_register(
720 reg
->SrcRegisterInd
.File
,
721 reg
->SrcRegisterInd
.SwizzleX
,
722 reg
->SrcRegisterInd
.SwizzleY
,
723 reg
->SrcRegisterInd
.SwizzleZ
,
724 reg
->SrcRegisterInd
.SwizzleW
,
725 reg
->SrcRegisterInd
.Negate
,
726 reg
->SrcRegisterInd
.Indirect
,
727 reg
->SrcRegisterInd
.Dimension
,
728 reg
->SrcRegisterInd
.Index
,
733 if( reg
->SrcRegister
.Dimension
) {
734 struct tgsi_dimension
*dim
;
736 assert( !reg
->SrcRegisterDim
.Dimension
);
738 if( maxsize
<= size
)
740 dim
= (struct tgsi_dimension
*) &tokens
[size
];
743 *dim
= tgsi_build_dimension(
744 reg
->SrcRegisterDim
.Indirect
,
745 reg
->SrcRegisterDim
.Index
,
749 if( reg
->SrcRegisterDim
.Indirect
) {
750 struct tgsi_src_register
*ind
;
752 if( maxsize
<= size
)
754 ind
= (struct tgsi_src_register
*) &tokens
[size
];
757 *ind
= tgsi_build_src_register(
758 reg
->SrcRegisterDimInd
.File
,
759 reg
->SrcRegisterDimInd
.SwizzleX
,
760 reg
->SrcRegisterDimInd
.SwizzleY
,
761 reg
->SrcRegisterDimInd
.SwizzleZ
,
762 reg
->SrcRegisterDimInd
.SwizzleW
,
763 reg
->SrcRegisterDimInd
.Negate
,
764 reg
->SrcRegisterDimInd
.Indirect
,
765 reg
->SrcRegisterDimInd
.Dimension
,
766 reg
->SrcRegisterDimInd
.Index
,
776 struct tgsi_instruction_ext_nv
777 tgsi_default_instruction_ext_nv( void )
779 struct tgsi_instruction_ext_nv instruction_ext_nv
;
781 instruction_ext_nv
.Type
= TGSI_INSTRUCTION_EXT_TYPE_NV
;
782 instruction_ext_nv
.Precision
= TGSI_PRECISION_DEFAULT
;
783 instruction_ext_nv
.CondDstIndex
= 0;
784 instruction_ext_nv
.CondFlowIndex
= 0;
785 instruction_ext_nv
.CondMask
= TGSI_CC_TR
;
786 instruction_ext_nv
.CondSwizzleX
= TGSI_SWIZZLE_X
;
787 instruction_ext_nv
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
788 instruction_ext_nv
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
789 instruction_ext_nv
.CondSwizzleW
= TGSI_SWIZZLE_W
;
790 instruction_ext_nv
.CondDstUpdate
= 0;
791 instruction_ext_nv
.CondFlowEnable
= 0;
792 instruction_ext_nv
.Padding
= 0;
793 instruction_ext_nv
.Extended
= 0;
795 return instruction_ext_nv
;
799 /** test for inequality of 32-bit values pointed to by a and b */
800 static INLINE boolean
801 compare32(const void *a
, const void *b
)
803 return *((uint32_t *) a
) != *((uint32_t *) b
);
808 tgsi_compare_instruction_ext_nv(
809 struct tgsi_instruction_ext_nv a
,
810 struct tgsi_instruction_ext_nv b
)
812 a
.Padding
= b
.Padding
= 0;
813 a
.Extended
= b
.Extended
= 0;
814 return compare32(&a
, &b
);
817 struct tgsi_instruction_ext_nv
818 tgsi_build_instruction_ext_nv(
820 unsigned cond_dst_index
,
821 unsigned cond_flow_index
,
823 unsigned cond_swizzle_x
,
824 unsigned cond_swizzle_y
,
825 unsigned cond_swizzle_z
,
826 unsigned cond_swizzle_w
,
827 unsigned cond_dst_update
,
828 unsigned cond_flow_enable
,
829 struct tgsi_token
*prev_token
,
830 struct tgsi_instruction
*instruction
,
831 struct tgsi_header
*header
)
833 struct tgsi_instruction_ext_nv instruction_ext_nv
;
835 instruction_ext_nv
= tgsi_default_instruction_ext_nv();
836 instruction_ext_nv
.Precision
= precision
;
837 instruction_ext_nv
.CondDstIndex
= cond_dst_index
;
838 instruction_ext_nv
.CondFlowIndex
= cond_flow_index
;
839 instruction_ext_nv
.CondMask
= cond_mask
;
840 instruction_ext_nv
.CondSwizzleX
= cond_swizzle_x
;
841 instruction_ext_nv
.CondSwizzleY
= cond_swizzle_y
;
842 instruction_ext_nv
.CondSwizzleZ
= cond_swizzle_z
;
843 instruction_ext_nv
.CondSwizzleW
= cond_swizzle_w
;
844 instruction_ext_nv
.CondDstUpdate
= cond_dst_update
;
845 instruction_ext_nv
.CondFlowEnable
= cond_flow_enable
;
847 prev_token
->Extended
= 1;
848 instruction_grow( instruction
, header
);
850 return instruction_ext_nv
;
853 struct tgsi_instruction_ext_label
854 tgsi_default_instruction_ext_label( void )
856 struct tgsi_instruction_ext_label instruction_ext_label
;
858 instruction_ext_label
.Type
= TGSI_INSTRUCTION_EXT_TYPE_LABEL
;
859 instruction_ext_label
.Label
= 0;
860 instruction_ext_label
.Padding
= 0;
861 instruction_ext_label
.Extended
= 0;
863 return instruction_ext_label
;
867 tgsi_compare_instruction_ext_label(
868 struct tgsi_instruction_ext_label a
,
869 struct tgsi_instruction_ext_label b
)
871 a
.Padding
= b
.Padding
= 0;
872 a
.Extended
= b
.Extended
= 0;
873 return compare32(&a
, &b
);
876 struct tgsi_instruction_ext_label
877 tgsi_build_instruction_ext_label(
879 struct tgsi_token
*prev_token
,
880 struct tgsi_instruction
*instruction
,
881 struct tgsi_header
*header
)
883 struct tgsi_instruction_ext_label instruction_ext_label
;
885 instruction_ext_label
= tgsi_default_instruction_ext_label();
886 instruction_ext_label
.Label
= label
;
888 prev_token
->Extended
= 1;
889 instruction_grow( instruction
, header
);
891 return instruction_ext_label
;
894 struct tgsi_instruction_ext_texture
895 tgsi_default_instruction_ext_texture( void )
897 struct tgsi_instruction_ext_texture instruction_ext_texture
;
899 instruction_ext_texture
.Type
= TGSI_INSTRUCTION_EXT_TYPE_TEXTURE
;
900 instruction_ext_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
901 instruction_ext_texture
.Padding
= 0;
902 instruction_ext_texture
.Extended
= 0;
904 return instruction_ext_texture
;
908 tgsi_compare_instruction_ext_texture(
909 struct tgsi_instruction_ext_texture a
,
910 struct tgsi_instruction_ext_texture b
)
912 a
.Padding
= b
.Padding
= 0;
913 a
.Extended
= b
.Extended
= 0;
914 return compare32(&a
, &b
);
917 struct tgsi_instruction_ext_texture
918 tgsi_build_instruction_ext_texture(
920 struct tgsi_token
*prev_token
,
921 struct tgsi_instruction
*instruction
,
922 struct tgsi_header
*header
)
924 struct tgsi_instruction_ext_texture instruction_ext_texture
;
926 instruction_ext_texture
= tgsi_default_instruction_ext_texture();
927 instruction_ext_texture
.Texture
= texture
;
929 prev_token
->Extended
= 1;
930 instruction_grow( instruction
, header
);
932 return instruction_ext_texture
;
935 struct tgsi_src_register
936 tgsi_default_src_register( void )
938 struct tgsi_src_register src_register
;
940 src_register
.File
= TGSI_FILE_NULL
;
941 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
942 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
943 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
944 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
945 src_register
.Negate
= 0;
946 src_register
.Indirect
= 0;
947 src_register
.Dimension
= 0;
948 src_register
.Index
= 0;
949 src_register
.Extended
= 0;
954 struct tgsi_src_register
955 tgsi_build_src_register(
965 struct tgsi_instruction
*instruction
,
966 struct tgsi_header
*header
)
968 struct tgsi_src_register src_register
;
970 assert( file
<= TGSI_FILE_IMMEDIATE
);
971 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
972 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
973 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
974 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
975 assert( negate
<= 1 );
976 assert( index
>= -0x8000 && index
<= 0x7FFF );
978 src_register
= tgsi_default_src_register();
979 src_register
.File
= file
;
980 src_register
.SwizzleX
= swizzle_x
;
981 src_register
.SwizzleY
= swizzle_y
;
982 src_register
.SwizzleZ
= swizzle_z
;
983 src_register
.SwizzleW
= swizzle_w
;
984 src_register
.Negate
= negate
;
985 src_register
.Indirect
= indirect
;
986 src_register
.Dimension
= dimension
;
987 src_register
.Index
= index
;
989 instruction_grow( instruction
, header
);
994 struct tgsi_full_src_register
995 tgsi_default_full_src_register( void )
997 struct tgsi_full_src_register full_src_register
;
999 full_src_register
.SrcRegister
= tgsi_default_src_register();
1000 full_src_register
.SrcRegisterExtSwz
= tgsi_default_src_register_ext_swz();
1001 full_src_register
.SrcRegisterExtMod
= tgsi_default_src_register_ext_mod();
1002 full_src_register
.SrcRegisterInd
= tgsi_default_src_register();
1003 full_src_register
.SrcRegisterDim
= tgsi_default_dimension();
1004 full_src_register
.SrcRegisterDimInd
= tgsi_default_src_register();
1006 return full_src_register
;
1009 struct tgsi_src_register_ext_swz
1010 tgsi_default_src_register_ext_swz( void )
1012 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1014 src_register_ext_swz
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_SWZ
;
1015 src_register_ext_swz
.ExtSwizzleX
= TGSI_EXTSWIZZLE_X
;
1016 src_register_ext_swz
.ExtSwizzleY
= TGSI_EXTSWIZZLE_Y
;
1017 src_register_ext_swz
.ExtSwizzleZ
= TGSI_EXTSWIZZLE_Z
;
1018 src_register_ext_swz
.ExtSwizzleW
= TGSI_EXTSWIZZLE_W
;
1019 src_register_ext_swz
.NegateX
= 0;
1020 src_register_ext_swz
.NegateY
= 0;
1021 src_register_ext_swz
.NegateZ
= 0;
1022 src_register_ext_swz
.NegateW
= 0;
1023 src_register_ext_swz
.Padding
= 0;
1024 src_register_ext_swz
.Extended
= 0;
1026 return src_register_ext_swz
;
1030 tgsi_compare_src_register_ext_swz(
1031 struct tgsi_src_register_ext_swz a
,
1032 struct tgsi_src_register_ext_swz b
)
1034 a
.Padding
= b
.Padding
= 0;
1035 a
.Extended
= b
.Extended
= 0;
1036 return compare32(&a
, &b
);
1039 struct tgsi_src_register_ext_swz
1040 tgsi_build_src_register_ext_swz(
1041 unsigned ext_swizzle_x
,
1042 unsigned ext_swizzle_y
,
1043 unsigned ext_swizzle_z
,
1044 unsigned ext_swizzle_w
,
1049 struct tgsi_token
*prev_token
,
1050 struct tgsi_instruction
*instruction
,
1051 struct tgsi_header
*header
)
1053 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1055 assert( ext_swizzle_x
<= TGSI_EXTSWIZZLE_ONE
);
1056 assert( ext_swizzle_y
<= TGSI_EXTSWIZZLE_ONE
);
1057 assert( ext_swizzle_z
<= TGSI_EXTSWIZZLE_ONE
);
1058 assert( ext_swizzle_w
<= TGSI_EXTSWIZZLE_ONE
);
1059 assert( negate_x
<= 1 );
1060 assert( negate_y
<= 1 );
1061 assert( negate_z
<= 1 );
1062 assert( negate_w
<= 1 );
1064 src_register_ext_swz
= tgsi_default_src_register_ext_swz();
1065 src_register_ext_swz
.ExtSwizzleX
= ext_swizzle_x
;
1066 src_register_ext_swz
.ExtSwizzleY
= ext_swizzle_y
;
1067 src_register_ext_swz
.ExtSwizzleZ
= ext_swizzle_z
;
1068 src_register_ext_swz
.ExtSwizzleW
= ext_swizzle_w
;
1069 src_register_ext_swz
.NegateX
= negate_x
;
1070 src_register_ext_swz
.NegateY
= negate_y
;
1071 src_register_ext_swz
.NegateZ
= negate_z
;
1072 src_register_ext_swz
.NegateW
= negate_w
;
1074 prev_token
->Extended
= 1;
1075 instruction_grow( instruction
, header
);
1077 return src_register_ext_swz
;
1080 struct tgsi_src_register_ext_mod
1081 tgsi_default_src_register_ext_mod( void )
1083 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1085 src_register_ext_mod
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_MOD
;
1086 src_register_ext_mod
.Complement
= 0;
1087 src_register_ext_mod
.Bias
= 0;
1088 src_register_ext_mod
.Scale2X
= 0;
1089 src_register_ext_mod
.Absolute
= 0;
1090 src_register_ext_mod
.Negate
= 0;
1091 src_register_ext_mod
.Padding
= 0;
1092 src_register_ext_mod
.Extended
= 0;
1094 return src_register_ext_mod
;
1098 tgsi_compare_src_register_ext_mod(
1099 struct tgsi_src_register_ext_mod a
,
1100 struct tgsi_src_register_ext_mod b
)
1102 a
.Padding
= b
.Padding
= 0;
1103 a
.Extended
= b
.Extended
= 0;
1104 return compare32(&a
, &b
);
1107 struct tgsi_src_register_ext_mod
1108 tgsi_build_src_register_ext_mod(
1109 unsigned complement
,
1114 struct tgsi_token
*prev_token
,
1115 struct tgsi_instruction
*instruction
,
1116 struct tgsi_header
*header
)
1118 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1120 assert( complement
<= 1 );
1121 assert( bias
<= 1 );
1122 assert( scale_2x
<= 1 );
1123 assert( absolute
<= 1 );
1124 assert( negate
<= 1 );
1126 src_register_ext_mod
= tgsi_default_src_register_ext_mod();
1127 src_register_ext_mod
.Complement
= complement
;
1128 src_register_ext_mod
.Bias
= bias
;
1129 src_register_ext_mod
.Scale2X
= scale_2x
;
1130 src_register_ext_mod
.Absolute
= absolute
;
1131 src_register_ext_mod
.Negate
= negate
;
1133 prev_token
->Extended
= 1;
1134 instruction_grow( instruction
, header
);
1136 return src_register_ext_mod
;
1139 struct tgsi_dimension
1140 tgsi_default_dimension( void )
1142 struct tgsi_dimension dimension
;
1144 dimension
.Indirect
= 0;
1145 dimension
.Dimension
= 0;
1146 dimension
.Padding
= 0;
1147 dimension
.Index
= 0;
1148 dimension
.Extended
= 0;
1153 struct tgsi_dimension
1154 tgsi_build_dimension(
1157 struct tgsi_instruction
*instruction
,
1158 struct tgsi_header
*header
)
1160 struct tgsi_dimension dimension
;
1162 dimension
= tgsi_default_dimension();
1163 dimension
.Indirect
= indirect
;
1164 dimension
.Index
= index
;
1166 instruction_grow( instruction
, header
);
1171 struct tgsi_dst_register
1172 tgsi_default_dst_register( void )
1174 struct tgsi_dst_register dst_register
;
1176 dst_register
.File
= TGSI_FILE_NULL
;
1177 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1178 dst_register
.Indirect
= 0;
1179 dst_register
.Dimension
= 0;
1180 dst_register
.Index
= 0;
1181 dst_register
.Padding
= 0;
1182 dst_register
.Extended
= 0;
1184 return dst_register
;
1187 struct tgsi_dst_register
1188 tgsi_build_dst_register(
1192 struct tgsi_instruction
*instruction
,
1193 struct tgsi_header
*header
)
1195 struct tgsi_dst_register dst_register
;
1197 assert( file
<= TGSI_FILE_IMMEDIATE
);
1198 assert( mask
<= TGSI_WRITEMASK_XYZW
);
1199 assert( index
>= -32768 && index
<= 32767 );
1201 dst_register
= tgsi_default_dst_register();
1202 dst_register
.File
= file
;
1203 dst_register
.WriteMask
= mask
;
1204 dst_register
.Index
= index
;
1206 instruction_grow( instruction
, header
);
1208 return dst_register
;
1211 struct tgsi_full_dst_register
1212 tgsi_default_full_dst_register( void )
1214 struct tgsi_full_dst_register full_dst_register
;
1216 full_dst_register
.DstRegister
= tgsi_default_dst_register();
1217 full_dst_register
.DstRegisterExtConcode
=
1218 tgsi_default_dst_register_ext_concode();
1219 full_dst_register
.DstRegisterExtModulate
=
1220 tgsi_default_dst_register_ext_modulate();
1222 return full_dst_register
;
1225 struct tgsi_dst_register_ext_concode
1226 tgsi_default_dst_register_ext_concode( void )
1228 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1230 dst_register_ext_concode
.Type
= TGSI_DST_REGISTER_EXT_TYPE_CONDCODE
;
1231 dst_register_ext_concode
.CondMask
= TGSI_CC_TR
;
1232 dst_register_ext_concode
.CondSwizzleX
= TGSI_SWIZZLE_X
;
1233 dst_register_ext_concode
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
1234 dst_register_ext_concode
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
1235 dst_register_ext_concode
.CondSwizzleW
= TGSI_SWIZZLE_W
;
1236 dst_register_ext_concode
.CondSrcIndex
= 0;
1237 dst_register_ext_concode
.Padding
= 0;
1238 dst_register_ext_concode
.Extended
= 0;
1240 return dst_register_ext_concode
;
1244 tgsi_compare_dst_register_ext_concode(
1245 struct tgsi_dst_register_ext_concode a
,
1246 struct tgsi_dst_register_ext_concode b
)
1248 a
.Padding
= b
.Padding
= 0;
1249 a
.Extended
= b
.Extended
= 0;
1250 return compare32(&a
, &b
);
1253 struct tgsi_dst_register_ext_concode
1254 tgsi_build_dst_register_ext_concode(
1261 struct tgsi_token
*prev_token
,
1262 struct tgsi_instruction
*instruction
,
1263 struct tgsi_header
*header
)
1265 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1267 assert( cc
<= TGSI_CC_FL
);
1268 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
1269 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
1270 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
1271 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
1272 assert( index
>= -32768 && index
<= 32767 );
1274 dst_register_ext_concode
= tgsi_default_dst_register_ext_concode();
1275 dst_register_ext_concode
.CondMask
= cc
;
1276 dst_register_ext_concode
.CondSwizzleX
= swizzle_x
;
1277 dst_register_ext_concode
.CondSwizzleY
= swizzle_y
;
1278 dst_register_ext_concode
.CondSwizzleZ
= swizzle_z
;
1279 dst_register_ext_concode
.CondSwizzleW
= swizzle_w
;
1280 dst_register_ext_concode
.CondSrcIndex
= index
;
1282 prev_token
->Extended
= 1;
1283 instruction_grow( instruction
, header
);
1285 return dst_register_ext_concode
;
1288 struct tgsi_dst_register_ext_modulate
1289 tgsi_default_dst_register_ext_modulate( void )
1291 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1293 dst_register_ext_modulate
.Type
= TGSI_DST_REGISTER_EXT_TYPE_MODULATE
;
1294 dst_register_ext_modulate
.Modulate
= TGSI_MODULATE_1X
;
1295 dst_register_ext_modulate
.Padding
= 0;
1296 dst_register_ext_modulate
.Extended
= 0;
1298 return dst_register_ext_modulate
;
1302 tgsi_compare_dst_register_ext_modulate(
1303 struct tgsi_dst_register_ext_modulate a
,
1304 struct tgsi_dst_register_ext_modulate b
)
1306 a
.Padding
= b
.Padding
= 0;
1307 a
.Extended
= b
.Extended
= 0;
1308 return compare32(&a
, &b
);
1311 struct tgsi_dst_register_ext_modulate
1312 tgsi_build_dst_register_ext_modulate(
1314 struct tgsi_token
*prev_token
,
1315 struct tgsi_instruction
*instruction
,
1316 struct tgsi_header
*header
)
1318 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1320 assert( modulate
<= TGSI_MODULATE_EIGHTH
);
1322 dst_register_ext_modulate
= tgsi_default_dst_register_ext_modulate();
1323 dst_register_ext_modulate
.Modulate
= modulate
;
1325 prev_token
->Extended
= 1;
1326 instruction_grow( instruction
, header
);
1328 return dst_register_ext_modulate
;