From: Andrii Simiklit <andrii.simik...@globallogic.com>

Test that usage of upside down miptree doesn't cause assertion

The miptree:

level 0 = 1x1
level 1 = 2x2
level 2 = 4x4
...
level n = NxN

should be acceptable for case when we don't use a min filter.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107987
Signed-off-by: Andrii Simiklit <andrii.simik...@globallogic.com>
---
 tests/opengl.py                           |   1 +
 tests/texturing/CMakeLists.gl.txt         |   1 +
 tests/texturing/tex-upside-down-miptree.c | 171 ++++++++++++++++++++++
 3 files changed, 173 insertions(+)
 create mode 100644 tests/texturing/tex-upside-down-miptree.c

diff --git a/tests/opengl.py b/tests/opengl.py
index f7e408cd5..f6a38e40e 100644
--- a/tests/opengl.py
+++ b/tests/opengl.py
@@ -704,6 +704,7 @@ with profile.test_list.group_manager(
     g(['getteximage-targets', '1D'])
     g(['getteximage-targets', '2D'])
     g(['teximage-scale-bias'])
+    g(['tex-upside-down-miptree'])
     add_msaa_visual_plain_tests(g, ['draw-pixels'])
     add_msaa_visual_plain_tests(g, ['read-front'], run_concurrent=False)
     add_msaa_visual_plain_tests(g, ['read-front', 'clear-front-first'],
diff --git a/tests/texturing/CMakeLists.gl.txt 
b/tests/texturing/CMakeLists.gl.txt
index e5d41e432..02b572c79 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -98,5 +98,6 @@ piglit_add_executable (texture-al texture-al.c)
 piglit_add_executable (texture-rg texture-rg.c)
 piglit_add_executable (teximage-colors teximage-colors.c)
 piglit_add_executable (zero-tex-coord zero-tex-coord.c)
+piglit_add_executable (tex-upside-down-miptree tex-upside-down-miptree.c)
 
 # vim: ft=cmake:
diff --git a/tests/texturing/tex-upside-down-miptree.c 
b/tests/texturing/tex-upside-down-miptree.c
new file mode 100644
index 000000000..2d10fb49a
--- /dev/null
+++ b/tests/texturing/tex-upside-down-miptree.c
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2018 Andrii Simiklit
+ *
+ * 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.
+ *
+ * Authors:
+ *    Andrii Simiklit <asimiklit.w...@gmail.com>
+ *
+ */
+
+/**
+ * Test what there no an assertion when we use upside down miptree and
+ * GL_TEXTURE_MIN_FILTER is GL_LINEAR, base level is not 0
+ * Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107987
+ */
+
+#include "piglit-util-gl.h"
+#define TW 64
+#define TH 64
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+       config.supports_gl_compat_version = 10;
+
+       config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+       config.khr_no_error_support = PIGLIT_NO_ERRORS;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static unsigned nlevels = 0;
+
+static void
+get_rect_bounds(int pos, int *x, int *y, int *w, int *h)
+{
+       *x = pos * (piglit_width / 3) + 5;
+       *y = 5;
+       *w = piglit_width / 3 - 10;
+       *h = piglit_height - 10;
+}
+
+
+static void
+draw_rect(int pos)
+{
+       int x, y, w, h;
+       get_rect_bounds(pos, &x, &y, &w, &h);
+       piglit_draw_rect_tex(x, y, w, h, 0, 0, 1, 1);
+}
+
+
+static GLboolean
+probe_pos(int pos, const GLfloat expected[4])
+{
+       int x, y, w, h;
+       get_rect_bounds(pos, &x, &y, &w, &h);
+       return piglit_probe_rect_rgba(x, y, w, h, expected);
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+       GLboolean pass = GL_TRUE;
+       unsigned level;
+       static const char *fragShaderText =
+               "uniform sampler2D tex;\n"
+               "void main()\n"
+               "{\n"
+               "   gl_FragColor = texture2D(tex, gl_TexCoord[0].xy).rgba;\n"
+               "}\n";
+       const GLfloat oneby255 = (1.0 / 255.0);
+       const GLfloat expected[4] = { oneby255 * 255.0,
+                                                                               
        oneby255 * 128.0,
+                                                                               
        oneby255 * 64.0,
+                                                                               
        oneby255 * 32.0 };
+       GLint tex;
+       int pos = 0;
+       GLuint prog;
+
+       piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+       piglit_require_GLSL_version(110);
+       prog = piglit_build_simple_program(NULL, fragShaderText);
+       glUseProgram(prog);
+       tex = glGetUniformLocation(prog, "tex");
+       glUniform1i(tex, 0);
+
+       for(level = 1; level < nlevels && pass; ++level)
+       {
+               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
+               glClear(GL_COLOR_BUFFER_BIT);
+               /* If we the draw_rect function doesn't cause crash/assertion
+               * it means everything is okay and test will be marked
+               * as pass
+               */
+               draw_rect(pos);
+               /** Just in case we check it
+                */
+               pass = pass && probe_pos(pos, expected);
+       }
+
+       glUseProgram(0);
+       glDeleteProgram(prog);
+       piglit_present_results();
+
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+static void
+setup_texture(void)
+{
+       GLuint t;
+       GLubyte img[TH][TW][4];
+       int i, j, w, h;
+
+       for (i = 0; i < TH; i++) {
+               for (j = 0; j < TW; j++) {
+                       img[i][j][0] = 255;
+                       img[i][j][1] = 128;
+                       img[i][j][2] = 64;
+                       img[i][j][3] = 32;
+               }
+       }
+
+       /* make an abnormal upside down miptree
+        */
+       glGenTextures(1, &t);
+       glBindTexture(GL_TEXTURE_2D, t);
+       w = TW;
+       h = TH;
+       for (nlevels = 0; w > 0 && h > 0; nlevels++) {
+               w /= 2;
+               h /= 2;
+       }
+       w = TW;
+       h = TH;
+       for (i = 0; w > 0 && h > 0; i++) {
+               glTexImage2D(GL_TEXTURE_2D, nlevels - 1 - i, GL_RGBA, w, h, 0,
+                               GL_RGBA, GL_UNSIGNED_BYTE, img);
+               w /= 2;
+               h /= 2;
+       }
+
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+       glClearColor(0.5, 0.5, 0.5, 0.0);
+       piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+       setup_texture();
+}
-- 
2.17.1

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

Reply via email to