<div dir="ltr">On 12 December 2013 08:32, Francisco Jerez <span dir="ltr"><<a href="mailto:currojerez@riseup.net" target="_blank">currojerez@riseup.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>> writes:<br>
<br>
> On 26 November 2013 00:02, Francisco Jerez <<a href="mailto:currojerez@riseup.net">currojerez@riseup.net</a>> wrote:<br>
><br>
>> ---<br>
>> src/glsl/link_uniforms.cpp | 13 +++++++++++-<br>
>> src/glsl/linker.cpp | 50<br>
>> ++++++++++++++++++++++++++++++++++++++++++++++<br>
>> 2 files changed, 62 insertions(+), 1 deletion(-)<br>
>><br>
>> diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp<br>
>> index 0a15739..c75a38c 100644<br>
>> --- a/src/glsl/link_uniforms.cpp<br>
>> +++ b/src/glsl/link_uniforms.cpp<br>
>> @@ -240,7 +240,8 @@ class count_uniform_size : public<br>
>> program_resource_visitor {<br>
>> public:<br>
>> count_uniform_size(struct string_to_uint_map *map)<br>
>> : num_active_uniforms(0), num_values(0), num_shader_samplers(0),<br>
>> - num_shader_uniform_components(0), is_ubo_var(false), map(map)<br>
>> + num_shader_images(0), num_shader_uniform_components(0),<br>
>> + is_ubo_var(false), map(map)<br>
>> {<br>
>> /* empty */<br>
>> }<br>
>> @@ -248,6 +249,7 @@ public:<br>
>> void start_shader()<br>
>> {<br>
>> this->num_shader_samplers = 0;<br>
>> + this->num_shader_images = 0;<br>
>> this->num_shader_uniform_components = 0;<br>
>> }<br>
>><br>
>> @@ -277,6 +279,11 @@ public:<br>
>> unsigned num_shader_samplers;<br>
>><br>
>> /**<br>
>> + * Number of images used<br>
>> + */<br>
>> + unsigned num_shader_images;<br>
>> +<br>
>> + /**<br>
>> * Number of uniforms used in the current shader<br>
>> */<br>
>> unsigned num_shader_uniform_components;<br>
>> @@ -303,6 +310,9 @@ private:<br>
>> if (type->contains_sampler()) {<br>
>> this->num_shader_samplers +=<br>
>> type->is_array() ? type->array_size() : 1;<br>
>> + } else if (type->contains_image()) {<br>
>> + this->num_shader_images += values;<br>
>> + this->num_shader_uniform_components += values;<br>
>><br>
><br>
> How come images contribute to num_shader_uniform_components but samplers<br>
> don't? There should be a comment explaining this difference.<br>
><br>
><br>
>> } else {<br>
>> /* Accumulate the total number of uniform slots used by this<br>
>> shader.<br>
>> * Note that samplers do not count against this limit because they<br>
>> @@ -782,6 +792,7 @@ link_assign_uniform_locations(struct gl_shader_program<br>
>> *prog)<br>
>> }<br>
>><br>
>> sh->num_samplers = uniform_size.num_shader_samplers;<br>
>> + sh->NumImages = uniform_size.num_shader_images;<br>
>> sh->num_uniform_components =<br>
>> uniform_size.num_shader_uniform_components;<br>
>><br>
>> sh->num_combined_uniform_components = sh->num_uniform_components;<br>
>> diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp<br>
>> index fac186a..86a0cae 100644<br>
>> --- a/src/glsl/linker.cpp<br>
>> +++ b/src/glsl/linker.cpp<br>
>> @@ -1980,6 +1980,55 @@ check_resources(struct gl_context *ctx, struct<br>
>> gl_shader_program *prog)<br>
>> }<br>
>> }<br>
>><br>
>> +/**<br>
>> + * Validate shader image resources.<br>
>> + */<br>
>> +static void<br>
>> +check_image_resources(struct gl_context *ctx, struct gl_shader_program<br>
>> *prog)<br>
>> +{<br>
>> + STATIC_ASSERT(MESA_SHADER_TYPES == 3);<br>
>> + static const char *const shader_names[MESA_SHADER_TYPES] = {<br>
>> + "vertex", "geometry", "fragment"<br>
>> + };<br>
>><br>
><br>
> Use _mesa_glsl_shader_target_name() instead of hardcoding this array.<br>
><br>
<br>
</div></div>Neither of the _mesa_glsl_shader_target_name() overloads accept a<br>
gl_shader_type as argument, the first one takes a GLenum, the second one<br>
takes a _mesa_glsl_parser_targets enumerant -- Yes, the enum values<br>
happen to match Mesa's gl_shader_type, but...<br></blockquote><div><br></div><div>Argh, that's frustrating. There's no good reason to have two enums. I'll send out a patch series that consolidates them into one.<br>
</div><br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
><br>
>> + const unsigned max_images[MESA_SHADER_TYPES] = {<br>
>> + ctx->Const.VertexProgram.MaxImageUniforms,<br>
>> + ctx->Const.GeometryProgram.MaxImageUniforms,<br>
>> + ctx->Const.FragmentProgram.MaxImageUniforms<br>
>> + };<br>
>><br>
><br>
> Rather than doing STATIC_ASSERT(MESA_SHADER_TYPES == 3), I think this would<br>
> be slightly cleaner, since it will be more obvious what needs fixing if the<br>
> assertion ever fires:<br>
><br>
> const unsigned max_images[] = {<br>
> ctx->Const.VertexProgram.MaxImageUniforms,<br>
> ctx->Const.GeometryProgram.MaxImageUniforms,<br>
> ctx->Const.FragmentProgram.MaxImageUniforms<br>
> };<br>
> STATIC_ASSERT(Elements(max_images) == MESA_SHADER_TYPES);<br>
><br>
><br>
> With those changes, the patch is:<br>
><br>
> Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div></div></blockquote></div><br></div></div>