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 **************************************************************************/
33 #include "pipe/p_compiler.h"
34 #include "pipe/p_shader_tokens.h"
35 #include "pipe/tgsi/util/tgsi_parse.h"
36 #include "pipe/tgsi/util/tgsi_build.h"
37 #include "pipe/tgsi/util/tgsi_util.h"
38 #include "st_mesa_to_tgsi.h"
39 #include "shader/prog_instruction.h"
40 #include "shader/prog_parameter.h"
46 * Map mesa register file to TGSI register file.
50 enum register_file file
)
53 case PROGRAM_UNDEFINED
:
54 return TGSI_FILE_NULL
;
55 case PROGRAM_TEMPORARY
:
56 return TGSI_FILE_TEMPORARY
;
57 //case PROGRAM_LOCAL_PARAM:
58 //case PROGRAM_ENV_PARAM:
59 case PROGRAM_STATE_VAR
:
60 case PROGRAM_NAMED_PARAM
:
62 return TGSI_FILE_CONSTANT
;
63 case PROGRAM_CONSTANT
:
64 return TGSI_FILE_IMMEDIATE
;
66 return TGSI_FILE_INPUT
;
68 return TGSI_FILE_OUTPUT
;
70 return TGSI_FILE_ADDRESS
;
73 return TGSI_FILE_NULL
;
78 * Map mesa register file index to TGSI index.
79 * Take special care when processing input and output indices.
80 * \param file one of TGSI_FILE_x
81 * \param index the mesa register file index
82 * \param inputMapping maps Mesa input indexes to TGSI input indexes
83 * \param outputMapping maps Mesa output indexes to TGSI output indexes
86 map_register_file_index(
89 const GLuint inputMapping
[],
90 const GLuint outputMapping
[],
91 const GLuint immediateMapping
[])
95 /* inputs are mapped according to the user-defined map */
96 return inputMapping
[index
];
98 case TGSI_FILE_OUTPUT
:
99 return outputMapping
[index
];
101 case TGSI_FILE_IMMEDIATE
:
102 return immediateMapping
[index
];
110 * Map mesa texture target to TGSI texture target.
116 switch( textarget
) {
117 case TEXTURE_1D_INDEX
:
118 return TGSI_TEXTURE_1D
;
119 case TEXTURE_2D_INDEX
:
120 return TGSI_TEXTURE_2D
;
121 case TEXTURE_3D_INDEX
:
122 return TGSI_TEXTURE_3D
;
123 case TEXTURE_CUBE_INDEX
:
124 return TGSI_TEXTURE_CUBE
;
125 case TEXTURE_RECT_INDEX
:
126 return TGSI_TEXTURE_RECT
;
131 return TGSI_TEXTURE_1D
;
140 return TGSI_SAT_NONE
;
141 case SATURATE_ZERO_ONE
:
142 return TGSI_SAT_ZERO_ONE
;
143 case SATURATE_PLUS_MINUS_ONE
:
144 return TGSI_SAT_MINUS_PLUS_ONE
;
147 return TGSI_SAT_NONE
;
155 assert( WRITEMASK_X
== TGSI_WRITEMASK_X
);
156 assert( WRITEMASK_Y
== TGSI_WRITEMASK_Y
);
157 assert( WRITEMASK_Z
== TGSI_WRITEMASK_Z
);
158 assert( WRITEMASK_W
== TGSI_WRITEMASK_W
);
159 assert( (writemask
& ~TGSI_WRITEMASK_XYZW
) == 0 );
164 static struct tgsi_full_immediate
165 make_immediate(const float *value
, uint size
)
167 struct tgsi_full_immediate imm
;
168 imm
.Immediate
.Type
= TGSI_TOKEN_TYPE_IMMEDIATE
;
169 imm
.Immediate
.Size
= 1 + size
; /* one for the token itself */
170 imm
.Immediate
.DataType
= TGSI_IMM_FLOAT32
;
171 imm
.u
.ImmediateFloat32
= (struct tgsi_immediate_float32
*) value
;
177 const struct prog_instruction
*inst
,
178 struct tgsi_full_instruction
*fullinst
,
179 const GLuint inputMapping
[],
180 const GLuint outputMapping
[],
181 const GLuint immediateMapping
[],
182 GLuint preamble_size
,
186 struct tgsi_full_dst_register
*fulldst
;
187 struct tgsi_full_src_register
*fullsrc
;
189 *fullinst
= tgsi_default_full_instruction();
191 fullinst
->Instruction
.Saturate
= convert_sat( inst
->SaturateMode
);
192 fullinst
->Instruction
.NumDstRegs
= _mesa_num_inst_dst_regs( inst
->Opcode
);
193 fullinst
->Instruction
.NumSrcRegs
= _mesa_num_inst_src_regs( inst
->Opcode
);
195 fulldst
= &fullinst
->FullDstRegisters
[0];
196 fulldst
->DstRegister
.File
= map_register_file( inst
->DstReg
.File
);
197 fulldst
->DstRegister
.Index
= map_register_file_index(
198 fulldst
->DstRegister
.File
,
204 fulldst
->DstRegister
.WriteMask
= convert_writemask( inst
->DstReg
.WriteMask
);
206 for( i
= 0; i
< fullinst
->Instruction
.NumSrcRegs
; i
++ ) {
209 fullsrc
= &fullinst
->FullSrcRegisters
[i
];
210 fullsrc
->SrcRegister
.File
= map_register_file( inst
->SrcReg
[i
].File
);
211 fullsrc
->SrcRegister
.Index
= map_register_file_index(
212 fullsrc
->SrcRegister
.File
,
213 inst
->SrcReg
[i
].Index
,
218 for( j
= 0; j
< 4; j
++ ) {
221 swz
= GET_SWZ( inst
->SrcReg
[i
].Swizzle
, j
);
222 if( swz
> SWIZZLE_W
) {
223 tgsi_util_set_src_register_extswizzle(
224 &fullsrc
->SrcRegisterExtSwz
,
229 tgsi_util_set_src_register_swizzle(
230 &fullsrc
->SrcRegister
,
236 if( inst
->SrcReg
[i
].NegateBase
== NEGATE_XYZW
) {
237 fullsrc
->SrcRegister
.Negate
= 1;
239 else if( inst
->SrcReg
[i
].NegateBase
!= NEGATE_NONE
) {
240 if( inst
->SrcReg
[i
].NegateBase
& NEGATE_X
) {
241 fullsrc
->SrcRegisterExtSwz
.NegateX
= 1;
243 if( inst
->SrcReg
[i
].NegateBase
& NEGATE_Y
) {
244 fullsrc
->SrcRegisterExtSwz
.NegateY
= 1;
246 if( inst
->SrcReg
[i
].NegateBase
& NEGATE_Z
) {
247 fullsrc
->SrcRegisterExtSwz
.NegateZ
= 1;
249 if( inst
->SrcReg
[i
].NegateBase
& NEGATE_W
) {
250 fullsrc
->SrcRegisterExtSwz
.NegateW
= 1;
254 if( inst
->SrcReg
[i
].Abs
) {
255 fullsrc
->SrcRegisterExtMod
.Absolute
= 1;
258 if( inst
->SrcReg
[i
].NegateAbs
) {
259 fullsrc
->SrcRegisterExtMod
.Negate
= 1;
262 if( inst
->SrcReg
[i
].RelAddr
) {
263 fullsrc
->SrcRegister
.Indirect
= 1;
265 fullsrc
->SrcRegisterInd
.File
= TGSI_FILE_ADDRESS
;
266 fullsrc
->SrcRegisterInd
.Index
= 0;
270 switch( inst
->Opcode
) {
272 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ARL
;
275 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ABS
;
278 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ADD
;
281 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_BGNLOOP2
;
282 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
285 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_BGNSUB
;
288 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_BRA
;
291 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_BRK
;
294 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_CAL
;
295 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
298 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_CMP
;
301 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_CONT
;
304 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_COS
;
307 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DDX
;
310 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DDY
;
313 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DP3
;
316 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DP4
;
319 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DPH
;
322 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_DST
;
325 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ELSE
;
326 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
329 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ENDIF
;
332 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ENDLOOP2
;
333 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
336 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_ENDSUB
;
339 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_EX2
;
342 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_EXP
;
345 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_FLR
;
348 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_FRC
;
351 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_IF
;
352 fullinst
->InstructionExtLabel
.Label
= inst
->BranchTarget
+ preamble_size
;
355 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_INT
;
358 /* predicated w/ a register */
359 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_KILP
;
363 assert(inst
->DstReg
.CondMask
== COND_TR
);
364 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_KIL
;
367 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_LG2
;
370 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_LOG
;
373 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_LIT
;
376 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_LRP
;
379 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MAD
;
382 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MAX
;
385 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MIN
;
388 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MOV
;
391 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_MUL
;
394 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOISE1
;
397 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOISE2
;
400 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOISE3
;
403 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOISE4
;
406 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_NOP
;
409 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_POW
;
412 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_RCP
;
415 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_RET
;
418 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_RSQ
;
419 tgsi_util_set_full_src_register_sign_mode(
420 &fullinst
->FullSrcRegisters
[0],
421 TGSI_UTIL_SIGN_CLEAR
);
424 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SCS
;
425 fulldst
->DstRegister
.WriteMask
&= TGSI_WRITEMASK_XY
;
428 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SEQ
;
431 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SGE
;
434 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SGT
;
437 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SIN
;
440 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SLE
;
443 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SLT
;
446 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SNE
;
449 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SUB
;
452 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_SWZ
;
455 /* ordinary texture lookup */
456 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TEX
;
457 fullinst
->Instruction
.NumSrcRegs
= 2;
458 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
459 fullinst
->FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
460 fullinst
->FullSrcRegisters
[1].SrcRegister
.Index
= inst
->TexSrcUnit
;
463 /* texture lookup with LOD bias */
464 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TXB
;
465 fullinst
->Instruction
.NumSrcRegs
= 2;
466 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
467 fullinst
->FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
468 fullinst
->FullSrcRegisters
[1].SrcRegister
.Index
= inst
->TexSrcUnit
;
471 /* texture lookup with explicit partial derivatives */
472 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TXD
;
473 fullinst
->Instruction
.NumSrcRegs
= 4;
474 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
475 /* src[0] = coord, src[1] = d[strq]/dx, src[2] = d[strq]/dy */
476 fullinst
->FullSrcRegisters
[3].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
477 fullinst
->FullSrcRegisters
[3].SrcRegister
.Index
= inst
->TexSrcUnit
;
480 /* texture lookup with explicit LOD */
481 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TXL
;
482 fullinst
->Instruction
.NumSrcRegs
= 2;
483 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
484 fullinst
->FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
485 fullinst
->FullSrcRegisters
[1].SrcRegister
.Index
= inst
->TexSrcUnit
;
488 /* texture lookup with divide by Q component */
489 /* convert to TEX w/ special flag for division */
490 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_TEX
;
491 fullinst
->Instruction
.NumSrcRegs
= 2;
492 fullinst
->InstructionExtTexture
.Texture
= map_texture_target( inst
->TexSrcTarget
);
493 fullinst
->FullSrcRegisters
[0].SrcRegisterExtSwz
.ExtDivide
= TGSI_EXTSWIZZLE_W
;
494 fullinst
->FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
495 fullinst
->FullSrcRegisters
[1].SrcRegister
.Index
= inst
->TexSrcUnit
;
498 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_XPD
;
499 fulldst
->DstRegister
.WriteMask
&= TGSI_WRITEMASK_XYZ
;
502 fullinst
->Instruction
.Opcode
= TGSI_OPCODE_RET
;
510 * \param usage_mask bitfield of TGSI_WRITEMASK_{XYZW} tokens
512 static struct tgsi_full_declaration
515 GLboolean interpolate_info
,
518 GLboolean semantic_info
,
519 GLuint semantic_name
,
520 GLbitfield semantic_index
)
522 struct tgsi_full_declaration decl
;
524 assert(semantic_name
< TGSI_SEMANTIC_COUNT
);
526 decl
= tgsi_default_full_declaration();
527 decl
.Declaration
.File
= TGSI_FILE_INPUT
;
528 decl
.Declaration
.Declare
= TGSI_DECLARE_RANGE
;
529 decl
.Declaration
.UsageMask
= usage_mask
;
530 decl
.Declaration
.Semantic
= semantic_info
;
531 decl
.u
.DeclarationRange
.First
= index
;
532 decl
.u
.DeclarationRange
.Last
= index
;
534 decl
.Semantic
.SemanticName
= semantic_name
;
535 decl
.Semantic
.SemanticIndex
= semantic_index
;
537 if (interpolate_info
) {
538 decl
.Declaration
.Interpolate
= 1;
539 decl
.Interpolation
.Interpolate
= interpolate
;
546 * \param usage_mask bitfield of TGSI_WRITEMASK_{XYZW} tokens
548 static struct tgsi_full_declaration
551 GLuint semantic_name
,
552 GLuint semantic_index
,
553 GLbitfield usage_mask
)
555 struct tgsi_full_declaration decl
;
557 assert(semantic_name
< TGSI_SEMANTIC_COUNT
);
559 decl
= tgsi_default_full_declaration();
560 decl
.Declaration
.File
= TGSI_FILE_OUTPUT
;
561 decl
.Declaration
.Declare
= TGSI_DECLARE_RANGE
;
562 decl
.Declaration
.UsageMask
= usage_mask
;
563 decl
.Declaration
.Semantic
= 1;
564 decl
.u
.DeclarationRange
.First
= index
;
565 decl
.u
.DeclarationRange
.Last
= index
;
566 decl
.Semantic
.SemanticName
= semantic_name
;
567 decl
.Semantic
.SemanticIndex
= semantic_index
;
573 static struct tgsi_full_declaration
578 struct tgsi_full_declaration decl
;
579 decl
= tgsi_default_full_declaration();
580 decl
.Declaration
.File
= TGSI_FILE_TEMPORARY
;
581 decl
.Declaration
.Declare
= TGSI_DECLARE_RANGE
;
582 decl
.u
.DeclarationRange
.First
= start_index
;
583 decl
.u
.DeclarationRange
.Last
= end_index
;
588 static struct tgsi_full_declaration
589 make_sampler_decl(GLuint index
)
591 struct tgsi_full_declaration decl
;
592 decl
= tgsi_default_full_declaration();
593 decl
.Declaration
.File
= TGSI_FILE_SAMPLER
;
594 decl
.Declaration
.Declare
= TGSI_DECLARE_RANGE
;
595 decl
.u
.DeclarationRange
.First
= index
;
596 decl
.u
.DeclarationRange
.Last
= index
;
600 /** Reference into a constant buffer */
601 static struct tgsi_full_declaration
602 make_constant_decl(GLuint first
, GLuint last
)
604 struct tgsi_full_declaration decl
;
605 decl
= tgsi_default_full_declaration();
606 decl
.Declaration
.File
= TGSI_FILE_CONSTANT
;
607 decl
.Declaration
.Declare
= TGSI_DECLARE_RANGE
;
608 decl
.u
.DeclarationRange
.First
= first
;
609 decl
.u
.DeclarationRange
.Last
= last
;
616 * Find the temporaries which are used in the given program.
619 find_temporaries(const struct gl_program
*program
,
620 GLboolean tempsUsed
[MAX_PROGRAM_TEMPS
])
624 for (i
= 0; i
< MAX_PROGRAM_TEMPS
; i
++)
625 tempsUsed
[i
] = GL_FALSE
;
627 for (i
= 0; i
< program
->NumInstructions
; i
++) {
628 const struct prog_instruction
*inst
= program
->Instructions
+ i
;
629 const GLuint n
= _mesa_num_inst_src_regs( inst
->Opcode
);
630 for (j
= 0; j
< n
; j
++) {
631 if (inst
->SrcReg
[j
].File
== PROGRAM_TEMPORARY
)
632 tempsUsed
[inst
->SrcReg
[j
].Index
] = GL_TRUE
;
633 if (inst
->DstReg
.File
== PROGRAM_TEMPORARY
)
634 tempsUsed
[inst
->DstReg
.Index
] = GL_TRUE
;
643 * Translate Mesa program to TGSI format.
644 * \param program the program to translate
645 * \param numInputs number of input registers used
646 * \param inputMapping maps Mesa fragment program inputs to TGSI generic
648 * \param inputSemanticName the TGSI_SEMANTIC flag for each input
649 * \param inputSemanticIndex the semantic index (ex: which texcoord) for each input
650 * \param interpMode the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input
652 * \param numOutputs number of output registers used
653 * \param outputMapping maps Mesa fragment program outputs to TGSI
655 * \param outputSemanticName the TGSI_SEMANTIC flag for each output
656 * \param outputSemanticIndex the semantic index (ex: which texcoord) for each output
657 * \param tokens array to store translated tokens in
658 * \param maxTokens size of the tokens array
662 tgsi_translate_mesa_program(
664 const struct gl_program
*program
,
666 const GLuint inputMapping
[],
667 const ubyte inputSemanticName
[],
668 const ubyte inputSemanticIndex
[],
669 const GLuint interpMode
[],
671 const GLuint outputMapping
[],
672 const ubyte outputSemanticName
[],
673 const ubyte outputSemanticIndex
[],
674 struct tgsi_token
*tokens
,
678 GLuint ti
; /* token index */
679 struct tgsi_header
*header
;
680 struct tgsi_processor
*processor
;
681 struct tgsi_full_instruction fullinst
;
682 GLuint preamble_size
= 0;
683 GLuint immediates
[1000];
684 GLuint numImmediates
= 0;
686 assert(procType
== TGSI_PROCESSOR_FRAGMENT
||
687 procType
== TGSI_PROCESSOR_VERTEX
);
689 *(struct tgsi_version
*) &tokens
[0] = tgsi_build_version();
691 header
= (struct tgsi_header
*) &tokens
[1];
692 *header
= tgsi_build_header();
694 processor
= (struct tgsi_processor
*) &tokens
[2];
695 *processor
= tgsi_build_processor( procType
, header
);
700 * Declare input attributes.
702 if (procType
== TGSI_PROCESSOR_FRAGMENT
) {
703 for (i
= 0; i
< numInputs
; i
++) {
704 struct tgsi_full_declaration fulldecl
;
705 fulldecl
= make_input_decl(i
,
706 GL_TRUE
, interpMode
[i
],
708 GL_TRUE
, inputSemanticName
[i
],
709 inputSemanticIndex
[i
]);
710 ti
+= tgsi_build_full_declaration(&fulldecl
,
718 /* XXX: this could probaby be merged with the clause above.
719 * the only difference is the semantic tags.
721 for (i
= 0; i
< numInputs
; i
++) {
722 struct tgsi_full_declaration fulldecl
;
723 fulldecl
= make_input_decl(i
,
727 ti
+= tgsi_build_full_declaration(&fulldecl
,
735 * Declare output attributes.
737 if (procType
== TGSI_PROCESSOR_FRAGMENT
) {
738 for (i
= 0; i
< numOutputs
; i
++) {
739 struct tgsi_full_declaration fulldecl
;
740 switch (outputSemanticName
[i
]) {
741 case TGSI_SEMANTIC_POSITION
:
742 fulldecl
= make_output_decl(i
,
743 TGSI_SEMANTIC_POSITION
, 0, /* Z / Depth */
746 case TGSI_SEMANTIC_COLOR
:
747 fulldecl
= make_output_decl(i
,
748 TGSI_SEMANTIC_COLOR
, 0,
749 TGSI_WRITEMASK_XYZW
);
754 ti
+= tgsi_build_full_declaration(&fulldecl
,
762 for (i
= 0; i
< numOutputs
; i
++) {
763 struct tgsi_full_declaration fulldecl
;
764 fulldecl
= make_output_decl(i
,
765 outputSemanticName
[i
],
766 outputSemanticIndex
[i
],
767 TGSI_WRITEMASK_XYZW
);
768 ti
+= tgsi_build_full_declaration(&fulldecl
,
775 /* temporary decls */
777 GLboolean tempsUsed
[MAX_PROGRAM_TEMPS
+ 1];
778 GLboolean inside_range
= GL_FALSE
;
781 find_temporaries(program
, tempsUsed
);
782 tempsUsed
[MAX_PROGRAM_TEMPS
] = GL_FALSE
;
783 for (i
= 0; i
< MAX_PROGRAM_TEMPS
+ 1; i
++) {
784 if (tempsUsed
[i
] && !inside_range
) {
785 inside_range
= GL_TRUE
;
788 else if (!tempsUsed
[i
] && inside_range
) {
789 struct tgsi_full_declaration fulldecl
;
791 inside_range
= GL_FALSE
;
792 fulldecl
= make_temp_decl( start_range
, i
- 1 );
793 ti
+= tgsi_build_full_declaration(
802 /* immediates/literals */
803 for (i
= 0; program
->Parameters
&& i
< program
->Parameters
->NumParameters
;
805 if (program
->Parameters
->Parameters
[i
].Type
== PROGRAM_CONSTANT
) {
806 struct tgsi_full_immediate fullimm
807 = make_immediate(program
->Parameters
->ParameterValues
[i
],
808 program
->Parameters
->Parameters
[i
].Size
);
809 ti
+= tgsi_build_full_immediate(&fullimm
,
813 immediates
[i
] = numImmediates
;
818 /* constant buffer refs */
820 GLint start
= -1, end
= -1;
823 program
->Parameters
&& i
< program
->Parameters
->NumParameters
;
825 GLboolean emit
= (i
== program
->Parameters
->NumParameters
- 1);
827 switch (program
->Parameters
->Parameters
[i
].Type
) {
828 case PROGRAM_ENV_PARAM
:
829 case PROGRAM_STATE_VAR
:
830 case PROGRAM_NAMED_PARAM
:
831 case PROGRAM_UNIFORM
:
833 /* begin a sequence */
838 /* continue sequence */
844 /* end of sequence */
849 if (emit
&& start
>= 0) {
850 struct tgsi_full_declaration fulldecl
;
851 fulldecl
= make_constant_decl( start
, end
);
852 ti
+= tgsi_build_full_declaration(&fulldecl
,
861 /* texture samplers */
862 for (i
= 0; i
< 8; i
++) {
863 if (program
->SamplersUsed
& (1 << i
)) {
864 struct tgsi_full_declaration fulldecl
;
865 fulldecl
= make_sampler_decl( i
);
866 ti
+= tgsi_build_full_declaration(&fulldecl
,
874 for( i
= 0; i
< program
->NumInstructions
; i
++ ) {
876 &program
->Instructions
[i
],
884 ti
+= tgsi_build_full_instruction(