From: Ian Romanick <[email protected]>

Signed-off-by: Ian Romanick <[email protected]>
---
 tests/shaders/built-in-constants.c | 90 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 89 insertions(+), 1 deletion(-)

diff --git a/tests/shaders/built-in-constants.c 
b/tests/shaders/built-in-constants.c
index 9e5b940..fb955ae 100644
--- a/tests/shaders/built-in-constants.c
+++ b/tests/shaders/built-in-constants.c
@@ -39,6 +39,15 @@ unsigned num_tests = 0;
 int required_glsl_version = 0;
 char *required_glsl_version_string = NULL;
 
+/**
+ * NUL separated list of extensions required for the current test set.
+ *
+ * The list is terminated by two consecutive NUL characters.
+ * \c required_extensions_length is the total size of \c required_extensions
+ * that has been consumed \b not \b including the NUL characters at the end.
+ */
+char required_extensions[500] = { '\0', '\0' };
+unsigned required_extensions_length = 0;
 
 static const char *const uniform_template =
        "uniform float f[%s %s %d ? 1 : -1];\n"
@@ -148,6 +157,7 @@ parse_file(const char *filename)
        /* The format of the test file is:
         *
         * major.minor
+        * GL_ARB_some_extension
         * gl_MaxFoo 8
         * gl_MaxBar 16
         * gl_MinAsdf -2
@@ -169,6 +179,42 @@ parse_file(const char *filename)
        if (line[0] != '\0')
                line++;
 
+       /* Process the list of required extensions.
+        */
+       while (strncmp("GL_", line, 3) == 0) {
+               char *end_of_line = strchrnul(line, '\n');
+               const ptrdiff_t len = end_of_line - line;
+
+               assert(end_of_line[0] == '\n' || end_of_line[0] == '\0');
+
+               if ((required_extensions_length + len + 2)
+                   > sizeof(required_extensions)) {
+                       fprintf(stderr, "Too many required extensions!\n");
+                       piglit_report_result(PIGLIT_FAIL);
+               }
+
+               /* Copy the new extension to the list.
+                */
+               memcpy(&required_extensions[required_extensions_length],
+                      line,
+                      len);
+
+               /* Advance the count.
+                */
+               required_extensions_length += len;
+
+               /* Terminate the list.
+                */
+               required_extensions[required_extensions_length] = '\0';
+               required_extensions[required_extensions_length + 1] = '\0';
+
+               /* Advance to the next input line.
+                */
+               line = end_of_line;
+               if (line[0] == '\n')
+                       line++;
+       }
+
        while (line[0] != '\0') {
                char *endptr;
 
@@ -271,21 +317,63 @@ piglit_init(int argc, char **argv)
        int minor;
        int glsl_version;
 
+       const char *ext;
+       static const char newline[] = "\n";
+       char *extension_enables = (char *) newline;
+
        piglit_get_glsl_version(&is_es, &major, &minor);
        glsl_version = major * 100 + minor;
        if (glsl_version < required_glsl_version)
                piglit_report_result(PIGLIT_SKIP);
 
+       /* Process the list of required extensions.  While doing this,
+        * generate the GLSL code that will enable those extensions in the
+        * shaders.
+        */
+       for (ext = required_extensions; ext[0] != '\0'; ext += strlen(ext) + 1) 
{
+               int result;
+               char *ptr;
+
+               if (!piglit_is_extension_supported(ext)) {
+                       printf("%s not supported\n", ext);
+                       piglit_report_result(PIGLIT_SKIP);
+               }
+
+               result = asprintf(&ptr, "%s#extension %s: require\n",
+                                 extension_enables, ext);
+               if (result < 0) {
+                       fprintf(stderr, "asprintf error\n");
+                       piglit_report_result(PIGLIT_FAIL);
+               }
+
+               /* Don't free a string that didn't come from asprintf, and
+                * don't leak the previous asprintf data when over-writing
+                * with the new asprintf data. :)
+                */
+               if (extension_enables != newline)
+                       free(extension_enables);
+
+               extension_enables = ptr;
+       }
+
        /* Generate the version declaration that will be used by all of the
         * shaders in the test run.
         */
        asprintf(&version_string,
                 "#version %d %s\n"
+                "%s"
                 "#ifdef GL_ES\n"
                 "precision mediump float;\n"
                 "#endif\n",
                 required_glsl_version,
-                required_glsl_version == 300 ? "es" : "");
+                required_glsl_version == 300 ? "es" : "",
+                extension_enables);
+
+       /* Don't free a string that didn't come from asprintf, and don't leak
+        * the string that did come from asprintf. :)
+        */
+       if (extension_enables != newline)
+               free(extension_enables);
 
        /* Create the shaders that will be used for the real part of the test.
         */
-- 
1.8.1.4

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

Reply via email to