general: Add a spot light sanity check

Submitted by Daniel Scharrer on Aug. 20, 2016, 3:20 a.m.

Details

Message ID 20160820032027.4064-1-daniel@constexpr.org
State New
Headers show
Series "general: Add a spot light sanity check" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Daniel Scharrer Aug. 20, 2016, 3:20 a.m.
Signed-off-by: Daniel Scharrer <daniel@constexpr.org>
---

This tests for the bug fixed by the Mesa patch at
https://patchwork.freedesktop.org/patch/106411/

The test passes on amdgpu-pro, llvmpipe (patched and unpatched)
and radeonsi (patched). It fails on unpatched radeonsi.

 tests/all.py                    |   1 +
 tests/general/CMakeLists.gl.txt |   1 +
 tests/general/spot-light.c      | 131 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 tests/general/spot-light.c

Patch hide | download patch | download mbox

diff --git a/tests/all.py b/tests/all.py
index e110f59..8b94c48 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -876,6 +876,7 @@  with profile.group_manager(
       run_concurrent=False)
     g(['select', 'scissor'], 'GL_SELECT - scissor-test enabled',
       run_concurrent=False)
+    g(['spot-light'], run_concurrent=False)
     g(['stencil-drawpixels'], run_concurrent=False)
     g(['texgen'], run_concurrent=False)
     g(['two-sided-lighting'], run_concurrent=False)
diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index 3a46fb0..6adacee 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -108,6 +108,7 @@  piglit_add_executable (scissor-offscreen scissor-offscreen.c)
 piglit_add_executable (scissor-polygon scissor-polygon.c)
 piglit_add_executable (scissor-stencil-clear scissor-stencil-clear.c)
 piglit_add_executable (select select.c)
+piglit_add_executable (spot-light spot-light.c)
 piglit_add_executable (stencil-drawpixels stencil-drawpixels.c)
 piglit_add_executable (stencil-twoside stencil-twoside.c)
 piglit_add_executable (stencil-wrap stencil-wrap.c)
