summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Jerez <currojerez@riseup.net>2014-12-04 12:48:31 +0200
committerFrancisco Jerez <currojerez@riseup.net>2015-01-31 18:02:42 +0200
commit01027b7d2a1ca80139ac3a4db1c6cf2cf5d1febe (patch)
tree0679be5f5fb328f051a501ae7b2ea59b3ce38b4f
parenta5d7c79485bc87002f6b92163c1ac50d56dd82cf (diff)
arb_shader_image_load_store: Import image format bitcasting test.
The ARB_shader_image_load_store extension allows the reinterpretation of the binary contents of an existing image as an image of a different compatible format. The resulting values should be predictable and are defined in terms of the usual GL pixel transfer operations. v2: Actually bind the image with the bitcasted format.
-rw-r--r--tests/all.py1
-rw-r--r--tests/spec/arb_shader_image_load_store/CMakeLists.gl.txt1
-rw-r--r--tests/spec/arb_shader_image_load_store/bitcast.c174
3 files changed, 176 insertions, 0 deletions
diff --git a/tests/all.py b/tests/all.py
index 6adbb4189..9ae9f6b4b 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -4427,6 +4427,7 @@ import_glsl_parser_tests(spec['ARB_shader_image_load_store'],
os.path.join(TESTS_DIR, 'spec', 'arb_shader_image_load_store'),
[''])
arb_shader_image_load_store['atomicity'] = PiglitGLTest(['arb_shader_image_load_store-atomicity'], run_concurrent=True)
+arb_shader_image_load_store['bitcast'] = PiglitGLTest(['arb_shader_image_load_store-bitcast'], run_concurrent=True)
profile.tests['hiz'] = hiz
profile.tests['fast_color_clear'] = fast_color_clear
diff --git a/tests/spec/arb_shader_image_load_store/CMakeLists.gl.txt b/tests/spec/arb_shader_image_load_store/CMakeLists.gl.txt
index 8c67bb690..6b53370f6 100644
--- a/tests/spec/arb_shader_image_load_store/CMakeLists.gl.txt
+++ b/tests/spec/arb_shader_image_load_store/CMakeLists.gl.txt
@@ -13,5 +13,6 @@ link_libraries (
set(depends image.c grid.c common.c)
piglit_add_executable(arb_shader_image_load_store-atomicity atomicity.c ${depends})
+piglit_add_executable(arb_shader_image_load_store-bitcast bitcast.c ${depends})
# vim: ft=cmake:
diff --git a/tests/spec/arb_shader_image_load_store/bitcast.c b/tests/spec/arb_shader_image_load_store/bitcast.c
new file mode 100644
index 000000000..ab04ca116
--- /dev/null
+++ b/tests/spec/arb_shader_image_load_store/bitcast.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2014 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 bitcast.c
+ *
+ * Test that the reinterpretation of the binary contents of an image
+ * as a different compatible format yields predictable results as
+ * specified by the extension.
+ */
+
+#include "common.h"
+
+/** Window width. */
+#define W 16
+
+/** Window height. */
+#define H 96
+
+/** Total number of pixels in the window and image. */
+#define N (W * H)
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+config.supports_gl_core_version = 32;
+
+config.window_width = W;
+config.window_height = H;
+config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static bool
+init_image(const struct image_info img,
+ const struct image_format_info *dst_format)
+{
+ const unsigned m = image_num_components(img.format);
+ uint32_t pixels[4 * N];
+ int i;
+
+ for (i = 0; i < m * N; ++i)
+ pixels[i] = encode(img.format,
+ get_idx(image_format_scale(img.format), i % m)
+ * i / (m * N));
+
+ if (!upload_image(img, 0, pixels))
+ return false;
+
+ glBindImageTexture(0, get_texture(0), 0, GL_TRUE, 0,
+ GL_READ_ONLY, dst_format->format);
+
+ return piglit_check_gl_error(GL_NO_ERROR);
+}
+
+static bool
+check(const struct grid_info grid, const struct image_info src_img,
+ const struct image_info dst_img)
+{
+ uint32_t pixels_fb[4 * N];
+ uint32_t pixels_img[4 * N];
+
+ if (!download_result(grid, pixels_fb))
+ return false;
+
+ /*
+ * According to the spec, the reinterpretation of the texture
+ * data performed by image loads is equivalent to:
+ *
+ * "reading the texel from the source format to scratch
+ * memory according to the process described for GetTexImage
+ * (section 6.1.4), using default pixel storage modes and
+ * <format> and <type> parameters corresponding to the source
+ * format in Table X.3; and [...]
+ */
+ glBindTexture(src_img.target->target, get_texture(0));
+ glGetTexImage(src_img.target->target, 0, src_img.format->pixel_format,
+ src_img.format->pixel_type, pixels_img);
+
+ /*
+ * [...] writing the texel from scratch memory to the destination
+ * format according to the process described for
+ * TexSubImage3D (section 3.9.2), using default pixel storage
+ * modes and <format> and <type> parameters corresponding to
+ * the destination format in Table X.3."
+ */
+ glTexImage2D(dst_img.target->target, 0, dst_img.format->format,
+ W, H, 0, dst_img.format->pixel_format,
+ dst_img.format->pixel_type, pixels_img);
+ glGetTexImage(dst_img.target->target, 0, grid.format->pixel_format,
+ image_base_type(grid.format), pixels_img);
+
+ return piglit_check_gl_error(GL_NO_ERROR) &&
+ check_pixels_v(dst_img, pixels_fb, pixels_img);
+}
+
+static bool
+run_test(const struct image_format_info *src_format,
+ const struct image_format_info *dst_format)
+{
+ const struct grid_info grid =
+ grid_info(GL_FRAGMENT_SHADER,
+ image_base_internal_format(dst_format), W, H);
+ const struct image_info src_img =
+ image_info(GL_TEXTURE_2D, src_format->format, W, H);
+ const struct image_info dst_img =
+ image_info(GL_TEXTURE_2D, dst_format->format, W, H);
+ GLuint prog = generate_program(
+ grid, GL_FRAGMENT_SHADER,
+ concat(image_hunk(dst_img, ""),
+ hunk("uniform IMAGE_T img;\n"
+ "\n"
+ "GRID_T op(ivec2 idx, GRID_T x) {\n"
+ " return imageLoad(img, IMAGE_ADDR(idx));\n"
+ "}\n"), NULL));
+ bool ret = prog && init_fb(grid) &&
+ init_image(src_img, dst_format) &&
+ set_uniform_int(prog, "img", 0) &&
+ draw_grid(grid, prog) &&
+ check(grid, src_img, dst_img);
+
+ glDeleteProgram(prog);
+ return ret;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ const struct image_format_info *src_format, *dst_format;
+ enum piglit_result status = PIGLIT_PASS;
+
+ piglit_require_extension("GL_ARB_shader_image_load_store");
+
+ for (src_format = image_formats_load_store;
+ src_format->name; ++src_format) {
+ for (dst_format = image_formats_load_store;
+ dst_format->name; ++dst_format) {
+ if (dst_format != src_format &&
+ image_compat_format(dst_format) ==
+ image_compat_format(src_format)) {
+ subtest(&status, true,
+ run_test(src_format, dst_format),
+ "%s to %s bitcast test",
+ src_format->name, dst_format->name);
+ }
+ }
+ }
+
+ piglit_report_result(status);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_FAIL;
+}