---
 tests/all.tests                                    |    1 +
 .../arb_uniform_buffer_object/CMakeLists.gl.txt    |    1 +
 ...tactiveuniformblockiv-uniform-block-data-size.c |  143 ++++++++++++++++++++
 .../spec/arb_uniform_buffer_object/uniform-types.c |  105 ++++++++++++++
 .../spec/arb_uniform_buffer_object/uniform-types.h |   35 +++++
 5 files changed, 285 insertions(+)
 create mode 100644 
tests/spec/arb_uniform_buffer_object/getactiveuniformblockiv-uniform-block-data-size.c
 create mode 100644 tests/spec/arb_uniform_buffer_object/uniform-types.c
 create mode 100644 tests/spec/arb_uniform_buffer_object/uniform-types.h

diff --git a/tests/all.tests b/tests/all.tests
index 899b8d2..2a8417c 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1901,6 +1901,7 @@ add_shader_test_dir(spec['ARB_uniform_buffer_object'],
                    recursive=True)
 arb_uniform_buffer_object['bindbuffer-general-point'] = 
concurrent_test('arb_uniform_buffer_object-bindbuffer-general-point')
 arb_uniform_buffer_object['buffer-targets'] = 
concurrent_test('arb_uniform_buffer_object-buffer-targets')
+arb_uniform_buffer_object['getactiveuniformblockiv-uniform-block-data-size'] = 
concurrent_test('arb_uniform_buffer_object-getactiveuniformblockiv-uniform-block-data-size')
 arb_uniform_buffer_object['getactiveuniformblockname'] = 
concurrent_test('arb_uniform_buffer_object-getactiveuniformblockname')
 arb_uniform_buffer_object['getactiveuniformname'] = 
concurrent_test('arb_uniform_buffer_object-getactiveuniformname')
 arb_uniform_buffer_object['getactiveuniformsiv-uniform-block-index'] = 