diff --git a/tests/general/spot-light.c b/tests/general/spot-light.c
new file mode 100644
index 0000000..a800aca
--- /dev/null
+++ b/tests/general/spot-light.c
@@ -0,0 +1,131 @@ 
+/*
+ * Copyright (C) 2016 Daniel Scharrer <daniel@constexpr.org>
+ *
+ * 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.
+ */
+
+/** @file spot-light.c
+ *
+ * This is a simple sanity test for fixed function spot lights in OpenGL.
+ *
+ * It tests that vertices directly in front of the spot light are lit with
+ * full intensity and that lighting of vertices beyond the spot cutoff,
+ * and especially of those behind the spot light, is not affected by the
+ * spot light. This is done for three spot lights with different exponents.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLfloat pos[4] = {5.0, 5.0, 0.0, 1.0}; /* center */
+static GLfloat light0_dir[3] = {-1.0, 0.0, 0.0}; /* left */
+static GLfloat light1_dir[3] = {0.0, 1.0, 0.0}; /* up */
+static GLfloat light2_dir[3] = {1.0, 0.0, 0.0}; /* right */
+static GLfloat light0_ambient[4] = {1.0, 0.0, 0.0, 1.0};
+static GLfloat light1_ambient[4] = {0.0, 1.0, 0.0, 1.0};
+static GLfloat light2_ambient[4] = {0.0, 0.0, 1.0, 1.0};
+static GLfloat global_ambient[4] = {0.2, 0.2, 0.2, 1.0};
+
+enum piglit_result
+piglit_display(void)
+{
+	GLboolean pass = GL_TRUE;
+	GLfloat expected_left[4] = {1.0, 0.2, 0.2, 1.0};
+	GLfloat expected_bottom[4] = {0.2, 0.2, 0.2, 1.0};
+	GLfloat expected_right[4] = {0.2, 0.2, 1.0, 1.0};
+	GLfloat expected_top[4] = {0.2, 1.0, 0.2, 1.0};
+	GLfloat expected_bottom_left[4] = {0.2, 0.2, 0.2, 1.0};
+	GLfloat expected_top_left[4] = {0.2, 1.0, 0.2, 1.0};
+	GLfloat expected_bottom_right[4] = {0.2, 0.2, 0.2, 1.0};
+	GLfloat expected_top_right[4] = {0.2, 1.0, 0.2, 1.0};
+
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glPointSize(1);
+	glBegin(GL_POINTS);
+		for(int x = 0; x < 11; x++)
+		for(int y = 0; y < 11; y++)
+		{
+			glVertex2f(x, y);
+		}
+	glEnd();
+
+	pass = pass && piglit_probe_pixel_rgba( 0,  5, expected_left);
+	pass = pass && piglit_probe_pixel_rgba( 5,  0, expected_bottom);
+	pass = pass && piglit_probe_pixel_rgba(10,  5, expected_right);
+	pass = pass && piglit_probe_pixel_rgba( 5, 10, expected_top);
+	pass = pass && piglit_probe_pixel_rgba( 0,  0, expected_bottom_left);
+	pass = pass && piglit_probe_pixel_rgba( 0, 10, expected_top_left);
+	pass = pass && piglit_probe_pixel_rgba(10,  0, expected_bottom_right);
+	pass = pass && piglit_probe_pixel_rgba(10, 10, expected_top_right);
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLfloat zero[4] = {0.0, 0.0, 0.0, 1.0};
+	GLfloat one[4] = {1.0, 1.0, 1.0, 1.0};
+
+	glClearColor(0.0, 0.0, 0.0, 1.0);
+
+	glEnable(GL_LIGHT0);
+	glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 44.0);
+	glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 1.0);
+	glLightfv(GL_LIGHT0, GL_POSITION, pos);
+	glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light0_dir);
+	glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
+
+	glEnable(GL_LIGHT1);
+	glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 60.0);
+	glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 0.0);
+	glLightfv(GL_LIGHT1, GL_POSITION, pos);
+	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_dir);
+	glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
+
+	glEnable(GL_LIGHT2);
+	glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 44.0);
+	glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 5.0);
+	glLightfv(GL_LIGHT2, GL_POSITION, pos);
+	glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, light2_dir);
+	glLightfv(GL_LIGHT2, GL_AMBIENT, light2_ambient);
+
+	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
+	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
+
+	/* We are not interested in testing diffuse lighting, enable only the ambient term. */
+	glMaterialfv(GL_FRONT, GL_DIFFUSE, zero);
+	glMaterialfv(GL_FRONT, GL_AMBIENT, one);
+
+	glEnable(GL_LIGHTING);
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+}

Comments

On 08/19/2016 09:20 PM, Daniel Scharrer wrote:
> Signed-off-by: Daniel Scharrer <daniel@constexpr.org>
> ---
>
> This tests for the bug fixed by the Mesa patch at
> https://patchwork.freedesktop.org/patch/106411/
>
> The test passes on amdgpu-pro, llvmpipe (patched and unpatched)
> and radeonsi (patched). It fails on unpatched radeonsi.
>
>   tests/all.py                    |   1 +
>   tests/general/CMakeLists.gl.txt |   1 +
>   tests/general/spot-light.c      | 131 ++++++++++++++++++++++++++++++++++++++++

We're trying to get away from dumping new tests in the general/, bugs/ 
etc. directories.

How about putting this into tests/spec/gl-1.0/ ?


