<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 11, 2014 at 10:37 AM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On 03/10/2014 04:15 PM, Anuj Phogat wrote:<br>
><br>
><br>
><br>
> On Mon, Mar 10, 2014 at 3:27 PM, Ian Romanick <<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a><br>
</div><div><div>> <mailto:<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>>> wrote:<br>
><br>
> On 03/10/2014 11:19 AM, Anuj Phogat wrote:<br>
> > Currently overlapping locations of input variables are not allowed<br>
> for all<br>
> > the shader types in OpenGL and OpenGL ES.<br>
> ><br>
> >>From OpenGL ES 3.0 spec, page 56:<br>
> > "Binding more than one attribute name to the same location is<br>
> referred<br>
> > to as aliasing, and is not permitted in OpenGL ES Shading Language<br>
> > 3.00 vertex shaders. LinkProgram will fail when this condition<br>
> exists.<br>
> > However, aliasing is possible in OpenGL ES Shading Language<br>
> 1.00 vertex<br>
> > shaders."<br>
> ><br>
> > Taking in to account what different versions of OpenGL and OpenGL<br>
> ES specs<br>
> > say about aliasing:<br>
> > - It is allowed only on vertex shader input attributes in<br>
> OpenGL (2.0 and<br>
> > above) and OpenGL ES 2.0.<br>
> > - It is explictly disallowed in OpenGL ES 3.0.<br>
> ><br>
> > Fixes Khronos CTS failing test:<br>
> > explicit_attrib_location_vertex_input_aliased.test<br>
> > See more details about this at below mentioned khronos bug.<br>
> ><br>
> > Signed-off-by: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com" target="_blank">anuj.phogat@gmail.com</a><br>
</div></div>> <mailto:<a href="mailto:anuj.phogat@gmail.com" target="_blank">anuj.phogat@gmail.com</a>>><br>
<div>> > Cc: "9.2 10.0 10.1" <<a href="mailto:mesa-stable@lists.freedesktop.org" target="_blank">mesa-stable@lists.freedesktop.org</a><br>
</div>> <mailto:<a href="mailto:mesa-stable@lists.freedesktop.org" target="_blank">mesa-stable@lists.freedesktop.org</a>>><br>
<div><div>> > Bugzilla: Khronos #9609<br>
> > ---<br>
> > src/glsl/linker.cpp | 74<br>
> +++++++++++++++++++++++++++++++++++++++++++----------<br>
> > 1 file changed, 61 insertions(+), 13 deletions(-)<br>
> ><br>
> > diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp<br>
> > index a619bc8..9bd698b 100644<br>
> > --- a/src/glsl/linker.cpp<br>
> > +++ b/src/glsl/linker.cpp<br>
> > @@ -1798,10 +1798,12 @@<br>
> assign_attribute_or_color_locations(gl_shader_program *prog,<br>
> > * active attribute array, both of which require<br>
> multiple<br>
> > * contiguous generic attributes."<br>
> > *<br>
> > - * Previous versions of the spec contain similar<br>
> language but omit<br>
> > - * the bit about attribute arrays.<br>
> > + * I think above text prohibits the aliasing of explicit and<br>
> > + * automatic assignments. But, aliasing is allowed in manual<br>
> > + * assignments of attribute locations. See below<br>
> comments for<br>
> > + * the details.<br>
><br>
> The text above (outside the diff) forbids things like:<br>
><br>
> layout(location=0) in mat4 m;<br>
> layout(location=1) in vec4 v;<br>
><br>
> where v and m now partially overlap because m consumes 4 slots (0<br>
> through 3, inclusive).<br>
><br>
><br>
> This should not be a problem as along as there's only one active attribute<br>
> in vertex shader. If a developer uses such locations, its his<br>
> responsibility<br>
> to use just one of them in any path in shader program. Khronos CTS test<br>
> also expects linking to happen in above case.<br>
><br>
> OpenGL 4.0 spec makes similar looking statements at two different places.<br>
> First for vertex shader input locations at page 60:<br>
><br>
> "LinkProgram will fail if the attribute bindings assigned by BindAttri-<br>
> bLocation do not leave not enough space to assign a location for an<br>
> active matrix<br>
> attribute or an active attribute array, both of which require multiple<br>
> contiguous<br>
> generic attributes."<br>
<br>
</div></div>Somewhere in the intervening specs, the language was changed. In 4.4 it<br>
says:<br>
<br>
"LinkProgram will fail if the attribute bindings specified either<br>
by BindAttribLocation or explicitly set within the shader text do<br>
<div> not leave not enough space to assign a location for an active<br>
matrix attribute or an active attribute array, both of which<br>
require multiple contiguous generic attributes."<br>
<br>
> This statement sounds little unclear to me. It doesn't say what happens if<br>
> locations set in shader text don't leave enough space. It also doesn't make<br>
> clear who assigns the location in "to assign a location for an active<br>
> matrix".<br>
> explicit or automatic assignment?<br>
<br>
</div>You may be right. We'll have to prod other implementations. I'll also<br>
do some spec archaeology.<br></blockquote><div>Piglit tests I posted on mailing list passes on NVIDIA's OpenGL 4.3 linux</div><div>driver. NVIDIA allows the kind of overlapping you described above.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br>
> Second for fragment output locations at page 233:<br>
> "if the explicit binding assigments do not leave enough space for the linker<br>
> to automatically assign a location for a varying out array, which requires<br>
> multiple contiguous locations."<br>
><br>
> This statement makes the condition more clear for linking error. Notice<br>
> the words<br>
> 'explicit' and 'automatically' in text from page 233.<br>
><br>
> So I interpreted the two statements as:<br>
> Aliasing of explicit and automatic assignments is prohibited.<br>
> But, aliasing is allowed in explicit assignments of attribute locations.<br>
><br>
> Do you interpret them differently ?<br>
><br>
><br>
> Does this patch affect this?<br>
><br>
> Yes. It allows linking in such cases.<br>
><br>
><br>
> > *<br>
> > - * Page 61 of the OpenGL 4.0 spec also says:<br>
> > + * From OpenGL 4.0 spec, page 61:<br>
> > *<br>
> > * "It is possible for an application to bind more<br>
> than one<br>
> > * attribute name to the same location. This is<br>
> referred to as<br>
> > @@ -1814,12 +1816,48 @@<br>
> assign_attribute_or_color_locations(gl_shader_program *prog,<br>
> > * but implementations are not required to generate<br>
> an error<br>
> > * in this case."<br>
> > *<br>
> > - * These two paragraphs are either somewhat<br>
> contradictory, or I<br>
> > - * don't fully understand one or both of them.<br>
> > - */<br>
> > - /* FINISHME: The code as currently written does not support<br>
> > - * FINISHME: attribute location aliasing (see comment<br>
> above).<br>
> > + * From GLSL 4.30 spec, page 54:<br>
> > + *<br>
> > + * "A program will fail to link if any two non-vertex<br>
> shader<br>
> > + * input variables are assigned to the same<br>
> location. For<br>
> > + * vertex shaders, multiple input variables may be<br>
> assigned<br>
> > + * to the same location using either layout<br>
> qualifiers or via<br>
> > + * the OpenGL API. However, such aliasing is<br>
> intended only to<br>
> > + * support vertex shaders where each execution path<br>
> accesses<br>
> > + * at most one input per each location.<br>
> Implementations are<br>
> > + * permitted, but not required, to generate<br>
> link-time errors<br>
> > + * if they detect that every path through the vertex<br>
> shader<br>
> > + * executable accesses multiple inputs assigned to<br>
> any single<br>
> > + * location. For all shader types, a program will<br>
> fail to link<br>
> > + * if explicit location assignments leave the linker<br>
> unable<br>
> > + * to find space for other variables without explicit<br>
> > + * assignments."<br>
> > + *<br>
> > + * From OpenGL ES 3.0 spec, page 56:<br>
> > + *<br>
> > + * "Binding more than one attribute name to the same<br>
> location<br>
> > + * is referred to as aliasing, and is not permitted<br>
> in OpenGL<br>
> > + * ES Shading Language 3.00 vertex shaders.<br>
> LinkProgram will<br>
> > + * fail when this condition exists. However, aliasing is<br>
> > + * possible in OpenGL ES Shading Language 1.00<br>
> vertex shaders.<br>
> > + * This will only work if only one of the aliased<br>
> attributes<br>
> > + * is active in the executable program, or if no<br>
> path through<br>
> > + * the shader consumes more than one attribute of a<br>
> set of<br>
> > + * attributes aliased to the same location. A link<br>
> error can<br>
> > + * occur if the linker determines that every path<br>
> through the<br>
> > + * shader consumes multiple aliased attributes, but<br>
> implemen-<br>
> > + * tations are not required to generate an error in<br>
> this case."<br>
> > + *<br>
> > + * After looking at above references from OpenGL,<br>
> OpenGL ES<br>
> > + * and GLSL specifications, we allow aliasing of<br>
> vertex input<br>
> > + * variables in: OpenGL 2.0 (and above) and OpenGL<br>
> ES 2.0.<br>
> > + *<br>
> > + * NOTE: This is not required by the spec but its worth<br>
> > + * mentioning here that we're not doing anything to<br>
> make sure<br>
> > + * that no path through the vertex shader executable<br>
> accesses<br>
> > + * multiple inputs assigned to any single location.<br>
><br>
> These last two paragraphis should be un-indented.<br>
><br>
> > */<br>
> > +<br>
> > /* Mask representing the contiguous slots that will be<br>
> used by<br>
> > * this attribute.<br>
> > */<br>
> > @@ -1832,11 +1870,21 @@<br>
> assign_attribute_or_color_locations(gl_shader_program *prog,<br>
> > if ((~(use_mask << attr) & used_locations) !=<br>
> used_locations) {<br>
> > const char *const string = (target_index ==<br>
> MESA_SHADER_VERTEX)<br>
> > ? "vertex shader input" : "fragment shader output";<br>
> > - linker_error(prog,<br>
> > - "insufficient contiguous locations "<br>
> > - "available for %s `%s' %d %d %d", string,<br>
> > - var->name, used_locations, use_mask, attr);<br>
> > - return false;<br>
> > +<br>
> > + if (target_index == MESA_SHADER_FRAGMENT ||<br>
> > + (prog->IsES && prog->Version >= 300)) {<br>
> > +<br>
> > + linker_error(prog,<br>
> > + "overlapping location is assigned "<br>
> > + "to %s `%s' %d %d %d\n", string,<br>
> > + var->name, used_locations,<br>
> use_mask, attr);<br>
> > + return false;<br>
> > + } else {<br>
> > + linker_warning(prog,<br>
> > + "overlapping location is assigned "<br>
> > + "to %s `%s' %d %d %d\n", string,<br>
> > + var->name, used_locations,<br>
> use_mask, attr);<br>
> > + }<br>
> > }<br>
> ><br>
> > used_locations |= (use_mask << attr);<br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>