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 "util/u_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
.NrTokens
= 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_COUNT
);
143 assert( interpolate
< TGSI_INTERPOLATE_COUNT
);
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
->NrTokens
< 0xFF );
165 declaration
->NrTokens
++;
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
;
311 immediate
.NrTokens
= 1;
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
[0].Float
= 0.0f
;
339 fullimm
.u
[1].Float
= 0.0f
;
340 fullimm
.u
[2].Float
= 0.0f
;
341 fullimm
.u
[3].Float
= 0.0f
;
348 struct tgsi_immediate
*immediate
,
349 struct tgsi_header
*header
)
351 assert( immediate
->NrTokens
< 0xFF );
353 immediate
->NrTokens
++;
355 header_bodysize_grow( header
);
358 union tgsi_immediate_data
359 tgsi_build_immediate_float32(
361 struct tgsi_immediate
*immediate
,
362 struct tgsi_header
*header
)
364 union tgsi_immediate_data immediate_data
;
366 immediate_data
.Float
= value
;
368 immediate_grow( immediate
, header
);
370 return immediate_data
;
374 tgsi_build_full_immediate(
375 const struct tgsi_full_immediate
*full_imm
,
376 struct tgsi_token
*tokens
,
377 struct tgsi_header
*header
,
380 unsigned size
= 0, i
;
381 struct tgsi_immediate
*immediate
;
383 if( maxsize
<= size
)
385 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
388 *immediate
= tgsi_build_immediate( header
);
390 assert( full_imm
->Immediate
.NrTokens
<= 4 + 1 );
392 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
393 union tgsi_immediate_data
*data
;
395 if( maxsize
<= size
)
397 data
= (union tgsi_immediate_data
*) &tokens
[size
];
400 *data
= tgsi_build_immediate_float32(
401 full_imm
->u
[i
].Float
,
413 struct tgsi_instruction
414 tgsi_default_instruction( void )
416 struct tgsi_instruction instruction
;
418 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
419 instruction
.NrTokens
= 1;
420 instruction
.Opcode
= TGSI_OPCODE_MOV
;
421 instruction
.Saturate
= TGSI_SAT_NONE
;
422 instruction
.NumDstRegs
= 1;
423 instruction
.NumSrcRegs
= 1;
424 instruction
.Padding
= 0;
425 instruction
.Extended
= 0;
430 struct tgsi_instruction
431 tgsi_build_instruction(
434 unsigned num_dst_regs
,
435 unsigned num_src_regs
,
436 struct tgsi_header
*header
)
438 struct tgsi_instruction instruction
;
440 assert (opcode
<= TGSI_OPCODE_LAST
);
441 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
442 assert (num_dst_regs
<= 3);
443 assert (num_src_regs
<= 15);
445 instruction
= tgsi_default_instruction();
446 instruction
.Opcode
= opcode
;
447 instruction
.Saturate
= saturate
;
448 instruction
.NumDstRegs
= num_dst_regs
;
449 instruction
.NumSrcRegs
= num_src_regs
;
451 header_bodysize_grow( header
);
458 struct tgsi_instruction
*instruction
,
459 struct tgsi_header
*header
)
461 assert (instruction
->NrTokens
< 0xFF);
463 instruction
->NrTokens
++;
465 header_bodysize_grow( header
);
468 struct tgsi_full_instruction
469 tgsi_default_full_instruction( void )
471 struct tgsi_full_instruction full_instruction
;
474 full_instruction
.Instruction
= tgsi_default_instruction();
475 full_instruction
.InstructionExtNv
= tgsi_default_instruction_ext_nv();
476 full_instruction
.InstructionExtLabel
= tgsi_default_instruction_ext_label();
477 full_instruction
.InstructionExtTexture
= tgsi_default_instruction_ext_texture();
478 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
479 full_instruction
.FullDstRegisters
[i
] = tgsi_default_full_dst_register();
481 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
482 full_instruction
.FullSrcRegisters
[i
] = tgsi_default_full_src_register();
485 full_instruction
.Flags
= 0x0;
487 return full_instruction
;
491 tgsi_build_full_instruction(
492 const struct tgsi_full_instruction
*full_inst
,
493 struct tgsi_token
*tokens
,
494 struct tgsi_header
*header
,
499 struct tgsi_instruction
*instruction
;
500 struct tgsi_token
*prev_token
;
502 if( maxsize
<= size
)
504 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
507 *instruction
= tgsi_build_instruction(
508 full_inst
->Instruction
.Opcode
,
509 full_inst
->Instruction
.Saturate
,
510 full_inst
->Instruction
.NumDstRegs
,
511 full_inst
->Instruction
.NumSrcRegs
,
513 prev_token
= (struct tgsi_token
*) instruction
;
515 if( tgsi_compare_instruction_ext_nv(
516 full_inst
->InstructionExtNv
,
517 tgsi_default_instruction_ext_nv() ) ) {
518 struct tgsi_instruction_ext_nv
*instruction_ext_nv
;
520 if( maxsize
<= size
)
523 (struct tgsi_instruction_ext_nv
*) &tokens
[size
];
526 *instruction_ext_nv
= tgsi_build_instruction_ext_nv(
527 full_inst
->InstructionExtNv
.Precision
,
528 full_inst
->InstructionExtNv
.CondDstIndex
,
529 full_inst
->InstructionExtNv
.CondFlowIndex
,
530 full_inst
->InstructionExtNv
.CondMask
,
531 full_inst
->InstructionExtNv
.CondSwizzleX
,
532 full_inst
->InstructionExtNv
.CondSwizzleY
,
533 full_inst
->InstructionExtNv
.CondSwizzleZ
,
534 full_inst
->InstructionExtNv
.CondSwizzleW
,
535 full_inst
->InstructionExtNv
.CondDstUpdate
,
536 full_inst
->InstructionExtNv
.CondFlowEnable
,
540 prev_token
= (struct tgsi_token
*) instruction_ext_nv
;
543 if( tgsi_compare_instruction_ext_label(
544 full_inst
->InstructionExtLabel
,
545 tgsi_default_instruction_ext_label() ) ) {
546 struct tgsi_instruction_ext_label
*instruction_ext_label
;
548 if( maxsize
<= size
)
550 instruction_ext_label
=
551 (struct tgsi_instruction_ext_label
*) &tokens
[size
];
554 *instruction_ext_label
= tgsi_build_instruction_ext_label(
555 full_inst
->InstructionExtLabel
.Label
,
559 prev_token
= (struct tgsi_token
*) instruction_ext_label
;
562 if( tgsi_compare_instruction_ext_texture(
563 full_inst
->InstructionExtTexture
,
564 tgsi_default_instruction_ext_texture() ) ) {
565 struct tgsi_instruction_ext_texture
*instruction_ext_texture
;
567 if( maxsize
<= size
)
569 instruction_ext_texture
=
570 (struct tgsi_instruction_ext_texture
*) &tokens
[size
];
573 *instruction_ext_texture
= tgsi_build_instruction_ext_texture(
574 full_inst
->InstructionExtTexture
.Texture
,
578 prev_token
= (struct tgsi_token
*) instruction_ext_texture
;
581 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
582 const struct tgsi_full_dst_register
*reg
= &full_inst
->FullDstRegisters
[i
];
583 struct tgsi_dst_register
*dst_register
;
584 struct tgsi_token
*prev_token
;
586 if( maxsize
<= size
)
588 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
591 *dst_register
= tgsi_build_dst_register(
592 reg
->DstRegister
.File
,
593 reg
->DstRegister
.WriteMask
,
594 reg
->DstRegister
.Indirect
,
595 reg
->DstRegister
.Index
,
598 prev_token
= (struct tgsi_token
*) dst_register
;
600 if( tgsi_compare_dst_register_ext_concode(
601 reg
->DstRegisterExtConcode
,
602 tgsi_default_dst_register_ext_concode() ) ) {
603 struct tgsi_dst_register_ext_concode
*dst_register_ext_concode
;
605 if( maxsize
<= size
)
607 dst_register_ext_concode
=
608 (struct tgsi_dst_register_ext_concode
*) &tokens
[size
];
611 *dst_register_ext_concode
= tgsi_build_dst_register_ext_concode(
612 reg
->DstRegisterExtConcode
.CondMask
,
613 reg
->DstRegisterExtConcode
.CondSwizzleX
,
614 reg
->DstRegisterExtConcode
.CondSwizzleY
,
615 reg
->DstRegisterExtConcode
.CondSwizzleZ
,
616 reg
->DstRegisterExtConcode
.CondSwizzleW
,
617 reg
->DstRegisterExtConcode
.CondSrcIndex
,
621 prev_token
= (struct tgsi_token
*) dst_register_ext_concode
;
624 if( tgsi_compare_dst_register_ext_modulate(
625 reg
->DstRegisterExtModulate
,
626 tgsi_default_dst_register_ext_modulate() ) ) {
627 struct tgsi_dst_register_ext_modulate
*dst_register_ext_modulate
;
629 if( maxsize
<= size
)
631 dst_register_ext_modulate
=
632 (struct tgsi_dst_register_ext_modulate
*) &tokens
[size
];
635 *dst_register_ext_modulate
= tgsi_build_dst_register_ext_modulate(
636 reg
->DstRegisterExtModulate
.Modulate
,
640 prev_token
= (struct tgsi_token
*) dst_register_ext_modulate
;
643 if( reg
->DstRegister
.Indirect
) {
644 struct tgsi_src_register
*ind
;
646 if( maxsize
<= size
)
648 ind
= (struct tgsi_src_register
*) &tokens
[size
];
651 *ind
= tgsi_build_src_register(
652 reg
->DstRegisterInd
.File
,
653 reg
->DstRegisterInd
.SwizzleX
,
654 reg
->DstRegisterInd
.SwizzleY
,
655 reg
->DstRegisterInd
.SwizzleZ
,
656 reg
->DstRegisterInd
.SwizzleW
,
657 reg
->DstRegisterInd
.Negate
,
658 reg
->DstRegisterInd
.Indirect
,
659 reg
->DstRegisterInd
.Dimension
,
660 reg
->DstRegisterInd
.Index
,
666 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
667 const struct tgsi_full_src_register
*reg
= &full_inst
->FullSrcRegisters
[i
];
668 struct tgsi_src_register
*src_register
;
669 struct tgsi_token
*prev_token
;
671 if( maxsize
<= size
)
673 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
676 *src_register
= tgsi_build_src_register(
677 reg
->SrcRegister
.File
,
678 reg
->SrcRegister
.SwizzleX
,
679 reg
->SrcRegister
.SwizzleY
,
680 reg
->SrcRegister
.SwizzleZ
,
681 reg
->SrcRegister
.SwizzleW
,
682 reg
->SrcRegister
.Negate
,
683 reg
->SrcRegister
.Indirect
,
684 reg
->SrcRegister
.Dimension
,
685 reg
->SrcRegister
.Index
,
688 prev_token
= (struct tgsi_token
*) src_register
;
690 if( tgsi_compare_src_register_ext_swz(
691 reg
->SrcRegisterExtSwz
,
692 tgsi_default_src_register_ext_swz() ) ) {
693 struct tgsi_src_register_ext_swz
*src_register_ext_swz
;
695 /* Use of the extended swizzle requires the simple swizzle to be identity.
697 assert( reg
->SrcRegister
.SwizzleX
== TGSI_SWIZZLE_X
);
698 assert( reg
->SrcRegister
.SwizzleY
== TGSI_SWIZZLE_Y
);
699 assert( reg
->SrcRegister
.SwizzleZ
== TGSI_SWIZZLE_Z
);
700 assert( reg
->SrcRegister
.SwizzleW
== TGSI_SWIZZLE_W
);
701 assert( reg
->SrcRegister
.Negate
== FALSE
);
703 if( maxsize
<= size
)
705 src_register_ext_swz
=
706 (struct tgsi_src_register_ext_swz
*) &tokens
[size
];
709 *src_register_ext_swz
= tgsi_build_src_register_ext_swz(
710 reg
->SrcRegisterExtSwz
.ExtSwizzleX
,
711 reg
->SrcRegisterExtSwz
.ExtSwizzleY
,
712 reg
->SrcRegisterExtSwz
.ExtSwizzleZ
,
713 reg
->SrcRegisterExtSwz
.ExtSwizzleW
,
714 reg
->SrcRegisterExtSwz
.NegateX
,
715 reg
->SrcRegisterExtSwz
.NegateY
,
716 reg
->SrcRegisterExtSwz
.NegateZ
,
717 reg
->SrcRegisterExtSwz
.NegateW
,
721 prev_token
= (struct tgsi_token
*) src_register_ext_swz
;
724 if( tgsi_compare_src_register_ext_mod(
725 reg
->SrcRegisterExtMod
,
726 tgsi_default_src_register_ext_mod() ) ) {
727 struct tgsi_src_register_ext_mod
*src_register_ext_mod
;
729 if( maxsize
<= size
)
731 src_register_ext_mod
=
732 (struct tgsi_src_register_ext_mod
*) &tokens
[size
];
735 *src_register_ext_mod
= tgsi_build_src_register_ext_mod(
736 reg
->SrcRegisterExtMod
.Complement
,
737 reg
->SrcRegisterExtMod
.Bias
,
738 reg
->SrcRegisterExtMod
.Scale2X
,
739 reg
->SrcRegisterExtMod
.Absolute
,
740 reg
->SrcRegisterExtMod
.Negate
,
744 prev_token
= (struct tgsi_token
*) src_register_ext_mod
;
747 if( reg
->SrcRegister
.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
->SrcRegisterInd
.File
,
757 reg
->SrcRegisterInd
.SwizzleX
,
758 reg
->SrcRegisterInd
.SwizzleY
,
759 reg
->SrcRegisterInd
.SwizzleZ
,
760 reg
->SrcRegisterInd
.SwizzleW
,
761 reg
->SrcRegisterInd
.Negate
,
762 reg
->SrcRegisterInd
.Indirect
,
763 reg
->SrcRegisterInd
.Dimension
,
764 reg
->SrcRegisterInd
.Index
,
769 if( reg
->SrcRegister
.Dimension
) {
770 struct tgsi_dimension
*dim
;
772 assert( !reg
->SrcRegisterDim
.Dimension
);
774 if( maxsize
<= size
)
776 dim
= (struct tgsi_dimension
*) &tokens
[size
];
779 *dim
= tgsi_build_dimension(
780 reg
->SrcRegisterDim
.Indirect
,
781 reg
->SrcRegisterDim
.Index
,
785 if( reg
->SrcRegisterDim
.Indirect
) {
786 struct tgsi_src_register
*ind
;
788 if( maxsize
<= size
)
790 ind
= (struct tgsi_src_register
*) &tokens
[size
];
793 *ind
= tgsi_build_src_register(
794 reg
->SrcRegisterDimInd
.File
,
795 reg
->SrcRegisterDimInd
.SwizzleX
,
796 reg
->SrcRegisterDimInd
.SwizzleY
,
797 reg
->SrcRegisterDimInd
.SwizzleZ
,
798 reg
->SrcRegisterDimInd
.SwizzleW
,
799 reg
->SrcRegisterDimInd
.Negate
,
800 reg
->SrcRegisterDimInd
.Indirect
,
801 reg
->SrcRegisterDimInd
.Dimension
,
802 reg
->SrcRegisterDimInd
.Index
,
812 struct tgsi_instruction_ext_nv
813 tgsi_default_instruction_ext_nv( void )
815 struct tgsi_instruction_ext_nv instruction_ext_nv
;
817 instruction_ext_nv
.Type
= TGSI_INSTRUCTION_EXT_TYPE_NV
;
818 instruction_ext_nv
.Precision
= TGSI_PRECISION_DEFAULT
;
819 instruction_ext_nv
.CondDstIndex
= 0;
820 instruction_ext_nv
.CondFlowIndex
= 0;
821 instruction_ext_nv
.CondMask
= TGSI_CC_TR
;
822 instruction_ext_nv
.CondSwizzleX
= TGSI_SWIZZLE_X
;
823 instruction_ext_nv
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
824 instruction_ext_nv
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
825 instruction_ext_nv
.CondSwizzleW
= TGSI_SWIZZLE_W
;
826 instruction_ext_nv
.CondDstUpdate
= 0;
827 instruction_ext_nv
.CondFlowEnable
= 0;
828 instruction_ext_nv
.Padding
= 0;
829 instruction_ext_nv
.Extended
= 0;
831 return instruction_ext_nv
;
835 /** test for inequality of 32-bit values pointed to by a and b */
836 static INLINE boolean
837 compare32(const void *a
, const void *b
)
839 return *((uint32_t *) a
) != *((uint32_t *) b
);
844 tgsi_compare_instruction_ext_nv(
845 struct tgsi_instruction_ext_nv a
,
846 struct tgsi_instruction_ext_nv b
)
848 a
.Padding
= b
.Padding
= 0;
849 a
.Extended
= b
.Extended
= 0;
850 return compare32(&a
, &b
);
853 struct tgsi_instruction_ext_nv
854 tgsi_build_instruction_ext_nv(
856 unsigned cond_dst_index
,
857 unsigned cond_flow_index
,
859 unsigned cond_swizzle_x
,
860 unsigned cond_swizzle_y
,
861 unsigned cond_swizzle_z
,
862 unsigned cond_swizzle_w
,
863 unsigned cond_dst_update
,
864 unsigned cond_flow_enable
,
865 struct tgsi_token
*prev_token
,
866 struct tgsi_instruction
*instruction
,
867 struct tgsi_header
*header
)
869 struct tgsi_instruction_ext_nv instruction_ext_nv
;
871 instruction_ext_nv
= tgsi_default_instruction_ext_nv();
872 instruction_ext_nv
.Precision
= precision
;
873 instruction_ext_nv
.CondDstIndex
= cond_dst_index
;
874 instruction_ext_nv
.CondFlowIndex
= cond_flow_index
;
875 instruction_ext_nv
.CondMask
= cond_mask
;
876 instruction_ext_nv
.CondSwizzleX
= cond_swizzle_x
;
877 instruction_ext_nv
.CondSwizzleY
= cond_swizzle_y
;
878 instruction_ext_nv
.CondSwizzleZ
= cond_swizzle_z
;
879 instruction_ext_nv
.CondSwizzleW
= cond_swizzle_w
;
880 instruction_ext_nv
.CondDstUpdate
= cond_dst_update
;
881 instruction_ext_nv
.CondFlowEnable
= cond_flow_enable
;
883 prev_token
->Extended
= 1;
884 instruction_grow( instruction
, header
);
886 return instruction_ext_nv
;
889 struct tgsi_instruction_ext_label
890 tgsi_default_instruction_ext_label( void )
892 struct tgsi_instruction_ext_label instruction_ext_label
;
894 instruction_ext_label
.Type
= TGSI_INSTRUCTION_EXT_TYPE_LABEL
;
895 instruction_ext_label
.Label
= 0;
896 instruction_ext_label
.Padding
= 0;
897 instruction_ext_label
.Extended
= 0;
899 return instruction_ext_label
;
903 tgsi_compare_instruction_ext_label(
904 struct tgsi_instruction_ext_label a
,
905 struct tgsi_instruction_ext_label b
)
907 a
.Padding
= b
.Padding
= 0;
908 a
.Extended
= b
.Extended
= 0;
909 return compare32(&a
, &b
);
912 struct tgsi_instruction_ext_label
913 tgsi_build_instruction_ext_label(
915 struct tgsi_token
*prev_token
,
916 struct tgsi_instruction
*instruction
,
917 struct tgsi_header
*header
)
919 struct tgsi_instruction_ext_label instruction_ext_label
;
921 instruction_ext_label
= tgsi_default_instruction_ext_label();
922 instruction_ext_label
.Label
= label
;
924 prev_token
->Extended
= 1;
925 instruction_grow( instruction
, header
);
927 return instruction_ext_label
;
930 struct tgsi_instruction_ext_texture
931 tgsi_default_instruction_ext_texture( void )
933 struct tgsi_instruction_ext_texture instruction_ext_texture
;
935 instruction_ext_texture
.Type
= TGSI_INSTRUCTION_EXT_TYPE_TEXTURE
;
936 instruction_ext_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
937 instruction_ext_texture
.Padding
= 0;
938 instruction_ext_texture
.Extended
= 0;
940 return instruction_ext_texture
;
944 tgsi_compare_instruction_ext_texture(
945 struct tgsi_instruction_ext_texture a
,
946 struct tgsi_instruction_ext_texture b
)
948 a
.Padding
= b
.Padding
= 0;
949 a
.Extended
= b
.Extended
= 0;
950 return compare32(&a
, &b
);
953 struct tgsi_instruction_ext_texture
954 tgsi_build_instruction_ext_texture(
956 struct tgsi_token
*prev_token
,
957 struct tgsi_instruction
*instruction
,
958 struct tgsi_header
*header
)
960 struct tgsi_instruction_ext_texture instruction_ext_texture
;
962 instruction_ext_texture
= tgsi_default_instruction_ext_texture();
963 instruction_ext_texture
.Texture
= texture
;
965 prev_token
->Extended
= 1;
966 instruction_grow( instruction
, header
);
968 return instruction_ext_texture
;
971 struct tgsi_src_register
972 tgsi_default_src_register( void )
974 struct tgsi_src_register src_register
;
976 src_register
.File
= TGSI_FILE_NULL
;
977 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
978 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
979 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
980 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
981 src_register
.Negate
= 0;
982 src_register
.Indirect
= 0;
983 src_register
.Dimension
= 0;
984 src_register
.Index
= 0;
985 src_register
.Extended
= 0;
990 struct tgsi_src_register
991 tgsi_build_src_register(
1001 struct tgsi_instruction
*instruction
,
1002 struct tgsi_header
*header
)
1004 struct tgsi_src_register src_register
;
1006 assert( file
< TGSI_FILE_COUNT
);
1007 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
1008 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
1009 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
1010 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
1011 assert( negate
<= 1 );
1012 assert( index
>= -0x8000 && index
<= 0x7FFF );
1014 src_register
= tgsi_default_src_register();
1015 src_register
.File
= file
;
1016 src_register
.SwizzleX
= swizzle_x
;
1017 src_register
.SwizzleY
= swizzle_y
;
1018 src_register
.SwizzleZ
= swizzle_z
;
1019 src_register
.SwizzleW
= swizzle_w
;
1020 src_register
.Negate
= negate
;
1021 src_register
.Indirect
= indirect
;
1022 src_register
.Dimension
= dimension
;
1023 src_register
.Index
= index
;
1025 instruction_grow( instruction
, header
);
1027 return src_register
;
1030 struct tgsi_full_src_register
1031 tgsi_default_full_src_register( void )
1033 struct tgsi_full_src_register full_src_register
;
1035 full_src_register
.SrcRegister
= tgsi_default_src_register();
1036 full_src_register
.SrcRegisterExtSwz
= tgsi_default_src_register_ext_swz();
1037 full_src_register
.SrcRegisterExtMod
= tgsi_default_src_register_ext_mod();
1038 full_src_register
.SrcRegisterInd
= tgsi_default_src_register();
1039 full_src_register
.SrcRegisterDim
= tgsi_default_dimension();
1040 full_src_register
.SrcRegisterDimInd
= tgsi_default_src_register();
1042 return full_src_register
;
1045 struct tgsi_src_register_ext_swz
1046 tgsi_default_src_register_ext_swz( void )
1048 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1050 src_register_ext_swz
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_SWZ
;
1051 src_register_ext_swz
.ExtSwizzleX
= TGSI_EXTSWIZZLE_X
;
1052 src_register_ext_swz
.ExtSwizzleY
= TGSI_EXTSWIZZLE_Y
;
1053 src_register_ext_swz
.ExtSwizzleZ
= TGSI_EXTSWIZZLE_Z
;
1054 src_register_ext_swz
.ExtSwizzleW
= TGSI_EXTSWIZZLE_W
;
1055 src_register_ext_swz
.NegateX
= 0;
1056 src_register_ext_swz
.NegateY
= 0;
1057 src_register_ext_swz
.NegateZ
= 0;
1058 src_register_ext_swz
.NegateW
= 0;
1059 src_register_ext_swz
.Padding
= 0;
1060 src_register_ext_swz
.Extended
= 0;
1062 return src_register_ext_swz
;
1066 tgsi_compare_src_register_ext_swz(
1067 struct tgsi_src_register_ext_swz a
,
1068 struct tgsi_src_register_ext_swz b
)
1070 a
.Padding
= b
.Padding
= 0;
1071 a
.Extended
= b
.Extended
= 0;
1072 return compare32(&a
, &b
);
1075 struct tgsi_src_register_ext_swz
1076 tgsi_build_src_register_ext_swz(
1077 unsigned ext_swizzle_x
,
1078 unsigned ext_swizzle_y
,
1079 unsigned ext_swizzle_z
,
1080 unsigned ext_swizzle_w
,
1085 struct tgsi_token
*prev_token
,
1086 struct tgsi_instruction
*instruction
,
1087 struct tgsi_header
*header
)
1089 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1091 assert( ext_swizzle_x
<= TGSI_EXTSWIZZLE_ONE
);
1092 assert( ext_swizzle_y
<= TGSI_EXTSWIZZLE_ONE
);
1093 assert( ext_swizzle_z
<= TGSI_EXTSWIZZLE_ONE
);
1094 assert( ext_swizzle_w
<= TGSI_EXTSWIZZLE_ONE
);
1095 assert( negate_x
<= 1 );
1096 assert( negate_y
<= 1 );
1097 assert( negate_z
<= 1 );
1098 assert( negate_w
<= 1 );
1100 src_register_ext_swz
= tgsi_default_src_register_ext_swz();
1101 src_register_ext_swz
.ExtSwizzleX
= ext_swizzle_x
;
1102 src_register_ext_swz
.ExtSwizzleY
= ext_swizzle_y
;
1103 src_register_ext_swz
.ExtSwizzleZ
= ext_swizzle_z
;
1104 src_register_ext_swz
.ExtSwizzleW
= ext_swizzle_w
;
1105 src_register_ext_swz
.NegateX
= negate_x
;
1106 src_register_ext_swz
.NegateY
= negate_y
;
1107 src_register_ext_swz
.NegateZ
= negate_z
;
1108 src_register_ext_swz
.NegateW
= negate_w
;
1110 prev_token
->Extended
= 1;
1111 instruction_grow( instruction
, header
);
1113 return src_register_ext_swz
;
1116 struct tgsi_src_register_ext_mod
1117 tgsi_default_src_register_ext_mod( void )
1119 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1121 src_register_ext_mod
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_MOD
;
1122 src_register_ext_mod
.Complement
= 0;
1123 src_register_ext_mod
.Bias
= 0;
1124 src_register_ext_mod
.Scale2X
= 0;
1125 src_register_ext_mod
.Absolute
= 0;
1126 src_register_ext_mod
.Negate
= 0;
1127 src_register_ext_mod
.Padding
= 0;
1128 src_register_ext_mod
.Extended
= 0;
1130 return src_register_ext_mod
;
1134 tgsi_compare_src_register_ext_mod(
1135 struct tgsi_src_register_ext_mod a
,
1136 struct tgsi_src_register_ext_mod b
)
1138 a
.Padding
= b
.Padding
= 0;
1139 a
.Extended
= b
.Extended
= 0;
1140 return compare32(&a
, &b
);
1143 struct tgsi_src_register_ext_mod
1144 tgsi_build_src_register_ext_mod(
1145 unsigned complement
,
1150 struct tgsi_token
*prev_token
,
1151 struct tgsi_instruction
*instruction
,
1152 struct tgsi_header
*header
)
1154 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1156 assert( complement
<= 1 );
1157 assert( bias
<= 1 );
1158 assert( scale_2x
<= 1 );
1159 assert( absolute
<= 1 );
1160 assert( negate
<= 1 );
1162 src_register_ext_mod
= tgsi_default_src_register_ext_mod();
1163 src_register_ext_mod
.Complement
= complement
;
1164 src_register_ext_mod
.Bias
= bias
;
1165 src_register_ext_mod
.Scale2X
= scale_2x
;
1166 src_register_ext_mod
.Absolute
= absolute
;
1167 src_register_ext_mod
.Negate
= negate
;
1169 prev_token
->Extended
= 1;
1170 instruction_grow( instruction
, header
);
1172 return src_register_ext_mod
;
1175 struct tgsi_dimension
1176 tgsi_default_dimension( void )
1178 struct tgsi_dimension dimension
;
1180 dimension
.Indirect
= 0;
1181 dimension
.Dimension
= 0;
1182 dimension
.Padding
= 0;
1183 dimension
.Index
= 0;
1184 dimension
.Extended
= 0;
1189 struct tgsi_dimension
1190 tgsi_build_dimension(
1193 struct tgsi_instruction
*instruction
,
1194 struct tgsi_header
*header
)
1196 struct tgsi_dimension dimension
;
1198 dimension
= tgsi_default_dimension();
1199 dimension
.Indirect
= indirect
;
1200 dimension
.Index
= index
;
1202 instruction_grow( instruction
, header
);
1207 struct tgsi_dst_register
1208 tgsi_default_dst_register( void )
1210 struct tgsi_dst_register dst_register
;
1212 dst_register
.File
= TGSI_FILE_NULL
;
1213 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1214 dst_register
.Indirect
= 0;
1215 dst_register
.Dimension
= 0;
1216 dst_register
.Index
= 0;
1217 dst_register
.Padding
= 0;
1218 dst_register
.Extended
= 0;
1220 return dst_register
;
1223 struct tgsi_dst_register
1224 tgsi_build_dst_register(
1229 struct tgsi_instruction
*instruction
,
1230 struct tgsi_header
*header
)
1232 struct tgsi_dst_register dst_register
;
1234 assert( file
< TGSI_FILE_COUNT
);
1235 assert( mask
<= TGSI_WRITEMASK_XYZW
);
1236 assert( index
>= -32768 && index
<= 32767 );
1238 dst_register
= tgsi_default_dst_register();
1239 dst_register
.File
= file
;
1240 dst_register
.WriteMask
= mask
;
1241 dst_register
.Index
= index
;
1242 dst_register
.Indirect
= indirect
;
1244 instruction_grow( instruction
, header
);
1246 return dst_register
;
1249 struct tgsi_full_dst_register
1250 tgsi_default_full_dst_register( void )
1252 struct tgsi_full_dst_register full_dst_register
;
1254 full_dst_register
.DstRegister
= tgsi_default_dst_register();
1255 full_dst_register
.DstRegisterInd
= tgsi_default_src_register();
1256 full_dst_register
.DstRegisterExtConcode
=
1257 tgsi_default_dst_register_ext_concode();
1258 full_dst_register
.DstRegisterExtModulate
=
1259 tgsi_default_dst_register_ext_modulate();
1261 return full_dst_register
;
1264 struct tgsi_dst_register_ext_concode
1265 tgsi_default_dst_register_ext_concode( void )
1267 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1269 dst_register_ext_concode
.Type
= TGSI_DST_REGISTER_EXT_TYPE_CONDCODE
;
1270 dst_register_ext_concode
.CondMask
= TGSI_CC_TR
;
1271 dst_register_ext_concode
.CondSwizzleX
= TGSI_SWIZZLE_X
;
1272 dst_register_ext_concode
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
1273 dst_register_ext_concode
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
1274 dst_register_ext_concode
.CondSwizzleW
= TGSI_SWIZZLE_W
;
1275 dst_register_ext_concode
.CondSrcIndex
= 0;
1276 dst_register_ext_concode
.Padding
= 0;
1277 dst_register_ext_concode
.Extended
= 0;
1279 return dst_register_ext_concode
;
1283 tgsi_compare_dst_register_ext_concode(
1284 struct tgsi_dst_register_ext_concode a
,
1285 struct tgsi_dst_register_ext_concode b
)
1287 a
.Padding
= b
.Padding
= 0;
1288 a
.Extended
= b
.Extended
= 0;
1289 return compare32(&a
, &b
);
1292 struct tgsi_dst_register_ext_concode
1293 tgsi_build_dst_register_ext_concode(
1300 struct tgsi_token
*prev_token
,
1301 struct tgsi_instruction
*instruction
,
1302 struct tgsi_header
*header
)
1304 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1306 assert( cc
<= TGSI_CC_FL
);
1307 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
1308 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
1309 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
1310 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
1311 assert( index
>= -32768 && index
<= 32767 );
1313 dst_register_ext_concode
= tgsi_default_dst_register_ext_concode();
1314 dst_register_ext_concode
.CondMask
= cc
;
1315 dst_register_ext_concode
.CondSwizzleX
= swizzle_x
;
1316 dst_register_ext_concode
.CondSwizzleY
= swizzle_y
;
1317 dst_register_ext_concode
.CondSwizzleZ
= swizzle_z
;
1318 dst_register_ext_concode
.CondSwizzleW
= swizzle_w
;
1319 dst_register_ext_concode
.CondSrcIndex
= index
;
1321 prev_token
->Extended
= 1;
1322 instruction_grow( instruction
, header
);
1324 return dst_register_ext_concode
;
1327 struct tgsi_dst_register_ext_modulate
1328 tgsi_default_dst_register_ext_modulate( void )
1330 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1332 dst_register_ext_modulate
.Type
= TGSI_DST_REGISTER_EXT_TYPE_MODULATE
;
1333 dst_register_ext_modulate
.Modulate
= TGSI_MODULATE_1X
;
1334 dst_register_ext_modulate
.Padding
= 0;
1335 dst_register_ext_modulate
.Extended
= 0;
1337 return dst_register_ext_modulate
;
1341 tgsi_compare_dst_register_ext_modulate(
1342 struct tgsi_dst_register_ext_modulate a
,
1343 struct tgsi_dst_register_ext_modulate b
)
1345 a
.Padding
= b
.Padding
= 0;
1346 a
.Extended
= b
.Extended
= 0;
1347 return compare32(&a
, &b
);
1350 struct tgsi_dst_register_ext_modulate
1351 tgsi_build_dst_register_ext_modulate(
1353 struct tgsi_token
*prev_token
,
1354 struct tgsi_instruction
*instruction
,
1355 struct tgsi_header
*header
)
1357 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1359 assert( modulate
<= TGSI_MODULATE_EIGHTH
);
1361 dst_register_ext_modulate
= tgsi_default_dst_register_ext_modulate();
1362 dst_register_ext_modulate
.Modulate
= modulate
;
1364 prev_token
->Extended
= 1;
1365 instruction_grow( instruction
, header
);
1367 return dst_register_ext_modulate
;