glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / arb_shader_image_load_store / qualifiers.c
blobd0afc3a7758abe6f27b5c0d61fb899ffb43fb52c
1 /*
2 * Copyright (C) 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /** @file qualifiers.c
26 * Test several combinations of image access qualifiers and binding
27 * access modes and check that omitting optional qualifiers doesn't
28 * have any effect on the rendering.
31 #include "common.h"
33 /** Window width. */
34 #define W 16
36 /** Window height. */
37 #define H 96
39 /** Total number of pixels in the window and images. */
40 #define N (W * H)
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_core_version = 32;
46 config.window_width = W;
47 config.window_height = H;
48 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
49 config.khr_no_error_support = PIGLIT_NO_ERRORS;
51 PIGLIT_GL_TEST_CONFIG_END
53 static bool
54 init_image_pixels(const struct image_info img, unsigned unit,
55 uint32_t *r_pixels)
57 const unsigned m = image_num_components(img.format);
58 const struct image_datum s = image_format_scale(img.format);
59 unsigned i;
61 for (i = 0; i < m * N; ++i)
62 r_pixels[i] =
63 (unit == 1 ? 0 :
64 encode(img.format, get_idx(s, i % m) * i / (m * N)));
66 return true;
69 static bool
70 init_image(const struct image_info img, unsigned unit,
71 bool strict_binding)
73 uint32_t pixels[4 * N];
74 bool ret = init_image_pixels(img, unit, pixels) &&
75 upload_image(img, unit, pixels);
77 if (strict_binding)
78 glBindImageTexture(unit, get_texture(unit), 0, GL_TRUE, 0,
79 (unit == 1 ? GL_WRITE_ONLY : GL_READ_ONLY),
80 img.format->format);
82 return ret && piglit_check_gl_error(GL_NO_ERROR);
85 static bool
86 check(const struct grid_info grid, const struct image_info img)
88 uint32_t pixels[4 * N], expect[4 * N];
90 return init_image_pixels(img, 0, expect) &&
91 download_image(img, 1, pixels) &&
92 check_pixels_v(img, pixels, expect);
95 static char *
96 test_hunk(bool strict_layout_qualifiers,
97 bool strict_access_qualifiers)
99 char *s = NULL;
101 (void)!asprintf(&s, "#define SRC_IMAGE_Q IMAGE_LAYOUT_Q %s\n"
102 "#define DST_IMAGE_Q %s %s\n",
103 (strict_access_qualifiers ? "readonly" : ""),
104 (strict_layout_qualifiers || !strict_access_qualifiers ?
105 "IMAGE_LAYOUT_Q" : ""),
106 (strict_access_qualifiers ? "writeonly" : ""));
107 return s;
111 * Copy from a source image into a destination image of the specified
112 * format and check the result.
114 * If \a strict_layout_qualifiers is false, uniform layout qualifiers
115 * will be omitted where allowed by the spec. If \a
116 * strict_access_qualifiers is false, the "readonly" and "writeonly"
117 * qualifiers will be omitted. If \a strict_binding is false, the
118 * image will be bound as READ_WRITE, otherwise only the required
119 * access type will be used.
121 static bool
122 run_test(const struct image_format_info *format,
123 bool strict_layout_qualifiers,
124 bool strict_access_qualifiers,
125 bool strict_binding)
127 const struct grid_info grid =
128 grid_info(GL_FRAGMENT_SHADER,
129 image_base_internal_format(format), W, H);
130 const struct image_info img =
131 image_info(GL_TEXTURE_2D, format->format, W, H);
132 GLuint prog = generate_program(
133 grid, GL_FRAGMENT_SHADER,
134 concat(image_hunk(img, ""),
135 test_hunk(strict_layout_qualifiers,
136 strict_access_qualifiers),
137 hunk("SRC_IMAGE_Q uniform IMAGE_BARE_T src_img;\n"
138 "DST_IMAGE_Q uniform IMAGE_BARE_T dst_img;\n"
139 "\n"
140 "GRID_T op(ivec2 idx, GRID_T x) {\n"
141 " imageStore(dst_img, IMAGE_ADDR(idx),"
142 " imageLoad(src_img, IMAGE_ADDR(idx)));\n"
143 " return x;\n"
144 "}\n"), NULL));
145 bool ret = prog && init_fb(grid) &&
146 init_image(img, 0, strict_binding) &&
147 init_image(img, 1, strict_binding) &&
148 set_uniform_int(prog, "src_img", 0) &&
149 set_uniform_int(prog, "dst_img", 1) &&
150 draw_grid(grid, prog) &&
151 check(grid, img);
153 glDeleteProgram(prog);
154 return ret;
157 void
158 piglit_init(int argc, char **argv)
160 enum piglit_result status = PIGLIT_PASS;
161 const struct image_format_info *format;
162 unsigned i;
164 piglit_require_extension("GL_ARB_shader_image_load_store");
166 for (format = image_formats_load_store; format->name; ++format) {
167 for (i = 0; i < 8; ++i) {
168 const bool strict_layout_qualifiers = i & 1;
169 const bool strict_access_qualifiers = i & 2;
170 const bool strict_binding = i & 4;
172 subtest(&status, true,
173 run_test(format, strict_layout_qualifiers,
174 strict_access_qualifiers,
175 strict_binding),
176 "%s/%s layout qualifiers/%s access qualifiers/"
177 "%s binding test", format->name,
178 (strict_layout_qualifiers ? "strict" : "permissive"),
179 (strict_access_qualifiers ? "strict" : "permissive"),
180 (strict_binding ? "strict" : "permissive"));
184 piglit_report_result(status);
187 enum piglit_result
188 piglit_display(void)
190 return PIGLIT_FAIL;