v2:
   - fixed indentation: spaces -> tabs (Ian)
   - require core/compatibility version 3.2 instead of
     ARB_geometry_shader4 which is not going to be supported by
     mesa (Ian)
   - drop _EXT, use core names instead (Ian)
   - now using piglit_build_simple_program_multiple_shaders()

Signed-off-by: Topi Pohjolainen <[email protected]>
---
 tests/all.tests                                    |   3 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../spec/arb_transform_feedback3/CMakeLists.gl.txt |  13 +
 tests/spec/arb_transform_feedback3/CMakeLists.txt  |   1 +
 .../ext_interleaved_single_stream_many_buffers.c   | 332 +++++++++++++++++++++
 tests/spec/arb_transform_feedback3/xfb3_common.h   |  48 +++
 6 files changed, 398 insertions(+)
 create mode 100644 tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_transform_feedback3/CMakeLists.txt
 create mode 100644 
tests/spec/arb_transform_feedback3/ext_interleaved_single_stream_many_buffers.c
 create mode 100644 tests/spec/arb_transform_feedback3/xfb3_common.h

diff --git a/tests/all.tests b/tests/all.tests
index 395ceac..6f92947 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2304,6 +2304,9 @@ for param in ['gl_NextBuffer-1', 'gl_NextBuffer-2', 
'gl_SkipComponents1-1',
     arb_transform_feedback3[param] = concurrent_test(
             'ext_transform_feedback-output-type {0}'.format(param))
 
+arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_single_stream_many_buffers_vs']
 = 
PlainExecTest(['arb_transform_feedback3-ext_interleaved_single_stream_many_buffers',
 '-auto', 'vs'])
+arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_single_stream_many_buffers_gs']
 = 
PlainExecTest(['arb_transform_feedback3-ext_interleaved_single_stream_many_buffers',
 '-auto', 'gs'])
+
 arb_uniform_buffer_object = Group()
 spec['ARB_uniform_buffer_object'] = arb_uniform_buffer_object
 import_glsl_parser_tests(spec['ARB_uniform_buffer_object'],
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 57146f6..5dc6ad2 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -39,6 +39,7 @@ add_subdirectory (arb_texture_storage_multisample)
 add_subdirectory (arb_texture_view)
 add_subdirectory (arb_timer_query)
 add_subdirectory (arb_transform_feedback2)
+add_subdirectory (arb_transform_feedback3)
 add_subdirectory (ati_envmap_bumpmap)
 add_subdirectory (ext_fog_coord)
 add_subdirectory (ext_framebuffer_multisample)
diff --git a/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt 
b/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
new file mode 100644
index 0000000..a202233
--- /dev/null
+++ b/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
@@ -0,0 +1,13 @@
+include_directories(
+       ${GLEXT_INCLUDE_DIR}
+       ${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+       piglitutil_${piglit_target_api}
+       ${OPENGL_gl_LIBRARY}
+)
+
+piglit_add_executable 
(arb_transform_feedback3-ext_interleaved_single_stream_many_buffers 
ext_interleaved_single_stream_many_buffers.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_transform_feedback3/CMakeLists.txt 
b/tests/spec/arb_transform_feedback3/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_transform_feedback3/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git 
a/tests/spec/arb_transform_feedback3/ext_interleaved_single_stream_many_buffers.c
 
b/tests/spec/arb_transform_feedback3/ext_interleaved_single_stream_many_buffers.c
new file mode 100644
index 0000000..5e01ebd
--- /dev/null
+++ 
b/tests/spec/arb_transform_feedback3/ext_interleaved_single_stream_many_buffers.c
@@ -0,0 +1,332 @@
+/*
+ * Copyright © 2013 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 "xfb3_common.h"
+
+/**
+ * @file ext_interleaved_single_stream_many_buffers.c 
+ *
+ * Records interleaved varyings using single vertex stream into separate
+ * buffers. The test tries to use as many buffers the tested GL-stack can
+ * support trying to ouput the maximum amount of supported varyings evenly
+ * between the buffers.
+ * The test can be executed in two different ways: the stream originating from
+ * vertex shader or from single geometry shader instance.
+ *
+ * Recording both vertex shader and geometry shader outputs in parallel is not
+ * supported by the extension. The spec says:
+ *
+ * "When a geometry shader is active (see section 2.12), transform feedback
+ *  records the values of the selected geometry shader output variables from 
the
+ *  emitted vertices. Otherwise, the values of the selected vertex shader 
output
+ *  variables are recorded."
+ * 
+ * This test uses the "EXT"-style GLSL transform feedback.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+       config.supports_gl_compat_version = 32;
+       config.supports_gl_core_version = 32;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static char *
+generate_shader(const char *prologue, unsigned prologue_len,
+               const char *epilogue, unsigned epilogue_len,
+               unsigned n_bufs, unsigned n_vars_per_buf)
+{
+       unsigned i;
+       char *res;
+       char *curr;
+       static const char output_decl[] = "out float x%u_out;\n";
+       static const char output_assign[] = "  x%u_out = %u.0;\n";
+       static const char main_opening[] = "void main() {\n";
+       const unsigned int_extra = formatted_int_extra_space(
+                                               n_bufs * n_vars_per_buf);
+
+       curr = res = malloc(prologue_len + sizeof(main_opening) +
+                       n_bufs * n_vars_per_buf *
+                               (sizeof(output_decl) + int_extra +
+                                sizeof(output_assign) + 2 * int_extra) +
+                       epilogue_len);
+
+       curr += snprintf(curr, prologue_len, prologue);
+
+       for (i = 0; i < n_bufs * n_vars_per_buf; ++i)
+               curr += sprintf(curr, output_decl, i);
+
+       curr += sprintf(curr, main_opening);
+
+       for (i = 0; i < n_bufs * n_vars_per_buf; ++i)
+               curr += sprintf(curr, output_assign, i, i);
+
+       curr += snprintf(curr, epilogue_len, epilogue);
+
+       return res;
+}
+
+static char *
+generate_geometry_shader(unsigned n_bufs, unsigned n_vars_per_buf)
+{
+       static const char prologue[] =
+               "#version 150\n"
+               "#extension GL_ARB_gpu_shader5 : enable\n"
+               "layout(points) in;\n"
+               "layout(points, max_vertices = 1) out;\n";
+       static const char epilogue[] = "  EmitVertex();\n}\n";
+
+       return generate_shader(prologue, sizeof(prologue),
+                       epilogue, sizeof(epilogue), n_bufs, n_vars_per_buf);
+}
+
+static char *
+generate_vertex_shader(unsigned n_bufs, unsigned n_vars_per_buf)
+{
+       static const char prologue[] = "#version 150\n";
+       static const char epilogue[] = "  }\n";
+
+       return generate_shader(prologue, sizeof(prologue),
+                       epilogue, sizeof(epilogue), n_bufs, n_vars_per_buf);
+}
+
+static void
+setup_varyings(GLuint prog, unsigned n_bufs, unsigned n_vars_per_buf)
+{
+       /**
+        * The spec for ARB_transform_feedback3 says:
+        *
+        * If a string in <varyings> is "gl_NextBuffer", it does not identify a
+        * varying variable, but instead serves as a buffer separator value to 
+        * direct subsequent varyings at the next transform feedback binding
+        * point.
+        */
+       static const char separator[] = "gl_NextBuffer";
+       static const char var_template[] = "x%u_out";
+       const unsigned int_extra = formatted_int_extra_space(
+                                               n_bufs * n_vars_per_buf);
+       /* Every 'n' buffers are separated by 'n - 1' separator strings */
+       const unsigned var_n = n_bufs * n_vars_per_buf + n_bufs - 1;
+       char *var_strings;
+       const char **var_array;
+       const char **curr_var;
+       unsigned i, j, pos;
+
+       var_strings = (char *)malloc(n_bufs * n_vars_per_buf *
+                               (sizeof(var_template) + int_extra) +
+                               (n_bufs - 1) * sizeof(separator));
+       var_array = (const char**)malloc(var_n * sizeof(const char *));
+
+       for (i = 0, pos = 0, curr_var = var_array; i < n_bufs; ++i) {
+               if (i != 0) {
+                       *curr_var++ = var_strings + pos;
+                       pos += sprintf(var_strings + pos, separator);
+                       ++pos; /* terminator */
+               }
+
+               for (j = 0; j < n_vars_per_buf; ++j) {
+                       *curr_var++ = var_strings + pos;
+                       pos += sprintf(var_strings + pos, var_template,
+                                       i * n_vars_per_buf + j);
+                       ++pos; /* terminator */
+               }
+       }
+
+       /**
+        * It should be noticed that when mixed mode is used, i.e., where one
+        * records multiple attributes per buffer but also uses separate
+        * buffers, the mode must be set to interleaved.
+        */
+       glTransformFeedbackVaryings(prog, var_n, var_array,
+                               GL_INTERLEAVED_ATTRIBS);
+
+       free(var_strings);
+       free(var_array);
+}
+
+static void
+build_and_use_program(bool use_gs, unsigned n_bufs, unsigned n_vars_per_buf)
+{
+       GLuint prog;
+
+       if (use_gs) {
+               char *gs_text = generate_geometry_shader(n_bufs,
+                                               n_vars_per_buf);
+               prog = piglit_build_simple_program_multiple_shaders(
+                               GL_VERTEX_SHADER, vs_pass_thru_text,
+                               GL_GEOMETRY_SHADER, gs_text, 0);
+               free(gs_text);
+       } else {
+               char *vs_text = generate_vertex_shader(n_bufs, n_vars_per_buf);
+               prog = piglit_build_simple_program_multiple_shaders(
+                               GL_VERTEX_SHADER, vs_text, 0);
+               free(vs_text);
+       }
+
+       /**
+        * In the EXT-style the recorded varyings need to be set before linking.
+        */
+       setup_varyings(prog, n_bufs, n_vars_per_buf);
+
+       if (!piglit_check_gl_error(GL_NO_ERROR))
+               piglit_report_result(PIGLIT_FAIL);
+
+       glLinkProgram(prog);
+       if (!piglit_link_check_status(prog))
+               piglit_report_result(PIGLIT_FAIL);
+       if (!piglit_check_gl_error(GL_NO_ERROR))
+               piglit_report_result(PIGLIT_FAIL);
+
+       glUseProgram(prog);
+}
+
+static bool
+probe_buffers(GLuint *xfb, unsigned n_bufs, unsigned n_vars_per_buf)
+{
+       int i, j;
+       bool pass = true;
+       float *expected = malloc(n_vars_per_buf * sizeof(float));
+
+       for (i = 0; i < n_bufs; ++i) {
+               char label[32];
+
+               sprintf(label, "buf[%u]", i);
+
+               for (j = 0; j < n_vars_per_buf; ++j)
+                       expected[j] = (i * n_vars_per_buf) + j;
+
+               pass = piglit_probe_buffer(xfb[i],
+                               GL_TRANSFORM_FEEDBACK_BUFFER, label, 1,
+                               n_vars_per_buf, expected) && pass;
+       }
+
+       free(expected);
+
+       return pass;
+}
+
+static void
+print_usage_and_exit(const char *prog_name)
+{
+       printf("Usage: %s <subtest>\n"
+              "  where <subtest> is one of the following:\n"
+              "    gs\n"
+              "    vs\n", prog_name);
+       piglit_report_result(PIGLIT_FAIL);
+}
+
+static void
+check_driver(GLint *max_bufs, GLint *max_xfb_comps)
+{
+       piglit_require_GLSL_version(150);
+       piglit_require_extension("GL_ARB_transform_feedback3");
+       piglit_require_extension("GL_ARB_gpu_shader5");
+
+       glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, max_bufs);
+       glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS,
+               max_xfb_comps);
+
+       if (!*max_bufs || !*max_xfb_comps) {
+               printf("Maximum amount of buffers and components need to be"
+                       "positive (%u:%u).\n", *max_bufs, *max_xfb_comps);
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+       /* Get the number of varyings - each consumes four components */
+       *max_xfb_comps /= 4;
+
+       if (*max_bufs > *max_xfb_comps) {
+               printf("Maximum amount of buffers exceeds maximum amount of "
+                       "varyings (%u:%u).\n", *max_bufs, *max_xfb_comps);
+               piglit_report_result(PIGLIT_FAIL);
+       }
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+       int i;
+       bool pass, use_gs;
+       GLuint *xfb;
+       GLint max_bufs, max_xfb_comps;
+       GLuint vao;
+
+       if (argc != 2)
+               print_usage_and_exit(argv[0]);
+       if (strcmp(argv[1], "vs") == 0)
+               use_gs = false;
+       else if (strcmp(argv[1], "gs") == 0)
+               use_gs = true;
+       else
+               print_usage_and_exit(argv[0]);
+
+       check_driver(&max_bufs, &max_xfb_comps);
+
+       build_and_use_program(use_gs, max_bufs, max_xfb_comps / max_bufs);
+
+       xfb = malloc(max_bufs * sizeof(GLuint));
+
+       /* Set up the transform feedback buffers. */
+       glGenBuffers(max_bufs, xfb);
+       for (i = 0; i < max_bufs; ++i) {
+               glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, i, xfb[i]);
+               glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER,
+                       (max_xfb_comps / max_bufs) * sizeof(float), NULL,
+                       GL_STREAM_READ);
+       }
+
+       /* Test only records using transform feedback. */
+       glEnable(GL_RASTERIZER_DISCARD);
+
+       if (!piglit_check_gl_error(GL_NO_ERROR)) {
+               free(xfb);
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+       /* Test is run under desktop OpenGL 3.2 -> use of VAOs is required */
+       glGenVertexArrays(1, &vao);
+       glBindVertexArray(vao);
+
+       /* Draw and record */
+       glBeginTransformFeedback(GL_POINTS);
+       glDrawArrays(GL_POINTS, 0, 1);
+       glEndTransformFeedback();
+
+       if (!piglit_check_gl_error(GL_NO_ERROR)) {
+               free(xfb);
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+       pass = probe_buffers(xfb, max_bufs, max_xfb_comps / max_bufs);
+       free(xfb);
+
+       piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+       /* Should never be reached */
+       return PIGLIT_FAIL;
+}
diff --git a/tests/spec/arb_transform_feedback3/xfb3_common.h 
b/tests/spec/arb_transform_feedback3/xfb3_common.h
new file mode 100644
index 0000000..2cdaae9
--- /dev/null
+++ b/tests/spec/arb_transform_feedback3/xfb3_common.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright © 2013 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.
+ */
+#ifndef XFB3_COMMON_H
+#define XFB3_COMMON_H
+
+#include <math.h>
+
+static const char vs_pass_thru_text[] =
+       "#version 150\n"
+       "void main() {\n"
+       "  gl_Position = vec4(0.0);\n"
+       "}\n";
+
+/**
+ * Resolve how many characters are needed to format string representation for
+ * integer value "n_vars". All format specifiers in the test cases are the same
+ * ,"%u", resulting in two characters (strlen("%u")) per value being reserved
+ * when the space for the formatted string is determined.
+ */
+inline static unsigned
+formatted_int_extra_space(unsigned n_vars)
+{
+       unsigned total = (unsigned)ceil(log10(n_vars));
+
+       return total > 2 ? total - 2 : 0;
+}
+
+#endif /* XFB3_COMMON_H */
-- 
1.8.3.1

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

Reply via email to