[Piglit] [PATCH 8/9] ARB_viewport_array: Rendering test with multiple depthranges

Brian Paul brianp at vmware.com
Wed Oct 30 00:47:28 CET 2013


On 10/29/2013 03:55 PM, Jon Ashburn wrote:
> Draws quads into a single framebuffer surface with multiple viewports
> via a geometry shader.  Each different viewport has a different DepthRange.
> The fragment shader outputs a color based on the depthRange, z, and viewport
> index. Confirm that each quad has the correct color and therefore has
> the correct depthRange for that viewport index.
>
> Tested on Nvidia Quadro 600, test passes.
> ---
>   tests/all.tests                                   |   1 +
>   tests/spec/arb_viewport_array/CMakeLists.gl.txt   |   1 +
>   tests/spec/arb_viewport_array/render_depthrange.c | 195 ++++++++++++++++++++++
>   3 files changed, 197 insertions(+)
>   create mode 100644 tests/spec/arb_viewport_array/render_depthrange.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 9bfb947..15ab94c 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -1738,6 +1738,7 @@ arb_viewport_array['bounds'] = concurrent_test('arb_viewport_array-bounds')
>   arb_viewport_array['queries'] = concurrent_test('arb_viewport_array-queries')
>   arb_viewport_array['minmax'] = concurrent_test('arb_viewport_array-minmax')
>   arb_viewport_array['render-viewport'] = concurrent_test('arb_viewport_array-render-viewport')
> +arb_viewport_array['render-depthrange'] = concurrent_test('arb_viewport_array-render-depthrange')
>
>   nv_vertex_program = Group()
>   spec['NV_vertex_program'] = nv_vertex_program
> diff --git a/tests/spec/arb_viewport_array/CMakeLists.gl.txt b/tests/spec/arb_viewport_array/CMakeLists.gl.txt
> index 0514b81..418c1d1 100644
> --- a/tests/spec/arb_viewport_array/CMakeLists.gl.txt
> +++ b/tests/spec/arb_viewport_array/CMakeLists.gl.txt
> @@ -16,5 +16,6 @@ piglit_add_executable(arb_viewport_array-bounds bounds.c)
>   piglit_add_executable(arb_viewport_array-queries queries.c)
>   piglit_add_executable(arb_viewport_array-minmax minmax.c)
>   piglit_add_executable(arb_viewport_array-render-viewport render_viewport.c)
> +piglit_add_executable(arb_viewport_array-render-depthrange render_depthrange.c)
>
>   # vim: ft=cmake:
> diff --git a/tests/spec/arb_viewport_array/render_depthrange.c b/tests/spec/arb_viewport_array/render_depthrange.c
> new file mode 100644
> index 0000000..6e5dbd5
> --- /dev/null
> +++ b/tests/spec/arb_viewport_array/render_depthrange.c
> @@ -0,0 +1,195 @@
> +/*
> + * Copyright © 2013 LunarG, 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.
> + *
> + * Author: Jon Ashburn <jon at lunarg.com>
> + */
> +
> +/**
> + * Draws quads into a single framebuffer surface with multiple viewports
> + * via a geometry shader.  Each different viewport has a different DepthRange.
> + * The fragment shader outputs a color based on the depthRange, z, and viewport
> + * index. Confirm that each quad has the correct color and therefore has
> + * the correct depthRange for that viewport index.
> + * From the OpenGL 4.3 Core3 Profile Spec section 13.6:
> + *     "DepthRangeIndexed specifies the depth range for a single viewport and
> + *     is equivalent (assuming no errors are generated) to:
> + *         double v[] = { n, f };
> + *         DepthRangeArrayv(index, 1, v);"
> + *     "DepthRange sets the depth range for all viewports to the same values
> + *     and is equivalent (assuming no errors are generated) to:
> + *         for (uint i = 0; i < MAX_VIEWPORTS; i++)
> + *         DepthRangeIndexed(i, n, f );"
> + */
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 32;
> +	config.supports_gl_core_version = 32;
> +
> +	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +const char *vsSource = {
> +	"#version 430\n"
> +	"in vec4 piglit_vertex;\n"
> +	"void main() {\n"
> +	"	gl_Position = piglit_vertex;\n"
> +	"}\n"
> +};
> +
> +const char *gsSource = {
> +	"#version 430\n"
> +	"layout(triangles) in;\n"
> +	"layout(triangle_strip, max_vertices = 3) out;\n"
> +	"uniform int idx;\n"
> +	"\n"
> +	"void main()\n"
> +	"{\n"
> +	"	gl_ViewportIndex = idx;\n"
> +	"	for(int i = 0; i < gl_in.length(); i++) {\n"
> +	"		gl_Position = gl_in[i].gl_Position;\n"
> +	"		EmitVertex();\n"
> +	"	}\n"
> +	"	EndPrimitive();\n"
> +	"}\n"
> +};
> +
> +const char *fsSource = {
> +	"#version 430\n"
> +	"uniform vec3 color;\n"
> +	"in int gl_ViewportIndex;\n"
> +	"void main() {\n"
> +	"	float idx = gl_ViewportIndex / 10.0;\n"
> +	"	gl_FragColor = vec4(gl_FragCoord.z, gl_DepthRange.far, idx, 1.0);\n"
> +	"}\n"
> +};
> +
> +static GLuint colorLoc;
> +static GLuint vpIndexLoc;
> +
> +/**
> + * Draws a single quad into multiple viewport each with a different
> + * depthRange and fixed Z plane.  Reads back the expected color (which is a
> + * a function (funcOf(Z, depthRange, viewportIndex)) to test if the drawing
> + * with different depthRanges per viewport index is correct.
> + * From GLSL 4.30.6 Spec section 7.4:
> + *     "Depth range in window coordinates,
> + *      section 13.6.1 “Controlling the Viewport” in the
> + *      OpenGL Graphics System Specification.
> + *      Note: Depth-range state is only for viewport 0."
> + *
> + */
> +static bool
> +draw_multi_viewport(void)
> +{
> +	bool pass = true;
> +	int i, j;
> +	const int divX=2, divY=4;
> +	GLfloat w = (GLfloat) piglit_width / (GLfloat) divX;
> +	GLfloat h = (GLfloat) piglit_height / (GLfloat) divY;
> +	GLfloat zVal = 0.25;
> +	GLfloat drFar = 0.6;
> +	GLfloat colors[divX*divY][3];
> +	GLdouble depthRange[][2] = {{0.5, 1.0},
> +				    {0.0, 0.8},
> +				    {1.0, 0.75},
> +				    {0.3, 0.8},
> +				    {0.7, 0.6},
> +				    {0.9, 0.1},
> +				    {0.1, 0.9},
> +				    {0.2, 0.4}};

Const qualify?


> +
> +	assert(ARRAY_SIZE(depthRange) == divX*divY);
> +
> +
> +	glClearDepthf(1.0);
> +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
> +	glEnable(GL_DEPTH_TEST);
> +	glDepthRangeIndexed(0, 0.4, drFar);
> +	glDepthFunc(GL_ALWAYS);
> +
> +	/* initialize expected colors */
> +	/* Frag shader uses FragCoord.z for the Red, DepthRange[0].far for
> +	   Green color, and Blue is viewportIndex / 10.0 */

For multi-line comments we use a style like this:

/* Frag shader uses FragCoord.z for the Red, DepthRange[0].far for
  * Green color, and Blue is viewportIndex / 10.0
  */


> +	for (i = 0; i < divX * divY; i++) {
> +		GLfloat near = depthRange[i][0];
> +		GLfloat far = depthRange[i][1];
> +		colors[i][0] = (((far - near) * zVal)  + near + far) / 2.0;
> +		colors[i][1] = drFar;
> +		colors[i][2] = (GLfloat) (i + 1) / 10.0;
> +	}
> +
> +	/* draw with varying viewports and depth ranges */
> +	for (i = 0; i < divX; i++) {
> +		for (j = 0; j < divY; j++) {
> +			int p, idx;
> +			/* start at index 1 instead of zero, since index 0
> +			   contains the Frag Shader gl_DepthRange value */
> +			idx = j + 1 + i*divY;
> +			glUniform3fv(colorLoc, 1, &colors[idx-1][0]);
> +			glUniform1i(vpIndexLoc, idx);
> +			glViewportIndexedf(idx, i * w, j * h, w, h);
> +			glDepthRangeIndexed(idx, depthRange[idx-1][0],
> +					    depthRange[idx-1][1]);
> +			piglit_draw_rect_z(zVal, -1.0, -1.0, 2.0, 2.0);
> +			pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
> +			p = piglit_probe_pixel_rgb(i * w + w/2, j * h + h/2,
> +						   &colors[idx-1][0]);
> +			piglit_present_results();
> +			if (!p) {
> +				printf("Wrong color for viewport i,j %d %d\n",
> +				       i, j);
> +				pass = false;
> +			}
> +		}
> +	}
> +	return pass;
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	bool pass= true;
> +
> +	pass = draw_multi_viewport();
> +	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
> +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	GLuint program;
> +
> +	piglit_require_extension("GL_ARB_viewport_array");
> +
> +	program = piglit_build_simple_program_multiple_shaders(
> +					GL_VERTEX_SHADER, vsSource,
> +					GL_GEOMETRY_SHADER, gsSource,
> +					GL_FRAGMENT_SHADER, fsSource,
> +					0);
> +	glUseProgram(program);
> +	colorLoc = glGetUniformLocation(program, "color");
> +	vpIndexLoc = glGetUniformLocation(program, "idx");
> +}
>

With above fixes:  Reviewed-by: Brian Paul <brianp at vmware.com>




More information about the Piglit mailing list