[Mesa-dev] [PATCH] glsl: Fail linkage when UBO exceeds GL_MAX_UNIFORM_BLOCK_SIZE.

Roland Scheidegger sroland at vmware.com
Tue Jun 16 07:22:54 PDT 2015


This looks like a good idea to me.
That said, llvmpipe would still crash if the declared size in the shader
wouldn't exceed the max uniform block size, but the bound buffer does
IIRC (the test doesn't test this but could be easily modified to do so).
So, I'm wondering if we should do both - fail to link if the declared
size exceeds the limit, and just limit the size we copy in llvmpipe to
the limit, though it's possible this would require some more changes to
be really safe so we don't try to access such elements (with indirect
access, though we don't verify direct ones at all) in the shader.

Reviewed-by: Roland Scheidegger <sroland at vmware.com>


Am 16.06.2015 um 12:29 schrieb Jose Fonseca:
> It's not totally clear whether other Mesa drivers can safely cope with
> over-sized UBOs, but at least for llvmpipe receiving a UBO larger than
> its limit causes problems, as it won't fit into its internal display
> lists.
> 
> This fixes piglit "arb_uniform_buffer_object-maxuniformblocksize
> fsexceed" without regressions for llvmpipe.
> 
> NVIDIA driver also fails to link the shader from
> "arb_uniform_buffer_object-maxuniformblocksize fsexceed".
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=65525
> 
> PS: I don't recommend cherry-picking this for Mesa stable, as some app
> might inadvertently been relying on UBOs larger than
> GL_MAX_UNIFORM_BLOCK_SIZE to work on other drivers, so even if this
> commit is universally accepted it's probably best to let it mature in
> master for a while.
> ---
>  src/glsl/linker.cpp | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
> index 9978380..4a726d4 100644
> --- a/src/glsl/linker.cpp
> +++ b/src/glsl/linker.cpp
> @@ -2355,6 +2355,13 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
>     unsigned total_uniform_blocks = 0;
>  
>     for (unsigned i = 0; i < prog->NumUniformBlocks; i++) {
> +      if (prog->UniformBlocks[i].UniformBufferSize > ctx->Const.MaxUniformBlockSize) {
> +         linker_error(prog, "Uniform block %s too big (%d/%d)\n",
> +                      prog->UniformBlocks[i].Name,
> +                      prog->UniformBlocks[i].UniformBufferSize,
> +                      ctx->Const.MaxUniformBlockSize);
> +      }
> +
>        for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) {
>  	 if (prog->UniformBlockStageIndex[j][i] != -1) {
>  	    blocks[j]++;
> 



More information about the mesa-dev mailing list