[Piglit] [PATCH] arb_shader_image_size: test GLSL's builtin imageSize
Martin Peres
martin.peres at linux.intel.com
Wed Apr 29 03:52:41 PDT 2015
v2:
- make sure that GL_ARB_shader_image_size == 1 in the shaders
Signed-off-by: Martin Peres <martin.peres at linux.intel.com>
---
tests/all.py | 5 +
tests/quick.py | 7 +
tests/spec/CMakeLists.txt | 1 +
tests/spec/arb_shader_image_size/CMakeLists.gl.txt | 16 ++
tests/spec/arb_shader_image_size/CMakeLists.txt | 1 +
tests/spec/arb_shader_image_size/builtin.c | 238 +++++++++++++++++++++
6 files changed, 268 insertions(+)
create mode 100755 tests/spec/arb_shader_image_size/CMakeLists.gl.txt
create mode 100644 tests/spec/arb_shader_image_size/CMakeLists.txt
create mode 100755 tests/spec/arb_shader_image_size/builtin.c
diff --git a/tests/all.py b/tests/all.py
index 18124b7..2fad427 100755
--- a/tests/all.py
+++ b/tests/all.py
@@ -4328,6 +4328,11 @@ with profile.group_manager(
g(['arb_shader_image_load_store-unused'], 'unused')
with profile.group_manager(
+ PiglitGLTest,
+ grouptools.join('spec', 'arb_shader_image_size')) as g:
+ g(['arb_shader_image_size-builtin'], 'builtin')
+
+with profile.group_manager(
PiglitGLTest,
grouptools.join('spec', 'arb_texture_stencil8')) as g:
g(['arb_texture_stencil8-draw'], 'draw')
diff --git a/tests/quick.py b/tests/quick.py
index d0aca02..26335ba 100644
--- a/tests/quick.py
+++ b/tests/quick.py
@@ -24,5 +24,12 @@ with profile.group_manager(
g(['arb_shader_image_load_store-shader-mem-barrier', '--quick'],
'shader-mem-barrier')
+# Set the --quick flag on a few image_size_tests
+with profile.group_manager(
+ PiglitGLTest,
+ grouptools.join('spec', 'arb_shader_image_size')) as g:
+ with profile.allow_reassignment:
+ g(['arb_shader_image_size-builtin', '--quick'], 'builtin')
+
# These take too long
profile.filter_tests(lambda n, _: '-explosion' not in n)
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 330b38c..d5a7a16 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -46,6 +46,7 @@ add_subdirectory (arb_shader_texture_lod/execution)
add_subdirectory (arb_shader_atomic_counters)
add_subdirectory (arb_shader_objects)
add_subdirectory (arb_shader_image_load_store)
+add_subdirectory (arb_shader_image_size)
add_subdirectory (arb_shading_language_420pack/execution)
add_subdirectory (arb_stencil_texturing)
add_subdirectory (arb_sync)
diff --git a/tests/spec/arb_shader_image_size/CMakeLists.gl.txt b/tests/spec/arb_shader_image_size/CMakeLists.gl.txt
new file mode 100755
index 0000000..03de9b0
--- /dev/null
+++ b/tests/spec/arb_shader_image_size/CMakeLists.gl.txt
@@ -0,0 +1,16 @@
+include_directories(
+ ${GLEXT_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+ piglitutil_${piglit_target_api}
+ ${OPENGL_gl_LIBRARY}
+ ${OPENGL_glu_LIBRARY}
+)
+
+piglit_add_executable (arb_shader_image_size-builtin builtin.c
+ ../arb_shader_image_load_store/image.c
+ ../arb_shader_image_load_store/grid.c
+ ../arb_shader_image_load_store/common.c)
+# vim: ft=cmake:
diff --git a/tests/spec/arb_shader_image_size/CMakeLists.txt b/tests/spec/arb_shader_image_size/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_shader_image_size/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_shader_image_size/builtin.c b/tests/spec/arb_shader_image_size/builtin.c
new file mode 100755
index 0000000..1b29253
--- /dev/null
+++ b/tests/spec/arb_shader_image_size/builtin.c
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2015 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 builtin.c
+ *
+ * Tests GLSL's imageSize builtin. The code is highly-based on
+ * image_load_store's max-size test from Francisco Jerez. It also uses the
+ * grid framework he introduced.
+ *
+ * From GL_ARB_shader_image_size's spec:
+ *
+ * "Including the following line in a shader can be used to control the
+ * language features described in this extension:
+ *
+ * #extension GL_ARB_shader_image_size
+ *
+ * A new preprocessor #define is added to the OpenGL Shading Language:
+ *
+ * #define GL_ARB_shader_image_size 1
+ *
+ * Add to section 8.11 "Image Functions"
+ *
+ * Syntax:
+ * int imageSize(gimage1D image)
+ * ivec2 imageSize(gimage2D image)
+ * ivec3 imageSize(gimage3D image)
+ * ivec2 imageSize(gimageCube image)
+ * ivec3 imageSize(gimageCubeArray image)
+ * ivec2 imageSize(gimageRect image)
+ * ivec2 imageSize(gimage1DArray image)
+ * ivec3 imageSize(gimage2DArray image)
+ * int imageSize(gimageBuffer image)
+ * ivec2 imageSize(gimage2DMS image)
+ * ivec3 imageSize(gimage2DMSArray image)
+ *
+ * Description:
+ *
+ * Returns the dimensions of the image or images bound to <image>. For
+ * arrayed images, the last component of the return value will hold the
+ * size of the array. Cube images return the dimensions of one face, and
+ * number of cubes in the cube map array, if arrayed."
+ */
+
+#include "../arb_shader_image_load_store/common.h"
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_core_version = 32;
+
+ config.window_visual = PIGLIT_GL_VISUAL_RGBA |
+ PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static bool
+randomize_image(const struct image_info img, unsigned unit)
+{
+ const unsigned n = image_num_components(img.format) * product(img.size);
+ uint32_t *pixels = malloc(sizeof(uint32_t) * n);
+ bool ret;
+
+ ret = upload_image(img, unit, pixels);
+
+ free(pixels);
+ return ret;
+}
+
+static bool
+check(const struct grid_info grid, struct image_info img_src)
+{
+ struct image_info img = image_info_for_grid(grid);
+ const unsigned n = image_num_components(img.format) * product(img.size);
+ uint32_t *pixels = malloc(sizeof(uint32_t) * n);
+ bool ret;
+
+ ret = download_result(grid, pixels);
+
+ if (img_src.target->target == GL_TEXTURE_CUBE_MAP_ARRAY) {
+ ret &= check_pixels(img, pixels, img_src.size.x, img_src.size.y,
+ img_src.size.z / 6.0, img_src.size.w);
+ } else if (image_target_samples(img_src.target) > 1) {
+ ret &= check_pixels(img, pixels, img_src.size.y, img_src.size.z,
+ img_src.size.w, 1.0);
+ } else {
+ ret &= check_pixels(img, pixels, img_src.size.x, img_src.size.y,
+ img_src.size.z, img_src.size.w);
+ }
+
+ free(pixels);
+ return ret;
+}
+
+static bool
+run_test(const struct image_target_info *target,
+ const struct image_extent size)
+{
+ const struct grid_info grid = grid_info(GL_FRAGMENT_SHADER, GL_RGBA32I,
+ 16, 16);
+ const struct image_info img = {
+ target, grid.format, size,
+ image_format_epsilon(grid.format)
+ };
+ GLuint prog = generate_program(
+ grid, GL_FRAGMENT_SHADER,
+ concat(hunk("#extension GL_ARB_shader_image_size : enable\n"),
+ image_hunk(img, ""),
+ hunk("readonly uniform IMAGE_T src_img;\n"
+ "\n"
+ "GRID_T op(ivec2 idx, GRID_T x) {\n"
+ " #if GL_ARB_shader_image_size == 1\n"
+ " return ivec4(imageSize(src_img), ivec3(1));\n"
+ " #else\n"
+ " return ivec4(-1, -1, -1, -1);\n"
+ " #endif\n"
+ "}\n"), NULL));
+ bool ret = prog && init_fb(grid) &&
+ randomize_image(img, 0) &&
+ set_uniform_int(prog, "src_img", 0) &&
+ draw_grid(grid, prog) &&
+ check(grid, img);
+
+ glDeleteProgram(prog);
+ return ret;
+}
+
+static struct image_extent
+get_test_extent(const struct image_target_info *target, unsigned d)
+{
+ const struct image_extent ls = image_target_limits(target);
+ const unsigned high = ~0, low = 8;
+ struct image_extent ext;
+ int i;
+
+ for (i = 0; i < 4; ++i)
+ set_idx(ext, i, MIN2(get_idx(ls, i), (i == d ? high : low)));
+
+ if (target->target == GL_TEXTURE_CUBE_MAP ||
+ target->target == GL_TEXTURE_CUBE_MAP_ARRAY) {
+ /* Cube maps have to be square and the number of faces
+ * should be a multiple of six. */
+ ext.y = ext.x;
+ ext.z = 6 * MAX2(ext.z / 6, 1);
+
+ } else if (image_target_samples(target) > 1) {
+ /* Use the maximum number of samples to keep things
+ * interesting. */
+ ext.x = image_target_samples(target);
+ }
+
+ return ext;
+}
+
+static bool
+should_test_dimension(const struct image_target_info *target, int d)
+{
+ const struct image_extent ls = image_target_limits(target);
+
+ return get_idx(ls, d) > 1 &&
+ /* Skip second cube map dimension as faces have to be
+ * square. */
+ !(target->target == GL_TEXTURE_CUBE_MAP && d >= 1) &&
+ !(target->target == GL_TEXTURE_CUBE_MAP_ARRAY && d == 1) &&
+ /* Skip sample dimension. */
+ !(image_target_samples(target) > 1 && d == 0);
+}
+
+static bool
+is_test_reasonable(bool quick, const struct image_extent size)
+{
+ /* Set an arbitrary limit on the number of texels so the test
+ * doesn't take forever. */
+ return product(size) < (quick ? 4 : 64) * 1024 * 1024;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ const bool quick = (argc >= 2 && !strcmp(argv[1], "--quick"));
+ enum piglit_result status = PIGLIT_PASS;
+ const struct image_target_info *target;
+ const struct image_stage_info *stage;
+ int d;
+
+ /* The spec of the extension says we should require GL 4.2 but let's
+ * just request GL_ARB_shader_image_size which will in turns require
+ * GL_ARB_shader_image_load_store which should be sufficient.
+ */
+ piglit_require_extension("GL_ARB_shader_image_size");
+
+
+ for (stage = image_stages(); stage->stage; ++stage) {
+ for (target = image_targets(); target->name; ++target) {
+ for (d = 0; d < 4; ++d) {
+ if (should_test_dimension(target, d)) {
+ const struct image_extent size =
+ get_test_extent(target, d);
+
+ subtest(&status,
+ is_test_reasonable(quick, size),
+ run_test(target, size),
+ "%s/image%s max size test/"
+ "%dx%dx%dx%d", stage->name,
+ target->name,
+ size.x, size.y, size.z, size.w);
+ }
+ }
+ }
+ }
+
+ piglit_report_result(status);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_FAIL;
+}
--
2.3.6
More information about the Piglit
mailing list