[Piglit] [PATCH 5/5] Test that ReadPixels into a PBO properly resolves fast clears.
Paul Berry
stereotype441 at gmail.com
Wed May 22 10:20:27 PDT 2013
---
tests/all.tests | 1 +
tests/fast_color_clear/CMakeLists.gl.txt | 1 +
tests/fast_color_clear/read-to-pbo-after-clear.c | 181 +++++++++++++++++++++++
3 files changed, 183 insertions(+)
create mode 100644 tests/fast_color_clear/read-to-pbo-after-clear.c
diff --git a/tests/all.tests b/tests/all.tests
index 07f1040..2f88b09 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2338,6 +2338,7 @@ for subtest in ('sample', 'read_pixels', 'blit', 'copy'):
['fcc-read-after-clear', subtest, buffer_type])
add_concurrent_test(fast_color_clear, test_name)
add_concurrent_test(fast_color_clear, 'fcc-blit-between-clears')
+add_plain_test(fast_color_clear, 'fcc-read-to-pbo-after-clear')
asmparsertest = Group()
def add_asmparsertest(group, shader):
diff --git a/tests/fast_color_clear/CMakeLists.gl.txt b/tests/fast_color_clear/CMakeLists.gl.txt
index 4035569..792d42a 100644
--- a/tests/fast_color_clear/CMakeLists.gl.txt
+++ b/tests/fast_color_clear/CMakeLists.gl.txt
@@ -11,6 +11,7 @@ link_libraries (
)
piglit_add_executable (fcc-read-after-clear read-after-clear.c)
+piglit_add_executable (fcc-read-to-pbo-after-clear read-to-pbo-after-clear.c)
piglit_add_executable (fcc-blit-between-clears blit-between-clears.c)
# vim: ft=cmake:
diff --git a/tests/fast_color_clear/read-to-pbo-after-clear.c b/tests/fast_color_clear/read-to-pbo-after-clear.c
new file mode 100644
index 0000000..41dc4fe
--- /dev/null
+++ b/tests/fast_color_clear/read-to-pbo-after-clear.c
@@ -0,0 +1,181 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * 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 read-to-pbo-after-clear.c
+ *
+ * On i965/gen7+, glReadPixels uses the hardware blitter when reading
+ * from the window system buffer to a PBO, provided that no format
+ * conversions need to be performed. This test verifies that fast
+ * color clears are properly resolved before this blit occurs.
+ *
+ * The test operates by painting the window system framebuffer red
+ * using a non-fast-clear technique (rendering a quad using a shader),
+ * and then clearing it to green using a fast clear. Then it reads
+ * from the window to a PBO using glReadPixels(), and then maps the
+ * PBO into CPU memory and verifies that it contains green.
+ */
+
+#include "piglit-util-gl-common.h"
+
+#define TEX_WIDTH 512
+#define TEX_HEIGHT 512
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+ config.supports_gl_compat_version = 11;
+ config.window_width = TEX_WIDTH;
+ config.window_height = TEX_HEIGHT;
+ config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+PIGLIT_GL_TEST_CONFIG_END
+
+
+static const char *vs_text =
+ "void main()\n"
+ "{\n"
+ " gl_Position = gl_Vertex;\n"
+ " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
+ "}\n";
+
+static const char *fs_text_paint_red =
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
+ "}\n";
+
+static const char *fs_text_sample =
+ "uniform sampler2D samp;\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = texture2D(samp, gl_TexCoord[0].xy);\n"
+ "}\n";
+
+static GLuint prog_paint_red, prog_sample, pbo;
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint vs, fs_paint_red, fs_sample;
+
+ /* Requirements */
+ piglit_require_gl_version(11);
+ piglit_require_GLSL_version(110);
+ piglit_require_extension("GL_ARB_pixel_buffer_object");
+
+ /* Compile shaders */
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+ fs_paint_red = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
+ fs_text_paint_red);
+ prog_paint_red = piglit_link_simple_program(vs, fs_paint_red);
+ if (!prog_paint_red)
+ piglit_report_result(PIGLIT_FAIL);
+ fs_sample = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
+ fs_text_sample);
+ prog_sample = piglit_link_simple_program(vs, fs_sample);
+ if (!prog_sample)
+ piglit_report_result(PIGLIT_FAIL);
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ piglit_report_result(PIGLIT_FAIL);
+
+ /* Set up PBO */
+ glGenBuffers(1, &pbo);
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
+ glBufferData(GL_PIXEL_PACK_BUFFER, 4 * TEX_WIDTH * TEX_HEIGHT, NULL,
+ GL_STREAM_READ);
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ piglit_report_result(PIGLIT_FAIL);
+}
+
+
+bool
+check_pbo_data(const GLubyte *expected)
+{
+ int i, j, k;
+ const GLubyte *data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
+ for (i = 0; i < TEX_HEIGHT; i++) {
+ for (j = 0; j < TEX_WIDTH; j++) {
+ const GLubyte *actual = &data[(i * TEX_WIDTH + j) * 4];
+ for (k = 0; k < 4; k++) {
+ if (actual[k] != expected[k]) {
+ printf("Failure at (%d, %d):\n"
+ "Expected BGRA %d, %d, %d, %d\n"
+ "Got BGRA %d, %d, %d, %d\n",
+ i, j,
+ expected[0], expected[1],
+ expected[2], expected[3],
+ actual[0], actual[1],
+ actual[2], actual[3]);
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
+ return false;
+ }
+ }
+ }
+ }
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
+ return true;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ bool pass = true;
+ static const GLubyte green_ubytes[] = { 0, 255, 0, 255 };
+
+ /* Paint the window red using a shader (not a fast clear). */
+ glUseProgram(prog_paint_red);
+ glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT);
+ piglit_draw_rect(-1, -1, 2, 2);
+
+ /* Clear the window to green; this will be optimized using a
+ * fast color clear if the hardware is capable of it.
+ */
+ glClearColor(0, 1, 0, 1);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* Read directly from the window into a PBO using
+ * glReadPixels(). Note: we read using GL_UNSIGNED_BYTE and
+ * GL_BGRA since that's the case that causes the i965 driver
+ * to perform the read using a blit.
+ */
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
+ glReadPixels(0, 0, TEX_WIDTH, TEX_HEIGHT, GL_BGRA,
+ GL_UNSIGNED_BYTE, NULL);
+ pass = check_pbo_data(green_ubytes) && pass;
+
+ /* Note: piglit_present_results() will force a resolve to
+ * occur, so even if the test has failed, the window might
+ * appear green. To avoid confusing the user, clear the
+ * window to black before calling piglit_present_results().
+ */
+ glClearColor(0, 0, 0, 1);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ pass = false;
+
+ piglit_present_results();
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
--
1.8.2.3
More information about the Piglit
mailing list