[Piglit] [PATCH] mesa_tile_raster_order: Add a test for the extension.
Eric Anholt
eric at anholt.net
Sat Aug 5 00:02:24 UTC 2017
This doesn't test repeated copies with TextureBarrier()s in between,
but that doesn't seem like important new behavior in this extension.
---
tests/all.py | 5 +
tests/spec/CMakeLists.txt | 1 +
.../spec/mesa_tile_raster_order/CMakeLists.gl.txt | 11 +
tests/spec/mesa_tile_raster_order/CMakeLists.txt | 1 +
tests/spec/mesa_tile_raster_order/rasterorder.c | 265 +++++++++++++++++++++
5 files changed, 283 insertions(+)
create mode 100644 tests/spec/mesa_tile_raster_order/CMakeLists.gl.txt
create mode 100644 tests/spec/mesa_tile_raster_order/CMakeLists.txt
create mode 100644 tests/spec/mesa_tile_raster_order/rasterorder.c
diff --git a/tests/all.py b/tests/all.py
index 9e3ce122bc3e..e087675cb030 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -4349,6 +4349,11 @@ with profile.test_list.group_manager(
with profile.test_list.group_manager(
PiglitGLTest,
+ grouptools.join('spec', 'mesa_tile_raster_order')) as g:
+ g(['mesa_tile_raster_order-rasterorder'])
+
+with profile.test_list.group_manager(
+ PiglitGLTest,
grouptools.join('spec', 'oes_read_format')) as g:
g(['oes-read-format'], run_concurrent=False)
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 4cc6da64cd3b..15087395e64c 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -153,6 +153,7 @@ add_subdirectory (arb_texture_stencil8)
add_subdirectory (arb_vertex_attrib_64bit)
add_subdirectory (ext_framebuffer_blit)
add_subdirectory (mesa_pack_invert)
+add_subdirectory (mesa_tile_raster_order)
add_subdirectory (ext_texture_format_bgra8888)
add_subdirectory (oes_draw_elements_base_vertex)
add_subdirectory (arb_shader_draw_parameters)
diff --git a/tests/spec/mesa_tile_raster_order/CMakeLists.gl.txt b/tests/spec/mesa_tile_raster_order/CMakeLists.gl.txt
new file mode 100644
index 000000000000..074365e4d5fc
--- /dev/null
+++ b/tests/spec/mesa_tile_raster_order/CMakeLists.gl.txt
@@ -0,0 +1,11 @@
+include_directories(
+ ${GLEXT_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+ piglitutil_${piglit_target_api}
+ ${OPENGL_gl_LIBRARY}
+)
+
+piglit_add_executable (mesa_tile_raster_order-rasterorder rasterorder.c)
diff --git a/tests/spec/mesa_tile_raster_order/CMakeLists.txt b/tests/spec/mesa_tile_raster_order/CMakeLists.txt
new file mode 100644
index 000000000000..144a306f4e7d
--- /dev/null
+++ b/tests/spec/mesa_tile_raster_order/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/mesa_tile_raster_order/rasterorder.c b/tests/spec/mesa_tile_raster_order/rasterorder.c
new file mode 100644
index 000000000000..4bf5775d8d33
--- /dev/null
+++ b/tests/spec/mesa_tile_raster_order/rasterorder.c
@@ -0,0 +1,265 @@
+/*
+ * Copyright © 2017 Broadcom
+ *
+ * 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
+ *
+ * Basic tests of GL_MESA_tile_raster_order: overlapping copies in
+ * diagonal directions, and making sure that glIsEnabled() has the
+ * right initial defaults.
+ */
+
+#include "piglit-util-gl.h"
+
+#define W 256
+#define H 256
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 10;
+
+ config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+ config.window_width = W;
+ config.window_height = H;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const char *vs_fragcoord =
+ "attribute vec4 piglit_vertex;\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = piglit_vertex;\n"
+ "}\n";
+
+const char *fs_fragcoord =
+ "uniform sampler2D s;\n"
+ "varying vec2 texcoord;\n"
+ "void main() {\n"
+ " gl_FragColor = vec4((gl_FragCoord.x - 0.5) / 255.0,\n"
+ " (gl_FragCoord.y - 0.5) / 255.0,\n"
+ " 0.0,\n"
+ " 0.0);\n"
+ "}\n";
+
+static const char *vs_tex =
+ "attribute vec4 piglit_vertex;\n"
+ "attribute vec2 piglit_texcoord;\n"
+ "varying vec2 texcoord;\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = piglit_vertex;\n"
+ " texcoord = piglit_texcoord;\n"
+ "}\n";
+
+const char *fs_tex =
+ "uniform sampler2D s;\n"
+ "varying vec2 texcoord;\n"
+ "void main() {\n"
+ " gl_FragColor = texture2D(s, texcoord);\n"
+ "}\n";
+
+/* Include the enums here for the moment, until we get new XML. */
+#ifndef GL_TILE_RASTER_ORDER_FIXED_MESA
+#define GL_TILE_RASTER_ORDER_FIXED_MESA 0x8BB8
+#define GL_TILE_RASTER_ORDER_INCREASING_X_MESA 0x8BB9
+#define GL_TILE_RASTER_ORDER_INCREASING_Y_MESA 0x8BBA
+#endif
+
+struct copy_desc {
+ bool inc_x, inc_y;
+ float dst_x, dst_y;
+ float src_x, src_y;
+ float w, h;
+};
+
+GLuint prog_tex, prog_fragcoord;
+
+bool
+test_one(const struct copy_desc *copy)
+{
+ uint8_t expected[W * H * 4];
+
+ printf("Testing copy from %d,%d to %d,%d (%dx%d) %cX %cY\n",
+ (int)copy->src_x, (int)copy->src_y,
+ (int)copy->dst_x, (int)copy->dst_y,
+ (int)copy->w, (int)copy->h,
+ copy->inc_x ? '+' : '-',
+ copy->inc_y ? '+' : '-');
+
+ for (int y = 0; y < H; y++) {
+ for (int x = 0; x < W; x++) {
+ if (x >= copy->dst_x && x < copy->dst_x + copy->w &&
+ y >= copy->dst_y && y < copy->dst_y + copy->h) {
+ expected[(y * W + x) * 4 + 0] =
+ x - copy->dst_x + copy->src_x;
+ expected[(y * W + x) * 4 + 1] =
+ y - copy->dst_y + copy->src_y;
+ } else {
+ expected[(y * W + x) * 4 + 0] = x;
+ expected[(y * W + x) * 4 + 1] = y;
+ }
+ expected[(y * W + x) * 4 + 2] = 0;
+ expected[(y * W + x) * 4 + 3] = 0;
+ }
+ }
+
+ /* Fill the window with ubytes from 0-255 according to x/y coordinate.
+ */
+ glUseProgram(prog_fragcoord);
+ piglit_draw_rect(-1, -1, 2, 2);
+
+ /* Do the copy of the rectangle. */
+ glEnable(GL_TILE_RASTER_ORDER_FIXED_MESA);
+ if (copy->inc_x)
+ glEnable(GL_TILE_RASTER_ORDER_INCREASING_X_MESA);
+ else
+ glDisable(GL_TILE_RASTER_ORDER_INCREASING_X_MESA);
+ if (copy->inc_y)
+ glEnable(GL_TILE_RASTER_ORDER_INCREASING_Y_MESA);
+ else
+ glDisable(GL_TILE_RASTER_ORDER_INCREASING_Y_MESA);
+
+ glUseProgram(prog_tex);
+ piglit_draw_rect_tex(-1 + 2 * copy->dst_x / W,
+ -1 + 2 * copy->dst_y / W,
+ 2 * copy->w / W,
+ 2 * copy->h / H,
+ copy->src_x / W,
+ copy->src_y / H,
+ copy->w / W,
+ copy->h / H);
+
+ glDisable(GL_TILE_RASTER_ORDER_FIXED_MESA);
+
+ return piglit_probe_image_ubyte(0, 0, W, H, GL_RGBA, expected);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ /* Be careful with small-delta copies, as the piglit tolerance
+ * means that we will pass tests when texels are offset by
+ * small amounts.
+ */
+ static const struct copy_desc tests[] = {
+ {
+ .inc_x = true, .inc_y = true,
+ .dst_x = 20, .dst_y = 20,
+ .src_x = 40, .src_y = 40,
+ .w = 100, .h = 100,
+ },
+ {
+ .inc_x = false, .inc_y = true,
+ .dst_x = 40, .dst_y = 20,
+ .src_x = 20, .src_y = 40,
+ .w = 100, .h = 100,
+ },
+ {
+ .inc_x = true, .inc_y = false,
+ .dst_x = 20, .dst_y = 40,
+ .src_x = 40, .src_y = 20,
+ .w = 100, .h = 100,
+ },
+ {
+ .inc_x = false, .inc_y = false,
+ .dst_x = 40, .dst_y = 40,
+ .src_x = 20, .src_y = 20,
+ .w = 100, .h = 100,
+ },
+ };
+ bool pass = true;
+ GLuint fbo;
+ GLuint tex;
+
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ /* We will initialize the texture values with drawing, to
+ * increase the chance of catching flushing bugs.
+ */
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, W, H, 0,
+ GL_RGBA, GL_FLOAT, NULL);
+
+ glGenFramebuffers(1, &fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, tex, 0);
+
+ if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) !=
+ GL_FRAMEBUFFER_COMPLETE) {
+ fprintf(stderr, "FBO incomplete\n");
+ return PIGLIT_FAIL;
+ }
+
+ for (int i = 0; i < ARRAY_SIZE(tests); i++) {
+ if (!test_one(&tests[i])) {
+ pass = false;
+ break;
+ }
+ }
+
+ /* Visualize the results */
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
+ glBlitFramebuffer(0, 0, W, H,
+ 0, 0, W, H,
+ GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ piglit_present_results();
+
+ glDeleteFramebuffers(1, &fbo);
+ glDeleteTextures(1, &tex);
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void piglit_init(int argc, char **argv)
+{
+ piglit_require_GLSL();
+ piglit_require_extension("GL_MESA_tile_raster_order");
+ piglit_require_extension("GL_ARB_framebuffer_object");
+
+ prog_tex = piglit_build_simple_program(vs_tex, fs_tex);
+ prog_fragcoord = piglit_build_simple_program(vs_fragcoord, fs_fragcoord);
+
+ if (glIsEnabled(GL_TILE_RASTER_ORDER_FIXED_MESA)) {
+ fprintf(stderr,
+ "GL_TILE_RASTER_ORDER_FIXED_MESA should default off\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ if (!glIsEnabled(GL_TILE_RASTER_ORDER_INCREASING_X_MESA)) {
+ fprintf(stderr,
+ "GL_TILE_RASTER_ORDER_INCREASING_X_MESA "
+ "should default on\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ if (!glIsEnabled(GL_TILE_RASTER_ORDER_INCREASING_Y_MESA)) {
+ fprintf(stderr,
+ "GL_TILE_RASTER_ORDER_INCREASING_Y_MESA "
+ "should default on\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+}
--
2.13.3
More information about the Piglit
mailing list