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 **************************************************************************/
34 #include "tgsi_platform.h"
35 #include "pipe/tgsi/exec/tgsi_core.h"
36 #include "st_mesa_to_tgsi.h"
37 #include "shader/prog_parameter.h"
41 #define EMIT_IMMEDIATES 0
45 * Map mesa register file to TGSI register file.
49 enum register_file file
)
52 case PROGRAM_UNDEFINED
:
53 return TGSI_FILE_NULL
;
54 case PROGRAM_TEMPORARY
:
55 return TGSI_FILE_TEMPORARY
;
56 //case PROGRAM_LOCAL_PARAM:
57 //case PROGRAM_ENV_PARAM:
58 case PROGRAM_STATE_VAR
:
59 case PROGRAM_NAMED_PARAM
:
61 return TGSI_FILE_CONSTANT
;
62 case PROGRAM_CONSTANT
:
64 return TGSI_FILE_IMMEDIATE
;
66 return TGSI_FILE_CONSTANT
;
69 return TGSI_FILE_INPUT
;
71 return TGSI_FILE_OUTPUT
;
73 return TGSI_FILE_ADDRESS
;
76 return TGSI_FILE_NULL
;
81 * Map mesa register file index to TGSI index.
82 * Take special care when processing input and output indices.
83 * \param file one of TGSI_FILE_x
84 * \param index the mesa register file index
85 * \param inputMapping maps Mesa input indexes to TGSI input indexes
86 * \param outputMapping maps Mesa output indexes to TGSI output indexes
89 map_register_file_index(
92 const GLuint inputMapping
[],
93 const GLuint outputMapping
[],
94 const GLuint immediateMapping
[])
98 /* inputs are mapped according to the user-defined map */
99 return inputMapping
[index
];
101 case TGSI_FILE_OUTPUT
:
102 return outputMapping
[index
];
105 case TGSI_FILE_IMMEDIATE
:
106 return immediateMapping
[index
];
115 * Map mesa texture target to TGSI texture target.
121 switch( textarget
) {
122 case TEXTURE_1D_INDEX
:
123 return TGSI_TEXTURE_1D
;
124 case TEXTURE_2D_INDEX
:
125 return TGSI_TEXTURE_2D
;
126 case TEXTURE_3D_INDEX
:
127 return TGSI_TEXTURE_3D
;
128 case TEXTURE_CUBE_INDEX
:
129 return TGSI_TEXTURE_CUBE
;
130 case TEXTURE_RECT_INDEX
:
131 return TGSI_TEXTURE_RECT
;
136 return TGSI_TEXTURE_1D
;
145 return TGSI_SAT_NONE
;
146 case SATURATE_ZERO_ONE
:
147 return TGSI_SAT_ZERO_ONE
;
148 case SATURATE_PLUS_MINUS_ONE
:
149 return TGSI_SAT_MINUS_PLUS_ONE
;
152 return TGSI_SAT_NONE
;
160 assert( WRITEMASK_X
== TGSI_WRITEMASK_X
);
161 assert( WRITEMASK_Y
== TGSI_WRITEMASK_Y
);
162 assert( WRITEMASK_Z
== TGSI_WRITEMASK_Z
);
163 assert( WRITEMASK_W
== TGSI_WRITEMASK_W
);
164 assert( (writemask
& ~TGSI_WRITEMASK_XYZW
) == 0 );
170 static struct tgsi_full_immediate
171 make_immediate(const float *value
, uint size
)
173 struct tgsi_full_immediate imm
;
174 imm
.Immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
175 imm
.Immediate
.Size
= 1 + size
; /* one for the token itself */
176 imm
.Immediate
.DataType
= TGSI_IMM_FLOAT32
;
177 imm
.u
.ImmediateFloat32
= (struct tgsi_immediate_float32
*) value
;
184 const struct prog_instruction
*inst
,
185 struct tgsi_full_instruction
*fullinst
,
186 const GLuint inputMapping
[],
187 const GLuint outputMapping
[],
188 const GLuint immediateMapping
[],
189 GLuint preamble_size
,
193 struct tgsi_full_dst_register
*fulldst
;
194 struct tgsi_full_src_register
*fullsrc
;
196 *fullinst
= tgsi_default_full_instruction();
198 fullinst
->Instruction
.Saturate
= convert_sat( inst
->SaturateMode
);
199 fullinst
->Instruction
.NumDstRegs
= _mesa_num_inst_dst_regs( inst
->Opcode
);
200 fullinst
->Instruction
.NumSrcRegs
= _mesa_num_inst_src_regs( inst
->Opcode
);
202 fulldst
= &fullinst
->FullDstRegisters
[0];
203 fulldst
->DstRegister
.File
= map_register_file( inst
->DstReg
.File
);
204 fulldst
->DstRegister
.Index
= map_register_file_index(
205 fulldst
->DstRegister
.File
,
211 fulldst
->DstRegister
.WriteMask
= convert_writemask( inst
->DstReg
.WriteMask
);
213 for( i
= 0; i
< fullinst
->Instruction
.NumSrcRegs
; i
++ ) {
216 fullsrc
= &fullinst
->FullSrcRegisters
[i
];
217 fullsrc
->SrcRegister
.File
= map_register_file( inst
->SrcReg
[i
].File
);
218 fullsrc
->SrcRegister
.Index
= map_register_file_index(
219 fullsrc
->SrcRegister
.File
,
220 inst
->SrcReg
[i
].Index
,
225 for( j
= 0; j
< 4; j
++ ) {
228 swz
= GET_SWZ( inst
->SrcReg
[i
].Swizzle
, j
);
229 if( swz
> SWIZZLE_W
) {
230 tgsi_util_set_src_register_extswizzle(
231 &fullsrc
->SrcRegisterExtSwz
,
236 tgsi_util_set_src_register_swizzle(
237 &fullsrc
->SrcRegister
,
243 if( inst
->SrcReg
[i
].NegateBase
== NEGATE_XYZW
) {
244 fullsrc
->SrcRegister
.Negate
= 1;
246 else if( inst
->SrcReg
[i
].NegateBase
!= NEGATE_NONE
) {
247 if( inst
->SrcReg
[i
].NegateBase
& NEGATE_X
) {
248 fullsrc
->SrcRegisterExtSwz
.NegateX
= 1;
250 if( inst
->SrcReg
[i
].NegateBase
& NEGATE_Y
) {
251 fullsrc
->SrcRegisterExtSwz
.NegateY
= 1;
253 if( inst
->SrcReg
[i
].NegateBase
& NEGATE_Z
) {
254 fullsrc
->SrcRegisterExtSwz
.NegateZ
= 1;
256 if( inst
->SrcReg
[i
].NegateBase
& NEGATE_W
) {
257 fullsrc
->SrcRegisterExtSwz
.NegateW
= 1;
261 if( inst
->SrcReg
[i
].Abs
) {
262 fullsrc
->SrcRegisterExtMod
.Absolute
= 1;
265 if( inst
->SrcReg
[i
].NegateAbs
) {
266 fullsrc
->SrcRegisterExtMod
.Negate
= 1;
269 if( inst
->SrcReg
[i
].RelAddr
) {
270 fullsrc
->SrcRegister
.Indirect
= 1;
272 fullsrc
->SrcRegisterInd
.File
= TGSI_FILE_ADDRESS
;
273 fullsrc
->SrcRegisterInd
.Index
= 0;
277 switch( inst
->Opcode
) {
279 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ARL
;
282 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ABS
;
285 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ADD
;
288 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_BGNLOOP2
;
289 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
292 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_BGNSUB
;
295 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_BRA
;
298 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_BRK
;
301 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_CAL
;
302 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
305 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_CMP
;
308 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_CONT
;
311 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_COS
;
314 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DDX
;
317 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DDY
;
320 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DP3
;
323 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DP4
;
326 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DPH
;
329 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DST
;
332 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ELSE
;
333 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
336 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ENDIF
;
339 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ENDLOOP2
;
340 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
343 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ENDSUB
;
346 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_EX2
;
349 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_EXP
;
352 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_FLR
;
355 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_FRC
;
358 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_IF
;
359 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
362 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_INT
;
365 /* predicated w/ a register */
366 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_KILP
;
370 assert(inst
->DstReg
.CondMask
== COND_TR
);
371 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_KIL
;
374 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_LG2
;
377 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_LOG
;
380 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_LIT
;
383 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_LRP
;
386 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MAD
;
389 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MAX
;
392 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MIN
;
395 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MOV
;
398 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MUL
;
401 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOISE1
;
404 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOISE2
;
407 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOISE3
;
410 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOISE4
;
413 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOP
;
416 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_POW
;
419 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_RCP
;
422 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_RET
;
425 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_RSQ
;
426 tgsi_util_set_full_src_register_sign_mode(
427 &fullinst
->FullSrcRegisters
[0],
428 TGSI_UTIL_SIGN_CLEAR
);
431 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SCS
;
432 fulldst
->DstRegister
.WriteMask
&= TGSI_WRITEMASK_XY
;
435 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SEQ
;
438 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SGE
;
441 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SGT
;
444 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SIN
;
447 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SLE
;
450 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SLT
;
453 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SNE
;
456 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SUB
;
459 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SWZ
;
462 /* ordinary texture lookup */
463 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TEX
;
464 fullinst
->Instruction
.NumSrcRegs
= 2;
465 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
466 fullinst
->FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
467 fullinst
->FullSrcRegisters
[1].SrcRegister
.Index
= inst
->TexSrcUnit
;
470 /* texture lookup with LOD bias */
471 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TXB
;
472 fullinst
->Instruction
.NumSrcRegs
= 2;
473 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
474 fullinst
->FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
475 fullinst
->FullSrcRegisters
[1].SrcRegister
.Index
= inst
->TexSrcUnit
;
478 /* texture lookup with explicit partial derivatives */
479 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TXD
;
480 fullinst
->Instruction
.NumSrcRegs
= 4;
481 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
482 /* src[0] = coord, src[1] = d[strq]/dx, src[2] = d[strq]/dy */
483 fullinst
->FullSrcRegisters
[3].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
484 fullinst
->FullSrcRegisters
[3].SrcRegister
.Index
= inst
->TexSrcUnit
;
487 /* texture lookup with explicit LOD */
488 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TXL
;
489 fullinst
->Instruction
.NumSrcRegs
= 2;
490 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
491 fullinst
->FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
492 fullinst
->FullSrcRegisters
[1].SrcRegister
.Index
= inst
->TexSrcUnit
;
495 /* texture lookup with divide by Q component */
496 /* convert to TEX w/ special flag for division */
497 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TEX
;
498 fullinst
->Instruction
.NumSrcRegs
= 2;
499 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
500 fullinst
->FullSrcRegisters
[0].SrcRegisterExtSwz
.ExtDivide
= TGSI_EXTSWIZZLE_W
;
501 fullinst
->FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
502 fullinst
->FullSrcRegisters
[1].SrcRegister
.Index
= inst
->TexSrcUnit
;
505 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_XPD
;
506 fulldst
->DstRegister
.WriteMask
&= TGSI_WRITEMASK_XYZ
;
509 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_RET
;
517 * \param usage_mask bitfield of TGSI_WRITEMASK_{XYZW} tokens
519 static struct tgsi_full_declaration
524 GLboolean semantic_info
,
525 GLuint semantic_name
,
526 GLbitfield semantic_index
)
528 struct tgsi_full_declaration decl
;
530 assert(semantic_name
< TGSI_SEMANTIC_COUNT
);
532 decl
= tgsi_default_full_declaration();
533 decl
.Declaration
.File
= TGSI_FILE_INPUT
;
534 decl
.Declaration
.Declare
= TGSI_DECLARE_RANGE
;
535 decl
.Declaration
.UsageMask
= usage_mask
;
536 decl
.Declaration
.Semantic
= semantic_info
;
537 decl
.Declaration
.Interpolate
= 1;
538 decl
.u
.DeclarationRange
.First
= index
;
539 decl
.u
.DeclarationRange
.Last
= index
;
541 decl
.Semantic
.SemanticName
= semantic_name
;
542 decl
.Semantic
.SemanticIndex
= semantic_index
;
544 decl
.Interpolation
.Interpolate
= interpolate
;
550 * \param usage_mask bitfield of TGSI_WRITEMASK_{XYZW} tokens
552 static struct tgsi_full_declaration
555 GLuint semantic_name
,
556 GLuint semantic_index
,
557 GLbitfield usage_mask
)
559 struct tgsi_full_declaration decl
;
561 assert(semantic_name
< TGSI_SEMANTIC_COUNT
);
563 decl
= tgsi_default_full_declaration();
564 decl
.Declaration
.File
= TGSI_FILE_OUTPUT
;
565 decl
.Declaration
.Declare
= TGSI_DECLARE_RANGE
;
566 decl
.Declaration
.UsageMask
= usage_mask
;
567 decl
.Declaration
.Semantic
= 1;
568 decl
.u
.DeclarationRange
.First
= index
;
569 decl
.u
.DeclarationRange
.Last
= index
;
570 decl
.Semantic
.SemanticName
= semantic_name
;
571 decl
.Semantic
.SemanticIndex
= semantic_index
;
577 static struct tgsi_full_declaration
582 struct tgsi_full_declaration decl
;
583 decl
= tgsi_default_full_declaration();
584 decl
.Declaration
.File
= TGSI_FILE_TEMPORARY
;
585 decl
.Declaration
.Declare
= TGSI_DECLARE_RANGE
;
586 decl
.u
.DeclarationRange
.First
= start_index
;
587 decl
.u
.DeclarationRange
.Last
= end_index
;
593 * Find the temporaries which are used in the given program.
596 find_temporaries(const struct gl_program
*program
,
597 GLboolean tempsUsed
[MAX_PROGRAM_TEMPS
])
601 for (i
= 0; i
< MAX_PROGRAM_TEMPS
; i
++)
602 tempsUsed
[i
] = GL_FALSE
;
604 for (i
= 0; i
< program
->NumInstructions
; i
++) {
605 const struct prog_instruction
*inst
= program
->Instructions
+ i
;
606 const GLuint n
= _mesa_num_inst_src_regs( inst
->Opcode
);
607 for (j
= 0; j
< n
; j
++) {
608 if (inst
->SrcReg
[j
].File
== PROGRAM_TEMPORARY
)
609 tempsUsed
[inst
->SrcReg
[j
].Index
] = GL_TRUE
;
610 if (inst
->DstReg
.File
== PROGRAM_TEMPORARY
)
611 tempsUsed
[inst
->DstReg
.Index
] = GL_TRUE
;
620 * Translate Mesa program to TGSI format.
621 * \param program the program to translate
622 * \param numInputs number of input registers used
623 * \param inputMapping maps Mesa fragment program inputs to TGSI generic
625 * \param inputSemanticName the TGSI_SEMANTIC flag for each input
626 * \param inputSemanticIndex the semantic index (ex: which texcoord) for each input
627 * \param interpMode the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input
629 * \param numOutputs number of output registers used
630 * \param outputMapping maps Mesa fragment program outputs to TGSI
632 * \param outputSemanticName the TGSI_SEMANTIC flag for each output
633 * \param outputSemanticIndex the semantic index (ex: which texcoord) for each output
634 * \param tokens array to store translated tokens in
635 * \param maxTokens size of the tokens array
639 tgsi_translate_mesa_program(
641 const struct gl_program
*program
,
643 const GLuint inputMapping
[],
644 const ubyte inputSemanticName
[],
645 const ubyte inputSemanticIndex
[],
646 const GLuint interpMode
[],
648 const GLuint outputMapping
[],
649 const ubyte outputSemanticName
[],
650 const ubyte outputSemanticIndex
[],
651 struct tgsi_token
*tokens
,
655 GLuint ti
; /* token index */
656 struct tgsi_header
*header
;
657 struct tgsi_processor
*processor
;
658 struct tgsi_full_instruction fullinst
;
659 GLuint preamble_size
= 0;
660 GLuint immediates
[1000];
662 GLuint numImmediates
= 0;
665 assert(procType
== TGSI_PROCESSOR_FRAGMENT
||
666 procType
== TGSI_PROCESSOR_VERTEX
);
668 *(struct tgsi_version
*) &tokens
[0] = tgsi_build_version();
670 header
= (struct tgsi_header
*) &tokens
[1];
671 *header
= tgsi_build_header();
673 processor
= (struct tgsi_processor
*) &tokens
[2];
674 *processor
= tgsi_build_processor( procType
, header
);
679 * Declare input attributes.
681 if (procType
== TGSI_PROCESSOR_FRAGMENT
) {
682 for (i
= 0; i
< numInputs
; i
++) {
683 struct tgsi_full_declaration fulldecl
;
684 switch (inputSemanticName
[i
]) {
685 case TGSI_SEMANTIC_POSITION
:
686 /* Fragment XY pos */
687 fulldecl
= make_input_decl(i
,
688 TGSI_INTERPOLATE_CONSTANT
,
690 GL_TRUE
, TGSI_SEMANTIC_POSITION
, 0 );
691 ti
+= tgsi_build_full_declaration(
696 /* Fragment ZW pos */
697 fulldecl
= make_input_decl(i
,
698 TGSI_INTERPOLATE_LINEAR
,
700 GL_TRUE
, TGSI_SEMANTIC_POSITION
, 0 );
701 ti
+= tgsi_build_full_declaration(&fulldecl
,
707 fulldecl
= make_input_decl(i
,
710 GL_TRUE
, inputSemanticName
[i
],
711 inputSemanticIndex
[i
]);
712 ti
+= tgsi_build_full_declaration(&fulldecl
,
722 for (i
= 0; i
< numInputs
; i
++) {
723 struct tgsi_full_declaration fulldecl
;
724 fulldecl
= make_input_decl(i
,
725 TGSI_INTERPOLATE_ATTRIB
,
727 GL_FALSE
, inputSemanticName
[i
],
728 inputSemanticIndex
[i
]);
729 ti
+= tgsi_build_full_declaration(&fulldecl
,
737 * Declare output attributes.
739 if (procType
== TGSI_PROCESSOR_FRAGMENT
) {
740 for (i
= 0; i
< numOutputs
; i
++) {
741 struct tgsi_full_declaration fulldecl
;
742 switch (outputSemanticName
[i
]) {
743 case TGSI_SEMANTIC_POSITION
:
744 fulldecl
= make_output_decl(i
,
745 TGSI_SEMANTIC_POSITION
, 0, /* Z / Depth */
748 case TGSI_SEMANTIC_COLOR
:
749 fulldecl
= make_output_decl(i
,
750 TGSI_SEMANTIC_COLOR
, 0,
751 TGSI_WRITEMASK_XYZW
);
756 ti
+= tgsi_build_full_declaration(&fulldecl
,
764 for (i
= 0; i
< numOutputs
; i
++) {
765 struct tgsi_full_declaration fulldecl
;
766 fulldecl
= make_output_decl(i
,
767 outputSemanticName
[i
],
768 outputSemanticIndex
[i
],
769 TGSI_WRITEMASK_XYZW
);
770 ti
+= tgsi_build_full_declaration(&fulldecl
,
777 /* temporary decls */
779 GLboolean tempsUsed
[MAX_PROGRAM_TEMPS
+ 1];
780 GLboolean inside_range
= GL_FALSE
;
783 find_temporaries(program
, tempsUsed
);
784 tempsUsed
[MAX_PROGRAM_TEMPS
] = GL_FALSE
;
785 for (i
= 0; i
< MAX_PROGRAM_TEMPS
+ 1; i
++) {
786 if (tempsUsed
[i
] && !inside_range
) {
787 inside_range
= GL_TRUE
;
790 else if (!tempsUsed
[i
] && inside_range
) {
791 struct tgsi_full_declaration fulldecl
;
793 inside_range
= GL_FALSE
;
794 fulldecl
= make_temp_decl( start_range
, i
- 1 );
795 ti
+= tgsi_build_full_declaration(
804 /* immediates/literals */
806 for (i
= 0; i
< program
->Parameters
->NumParameters
; i
++) {
807 if (program
->Parameters
->Parameters
[i
].Type
== PROGRAM_CONSTANT
) {
808 struct tgsi_full_immediate fullimm
809 = make_immediate(program
->Parameters
->ParameterValues
[i
],
810 program
->Parameters
->Parameters
[i
].Size
);
811 ti
+= tgsi_build_full_immediate(&fullimm
,
815 immediates
[i
] = numImmediates
;
821 for( i
= 0; i
< program
->NumInstructions
; i
++ ) {
823 &program
->Instructions
[i
],
831 ti
+= tgsi_build_full_instruction(