[Piglit] [PATCH 16/18] !UPSTREAM gles2: Add test fbo-draw-sample

Fabian Bieler fabianbieler at fastmail.fm
Sun Jan 7 22:23:04 UTC 2018


Please disregard this patch.

On 2018-01-07 23:14, Fabian Bieler wrote:
> Alternate drawing solid colors to an fbo and sampling from it to the
> framebuffer.
> 
> Some Tiled renderers reorder draw calls so to to minimize tile switching.
> 
> TODO
> ---
>  tests/all.py                             |   1 +
>  tests/spec/gles-2.0/CMakeLists.gles2.txt |   1 +
>  tests/spec/gles-2.0/fbo-draw-sample.c    | 164 +++++++++++++++++++++++++++++++
>  3 files changed, 166 insertions(+)
>  create mode 100644 tests/spec/gles-2.0/fbo-draw-sample.c
> 
> diff --git a/tests/all.py b/tests/all.py
> index 8add41457..ca2a73307 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -4643,6 +4643,7 @@ with profile.test_list.group_manager(
>      g(['minmax_gles2'])
>      g(['multiple-shader-objects_gles2'])
>      g(['fbo_discard_gles2'])
> +    g(['gles-2.0-fbo-draw-sample'])
>      g(['draw_buffers_gles2'])
>  
>  with profile.test_list.group_manager(
> diff --git a/tests/spec/gles-2.0/CMakeLists.gles2.txt b/tests/spec/gles-2.0/CMakeLists.gles2.txt
> index a29ad820c..1d0de6c13 100644
> --- a/tests/spec/gles-2.0/CMakeLists.gles2.txt
> +++ b/tests/spec/gles-2.0/CMakeLists.gles2.txt
> @@ -8,6 +8,7 @@ piglit_add_executable(link-no-vsfs_gles2 link-no-vsfs.c)
>  piglit_add_executable(minmax_gles2 minmax.c)
>  piglit_add_executable(multiple-shader-objects_gles2 multiple-shader-objects.c)
>  piglit_add_executable(fbo_discard_gles2 fbo-discard.c)
> +piglit_add_executable(gles-2.0-fbo-draw-sample fbo-draw-sample.c)
>  piglit_add_executable(draw_buffers_gles2 draw-buffers.c)
>  
>  # vim: ft=cmake:
> diff --git a/tests/spec/gles-2.0/fbo-draw-sample.c b/tests/spec/gles-2.0/fbo-draw-sample.c
> new file mode 100644
> index 000000000..57d07cc62
> --- /dev/null
> +++ b/tests/spec/gles-2.0/fbo-draw-sample.c
> @@ -0,0 +1,164 @@
> +/*
> + * Copyright © 2017 Fabian Bieler
> + *
> + * 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 fbo-draw-sample.c
> + *
> + * Alternate drawing solid colors to an fbo and sampling from it to the
> + * framebuffer.
> + *
> + * Some Tiled renderers reorder draw calls so to to minimize tile switching.
> + * TODO
> + */
> +
> +#include "piglit-util-gl.h"
> +
> +#define TILESIZE 32
> +#define X_TILES 8
> +#define Y_TILES 8
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +	config.supports_gl_es_version = 20;
> +	config.window_visual = PIGLIT_GL_VISUAL_RGB;
> +	config.window_width = TILESIZE * X_TILES;
> +	config.window_height = TILESIZE * Y_TILES;
> +	config.khr_no_error_support = PIGLIT_NO_ERRORS;
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +enum { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE };
> +
> +static const GLfloat colors[][4] = {
> +	{ 0.0, 0.0, 0.0, 1.0 },
> +	{ 0.0, 0.0, 1.0, 1.0 },
> +	{ 0.0, 1.0, 0.0, 1.0 },
> +	{ 0.0, 1.0, 1.0, 1.0 },
> +	{ 1.0, 0.0, 0.0, 1.0 },
> +	{ 1.0, 0.0, 1.0, 1.0 },
> +	{ 1.0, 1.0, 0.0, 1.0 },
> +	{ 1.0, 1.0, 1.0, 1.0 }
> +};
> +
> +static const char *vs_color_src =
> +	"attribute vec4 piglit_vertex;\n"
> +	"void main()\n"
> +	"{\n"
> +	"	gl_Position = piglit_vertex;\n"
> +	"}\n";
> +
> +static const char *fs_color_src =
> +	"precision highp float;\n"
> +	"uniform vec4 color;\n"
> +	"void main()\n"
> +	"{\n"
> +	"	 gl_FragColor = color;\n"
> +	"}\n";
> +
> +static const char *vs_tex_src =
> +	"attribute vec4 piglit_vertex;\n"
> +	"attribute vec4 piglit_texcoord;\n"
> +	"varying vec2 tex_coord;\n"
> +	"void main()\n"
> +	"{\n"
> +	"	gl_Position = piglit_vertex;\n"
> +	"	tex_coord = piglit_texcoord.xy;\n"
> +	"}\n";
> +
> +static const char *fs_tex_src =
> +	"precision highp float;\n"
> +	"uniform sampler2D tex;\n"
> +	"varying vec2 tex_coord;\n"
> +	"void main()\n"
> +	"{\n"
> +	"	 gl_FragColor = texture2D(tex, tex_coord);\n"
> +	"}\n";
> +
> +static int color_prog, tex_prog;
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	color_prog = piglit_build_simple_program(vs_color_src, fs_color_src);
> +	tex_prog = piglit_build_simple_program(vs_tex_src, fs_tex_src);
> +	int tex_loc = glGetUniformLocation(tex_prog, "tex");
> +	glUniform1i(tex_loc, 0);
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	bool pass = true;
> +	unsigned fbo;
> +	unsigned tex;
> +
> +	int color_loc = glGetUniformLocation(color_prog, "color");
> +
> +	glGenFramebuffers(1, &fbo);
> +	glGenTextures(1, &tex);
> +
> +	glBindTexture(GL_TEXTURE_2D, tex);
> +	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> +	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, piglit_width,
> +		     piglit_height, 0, GL_RGB, GL_INT, NULL);
> +
> +	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
> +	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
> +			       GL_TEXTURE_2D, tex, 0);
> +
> +	const GLenum e =
> +		glCheckFramebufferStatus(GL_FRAMEBUFFER);
> +	if (e != GL_FRAMEBUFFER_COMPLETE) {
> +		printf("FBO incomplete (%x): %s\n",
> +		       e, piglit_get_gl_enum_name(e));
> +		return PIGLIT_FAIL;
> +	}
> +
> +	for (int i = 0; i < ARRAY_SIZE(colors); ++i) {
> +		glBindFramebuffer(GL_FRAMEBUFFER, fbo);
> +		glUseProgram(color_prog);
> +
> +		for (int y = 0; y < Y_TILES; ++y) {
> +			for (int x = 0; x < X_TILES; ++x) {
> +				const float w = 2.0 / X_TILES;
> +				const float h = 2.0 / Y_TILES;
> +				glUniform4fv(color_loc, 1, colors[i]);
> +				piglit_draw_rect(-1 + x * w, -1 + y * h,
> +						 w, h);
> +			}
> +		}
> +
> +		glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
> +		glUseProgram(tex_prog);
> +
> +		piglit_draw_rect_tex(-1, -1, 2, 2, 0, 0, 1, 1);
> +
> +		/* Check result */
> +		pass = piglit_probe_rect_rgb(0, 0, piglit_width,
> +					     piglit_height, colors[i]) &&
> +		       pass;
> +	}
> +
> +	piglit_present_results();
> +
> +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> 


More information about the Piglit mailing list