[Piglit] [PATCH] Respect GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT in binding-layout.c.

Ian Romanick idr at freedesktop.org
Tue Jun 13 17:54:55 UTC 2017


This patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

On 06/04/2017 06:30 PM, Kenneth Graunke wrote:
> The spec/arb_shading_language_420pack/execution/binding-layout test
> assumed that it could bind buffers at 16-byte offsets.  This may not
> be true - we need to respect GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT.
> 
> This prevents crashes on drivers which require an alignment larger than
> 16 bytes.  The closed source AMD and NVIDIA drivers appear to require
> an alignment of 256 bytes, and I have a patch to bump i965 to 32 bytes.
> ---
>  .../execution/binding-layout.c                           | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/spec/arb_shading_language_420pack/execution/binding-layout.c b/tests/spec/arb_shading_language_420pack/execution/binding-layout.c
> index bda43dd0d..acbb8f4dd 100644
> --- a/tests/spec/arb_shading_language_420pack/execution/binding-layout.c
> +++ b/tests/spec/arb_shading_language_420pack/execution/binding-layout.c
> @@ -152,6 +152,7 @@ piglit_init(int argc, char **argv)
>  	};
>  	bool pass = true;
>  	GLuint bo;
> +	GLint alignment;
>  
>  	piglit_require_extension("GL_ARB_shading_language_420pack");
>  	piglit_require_extension("GL_ARB_explicit_attrib_location");
> @@ -167,14 +168,21 @@ piglit_init(int argc, char **argv)
>  	if (!pass)
>  		piglit_report_result(PIGLIT_FAIL);
>  
> +	/* Pad out to the alignment or the size of a vec4. */
> +	glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment);
> +	alignment = MAX2(alignment, 4 * sizeof(float));
> +
>  	glGenBuffers(1, &bo);
>  	glBindBuffer(GL_UNIFORM_BUFFER, bo);
> -	glBufferData(GL_UNIFORM_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
> +	glBufferData(GL_UNIFORM_BUFFER, 3 * alignment, NULL, GL_STATIC_DRAW);
> +	glBufferSubData(GL_UNIFORM_BUFFER, 0 * alignment, 16, &data[0]);
> +	glBufferSubData(GL_UNIFORM_BUFFER, 1 * alignment, 16, &data[4]);
> +	glBufferSubData(GL_UNIFORM_BUFFER, 2 * alignment, 16, &data[8]);
>  	glBindBuffer(GL_UNIFORM_BUFFER, 0);
>  
> -	glBindBufferRange(GL_UNIFORM_BUFFER, 2, bo,  0, 16);
> -	glBindBufferRange(GL_UNIFORM_BUFFER, 3, bo, 16, 16);
> -	glBindBufferRange(GL_UNIFORM_BUFFER, 4, bo, 32, 16);
> +	glBindBufferRange(GL_UNIFORM_BUFFER, 2, bo, 0 * alignment, 16);
> +	glBindBufferRange(GL_UNIFORM_BUFFER, 3, bo, 1 * alignment, 16);
> +	glBindBufferRange(GL_UNIFORM_BUFFER, 4, bo, 2 * alignment, 16);
>  
>  	glClearColor(0.5, 0.5, 0.5, 1.0);
>  }
> 



More information about the Piglit mailing list