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
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
26 * Test that image array indexing gives the expected results. The
27 * original ARB_shader_image_load_store is rather vague in this
28 * regard, but the GLSL 4.2 specification states that:
30 * "When aggregated into arrays within a shader, images can only be
31 * indexed with a dynamically uniform integral expression, otherwise
32 * results are undefined."
34 * Which means that we can only check indexing with dynamically
35 * uniform expressions, i.e. expressions that are invariant for all
36 * shader invocations in which they are evaluated.
47 /** Total number of pixels in the window and images. */
50 PIGLIT_GL_TEST_CONFIG_BEGIN
52 config
.supports_gl_core_version
= 32;
54 config
.window_width
= W
;
55 config
.window_height
= H
;
56 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
57 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
59 PIGLIT_GL_TEST_CONFIG_END
62 init_images(const struct image_info img
, GLuint prog
)
64 uint32_t pixels
[H
][W
];
67 for (unit
= 0; unit
< 8; ++unit
) {
70 for (i
= 0; i
< W
; ++i
)
71 for (j
= 0; j
< H
; ++j
)
72 pixels
[j
][i
] = (i
+ j
+ unit
) % 16;
74 if (!upload_image(img
, unit
, pixels
[0]))
77 (void)!asprintf(&name
, "imgs[%d]", unit
);
78 set_uniform_int(prog
, name
, unit
);
86 check(const struct grid_info grid
, unsigned u
)
88 uint32_t pixels
[H
][W
];
89 uint32_t expect
[H
][W
];
92 for (i
= 0; i
< W
; ++i
) {
93 for (j
= 0; j
< H
; ++j
) {
95 /* Skipped invocation. */
96 expect
[j
][i
] = 0xdeadcafe;
98 /* Active invocation. */
101 for (unit
= 0; unit
< 8; ++unit
)
103 ((i
+ j
+ (unit
+ u
) % 8) % 16));
110 return download_result(grid
, pixels
[0]) &&
111 check_pixels_v(image_info_for_grid(grid
),
112 pixels
[0], expect
[0]);
116 * Discard a number of fragments and then load elements from an array
117 * of images using dynamically uniform indices.
120 run_test(const struct image_stage_info
*stage
)
122 const struct grid_info grid
=
123 grid_info(stage
->stage
, GL_R32UI
, W
, H
);
124 const struct image_info img
= image_info_for_grid(grid
);
125 GLuint prog
= generate_program(
127 concat(image_hunk(img
, ""),
128 hunk("uniform int u;\n"
129 "IMAGE_UNIFORM_T imgs[8];\n"
131 "GRID_T op(ivec2 idx, GRID_T x) {\n"
134 " if (idx.x % 2 == idx.y % 3)\n"
135 " return GRID_T(0xdeadcafeu);\n"
137 " for (i = 0; i < 8; ++i) {\n"
139 " imageLoad(imgs[(i + u) % 8],"
140 " IMAGE_ADDR(idx)).x);\n"
147 init_images(img
, prog
) &&
148 set_uniform_int(prog
, "u", 5) &&
149 draw_grid(grid
, prog
) &&
152 glDeleteProgram(prog
);
157 piglit_init(int argc
, char **argv
)
159 enum piglit_result status
= PIGLIT_PASS
;
160 const struct image_stage_info
*stage
;
162 piglit_require_extension("GL_ARB_shader_image_load_store");
164 for (stage
= image_stages(); stage
->name
; ++stage
)
165 subtest(&status
, true, run_test(stage
),
166 "%s shader/dynamically uniform indexing test",
169 piglit_report_result(status
);