v2: Rebase to master, make it work on core contexts, and add a few
    formats I'd missed when writing the table originally.
---
 tests/all.tests                                    |  3 +-
 tests/spec/gl-3.0/required-sized-texture-formats.c | 57 ++++++++++----
 tests/util/sized-internalformats.c                 | 87 ++++++++++++++++++++++
 tests/util/sized-internalformats.h                 | 14 ++++
 4 files changed, 146 insertions(+), 15 deletions(-)

diff --git a/tests/all.tests b/tests/all.tests
index 5643919..8e452a7 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -696,7 +696,7 @@ add_concurrent_test(gl30, 'genmipmap-errors')
 add_concurrent_test(gl30, 'getfragdatalocation')
 add_concurrent_test(gl30, 'integer-errors')
 gl30['minmax'] = concurrent_test('gl-3.0-minmax')
-add_concurrent_test(gl30, 'gl-3.0-required-sized-texture-formats')
+gl30['required-sized-texture-formats'] = 
concurrent_test('gl-3.0-required-sized-texture-formats 30')
 add_concurrent_test(gl30, 'gl-3.0-required-renderbuffer-attachment-formats')
 add_concurrent_test(gl30, 'gl-3.0-required-texture-attachment-formats')
 add_concurrent_test(gl30, 'gl-3.0-texture-integer')
@@ -712,6 +712,7 @@ gl31['minmax'] = concurrent_test('gl-3.1-minmax')
 for subtest in ['generated', 'written', 'flush']:
         cmdline = 'primitive-restart-xfb {0}'.format(subtest)
         gl31[cmdline] = concurrent_test('gl-3.1-' + cmdline)
+gl31['required-sized-texture-formats'] = 
concurrent_test('gl-3.0-required-sized-texture-formats 31')
 
 # Group spec/glsl-es-1.00
 spec['glsl-es-1.00'] = Group()
diff --git a/tests/spec/gl-3.0/required-sized-texture-formats.c 
b/tests/spec/gl-3.0/required-sized-texture-formats.c
index 9ec5954..a3524e7 100644
--- a/tests/spec/gl-3.0/required-sized-texture-formats.c
+++ b/tests/spec/gl-3.0/required-sized-texture-formats.c
@@ -35,18 +35,19 @@
  *      internal formats for any texture type will allocate exactly
  *      the internal component sizes and types shown for that format
  *      in tables 3.16- 3.17:"
+ *
+ * In GL 3.1 this is changed to allow increased precision for the
+ * required sized formats.  From page 118 of the GL 3.1 core spec PDF
+ * (20090528):
+ *
+ *     "In addition, implementations are required to support the
+ *      following sized and compressed internal formats. Requesting
+ *      one of these sized internal formats for any texture type will
+ *      allocate at least the internal component sizes, and exactly
+ *      the component types shown for that format in tables 3.12-
+ *      3.13: "
  */
 
