Add very rudimentary tests for the 3 vertex related queries in
ARB_pipeline_statistics_query. This can be accomplished easily with 1
shader, and 1 draw call - and is sort of required to work before testing
the other stages.

The library introduced here will be reused on other tests.

Note about the library: I attempted to use the existing piglit_add_library,
however I was getting cmake warnings (cmake --help-policy CMP0038). Since the
library won't grow large, I simply went with a static library using standard
CMAKE directives.

v2: Pull the separate rules.py into this file
Make the init function check that the tokens are supported.
Use glGetQueryObjectui64v instead of glGetQueryObjectuiv
Rename directory location to arb_pipeline_statistics_query (Jordan)
Rename binaries (Ilia)
Use new concurrent command in all.py

Signed-off-by: Ben Widawsky <[email protected]>
---
 tests/all.py                                       |   4 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../CMakeLists.gl.txt                              |  22 ++++
 .../arb_pipeline_statistics_query/CMakeLists.txt   |   1 +
 .../pipeline_stats_vert.c                          | 132 +++++++++++++++++++++
 .../arb_pipeline_statistics_query/pipestat_help.c  |  94 +++++++++++++++
 .../arb_pipeline_statistics_query/pipestat_help.h  |  29 +++++
 7 files changed, 283 insertions(+)
 create mode 100644 tests/spec/arb_pipeline_statistics_query/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_pipeline_statistics_query/CMakeLists.txt
 create mode 100644 
tests/spec/arb_pipeline_statistics_query/pipeline_stats_vert.c
 create mode 100644 tests/spec/arb_pipeline_statistics_query/pipestat_help.c
 create mode 100644 tests/spec/arb_pipeline_statistics_query/pipestat_help.h

diff --git a/tests/all.py b/tests/all.py
index d7a921a..10fbd4d 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3764,6 +3764,10 @@ spec['EXT_polygon_offset_clamp'] = 
ext_polygon_offset_clamp
 add_concurrent_test(ext_polygon_offset_clamp, 
['ext_polygon_offset_clamp-draw'])
 add_concurrent_test(ext_polygon_offset_clamp, 
['ext_polygon_offset_clamp-dlist'])
 
+arb_pipeline_statistics_query = {}
+spec['ARB_pipeline_statistics_query'] = arb_pipeline_statistics_query
+add_concurrent_test(arb_pipeline_statistics_query, 
['arb_pipeline_statistics_query-vert'])
+
 # group glslparsertest ------------------------------------------------------
 glslparsertest = {}
 # Add all shader source files in the directories below.
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 31d6988..d5d3918 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -119,3 +119,4 @@ add_subdirectory (arb_vertex_array_object)
 add_subdirectory (oes_texture_float)
 add_subdirectory (arb_direct_state_access)
 add_subdirectory (ext_polygon_offset_clamp)
