Hi Ian, Kenneth,

Ian Romanick <i...@freedesktop.org> writes:
> On 10/10/2011 03:30 PM, tom fogal wrote:
> > One of our programs which relies on shaders heavily is having
> > issues, and I have tracked it down to unexpected values in
> > gl_NormalMatrix within the fragment shader.
>
> I think we could make a more general piglit test the reproduce this
> sort of failure.

Attached is a new patch against piglit master.  I took the approach of
generating the shader instead of uniforms, because I perceived it to be
easier to specify .x, .y, and .z as the gl_NormalMatrix vector element.

> > Is this a known issue?  Any workarounds available?  Anything else I
> > could do to help debug?
>
> Yikes!  A *lot* has changed in the fragment shader back-end for i965
> since 7.10.2.  Have you at least tried 7.10.3?  7.11?

I've compiled Mesa master (983fa4) and enabled it (thanks for the help,
Kenneth!) and I can reproduce it there.

The attached piglit test succeeds with: the nvidia binary blob,
and with both versions of Mesa (7.10.2 and master-983fa4) when
LIBGL_ALWAYS_SOFTWARE is set to 1.  It fails on both versions of Mesa
when software mode is disabled.

What else can I do to help?

Thanks,

-tom

From d007b5a25bf6dbcc44beb29c689460d198f9f63b Mon Sep 17 00:00:00 2001
From: Tom Fogal <tfo...@alumni.unh.edu>
Date: Wed, 12 Oct 2011 15:18:28 -0600
Subject: [PATCH] Add a test program for gl_NormalMatrix.

---
 tests/all.tests                      |    1 +
 tests/shaders/CMakeLists.gl.txt      |    1 +
 tests/shaders/glsl-fs-normalmatrix.c |  139 ++++++++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+), 0 deletions(-)
 create mode 100644 tests/shaders/glsl-fs-normalmatrix.c

diff --git a/tests/all.tests b/tests/all.tests
index ee46be2..1a9bb11 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -386,6 +386,7 @@ add_plain_test(shaders, 'glsl-fs-loop')
 add_plain_test(shaders, 'glsl-fs-loop-nested')
 add_plain_test(shaders, 'glsl-fs-mix')
 add_plain_test(shaders, 'glsl-fs-mix-constant')
+add_plain_test(shaders, 'glsl-fs-normalmatrix')
 add_plain_test(shaders, 'glsl-fs-pointcoord')
 add_plain_test(shaders, 'glsl-fs-raytrace-bug27060')
 add_plain_test(shaders, 'glsl-fs-sampler-numbering')
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt
index d0e3005..c21432f 100644
--- a/tests/shaders/CMakeLists.gl.txt
+++ b/tests/shaders/CMakeLists.gl.txt
@@ -80,6 +80,7 @@ add_executable (glsl-fs-loop glsl-fs-loop.c)
 add_executable (glsl-fs-loop-nested glsl-fs-loop-nested.c)
 add_executable (glsl-fs-mix glsl-fs-mix.c)
 add_executable (glsl-fs-mix-constant glsl-fs-mix-constant.c)
+add_executable (glsl-fs-normalmatrix glsl-fs-normalmatrix.c)
 IF (NOT MSVC)
 	add_executable (glsl-fs-raytrace-bug27060 glsl-fs-raytrace-bug27060.c)
 ENDIF (NOT MSVC)
diff --git a/tests/shaders/glsl-fs-normalmatrix.c b/tests/shaders/glsl-fs-normalmatrix.c
new file mode 100644
index 0000000..f36b0ef
--- /dev/null
+++ b/tests/shaders/glsl-fs-normalmatrix.c
@@ -0,0 +1,139 @@
+/*
+ * 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:
+ *    Tom Fogal
+ *
+ */
+
+/** @file glsl-fs-normalmatrix.c
+ *
+ * Tests gl_NormalMatrix for appropriate initial values.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static const char vert[] = {
+	"void main() {\n"
+	"  gl_Position = ftransform();\n"
+	"}\n"
+};
+/* Creates a fragment shader which colors everything red if
+ *   gl_NormalMatrix[elem].element
+ * is between 'low' and 'high', otherwise everything is green.
+ * The returned string is dynamically allocated and must be free'd by the
+ * caller. */
+static char* generate_fs(double low, double high, unsigned elem, char element)
+{
+	char* shader = calloc(1, 1024);
+	char* tmp = calloc(1, 512); /* for intermediate/appends. */
+
+	snprintf(shader, 1024, "void main(void) {\n");
+	snprintf(tmp, 512,
+					 "  if(%f <= gl_NormalMatrix[%u].%c && gl_NormalMatrix[%u].%c <= %f)",
+					 low, elem, element, elem, element, high);
+	strncat(shader, tmp, 512);
+	strncat(shader, " {\n", 512);
+	strcat(shader, "    gl_FragColor = vec4(1.0, 0.0, 0.0, 0.05);\n");
+	strcat(shader, "  } else {\n");
+	strcat(shader, "    gl_FragColor = vec4(0.0, 1.0, 0.0, 0.05);\n");
+	strcat(shader, "  }\n");
+	strcat(shader, "}\n");
+
+	free(tmp);
+	return shader;
+}
+static int test(double low, double high, unsigned elem, char element);
+
+enum piglit_result
+piglit_display(void)
+{
+	GLboolean pass = GL_TRUE;
+
+	glClearColor(0.0, 0.0, 0.0, 0.0);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+
+	pass &= test(0.99,  1.0,   0, 'x');
+	pass &= test(0.0,   0.001, 0, 'y');
+	pass &= test(0.0,   0.001, 0, 'z');
+	pass &= test(0.0,   0.001, 1, 'x');
+	pass &= test(0.999, 1.0,   1, 'y');
+	pass &= test(0.0,   0.001, 1, 'z');
+	pass &= test(0.0,   0.001, 2, 'x');
+	pass &= test(0.0,   0.0,   2, 'y');
+	pass &= test(0.999, 1.0,   2, 'z');
+
+	glutSwapBuffers();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+static int test(double low, double high, unsigned elem, char element)
+{
+	GLint vs, fs, prog;
+	float color[] = {1.0, 0.0, 0.0, 0.0};
+	char* shader;
+	int retval;
+
+	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);
+	shader = generate_fs(low, high, elem, element);
+#ifdef GLSL_DEBUG
+	printf("generated shader:\n%s\n", shader);
+#endif
+	printf("test: %g <= gl_NormalMatrix[%u].%c <= %g\n", low, elem, element,
+	       high);
+	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, shader);
+	prog = piglit_link_simple_program(vs, fs);
+	glUseProgram(prog);
+	free(shader);
+
+	piglit_draw_rect(0,0, 20,20);
+	glutSwapBuffers();
+	retval = piglit_probe_pixel_rgb(5,5, color);
+
+	/* clean up shaders. */
+	glUseProgram(0);
+	glDetachShader(prog, vs);
+	glDetachShader(prog, fs);
+	glDeleteProgram(prog);
+
+	return retval;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* Set up projection matrix so we can just draw using window
+	 * coordinates.
+	 */
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+	if (!GLEW_VERSION_2_0) {
+		printf("Requires OpenGL 2.0\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+	piglit_require_vertex_shader();
+	piglit_require_fragment_shader();
+}
-- 
1.7.3.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to