<div dir="ltr"><div><div>On second thought, the glsl_type::uniform_locations() method comment in the header file says:<br>/**<br> * Calculate the number of unique values from glGetUniformLocation for the<br> * elements of the type.<br>
 */<br><br></div>Which makes me believe that maybe we should return at least 1 for every case because this is only called for explicit locations and therefore will not make shaders failing to link unless they've explicitely used more locations than they should.<br>
</div>Maybe glsl_type::uniform_locations() should be renamed to something that makes it clear it's only used for explicit locations too, or make it clear that it reflects the size for the API, not GPU memory (since it's only used to fill prog->UniformRemapTable).<br>
<div><div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Aug 23, 2014 at 2:07 PM, Micael <span dir="ltr"><<a href="mailto:kam1kaz3@gmail.com" target="_blank">kam1kaz3@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="">On Fri, Aug 22, 2014 at 9:23 PM, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'm not sure this is correct, and I think we need a more complex fix.<br>
As Dave points out, bindless will make it even more complex.<br>
<br>
In a non-bindless, static-sampler-array-indexing world, applications<br>
assume that samplers will use zero uniform locations.  The sampler<br>
information is baked into the instructions, and it isn't represented<br>
anywhere else in GPU memory.  As a result, I would not be surprised to<br>
see previously working applications fail to link (due to using too many<br>
uniforms) with this change.<br>
<br>
It seems that the only time a sampler needs non-zero space is when it is<br>
part of any array samplers (or array of structures containing samplers,<br>
etc.) or is bindless.  In the array cases, it is probably only necessary<br>
when the index is dynamic.  I think the array splitting and structure<br>
splitting passes may make that moot.<br></blockquote><div><br></div></div><div>Did you miss the case of assigning an explicit location to a sampler, or did you ommit on purpose?<br></div><div>I'm not very familiar with mesa source, but as far as I could analyze it, only reserve_explicit_locations() and validate_explicit_location() call glsl_type::uniform_locations(), everything else uses glsl_type::component_slots().<br>

</div><div>Now I agree with you that simply returning 1 from glsl_type::uniform_locations() for samplers can be misleading.<br></div><div><br></div><div>How about if glsl_type::uniform_locations() takes a "bool isExplicitLocation" and return at least 1 for every type? I am aware that this won't solve the bindless textures issue, but it would fix this bug (and the integer underflows) for now, I think.<br>

</div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
The 82921 bug seems to be an orthognal issue.  There is a difference<br>
between the API visible locations assigned to a uniform and the GPU<br>
visible locations where the uniform is stored.  My guess is that we're<br>
using the same accounting for both in places where we should not.<br>
<div><div><br>
On 08/21/2014 04:25 PM, Micael Dias wrote:<br>
> ---<br>
> If samplers occupy zero locations we can run into a lot of issues. See #82921.<br>
> I briefly tested this with my own code (which was previously crashing and<br>
> misbehaving) and also ran other apps and everything seems to work fine.<br>
> I'm not used to contributing code in this fashion, so please forgive me if I'm<br>
> making some mistake. Thanks.<br>
><br>
>  src/glsl/glsl_types.cpp | 2 ++<br>
>  1 file changed, 2 insertions(+)<br>
><br>
> diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp<br>
> index 66e9b13..cc05193 100644<br>
> --- a/src/glsl/glsl_types.cpp<br>
> +++ b/src/glsl/glsl_types.cpp<br>
> @@ -691,6 +691,8 @@ glsl_type::uniform_locations() const<br>
>        return size;<br>
>     case GLSL_TYPE_ARRAY:<br>
>        return this->length * this->fields.array->uniform_locations();<br>
> +   case GLSL_TYPE_SAMPLER:<br>
> +      return 1;<br>
>     default:<br>
>        break;<br>
>     }<br>
><br>
<br>
</div></div></blockquote></div></div></div><span class=""><font color="#888888"><br><br clear="all"><br>-- <br>Micael Dias
</font></span></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>Micael Dias
</div></div></div></div></div></div>