[Piglit] [PATCH] arb_uniform_buffer_object: Add UBO from vs-struct-pad tests

Ian Romanick idr at freedesktop.org
Fri Aug 16 22:03:05 PDT 2013


On 08/16/2013 01:38 PM, Ian Romanick wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> The vs-struct-pad and fs-struct-pad tests both fail on Mesa.  The UBOs
> from those tests are added here to help narrow down the origin of the
> problem.
>
> This test passes on NVIDIA (304.64 on GTX 260).
>
> v2: Correct version of the patch to send to the list.

After more review of the spec (and testing on AMD drivers), I believe 
the first version (with offsets 0, 16, 20, and 24) is correct after all. 
  It all comes down to this text from rule #9 (emphasis mine):

       (9) If the member is a structure, the base alignment of the 
structure is
           <N>, where <N> is the largest base alignment value of any of its
           members, and *rounded up to the base alignment of a vec4*. The
           individual members of this sub-structure are then assigned 
offsets
           by applying this set of rules recursively, where the base 
offset of
           the first member of the sub-structure is equal to the aligned 
offset
           of the structure. The structure may have padding at the end; the
           base offset of the member following the sub-structure is 
rounded up
           to the next multiple of the base alignment of the structure.

In part of our code we're not doing the rounding on substructures, and 
it doesn't look like my old NVIDIA drivers are either.  Ugh.

> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>   .../spec/arb_uniform_buffer_object/layout-std140.c | 25 +++++++++++++++++++++-
>   1 file changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/tests/spec/arb_uniform_buffer_object/layout-std140.c b/tests/spec/arb_uniform_buffer_object/layout-std140.c
> index 43d0336..d76a0a5 100644
> --- a/tests/spec/arb_uniform_buffer_object/layout-std140.c
> +++ b/tests/spec/arb_uniform_buffer_object/layout-std140.c
> @@ -69,6 +69,10 @@ static const struct result {
>   	{ "o[1].l", 336, 2 },
>   	{ "o[1].m", 368, 1 },
>   	{ "o[1].n", 384, 2 },
> +	{ "s.s1.r", 0, 1 },
> +	{ "s.s2.g", 4, 1 },
> +	{ "s.s2.b", 8, 1 },
> +	{ "s.s2.a", 12, 1 },
>   };
>
>   static const char frag_shader_text[] =
> @@ -95,9 +99,28 @@ static const char frag_shader_text[] =
>   	"	} o[2];\n"
>   	"};\n"
>   	"\n"
> +	"struct S1 {\n"
> +	"	float r;\n"
> +	"};\n"
> +	"\n"
> +	"struct S2 {\n"
> +	"	float g;\n"
> +	"	float b;\n"
> +	"	float a;\n"
> +	"};\n"
> +	"\n"
> +	"struct S {\n"
> +	"       S1 s1;\n"
> +	"       S2 s2;\n"
> +	"};\n"
> +	"\n"
> +	"layout(std140) uniform ubo1 {\n"
> +	"	S s;\n"
> +	"};\n"
> +	"\n"
>   	"void main()\n"
>   	"{\n"
> -	"	gl_FragColor = vec4(a + b.x + c.x + float(f.d) + g + h[0] + i[0].x + o[1].k.x);\n"
> +	"	gl_FragColor = vec4(a + b.x + c.x + float(f.d) + g + h[0] + i[0].x + o[1].k.x + s.s1.r + s.s2.g + s.s2.b + s.s2.a);\n"
>   	"}\n";
>
>   static void
>



More information about the Piglit mailing list