Branch
Hash :
44861c48
Author :
Date :
2018-03-23T14:36:39
Clarify aliasing rules in CHROMIUM_bind_uniform_location The CHROMIUM_bind_uniform_location spec previously had some conflicting information on when uniform location aliasing was allowed. Now the section on uniform location aliasing makes it clear that aliasing locations of two statically used uniforms is an error. This guarantees compatibility between different compiler versions that may treat a different subset of uniforms as active, depending on optimizations. It follows the spirit of GLSL ES 3.00.6 spec section 12.46, that has similar rules for attributes. The implementation is fixed to correctly follow the spec. When flattening uniforms, static use is tracked separately from activeness. BUG=angleproject:2262 TEST=angle_end2end_tests Change-Id: I570fd384064aec66ef0380a53fa01ac5e43eec5a Reviewed-on: https://chromium-review.googlesource.com/978144 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
Name
CHROMIUM_bind_uniform_location
Name Strings
GL_CHROMIUM_bind_uniform_location
Version
Last Modifed Date: September 8, 2015
Dependencies
OpenGL ES 2.0 is required.
Overview
This extension is simlar to glBindAttribLocation but instead
lets you choose a location for a uniform. This allows you
to not have to query the locations of uniforms.
This allows the client program to know the locations of uniforms
without having to wait for shaders to compile or GLSL programs to
link to query the locations and therefore have no blocking calls
when initializing programs.
Issues
If a uniform is an array you can only call glBindUniformLocation
for the location of the first element. Other elements' locations
must be queried if you need them. Often this is not an issue
because you can set all the elements with a single gl call from
the first location.
Good Example:
--shader--
uniform float u_someArray[4];
--C--
GLint location = 123;
glBindUniformLocation(program, location, "u_someArray");
glLinkProgram(program);
glUseProgram(program);
// set all 4 floats in u_someArray
float values[] = { 0.1f, 0.2f, 0.3f, 0.4f, };
glUniform1fv(location, 4, values);
Bad example 1:
GLint location = 123;
glBindUniformLocation(program, location, "u_someArray");
glLinkProgram(program);
glUseProgram(program);
// set floats in u_someArray one at a time
glUniform1f(location, 0.1f);
glUniform1f(location + 1, 0.2f); // ERROR! math not allowed on locations
Bad example 2:
GLint location0 = 123;
GLint location1 = 124;
glBindUniformLocation(program, location0, "u_someArray[0]");
glBindUniformLocation(program, location1, "u_someArray[1]"); // ERROR!
// not allowed to assign locations to array elements
If you need to set individual elements of a uniform array you must query the
location of the each element you wish to set.
If a uniform has its location explicitly set within the shader text and a
different location set via the API, the assignment in the shader text is
used.
If the location of a statically used uniform set via the API conflicts with
the location of a different uniform set in the shader text, linking must
fail.
New Tokens
None
New Procedures and Functions
void BindUniformLocationCHROMIUM (GLuint program, GLint location,
const GLhchar* name);
specifes that the uniform variable named <name> in program <program>
should be bound to uniform location <location> when the program is next
linked. If <name> was bound previously, its assigned binding is replaced
with <location>. <name> must be a null terminated string. The error
INVALID_VALUE is generated if <location> is equal or greater than
(MAX_VERTEX_UNIFORM_VECTORS + MAX_FRAGMENT_UNIFORM_VECTORS) * 4
or less than 0. BindUniformLocation has no effect until the program is
linked. In particular, it doesn't modify the bindings of uniform
variables in a program that has already been linked.
The error INVALID_OPERATION is generated if name starts with the reserved
"gl_" prefix. The error INVALID_VALUE is generated if name ends with
an array element expression other than "[0]".
When a program is linked, any active uniforms without a binding specified
through BindUniformLocation will be automatically be bound to locations by
the GL. Such bindings can be queried using the command
GetUniformLocation.
BindUniformLocation may be issued before any shader objects are attached
to a program object. Hence it is allowed to bind any name (except a name
starting with "gl_") to an index, including a name that is never used as a
uniform in any shader object. Assigned bindings for uniform variables
that do not exist or are not active are ignored. Using such bindings
behaves as if passed location was -1.
It is possible for an application to bind more than one uniform name to
the same location. This is referred to as aliasing. This will only work
if only one of the aliased uniforms is statically used in the executable
program. If two statically used uniforms in a program are bound to the same
location, link must fail.
Errors
None.
New State
None.
Revision History
7/20/2012 Documented the extension
9/8/2015 Require program link to fail if two statically used uniforms
are bound to the same location.
11/6/2015 Require inactive and non-existing, bound uniform locations
to behave like location -1.
3/9/2017 Locations set in the shader override ones set by the binding
API.
3/26/2018 Clarify that aliasing rules apply to statically used uniforms.