From b2793d0a998a92b48978d2aa31f8715ae1cb77a8 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 8 Sep 2014 14:07:41 -0700 Subject: arb_uniform_buffer_object: Add test for padding after a UBO struct Similar to struct_base_alignment.shader_test. Instead of putting a struct after the small struct, put some fields with less that vec4 alignment after the struct. NOTE: On Mesa we get the correct locations, but the shader doesn't generate the correct results. The test fails. Signed-off-by: Ian Romanick Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=83533 Reviewed-by: Chris Forbes --- .../field_after_struct_base_alignment.shader_test | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tests/spec/arb_uniform_buffer_object/field_after_struct_base_alignment.shader_test diff --git a/tests/spec/arb_uniform_buffer_object/field_after_struct_base_alignment.shader_test b/tests/spec/arb_uniform_buffer_object/field_after_struct_base_alignment.shader_test new file mode 100644 index 000000000..2c20dc09d --- /dev/null +++ b/tests/spec/arb_uniform_buffer_object/field_after_struct_base_alignment.shader_test @@ -0,0 +1,96 @@ +[require] +GLSL >= 1.30 +GL_ARB_uniform_buffer_object + +[vertex shader] +#extension GL_ARB_uniform_buffer_object : require + +struct S1 { + float r; +}; + +/* Section 2.11.4 (Uniform Variables), subsection Standard Uniform + * Block Layout, of the OpenGL 3.1 spec says (emphasis mine): + * + * "(9) If the member is a structure, the base alignment of the + * structure is , where 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." + */ +struct S { + S1 s1; + float g; + float b; + float a; +}; + +layout(std140) uniform ubo1 { + S s; +}; + +in vec4 piglit_vertex; +flat out int pass; + +void main() +{ + /* std140 (or shared) layout prevents any fields or blocks from being + * eliminted. Section 2.11.6 of the OpenGL ES 3.0 spec makes this + * explicit, but desktop GL specs only say it implicitly. Either way, + * there is no need to reference any field of the std140 block. + */ + gl_Position = piglit_vertex; + + pass = int(s.g == 3.3); + +} + +[fragment shader] +out vec4 piglit_fragcolor; +flat in int pass; + +void main() +{ + piglit_fragcolor = bool(pass) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); +} + +[test] +link success + +active uniform s.s1.r GL_UNIFORM_TYPE GL_FLOAT +active uniform s.s1.r GL_UNIFORM_SIZE 1 +active uniform s.s1.r GL_UNIFORM_OFFSET 0 +active uniform s.s1.r GL_UNIFORM_ARRAY_STRIDE 0 +active uniform s.s1.r GL_UNIFORM_MATRIX_STRIDE 0 +active uniform s.s1.r GL_UNIFORM_IS_ROW_MAJOR 0 + +active uniform s.g GL_UNIFORM_TYPE GL_FLOAT +active uniform s.g GL_UNIFORM_SIZE 1 +active uniform s.g GL_UNIFORM_OFFSET 16 +active uniform s.g GL_UNIFORM_ARRAY_STRIDE 0 +active uniform s.g GL_UNIFORM_MATRIX_STRIDE 0 +active uniform s.g GL_UNIFORM_IS_ROW_MAJOR 0 + +active uniform s.b GL_UNIFORM_TYPE GL_FLOAT +active uniform s.b GL_UNIFORM_SIZE 1 +active uniform s.b GL_UNIFORM_OFFSET 20 +active uniform s.b GL_UNIFORM_ARRAY_STRIDE 0 +active uniform s.b GL_UNIFORM_MATRIX_STRIDE 0 +active uniform s.b GL_UNIFORM_IS_ROW_MAJOR 0 + +active uniform s.a GL_UNIFORM_TYPE GL_FLOAT +active uniform s.a GL_UNIFORM_SIZE 1 +active uniform s.a GL_UNIFORM_OFFSET 24 +active uniform s.a GL_UNIFORM_ARRAY_STRIDE 0 +active uniform s.a GL_UNIFORM_MATRIX_STRIDE 0 +active uniform s.a GL_UNIFORM_IS_ROW_MAJOR 0 + +uniform float s.g 3.3 + +draw rect -1 -1 2 2 +probe all rgba 0.0 1.0 0.0 1.0 -- cgit v1.2.3