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 atomic ops with unused return value still have the
27 * expected effect (which implies that they aren't being optimized out
28 * accidentally by the compiler).
39 /** Total number of pixels in the window and image. */
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
54 init_image(const struct image_info img
, uint32_t v
)
58 return init_pixels(img
, pixels
, v
, 0, 0, 0) &&
59 upload_image(img
, 0, pixels
);
63 check(const struct image_info img
, uint32_t v
)
67 return download_image(img
, 0, pixels
) &&
68 check_pixels(img
, pixels
, v
, 0, 0, 0);
72 * Test skeleton: Init image to \a init_value, run the provided shader
73 * \a op and check that the resulting image pixels equal \a
77 run_test(uint32_t init_value
, uint32_t check_value
,
80 const struct grid_info grid
=
81 grid_info(GL_FRAGMENT_SHADER
, GL_R32UI
, W
, H
);
82 const struct image_info img
= image_info_for_grid(grid
);
83 GLuint prog
= generate_program(
84 grid
, GL_FRAGMENT_SHADER
,
85 concat(image_hunk(img
, ""),
86 hunk("IMAGE_UNIFORM_T img;\n"),
90 init_image(img
, init_value
) &&
91 set_uniform_int(prog
, "img", 0) &&
92 draw_grid(grid
, prog
) &&
93 check(img
, check_value
);
95 glDeleteProgram(prog
);
100 piglit_init(int argc
, char **argv
)
102 enum piglit_result status
= PIGLIT_PASS
;
104 piglit_require_extension("GL_ARB_shader_image_load_store");
106 subtest(&status
, true,
108 "GRID_T op(ivec2 idx, GRID_T x) {\n"
109 " imageAtomicAdd(img, IMAGE_ADDR(idx), BASE_T(33));\n"
114 subtest(&status
, true,
115 run_test(0xffffffff, 33,
116 "GRID_T op(ivec2 idx, GRID_T x) {\n"
117 " imageAtomicMin(img, IMAGE_ADDR(idx), BASE_T(33));\n"
122 subtest(&status
, true,
124 "GRID_T op(ivec2 idx, GRID_T x) {\n"
125 " imageAtomicMax(img, IMAGE_ADDR(idx), BASE_T(33));\n"
130 subtest(&status
, true,
131 run_test(0xffffffff, 33,
132 "GRID_T op(ivec2 idx, GRID_T x) {\n"
133 " imageAtomicAnd(img, IMAGE_ADDR(idx), BASE_T(33));\n"
138 subtest(&status
, true,
140 "GRID_T op(ivec2 idx, GRID_T x) {\n"
141 " imageAtomicOr(img, IMAGE_ADDR(idx), BASE_T(33));\n"
146 subtest(&status
, true,
148 "GRID_T op(ivec2 idx, GRID_T x) {\n"
149 " imageAtomicXor(img, IMAGE_ADDR(idx), BASE_T(33));\n"
154 subtest(&status
, true,
156 "GRID_T op(ivec2 idx, GRID_T x) {\n"
157 " imageAtomicExchange(img, IMAGE_ADDR(idx),"
161 "imageAtomicExchange");
163 subtest(&status
, true,
165 "GRID_T op(ivec2 idx, GRID_T x) {\n"
166 " imageAtomicCompSwap(img, IMAGE_ADDR(idx),"
167 " BASE_T(0), BASE_T(33));\n"
170 "imageAtomicCompSwap");
172 piglit_report_result(status
);