[Mesa-dev] [PATCH 1/3][mesa-demos] query2-info: add a demo that dumps any possible combination for glGetInternalformati*v

Alejandro Piñeiro apinheiro at igalia.com
Sat May 21 18:08:29 UTC 2016


When the support of ARB_internalformat_query2 was sent to review to
the mesa list, Dave Airlie proposed the following (quoting):

"One thing I think would be really useful but might be outside the scope
of your work is a mesa-demos glxinfo super query app.

Something that does what vulkaninfo kinda does and dumps out the
results of every possible query for every possibly GL format."

This commit does that. It is worth to note that it does it only if
ARB_internalformat_query2 is supported, as the rationale behind this
demo was getting all that info.
---

Note that the implementation of util_get_gl_enum_name is empty. It will
be send on the two following patches. This is a workaround to the mesa-dev
ml size limit per patch.

 .gitignore                     |   1 +
 src/CMakeLists.txt             |   1 +
 src/query2-info/CMakeLists.txt |  25 +++
 src/query2-info/query2-info.c  | 234 ++++++++++++++++++++++++
 src/query2-info/util-string.c  |  34 ++++
 src/query2-info/util-string.h  |  25 +++
 src/query2-info/util.c         | 402 +++++++++++++++++++++++++++++++++++++++++
 src/query2-info/util.h         | 263 +++++++++++++++++++++++++++
 8 files changed, 985 insertions(+)
 create mode 100644 src/query2-info/CMakeLists.txt
 create mode 100644 src/query2-info/query2-info.c
 create mode 100644 src/query2-info/util-string.c
 create mode 100644 src/query2-info/util-string.h
 create mode 100644 src/query2-info/util.c
 create mode 100644 src/query2-info/util.h

diff --git a/.gitignore b/.gitignore
index f41f6ba..ccb72a1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,3 +49,4 @@ ltsugar.m4
 ltversion.m4
 lt~obsolete.m4
 missing
+src/query2-info/query2-info
\ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4e1c54e..3b3ac0b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,6 +7,7 @@ add_subdirectory (redbook)
 add_subdirectory (samples)
 add_subdirectory (perf)
 add_subdirectory (objviewer)
+add_subdirectory (query2-info)
 
 add_subdirectory (glsl)
 add_subdirectory (fp)
