From 452a51bb86c28cb9b9982038f0408cc586a02a72 Mon Sep 17 00:00:00 2001 Message-Id: <452a51bb86c28cb9b9982038f0408cc586a02a72.1515707167.git.fabianbieler@fastmail.fm> From: Fabian Bieler Date: Thu, 11 Jan 2018 22:40:50 +0100 Subject: [PATCH] gles2: Add fbo ping-pong test. Content-Type: text/plain; charset=UTF-8 To: piglit@lists.freedesktop.org This test toggles between two FBOs rendering to one and sampling from the other. It renders multiple tiles across the render targets. Each tile samples from all tiles in the other FBO and checks the color against an expected color (passed as a uniform). This test is especially useful for tiling renderers that reorder draw calls for performance reasons. --- tests/all.py | 1 + tests/spec/gles-2.0/CMakeLists.gles2.txt | 1 + tests/spec/gles-2.0/fbo-ping-pong.c | 171 +++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 tests/spec/gles-2.0/fbo-ping-pong.c diff --git a/tests/all.py b/tests/all.py index 8add41457..15c075fde 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-ping-pong']) 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..4cacac26e 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-ping-pong fbo-ping-pong.c) piglit_add_executable(draw_buffers_gles2 draw-buffers.c) # vim: ft=cmake: diff --git a/tests/spec/gles-2.0/fbo-ping-pong.c b/tests/spec/gles-2.0/fbo-ping-pong.c new file mode 100644 index 000000000..6d4f1e73a --- /dev/null +++ b/tests/spec/gles-2.0/fbo-ping-pong.c @@ -0,0 +1,171 @@ +/* + * 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-ping-pong.c + * + * Some tiling renderers reorder draw-calls for performance reasons. + * This could interfere with the integrity of resources written to by draws + * calls and read from by subsequent draw calls. + * + * This test toggles between two FBOs rendering to one and sampling from the + * other. + * + * It renders multiple tiles across the render targets. Each tile samples + * from all tiles in the other FBO and checks the color against an expected + * color (passed as a uniform). + */ + +#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.khr_no_error_support = PIGLIT_NO_ERRORS; +PIGLIT_GL_TEST_CONFIG_END + +static const char *vs_src = + "attribute vec4 piglit_vertex;\n" + "attribute vec2 piglit_texcoord;\n" + "varying vec2 tex_coord;\n" + "void main()\n" + "{\n" + " tex_coord = piglit_texcoord;\n" + " gl_Position = piglit_vertex;\n" + "}\n"; + +static const char *fs_src = + "precision highp float;\n" + "uniform sampler2D tex;\n" + "uniform vec4 expected_color;\n" + "uniform vec4 tolerance;\n" + "uniform vec4 good_color;\n" + "uniform vec4 bad_color;\n" + "varying vec2 tex_coord;\n" + "void main()\n" + "{\n" + " vec4 sampled_color = texture2D(tex, tex_coord);\n" + " if (any(greaterThan(abs(sampled_color - expected_color), tolerance)))\n" + " gl_FragColor = bad_color;\n" + " else\n" + " gl_FragColor = good_color;\n" + "}\n"; + +void +piglit_init(int argc, char **argv) +{ + bool pass = true; + const int width = TILESIZE * X_TILES; + const int height = TILESIZE * Y_TILES; + + const float color[][4] = { + { 0, 0, 0, 0 }, + { 0, 0, 0, 1 }, + { 0, 0, 1, 0 }, + { 0, 1, 0, 0 }, + { 1, 0, 0, 0 }, + }; + + /* set up shader */ + int prog = piglit_build_simple_program(vs_src, fs_src); + + glUseProgram(prog); + + int sampler_loc = glGetUniformLocation(prog, "tex"); + glUniform1i(sampler_loc, 0); + int tolerance_loc = glGetUniformLocation(prog, "tolerance"); + glUniform4fv(tolerance_loc, 1, piglit_tolerance); + int expected_color_loc = glGetUniformLocation(prog, "expected_color"); + int good_color_loc = glGetUniformLocation(prog, "good_color"); + int bad_color_loc = glGetUniformLocation(prog, "bad_color"); + glUniform4fv(bad_color_loc, 1, color[0]); + + /* create textures and FBOs */ + unsigned texture[2]; + unsigned fbo[2]; + glGenTextures(2, texture); + glGenFramebuffers(2, fbo); + + for (int i = 0; i < 2; ++i) { + glBindTexture(GL_TEXTURE_2D, texture[i]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, texture[i], 0); + + assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == + GL_FRAMEBUFFER_COMPLETE); + } + + glViewport(0, 0, width, height); + + /* zeroth render pass */ + glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]); + glClearColor(color[0][0], color[0][1], color[0][2], color[0][3]); + glClear(GL_COLOR_BUFFER_BIT); + + /* render pass 1 to n */ + for (int i = 1; i < ARRAY_SIZE(color); ++i) { + glUniform4fv(expected_color_loc, 1, color[i - 1]); + glUniform4fv(good_color_loc, 1, color[i]); + + glBindTexture(GL_TEXTURE_2D, texture[i % 2]); + glBindFramebuffer(GL_FRAMEBUFFER, fbo[(i + 1) % 2]); + + 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; + piglit_draw_rect_tex(-1 + x * w, -1 + y * h, + w, h, 0, 0, 1, 1); + } + } + + /* debug aid; disabled due to observer effect */ + /* pass = piglit_probe_rect_rgba(0, 0, width, height, + color[i]) && pass; */ + } + + /* Check result */ + pass = piglit_probe_rect_rgba(0, 0, width, height, + color[ARRAY_SIZE(color) - 1]) && pass; + + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); +} + +enum piglit_result +piglit_display(void) +{ + /* unreached */ + return PIGLIT_FAIL; +} -- 2.15.1