Merge branch 'mesa_7_5_branch'
[mesa.git] / src / mesa / shader / prog_parameter.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.3
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 /**
26 * \file prog_parameter.c
27 * Program parameter lists and functions.
28 * \author Brian Paul
29 */
30
31
32 #include "main/glheader.h"
33 #include "main/imports.h"
34 #include "main/macros.h"
35 #include "prog_instruction.h"
36 #include "prog_parameter.h"
37 #include "prog_statevars.h"
38
39
40 struct gl_program_parameter_list *
41 _mesa_new_parameter_list(void)
42 {
43 return CALLOC_STRUCT(gl_program_parameter_list);
44 }
45
46
47 struct gl_program_parameter_list *
48 _mesa_new_parameter_list_sized(unsigned size)
49 {
50 struct gl_program_parameter_list *p = _mesa_new_parameter_list();
51
52 if ((p != NULL) && (size != 0)) {
53 p->Size = size;
54
55 /* alloc arrays */
56 p->Parameters = (struct gl_program_parameter *)
57 _mesa_calloc(size * sizeof(struct gl_program_parameter));
58
59 p->ParameterValues = (GLfloat (*)[4])
60 _mesa_align_malloc(size * 4 *sizeof(GLfloat), 16);
61
62
63 if ((p->Parameters == NULL) || (p->ParameterValues == NULL)) {
64 _mesa_free(p->Parameters);
65 _mesa_align_free(p->ParameterValues);
66 _mesa_free(p);
67 p = NULL;
68 }
69 }
70
71 return p;
72 }
73
74
75 /**
76 * Free a parameter list and all its parameters
77 */
78 void
79 _mesa_free_parameter_list(struct gl_program_parameter_list *paramList)
80 {
81 GLuint i;
82 for (i = 0; i < paramList->NumParameters; i++) {
83 if (paramList->Parameters[i].Name)
84 _mesa_free((void *) paramList->Parameters[i].Name);
85 }
86 _mesa_free(paramList->Parameters);
87 if (paramList->ParameterValues)
88 _mesa_align_free(paramList->ParameterValues);
89 _mesa_free(paramList);
90 }
91
92
93 /**
94 * Add a new parameter to a parameter list.
95 * Note that parameter values are usually 4-element GLfloat vectors.
96 * When size > 4 we'll allocate a sequential block of parameters to
97 * store all the values (in blocks of 4).
98 *
99 * \param paramList the list to add the parameter to
100 * \param type type of parameter, such as
101 * \param name the parameter name, will be duplicated/copied!
102 * \param size number of elements in 'values' vector (1..4, or more)
103 * \param values initial parameter value, up to 4 GLfloats, or NULL
104 * \param state state indexes, or NULL
105 * \return index of new parameter in the list, or -1 if error (out of mem)
106 */
107 GLint
108 _mesa_add_parameter(struct gl_program_parameter_list *paramList,
109 gl_register_file type, const char *name,
110 GLuint size, GLenum datatype, const GLfloat *values,
111 const gl_state_index state[STATE_LENGTH],
112 GLbitfield flags)
113 {
114 const GLuint oldNum = paramList->NumParameters;
115 const GLuint sz4 = (size + 3) / 4; /* no. of new param slots needed */
116
117 assert(size > 0);
118
119 if (oldNum + sz4 > paramList->Size) {
120 /* Need to grow the parameter list array (alloc some extra) */
121 paramList->Size = paramList->Size + 4 * sz4;
122
123 /* realloc arrays */
124 paramList->Parameters = (struct gl_program_parameter *)
125 _mesa_realloc(paramList->Parameters,
126 oldNum * sizeof(struct gl_program_parameter),
127 paramList->Size * sizeof(struct gl_program_parameter));
128
129 paramList->ParameterValues = (GLfloat (*)[4])
130 _mesa_align_realloc(paramList->ParameterValues, /* old buf */
131 oldNum * 4 * sizeof(GLfloat), /* old size */
132 paramList->Size * 4 *sizeof(GLfloat), /* new sz */
133 16);
134 }
135
136 if (!paramList->Parameters ||
137 !paramList->ParameterValues) {
138 /* out of memory */
139 paramList->NumParameters = 0;
140 paramList->Size = 0;
141 return -1;
142 }
143 else {
144 GLuint i;
145
146 paramList->NumParameters = oldNum + sz4;
147
148 _mesa_memset(&paramList->Parameters[oldNum], 0,
149 sz4 * sizeof(struct gl_program_parameter));
150
151 for (i = 0; i < sz4; i++) {
152 struct gl_program_parameter *p = paramList->Parameters + oldNum + i;
153 p->Name = name ? _mesa_strdup(name) : NULL;
154 p->Type = type;
155 p->Size = size;
156 p->DataType = datatype;
157 p->Flags = flags;
158 if (values) {
159 COPY_4V(paramList->ParameterValues[oldNum + i], values);
160 values += 4;
161 p->Initialized = GL_TRUE;
162 }
163 else {
164 /* silence valgrind */
165 ASSIGN_4V(paramList->ParameterValues[oldNum + i], 0, 0, 0, 0);
166 }
167 size -= 4;
168 }
169
170 if (state) {
171 for (i = 0; i < STATE_LENGTH; i++)
172 paramList->Parameters[oldNum].StateIndexes[i] = state[i];
173 }
174
175 return (GLint) oldNum;
176 }
177 }
178
179
180 /**
181 * Add a new named program parameter (Ex: NV_fragment_program DEFINE statement)
182 * \return index of the new entry in the parameter list
183 */
184 GLint
185 _mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
186 const char *name, const GLfloat values[4])
187 {
188 return _mesa_add_parameter(paramList, PROGRAM_NAMED_PARAM, name,
189 4, GL_NONE, values, NULL, 0x0);
190
191 }
192
193
194 /**
195 * Add a new named constant to the parameter list.
196 * This will be used when the program contains something like this:
197 * PARAM myVals = { 0, 1, 2, 3 };
198 *
199 * \param paramList the parameter list
200 * \param name the name for the constant
201 * \param values four float values
202 * \return index/position of the new parameter in the parameter list
203 */
204 GLint
205 _mesa_add_named_constant(struct gl_program_parameter_list *paramList,
206 const char *name, const GLfloat values[4],
207 GLuint size)
208 {
209 /* first check if this is a duplicate constant */
210 GLint pos;
211 for (pos = 0; pos < paramList->NumParameters; pos++) {
212 const GLfloat *pvals = paramList->ParameterValues[pos];
213 if (pvals[0] == values[0] &&
214 pvals[1] == values[1] &&
215 pvals[2] == values[2] &&
216 pvals[3] == values[3] &&
217 _mesa_strcmp(paramList->Parameters[pos].Name, name) == 0) {
218 /* Same name and value is already in the param list - reuse it */
219 return pos;
220 }
221 }
222 /* not found, add new parameter */
223 return _mesa_add_parameter(paramList, PROGRAM_CONSTANT, name,
224 size, GL_NONE, values, NULL, 0x0);
225 }
226
227
228 /**
229 * Add a new unnamed constant to the parameter list. This will be used
230 * when a fragment/vertex program contains something like this:
231 * MOV r, { 0, 1, 2, 3 };
232 * We'll search the parameter list for an existing instance of the
233 * constant. If swizzleOut is non-null, we'll try swizzling when
234 * looking for a match.
235 *
236 * \param paramList the parameter list
237 * \param values four float values
238 * \param swizzleOut returns swizzle mask for accessing the constant
239 * \return index/position of the new parameter in the parameter list.
240 */
241 GLint
242 _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
243 const GLfloat values[4], GLuint size,
244 GLuint *swizzleOut)
245 {
246 GLint pos;
247 ASSERT(size >= 1);
248 ASSERT(size <= 4);
249
250 if (_mesa_lookup_parameter_constant(paramList, values,
251 size, &pos, swizzleOut)) {
252 return pos;
253 }
254
255 /* Look for empty space in an already unnamed constant parameter
256 * to add this constant. This will only work for single-element
257 * constants because we rely on smearing (i.e. .yyyy or .zzzz).
258 */
259 if (size == 1 && swizzleOut) {
260 for (pos = 0; pos < (GLint) paramList->NumParameters; pos++) {
261 struct gl_program_parameter *p = paramList->Parameters + pos;
262 if (p->Type == PROGRAM_CONSTANT && p->Size + size <= 4) {
263 /* ok, found room */
264 GLfloat *pVal = paramList->ParameterValues[pos];
265 GLuint swz = p->Size; /* 1, 2 or 3 for Y, Z, W */
266 pVal[p->Size] = values[0];
267 p->Size++;
268 *swizzleOut = MAKE_SWIZZLE4(swz, swz, swz, swz);
269 return pos;
270 }
271 }
272 }
273
274 /* add a new parameter to store this constant */
275 pos = _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL,
276 size, GL_NONE, values, NULL, 0x0);
277 if (pos >= 0 && swizzleOut) {
278 if (size == 1)
279 *swizzleOut = SWIZZLE_XXXX;
280 else
281 *swizzleOut = SWIZZLE_NOOP;
282 }
283 return pos;
284 }
285
286
287 /**
288 * Add a uniform to the parameter list.
289 * Note that if the uniform is an array, size may be greater than
290 * what's implied by the datatype.
291 * \param name uniform's name
292 * \param size number of floats to allocate
293 * \param datatype GL_FLOAT_VEC3, GL_FLOAT_MAT4, etc.
294 */
295 GLint
296 _mesa_add_uniform(struct gl_program_parameter_list *paramList,
297 const char *name, GLuint size, GLenum datatype,
298 const GLfloat *values)
299 {
300 GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
301 ASSERT(datatype != GL_NONE);
302 if (i >= 0 && paramList->Parameters[i].Type == PROGRAM_UNIFORM) {
303 ASSERT(paramList->Parameters[i].Size == size);
304 ASSERT(paramList->Parameters[i].DataType == datatype);
305 /* already in list */
306 return i;
307 }
308 else {
309 i = _mesa_add_parameter(paramList, PROGRAM_UNIFORM, name,
310 size, datatype, values, NULL, 0x0);
311 return i;
312 }
313 }
314
315
316 /**
317 * Mark the named uniform as 'used'.
318 */
319 void
320 _mesa_use_uniform(struct gl_program_parameter_list *paramList,
321 const char *name)
322 {
323 GLuint i;
324 for (i = 0; i < paramList->NumParameters; i++) {
325 struct gl_program_parameter *p = paramList->Parameters + i;
326 if ((p->Type == PROGRAM_UNIFORM || p->Type == PROGRAM_SAMPLER) &&
327 _mesa_strcmp(p->Name, name) == 0) {
328 p->Used = GL_TRUE;
329 /* Note that large uniforms may occupy several slots so we're
330 * not done searching yet.
331 */
332 }
333 }
334 }
335
336
337 /**
338 * Add a sampler to the parameter list.
339 * \param name uniform's name
340 * \param datatype GL_SAMPLER_2D, GL_SAMPLER_2D_RECT_ARB, etc.
341 * \param index the sampler number (as seen in TEX instructions)
342 * \return sampler index (starting at zero) or -1 if error
343 */
344 GLint
345 _mesa_add_sampler(struct gl_program_parameter_list *paramList,
346 const char *name, GLenum datatype)
347 {
348 GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
349 if (i >= 0 && paramList->Parameters[i].Type == PROGRAM_SAMPLER) {
350 ASSERT(paramList->Parameters[i].Size == 1);
351 ASSERT(paramList->Parameters[i].DataType == datatype);
352 /* already in list */
353 return (GLint) paramList->ParameterValues[i][0];
354 }
355 else {
356 GLuint i;
357 const GLint size = 1; /* a sampler is basically a texture unit number */
358 GLfloat value[4];
359 GLint numSamplers = 0;
360 for (i = 0; i < paramList->NumParameters; i++) {
361 if (paramList->Parameters[i].Type == PROGRAM_SAMPLER)
362 numSamplers++;
363 }
364 value[0] = (GLfloat) numSamplers;
365 value[1] = value[2] = value[3] = 0.0F;
366 (void) _mesa_add_parameter(paramList, PROGRAM_SAMPLER, name,
367 size, datatype, value, NULL, 0x0);
368 return numSamplers;
369 }
370 }
371
372
373 /**
374 * Add parameter representing a varying variable.
375 */
376 GLint
377 _mesa_add_varying(struct gl_program_parameter_list *paramList,
378 const char *name, GLuint size, GLbitfield flags)
379 {
380 GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
381 if (i >= 0 && paramList->Parameters[i].Type == PROGRAM_VARYING) {
382 /* already in list */
383 return i;
384 }
385 else {
386 /*assert(size == 4);*/
387 i = _mesa_add_parameter(paramList, PROGRAM_VARYING, name,
388 size, GL_NONE, NULL, NULL, flags);
389 return i;
390 }
391 }
392
393
394 /**
395 * Add parameter representing a vertex program attribute.
396 * \param size size of attribute (in floats), may be -1 if unknown
397 * \param attrib the attribute index, or -1 if unknown
398 */
399 GLint
400 _mesa_add_attribute(struct gl_program_parameter_list *paramList,
401 const char *name, GLint size, GLenum datatype, GLint attrib)
402 {
403 GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
404 if (i >= 0) {
405 /* replace */
406 if (attrib < 0)
407 attrib = i;
408 paramList->Parameters[i].StateIndexes[0] = attrib;
409 }
410 else {
411 /* add */
412 gl_state_index state[STATE_LENGTH];
413 state[0] = (gl_state_index) attrib;
414 if (size < 0)
415 size = 4;
416 i = _mesa_add_parameter(paramList, PROGRAM_INPUT, name,
417 size, datatype, NULL, state, 0x0);
418 }
419 return i;
420 }
421
422
423
424 #if 0 /* not used yet */
425 /**
426 * Returns the number of 4-component registers needed to store a piece
427 * of GL state. For matrices this may be as many as 4 registers,
428 * everything else needs
429 * just 1 register.
430 */
431 static GLuint
432 sizeof_state_reference(const GLint *stateTokens)
433 {
434 if (stateTokens[0] == STATE_MATRIX) {
435 GLuint rows = stateTokens[4] - stateTokens[3] + 1;
436 assert(rows >= 1);
437 assert(rows <= 4);
438 return rows;
439 }
440 else {
441 return 1;
442 }
443 }
444 #endif
445
446
447 /**
448 * Add a new state reference to the parameter list.
449 * This will be used when the program contains something like this:
450 * PARAM ambient = state.material.front.ambient;
451 *
452 * \param paramList the parameter list
453 * \param stateTokens an array of 5 (STATE_LENGTH) state tokens
454 * \return index of the new parameter.
455 */
456 GLint
457 _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
458 const gl_state_index stateTokens[STATE_LENGTH])
459 {
460 const GLuint size = 4; /* XXX fix */
461 char *name;
462 GLint index;
463
464 /* Check if the state reference is already in the list */
465 for (index = 0; index < (GLint) paramList->NumParameters; index++) {
466 GLuint i, match = 0;
467 for (i = 0; i < STATE_LENGTH; i++) {
468 if (paramList->Parameters[index].StateIndexes[i] == stateTokens[i]) {
469 match++;
470 }
471 else {
472 break;
473 }
474 }
475 if (match == STATE_LENGTH) {
476 /* this state reference is already in the parameter list */
477 return index;
478 }
479 }
480
481 name = _mesa_program_state_string(stateTokens);
482 index = _mesa_add_parameter(paramList, PROGRAM_STATE_VAR, name,
483 size, GL_NONE,
484 NULL, (gl_state_index *) stateTokens, 0x0);
485 paramList->StateFlags |= _mesa_program_state_flags(stateTokens);
486
487 /* free name string here since we duplicated it in add_parameter() */
488 _mesa_free(name);
489
490 return index;
491 }
492
493
494 /**
495 * Lookup a parameter value by name in the given parameter list.
496 * \return pointer to the float[4] values.
497 */
498 GLfloat *
499 _mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList,
500 GLsizei nameLen, const char *name)
501 {
502 GLuint i = _mesa_lookup_parameter_index(paramList, nameLen, name);
503 if (i < 0)
504 return NULL;
505 else
506 return paramList->ParameterValues[i];
507 }
508
509
510 /**
511 * Given a program parameter name, find its position in the list of parameters.
512 * \param paramList the parameter list to search
513 * \param nameLen length of name (in chars).
514 * If length is negative, assume that name is null-terminated.
515 * \param name the name to search for
516 * \return index of parameter in the list.
517 */
518 GLint
519 _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
520 GLsizei nameLen, const char *name)
521 {
522 GLint i;
523
524 if (!paramList)
525 return -1;
526
527 if (nameLen == -1) {
528 /* name is null-terminated */
529 for (i = 0; i < (GLint) paramList->NumParameters; i++) {
530 if (paramList->Parameters[i].Name &&
531 _mesa_strcmp(paramList->Parameters[i].Name, name) == 0)
532 return i;
533 }
534 }
535 else {
536 /* name is not null-terminated, use nameLen */
537 for (i = 0; i < (GLint) paramList->NumParameters; i++) {
538 if (paramList->Parameters[i].Name &&
539 _mesa_strncmp(paramList->Parameters[i].Name, name, nameLen) == 0
540 && _mesa_strlen(paramList->Parameters[i].Name) == (size_t)nameLen)
541 return i;
542 }
543 }
544 return -1;
545 }
546
547
548 /**
549 * Look for a float vector in the given parameter list. The float vector
550 * may be of length 1, 2, 3 or 4. If swizzleOut is non-null, we'll try
551 * swizzling to find a match.
552 * \param list the parameter list to search
553 * \param v the float vector to search for
554 * \param vSize number of element in v
555 * \param posOut returns the position of the constant, if found
556 * \param swizzleOut returns a swizzle mask describing location of the
557 * vector elements if found.
558 * \return GL_TRUE if found, GL_FALSE if not found
559 */
560 GLboolean
561 _mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
562 const GLfloat v[], GLuint vSize,
563 GLint *posOut, GLuint *swizzleOut)
564 {
565 GLuint i;
566
567 assert(vSize >= 1);
568 assert(vSize <= 4);
569
570 if (!list)
571 return -1;
572
573 for (i = 0; i < list->NumParameters; i++) {
574 if (list->Parameters[i].Type == PROGRAM_CONSTANT) {
575 if (!swizzleOut) {
576 /* swizzle not allowed */
577 GLuint j, match = 0;
578 for (j = 0; j < vSize; j++) {
579 if (v[j] == list->ParameterValues[i][j])
580 match++;
581 }
582 if (match == vSize) {
583 *posOut = i;
584 return GL_TRUE;
585 }
586 }
587 else {
588 /* try matching w/ swizzle */
589 if (vSize == 1) {
590 /* look for v[0] anywhere within float[4] value */
591 GLuint j;
592 for (j = 0; j < 4; j++) {
593 if (list->ParameterValues[i][j] == v[0]) {
594 /* found it */
595 *posOut = i;
596 *swizzleOut = MAKE_SWIZZLE4(j, j, j, j);
597 return GL_TRUE;
598 }
599 }
600 }
601 else if (vSize <= list->Parameters[i].Size) {
602 /* see if we can match this constant (with a swizzle) */
603 GLuint swz[4];
604 GLuint match = 0, j, k;
605 for (j = 0; j < vSize; j++) {
606 if (v[j] == list->ParameterValues[i][j]) {
607 swz[j] = j;
608 match++;
609 }
610 else {
611 for (k = 0; k < list->Parameters[i].Size; k++) {
612 if (v[j] == list->ParameterValues[i][k]) {
613 swz[j] = k;
614 match++;
615 break;
616 }
617 }
618 }
619 }
620 /* smear last value to remaining positions */
621 for (; j < 4; j++)
622 swz[j] = swz[j-1];
623
624 if (match == vSize) {
625 *posOut = i;
626 *swizzleOut = MAKE_SWIZZLE4(swz[0], swz[1], swz[2], swz[3]);
627 return GL_TRUE;
628 }
629 }
630 }
631 }
632 }
633
634 *posOut = -1;
635 return GL_FALSE;
636 }
637
638
639 struct gl_program_parameter_list *
640 _mesa_clone_parameter_list(const struct gl_program_parameter_list *list)
641 {
642 struct gl_program_parameter_list *clone;
643 GLuint i;
644
645 clone = _mesa_new_parameter_list();
646 if (!clone)
647 return NULL;
648
649 /** Not too efficient, but correct */
650 for (i = 0; i < list->NumParameters; i++) {
651 struct gl_program_parameter *p = list->Parameters + i;
652 struct gl_program_parameter *pCopy;
653 GLuint size = MIN2(p->Size, 4);
654 GLint j = _mesa_add_parameter(clone, p->Type, p->Name, size, p->DataType,
655 list->ParameterValues[i], NULL, 0x0);
656 ASSERT(j >= 0);
657 pCopy = clone->Parameters + j;
658 pCopy->Used = p->Used;
659 pCopy->Flags = p->Flags;
660 /* copy state indexes */
661 if (p->Type == PROGRAM_STATE_VAR) {
662 GLint k;
663 for (k = 0; k < STATE_LENGTH; k++) {
664 pCopy->StateIndexes[k] = p->StateIndexes[k];
665 }
666 }
667 else {
668 clone->Parameters[j].Size = p->Size;
669 }
670
671 }
672
673 clone->StateFlags = list->StateFlags;
674
675 return clone;
676 }
677
678
679 /**
680 * Return a new parameter list which is listA + listB.
681 */
682 struct gl_program_parameter_list *
683 _mesa_combine_parameter_lists(const struct gl_program_parameter_list *listA,
684 const struct gl_program_parameter_list *listB)
685 {
686 struct gl_program_parameter_list *list;
687
688 if (listA) {
689 list = _mesa_clone_parameter_list(listA);
690 if (list && listB) {
691 GLuint i;
692 for (i = 0; i < listB->NumParameters; i++) {
693 struct gl_program_parameter *param = listB->Parameters + i;
694 _mesa_add_parameter(list, param->Type, param->Name, param->Size,
695 param->DataType,
696 listB->ParameterValues[i],
697 param->StateIndexes,
698 param->Flags);
699 }
700 }
701 }
702 else if (listB) {
703 list = _mesa_clone_parameter_list(listB);
704 }
705 else {
706 list = NULL;
707 }
708 return list;
709 }
710
711
712
713 /**
714 * Find longest name of all uniform parameters in list.
715 */
716 GLuint
717 _mesa_longest_parameter_name(const struct gl_program_parameter_list *list,
718 gl_register_file type)
719 {
720 GLuint i, maxLen = 0;
721 if (!list)
722 return 0;
723 for (i = 0; i < list->NumParameters; i++) {
724 if (list->Parameters[i].Type == type) {
725 GLuint len = _mesa_strlen(list->Parameters[i].Name);
726 if (len > maxLen)
727 maxLen = len;
728 }
729 }
730 return maxLen;
731 }
732
733
734 /**
735 * Count the number of parameters in the last that match the given type.
736 */
737 GLuint
738 _mesa_num_parameters_of_type(const struct gl_program_parameter_list *list,
739 gl_register_file type)
740 {
741 GLuint i, count = 0;
742 if (list) {
743 for (i = 0; i < list->NumParameters; i++) {
744 if (list->Parameters[i].Type == type)
745 count++;
746 }
747 }
748 return count;
749 }