-PIGLIT_GL_TEST_CONFIG_BEGIN
-
-       config.supports_gl_compat_version = 10;
-
-       config.window_width = 32;
-       config.window_height = 32;
-       config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
-
-PIGLIT_GL_TEST_CONFIG_END
-
 GLenum type_queries[CHANNELS] = {
        GL_TEXTURE_RED_TYPE,
        GL_TEXTURE_GREEN_TYPE,
@@ -69,6 +70,8 @@ GLenum size_queries[CHANNELS] = {
        GL_TEXTURE_STENCIL_SIZE,
 };
 
+static int target_version;
+
 enum piglit_result
 piglit_display(void)
 {
@@ -83,7 +86,7 @@ piglit_init(int argc, char **argv)
        GLuint tex;
        int i, c;
 
-       piglit_require_gl_version(30);
+       piglit_require_gl_version(target_version);
 
        glGenTextures(1, &tex);
        glBindTexture(GL_TEXTURE_2D, tex);
@@ -95,11 +98,16 @@ piglit_init(int argc, char **argv)
                GLenum format, type;
                const struct sized_internalformat *f;
 
-               /* FINISHME: Add support for future GL versions. */
-               if (required_formats[i].version != 30)
+               if (!valid_for_gl_version(&required_formats[i], target_version))
                        continue;
 
                f = get_sized_internalformat(required_formats[i].token);
+               if (!f) {
+                       printf("Failed to get sized format for %s\n",
+                              
piglit_get_gl_enum_name(required_formats[i].token));
+                       pass = false;
+                       continue;
+               }
 
                if (f->token == GL_DEPTH24_STENCIL8 ||
                    f->token == GL_DEPTH32F_STENCIL8) {
@@ -184,10 +192,14 @@ piglit_init(int argc, char **argv)
                            f->bits[c] == UCMP) {
                                if (sizes[c] <= 0 || sizes[c] > 8)
                                        format_pass = false;
-                       } else {
+                       } else if (target_version == 30) {
                                if (sizes[c] != get_channel_size(f, c)) {
                                        format_pass = false;
                                }
+                       } else {
+                               if (sizes[c] < get_channel_size(f, c)) {
+                                       format_pass = false;
+                               }
                        }
 
                        if (types[c] != get_channel_type(f, c))
@@ -221,3 +233,20 @@ piglit_init(int argc, char **argv)
 
        piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
 }
+
+int
+main(int argc, char *argv[])
+{
+       struct piglit_gl_test_config config;
+
+       setup_required_size_test(argc, argv, &config);
+       target_version = MAX2(config.supports_gl_compat_version,
+                             config.supports_gl_core_version);
+       config.init = piglit_init;
+       config.display = piglit_display;
+
+       piglit_gl_test_run(argc, argv, &config);
+
+       /* UNREACHED */
+       return 0;
+}
diff --git a/tests/util/sized-internalformats.c 
b/tests/util/sized-internalformats.c
index 406aee4..1017832 100644
--- a/tests/util/sized-internalformats.c
+++ b/tests/util/sized-internalformats.c
@@ -41,6 +41,7 @@ static const struct {
        { 24, GL_UNSIGNED_NORMALIZED },
 
        { 16, GL_UNSIGNED_NORMALIZED },
+       { 16, GL_SIGNED_NORMALIZED },
        { 16, GL_FLOAT },
        { 16, GL_INT },
        { 16, GL_UNSIGNED_INT },
@@ -130,6 +131,19 @@ const struct sized_internalformat sized_internalformats[] 
= {
        FORMAT(GL_RGBA32I, I32, I32, I32, I32, NONE, NONE, NONE, NONE),
        FORMAT(GL_RGBA32UI, U32, U32, U32, U32, NONE, NONE, NONE, NONE),
 
+       /* SNORM formats introduced as required sized texture formats
+        * in GL 3.1, but didn't get sizes actually specified until GL
+        * 3.2's table 3.12.
+        */
+       FORMAT(GL_R8_SNORM, SN8, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+       FORMAT(GL_R16_SNORM, SN16, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+       FORMAT(GL_RG8_SNORM, SN8, SN8, NONE, NONE, NONE, NONE, NONE, NONE),
+       FORMAT(GL_RG16_SNORM, SN16, SN16, NONE, NONE, NONE, NONE, NONE, NONE),
+       FORMAT(GL_RGB8_SNORM, SN8, SN8, SN8, NONE, NONE, NONE, NONE, NONE),
+       FORMAT(GL_RGB16_SNORM, SN16, SN16, SN16, NONE, NONE, NONE, NONE, NONE),
+       FORMAT(GL_RGBA8_SNORM, SN8, SN8, SN8, SN8, NONE, NONE, NONE, NONE),
+       FORMAT(GL_RGBA16_SNORM, SN16, SN16, SN16, SN16, NONE, NONE, NONE, NONE),
+
        /* Sized internal luminance formats, table 3.17 of the GL 3.0
         * specification.
         */
@@ -225,6 +239,7 @@ const struct required_format required_formats[] = {
        /* Required color formats (texture-only): */
 
        { GL_RGBA16_SNORM, 31, false },
+       { GL_RGBA8_SNORM, 31, false },
        { GL_RGB32F, 30, false },
        { GL_RGB32I, 30, false },
        { GL_RGB32UI, 30, false },
@@ -244,11 +259,13 @@ const struct required_format required_formats[] = {
        { GL_RGB9_E5, 30, false },
 
        { GL_RG16_SNORM, 31, false },
+       { GL_RG8_SNORM, 31, false },
 
        { GL_COMPRESSED_RG_RGTC2, 30, false },
        { GL_COMPRESSED_SIGNED_RG_RGTC2, 30, false },
 
        { GL_R16_SNORM, 31, false },
+       { GL_R8_SNORM, 31, false },
 
        { GL_COMPRESSED_RED_RGTC1, 30, false },
        { GL_COMPRESSED_SIGNED_RED_RGTC1, 30, false },
@@ -313,3 +330,73 @@ print_bits(int size, GLenum type)
        else
                printf("??");
 }
+
+static bool
+string_starts_with(const char *string, const char *start)
+{
+       return !strncmp(string, start, strlen(start));
+}
+
+bool
+valid_for_gl_version(const struct required_format *format, int target_version)
+{
+       if (format->version > target_version)
+               return false;
+
+       /* Since we have a core context for 3.1, don't test
+        * deprecated formats there.
+        */
+       if (piglit_get_gl_version() >= 31 &&
+           !piglit_is_extension_supported("GL_ARB_compatibility")) {
+               const char *name = piglit_get_gl_enum_name(format->token);
+               if (string_starts_with(name, "GL_ALPHA") ||
+                   string_starts_with(name, "GL_LUMINANCE_ALPHA") ||
+                   string_starts_with(name, "GL_LUMINANCE") ||
+                   string_starts_with(name, "GL_INTENSITY")) {
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+static void
+usage(const char *name)
+{
+       fprintf(stderr, "usage: %s <30 | 31>\n", name);
+       piglit_report_result(PIGLIT_FAIL);
+}
+
+/**
+ * Sets up the test config for the 3 required size tests across GL
+ * compat/core versions.
+ */
+void
+setup_required_size_test(int argc, char **argv,
+                        struct piglit_gl_test_config *config)
+{
+       int target_version;
+
+       if (argc < 2)
+               usage(argv[0]);
+
+       piglit_gl_test_config_init(config);
+
+       target_version = strtol(argv[1], NULL, 0);
+
+       switch (target_version) {
+       case 30:
+               config->supports_gl_compat_version = 30;
+               break;
+       case 31:
+               config->supports_gl_core_version = target_version;
+               break;
+       default:
+               usage(argv[0]);
+       }
+
+       config->window_width = 32;
+       config->window_height = 32;
+       config->window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+}
diff --git a/tests/util/sized-internalformats.h 
b/tests/util/sized-internalformats.h
index e01c2f3..5271f14 100644
--- a/tests/util/sized-internalformats.h
+++ b/tests/util/sized-internalformats.h
@@ -36,6 +36,7 @@ enum bits_types {
        UN24,
 
        UN16,
+       SN16,
        F16,
        I16,
        U16,
@@ -104,3 +105,16 @@ get_channel_type(const struct sized_internalformat *f, 
enum channel c);
 
 void
 print_bits(int size, GLenum type);
+
+bool
+valid_for_gl_version(const struct required_format *format, int target_version);
+
+void
+piglit_init(int argc, char **argv);
+
+enum piglit_result
+piglit_display(void);
+
+void
+setup_required_size_test(int argc, char **argv,
+                        struct piglit_gl_test_config *config);
-- 
1.8.3.rc0

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to