2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Vertex and fragment program support functions.
32 #include "main/glheader.h"
33 #include "main/context.h"
34 #include "main/hash.h"
36 #include "prog_cache.h"
37 #include "prog_parameter.h"
38 #include "prog_instruction.h"
42 * A pointer to this dummy program is put into the hash table when
43 * glGenPrograms is called.
45 struct gl_program _mesa_DummyProgram
;
49 * Init context's vertex/fragment program state
52 _mesa_init_program(GLcontext
*ctx
)
56 ctx
->Program
.ErrorPos
= -1;
57 ctx
->Program
.ErrorString
= _mesa_strdup("");
59 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
60 ctx
->VertexProgram
.Enabled
= GL_FALSE
;
61 ctx
->VertexProgram
.PointSizeEnabled
= GL_FALSE
;
62 ctx
->VertexProgram
.TwoSideEnabled
= GL_FALSE
;
63 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
64 ctx
->Shared
->DefaultVertexProgram
);
65 assert(ctx
->VertexProgram
.Current
);
66 for (i
= 0; i
< MAX_NV_VERTEX_PROGRAM_PARAMS
/ 4; i
++) {
67 ctx
->VertexProgram
.TrackMatrix
[i
] = GL_NONE
;
68 ctx
->VertexProgram
.TrackMatrixTransform
[i
] = GL_IDENTITY_NV
;
70 ctx
->VertexProgram
.Cache
= _mesa_new_program_cache();
73 #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
74 ctx
->FragmentProgram
.Enabled
= GL_FALSE
;
75 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
76 ctx
->Shared
->DefaultFragmentProgram
);
77 assert(ctx
->FragmentProgram
.Current
);
78 ctx
->FragmentProgram
.Cache
= _mesa_new_program_cache();
82 /* XXX probably move this stuff */
83 #if FEATURE_ATI_fragment_shader
84 ctx
->ATIFragmentShader
.Enabled
= GL_FALSE
;
85 ctx
->ATIFragmentShader
.Current
= ctx
->Shared
->DefaultFragmentShader
;
86 assert(ctx
->ATIFragmentShader
.Current
);
87 ctx
->ATIFragmentShader
.Current
->RefCount
++;
93 * Free a context's vertex/fragment program state
96 _mesa_free_program_data(GLcontext
*ctx
)
98 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
99 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
, NULL
);
100 _mesa_delete_program_cache(ctx
, ctx
->VertexProgram
.Cache
);
102 #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
103 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
, NULL
);
104 _mesa_delete_program_cache(ctx
, ctx
->FragmentProgram
.Cache
);
106 /* XXX probably move this stuff */
107 #if FEATURE_ATI_fragment_shader
108 if (ctx
->ATIFragmentShader
.Current
) {
109 ctx
->ATIFragmentShader
.Current
->RefCount
--;
110 if (ctx
->ATIFragmentShader
.Current
->RefCount
<= 0) {
111 _mesa_free(ctx
->ATIFragmentShader
.Current
);
115 _mesa_free((void *) ctx
->Program
.ErrorString
);
120 * Update the default program objects in the given context to reference those
121 * specified in the shared state and release those referencing the old
125 _mesa_update_default_objects_program(GLcontext
*ctx
)
127 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
128 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
129 (struct gl_vertex_program
*)
130 ctx
->Shared
->DefaultVertexProgram
);
131 assert(ctx
->VertexProgram
.Current
);
134 #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
135 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
136 (struct gl_fragment_program
*)
137 ctx
->Shared
->DefaultFragmentProgram
);
138 assert(ctx
->FragmentProgram
.Current
);
141 /* XXX probably move this stuff */
142 #if FEATURE_ATI_fragment_shader
143 if (ctx
->ATIFragmentShader
.Current
) {
144 ctx
->ATIFragmentShader
.Current
->RefCount
--;
145 if (ctx
->ATIFragmentShader
.Current
->RefCount
<= 0) {
146 _mesa_free(ctx
->ATIFragmentShader
.Current
);
149 ctx
->ATIFragmentShader
.Current
= (struct ati_fragment_shader
*) ctx
->Shared
->DefaultFragmentShader
;
150 assert(ctx
->ATIFragmentShader
.Current
);
151 ctx
->ATIFragmentShader
.Current
->RefCount
++;
157 * Set the vertex/fragment program error state (position and error string).
158 * This is generally called from within the parsers.
161 _mesa_set_program_error(GLcontext
*ctx
, GLint pos
, const char *string
)
163 ctx
->Program
.ErrorPos
= pos
;
164 _mesa_free((void *) ctx
->Program
.ErrorString
);
167 ctx
->Program
.ErrorString
= _mesa_strdup(string
);
172 * Find the line number and column for 'pos' within 'string'.
173 * Return a copy of the line which contains 'pos'. Free the line with
175 * \param string the program string
176 * \param pos the position within the string
177 * \param line returns the line number corresponding to 'pos'.
178 * \param col returns the column number corresponding to 'pos'.
179 * \return copy of the line containing 'pos'.
182 _mesa_find_line_column(const GLubyte
*string
, const GLubyte
*pos
,
183 GLint
*line
, GLint
*col
)
185 const GLubyte
*lineStart
= string
;
186 const GLubyte
*p
= string
;
193 if (*p
== (GLubyte
) '\n') {
200 *col
= (pos
- lineStart
) + 1;
202 /* return copy of this line */
203 while (*p
!= 0 && *p
!= '\n')
206 s
= (GLubyte
*) _mesa_malloc(len
+ 1);
207 _mesa_memcpy(s
, lineStart
, len
);
215 * Initialize a new vertex/fragment program object.
217 static struct gl_program
*
218 _mesa_init_program_struct( GLcontext
*ctx
, struct gl_program
*prog
,
219 GLenum target
, GLuint id
)
224 _mesa_bzero(prog
, sizeof(*prog
));
226 prog
->Target
= target
;
227 prog
->Resident
= GL_TRUE
;
229 prog
->Format
= GL_PROGRAM_FORMAT_ASCII_ARB
;
231 /* default mapping from samplers to texture units */
232 for (i
= 0; i
< MAX_SAMPLERS
; i
++)
233 prog
->SamplerUnits
[i
] = i
;
241 * Initialize a new fragment program object.
244 _mesa_init_fragment_program( GLcontext
*ctx
, struct gl_fragment_program
*prog
,
245 GLenum target
, GLuint id
)
248 return _mesa_init_program_struct( ctx
, &prog
->Base
, target
, id
);
255 * Initialize a new vertex program object.
258 _mesa_init_vertex_program( GLcontext
*ctx
, struct gl_vertex_program
*prog
,
259 GLenum target
, GLuint id
)
262 return _mesa_init_program_struct( ctx
, &prog
->Base
, target
, id
);
269 * Allocate and initialize a new fragment/vertex program object but
270 * don't put it into the program hash table. Called via
271 * ctx->Driver.NewProgram. May be overridden (ie. replaced) by a
272 * device driver function to implement OO deriviation with additional
273 * types not understood by this function.
276 * \param id program id/number
277 * \param target program target/type
278 * \return pointer to new program object
281 _mesa_new_program(GLcontext
*ctx
, GLenum target
, GLuint id
)
283 struct gl_program
*prog
;
285 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
286 prog
= _mesa_init_vertex_program(ctx
, CALLOC_STRUCT(gl_vertex_program
),
289 case GL_FRAGMENT_PROGRAM_NV
:
290 case GL_FRAGMENT_PROGRAM_ARB
:
291 prog
=_mesa_init_fragment_program(ctx
,
292 CALLOC_STRUCT(gl_fragment_program
),
296 _mesa_problem(ctx
, "bad target in _mesa_new_program");
304 * Delete a program and remove it from the hash table, ignoring the
306 * Called via ctx->Driver.DeleteProgram. May be wrapped (OO deriviation)
307 * by a device driver function.
310 _mesa_delete_program(GLcontext
*ctx
, struct gl_program
*prog
)
314 ASSERT(prog
->RefCount
==0);
316 if (prog
== &_mesa_DummyProgram
)
320 _mesa_free(prog
->String
);
322 _mesa_free_instructions(prog
->Instructions
, prog
->NumInstructions
);
324 if (prog
->Parameters
) {
325 _mesa_free_parameter_list(prog
->Parameters
);
328 _mesa_free_parameter_list(prog
->Varying
);
330 if (prog
->Attributes
) {
331 _mesa_free_parameter_list(prog
->Attributes
);
334 /* XXX this is a little ugly */
335 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
) {
336 struct gl_vertex_program
*vprog
= (struct gl_vertex_program
*) prog
;
338 _mesa_free(vprog
->TnlData
);
346 * Return the gl_program object for a given ID.
347 * Basically just a wrapper for _mesa_HashLookup() to avoid a lot of
351 _mesa_lookup_program(GLcontext
*ctx
, GLuint id
)
354 return (struct gl_program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
361 * Reference counting for vertex/fragment programs
364 _mesa_reference_program(GLcontext
*ctx
,
365 struct gl_program
**ptr
,
366 struct gl_program
*prog
)
371 ASSERT((*ptr
)->Target
== prog
->Target
);
374 return; /* no change */
377 GLboolean deleteFlag
;
379 /*_glthread_LOCK_MUTEX((*ptr)->Mutex);*/
381 printf("Program %p ID=%u Target=%s Refcount-- to %d\n",
383 ((*ptr
)->Target
== GL_VERTEX_PROGRAM_ARB
? "VP" : "FP"),
384 (*ptr
)->RefCount
- 1);
386 ASSERT((*ptr
)->RefCount
> 0);
389 deleteFlag
= ((*ptr
)->RefCount
== 0);
390 /*_glthread_UNLOCK_MUTEX((*ptr)->Mutex);*/
394 ctx
->Driver
.DeleteProgram(ctx
, *ptr
);
402 /*_glthread_LOCK_MUTEX(prog->Mutex);*/
405 printf("Program %p ID=%u Target=%s Refcount++ to %d\n",
407 (prog
->Target
== GL_VERTEX_PROGRAM_ARB
? "VP" : "FP"),
410 /*_glthread_UNLOCK_MUTEX(prog->Mutex);*/
418 * Return a copy of a program.
419 * XXX Problem here if the program object is actually OO-derivation
420 * made by a device driver.
423 _mesa_clone_program(GLcontext
*ctx
, const struct gl_program
*prog
)
425 struct gl_program
*clone
;
427 clone
= ctx
->Driver
.NewProgram(ctx
, prog
->Target
, prog
->Id
);
431 assert(clone
->Target
== prog
->Target
);
432 assert(clone
->RefCount
== 1);
434 clone
->String
= (GLubyte
*) _mesa_strdup((char *) prog
->String
);
435 clone
->Format
= prog
->Format
;
436 clone
->Instructions
= _mesa_alloc_instructions(prog
->NumInstructions
);
437 if (!clone
->Instructions
) {
438 _mesa_reference_program(ctx
, &clone
, NULL
);
441 _mesa_copy_instructions(clone
->Instructions
, prog
->Instructions
,
442 prog
->NumInstructions
);
443 clone
->InputsRead
= prog
->InputsRead
;
444 clone
->OutputsWritten
= prog
->OutputsWritten
;
445 clone
->SamplersUsed
= prog
->SamplersUsed
;
446 clone
->ShadowSamplers
= prog
->ShadowSamplers
;
447 memcpy(clone
->TexturesUsed
, prog
->TexturesUsed
, sizeof(prog
->TexturesUsed
));
449 if (prog
->Parameters
)
450 clone
->Parameters
= _mesa_clone_parameter_list(prog
->Parameters
);
451 memcpy(clone
->LocalParams
, prog
->LocalParams
, sizeof(clone
->LocalParams
));
453 clone
->Varying
= _mesa_clone_parameter_list(prog
->Varying
);
454 if (prog
->Attributes
)
455 clone
->Attributes
= _mesa_clone_parameter_list(prog
->Attributes
);
456 memcpy(clone
->LocalParams
, prog
->LocalParams
, sizeof(clone
->LocalParams
));
457 clone
->NumInstructions
= prog
->NumInstructions
;
458 clone
->NumTemporaries
= prog
->NumTemporaries
;
459 clone
->NumParameters
= prog
->NumParameters
;
460 clone
->NumAttributes
= prog
->NumAttributes
;
461 clone
->NumAddressRegs
= prog
->NumAddressRegs
;
462 clone
->NumNativeInstructions
= prog
->NumNativeInstructions
;
463 clone
->NumNativeTemporaries
= prog
->NumNativeTemporaries
;
464 clone
->NumNativeParameters
= prog
->NumNativeParameters
;
465 clone
->NumNativeAttributes
= prog
->NumNativeAttributes
;
466 clone
->NumNativeAddressRegs
= prog
->NumNativeAddressRegs
;
467 clone
->NumAluInstructions
= prog
->NumAluInstructions
;
468 clone
->NumTexInstructions
= prog
->NumTexInstructions
;
469 clone
->NumTexIndirections
= prog
->NumTexIndirections
;
470 clone
->NumNativeAluInstructions
= prog
->NumNativeAluInstructions
;
471 clone
->NumNativeTexInstructions
= prog
->NumNativeTexInstructions
;
472 clone
->NumNativeTexIndirections
= prog
->NumNativeTexIndirections
;
474 switch (prog
->Target
) {
475 case GL_VERTEX_PROGRAM_ARB
:
477 const struct gl_vertex_program
*vp
478 = (const struct gl_vertex_program
*) prog
;
479 struct gl_vertex_program
*vpc
= (struct gl_vertex_program
*) clone
;
480 vpc
->IsPositionInvariant
= vp
->IsPositionInvariant
;
483 case GL_FRAGMENT_PROGRAM_ARB
:
485 const struct gl_fragment_program
*fp
486 = (const struct gl_fragment_program
*) prog
;
487 struct gl_fragment_program
*fpc
= (struct gl_fragment_program
*) clone
;
488 fpc
->FogOption
= fp
->FogOption
;
489 fpc
->UsesKill
= fp
->UsesKill
;
493 _mesa_problem(NULL
, "Unexpected target in _mesa_clone_program");
501 * Insert 'count' NOP instructions at 'start' in the given program.
502 * Adjust branch targets accordingly.
505 _mesa_insert_instructions(struct gl_program
*prog
, GLuint start
, GLuint count
)
507 const GLuint origLen
= prog
->NumInstructions
;
508 const GLuint newLen
= origLen
+ count
;
509 struct prog_instruction
*newInst
;
512 /* adjust branches */
513 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
514 struct prog_instruction
*inst
= prog
->Instructions
+ i
;
515 if (inst
->BranchTarget
> 0) {
516 if (inst
->BranchTarget
>= start
) {
517 inst
->BranchTarget
+= count
;
522 /* Alloc storage for new instructions */
523 newInst
= _mesa_alloc_instructions(newLen
);
528 /* Copy 'start' instructions into new instruction buffer */
529 _mesa_copy_instructions(newInst
, prog
->Instructions
, start
);
531 /* init the new instructions */
532 _mesa_init_instructions(newInst
+ start
, count
);
534 /* Copy the remaining/tail instructions to new inst buffer */
535 _mesa_copy_instructions(newInst
+ start
+ count
,
536 prog
->Instructions
+ start
,
539 /* free old instructions */
540 _mesa_free_instructions(prog
->Instructions
, origLen
);
542 /* install new instructions */
543 prog
->Instructions
= newInst
;
544 prog
->NumInstructions
= newLen
;
551 * Delete 'count' instructions at 'start' in the given program.
552 * Adjust branch targets accordingly.
555 _mesa_delete_instructions(struct gl_program
*prog
, GLuint start
, GLuint count
)
557 const GLuint origLen
= prog
->NumInstructions
;
558 const GLuint newLen
= origLen
- count
;
559 struct prog_instruction
*newInst
;
562 /* adjust branches */
563 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
564 struct prog_instruction
*inst
= prog
->Instructions
+ i
;
565 if (inst
->BranchTarget
> 0) {
566 if (inst
->BranchTarget
>= start
) {
567 inst
->BranchTarget
-= count
;
572 /* Alloc storage for new instructions */
573 newInst
= _mesa_alloc_instructions(newLen
);
578 /* Copy 'start' instructions into new instruction buffer */
579 _mesa_copy_instructions(newInst
, prog
->Instructions
, start
);
581 /* Copy the remaining/tail instructions to new inst buffer */
582 _mesa_copy_instructions(newInst
+ start
,
583 prog
->Instructions
+ start
+ count
,
586 /* free old instructions */
587 _mesa_free_instructions(prog
->Instructions
, origLen
);
589 /* install new instructions */
590 prog
->Instructions
= newInst
;
591 prog
->NumInstructions
= newLen
;
598 * Search instructions for registers that match (oldFile, oldIndex),
599 * replacing them with (newFile, newIndex).
602 replace_registers(struct prog_instruction
*inst
, GLuint numInst
,
603 GLuint oldFile
, GLuint oldIndex
,
604 GLuint newFile
, GLuint newIndex
)
607 for (i
= 0; i
< numInst
; i
++) {
609 for (j
= 0; j
< _mesa_num_inst_src_regs(inst
->Opcode
); j
++) {
610 if (inst
[i
].SrcReg
[j
].File
== oldFile
&&
611 inst
[i
].SrcReg
[j
].Index
== oldIndex
) {
612 inst
[i
].SrcReg
[j
].File
= newFile
;
613 inst
[i
].SrcReg
[j
].Index
= newIndex
;
617 if (inst
[i
].DstReg
.File
== oldFile
&& inst
[i
].DstReg
.Index
== oldIndex
) {
618 inst
[i
].DstReg
.File
= newFile
;
619 inst
[i
].DstReg
.Index
= newIndex
;
626 * Search instructions for references to program parameters. When found,
627 * increment the parameter index by 'offset'.
628 * Used when combining programs.
631 adjust_param_indexes(struct prog_instruction
*inst
, GLuint numInst
,
635 for (i
= 0; i
< numInst
; i
++) {
636 for (j
= 0; j
< _mesa_num_inst_src_regs(inst
->Opcode
); j
++) {
637 GLuint f
= inst
[i
].SrcReg
[j
].File
;
638 if (f
== PROGRAM_CONSTANT
||
639 f
== PROGRAM_UNIFORM
||
640 f
== PROGRAM_STATE_VAR
) {
641 inst
[i
].SrcReg
[j
].Index
+= offset
;
649 * Combine two programs into one. Fix instructions so the outputs of
650 * the first program go to the inputs of the second program.
653 _mesa_combine_programs(GLcontext
*ctx
,
654 const struct gl_program
*progA
,
655 const struct gl_program
*progB
)
657 struct prog_instruction
*newInst
;
658 struct gl_program
*newProg
;
659 const GLuint lenA
= progA
->NumInstructions
- 1; /* omit END instr */
660 const GLuint lenB
= progB
->NumInstructions
;
661 const GLuint numParamsA
= _mesa_num_parameters(progA
->Parameters
);
662 const GLuint newLength
= lenA
+ lenB
;
666 ASSERT(progA
->Target
== progB
->Target
);
668 newInst
= _mesa_alloc_instructions(newLength
);
672 _mesa_copy_instructions(newInst
, progA
->Instructions
, lenA
);
673 _mesa_copy_instructions(newInst
+ lenA
, progB
->Instructions
, lenB
);
675 /* adjust branch / instruction addresses for B's instructions */
676 for (i
= 0; i
< lenB
; i
++) {
677 newInst
[lenA
+ i
].BranchTarget
+= lenA
;
680 newProg
= ctx
->Driver
.NewProgram(ctx
, progA
->Target
, 0);
681 newProg
->Instructions
= newInst
;
682 newProg
->NumInstructions
= newLength
;
684 if (newProg
->Target
== GL_FRAGMENT_PROGRAM_ARB
) {
685 struct gl_fragment_program
*fprogA
, *fprogB
, *newFprog
;
686 fprogA
= (struct gl_fragment_program
*) progA
;
687 fprogB
= (struct gl_fragment_program
*) progB
;
688 newFprog
= (struct gl_fragment_program
*) newProg
;
690 newFprog
->UsesKill
= fprogA
->UsesKill
|| fprogB
->UsesKill
;
692 /* Connect color outputs of fprogA to color inputs of fprogB, via a
693 * new temporary register.
695 if ((progA
->OutputsWritten
& (1 << FRAG_RESULT_COLR
)) &&
696 (progB
->InputsRead
& (1 << FRAG_ATTRIB_COL0
))) {
697 GLint tempReg
= _mesa_find_free_register(newProg
, PROGRAM_TEMPORARY
);
699 _mesa_problem(ctx
, "No free temp regs found in "
700 "_mesa_combine_programs(), using 31");
703 /* replace writes to result.color[0] with tempReg */
704 replace_registers(newInst
, lenA
,
705 PROGRAM_OUTPUT
, FRAG_RESULT_COLR
,
706 PROGRAM_TEMPORARY
, tempReg
);
707 /* replace reads from input.color[0] with tempReg */
708 replace_registers(newInst
+ lenA
, lenB
,
709 PROGRAM_INPUT
, FRAG_ATTRIB_COL0
,
710 PROGRAM_TEMPORARY
, tempReg
);
713 inputsB
= progB
->InputsRead
;
714 if (progA
->OutputsWritten
& (1 << FRAG_RESULT_COLR
)) {
715 inputsB
&= ~(1 << FRAG_ATTRIB_COL0
);
717 newProg
->InputsRead
= progA
->InputsRead
| inputsB
;
718 newProg
->OutputsWritten
= progB
->OutputsWritten
;
719 newProg
->SamplersUsed
= progA
->SamplersUsed
| progB
->SamplersUsed
;
723 assert(0); /* XXX todo */
727 * Merge parameters (uniforms, constants, etc)
729 newProg
->Parameters
= _mesa_combine_parameter_lists(progA
->Parameters
,
732 adjust_param_indexes(newInst
+ lenA
, lenB
, numParamsA
);
742 * Scan the given program to find a free register of the given type.
743 * \param regFile - PROGRAM_INPUT, PROGRAM_OUTPUT or PROGRAM_TEMPORARY
746 _mesa_find_free_register(const struct gl_program
*prog
, GLuint regFile
)
748 GLboolean used
[MAX_PROGRAM_TEMPS
];
751 assert(regFile
== PROGRAM_INPUT
||
752 regFile
== PROGRAM_OUTPUT
||
753 regFile
== PROGRAM_TEMPORARY
);
755 _mesa_memset(used
, 0, sizeof(used
));
757 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
758 const struct prog_instruction
*inst
= prog
->Instructions
+ i
;
759 const GLuint n
= _mesa_num_inst_src_regs(inst
->Opcode
);
761 for (k
= 0; k
< n
; k
++) {
762 if (inst
->SrcReg
[k
].File
== regFile
) {
763 used
[inst
->SrcReg
[k
].Index
] = GL_TRUE
;
768 for (i
= 0; i
< MAX_PROGRAM_TEMPS
; i
++) {