mesa/main: Clamp GetUniformui64v values to be >= 0
[mesa.git] / src / mesa / main / uniform_query.cpp
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009-2010 VMware, Inc. All Rights Reserved.
6 * Copyright © 2010, 2011 Intel Corporation
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 #include <stdlib.h>
28 #include <inttypes.h> /* for PRIx64 macro */
29
30 #include "main/core.h"
31 #include "main/context.h"
32 #include "main/shaderapi.h"
33 #include "main/shaderobj.h"
34 #include "main/uniforms.h"
35 #include "compiler/glsl/ir.h"
36 #include "compiler/glsl/ir_uniform.h"
37 #include "compiler/glsl/glsl_parser_extras.h"
38 #include "compiler/glsl/program.h"
39 #include "util/bitscan.h"
40
41
42 extern "C" void GLAPIENTRY
43 _mesa_GetActiveUniform(GLuint program, GLuint index,
44 GLsizei maxLength, GLsizei *length, GLint *size,
45 GLenum *type, GLcharARB *nameOut)
46 {
47 GET_CURRENT_CONTEXT(ctx);
48 struct gl_shader_program *shProg;
49 struct gl_program_resource *res;
50
51 if (maxLength < 0) {
52 _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniform(maxLength < 0)");
53 return;
54 }
55
56 shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveUniform");
57 if (!shProg)
58 return;
59
60 res = _mesa_program_resource_find_index((struct gl_shader_program *) shProg,
61 GL_UNIFORM, index);
62
63 if (!res) {
64 _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniform(index)");
65 return;
66 }
67
68 if (nameOut)
69 _mesa_get_program_resource_name(shProg, GL_UNIFORM, index, maxLength,
70 length, nameOut, "glGetActiveUniform");
71 if (type)
72 _mesa_program_resource_prop((struct gl_shader_program *) shProg,
73 res, index, GL_TYPE, (GLint*) type,
74 "glGetActiveUniform");
75 if (size)
76 _mesa_program_resource_prop((struct gl_shader_program *) shProg,
77 res, index, GL_ARRAY_SIZE, (GLint*) size,
78 "glGetActiveUniform");
79 }
80
81 static GLenum
82 resource_prop_from_uniform_prop(GLenum uni_prop)
83 {
84 switch (uni_prop) {
85 case GL_UNIFORM_TYPE:
86 return GL_TYPE;
87 case GL_UNIFORM_SIZE:
88 return GL_ARRAY_SIZE;
89 case GL_UNIFORM_NAME_LENGTH:
90 return GL_NAME_LENGTH;
91 case GL_UNIFORM_BLOCK_INDEX:
92 return GL_BLOCK_INDEX;
93 case GL_UNIFORM_OFFSET:
94 return GL_OFFSET;
95 case GL_UNIFORM_ARRAY_STRIDE:
96 return GL_ARRAY_STRIDE;
97 case GL_UNIFORM_MATRIX_STRIDE:
98 return GL_MATRIX_STRIDE;
99 case GL_UNIFORM_IS_ROW_MAJOR:
100 return GL_IS_ROW_MAJOR;
101 case GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX:
102 return GL_ATOMIC_COUNTER_BUFFER_INDEX;
103 default:
104 return 0;
105 }
106 }
107
108 extern "C" void GLAPIENTRY
109 _mesa_GetActiveUniformsiv(GLuint program,
110 GLsizei uniformCount,
111 const GLuint *uniformIndices,
112 GLenum pname,
113 GLint *params)
114 {
115 GET_CURRENT_CONTEXT(ctx);
116 struct gl_shader_program *shProg;
117 struct gl_program_resource *res;
118 GLenum res_prop;
119
120 if (uniformCount < 0) {
121 _mesa_error(ctx, GL_INVALID_VALUE,
122 "glGetActiveUniformsiv(uniformCount < 0)");
123 return;
124 }
125
126 shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveUniform");
127 if (!shProg)
128 return;
129
130 res_prop = resource_prop_from_uniform_prop(pname);
131
132 /* We need to first verify that each entry exists as active uniform. If
133 * not, generate error and do not cause any other side effects.
134 *
135 * In the case of and error condition, Page 16 (section 2.3.1 Errors)
136 * of the OpenGL 4.5 spec says:
137 *
138 * "If the generating command modifies values through a pointer argu-
139 * ment, no change is made to these values."
140 */
141 for (int i = 0; i < uniformCount; i++) {
142 if (!_mesa_program_resource_find_index(shProg, GL_UNIFORM,
143 uniformIndices[i])) {
144 _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniformsiv(index)");
145 return;
146 }
147 }
148
149 for (int i = 0; i < uniformCount; i++) {
150 res = _mesa_program_resource_find_index(shProg, GL_UNIFORM,
151 uniformIndices[i]);
152 if (!_mesa_program_resource_prop(shProg, res, uniformIndices[i],
153 res_prop, &params[i],
154 "glGetActiveUniformsiv"))
155 break;
156 }
157 }
158
159 static struct gl_uniform_storage *
160 validate_uniform_parameters(GLint location, GLsizei count,
161 unsigned *array_index,
162 struct gl_context *ctx,
163 struct gl_shader_program *shProg,
164 const char *caller)
165 {
166 if (shProg == NULL) {
167 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(program not linked)", caller);
168 return NULL;
169 }
170
171 /* From page 12 (page 26 of the PDF) of the OpenGL 2.1 spec:
172 *
173 * "If a negative number is provided where an argument of type sizei or
174 * sizeiptr is specified, the error INVALID_VALUE is generated."
175 */
176 if (count < 0) {
177 _mesa_error(ctx, GL_INVALID_VALUE, "%s(count < 0)", caller);
178 return NULL;
179 }
180
181 /* Check that the given location is in bounds of uniform remap table.
182 * Unlinked programs will have NumUniformRemapTable == 0, so we can take
183 * the shProg->data->LinkStatus check out of the main path.
184 */
185 if (unlikely(location >= (GLint) shProg->NumUniformRemapTable)) {
186 if (!shProg->data->LinkStatus)
187 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(program not linked)",
188 caller);
189 else
190 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)",
191 caller, location);
192
193 return NULL;
194 }
195
196 if (location == -1) {
197 if (!shProg->data->LinkStatus)
198 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(program not linked)",
199 caller);
200
201 return NULL;
202 }
203
204 /* Page 82 (page 96 of the PDF) of the OpenGL 2.1 spec says:
205 *
206 * "If any of the following conditions occur, an INVALID_OPERATION
207 * error is generated by the Uniform* commands, and no uniform values
208 * are changed:
209 *
210 * ...
211 *
212 * - if no variable with a location of location exists in the
213 * program object currently in use and location is not -1,
214 * - if count is greater than one, and the uniform declared in the
215 * shader is not an array variable,
216 */
217 if (location < -1 || !shProg->UniformRemapTable[location]) {
218 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)",
219 caller, location);
220 return NULL;
221 }
222
223 /* If the driver storage pointer in remap table is -1, we ignore silently.
224 *
225 * GL_ARB_explicit_uniform_location spec says:
226 * "What happens if Uniform* is called with an explicitly defined
227 * uniform location, but that uniform is deemed inactive by the
228 * linker?
229 *
230 * RESOLVED: The call is ignored for inactive uniform variables and
231 * no error is generated."
232 *
233 */
234 if (shProg->UniformRemapTable[location] ==
235 INACTIVE_UNIFORM_EXPLICIT_LOCATION)
236 return NULL;
237
238 struct gl_uniform_storage *const uni = shProg->UniformRemapTable[location];
239
240 /* Even though no location is assigned to a built-in uniform and this
241 * function should already have returned NULL, this test makes it explicit
242 * that we are not allowing to update the value of a built-in.
243 */
244 if (uni->builtin)
245 return NULL;
246
247 if (uni->array_elements == 0) {
248 if (count > 1) {
249 _mesa_error(ctx, GL_INVALID_OPERATION,
250 "%s(count = %u for non-array \"%s\"@%d)",
251 caller, count, uni->name, location);
252 return NULL;
253 }
254
255 assert((location - uni->remap_location) == 0);
256 *array_index = 0;
257 } else {
258 /* The array index specified by the uniform location is just the uniform
259 * location minus the base location of of the uniform.
260 */
261 *array_index = location - uni->remap_location;
262
263 /* If the uniform is an array, check that array_index is in bounds.
264 * array_index is unsigned so no need to check for less than zero.
265 */
266 if (*array_index >= uni->array_elements) {
267 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)",
268 caller, location);
269 return NULL;
270 }
271 }
272 return uni;
273 }
274
275 /**
276 * Called via glGetUniform[fiui]v() to get the current value of a uniform.
277 */
278 extern "C" void
279 _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
280 GLsizei bufSize, enum glsl_base_type returnType,
281 GLvoid *paramsOut)
282 {
283 struct gl_shader_program *shProg =
284 _mesa_lookup_shader_program_err(ctx, program, "glGetUniformfv");
285 unsigned offset;
286
287 struct gl_uniform_storage *const uni =
288 validate_uniform_parameters(location, 1, &offset,
289 ctx, shProg, "glGetUniform");
290 if (uni == NULL) {
291 /* For glGetUniform, page 264 (page 278 of the PDF) of the OpenGL 2.1
292 * spec says:
293 *
294 * "The error INVALID_OPERATION is generated if program has not been
295 * linked successfully, or if location is not a valid location for
296 * program."
297 *
298 * For glUniform, page 82 (page 96 of the PDF) of the OpenGL 2.1 spec
299 * says:
300 *
301 * "If the value of location is -1, the Uniform* commands will
302 * silently ignore the data passed in, and the current uniform
303 * values will not be changed."
304 *
305 * Allowing -1 for the location parameter of glUniform allows
306 * applications to avoid error paths in the case that, for example, some
307 * uniform variable is removed by the compiler / linker after
308 * optimization. In this case, the new value of the uniform is dropped
309 * on the floor. For the case of glGetUniform, there is nothing
310 * sensible to do for a location of -1.
311 *
312 * If the location was -1, validate_unfirom_parameters will return NULL
313 * without raising an error. Raise the error here.
314 */
315 if (location == -1) {
316 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniform(location=%d)",
317 location);
318 }
319
320 return;
321 }
322
323 {
324 unsigned elements = uni->type->components();
325 /* XXX: Remove the sampler/image check workarounds when bindless is fully
326 * implemented.
327 */
328 const int dmul =
329 (uni->type->is_64bit() && !uni->type->is_sampler() && !uni->type->is_image()) ? 2 : 1;
330 const int rmul = glsl_base_type_is_64bit(returnType) ? 2 : 1;
331
332 /* Calculate the source base address *BEFORE* modifying elements to
333 * account for the size of the user's buffer.
334 */
335 const union gl_constant_value *const src =
336 &uni->storage[offset * elements * dmul];
337
338 assert(returnType == GLSL_TYPE_FLOAT || returnType == GLSL_TYPE_INT ||
339 returnType == GLSL_TYPE_UINT || returnType == GLSL_TYPE_DOUBLE ||
340 returnType == GLSL_TYPE_UINT64 || returnType == GLSL_TYPE_INT64);
341
342 /* doubles have a different size than the other 3 types */
343 unsigned bytes = sizeof(src[0]) * elements * rmul;
344 if (bufSize < 0 || bytes > (unsigned) bufSize) {
345 _mesa_error(ctx, GL_INVALID_OPERATION,
346 "glGetnUniform*vARB(out of bounds: bufSize is %d,"
347 " but %u bytes are required)", bufSize, bytes);
348 return;
349 }
350
351 /* If the return type and the uniform's native type are "compatible,"
352 * just memcpy the data. If the types are not compatible, perform a
353 * slower convert-and-copy process.
354 */
355 if (returnType == uni->type->base_type ||
356 ((returnType == GLSL_TYPE_INT || returnType == GLSL_TYPE_UINT) &&
357 (uni->type->is_sampler() || uni->type->is_image()))) {
358 memcpy(paramsOut, src, bytes);
359 } else {
360 union gl_constant_value *const dst =
361 (union gl_constant_value *) paramsOut;
362 /* This code could be optimized by putting the loop inside the switch
363 * statements. However, this is not expected to be
364 * performance-critical code.
365 */
366 for (unsigned i = 0; i < elements; i++) {
367 int sidx = i * dmul;
368 int didx = i * rmul;
369
370 switch (returnType) {
371 case GLSL_TYPE_FLOAT:
372 switch (uni->type->base_type) {
373 case GLSL_TYPE_UINT:
374 dst[didx].f = (float) src[sidx].u;
375 break;
376 case GLSL_TYPE_INT:
377 case GLSL_TYPE_SAMPLER:
378 case GLSL_TYPE_IMAGE:
379 dst[didx].f = (float) src[sidx].i;
380 break;
381 case GLSL_TYPE_BOOL:
382 dst[didx].f = src[sidx].i ? 1.0f : 0.0f;
383 break;
384 case GLSL_TYPE_DOUBLE: {
385 double tmp;
386 memcpy(&tmp, &src[sidx].f, sizeof(tmp));
387 dst[didx].f = tmp;
388 break;
389 }
390 case GLSL_TYPE_UINT64: {
391 uint64_t tmp;
392 memcpy(&tmp, &src[sidx].u, sizeof(tmp));
393 dst[didx].f = tmp;
394 break;
395 }
396 case GLSL_TYPE_INT64: {
397 uint64_t tmp;
398 memcpy(&tmp, &src[sidx].i, sizeof(tmp));
399 dst[didx].f = tmp;
400 break;
401 }
402 default:
403 assert(!"Should not get here.");
404 break;
405 }
406 break;
407
408 case GLSL_TYPE_DOUBLE:
409 switch (uni->type->base_type) {
410 case GLSL_TYPE_UINT: {
411 double tmp = src[sidx].u;
412 memcpy(&dst[didx].f, &tmp, sizeof(tmp));
413 break;
414 }
415 case GLSL_TYPE_INT:
416 case GLSL_TYPE_SAMPLER:
417 case GLSL_TYPE_IMAGE: {
418 double tmp = src[sidx].i;
419 memcpy(&dst[didx].f, &tmp, sizeof(tmp));
420 break;
421 }
422 case GLSL_TYPE_BOOL: {
423 double tmp = src[sidx].i ? 1.0 : 0.0;
424 memcpy(&dst[didx].f, &tmp, sizeof(tmp));
425 break;
426 }
427 case GLSL_TYPE_FLOAT: {
428 double tmp = src[sidx].f;
429 memcpy(&dst[didx].f, &tmp, sizeof(tmp));
430 break;
431 }
432 case GLSL_TYPE_UINT64: {
433 uint64_t tmpu;
434 double tmp;
435 memcpy(&tmpu, &src[sidx].u, sizeof(tmpu));
436 tmp = tmpu;
437 memcpy(&dst[didx].f, &tmp, sizeof(tmp));
438 break;
439 }
440 case GLSL_TYPE_INT64: {
441 int64_t tmpi;
442 double tmp;
443 memcpy(&tmpi, &src[sidx].i, sizeof(tmpi));
444 tmp = tmpi;
445 memcpy(&dst[didx].f, &tmp, sizeof(tmp));
446 break;
447 }
448 default:
449 assert(!"Should not get here.");
450 break;
451 }
452 break;
453
454 case GLSL_TYPE_INT:
455 switch (uni->type->base_type) {
456 case GLSL_TYPE_FLOAT:
457 /* While the GL 3.2 core spec doesn't explicitly
458 * state how conversion of float uniforms to integer
459 * values works, in section 6.2 "State Tables" on
460 * page 267 it says:
461 *
462 * "Unless otherwise specified, when floating
463 * point state is returned as integer values or
464 * integer state is returned as floating-point
465 * values it is converted in the fashion
466 * described in section 6.1.2"
467 *
468 * That section, on page 248, says:
469 *
470 * "If GetIntegerv or GetInteger64v are called,
471 * a floating-point value is rounded to the
472 * nearest integer..."
473 */
474 dst[didx].i = IROUND(src[sidx].f);
475 break;
476 case GLSL_TYPE_BOOL:
477 dst[didx].i = src[sidx].i ? 1 : 0;
478 break;
479 case GLSL_TYPE_UINT:
480 dst[didx].i = MIN2(src[sidx].i, INT_MAX);
481 break;
482 case GLSL_TYPE_DOUBLE: {
483 double tmp;
484 memcpy(&tmp, &src[sidx].f, sizeof(tmp));
485 dst[didx].i = IROUNDD(tmp);
486 break;
487 }
488 case GLSL_TYPE_UINT64: {
489 uint64_t tmp;
490 memcpy(&tmp, &src[sidx].u, sizeof(tmp));
491 dst[didx].i = tmp;
492 break;
493 }
494 case GLSL_TYPE_INT64: {
495 int64_t tmp;
496 memcpy(&tmp, &src[sidx].i, sizeof(tmp));
497 dst[didx].i = tmp;
498 break;
499 }
500 default:
501 assert(!"Should not get here.");
502 break;
503 }
504 break;
505
506 case GLSL_TYPE_UINT:
507 switch (uni->type->base_type) {
508 case GLSL_TYPE_FLOAT:
509 /* The spec isn't terribly clear how to handle negative
510 * values with an unsigned return type.
511 *
512 * GL 4.5 section 2.2.2 ("Data Conversions for State
513 * Query Commands") says:
514 *
515 * "If a value is so large in magnitude that it cannot be
516 * represented by the returned data type, then the nearest
517 * value representable using the requested type is
518 * returned."
519 */
520 dst[didx].u = src[sidx].f < 0.0f ?
521 0u : (uint32_t) roundf(src[sidx].f);
522 break;
523 case GLSL_TYPE_BOOL:
524 dst[didx].i = src[sidx].i ? 1 : 0;
525 break;
526 case GLSL_TYPE_INT:
527 dst[didx].i = MAX2(src[sidx].i, 0);
528 break;
529 case GLSL_TYPE_DOUBLE: {
530 double tmp;
531 memcpy(&tmp, &src[sidx].f, sizeof(tmp));
532 dst[didx].u = tmp < 0.0 ? 0u : (uint32_t) round(tmp);
533 break;
534 }
535 case GLSL_TYPE_UINT64: {
536 uint64_t tmp;
537 memcpy(&tmp, &src[sidx].u, sizeof(tmp));
538 dst[didx].i = MIN2(tmp, INT_MAX);
539 break;
540 }
541 case GLSL_TYPE_INT64: {
542 int64_t tmp;
543 memcpy(&tmp, &src[sidx].i, sizeof(tmp));
544 dst[didx].i = MAX2(tmp, 0);
545 break;
546 }
547 default:
548 unreachable("invalid uniform type");
549 }
550 break;
551
552 case GLSL_TYPE_INT64:
553 switch (uni->type->base_type) {
554 case GLSL_TYPE_UINT: {
555 uint64_t tmp = src[sidx].u;
556 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
557 break;
558 }
559 case GLSL_TYPE_INT:
560 case GLSL_TYPE_SAMPLER:
561 case GLSL_TYPE_IMAGE: {
562 int64_t tmp = src[sidx].i;
563 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
564 break;
565 }
566 case GLSL_TYPE_BOOL: {
567 int64_t tmp = src[sidx].i ? 1.0f : 0.0f;
568 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
569 break;
570 }
571 case GLSL_TYPE_UINT64: {
572 uint64_t u64;
573 memcpy(&u64, &src[sidx].u, sizeof(u64));
574 int64_t tmp = MIN2(u64, INT_MAX);
575 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
576 break;
577 }
578 case GLSL_TYPE_FLOAT: {
579 int64_t tmp = src[sidx].f;
580 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
581 break;
582 }
583 default:
584 assert(!"Should not get here.");
585 break;
586 }
587 break;
588
589 case GLSL_TYPE_UINT64:
590 switch (uni->type->base_type) {
591 case GLSL_TYPE_UINT: {
592 uint64_t tmp = src[sidx].u;
593 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
594 break;
595 }
596 case GLSL_TYPE_INT:
597 case GLSL_TYPE_SAMPLER:
598 case GLSL_TYPE_IMAGE: {
599 int64_t tmp = MAX2(src[sidx].i, 0);
600 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
601 break;
602 }
603 case GLSL_TYPE_BOOL: {
604 int64_t tmp = src[sidx].i ? 1.0f : 0.0f;
605 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
606 break;
607 }
608 case GLSL_TYPE_INT64: {
609 uint64_t i64;
610 memcpy(&i64, &src[sidx].i, sizeof(i64));
611 uint64_t tmp = MAX2(i64, 0);
612 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
613 break;
614 }
615 case GLSL_TYPE_FLOAT: {
616 uint64_t tmp = src[sidx].f < 0.0f ?
617 0ull : (uint64_t) roundf(src[sidx].f);
618 memcpy(&dst[didx].u, &tmp, sizeof(tmp));
619 break;
620 }
621 default:
622 assert(!"Should not get here.");
623 break;
624 }
625 break;
626
627 default:
628 assert(!"Should not get here.");
629 break;
630 }
631 }
632 }
633 }
634 }
635
636 static void
637 log_uniform(const void *values, enum glsl_base_type basicType,
638 unsigned rows, unsigned cols, unsigned count,
639 bool transpose,
640 const struct gl_shader_program *shProg,
641 GLint location,
642 const struct gl_uniform_storage *uni)
643 {
644
645 const union gl_constant_value *v = (const union gl_constant_value *) values;
646 const unsigned elems = rows * cols * count;
647 const char *const extra = (cols == 1) ? "uniform" : "uniform matrix";
648
649 printf("Mesa: set program %u %s \"%s\" (loc %d, type \"%s\", "
650 "transpose = %s) to: ",
651 shProg->Name, extra, uni->name, location, uni->type->name,
652 transpose ? "true" : "false");
653 for (unsigned i = 0; i < elems; i++) {
654 if (i != 0 && ((i % rows) == 0))
655 printf(", ");
656
657 switch (basicType) {
658 case GLSL_TYPE_UINT:
659 printf("%u ", v[i].u);
660 break;
661 case GLSL_TYPE_INT:
662 printf("%d ", v[i].i);
663 break;
664 case GLSL_TYPE_UINT64: {
665 uint64_t tmp;
666 memcpy(&tmp, &v[i * 2].u, sizeof(tmp));
667 printf("%" PRIu64 " ", tmp);
668 break;
669 }
670 case GLSL_TYPE_INT64: {
671 int64_t tmp;
672 memcpy(&tmp, &v[i * 2].u, sizeof(tmp));
673 printf("%" PRId64 " ", tmp);
674 break;
675 }
676 case GLSL_TYPE_FLOAT:
677 printf("%g ", v[i].f);
678 break;
679 case GLSL_TYPE_DOUBLE: {
680 double tmp;
681 memcpy(&tmp, &v[i * 2].f, sizeof(tmp));
682 printf("%g ", tmp);
683 break;
684 }
685 default:
686 assert(!"Should not get here.");
687 break;
688 }
689 }
690 printf("\n");
691 fflush(stdout);
692 }
693
694 #if 0
695 static void
696 log_program_parameters(const struct gl_shader_program *shProg)
697 {
698 for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
699 if (shProg->_LinkedShaders[i] == NULL)
700 continue;
701
702 const struct gl_program *const prog = shProg->_LinkedShaders[i]->Program;
703
704 printf("Program %d %s shader parameters:\n",
705 shProg->Name, _mesa_shader_stage_to_string(i));
706 for (unsigned j = 0; j < prog->Parameters->NumParameters; j++) {
707 printf("%s: %p %f %f %f %f\n",
708 prog->Parameters->Parameters[j].Name,
709 prog->Parameters->ParameterValues[j],
710 prog->Parameters->ParameterValues[j][0].f,
711 prog->Parameters->ParameterValues[j][1].f,
712 prog->Parameters->ParameterValues[j][2].f,
713 prog->Parameters->ParameterValues[j][3].f);
714 }
715 }
716 fflush(stdout);
717 }
718 #endif
719
720 /**
721 * Propagate some values from uniform backing storage to driver storage
722 *
723 * Values propagated from uniform backing storage to driver storage
724 * have all format / type conversions previously requested by the
725 * driver applied. This function is most often called by the
726 * implementations of \c glUniform1f, etc. and \c glUniformMatrix2f,
727 * etc.
728 *
729 * \param uni Uniform whose data is to be propagated to driver storage
730 * \param array_index If \c uni is an array, this is the element of
731 * the array to be propagated.
732 * \param count Number of array elements to propagate.
733 */
734 extern "C" void
735 _mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage *uni,
736 unsigned array_index,
737 unsigned count)
738 {
739 unsigned i;
740
741 const unsigned components = uni->type->vector_elements;
742 const unsigned vectors = uni->type->matrix_columns;
743 const int dmul = uni->type->is_64bit() ? 2 : 1;
744
745 /* Store the data in the driver's requested type in the driver's storage
746 * areas.
747 */
748 unsigned src_vector_byte_stride = components * 4 * dmul;
749
750 for (i = 0; i < uni->num_driver_storage; i++) {
751 struct gl_uniform_driver_storage *const store = &uni->driver_storage[i];
752 uint8_t *dst = (uint8_t *) store->data;
753 const unsigned extra_stride =
754 store->element_stride - (vectors * store->vector_stride);
755 const uint8_t *src =
756 (uint8_t *) (&uni->storage[array_index * (dmul * components * vectors)].i);
757
758 #if 0
759 printf("%s: %p[%d] components=%u vectors=%u count=%u vector_stride=%u "
760 "extra_stride=%u\n",
761 __func__, dst, array_index, components,
762 vectors, count, store->vector_stride, extra_stride);
763 #endif
764
765 dst += array_index * store->element_stride;
766
767 switch (store->format) {
768 case uniform_native: {
769 unsigned j;
770 unsigned v;
771
772 if (src_vector_byte_stride == store->vector_stride) {
773 if (extra_stride) {
774 for (j = 0; j < count; j++) {
775 memcpy(dst, src, src_vector_byte_stride * vectors);
776 src += src_vector_byte_stride * vectors;
777 dst += store->vector_stride * vectors;
778
779 dst += extra_stride;
780 }
781 } else {
782 /* Unigine Heaven benchmark gets here */
783 memcpy(dst, src, src_vector_byte_stride * vectors * count);
784 src += src_vector_byte_stride * vectors * count;
785 dst += store->vector_stride * vectors * count;
786 }
787 } else {
788 for (j = 0; j < count; j++) {
789 for (v = 0; v < vectors; v++) {
790 memcpy(dst, src, src_vector_byte_stride);
791 src += src_vector_byte_stride;
792 dst += store->vector_stride;
793 }
794
795 dst += extra_stride;
796 }
797 }
798 break;
799 }
800
801 case uniform_int_float: {
802 const int *isrc = (const int *) src;
803 unsigned j;
804 unsigned v;
805 unsigned c;
806
807 for (j = 0; j < count; j++) {
808 for (v = 0; v < vectors; v++) {
809 for (c = 0; c < components; c++) {
810 ((float *) dst)[c] = (float) *isrc;
811 isrc++;
812 }
813
814 dst += store->vector_stride;
815 }
816
817 dst += extra_stride;
818 }
819 break;
820 }
821
822 default:
823 assert(!"Should not get here.");
824 break;
825 }
826 }
827 }
828
829
830 /**
831 * Return printable string for a given GLSL_TYPE_x
832 */
833 static const char *
834 glsl_type_name(enum glsl_base_type type)
835 {
836 switch (type) {
837 case GLSL_TYPE_UINT:
838 return "uint";
839 case GLSL_TYPE_INT:
840 return "int";
841 case GLSL_TYPE_FLOAT:
842 return "float";
843 case GLSL_TYPE_DOUBLE:
844 return "double";
845 case GLSL_TYPE_UINT64:
846 return "uint64";
847 case GLSL_TYPE_INT64:
848 return "int64";
849 case GLSL_TYPE_BOOL:
850 return "bool";
851 case GLSL_TYPE_SAMPLER:
852 return "sampler";
853 case GLSL_TYPE_IMAGE:
854 return "image";
855 case GLSL_TYPE_ATOMIC_UINT:
856 return "atomic_uint";
857 case GLSL_TYPE_STRUCT:
858 return "struct";
859 case GLSL_TYPE_INTERFACE:
860 return "interface";
861 case GLSL_TYPE_ARRAY:
862 return "array";
863 case GLSL_TYPE_VOID:
864 return "void";
865 case GLSL_TYPE_ERROR:
866 return "error";
867 default:
868 return "other";
869 }
870 }
871
872
873 static struct gl_uniform_storage *
874 validate_uniform(GLint location, GLsizei count, const GLvoid *values,
875 unsigned *offset, struct gl_context *ctx,
876 struct gl_shader_program *shProg,
877 enum glsl_base_type basicType, unsigned src_components)
878 {
879 struct gl_uniform_storage *const uni =
880 validate_uniform_parameters(location, count, offset,
881 ctx, shProg, "glUniform");
882 if (uni == NULL)
883 return NULL;
884
885 if (uni->type->is_matrix()) {
886 /* Can't set matrix uniforms (like mat4) with glUniform */
887 _mesa_error(ctx, GL_INVALID_OPERATION,
888 "glUniform%u(uniform \"%s\"@%d is matrix)",
889 src_components, uni->name, location);
890 return NULL;
891 }
892
893 /* Verify that the types are compatible. */
894 const unsigned components = uni->type->vector_elements;
895
896 if (components != src_components) {
897 /* glUniformN() must match float/vecN type */
898 _mesa_error(ctx, GL_INVALID_OPERATION,
899 "glUniform%u(\"%s\"@%u has %u components, not %u)",
900 src_components, uni->name, location,
901 components, src_components);
902 return NULL;
903 }
904
905 bool match;
906 switch (uni->type->base_type) {
907 case GLSL_TYPE_BOOL:
908 match = (basicType != GLSL_TYPE_DOUBLE);
909 break;
910 case GLSL_TYPE_SAMPLER:
911 match = (basicType == GLSL_TYPE_INT);
912 break;
913 case GLSL_TYPE_IMAGE:
914 match = (basicType == GLSL_TYPE_INT && _mesa_is_desktop_gl(ctx));
915 break;
916 default:
917 match = (basicType == uni->type->base_type);
918 break;
919 }
920
921 if (!match) {
922 _mesa_error(ctx, GL_INVALID_OPERATION,
923 "glUniform%u(\"%s\"@%d is %s, not %s)",
924 src_components, uni->name, location,
925 glsl_type_name(uni->type->base_type),
926 glsl_type_name(basicType));
927 return NULL;
928 }
929
930 if (unlikely(ctx->_Shader->Flags & GLSL_UNIFORMS)) {
931 log_uniform(values, basicType, components, 1, count,
932 false, shProg, location, uni);
933 }
934
935 /* Page 100 (page 116 of the PDF) of the OpenGL 3.0 spec says:
936 *
937 * "Setting a sampler's value to i selects texture image unit number
938 * i. The values of i range from zero to the implementation- dependent
939 * maximum supported number of texture image units."
940 *
941 * In addition, table 2.3, "Summary of GL errors," on page 17 (page 33 of
942 * the PDF) says:
943 *
944 * "Error Description Offending command
945 * ignored?
946 * ...
947 * INVALID_VALUE Numeric argument out of range Yes"
948 *
949 * Based on that, when an invalid sampler is specified, we generate a
950 * GL_INVALID_VALUE error and ignore the command.
951 */
952 if (uni->type->is_sampler()) {
953 for (int i = 0; i < count; i++) {
954 const unsigned texUnit = ((unsigned *) values)[i];
955
956 /* check that the sampler (tex unit index) is legal */
957 if (texUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
958 _mesa_error(ctx, GL_INVALID_VALUE,
959 "glUniform1i(invalid sampler/tex unit index for "
960 "uniform %d)", location);
961 return NULL;
962 }
963 }
964 /* We need to reset the validate flag on changes to samplers in case
965 * two different sampler types are set to the same texture unit.
966 */
967 ctx->_Shader->Validated = GL_FALSE;
968 }
969
970 if (uni->type->is_image()) {
971 for (int i = 0; i < count; i++) {
972 const int unit = ((GLint *) values)[i];
973
974 /* check that the image unit is legal */
975 if (unit < 0 || unit >= (int)ctx->Const.MaxImageUnits) {
976 _mesa_error(ctx, GL_INVALID_VALUE,
977 "glUniform1i(invalid image unit index for uniform %d)",
978 location);
979 return NULL;
980 }
981 }
982 }
983
984 return uni;
985 }
986
987
988 /**
989 * Called via glUniform*() functions.
990 */
991 extern "C" void
992 _mesa_uniform(GLint location, GLsizei count, const GLvoid *values,
993 struct gl_context *ctx, struct gl_shader_program *shProg,
994 enum glsl_base_type basicType, unsigned src_components)
995 {
996 unsigned offset;
997 int size_mul = glsl_base_type_is_64bit(basicType) ? 2 : 1;
998
999 struct gl_uniform_storage *uni;
1000 if (_mesa_is_no_error_enabled(ctx)) {
1001 /* From Seciton 7.6 (UNIFORM VARIABLES) of the OpenGL 4.5 spec:
1002 *
1003 * "If the value of location is -1, the Uniform* commands will
1004 * silently ignore the data passed in, and the current uniform values
1005 * will not be changed.
1006 */
1007 if (location == -1)
1008 return;
1009
1010 uni = shProg->UniformRemapTable[location];
1011
1012 /* The array index specified by the uniform location is just the
1013 * uniform location minus the base location of of the uniform.
1014 */
1015 assert(uni->array_elements > 0 || location == (int)uni->remap_location);
1016 offset = location - uni->remap_location;
1017 } else {
1018 uni = validate_uniform(location, count, values, &offset, ctx, shProg,
1019 basicType, src_components);
1020 if (!uni)
1021 return;
1022 }
1023
1024 const unsigned components = uni->type->vector_elements;
1025
1026 /* Page 82 (page 96 of the PDF) of the OpenGL 2.1 spec says:
1027 *
1028 * "When loading N elements starting at an arbitrary position k in a
1029 * uniform declared as an array, elements k through k + N - 1 in the
1030 * array will be replaced with the new values. Values for any array
1031 * element that exceeds the highest array element index used, as
1032 * reported by GetActiveUniform, will be ignored by the GL."
1033 *
1034 * Clamp 'count' to a valid value. Note that for non-arrays a count > 1
1035 * will have already generated an error.
1036 */
1037 if (uni->array_elements != 0) {
1038 count = MIN2(count, (int) (uni->array_elements - offset));
1039 }
1040
1041 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
1042
1043 /* Store the data in the "actual type" backing storage for the uniform.
1044 */
1045 if (!uni->type->is_boolean()) {
1046 memcpy(&uni->storage[size_mul * components * offset], values,
1047 sizeof(uni->storage[0]) * components * count * size_mul);
1048 } else {
1049 const union gl_constant_value *src =
1050 (const union gl_constant_value *) values;
1051 union gl_constant_value *dst = &uni->storage[components * offset];
1052 const unsigned elems = components * count;
1053
1054 for (unsigned i = 0; i < elems; i++) {
1055 if (basicType == GLSL_TYPE_FLOAT) {
1056 dst[i].i = src[i].f != 0.0f ? ctx->Const.UniformBooleanTrue : 0;
1057 } else {
1058 dst[i].i = src[i].i != 0 ? ctx->Const.UniformBooleanTrue : 0;
1059 }
1060 }
1061 }
1062
1063 _mesa_propagate_uniforms_to_driver_storage(uni, offset, count);
1064
1065 /* If the uniform is a sampler, do the extra magic necessary to propagate
1066 * the changes through.
1067 */
1068 if (uni->type->is_sampler()) {
1069 bool flushed = false;
1070
1071 shProg->SamplersValidated = GL_TRUE;
1072
1073 for (int i = 0; i < MESA_SHADER_STAGES; i++) {
1074 struct gl_linked_shader *const sh = shProg->_LinkedShaders[i];
1075
1076 /* If the shader stage doesn't use the sampler uniform, skip this. */
1077 if (!uni->opaque[i].active)
1078 continue;
1079
1080 bool changed = false;
1081 for (int j = 0; j < count; j++) {
1082 unsigned unit = uni->opaque[i].index + offset + j;
1083 if (sh->Program->SamplerUnits[unit] != ((unsigned *) values)[j]) {
1084 sh->Program->SamplerUnits[unit] = ((unsigned *) values)[j];
1085 changed = true;
1086 }
1087 }
1088
1089 if (changed) {
1090 if (!flushed) {
1091 FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT | _NEW_PROGRAM);
1092 flushed = true;
1093 }
1094
1095 struct gl_program *const prog = sh->Program;
1096 _mesa_update_shader_textures_used(shProg, prog);
1097 if (ctx->Driver.SamplerUniformChange)
1098 ctx->Driver.SamplerUniformChange(ctx, prog->Target, prog);
1099 }
1100 }
1101 }
1102
1103 /* If the uniform is an image, update the mapping from image
1104 * uniforms to image units present in the shader data structure.
1105 */
1106 if (uni->type->is_image()) {
1107 for (int i = 0; i < MESA_SHADER_STAGES; i++) {
1108 struct gl_linked_shader *sh = shProg->_LinkedShaders[i];
1109
1110 /* If the shader stage doesn't use the image uniform, skip this. */
1111 if (!uni->opaque[i].active)
1112 continue;
1113
1114 for (int j = 0; j < count; j++)
1115 sh->Program->sh.ImageUnits[uni->opaque[i].index + offset + j] =
1116 ((GLint *) values)[j];
1117 }
1118
1119 ctx->NewDriverState |= ctx->DriverFlags.NewImageUnits;
1120 }
1121 }
1122
1123 /**
1124 * Called by glUniformMatrix*() functions.
1125 * Note: cols=2, rows=4 ==> array[2] of vec4
1126 */
1127 extern "C" void
1128 _mesa_uniform_matrix(GLint location, GLsizei count,
1129 GLboolean transpose, const void *values,
1130 struct gl_context *ctx, struct gl_shader_program *shProg,
1131 GLuint cols, GLuint rows, enum glsl_base_type basicType)
1132 {
1133 unsigned offset;
1134 struct gl_uniform_storage *const uni =
1135 validate_uniform_parameters(location, count, &offset,
1136 ctx, shProg, "glUniformMatrix");
1137 if (uni == NULL)
1138 return;
1139
1140 if (!uni->type->is_matrix()) {
1141 _mesa_error(ctx, GL_INVALID_OPERATION,
1142 "glUniformMatrix(non-matrix uniform)");
1143 return;
1144 }
1145
1146 assert(basicType == GLSL_TYPE_FLOAT || basicType == GLSL_TYPE_DOUBLE);
1147 const unsigned size_mul = basicType == GLSL_TYPE_DOUBLE ? 2 : 1;
1148
1149 assert(!uni->type->is_sampler());
1150 const unsigned vectors = uni->type->matrix_columns;
1151 const unsigned components = uni->type->vector_elements;
1152
1153 /* Verify that the types are compatible. This is greatly simplified for
1154 * matrices because they can only have a float base type.
1155 */
1156 if (vectors != cols || components != rows) {
1157 _mesa_error(ctx, GL_INVALID_OPERATION,
1158 "glUniformMatrix(matrix size mismatch)");
1159 return;
1160 }
1161
1162 /* GL_INVALID_VALUE is generated if `transpose' is not GL_FALSE.
1163 * http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
1164 */
1165 if (transpose) {
1166 if (ctx->API == API_OPENGLES2 && ctx->Version < 30) {
1167 _mesa_error(ctx, GL_INVALID_VALUE,
1168 "glUniformMatrix(matrix transpose is not GL_FALSE)");
1169 return;
1170 }
1171 }
1172
1173 /* Section 2.11.7 (Uniform Variables) of the OpenGL 4.2 Core Profile spec
1174 * says:
1175 *
1176 * "If any of the following conditions occur, an INVALID_OPERATION
1177 * error is generated by the Uniform* commands, and no uniform values
1178 * are changed:
1179 *
1180 * ...
1181 *
1182 * - if the uniform declared in the shader is not of type boolean and
1183 * the type indicated in the name of the Uniform* command used does
1184 * not match the type of the uniform"
1185 *
1186 * There are no Boolean matrix types, so we do not need to allow
1187 * GLSL_TYPE_BOOL here (as _mesa_uniform does).
1188 */
1189 if (uni->type->base_type != basicType) {
1190 _mesa_error(ctx, GL_INVALID_OPERATION,
1191 "glUniformMatrix%ux%u(\"%s\"@%d is %s, not %s)",
1192 cols, rows, uni->name, location,
1193 glsl_type_name(uni->type->base_type),
1194 glsl_type_name(basicType));
1195 return;
1196 }
1197
1198 if (unlikely(ctx->_Shader->Flags & GLSL_UNIFORMS)) {
1199 log_uniform(values, uni->type->base_type, components, vectors, count,
1200 bool(transpose), shProg, location, uni);
1201 }
1202
1203 /* Page 82 (page 96 of the PDF) of the OpenGL 2.1 spec says:
1204 *
1205 * "When loading N elements starting at an arbitrary position k in a
1206 * uniform declared as an array, elements k through k + N - 1 in the
1207 * array will be replaced with the new values. Values for any array
1208 * element that exceeds the highest array element index used, as
1209 * reported by GetActiveUniform, will be ignored by the GL."
1210 *
1211 * Clamp 'count' to a valid value. Note that for non-arrays a count > 1
1212 * will have already generated an error.
1213 */
1214 if (uni->array_elements != 0) {
1215 count = MIN2(count, (int) (uni->array_elements - offset));
1216 }
1217
1218 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
1219
1220 /* Store the data in the "actual type" backing storage for the uniform.
1221 */
1222 const unsigned elements = components * vectors;
1223
1224 if (!transpose) {
1225 memcpy(&uni->storage[size_mul * elements * offset], values,
1226 sizeof(uni->storage[0]) * elements * count * size_mul);
1227 } else if (basicType == GLSL_TYPE_FLOAT) {
1228 /* Copy and transpose the matrix.
1229 */
1230 const float *src = (const float *)values;
1231 float *dst = &uni->storage[elements * offset].f;
1232
1233 for (int i = 0; i < count; i++) {
1234 for (unsigned r = 0; r < rows; r++) {
1235 for (unsigned c = 0; c < cols; c++) {
1236 dst[(c * components) + r] = src[c + (r * vectors)];
1237 }
1238 }
1239
1240 dst += elements;
1241 src += elements;
1242 }
1243 } else {
1244 assert(basicType == GLSL_TYPE_DOUBLE);
1245 const double *src = (const double *)values;
1246 double *dst = (double *)&uni->storage[elements * offset].f;
1247
1248 for (int i = 0; i < count; i++) {
1249 for (unsigned r = 0; r < rows; r++) {
1250 for (unsigned c = 0; c < cols; c++) {
1251 dst[(c * components) + r] = src[c + (r * vectors)];
1252 }
1253 }
1254
1255 dst += elements;
1256 src += elements;
1257 }
1258 }
1259
1260 _mesa_propagate_uniforms_to_driver_storage(uni, offset, count);
1261 }
1262
1263
1264 extern "C" bool
1265 _mesa_sampler_uniforms_are_valid(const struct gl_shader_program *shProg,
1266 char *errMsg, size_t errMsgLength)
1267 {
1268 /* Shader does not have samplers. */
1269 if (shProg->data->NumUniformStorage == 0)
1270 return true;
1271
1272 if (!shProg->SamplersValidated) {
1273 _mesa_snprintf(errMsg, errMsgLength,
1274 "active samplers with a different type "
1275 "refer to the same texture image unit");
1276 return false;
1277 }
1278 return true;
1279 }
1280
1281 extern "C" bool
1282 _mesa_sampler_uniforms_pipeline_are_valid(struct gl_pipeline_object *pipeline)
1283 {
1284 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
1285 * OpenGL 4.1 spec says:
1286 *
1287 * "[INVALID_OPERATION] is generated by any command that transfers
1288 * vertices to the GL if:
1289 *
1290 * ...
1291 *
1292 * - Any two active samplers in the current program object are of
1293 * different types, but refer to the same texture image unit.
1294 *
1295 * - The number of active samplers in the program exceeds the
1296 * maximum number of texture image units allowed."
1297 */
1298
1299 GLbitfield mask;
1300 GLbitfield TexturesUsed[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
1301 unsigned active_samplers = 0;
1302 const struct gl_program **prog =
1303 (const struct gl_program **) pipeline->CurrentProgram;
1304
1305
1306 memset(TexturesUsed, 0, sizeof(TexturesUsed));
1307
1308 for (unsigned idx = 0; idx < ARRAY_SIZE(pipeline->CurrentProgram); idx++) {
1309 if (!prog[idx])
1310 continue;
1311
1312 mask = prog[idx]->SamplersUsed;
1313 while (mask) {
1314 const int s = u_bit_scan(&mask);
1315 GLuint unit = prog[idx]->SamplerUnits[s];
1316 GLuint tgt = prog[idx]->sh.SamplerTargets[s];
1317
1318 /* FIXME: Samplers are initialized to 0 and Mesa doesn't do a
1319 * great job of eliminating unused uniforms currently so for now
1320 * don't throw an error if two sampler types both point to 0.
1321 */
1322 if (unit == 0)
1323 continue;
1324
1325 if (TexturesUsed[unit] & ~(1 << tgt)) {
1326 pipeline->InfoLog =
1327 ralloc_asprintf(pipeline,
1328 "Program %d: "
1329 "Texture unit %d is accessed with 2 different types",
1330 prog[idx]->Id, unit);
1331 return false;
1332 }
1333
1334 TexturesUsed[unit] |= (1 << tgt);
1335 }
1336
1337 active_samplers += prog[idx]->info.num_textures;
1338 }
1339
1340 if (active_samplers > MAX_COMBINED_TEXTURE_IMAGE_UNITS) {
1341 pipeline->InfoLog =
1342 ralloc_asprintf(pipeline,
1343 "the number of active samplers %d exceed the "
1344 "maximum %d",
1345 active_samplers, MAX_COMBINED_TEXTURE_IMAGE_UNITS);
1346 return false;
1347 }
1348
1349 return true;
1350 }