summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/uniform_query.cpp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2014-10-20 16:40:50 -0700
committerIan Romanick <ian.d.romanick@intel.com>2014-11-10 04:25:40 -0800
commit91a2fa1490b86b11430db6a604dc28bac1871695 (patch)
tree03608f7b7928cdde3aaa695e8ae65091ab5133ca /src/mesa/main/uniform_query.cpp
parent366540e9af86edc7451beb39204efbb4fe593973 (diff)
downloadexternal_mesa3d-91a2fa1490b86b11430db6a604dc28bac1871695.zip
external_mesa3d-91a2fa1490b86b11430db6a604dc28bac1871695.tar.gz
external_mesa3d-91a2fa1490b86b11430db6a604dc28bac1871695.tar.bz2
mesa: Rework array error checks in validate_uniform_parameters
Before ARB_explicit_uniform_location, Mesa's location encoding allowed locations for non-array types that had non-zero array indices. Basically, part of the location was the uniform and part was the array index. This meant that some checks had to occur for arrays and non-arrays. This is no longer possible, we the checks can be split up. Valgrind callgrind results for a trace of Tesseract: _mesa_Uniform4fv _mesa_Uniform4f _mesa_Uniform1i Before (64-bit): 50,499,557 17,487,316 686,227 After (64-bit): 50,023,791 17,274,432 684,293 _mesa_Uniform4fv _mesa_Uniform4f _mesa_Uniform1i Before (32-bit): 62,968,039 21,732,380 828,147 After (32-bit): 62,373,967 21,490,756 826,223 Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Diffstat (limited to 'src/mesa/main/uniform_query.cpp')
-rw-r--r--src/mesa/main/uniform_query.cpp41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index 16e08d4..b87dbdf 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -252,27 +252,30 @@ validate_uniform_parameters(struct gl_context *ctx,
struct gl_uniform_storage *const uni = shProg->UniformRemapTable[location];
- if (uni->array_elements == 0 && count > 1) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(count > 1 for non-array, location=%d)",
- caller, location);
- return NULL;
- }
+ if (uni->array_elements == 0) {
+ if (count > 1) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(count > 1 for non-array, location=%d)",
+ caller, location);
+ return NULL;
+ }
- /* The array index specified by the uniform location is just the uniform
- * location minus the base location of of the uniform.
- */
- *array_index = location - uni->remap_location;
+ assert((location - uni->remap_location) == 0);
+ *array_index = 0;
+ } else {
+ /* The array index specified by the uniform location is just the uniform
+ * location minus the base location of of the uniform.
+ */
+ *array_index = location - uni->remap_location;
- /* If the uniform is an array, check that array_index is in bounds.
- * If not an array, check that array_index is zero.
- * array_index is unsigned so no need to check for less than zero.
- */
- const unsigned limit = MAX2(uni->array_elements, 1);
- if (*array_index >= limit) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)",
- caller, location);
- return NULL;
+ /* If the uniform is an array, check that array_index is in bounds.
+ * array_index is unsigned so no need to check for less than zero.
+ */
+ if (*array_index >= uni->array_elements) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)",
+ caller, location);
+ return NULL;
+ }
}
return uni;
}