summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/uniforms.h
diff options
context:
space:
mode:
authorTapani Pälli <[email protected]>2014-03-06 11:00:17 +0200
committerTapani Pälli <[email protected]>2014-03-10 09:46:24 +0200
commit56b1be4399d76c0fe5ddf099a7ac5b45ab58e8cf (patch)
tree0ee265183905dec2e7c8d5679c5014e07f1bdb21 /src/mesa/main/uniforms.h
parentaa0d95a08dbf8f0e3ed66b624ccbc60753b61ef1 (diff)
mesa/glsl: introduce a remap table for uniform locations
Patch adds a remap table for uniforms that is used to provide a mapping from application specified uniform location to actual location in the UniformStorage. Existing UniformLocationBaseScale usage is removed as table can be used to set sequential values for array uniform elements. This mapping helps to implement GL_ARB_explicit_uniform_location so that uniforms locations can be reorganized and handled in a more easy manner. v2: small fixes + rename parameters for merge and split functions (Ian) improve documentation, remove old check for location bounds (Eric) Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/mesa/main/uniforms.h')
-rw-r--r--src/mesa/main/uniforms.h43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/mesa/main/uniforms.h b/src/mesa/main/uniforms.h
index bd50fd9b84d..4a5a1aa1513 100644
--- a/src/mesa/main/uniforms.h
+++ b/src/mesa/main/uniforms.h
@@ -340,39 +340,46 @@ struct gl_builtin_uniform_desc {
* element. We could insert dummy entries in the list for each array
* element after [0] but that causes complications elsewhere.
*
- * We solve this problem by encoding two values in the location that's
- * returned by glGetUniformLocation():
- * a) index into gl_uniform_list::Uniforms[] for the uniform
- * b) an array/field offset (0 for simple types)
+ * We solve this problem by creating multiple entries for uniform arrays
+ * in the UniformRemapTable so that their elements get sequential locations.
+ *
+ * Utility functions below offer functionality to split UniformRemapTable
+ * location in to location of the uniform in UniformStorage + offset to the
+ * array element (0 if not an array) and also merge it back again as the
+ * UniformRemapTable location.
*
- * These two values are encoded in the high and low halves of a GLint.
- * By putting the uniform number in the high part and the offset in the
- * low part, we can support the unofficial ability to index into arrays
- * by adding offsets to the location value.
*/
/*@{*/
/**
- * Combine the uniform's base location and the offset
+ * Combine the uniform's storage index and the array index
*/
static inline GLint
_mesa_uniform_merge_location_offset(const struct gl_shader_program *prog,
- unsigned base_location, unsigned offset)
+ unsigned storage_index,
+ unsigned uniform_array_index)
{
- assert(prog->UniformLocationBaseScale >= 1);
- assert(offset < prog->UniformLocationBaseScale);
- return (base_location * prog->UniformLocationBaseScale) + offset;
+ /* location in remap table + array element offset */
+ return prog->UniformStorage[storage_index].remap_location +
+ uniform_array_index;
}
/**
- * Separate the uniform base location and parameter offset
+ * Separate the uniform storage index and array index
*/
static inline void
_mesa_uniform_split_location_offset(const struct gl_shader_program *prog,
- GLint location, unsigned *base_location,
- unsigned *offset)
+ GLint location, unsigned *storage_index,
+ unsigned *uniform_array_index)
{
- *offset = location % prog->UniformLocationBaseScale;
- *base_location = location / prog->UniformLocationBaseScale;
+ *storage_index = prog->UniformRemapTable[location] - prog->UniformStorage;
+ *uniform_array_index = location -
+ prog->UniformRemapTable[location]->remap_location;
+
+ /*gl_uniform_storage in UniformStorage with the calculated base_location
+ * must match with the entry in remap table
+ */
+ assert(&prog->UniformStorage[*storage_index] ==
+ prog->UniformRemapTable[location]);
}
/*@}*/