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
.Pointer
= (void *) 0;
345 struct tgsi_immediate
*immediate
,
346 struct tgsi_header
*header
)
348 assert( immediate
->NrTokens
< 0xFF );
350 immediate
->NrTokens
++;
352 header_bodysize_grow( header
);
355 struct tgsi_immediate_float32
356 tgsi_build_immediate_float32(
358 struct tgsi_immediate
*immediate
,
359 struct tgsi_header
*header
)
361 struct tgsi_immediate_float32 immediate_float32
;
363 immediate_float32
.Float
= value
;
365 immediate_grow( immediate
, header
);
367 return immediate_float32
;
371 tgsi_build_full_immediate(
372 const struct tgsi_full_immediate
*full_imm
,
373 struct tgsi_token
*tokens
,
374 struct tgsi_header
*header
,
377 unsigned size
= 0, i
;
378 struct tgsi_immediate
*immediate
;
380 if( maxsize
<= size
)
382 immediate
= (struct tgsi_immediate
*) &tokens
[size
];
385 *immediate
= tgsi_build_immediate( header
);
387 for( i
= 0; i
< full_imm
->Immediate
.NrTokens
- 1; i
++ ) {
388 struct tgsi_immediate_float32
*if32
;
390 if( maxsize
<= size
)
392 if32
= (struct tgsi_immediate_float32
*) &tokens
[size
];
395 *if32
= tgsi_build_immediate_float32(
396 full_imm
->u
.ImmediateFloat32
[i
].Float
,
408 struct tgsi_instruction
409 tgsi_default_instruction( void )
411 struct tgsi_instruction instruction
;
413 instruction
.Type
= TGSI_TOKEN_TYPE_INSTRUCTION
;
414 instruction
.NrTokens
= 1;
415 instruction
.Opcode
= TGSI_OPCODE_MOV
;
416 instruction
.Saturate
= TGSI_SAT_NONE
;
417 instruction
.NumDstRegs
= 1;
418 instruction
.NumSrcRegs
= 1;
419 instruction
.Padding
= 0;
420 instruction
.Extended
= 0;
425 struct tgsi_instruction
426 tgsi_build_instruction(
429 unsigned num_dst_regs
,
430 unsigned num_src_regs
,
431 struct tgsi_header
*header
)
433 struct tgsi_instruction instruction
;
435 assert (opcode
<= TGSI_OPCODE_LAST
);
436 assert (saturate
<= TGSI_SAT_MINUS_PLUS_ONE
);
437 assert (num_dst_regs
<= 3);
438 assert (num_src_regs
<= 15);
440 instruction
= tgsi_default_instruction();
441 instruction
.Opcode
= opcode
;
442 instruction
.Saturate
= saturate
;
443 instruction
.NumDstRegs
= num_dst_regs
;
444 instruction
.NumSrcRegs
= num_src_regs
;
446 header_bodysize_grow( header
);
453 struct tgsi_instruction
*instruction
,
454 struct tgsi_header
*header
)
456 assert (instruction
->NrTokens
< 0xFF);
458 instruction
->NrTokens
++;
460 header_bodysize_grow( header
);
463 struct tgsi_full_instruction
464 tgsi_default_full_instruction( void )
466 struct tgsi_full_instruction full_instruction
;
469 full_instruction
.Instruction
= tgsi_default_instruction();
470 full_instruction
.InstructionExtNv
= tgsi_default_instruction_ext_nv();
471 full_instruction
.InstructionExtLabel
= tgsi_default_instruction_ext_label();
472 full_instruction
.InstructionExtTexture
= tgsi_default_instruction_ext_texture();
473 for( i
= 0; i
< TGSI_FULL_MAX_DST_REGISTERS
; i
++ ) {
474 full_instruction
.FullDstRegisters
[i
] = tgsi_default_full_dst_register();
476 for( i
= 0; i
< TGSI_FULL_MAX_SRC_REGISTERS
; i
++ ) {
477 full_instruction
.FullSrcRegisters
[i
] = tgsi_default_full_src_register();
480 return full_instruction
;
484 tgsi_build_full_instruction(
485 const struct tgsi_full_instruction
*full_inst
,
486 struct tgsi_token
*tokens
,
487 struct tgsi_header
*header
,
492 struct tgsi_instruction
*instruction
;
493 struct tgsi_token
*prev_token
;
495 if( maxsize
<= size
)
497 instruction
= (struct tgsi_instruction
*) &tokens
[size
];
500 *instruction
= tgsi_build_instruction(
501 full_inst
->Instruction
.Opcode
,
502 full_inst
->Instruction
.Saturate
,
503 full_inst
->Instruction
.NumDstRegs
,
504 full_inst
->Instruction
.NumSrcRegs
,
506 prev_token
= (struct tgsi_token
*) instruction
;
508 if( tgsi_compare_instruction_ext_nv(
509 full_inst
->InstructionExtNv
,
510 tgsi_default_instruction_ext_nv() ) ) {
511 struct tgsi_instruction_ext_nv
*instruction_ext_nv
;
513 if( maxsize
<= size
)
516 (struct tgsi_instruction_ext_nv
*) &tokens
[size
];
519 *instruction_ext_nv
= tgsi_build_instruction_ext_nv(
520 full_inst
->InstructionExtNv
.Precision
,
521 full_inst
->InstructionExtNv
.CondDstIndex
,
522 full_inst
->InstructionExtNv
.CondFlowIndex
,
523 full_inst
->InstructionExtNv
.CondMask
,
524 full_inst
->InstructionExtNv
.CondSwizzleX
,
525 full_inst
->InstructionExtNv
.CondSwizzleY
,
526 full_inst
->InstructionExtNv
.CondSwizzleZ
,
527 full_inst
->InstructionExtNv
.CondSwizzleW
,
528 full_inst
->InstructionExtNv
.CondDstUpdate
,
529 full_inst
->InstructionExtNv
.CondFlowEnable
,
533 prev_token
= (struct tgsi_token
*) instruction_ext_nv
;
536 if( tgsi_compare_instruction_ext_label(
537 full_inst
->InstructionExtLabel
,
538 tgsi_default_instruction_ext_label() ) ) {
539 struct tgsi_instruction_ext_label
*instruction_ext_label
;
541 if( maxsize
<= size
)
543 instruction_ext_label
=
544 (struct tgsi_instruction_ext_label
*) &tokens
[size
];
547 *instruction_ext_label
= tgsi_build_instruction_ext_label(
548 full_inst
->InstructionExtLabel
.Label
,
552 prev_token
= (struct tgsi_token
*) instruction_ext_label
;
555 if( tgsi_compare_instruction_ext_texture(
556 full_inst
->InstructionExtTexture
,
557 tgsi_default_instruction_ext_texture() ) ) {
558 struct tgsi_instruction_ext_texture
*instruction_ext_texture
;
560 if( maxsize
<= size
)
562 instruction_ext_texture
=
563 (struct tgsi_instruction_ext_texture
*) &tokens
[size
];
566 *instruction_ext_texture
= tgsi_build_instruction_ext_texture(
567 full_inst
->InstructionExtTexture
.Texture
,
571 prev_token
= (struct tgsi_token
*) instruction_ext_texture
;
574 for( i
= 0; i
< full_inst
->Instruction
.NumDstRegs
; i
++ ) {
575 const struct tgsi_full_dst_register
*reg
= &full_inst
->FullDstRegisters
[i
];
576 struct tgsi_dst_register
*dst_register
;
577 struct tgsi_token
*prev_token
;
579 if( maxsize
<= size
)
581 dst_register
= (struct tgsi_dst_register
*) &tokens
[size
];
584 *dst_register
= tgsi_build_dst_register(
585 reg
->DstRegister
.File
,
586 reg
->DstRegister
.WriteMask
,
587 reg
->DstRegister
.Indirect
,
588 reg
->DstRegister
.Index
,
591 prev_token
= (struct tgsi_token
*) dst_register
;
593 if( tgsi_compare_dst_register_ext_concode(
594 reg
->DstRegisterExtConcode
,
595 tgsi_default_dst_register_ext_concode() ) ) {
596 struct tgsi_dst_register_ext_concode
*dst_register_ext_concode
;
598 if( maxsize
<= size
)
600 dst_register_ext_concode
=
601 (struct tgsi_dst_register_ext_concode
*) &tokens
[size
];
604 *dst_register_ext_concode
= tgsi_build_dst_register_ext_concode(
605 reg
->DstRegisterExtConcode
.CondMask
,
606 reg
->DstRegisterExtConcode
.CondSwizzleX
,
607 reg
->DstRegisterExtConcode
.CondSwizzleY
,
608 reg
->DstRegisterExtConcode
.CondSwizzleZ
,
609 reg
->DstRegisterExtConcode
.CondSwizzleW
,
610 reg
->DstRegisterExtConcode
.CondSrcIndex
,
614 prev_token
= (struct tgsi_token
*) dst_register_ext_concode
;
617 if( tgsi_compare_dst_register_ext_modulate(
618 reg
->DstRegisterExtModulate
,
619 tgsi_default_dst_register_ext_modulate() ) ) {
620 struct tgsi_dst_register_ext_modulate
*dst_register_ext_modulate
;
622 if( maxsize
<= size
)
624 dst_register_ext_modulate
=
625 (struct tgsi_dst_register_ext_modulate
*) &tokens
[size
];
628 *dst_register_ext_modulate
= tgsi_build_dst_register_ext_modulate(
629 reg
->DstRegisterExtModulate
.Modulate
,
633 prev_token
= (struct tgsi_token
*) dst_register_ext_modulate
;
636 if( reg
->DstRegister
.Indirect
) {
637 struct tgsi_src_register
*ind
;
639 if( maxsize
<= size
)
641 ind
= (struct tgsi_src_register
*) &tokens
[size
];
644 *ind
= tgsi_build_src_register(
645 reg
->DstRegisterInd
.File
,
646 reg
->DstRegisterInd
.SwizzleX
,
647 reg
->DstRegisterInd
.SwizzleY
,
648 reg
->DstRegisterInd
.SwizzleZ
,
649 reg
->DstRegisterInd
.SwizzleW
,
650 reg
->DstRegisterInd
.Negate
,
651 reg
->DstRegisterInd
.Indirect
,
652 reg
->DstRegisterInd
.Dimension
,
653 reg
->DstRegisterInd
.Index
,
659 for( i
= 0; i
< full_inst
->Instruction
.NumSrcRegs
; i
++ ) {
660 const struct tgsi_full_src_register
*reg
= &full_inst
->FullSrcRegisters
[i
];
661 struct tgsi_src_register
*src_register
;
662 struct tgsi_token
*prev_token
;
664 if( maxsize
<= size
)
666 src_register
= (struct tgsi_src_register
*) &tokens
[size
];
669 *src_register
= tgsi_build_src_register(
670 reg
->SrcRegister
.File
,
671 reg
->SrcRegister
.SwizzleX
,
672 reg
->SrcRegister
.SwizzleY
,
673 reg
->SrcRegister
.SwizzleZ
,
674 reg
->SrcRegister
.SwizzleW
,
675 reg
->SrcRegister
.Negate
,
676 reg
->SrcRegister
.Indirect
,
677 reg
->SrcRegister
.Dimension
,
678 reg
->SrcRegister
.Index
,
681 prev_token
= (struct tgsi_token
*) src_register
;
683 if( tgsi_compare_src_register_ext_swz(
684 reg
->SrcRegisterExtSwz
,
685 tgsi_default_src_register_ext_swz() ) ) {
686 struct tgsi_src_register_ext_swz
*src_register_ext_swz
;
688 /* Use of the extended swizzle requires the simple swizzle to be identity.
690 assert( reg
->SrcRegister
.SwizzleX
== TGSI_SWIZZLE_X
);
691 assert( reg
->SrcRegister
.SwizzleY
== TGSI_SWIZZLE_Y
);
692 assert( reg
->SrcRegister
.SwizzleZ
== TGSI_SWIZZLE_Z
);
693 assert( reg
->SrcRegister
.SwizzleW
== TGSI_SWIZZLE_W
);
694 assert( reg
->SrcRegister
.Negate
== FALSE
);
696 if( maxsize
<= size
)
698 src_register_ext_swz
=
699 (struct tgsi_src_register_ext_swz
*) &tokens
[size
];
702 *src_register_ext_swz
= tgsi_build_src_register_ext_swz(
703 reg
->SrcRegisterExtSwz
.ExtSwizzleX
,
704 reg
->SrcRegisterExtSwz
.ExtSwizzleY
,
705 reg
->SrcRegisterExtSwz
.ExtSwizzleZ
,
706 reg
->SrcRegisterExtSwz
.ExtSwizzleW
,
707 reg
->SrcRegisterExtSwz
.NegateX
,
708 reg
->SrcRegisterExtSwz
.NegateY
,
709 reg
->SrcRegisterExtSwz
.NegateZ
,
710 reg
->SrcRegisterExtSwz
.NegateW
,
714 prev_token
= (struct tgsi_token
*) src_register_ext_swz
;
717 if( tgsi_compare_src_register_ext_mod(
718 reg
->SrcRegisterExtMod
,
719 tgsi_default_src_register_ext_mod() ) ) {
720 struct tgsi_src_register_ext_mod
*src_register_ext_mod
;
722 if( maxsize
<= size
)
724 src_register_ext_mod
=
725 (struct tgsi_src_register_ext_mod
*) &tokens
[size
];
728 *src_register_ext_mod
= tgsi_build_src_register_ext_mod(
729 reg
->SrcRegisterExtMod
.Complement
,
730 reg
->SrcRegisterExtMod
.Bias
,
731 reg
->SrcRegisterExtMod
.Scale2X
,
732 reg
->SrcRegisterExtMod
.Absolute
,
733 reg
->SrcRegisterExtMod
.Negate
,
737 prev_token
= (struct tgsi_token
*) src_register_ext_mod
;
740 if( reg
->SrcRegister
.Indirect
) {
741 struct tgsi_src_register
*ind
;
743 if( maxsize
<= size
)
745 ind
= (struct tgsi_src_register
*) &tokens
[size
];
748 *ind
= tgsi_build_src_register(
749 reg
->SrcRegisterInd
.File
,
750 reg
->SrcRegisterInd
.SwizzleX
,
751 reg
->SrcRegisterInd
.SwizzleY
,
752 reg
->SrcRegisterInd
.SwizzleZ
,
753 reg
->SrcRegisterInd
.SwizzleW
,
754 reg
->SrcRegisterInd
.Negate
,
755 reg
->SrcRegisterInd
.Indirect
,
756 reg
->SrcRegisterInd
.Dimension
,
757 reg
->SrcRegisterInd
.Index
,
762 if( reg
->SrcRegister
.Dimension
) {
763 struct tgsi_dimension
*dim
;
765 assert( !reg
->SrcRegisterDim
.Dimension
);
767 if( maxsize
<= size
)
769 dim
= (struct tgsi_dimension
*) &tokens
[size
];
772 *dim
= tgsi_build_dimension(
773 reg
->SrcRegisterDim
.Indirect
,
774 reg
->SrcRegisterDim
.Index
,
778 if( reg
->SrcRegisterDim
.Indirect
) {
779 struct tgsi_src_register
*ind
;
781 if( maxsize
<= size
)
783 ind
= (struct tgsi_src_register
*) &tokens
[size
];
786 *ind
= tgsi_build_src_register(
787 reg
->SrcRegisterDimInd
.File
,
788 reg
->SrcRegisterDimInd
.SwizzleX
,
789 reg
->SrcRegisterDimInd
.SwizzleY
,
790 reg
->SrcRegisterDimInd
.SwizzleZ
,
791 reg
->SrcRegisterDimInd
.SwizzleW
,
792 reg
->SrcRegisterDimInd
.Negate
,
793 reg
->SrcRegisterDimInd
.Indirect
,
794 reg
->SrcRegisterDimInd
.Dimension
,
795 reg
->SrcRegisterDimInd
.Index
,
805 struct tgsi_instruction_ext_nv
806 tgsi_default_instruction_ext_nv( void )
808 struct tgsi_instruction_ext_nv instruction_ext_nv
;
810 instruction_ext_nv
.Type
= TGSI_INSTRUCTION_EXT_TYPE_NV
;
811 instruction_ext_nv
.Precision
= TGSI_PRECISION_DEFAULT
;
812 instruction_ext_nv
.CondDstIndex
= 0;
813 instruction_ext_nv
.CondFlowIndex
= 0;
814 instruction_ext_nv
.CondMask
= TGSI_CC_TR
;
815 instruction_ext_nv
.CondSwizzleX
= TGSI_SWIZZLE_X
;
816 instruction_ext_nv
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
817 instruction_ext_nv
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
818 instruction_ext_nv
.CondSwizzleW
= TGSI_SWIZZLE_W
;
819 instruction_ext_nv
.CondDstUpdate
= 0;
820 instruction_ext_nv
.CondFlowEnable
= 0;
821 instruction_ext_nv
.Padding
= 0;
822 instruction_ext_nv
.Extended
= 0;
824 return instruction_ext_nv
;
828 /** test for inequality of 32-bit values pointed to by a and b */
829 static INLINE boolean
830 compare32(const void *a
, const void *b
)
832 return *((uint32_t *) a
) != *((uint32_t *) b
);
837 tgsi_compare_instruction_ext_nv(
838 struct tgsi_instruction_ext_nv a
,
839 struct tgsi_instruction_ext_nv b
)
841 a
.Padding
= b
.Padding
= 0;
842 a
.Extended
= b
.Extended
= 0;
843 return compare32(&a
, &b
);
846 struct tgsi_instruction_ext_nv
847 tgsi_build_instruction_ext_nv(
849 unsigned cond_dst_index
,
850 unsigned cond_flow_index
,
852 unsigned cond_swizzle_x
,
853 unsigned cond_swizzle_y
,
854 unsigned cond_swizzle_z
,
855 unsigned cond_swizzle_w
,
856 unsigned cond_dst_update
,
857 unsigned cond_flow_enable
,
858 struct tgsi_token
*prev_token
,
859 struct tgsi_instruction
*instruction
,
860 struct tgsi_header
*header
)
862 struct tgsi_instruction_ext_nv instruction_ext_nv
;
864 instruction_ext_nv
= tgsi_default_instruction_ext_nv();
865 instruction_ext_nv
.Precision
= precision
;
866 instruction_ext_nv
.CondDstIndex
= cond_dst_index
;
867 instruction_ext_nv
.CondFlowIndex
= cond_flow_index
;
868 instruction_ext_nv
.CondMask
= cond_mask
;
869 instruction_ext_nv
.CondSwizzleX
= cond_swizzle_x
;
870 instruction_ext_nv
.CondSwizzleY
= cond_swizzle_y
;
871 instruction_ext_nv
.CondSwizzleZ
= cond_swizzle_z
;
872 instruction_ext_nv
.CondSwizzleW
= cond_swizzle_w
;
873 instruction_ext_nv
.CondDstUpdate
= cond_dst_update
;
874 instruction_ext_nv
.CondFlowEnable
= cond_flow_enable
;
876 prev_token
->Extended
= 1;
877 instruction_grow( instruction
, header
);
879 return instruction_ext_nv
;
882 struct tgsi_instruction_ext_label
883 tgsi_default_instruction_ext_label( void )
885 struct tgsi_instruction_ext_label instruction_ext_label
;
887 instruction_ext_label
.Type
= TGSI_INSTRUCTION_EXT_TYPE_LABEL
;
888 instruction_ext_label
.Label
= 0;
889 instruction_ext_label
.Padding
= 0;
890 instruction_ext_label
.Extended
= 0;
892 return instruction_ext_label
;
896 tgsi_compare_instruction_ext_label(
897 struct tgsi_instruction_ext_label a
,
898 struct tgsi_instruction_ext_label b
)
900 a
.Padding
= b
.Padding
= 0;
901 a
.Extended
= b
.Extended
= 0;
902 return compare32(&a
, &b
);
905 struct tgsi_instruction_ext_label
906 tgsi_build_instruction_ext_label(
908 struct tgsi_token
*prev_token
,
909 struct tgsi_instruction
*instruction
,
910 struct tgsi_header
*header
)
912 struct tgsi_instruction_ext_label instruction_ext_label
;
914 instruction_ext_label
= tgsi_default_instruction_ext_label();
915 instruction_ext_label
.Label
= label
;
917 prev_token
->Extended
= 1;
918 instruction_grow( instruction
, header
);
920 return instruction_ext_label
;
923 struct tgsi_instruction_ext_texture
924 tgsi_default_instruction_ext_texture( void )
926 struct tgsi_instruction_ext_texture instruction_ext_texture
;
928 instruction_ext_texture
.Type
= TGSI_INSTRUCTION_EXT_TYPE_TEXTURE
;
929 instruction_ext_texture
.Texture
= TGSI_TEXTURE_UNKNOWN
;
930 instruction_ext_texture
.Padding
= 0;
931 instruction_ext_texture
.Extended
= 0;
933 return instruction_ext_texture
;
937 tgsi_compare_instruction_ext_texture(
938 struct tgsi_instruction_ext_texture a
,
939 struct tgsi_instruction_ext_texture b
)
941 a
.Padding
= b
.Padding
= 0;
942 a
.Extended
= b
.Extended
= 0;
943 return compare32(&a
, &b
);
946 struct tgsi_instruction_ext_texture
947 tgsi_build_instruction_ext_texture(
949 struct tgsi_token
*prev_token
,
950 struct tgsi_instruction
*instruction
,
951 struct tgsi_header
*header
)
953 struct tgsi_instruction_ext_texture instruction_ext_texture
;
955 instruction_ext_texture
= tgsi_default_instruction_ext_texture();
956 instruction_ext_texture
.Texture
= texture
;
958 prev_token
->Extended
= 1;
959 instruction_grow( instruction
, header
);
961 return instruction_ext_texture
;
964 struct tgsi_src_register
965 tgsi_default_src_register( void )
967 struct tgsi_src_register src_register
;
969 src_register
.File
= TGSI_FILE_NULL
;
970 src_register
.SwizzleX
= TGSI_SWIZZLE_X
;
971 src_register
.SwizzleY
= TGSI_SWIZZLE_Y
;
972 src_register
.SwizzleZ
= TGSI_SWIZZLE_Z
;
973 src_register
.SwizzleW
= TGSI_SWIZZLE_W
;
974 src_register
.Negate
= 0;
975 src_register
.Indirect
= 0;
976 src_register
.Dimension
= 0;
977 src_register
.Index
= 0;
978 src_register
.Extended
= 0;
983 struct tgsi_src_register
984 tgsi_build_src_register(
994 struct tgsi_instruction
*instruction
,
995 struct tgsi_header
*header
)
997 struct tgsi_src_register src_register
;
999 assert( file
< TGSI_FILE_COUNT
);
1000 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
1001 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
1002 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
1003 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
1004 assert( negate
<= 1 );
1005 assert( index
>= -0x8000 && index
<= 0x7FFF );
1007 src_register
= tgsi_default_src_register();
1008 src_register
.File
= file
;
1009 src_register
.SwizzleX
= swizzle_x
;
1010 src_register
.SwizzleY
= swizzle_y
;
1011 src_register
.SwizzleZ
= swizzle_z
;
1012 src_register
.SwizzleW
= swizzle_w
;
1013 src_register
.Negate
= negate
;
1014 src_register
.Indirect
= indirect
;
1015 src_register
.Dimension
= dimension
;
1016 src_register
.Index
= index
;
1018 instruction_grow( instruction
, header
);
1020 return src_register
;
1023 struct tgsi_full_src_register
1024 tgsi_default_full_src_register( void )
1026 struct tgsi_full_src_register full_src_register
;
1028 full_src_register
.SrcRegister
= tgsi_default_src_register();
1029 full_src_register
.SrcRegisterExtSwz
= tgsi_default_src_register_ext_swz();
1030 full_src_register
.SrcRegisterExtMod
= tgsi_default_src_register_ext_mod();
1031 full_src_register
.SrcRegisterInd
= tgsi_default_src_register();
1032 full_src_register
.SrcRegisterDim
= tgsi_default_dimension();
1033 full_src_register
.SrcRegisterDimInd
= tgsi_default_src_register();
1035 return full_src_register
;
1038 struct tgsi_src_register_ext_swz
1039 tgsi_default_src_register_ext_swz( void )
1041 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1043 src_register_ext_swz
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_SWZ
;
1044 src_register_ext_swz
.ExtSwizzleX
= TGSI_EXTSWIZZLE_X
;
1045 src_register_ext_swz
.ExtSwizzleY
= TGSI_EXTSWIZZLE_Y
;
1046 src_register_ext_swz
.ExtSwizzleZ
= TGSI_EXTSWIZZLE_Z
;
1047 src_register_ext_swz
.ExtSwizzleW
= TGSI_EXTSWIZZLE_W
;
1048 src_register_ext_swz
.NegateX
= 0;
1049 src_register_ext_swz
.NegateY
= 0;
1050 src_register_ext_swz
.NegateZ
= 0;
1051 src_register_ext_swz
.NegateW
= 0;
1052 src_register_ext_swz
.Padding
= 0;
1053 src_register_ext_swz
.Extended
= 0;
1055 return src_register_ext_swz
;
1059 tgsi_compare_src_register_ext_swz(
1060 struct tgsi_src_register_ext_swz a
,
1061 struct tgsi_src_register_ext_swz b
)
1063 a
.Padding
= b
.Padding
= 0;
1064 a
.Extended
= b
.Extended
= 0;
1065 return compare32(&a
, &b
);
1068 struct tgsi_src_register_ext_swz
1069 tgsi_build_src_register_ext_swz(
1070 unsigned ext_swizzle_x
,
1071 unsigned ext_swizzle_y
,
1072 unsigned ext_swizzle_z
,
1073 unsigned ext_swizzle_w
,
1078 struct tgsi_token
*prev_token
,
1079 struct tgsi_instruction
*instruction
,
1080 struct tgsi_header
*header
)
1082 struct tgsi_src_register_ext_swz src_register_ext_swz
;
1084 assert( ext_swizzle_x
<= TGSI_EXTSWIZZLE_ONE
);
1085 assert( ext_swizzle_y
<= TGSI_EXTSWIZZLE_ONE
);
1086 assert( ext_swizzle_z
<= TGSI_EXTSWIZZLE_ONE
);
1087 assert( ext_swizzle_w
<= TGSI_EXTSWIZZLE_ONE
);
1088 assert( negate_x
<= 1 );
1089 assert( negate_y
<= 1 );
1090 assert( negate_z
<= 1 );
1091 assert( negate_w
<= 1 );
1093 src_register_ext_swz
= tgsi_default_src_register_ext_swz();
1094 src_register_ext_swz
.ExtSwizzleX
= ext_swizzle_x
;
1095 src_register_ext_swz
.ExtSwizzleY
= ext_swizzle_y
;
1096 src_register_ext_swz
.ExtSwizzleZ
= ext_swizzle_z
;
1097 src_register_ext_swz
.ExtSwizzleW
= ext_swizzle_w
;
1098 src_register_ext_swz
.NegateX
= negate_x
;
1099 src_register_ext_swz
.NegateY
= negate_y
;
1100 src_register_ext_swz
.NegateZ
= negate_z
;
1101 src_register_ext_swz
.NegateW
= negate_w
;
1103 prev_token
->Extended
= 1;
1104 instruction_grow( instruction
, header
);
1106 return src_register_ext_swz
;
1109 struct tgsi_src_register_ext_mod
1110 tgsi_default_src_register_ext_mod( void )
1112 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1114 src_register_ext_mod
.Type
= TGSI_SRC_REGISTER_EXT_TYPE_MOD
;
1115 src_register_ext_mod
.Complement
= 0;
1116 src_register_ext_mod
.Bias
= 0;
1117 src_register_ext_mod
.Scale2X
= 0;
1118 src_register_ext_mod
.Absolute
= 0;
1119 src_register_ext_mod
.Negate
= 0;
1120 src_register_ext_mod
.Padding
= 0;
1121 src_register_ext_mod
.Extended
= 0;
1123 return src_register_ext_mod
;
1127 tgsi_compare_src_register_ext_mod(
1128 struct tgsi_src_register_ext_mod a
,
1129 struct tgsi_src_register_ext_mod b
)
1131 a
.Padding
= b
.Padding
= 0;
1132 a
.Extended
= b
.Extended
= 0;
1133 return compare32(&a
, &b
);
1136 struct tgsi_src_register_ext_mod
1137 tgsi_build_src_register_ext_mod(
1138 unsigned complement
,
1143 struct tgsi_token
*prev_token
,
1144 struct tgsi_instruction
*instruction
,
1145 struct tgsi_header
*header
)
1147 struct tgsi_src_register_ext_mod src_register_ext_mod
;
1149 assert( complement
<= 1 );
1150 assert( bias
<= 1 );
1151 assert( scale_2x
<= 1 );
1152 assert( absolute
<= 1 );
1153 assert( negate
<= 1 );
1155 src_register_ext_mod
= tgsi_default_src_register_ext_mod();
1156 src_register_ext_mod
.Complement
= complement
;
1157 src_register_ext_mod
.Bias
= bias
;
1158 src_register_ext_mod
.Scale2X
= scale_2x
;
1159 src_register_ext_mod
.Absolute
= absolute
;
1160 src_register_ext_mod
.Negate
= negate
;
1162 prev_token
->Extended
= 1;
1163 instruction_grow( instruction
, header
);
1165 return src_register_ext_mod
;
1168 struct tgsi_dimension
1169 tgsi_default_dimension( void )
1171 struct tgsi_dimension dimension
;
1173 dimension
.Indirect
= 0;
1174 dimension
.Dimension
= 0;
1175 dimension
.Padding
= 0;
1176 dimension
.Index
= 0;
1177 dimension
.Extended
= 0;
1182 struct tgsi_dimension
1183 tgsi_build_dimension(
1186 struct tgsi_instruction
*instruction
,
1187 struct tgsi_header
*header
)
1189 struct tgsi_dimension dimension
;
1191 dimension
= tgsi_default_dimension();
1192 dimension
.Indirect
= indirect
;
1193 dimension
.Index
= index
;
1195 instruction_grow( instruction
, header
);
1200 struct tgsi_dst_register
1201 tgsi_default_dst_register( void )
1203 struct tgsi_dst_register dst_register
;
1205 dst_register
.File
= TGSI_FILE_NULL
;
1206 dst_register
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1207 dst_register
.Indirect
= 0;
1208 dst_register
.Dimension
= 0;
1209 dst_register
.Index
= 0;
1210 dst_register
.Padding
= 0;
1211 dst_register
.Extended
= 0;
1213 return dst_register
;
1216 struct tgsi_dst_register
1217 tgsi_build_dst_register(
1222 struct tgsi_instruction
*instruction
,
1223 struct tgsi_header
*header
)
1225 struct tgsi_dst_register dst_register
;
1227 assert( file
< TGSI_FILE_COUNT
);
1228 assert( mask
<= TGSI_WRITEMASK_XYZW
);
1229 assert( index
>= -32768 && index
<= 32767 );
1231 dst_register
= tgsi_default_dst_register();
1232 dst_register
.File
= file
;
1233 dst_register
.WriteMask
= mask
;
1234 dst_register
.Index
= index
;
1235 dst_register
.Indirect
= indirect
;
1237 instruction_grow( instruction
, header
);
1239 return dst_register
;
1242 struct tgsi_full_dst_register
1243 tgsi_default_full_dst_register( void )
1245 struct tgsi_full_dst_register full_dst_register
;
1247 full_dst_register
.DstRegister
= tgsi_default_dst_register();
1248 full_dst_register
.DstRegisterInd
= tgsi_default_src_register();
1249 full_dst_register
.DstRegisterExtConcode
=
1250 tgsi_default_dst_register_ext_concode();
1251 full_dst_register
.DstRegisterExtModulate
=
1252 tgsi_default_dst_register_ext_modulate();
1254 return full_dst_register
;
1257 struct tgsi_dst_register_ext_concode
1258 tgsi_default_dst_register_ext_concode( void )
1260 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1262 dst_register_ext_concode
.Type
= TGSI_DST_REGISTER_EXT_TYPE_CONDCODE
;
1263 dst_register_ext_concode
.CondMask
= TGSI_CC_TR
;
1264 dst_register_ext_concode
.CondSwizzleX
= TGSI_SWIZZLE_X
;
1265 dst_register_ext_concode
.CondSwizzleY
= TGSI_SWIZZLE_Y
;
1266 dst_register_ext_concode
.CondSwizzleZ
= TGSI_SWIZZLE_Z
;
1267 dst_register_ext_concode
.CondSwizzleW
= TGSI_SWIZZLE_W
;
1268 dst_register_ext_concode
.CondSrcIndex
= 0;
1269 dst_register_ext_concode
.Padding
= 0;
1270 dst_register_ext_concode
.Extended
= 0;
1272 return dst_register_ext_concode
;
1276 tgsi_compare_dst_register_ext_concode(
1277 struct tgsi_dst_register_ext_concode a
,
1278 struct tgsi_dst_register_ext_concode b
)
1280 a
.Padding
= b
.Padding
= 0;
1281 a
.Extended
= b
.Extended
= 0;
1282 return compare32(&a
, &b
);
1285 struct tgsi_dst_register_ext_concode
1286 tgsi_build_dst_register_ext_concode(
1293 struct tgsi_token
*prev_token
,
1294 struct tgsi_instruction
*instruction
,
1295 struct tgsi_header
*header
)
1297 struct tgsi_dst_register_ext_concode dst_register_ext_concode
;
1299 assert( cc
<= TGSI_CC_FL
);
1300 assert( swizzle_x
<= TGSI_SWIZZLE_W
);
1301 assert( swizzle_y
<= TGSI_SWIZZLE_W
);
1302 assert( swizzle_z
<= TGSI_SWIZZLE_W
);
1303 assert( swizzle_w
<= TGSI_SWIZZLE_W
);
1304 assert( index
>= -32768 && index
<= 32767 );
1306 dst_register_ext_concode
= tgsi_default_dst_register_ext_concode();
1307 dst_register_ext_concode
.CondMask
= cc
;
1308 dst_register_ext_concode
.CondSwizzleX
= swizzle_x
;
1309 dst_register_ext_concode
.CondSwizzleY
= swizzle_y
;
1310 dst_register_ext_concode
.CondSwizzleZ
= swizzle_z
;
1311 dst_register_ext_concode
.CondSwizzleW
= swizzle_w
;
1312 dst_register_ext_concode
.CondSrcIndex
= index
;
1314 prev_token
->Extended
= 1;
1315 instruction_grow( instruction
, header
);
1317 return dst_register_ext_concode
;
1320 struct tgsi_dst_register_ext_modulate
1321 tgsi_default_dst_register_ext_modulate( void )
1323 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1325 dst_register_ext_modulate
.Type
= TGSI_DST_REGISTER_EXT_TYPE_MODULATE
;
1326 dst_register_ext_modulate
.Modulate
= TGSI_MODULATE_1X
;
1327 dst_register_ext_modulate
.Padding
= 0;
1328 dst_register_ext_modulate
.Extended
= 0;
1330 return dst_register_ext_modulate
;
1334 tgsi_compare_dst_register_ext_modulate(
1335 struct tgsi_dst_register_ext_modulate a
,
1336 struct tgsi_dst_register_ext_modulate b
)
1338 a
.Padding
= b
.Padding
= 0;
1339 a
.Extended
= b
.Extended
= 0;
1340 return compare32(&a
, &b
);
1343 struct tgsi_dst_register_ext_modulate
1344 tgsi_build_dst_register_ext_modulate(
1346 struct tgsi_token
*prev_token
,
1347 struct tgsi_instruction
*instruction
,
1348 struct tgsi_header
*header
)
1350 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate
;
1352 assert( modulate
<= TGSI_MODULATE_EIGHTH
);
1354 dst_register_ext_modulate
= tgsi_default_dst_register_ext_modulate();
1355 dst_register_ext_modulate
.Modulate
= modulate
;
1357 prev_token
->Extended
= 1;
1358 instruction_grow( instruction
, header
);
1360 return dst_register_ext_modulate
;