diff --git a/src/query2-info/CMakeLists.txt b/src/query2-info/CMakeLists.txt
new file mode 100644
index 0000000..8e5e480
--- /dev/null
+++ b/src/query2-info/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories (
+	${CMAKE_SOURCE_DIR}/src/util
+	${OPENGL_INCLUDE_PATH}
+	${GLUT_INCLUDE_DIR}
+	${GLEW_INCLUDE_DIR}
+)
+
+link_directories (
+	${CMAKE_SOURCE_DIR}/src/util
+)
+
+link_libraries (
+	util
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+	${GLUT_glut_LIBRARY}
+	${GLEW_glew_LIBRARY}
+)
+
+add_executable (query2-info
+	query2-info.c
+	util.c
+	util-string.c
+)
+install (TARGETS query2-info DESTINATION query2-info)
diff --git a/src/query2-info/query2-info.c b/src/query2-info/query2-info.c
new file mode 100644
index 0000000..5377943
--- /dev/null
+++ b/src/query2-info/query2-info.c
@@ -0,0 +1,234 @@
+/*
+ * Copyright © 2016 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.
+ */
+
+/**
+ *
+ * This program prints the outcome of calling glGetInternalformati*v
+ * with all the possible combinations of pname/target/internalformat.
+ *
+ * Command line optios:
+ *  -pname <pname>: Prints info for only that pname (numeric value).
+ *  -b:             Prints info using (b)oth 32 and 64 bit queries. By default
+ *                  it only uses the 64-bit one.
+ *  -f:             Prints info (f)iltering out the unsupported internalformat.
+ *  -h:             Prints help.
+ *
+ * Note that the filtering option is based on internalformat being supported
+ * or not, not on the combination of pname/target/internalformat being
+ * supported or not. In practice, is filter out based on the value returned by
+ * the pname GL_INTERNALFORMAT_SUPPORTED.
+ *
+ * Most of the code is based on the piglit tests for the extension
+ * ARB_internalformat_query2
+ *
+ * Author: Alejandro Piñeiro Iglesias <apinheiro at igalia.com>
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <inttypes.h>  /* for PRIu64 macro */
+
+#include <GL/glew.h>
+
+#include "glut_wrap.h"
+#include "util.h"
+
+#define WINDOW_WIDTH    640
+#define WINDOW_HEIGHT   480
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+
+int filter_supported = 0;
+int only_64bit_query = 1;
+int just_one_pname = 0;
+GLenum global_pname = 0;
+
+static void
+init(int argc, char *argv[])
+{
+   glutInit(&argc, argv);
+   glutInitWindowPosition(100, 0);
+#ifdef HAVE_FREEGLUT
+   glutInitContextVersion(3, 2);
+   glutInitContextProfile(GLUT_CORE_PROFILE);
+   glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
+#else
+   glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
+#endif
+   glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
+
+   if (glutCreateWindow(argv[0]) == GL_FALSE) {
+      fprintf(stderr, "Error creating glut window.\n");
+      exit(1);
+   }
+
+   /* glewInit requires glewExperimentel set to true for core
+    * profiles.  Depending on the glew version it also generates a
+    * GL_INVALID_ENUM, so we just call glGetError, instead of
+    * check_gl_error.
+    */
+   glewExperimental = GL_TRUE;
+   GLenum err = glewInit();
+   if (GLEW_OK != err) {
+      fprintf(stderr, "Error calling glewInit(): %s\n", glewGetErrorString(err));
+      exit(1);
+   }
+   glGetError();
+}
+
+static bool
+check_pname(const GLenum pname)
+{
+   int i;
+   for (i = 0; i < ARRAY_SIZE(valid_pnames); i++) {
+     if (pname == valid_pnames[i])
+       return true;
+   }
+   return false;
+}
+
+static void
+print_usage(void)
+{
+   printf("Usage: query2-info [-a] [-f] [-h] [-pname <pname>]\n");
+   printf("\t-pname <pname>: Prints info for only that pname (numeric value).\n");
+   printf("\t-b: Prints info using (b)oth 32 and 64 bit queries. "
+          "By default it only uses the 64-bit one.\n");
+   printf("\t-f: Prints info (f)iltering out the unsupported internalformat.\n");
+   printf("\t\tNOTE: the filtering is based on internalformat being supported"
+          " or not,\n\t\tnot on the combination of pname/target/internalformat being "
+          "supported or not.\n");
+   printf("\t-h: This information.\n");
+}
+
+static void
+parse_args(int argc, char **argv)
+{
+   int i;
+
+   for (i = 1; i < argc; i++) {
+      if (strcmp(argv[i], "-pname") == 0 && i + 1 < argc) {
+         global_pname = atoi(argv[i + 1]);
+         if (!check_pname(global_pname)) {
+            printf("Value `%i' is not a valid <pname> for "
+                   "GetInternalformati*v.\n", global_pname);
+            print_usage();
+            exit(0);
+         }
+         just_one_pname = true;
+         i++;
+      } else if (strcmp(argv[i], "-f") == 0) {
+         filter_supported = true;
+      } else if (strcmp(argv[i], "-b") == 0) {
+         only_64bit_query = 0;
+      } else if (strcmp(argv[i], "-h") == 0) {
+         print_usage();
+         exit(0);
+      } else {
+         printf("Unknown option `%s'\n", argv[i]);
+         print_usage();
+         exit(0);
+      }
+   }
+}
+
+/*
+ * Print all the values for a given pname.
+ */
+static void
+print_pname_values(const GLenum *targets, unsigned num_targets,
+                   const GLenum *internalformats, unsigned num_internalformats,
+                   const GLenum pname,
+                   test_data *data)
+{
+   unsigned i;
+   unsigned j;
+
+   for (i = 0; i < num_targets; i++) {
+      for (j = 0; j < num_internalformats; j++) {
+         bool filter;
+
+         filter = filter_supported ?
+            !test_data_check_supported(data, targets[i], internalformats[j]) :
+            false;
+
+         check_gl_error();
+
+         if (filter)
+            continue;
+
+         /* Some queries will not modify params if unsupported. Use -1 as
+          * reference value. */
+         test_data_set_value_at_index(data, 0, -1);
+         test_data_execute(data, targets[i], internalformats[j], pname);
+
+         check_gl_error();
+
+         print_case(targets[i], internalformats[j],
+                    pname, data);
+      }
+   }
+
+}
+
+int
+main(int argc,
+     char *argv[])
+{
+   test_data *data;
+   GLenum pname;
+   int testing64;
+
+   parse_args(argc, argv);
+
+   init(argc, argv);
+
+   if (!glewIsSupported("GL_ARB_internalformat_query2")) {
+      printf("GL_ARB_internalformat_query2 extension not found\n");
+      exit(1);
+   }
+
+   /* Note that we need to create test_data after initialization, as
+    * glGetInternalformat*v methods are not available until we call glewInit */
+   data = test_data_new(0, 64);
+   for (unsigned i = 0; i < ARRAY_SIZE(valid_pnames); i++) {
+      pname = valid_pnames[i];
+
+      /* Not really the optimal, but do their work */
+      if (just_one_pname && global_pname != pname)
+         continue;
+
+      for (testing64 = only_64bit_query; testing64 <= 1; testing64++) {
+         test_data_set_testing64(data, testing64);
+         print_pname_values(valid_targets, ARRAY_SIZE(valid_targets),
+                            valid_internalformats, ARRAY_SIZE(valid_internalformats),
+                            pname, data);
+      }
+   }
+
+   test_data_clear(&data);
+
+   return 0;
+}
diff --git a/src/query2-info/util-string.c b/src/query2-info/util-string.c
new file mode 100644
index 0000000..0773aab
--- /dev/null
+++ b/src/query2-info/util-string.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2016 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.
+ *
+ * This code was copied from piglit-util-gl-enum-gen.c
+ */
+
+#include "util-string.h"
+
+const char*
+util_get_gl_enum_name(const GLenum param)
+{
+	switch (param) {
+	default: return "(unrecognized enum)";
+	}
+}
diff --git a/src/query2-info/util-string.h b/src/query2-info/util-string.h
new file mode 100644
index 0000000..d142802
--- /dev/null
+++ b/src/query2-info/util-string.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright © 2016 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 <GL/glew.h>
+
+const char* util_get_gl_enum_name(const GLenum param);
diff --git a/src/query2-info/util.c b/src/query2-info/util.c
new file mode 100644
index 0000000..f486646
--- /dev/null
+++ b/src/query2-info/util.c
@@ -0,0 +1,402 @@
+/*
+ * Copyright © 2016 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 "util.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <inttypes.h>  /* for PRIu64 macro */
+#include "util-string.h"
+
+/* Generic callback type, doing a cast of params to void*, to avoid
+ * having two paths (32 and 64) for each check */
+typedef void (*GetInternalformat)(GLenum target, GLenum internalformat,
+                                  GLenum pname, GLsizei bufsize,
+                                  void *params);
+
+/* This struct is intended to abstract the fact that there are two
+ * really similar methods, and two really similar params (just change
+ * the type). All the castings and decision about which method should
+ * be used would be done here, just to keep the code of the test
+ * cleaner.
+ */
+struct _test_data {
+   /* int instead of a bool to make easier iterate on the
+    * possible values. */
+   int testing64;
+   int params_size;
+   void *params;
+   GetInternalformat callback;
+};
+
+/* Updates the callback and params based on current values of
+ * testing64 and params_size */
+static void
+sync_test_data(test_data *data)
+{
+   if (data->params != NULL)
+      free(data->params);
+
+   if (data->testing64) {
+      data->callback = (GetInternalformat) glGetInternalformati64v;
+      data->params = malloc(sizeof(GLint64) * data->params_size);
+   } else {
+      data->callback = (GetInternalformat) glGetInternalformativ;
+      data->params = malloc(sizeof(GLint) * data->params_size);
+   }
+}
+
+test_data*
+test_data_new(int testing64,
+              int params_size)
+{
+   test_data *result;
+
+   result = (test_data*) malloc(sizeof(test_data));
+   result->testing64 = testing64;
+   result->params_size = params_size;
+   result->params = NULL;
+
+   sync_test_data(result);
+
+   return result;
+}
+
+/*
+ * Frees @data, and sets its value to NULL.
+ */
+void
+test_data_clear(test_data **data)
+{
+   test_data *_data = *data;
+
+   if (_data == NULL)
+      return;
+
+   free(_data->params);
+   _data->params = NULL;
+
+   free(_data);
+   *data = NULL;
+}
+
+void
+test_data_execute(test_data *data,
+                  const GLenum target,
+                  const GLenum internalformat,
+                  const GLenum pname)
+{
+   data->callback(target, internalformat, pname,
+                  data->params_size, data->params);
+}
+
+void
+test_data_set_testing64(test_data *data,
+                        const int testing64)
+{
+   if (data->testing64 == testing64)
+      return;
+
+   data->testing64 = testing64;
+   sync_test_data(data);
+}
+
+void
+test_data_set_value_at_index(test_data *data,
+                             const int index,
+                             const GLint64 value)
+{
+   if (index > data->params_size || index < 0) {
+      fprintf(stderr, "ERROR: invalid index while setting"
+              " auxiliar test data\n");
+      return;
+   }
+
+   if (data->testing64) {
+      ((GLint64*)data->params)[index] = value;
+   } else {
+      ((GLint*)data->params)[index] = value;
+   }
+}
+
+GLint64
+test_data_value_at_index(const test_data *data,
+                         const int index)
+{
+   if (index > data->params_size || index < 0) {
+      fprintf(stderr, "ERROR: invalid index while retrieving"
+              " data from auxiliar test data\n");
+      return -1;
+   }
+
+   return data->testing64 ?
+      ((GLint64*)data->params)[index] :
+      ((GLint*)data->params)[index];
+}
+
+/*
+ * Returns if @target/@internalformat is supported using
+ * INTERNALFORMAT_SUPPORTED for @target and @internalformat.
+ *
+ * @data is only used to known if we are testing the 32-bit or the
+ * 64-bit query, so the content of @data will not be modified due this
+ * call.
+ */
+bool
+test_data_check_supported(const test_data *data,
+                          const GLenum target,
+                          const GLenum internalformat)
+{
+   bool result;
+   test_data *local_data = test_data_new(data->testing64, 1);
+
+   test_data_execute(local_data, target, internalformat,
+                     GL_INTERNALFORMAT_SUPPORTED);
+
+   check_gl_error();
+   result = test_data_value_at_index(local_data, 0) == GL_TRUE;
+
+   test_data_clear(&local_data);
+
+   return result;
+}
+
+/* There are cases where a pname is returning an already know GL enum
+ * instead of a value. */
+static bool
+pname_returns_enum(const GLenum pname)
+{
+   switch (pname) {
+   case GL_NUM_SAMPLE_COUNTS:
+   case GL_SAMPLES:
+   case GL_INTERNALFORMAT_RED_SIZE:
+   case GL_INTERNALFORMAT_GREEN_SIZE:
+   case GL_INTERNALFORMAT_BLUE_SIZE:
+   case GL_INTERNALFORMAT_ALPHA_SIZE:
+   case GL_INTERNALFORMAT_DEPTH_SIZE:
+   case GL_INTERNALFORMAT_STENCIL_SIZE:
+   case GL_INTERNALFORMAT_SHARED_SIZE:
+   case GL_MAX_WIDTH:
+   case GL_MAX_HEIGHT:
+   case GL_MAX_DEPTH:
+   case GL_MAX_LAYERS:
+   case GL_MAX_COMBINED_DIMENSIONS:
+   case GL_IMAGE_TEXEL_SIZE:
+   case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH:
+   case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT:
+   case GL_TEXTURE_COMPRESSED_BLOCK_SIZE:
+      return false;
+   default:
+      return true;
+   }
+}
+
+/* Needed to complement _pname_returns_enum because GL_POINTS/GL_FALSE
+ * and GL_LINES/GL_TRUE has the same value */
+static bool
+pname_returns_gl_boolean(const GLenum pname)
+{
+   switch(pname) {
+   case GL_INTERNALFORMAT_SUPPORTED:
+   case GL_COLOR_COMPONENTS:
+   case GL_DEPTH_COMPONENTS:
+   case GL_STENCIL_COMPONENTS:
+   case GL_COLOR_RENDERABLE:
+   case GL_DEPTH_RENDERABLE:
+   case GL_STENCIL_RENDERABLE:
+   case GL_MIPMAP:
+   case GL_TEXTURE_COMPRESSED:
+      return true;
+   default:
+      return false;
+   }
+}
+
+/* Needed because GL_NONE has the same value that GL_FALSE and GL_POINTS */
+static bool
+pname_can_return_gl_none(const GLenum pname)
+{
+   switch(pname) {
+   case GL_INTERNALFORMAT_PREFERRED:
+   case GL_INTERNALFORMAT_RED_TYPE:
+   case GL_INTERNALFORMAT_GREEN_TYPE:
+   case GL_INTERNALFORMAT_BLUE_TYPE:
+   case GL_INTERNALFORMAT_ALPHA_TYPE:
+   case GL_INTERNALFORMAT_DEPTH_TYPE:
+   case GL_INTERNALFORMAT_STENCIL_TYPE:
+   case GL_FRAMEBUFFER_RENDERABLE:
+   case GL_FRAMEBUFFER_RENDERABLE_LAYERED:
+   case GL_FRAMEBUFFER_BLEND:
+   case GL_READ_PIXELS:
+   case GL_READ_PIXELS_FORMAT:
+   case GL_READ_PIXELS_TYPE:
+   case GL_TEXTURE_IMAGE_FORMAT:
+   case GL_TEXTURE_IMAGE_TYPE:
+   case GL_GET_TEXTURE_IMAGE_FORMAT:
+   case GL_GET_TEXTURE_IMAGE_TYPE:
+   case GL_MANUAL_GENERATE_MIPMAP:
+   case GL_AUTO_GENERATE_MIPMAP:
+   case GL_COLOR_ENCODING:
+   case GL_SRGB_READ:
+   case GL_SRGB_WRITE:
+   case GL_SRGB_DECODE_ARB:
+   case GL_FILTER:
+   case GL_VERTEX_TEXTURE:
+   case GL_TESS_CONTROL_TEXTURE:
+   case GL_TESS_EVALUATION_TEXTURE:
+   case GL_GEOMETRY_TEXTURE:
+   case GL_FRAGMENT_TEXTURE:
+   case GL_COMPUTE_TEXTURE:
+   case GL_TEXTURE_SHADOW:
+   case GL_TEXTURE_GATHER:
+   case GL_TEXTURE_GATHER_SHADOW:
+   case GL_SHADER_IMAGE_LOAD:
+   case GL_SHADER_IMAGE_STORE:
+   case GL_SHADER_IMAGE_ATOMIC:
+   case GL_IMAGE_COMPATIBILITY_CLASS:
+   case GL_IMAGE_PIXEL_FORMAT:
+   case GL_IMAGE_PIXEL_TYPE:
+   case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
+   case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
+   case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST:
+   case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE:
+   case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE:
+   case GL_CLEAR_BUFFER:
+   case GL_TEXTURE_VIEW:
+   case GL_VIEW_COMPATIBILITY_CLASS:
+      return true;
+   default:
+      return false;
+   }
+}
+
+/* wrapper for GL_SAMPLE_COUNTS */
+static GLint64
+get_num_sample_counts(const GLenum target,
+                      const GLenum internalformat)
+{
+   GLint64 result = -1;
+   test_data *local_data = test_data_new(0, 1);
+
+   test_data_execute(local_data, target, internalformat,
+                     GL_NUM_SAMPLE_COUNTS);
+
+   if (check_gl_error())
+      result = -1;
+   else
+      result = test_data_value_at_index(local_data, 0);
+
+   test_data_clear(&local_data);
+
+   return result;
+}
+
+static const char*
+get_value_enum_name(const GLenum pname,
+                    const GLint64 value)
+{
+   if (pname_returns_gl_boolean(pname))
+      return value ? "GL_TRUE" : "GL_FALSE";
+   else if (pname_can_return_gl_none(pname) && value == 0)
+      return "GL_NONE";
+   else
+      return util_get_gl_enum_name(value);
+}
+/*
+ * Returns the number of values that a given pname returns. For
+ * example, for the case of GL_SAMPLES, it returns as many sample
+ * counts as the valure returned by GL_SAMPLE_COUNTS
+ */
+static unsigned
+pname_value_count(const GLenum pname,
+                  const GLenum target,
+                  const GLenum internalformat)
+{
+   switch (pname) {
+   case GL_SAMPLES:
+      return get_num_sample_counts(target, internalformat);
+   default:
+      return 1;
+   }
+}
+
+/*
+ * Prints the info of a case for a given pname, in a csv format. In order to
+ * get that the value is included on "", as some queries returns more than one
+ * value (ex: GL_SAMPLES).
+ * @target, @internalformat, @pname are the parameters othe the given query.
+ * @data contains the outcome of the query already being executed, so the given value.
+ *
+ */
+void
+print_case(const GLenum target,
+           const GLenum internalformat,
+           const GLenum pname,
+           const test_data *data)
+{
+   fprintf(stdout, "%s, %s, %s, %s, ",
+           data->testing64 ? "64 bit" : "32 bit",
+           util_get_gl_enum_name(pname),
+           util_get_gl_enum_name(target),
+           util_get_gl_enum_name(internalformat));
+
+   if (pname_returns_enum(pname)) {
+      fprintf(stdout, "\"%s\"\n",
+              get_value_enum_name(pname, test_data_value_at_index(data, 0)));
+   } else {
+      int count = pname_value_count(pname, target, internalformat);
+      int i = 0;
+
+      fprintf(stdout, "\"");
+      for (i = 0; i < count - 1; i++) {
+         fprintf(stdout, "%" PRIi64 ",", test_data_value_at_index(data, i));
+      }
+      fprintf(stdout, "%" PRIi64 "\"\n", test_data_value_at_index(data, i));
+   }
+}
+
+
+/*
+ * Checks for OpenGL error if one ocurred, and prints it. Retuns true if any
+ * error found;
+ */
+bool
+check_ogl_error (char *file,
+                 int line)
+{
+   GLenum gl_err;
+   bool result = false;
+
+   gl_err = glGetError();
+   while (gl_err != GL_NO_ERROR) {
+      result = true;
+      fprintf(stderr,"gl_error in file %s @ line %d: %s\n",
+              file, line, gluErrorString(gl_err));
+
+      gl_err = glGetError();
+   }
+
+   return result;
+}
diff --git a/src/query2-info/util.h b/src/query2-info/util.h
new file mode 100644
index 0000000..eee0e99
--- /dev/null
+++ b/src/query2-info/util.h
@@ -0,0 +1,263 @@
+/*
+ * Copyright © 2016 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 <GL/glew.h>
+#include <stdbool.h>
+
+static const GLenum valid_targets[] = {
+   GL_TEXTURE_1D,
+   GL_TEXTURE_1D_ARRAY,
+   GL_TEXTURE_2D,
+   GL_TEXTURE_2D_ARRAY,
+   GL_TEXTURE_3D,
+   GL_TEXTURE_CUBE_MAP,
+   GL_TEXTURE_CUBE_MAP_ARRAY,
+   GL_TEXTURE_RECTANGLE,
+   GL_TEXTURE_BUFFER,
+   GL_RENDERBUFFER,
+   GL_TEXTURE_2D_MULTISAMPLE,
+   GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
+};
+
+static const GLenum valid_pnames[] = {
+   GL_SAMPLES,
+   GL_NUM_SAMPLE_COUNTS,
+   GL_INTERNALFORMAT_SUPPORTED,
+   GL_INTERNALFORMAT_PREFERRED,
+   GL_INTERNALFORMAT_RED_SIZE,
+   GL_INTERNALFORMAT_GREEN_SIZE,
+   GL_INTERNALFORMAT_BLUE_SIZE,
+   GL_INTERNALFORMAT_ALPHA_SIZE,
+   GL_INTERNALFORMAT_DEPTH_SIZE,
+   GL_INTERNALFORMAT_STENCIL_SIZE,
+   GL_INTERNALFORMAT_SHARED_SIZE,
+   GL_INTERNALFORMAT_RED_TYPE,
+   GL_INTERNALFORMAT_GREEN_TYPE,
+   GL_INTERNALFORMAT_BLUE_TYPE,
+   GL_INTERNALFORMAT_ALPHA_TYPE,
+   GL_INTERNALFORMAT_DEPTH_TYPE,
+   GL_INTERNALFORMAT_STENCIL_TYPE,
+   GL_MAX_WIDTH,
+   GL_MAX_HEIGHT,
+   GL_MAX_DEPTH,
+   GL_MAX_LAYERS,
+   GL_MAX_COMBINED_DIMENSIONS,
+   GL_COLOR_COMPONENTS,
+   GL_DEPTH_COMPONENTS,
+   GL_STENCIL_COMPONENTS,
+   GL_COLOR_RENDERABLE,
+   GL_DEPTH_RENDERABLE,
+   GL_STENCIL_RENDERABLE,
+   GL_FRAMEBUFFER_RENDERABLE,
+   GL_FRAMEBUFFER_RENDERABLE_LAYERED,
+   GL_FRAMEBUFFER_BLEND,
+   GL_READ_PIXELS,
+   GL_READ_PIXELS_FORMAT,
+   GL_READ_PIXELS_TYPE,
+   GL_TEXTURE_IMAGE_FORMAT,
+   GL_TEXTURE_IMAGE_TYPE,
+   GL_GET_TEXTURE_IMAGE_FORMAT,
+   GL_GET_TEXTURE_IMAGE_TYPE,
+   GL_MIPMAP,
+   GL_MANUAL_GENERATE_MIPMAP,
+   GL_AUTO_GENERATE_MIPMAP,
+   GL_COLOR_ENCODING,
+   GL_SRGB_READ,
+   GL_SRGB_WRITE,
+   GL_SRGB_DECODE_ARB,
+   GL_FILTER,
+   GL_VERTEX_TEXTURE,
+   GL_TESS_CONTROL_TEXTURE,
+   GL_TESS_EVALUATION_TEXTURE,
+   GL_GEOMETRY_TEXTURE,
+   GL_FRAGMENT_TEXTURE,
+   GL_COMPUTE_TEXTURE,
+   GL_TEXTURE_SHADOW,
+   GL_TEXTURE_GATHER,
+   GL_TEXTURE_GATHER_SHADOW,
+   GL_SHADER_IMAGE_LOAD,
+   GL_SHADER_IMAGE_STORE,
+   GL_SHADER_IMAGE_ATOMIC,
+   GL_IMAGE_TEXEL_SIZE,
+   GL_IMAGE_COMPATIBILITY_CLASS,
+   GL_IMAGE_PIXEL_FORMAT,
+   GL_IMAGE_PIXEL_TYPE,
+   GL_IMAGE_FORMAT_COMPATIBILITY_TYPE,
+   GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST,
+   GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST,
+   GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE,
+   GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE,
+   GL_TEXTURE_COMPRESSED,
+   GL_TEXTURE_COMPRESSED_BLOCK_WIDTH,
+   GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT,
+   GL_TEXTURE_COMPRESSED_BLOCK_SIZE,
+   GL_CLEAR_BUFFER,
+   GL_TEXTURE_VIEW,
+   GL_VIEW_COMPATIBILITY_CLASS
+};
+
+/* From spec:
+ *
+ *  "INTERNALFORMAT_SUPPORTED:
+ *  <skip>
+ *
+ * <internalformats> that must be supported (in GL 4.2 or later)
+ *   include the following:
+ *    - "sized internal formats" from Table 3.12, 3.13, and 3.15,
+ *    - any specific "compressed internal format" from Table 3.14,
+ *    - any "image unit format" from Table 3.21.
+ *    - any generic "compressed internal format" from Table 3.14, if
+ *      the implementation accepts it for any texture specification
+ *      commands, and
+ *    - unsized or base internal format, if the implementation accepts
+ *      it for texture or image specification."
+ */
+static const GLenum valid_internalformats[] = {
+   /* Base/unsized internal format (from Table 3.11) */
+   GL_DEPTH_COMPONENT,
+   GL_DEPTH_STENCIL,
+   GL_RED,
+   GL_RG,
+   GL_RGB,
+   GL_RGBA,
+   /* Table 3.12 (Table 3.15 and 3.21 included here) */
+   GL_R8,
+   GL_R8_SNORM,
+   GL_R16,
+   GL_R16_SNORM,
+   GL_RG8,
+   GL_RG8_SNORM,
+   GL_RG16,
+   GL_RG16_SNORM,
+   GL_R3_G3_B2,
+   GL_RGB4,
+   GL_RGB5,
+   GL_RGB8,
+   GL_RGB8_SNORM,
+   GL_RGB10,
+   GL_RGB12,
+   GL_RGB16,
+   GL_RGB16_SNORM,
+   GL_RGBA2,
+   GL_RGBA4,
+   GL_RGB5_A1,
+   GL_RGBA8,
+   GL_RGBA8_SNORM,
+   GL_RGB10_A2,
+   GL_RGB10_A2UI,
+   GL_RGBA12,
+   GL_RGBA16,
+   GL_RGBA16_SNORM,
+   GL_SRGB8,
+   GL_SRGB8_ALPHA8,
+   GL_R16F,
+   GL_RG16F,
+   GL_RGB16F,
+   GL_RGBA16F,
+   GL_R32F,
+   GL_RG32F,
+   GL_RGB32F,
+   GL_RGBA32F,
+   GL_R11F_G11F_B10F,
+   GL_RGB9_E5,
+   GL_R8I,
+   GL_R8UI,
+   GL_R16I,
+   GL_R16UI,
+   GL_R32I,
+   GL_R32UI,
+   GL_RG8I,
+   GL_RG16I,
+   GL_RG16UI,
+   GL_RG32I,
+   GL_RG32UI,
+   GL_RGB8I,
+   GL_RGB8UI,
+   GL_RGB16I,
+   GL_RGB16UI,
+   GL_RGB32I,
+   GL_RGB32UI,
+   GL_RGBA8I,
+   GL_RGBA8UI,
+   GL_RGBA16I,
+   GL_RGBA16UI,
+   GL_RGBA32I,
+   GL_RGBA32UI,
+   /* Table 3.13 */
+   GL_DEPTH_COMPONENT16,
+   GL_DEPTH_COMPONENT24,
+   GL_DEPTH_COMPONENT32,
+   GL_DEPTH_COMPONENT32F,
+   GL_DEPTH24_STENCIL8,
+   GL_DEPTH32F_STENCIL8,
+   /* Table 3.14 (both specific and generic) */
+   GL_COMPRESSED_RED,
+   GL_COMPRESSED_RG,
+   GL_COMPRESSED_RGB,
+   GL_COMPRESSED_RGBA,
+   GL_COMPRESSED_SRGB,
+   GL_COMPRESSED_SRGB_ALPHA,
+   GL_COMPRESSED_RED_RGTC1,
+   GL_COMPRESSED_SIGNED_RED_RGTC1,
+   GL_COMPRESSED_RG_RGTC2,
+   GL_COMPRESSED_SIGNED_RG_RGTC2,
+   GL_COMPRESSED_RGBA_BPTC_UNORM,
+   GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM,
+   GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT,
+   GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,
+};
+
+#define check_gl_error() check_ogl_error(__FILE__, __LINE__)
+bool check_ogl_error(char *file,
+                     int line);
+
+typedef struct _test_data test_data;
+
+test_data* test_data_new(int testing64,
+                         int params_size);
+
+void test_data_clear(test_data **data);
+
+void test_data_execute(test_data *data,
+                       const GLenum target,
+                       const GLenum internalformat,
+                       const GLenum pname);
+
+void test_data_set_testing64(test_data *data,
+                             const int testing64);
+
+GLint64 test_data_value_at_index(const test_data *data,
+                                 const int index);
+
+void test_data_set_value_at_index(test_data *data,
+                                  const int index,
+                                  const GLint64 value);
+
+bool test_data_check_supported(const test_data *data,
+                               const GLenum target,
+                               const GLenum internalformat);
+
+void print_case(const GLenum target,
+                const GLenum internalformat,
+                const GLenum pname,
+                const test_data *data);
+
-- 
2.7.4



More information about the mesa-dev mailing list