>   3 files changed, 133 insertions(+)
>   create mode 100644 tests/general/spot-light.c
>
> diff --git a/tests/all.py b/tests/all.py
> index e110f59..8b94c48 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -876,6 +876,7 @@ with profile.group_manager(
>         run_concurrent=False)
>       g(['select', 'scissor'], 'GL_SELECT - scissor-test enabled',
>         run_concurrent=False)
> +    g(['spot-light'], run_concurrent=False)
>       g(['stencil-drawpixels'], run_concurrent=False)
>       g(['texgen'], run_concurrent=False)
>       g(['two-sided-lighting'], run_concurrent=False)
> diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
> index 3a46fb0..6adacee 100644
> --- a/tests/general/CMakeLists.gl.txt
> +++ b/tests/general/CMakeLists.gl.txt
> @@ -108,6 +108,7 @@ piglit_add_executable (scissor-offscreen scissor-offscreen.c)
>   piglit_add_executable (scissor-polygon scissor-polygon.c)
>   piglit_add_executable (scissor-stencil-clear scissor-stencil-clear.c)
>   piglit_add_executable (select select.c)
> +piglit_add_executable (spot-light spot-light.c)
>   piglit_add_executable (stencil-drawpixels stencil-drawpixels.c)
>   piglit_add_executable (stencil-twoside stencil-twoside.c)
>   piglit_add_executable (stencil-wrap stencil-wrap.c)
> diff --git a/tests/general/spot-light.c b/tests/general/spot-light.c
> new file mode 100644
> index 0000000..a800aca
> --- /dev/null
> +++ b/tests/general/spot-light.c
> @@ -0,0 +1,131 @@
> +/*
> + * Copyright (C) 2016 Daniel Scharrer <daniel@constexpr.org>
> + *
> + * 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.
> + */
> +
> +/** @file spot-light.c
> + *
> + * This is a simple sanity test for fixed function spot lights in OpenGL.
> + *
> + * It tests that vertices directly in front of the spot light are lit with
> + * full intensity and that lighting of vertices beyond the spot cutoff,
> + * and especially of those behind the spot light, is not affected by the
> + * spot light. This is done for three spot lights with different exponents.
> + */
> +
> +#include "piglit-util-gl.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 10;
> +
> +	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static GLfloat pos[4] = {5.0, 5.0, 0.0, 1.0}; /* center */
> +static GLfloat light0_dir[3] = {-1.0, 0.0, 0.0}; /* left */
> +static GLfloat light1_dir[3] = {0.0, 1.0, 0.0}; /* up */
> +static GLfloat light2_dir[3] = {1.0, 0.0, 0.0}; /* right */
> +static GLfloat light0_ambient[4] = {1.0, 0.0, 0.0, 1.0};
> +static GLfloat light1_ambient[4] = {0.0, 1.0, 0.0, 1.0};
> +static GLfloat light2_ambient[4] = {0.0, 0.0, 1.0, 1.0};
> +static GLfloat global_ambient[4] = {0.2, 0.2, 0.2, 1.0};
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	GLboolean pass = GL_TRUE;

Nowadays we try to use bool/true/false.


> +	GLfloat expected_left[4] = {1.0, 0.2, 0.2, 1.0};
> +	GLfloat expected_bottom[4] = {0.2, 0.2, 0.2, 1.0};
> +	GLfloat expected_right[4] = {0.2, 0.2, 1.0, 1.0};
> +	GLfloat expected_top[4] = {0.2, 1.0, 0.2, 1.0};
> +	GLfloat expected_bottom_left[4] = {0.2, 0.2, 0.2, 1.0};
> +	GLfloat expected_top_left[4] = {0.2, 1.0, 0.2, 1.0};
> +	GLfloat expected_bottom_right[4] = {0.2, 0.2, 0.2, 1.0};
> +	GLfloat expected_top_right[4] = {0.2, 1.0, 0.2, 1.0};

Those could be declared static const, but not a big deal.

> +
> +	glClear(GL_COLOR_BUFFER_BIT);
> +
> +	glPointSize(1);
> +	glBegin(GL_POINTS);
> +		for(int x = 0; x < 11; x++)
> +		for(int y = 0; y < 11; y++)

More indentation.

> +		{
> +			glVertex2f(x, y);
> +		}
> +	glEnd();
> +
> +	pass = pass && piglit_probe_pixel_rgba( 0,  5, expected_left);
> +	pass = pass && piglit_probe_pixel_rgba( 5,  0, expected_bottom);
> +	pass = pass && piglit_probe_pixel_rgba(10,  5, expected_right);
> +	pass = pass && piglit_probe_pixel_rgba( 5, 10, expected_top);
> +	pass = pass && piglit_probe_pixel_rgba( 0,  0, expected_bottom_left);
> +	pass = pass && piglit_probe_pixel_rgba( 0, 10, expected_top_left);
> +	pass = pass && piglit_probe_pixel_rgba(10,  0, expected_bottom_right);
> +	pass = pass && piglit_probe_pixel_rgba(10, 10, expected_top_right);

