[Piglit] [PATCH v3] miptree: test ability to use upside down miptree

asimiklit.work at gmail.com asimiklit.work at gmail.com
Wed Dec 12 11:11:25 UTC 2018


From: Andrii Simiklit <andrii.simiklit at 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.

v2: - Unnecessary function calls were removed
    - The 'glClearColor' call was moved to 'piglit_display' function
    - The program creation was moved to 'piglit_init' function
    - The requirements check was moved to 'piglit_init' function
               ( Erik Faye-Lund <erik.faye-lund at collabora.com> )

    - Fixed a leak of texture which is created in 'setup_texture'

v3: - Defined a constant for the test color instead of a hardcoded variant
    - Removed unused variable 'pos' which is always was 0
    - Implemented more effective number of levels calculator
    - Removed a stop when one of tests fails
    - Fixed two style issues
               ( Emil Velikov <emil.l.velikov at gmail.com> )

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107987
Signed-off-by: Andrii Simiklit <andrii.simiklit at globallogic.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
---
 tests/opengl.py                           |   1 +
 tests/texturing/CMakeLists.gl.txt         |   1 +
 tests/texturing/tex-upside-down-miptree.c | 162 ++++++++++++++++++++++
 3 files changed, 164 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..c70fc8058
--- /dev/null
+++ b/tests/texturing/tex-upside-down-miptree.c
@@ -0,0 +1,162 @@
+/*
+ * 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.work at 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"
+#include <math.h>
+
+#define TW 64
+#define TH 64
+#define MINIMUM(X, Y)  ((X) < (Y) ? (X) : (Y))
+#define LEVELS (log2(MINIMUM(TW,TH)) + 1)
+
+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
+
+GLuint prog = 0;
+GLuint texture = 0;
+static const GLubyte fancy_pixel[4] = { 255, 128, 64, 32 };
+static const char *fragShaderText =
+	"uniform sampler2D tex;\n"
+	"void main()\n"
+	"{\n"
+	"   gl_FragColor = texture2D(tex, gl_TexCoord[0].xy).rgba;\n"
+	"}\n";
+
+static void
+get_rect_bounds(int *x, int *y, int *w, int *h)
+{
+	*x = 5;
+	*y = 5;
+	*w = piglit_width / 3 - 10;
+	*h = piglit_height - 10;
+}
+
+
+static void
+draw_rect()
+{
+	int x, y, w, h;
+	get_rect_bounds(&x, &y, &w, &h);
+	piglit_draw_rect_tex(x, y, w, h, 0, 0, 1, 1);
+}
+
+
+static GLboolean
+probe_pos(const GLfloat expected[4])
+{
+	int x, y, w, h;
+	get_rect_bounds(&x, &y, &w, &h);
+	return piglit_probe_rect_rgba(x, y, w, h, expected);
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+	GLint tex;
+	GLboolean pass = GL_TRUE;
+	unsigned level;
+	const GLfloat oneby255 = (1.0 / 255.0);
+	const GLfloat expected[4] = { oneby255 * fancy_pixel[0],
+											oneby255 * fancy_pixel[1],
+											oneby255 * fancy_pixel[2],
+											oneby255 * fancy_pixel[3] };
+
+	glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+	glUseProgram(prog);
+	tex = glGetUniformLocation(prog, "tex");
+	glUniform1i(tex, 0);
+
+	for(level = 1; level < LEVELS; 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();
+		/** Just in case we check it
+		 */
+		pass = probe_pos(expected) && pass;
+	}
+
+	glUseProgram(0);
+	glDeleteProgram(prog);
+	glDeleteTextures(1, &texture);
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+static void
+setup_texture(void)
+{
+	GLubyte img[TH][TW][4];
+	int i, j, w, h;
+
+	for (i = 0; i < TH; i++)
+		for (j = 0; j < TW; j++)
+			memcpy(&img[i][j], fancy_pixel, sizeof(fancy_pixel));
+
+	/* make an abnormal upside down miptree
+	 */
+	glGenTextures(1, &texture);
+	glBindTexture(GL_TEXTURE_2D, texture);
+	w = TW;
+	h = TH;
+	for (i = 0; w > 0 && h > 0; i++) {
+		glTexImage2D(GL_TEXTURE_2D, LEVELS - 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);
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_GLSL_version(110);
+	prog = piglit_build_simple_program(NULL, fragShaderText);
+	setup_texture();
+}
-- 
2.17.1



More information about the Piglit mailing list