+add_subdirectory (arb_pipeline_statistics_query)
diff --git a/tests/spec/arb_pipeline_statistics_query/CMakeLists.gl.txt 
b/tests/spec/arb_pipeline_statistics_query/CMakeLists.gl.txt
new file mode 100644
index 0000000..d6c11b2
--- /dev/null
+++ b/tests/spec/arb_pipeline_statistics_query/CMakeLists.gl.txt
@@ -0,0 +1,22 @@
+include_directories(
+    ${GLEXT_INCLUDE_DIR}
+    ${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+    piglitutil_${piglit_target_api}
+    ${OPENGL_gl_LIBRARY}
+)
+
+# Display stuff in the tests
+#add_definitions (-DDISPLAY)
+
+# Don't bother with the piglit helper functions since we just need a simple
+# static link that won't be installed. (We'll actually anger newer cmake if we
+# use piglit helpers).
+add_library (pipestat_help STATIC pipestat_help.c)
+
+piglit_add_executable (arb_pipeline_statistics_query-vert 
pipeline_stats_vert.c)
+target_link_libraries (arb_pipeline_statistics_query-vert pipestat_help)
+
+# vim: ft=cmake
diff --git a/tests/spec/arb_pipeline_statistics_query/CMakeLists.txt 
b/tests/spec/arb_pipeline_statistics_query/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_pipeline_statistics_query/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_pipeline_statistics_query/pipeline_stats_vert.c 
b/tests/spec/arb_pipeline_statistics_query/pipeline_stats_vert.c
new file mode 100644
index 0000000..7072b4e
--- /dev/null
+++ b/tests/spec/arb_pipeline_statistics_query/pipeline_stats_vert.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2014 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 pipeline_stats_vert.c
+ *
+ *  This test verifies that the vertex shader related tokens of
+ *  ARB_pipeline_statistics_query() work as expected. OpenGL 4.4 Specification,
+ *  Core Profile.
+ *
+ *  Section 11.1.3 as quoted below makes it sound like we can't actually
+ *  reliably count on any of these values. Consider that information when
+ *  investigating failures.
+ *
+ * 10.1
+ *  When BeginQuery is called with a target of VERTICES_SUBMITTED_ARB, the
+ *  submitted vertices count maintained by the GL is set to zero. When a
+ *  vertices submitted query is active, the submitted vertices count is
+ *  incremented every time a vertex is transferred to the GL (see sections
+ *  10.3.4, and 10.5). In case of primitive types with adjacency information
+ *  (see sections 10.1.11 through 10.1.14) only the vertices belonging to the
+ *  main primitive are counted but not the adjacent vertices. In case of line
+ *  loop primitives implementations are allowed to count the first vertex
+ *  twice for the purposes of VERTICES_SUBMITTED_ARB queries.  Additionally,
+ *  vertices corresponding to incomplete primitives may or may not be
+ *  counted.
+ *
+ *  When BeginQuery is called with a target of PRIMITIVES_SUBMITTED_ARB, the
+ *  submitted primitives count maintained by the GL is set to zero. When a
+ *  primitives submitted query is active, the submitted primitives count is
+ *  incremented every time a point, line, triangle, or patch primitive is
+ *  transferred to the GL (see sections 10.1, 10.3.5, and 10.5). Restarting a
+ *  primitive topology using the primitive restart index has no effect on the
+ *  issued primitives count. Incomplete primitives may or may not be counted.
+ *
+ * 11.1.3 (the chicken clause)
+ *  Implementations are allowed to skip the execution of certain shader
+ *  invocations, and to execute additional shader invocations for any shader
+ *  type during programmable vertex processing due to implementation dependent
+ *  reasons, including the execution of shader invocations that don't have an
+ *  active program object present for the particular shader stage, as long as
+ *  the results of rendering otherwise remain unchanged.
+ */
+
+#include "piglit-util-gl.h"
+#include "pipestat_help.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+    config.supports_gl_compat_version = 30;
+    config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+PIGLIT_GL_TEST_CONFIG_END
+
+static const char *vs_src =
+       "#version 110                   \n"
+       "                               \n"
+       "void main()                    \n"
+       "{                              \n"
+       "   gl_Position = gl_Vertex;    \n"
+       "}                              \n";
+
+static struct query queries[] = {
+       {
+        .query = GL_PRIMITIVES_SUBMITTED_ARB,
+        .name = "GL_PRIMITIVES_SUBMITTED_ARB",
+        .expected = NUM_PRIMS},
+       {
+        .query = GL_VERTICES_SUBMITTED_ARB,
+        .name = "GL_VERTICES_SUBMITTED_ARB",
+        .expected = NUM_VERTS},
+       {
+        .query = GL_VERTEX_SHADER_INVOCATIONS_ARB,
+        .name = "GL_VERTEX_SHADER_INVOCATIONS_ARB",
+        .expected = NUM_VERTS}
+};
+
+/* Use DISPLAY for debug */
+enum piglit_result
+piglit_display(void)
+{
+       enum piglit_result ret = do_query(queries, ARRAY_SIZE(queries));
+#ifdef DISPLAY
+       piglit_present_results();
+#endif
+       return ret;
+}
+
+void
+piglit_init(int argc, char *argv[])
+{
+       GLuint vs, prog;
+
+       piglit_require_gl_version(11);
+       piglit_require_GLSL();
+
+#ifndef DISPLAY
+       glEnable(GL_RASTERIZER_DISCARD);
+#endif
+       do_query_init(queries, ARRAY_SIZE(queries));
+
+       /* Emit a very simply vertex shader just to make sure we actually go
+        * through the part of the pipeline we're trying to test. */
+       vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_src);
+       prog = glCreateProgram();
+       glAttachShader(prog, vs);
+       glLinkProgram(prog);
+
+       if (!piglit_link_check_status(prog)) {
+               glDeleteProgram(prog);
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+       glUseProgram(prog);
+}
diff --git a/tests/spec/arb_pipeline_statistics_query/pipestat_help.c 
b/tests/spec/arb_pipeline_statistics_query/pipestat_help.c
new file mode 100644
index 0000000..ab9630a
--- /dev/null
+++ b/tests/spec/arb_pipeline_statistics_query/pipestat_help.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright © 2014 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 pipestat_help.c
+ *
+ * Helper library for the pipeline statistics tests
+ */
+
+#include <stdint.h>
+#include <inttypes.h>
+#include "piglit-util-gl.h"
+#include "pipestat_help.h"
+
+void
+do_query_init(struct query *queries, const int count)
+{
+       int i;
+
+       /* Some of the token require more than just having the extension, but
+        * all require at least having the extension.
+        */
+       if (!piglit_is_extension_supported
+           ("GL_ARB_pipeline_statistics_query")) {
+               printf("Pipeline statistics not supported.\n");
+               piglit_report_result(PIGLIT_SKIP);
+       }
+
+       for (i = 0; i < count; i++) {
+               GLint bits;
+               glGetQueryiv(queries[i].query, GL_QUERY_COUNTER_BITS, &bits);
+               if (bits == 0) {
+                       printf("%s is unsupported.\n", queries[i].name);
+                       piglit_report_result(PIGLIT_SKIP);
+               }
+       }
+
+
+       for (i = 0; i < count; i++) {
+               glGenQueries(1, &queries[i].obj);
+               if (glGetError() != GL_NO_ERROR)
+                       piglit_report_result(PIGLIT_FAIL);
+       }
+}
+
+enum piglit_result
+do_query(const struct query *queries, const int count)
+{
+       const float green[] = {0, 1, 0, 0};
+       int i;
+
+       glClearColor(1.0, 0.0, 0.0, 0.0);
+       glClear(GL_COLOR_BUFFER_BIT);
+       glColor4fv(green);
+
+       for (i = 0; i < count; i++)
+               begin_query(&queries[i]);
+
+       piglit_draw_rect(-1, -1, 2, 2);
+
+       for (i = 0; i < count; i++)
+               end_query(&queries[i]);
+
+       for (i = 0; i < count; i++) {
+               GLuint64 params;
+               glGetQueryObjectui64v(queries[i].obj, GL_QUERY_RESULT, &params);
+               if (params != queries[i].expected) {
+                       fprintf(stderr, "%s was %" PRIu64 "Expected %" PRIu64 
"\n",
+                               queries[i].name, params, queries[i].expected);
+                       piglit_report_result(PIGLIT_FAIL);
+               }
+       }
+
+       return PIGLIT_PASS;
+}
diff --git a/tests/spec/arb_pipeline_statistics_query/pipestat_help.h 
b/tests/spec/arb_pipeline_statistics_query/pipestat_help.h
new file mode 100644
index 0000000..97cb3ca
--- /dev/null
+++ b/tests/spec/arb_pipeline_statistics_query/pipestat_help.h
@@ -0,0 +1,29 @@
+#define TEST_HEIGHT 10
+#define TEST_WIDTH 10
+
+/* We're going to be emitting a TRISTRIP to form a square (after doing a
+ * clear). This makes our pipeline quite predictable. */
+#define NUM_VERTS 4
+#define NUM_PRIMS 2
+
+struct query {
+       GLuint obj;
+       GLuint query;
+       const char *name;
+       GLuint64 expected;
+};
+
+static inline void
+begin_query(const struct query *q)
+{
+       glBeginQuery(q->query, q->obj);
+}
+
+static inline void
+end_query(const struct query *q)
+{
+       glEndQuery(q->query);
+}
+
+void do_query_init(struct query *queries, const int count);
+enum piglit_result do_query(const struct query *queries, const int count);
-- 
2.3.0

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

Reply via email to