We have to really careful when probing the color drawn by 1-pixel 
points.  Minor differences in rasterization from one driver to another 
could cause the points to be drawn at different locations.

IIRC, a 0.375 translation with an orthographic projection is supposed to 
be reliable.

Otherwise, you might consider spreading out the primitives and drawing 
small quads at each location, or larger points.


> +
> +	piglit_present_results();
> +
> +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	GLfloat zero[4] = {0.0, 0.0, 0.0, 1.0};
> +	GLfloat one[4] = {1.0, 1.0, 1.0, 1.0};
> +
> +	glClearColor(0.0, 0.0, 0.0, 1.0);
> +
> +	glEnable(GL_LIGHT0);
> +	glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 44.0);
> +	glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 1.0);
> +	glLightfv(GL_LIGHT0, GL_POSITION, pos);
> +	glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light0_dir);
> +	glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
> +
> +	glEnable(GL_LIGHT1);
> +	glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 60.0);
> +	glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 0.0);
> +	glLightfv(GL_LIGHT1, GL_POSITION, pos);
> +	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_dir);
> +	glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
> +
> +	glEnable(GL_LIGHT2);
> +	glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 44.0);
> +	glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 5.0);
> +	glLightfv(GL_LIGHT2, GL_POSITION, pos);
> +	glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, light2_dir);
> +	glLightfv(GL_LIGHT2, GL_AMBIENT, light2_ambient);
> +
> +	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
> +	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
> +
> +	/* We are not interested in testing diffuse lighting, enable only the ambient term. */
> +	glMaterialfv(GL_FRONT, GL_DIFFUSE, zero);
> +	glMaterialfv(GL_FRONT, GL_AMBIENT, one);
> +
> +	glEnable(GL_LIGHTING);
> +
> +	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
> +}
>
Quoting Daniel Scharrer (2016-08-19 20:20:27)
> Signed-off-by: Daniel Scharrer <daniel@constexpr.org>
> ---
> 
> This tests for the bug fixed by the Mesa patch at
> https://patchwork.freedesktop.org/patch/106411/
> 
> The test passes on amdgpu-pro, llvmpipe (patched and unpatched)
> and radeonsi (patched). It fails on unpatched radeonsi.
> 
>  tests/all.py                    |   1 +
>  tests/general/CMakeLists.gl.txt |   1 +
>  tests/general/spot-light.c      | 131 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 133 insertions(+)
>  create mode 100644 tests/general/spot-light.c
> 
> diff --git a/tests/all.py b/tests/all.py
> index e110f59..8b94c48 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -876,6 +876,7 @@ with profile.group_manager(
>        run_concurrent=False)
>      g(['select', 'scissor'], 'GL_SELECT - scissor-test enabled',
>        run_concurrent=False)
> +    g(['spot-light'], run_concurrent=False)

Is there a reason that this cannot be run concurrently? I'm not an
OpenGL expert, but generally only tests that do front buffer rendering
or lock-step things like timer-query require concurrent=False.

Dylan
Hi Daniel,

On 20 August 2016 at 04:20, Daniel Scharrer <daniel@constexpr.org> wrote:
> Signed-off-by: Daniel Scharrer <daniel@constexpr.org>
> ---
>
> This tests for the bug fixed by the Mesa patch at
> https://patchwork.freedesktop.org/patch/106411/
>
> The test passes on amdgpu-pro, llvmpipe (patched and unpatched)
> and radeonsi (patched). It fails on unpatched radeonsi.
>
Just an idea - one could keep the above in the commit message since it
gives nice reference points - mesa bug, piglit test ran against, etc.

> +       pass = pass && piglit_probe_pixel_rgba( 0,  5, expected_left);
Seems like many of the older piglit tests 'short circuit' as soon as
the first sub test fails. Can you please use the (newer) approach
which doesn't do so - pass = foo() && pass;
This allows one to see all points of failure at once.

Thanks
Emil