concurrent_test('arb_uniform_buffer_object-getactiveuniformsiv-uniform-block-index')
diff --git a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt 
b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
index 41d07bb..0285b46 100644
--- a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
+++ b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
@@ -12,6 +12,7 @@ link_libraries (
 
 add_executable (arb_uniform_buffer_object-bindbuffer-general-point 
bindbuffer-general-point.c)
 add_executable (arb_uniform_buffer_object-buffer-targets buffer-targets.c)
+add_executable 
(arb_uniform_buffer_object-getactiveuniformblockiv-uniform-block-data-size 
getactiveuniformblockiv-uniform-block-data-size.c uniform-types.c)
 add_executable (arb_uniform_buffer_object-getactiveuniformblockname 
getactiveuniformblockname.c)
 add_executable (arb_uniform_buffer_object-getactiveuniformname 
getactiveuniformname.c)
 add_executable 
(arb_uniform_buffer_object-getactiveuniformsiv-uniform-block-index 
getactiveuniformsiv-uniform-block-index.c)
diff --git 
a/tests/spec/arb_uniform_buffer_object/getactiveuniformblockiv-uniform-block-data-size.c
 
b/tests/spec/arb_uniform_buffer_object/getactiveuniformblockiv-uniform-block-data-size.c
new file mode 100644
index 0000000..06a88d9
--- /dev/null
+++ 
b/tests/spec/arb_uniform_buffer_object/getactiveuniformblockiv-uniform-block-data-size.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/** @file getactiveuniformblockiv-uniform-block-data-size.c
+ *
+ * From the GL_ARB_uniform_buffer_object spec:
+ *
+ *     "For uniform blocks laid out according to [std140] rules, the
+ *      minimum buffer object size returned by the
+ *      UNIFORM_BLOCK_DATA_SIZE query is derived by taking the offset
+ *      of the last basic machine unit consumed by the last uniform of
+ *      the uniform block (including any end-of-array or
+ *      end-of-structure padding), adding one, and rounding up to the
+ *      next multiple of the base alignment required for a vec4."
+ */
+
+#define _GNU_SOURCE
+#include "piglit-util-gl-common.h"
+#include "uniform-types.h"
+
+PIGLIT_GL_TEST_MAIN(
+    10 /*window_width*/,
+    10 /*window_height*/,
+    GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA)
+
+static int
+align(int v, int a)
+{
+       return (v + a - 1) & ~(a - 1);
+}
+
+static bool
+test_format(const struct uniform_type *type, bool row_major)
+{
+       /* Using 140 to get unsigned ints. */
+       const char *fs_template =
+               "#version 140\n"
+               "layout(std140) uniform ubo {\n"
+               "       float align_test;\n"
+               "       %s%s u;\n"
+               "};\n"
+               "\n"
+               "void main() {\n"
+               "       gl_FragColor = vec4(align_test);\n"
+               "}\n";
+       char *fs_source;
+       GLuint fs, prog;
+       GLint data_size;
+       int expected;
+       const struct uniform_type *transposed_type;
+
+       if (row_major)
+               transposed_type = get_transposed_type(type);
+       else
+               transposed_type = type;
+
+       asprintf(&fs_source, fs_template,
+                row_major ? "layout(row_major) " : "",
+                type->type);
+       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
+       prog = piglit_link_simple_program(0, fs);
+       if (!fs || !prog) {
+               fprintf(stderr, "Failed to compile shader:\n%s", fs_source);
+               piglit_report_result(PIGLIT_FAIL);
+       }
+       free(fs_source);
+
+       /* There's only one block, so it's uniform block 0. */
+       glGetActiveUniformBlockiv(prog, 0,
+                                 GL_UNIFORM_BLOCK_DATA_SIZE,
+                                 &data_size);
+
+       glDeleteShader(fs);
+       glDeleteProgram(prog);
+
+       /* "align_test" at the start of the UBO is a float, so our
+        * test uniform would start at byte 4 if not for alignment.
+        */
+       expected = 4;
+
+       /* The actual space for our object. */
+       expected = align(expected, transposed_type->alignment);
+       expected += transposed_type->size;
+
+       /* Finally, align to a vec4 like std140 says. */
+       expected = align(expected, 16);
+
+       printf("%-20s %10s %10d %10d%s\n",
+              type->type,
+              row_major ? "y" : "n",
+              data_size,
+              expected,
+              data_size == expected ? "" : " FAIL");
+
+       return data_size == expected;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+       bool pass = true;
+       unsigned int i;
+
+       piglit_require_extension("GL_ARB_uniform_buffer_object");
+       piglit_require_GLSL_version(140);
+
+       printf("%-20s %10s %10s %10s\n",
+              "type", "row_major", "DATA_SIZE", "expected");
+
+       for (i = 0; uniform_types[i].type; i++) {
+               pass = test_format(&uniform_types[i], false) && pass;
+               pass = test_format(&uniform_types[i], true) && pass;
+       }
+
+       piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result piglit_display(void)
+{
+       /* UNREACHED */
+       return PIGLIT_FAIL;
+}
+
diff --git a/tests/spec/arb_uniform_buffer_object/uniform-types.c 
b/tests/spec/arb_uniform_buffer_object/uniform-types.c
new file mode 100644
index 0000000..0dcc94a
--- /dev/null
+++ b/tests/spec/arb_uniform_buffer_object/uniform-types.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "piglit-util-gl-common.h"
+#include "uniform-types.h"
+
+const struct uniform_type uniform_types[] = {
+       { "float", GL_FLOAT, 4, 4 },
+       { "vec2", GL_FLOAT_VEC2, 8, 8 },
+       { "vec3", GL_FLOAT_VEC3, 12, 16 },
+       { "vec4", GL_FLOAT_VEC4, 16, 16 },
+
+       { "int", GL_INT, 4, 4 },
+       { "ivec2", GL_INT_VEC2, 8, 8 },
+       { "ivec3", GL_INT_VEC3, 12, 16 },
+       { "ivec4", GL_INT_VEC4, 16, 16 },
+
+       { "uint", GL_UNSIGNED_INT, 4, 4 },
+       { "uvec2", GL_UNSIGNED_INT_VEC2, 8, 8 },
+       { "uvec3", GL_UNSIGNED_INT_VEC3, 12, 16 },
+       { "uvec4", GL_UNSIGNED_INT_VEC4, 16, 16 },
+
+       { "bool", GL_BOOL, 4, 4 },
+       { "bvec2", GL_BOOL_VEC2, 8, 8 },
+       { "bvec3", GL_BOOL_VEC3, 12, 16 },
+       { "bvec4", GL_BOOL_VEC4, 16, 16 },
+
+       { "mat2", GL_FLOAT_MAT2, 32, 16 },
+       { "mat3", GL_FLOAT_MAT3, 48, 16 },
+       { "mat4", GL_FLOAT_MAT4, 64, 16 },
+
+       { "mat2x3", GL_FLOAT_MAT2x3, 32, 16 },
+       { "mat2x4", GL_FLOAT_MAT2x4, 32, 16 },
+
+       { "mat3x2", GL_FLOAT_MAT3x2, 48, 16 },
+       { "mat3x4", GL_FLOAT_MAT3x4, 48, 16 },
+
+       { "mat4x2", GL_FLOAT_MAT4x2, 64, 16 },
+       { "mat4x3", GL_FLOAT_MAT4x3, 64, 16 },
+
+       /* No sampler types listed, because they don't work in
+        * UBOs.
+        */
+
+       { NULL }
+};
+
+const struct uniform_type *
+get_transposed_type(const struct uniform_type *type)
+{
+       const char *name = NULL;
+       int i;
+
+       switch (type->gl_type) {
+       case GL_FLOAT_MAT2x3:
+               name = "mat3x2";
+               break;
+       case GL_FLOAT_MAT2x4:
+               name = "mat4x2";
+               break;
+       case GL_FLOAT_MAT3x2:
+               name = "mat2x3";
+               break;
+       case GL_FLOAT_MAT3x4:
+               name = "mat4x3";
+               break;
+       case GL_FLOAT_MAT4x2:
+               name = "mat2x4";
+               break;
+       case GL_FLOAT_MAT4x3:
+               name = "mat3x4";
+               break;
+       default:
+               return type;
+       }
+
+       for (i = 0; uniform_types[i].type; i++) {
+               if (strcmp(uniform_types[i].type, name) == 0)
+                       return &uniform_types[i];
+       }
+
+       printf("failed lookup of %s\n", name);
+       piglit_report_result(PIGLIT_FAIL);
+       return type;
+}
diff --git a/tests/spec/arb_uniform_buffer_object/uniform-types.h 
b/tests/spec/arb_uniform_buffer_object/uniform-types.h
new file mode 100644
index 0000000..50a7832
--- /dev/null
+++ b/tests/spec/arb_uniform_buffer_object/uniform-types.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+struct uniform_type {
+       const char *type;
+       GLenum gl_type;
+       unsigned int size;
+       unsigned int alignment;
+};
+
+/* Array of uniform types, terminated by type == NULL */
+extern const struct uniform_type uniform_types[];
+
+const struct uniform_type *
+get_transposed_type(const struct uniform_type *type);
-- 
1.7.10.4

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to