[Piglit] [PATCH] arb_texture_multisample-stencil-clear: new stencil clear test

Nicolai Hähnle nhaehnle at gmail.com
Fri Apr 22 21:29:57 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

This exhibits an MSAA-specific bug in the radeonsi driver with fast stencil
clear and decompress.

The test can optionally disable MSAA and change the number of samples, though
I've only added the default variant to the all run - that's enough to expose
the bug.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93767
---
 tests/all.py                                       |   1 +
 .../spec/arb_texture_multisample/CMakeLists.gl.txt |   1 +
 tests/spec/arb_texture_multisample/stencil-clear.c | 187 +++++++++++++++++++++
 3 files changed, 189 insertions(+)
 create mode 100644 tests/spec/arb_texture_multisample/stencil-clear.c

diff --git a/tests/all.py b/tests/all.py
index 93d64e6..7b74fed 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1777,6 +1777,7 @@ with profile.group_manager(
     g(['arb_texture_multisample-teximage-3d-multisample'])
     g(['arb_texture_multisample-teximage-2d-multisample'])
     g(['arb_texture_multisample-sample-depth']),
+    g(['arb_texture_multisample-stencil-clear']),
     g(['arb_texture_multisample-clear'])
 
 samplers_atm = ['sampler2DMS', 'isampler2DMS', 'usampler2DMS',
diff --git a/tests/spec/arb_texture_multisample/CMakeLists.gl.txt b/tests/spec/arb_texture_multisample/CMakeLists.gl.txt
index ae7fc34..a347143 100644
--- a/tests/spec/arb_texture_multisample/CMakeLists.gl.txt
+++ b/tests/spec/arb_texture_multisample/CMakeLists.gl.txt
@@ -23,4 +23,5 @@ piglit_add_executable (arb_texture_multisample-teximage-2d-multisample teximage-
 piglit_add_executable (arb_texture_multisample-teximage-3d-multisample teximage-3d-multisample.c)
 piglit_add_executable (arb_texture_multisample-sample-depth sample-depth.c)
 piglit_add_executable (arb_texture_multisample-clear clear.c)
+piglit_add_executable (arb_texture_multisample-stencil-clear stencil-clear.c)
 # vim: ft=cmake:
diff --git a/tests/spec/arb_texture_multisample/stencil-clear.c b/tests/spec/arb_texture_multisample/stencil-clear.c
new file mode 100644
index 0000000..cbd4b62
--- /dev/null
+++ b/tests/spec/arb_texture_multisample/stencil-clear.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2016 Advanced Micro Devices, Inc.
+ *
+ * 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 "piglit-util-gl.h"
+
+/* File: stencil-clear.c
+ *
+ * Tests whether clearing a multisample stencil texture, followed by a blit
+ * and subsequent rendering works correctly.
+ */
+
+#define TEX_WIDTH 256
+#define TEX_HEIGHT 256
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+    config.supports_gl_compat_version = 30;
+    config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+    config.window_width = TEX_WIDTH;
+    config.window_height = TEX_HEIGHT;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLuint fbo, fbo_copy;
+
+static void
+usage(void)
+{
+	fprintf(stderr, "usage: arb_texture_multisample-stencil-clear [samples N]\n");
+	exit(1);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	static const float black[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
+	bool pass = true;
+
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
+	glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT);
+
+	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+	glClearDepth(0.0f);
+	glClearStencil(0);
+	glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
+
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_copy);
+
+	/* This blit is there on purpose to trigger a bug in stencil decompress
+	 * on Radeon. The blit destination is not used.
+	 */
+	glBlitFramebuffer(0, 0, TEX_WIDTH, TEX_WIDTH, 0, 0, TEX_WIDTH, TEX_WIDTH, GL_STENCIL_BUFFER_BIT, GL_NEAREST);
+	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+	glEnable(GL_STENCIL_TEST);
+	glStencilMask(255);
+	glStencilFunc(GL_LEQUAL, 1, 255);
+	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+
+	glColor4f(1.0, 1.0, 1.0, 1.0);
+	glBegin(GL_TRIANGLE_FAN);
+		glVertex3f( 0.0174f, -0.00413f, 1.0f);
+		glVertex3f(-1.0f, -1.0f,  1.0f);
+		glVertex3f( 1.0f, -1.0f, -1.0f);
+		glVertex3f( 1.0f,  1.0f,  1.0f);
+		glVertex3f(-1.0f,  1.0f, -1.0f);
+		glVertex3f(-1.0f, -1.0f, -1.0f);
+	glEnd();
+
+	glDisable(GL_STENCIL_TEST);
+
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
+	glClearColor(1.0, 0.0, 1.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
+	glBlitFramebuffer(0, 0, TEX_WIDTH, TEX_HEIGHT, 0, 0, TEX_WIDTH, TEX_HEIGHT,
+			  GL_COLOR_BUFFER_BIT, GL_NEAREST);
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
+
+	pass = piglit_probe_rect_rgb(0, 0, TEX_WIDTH, TEX_HEIGHT, black) && pass;
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+GLuint create_fbo(unsigned num_samples)
+{
+	GLenum tex_target;
+	GLuint texColor;
+	GLuint texZS;
+	GLuint fbo;
+
+	/* setup an fbo with (optionally multisample) textures */
+	glGenTextures(1, &texColor);
+	glGenTextures(1, &texZS);
+
+	if (num_samples != 0) {
+		tex_target = GL_TEXTURE_2D_MULTISAMPLE;
+
+		glBindTexture(tex_target, texZS);
+		glTexImage2DMultisample(
+			tex_target, num_samples, GL_DEPTH32F_STENCIL8,
+			TEX_WIDTH, TEX_HEIGHT, GL_TRUE);
+
+		glBindTexture(tex_target, texColor);
+		glTexImage2DMultisample(
+			tex_target, num_samples, GL_RGBA8,
+			TEX_WIDTH, TEX_HEIGHT, GL_TRUE);
+	} else {
+		tex_target = GL_TEXTURE_2D;
+
+		glBindTexture(tex_target, texZS);
+		glTexParameteri(tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		glTexParameteri(tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexImage2D(tex_target, 0, GL_DEPTH32F_STENCIL8,
+			     TEX_WIDTH, TEX_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
+
+		glBindTexture(tex_target, texColor);
+		glTexParameteri(tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		glTexParameteri(tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexImage2D(tex_target, 0, GL_RGBA8, TEX_WIDTH, TEX_HEIGHT, 0,
+			     GL_RGBA, GL_FLOAT, NULL);
+	}
+
+	glGenFramebuffers(1, &fbo);
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
+	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
+			GL_DEPTH_STENCIL_ATTACHMENT,
+			tex_target, texZS, 0);
+	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
+			GL_COLOR_ATTACHMENT0,
+			tex_target, texColor, 0);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		printf("Error during tex/fbo setup; no point continuing.\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	return fbo;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	unsigned num_samples = 4;
+
+	piglit_require_extension("GL_ARB_texture_multisample");
+
+	for (int i = 1; i < argc; ++i) {
+		if (!strcmp(argv[i], "samples")) {
+			++i;
+			if (i >= argc)
+				usage();
+			num_samples = atoi(argv[i]);
+		} else
+			usage();
+	}
+
+	printf("Number of samples: %u\n", num_samples);
+
+	fbo = create_fbo(num_samples);
+	fbo_copy = create_fbo(0);
+}
-- 
2.5.0



More information about the Piglit mailing list