ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_shader_image_load_store / unused.c
blob5c3da7edadaf2df8abb3d7a46c8ac0d93fe0516a
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 unused.c
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).
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 image. */
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(const struct image_info img, uint32_t v)
56 uint32_t pixels[N];
58 return init_pixels(img, pixels, v, 0, 0, 0) &&
59 upload_image(img, 0, pixels);
62 static bool
63 check(const struct image_info img, uint32_t v)
65 uint32_t pixels[N];
67 return download_image(img, 0, pixels) &&
68 check_pixels(img, pixels, v, 0, 0, 0);
71 /**
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
74 * check_value.
76 static bool
77 run_test(uint32_t init_value, uint32_t check_value,
78 const char *op)
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"),
87 hunk(op), NULL));
88 bool ret = prog &&
89 init_fb(grid) &&
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);
96 return ret;
99 void
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,
107 run_test(0, 33,
108 "GRID_T op(ivec2 idx, GRID_T x) {\n"
109 " imageAtomicAdd(img, IMAGE_ADDR(idx), BASE_T(33));\n"
110 " return x;\n"
111 "}\n"),
112 "imageAtomicAdd");
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"
118 " return x;\n"
119 "}\n"),
120 "imageAtomicMin");
122 subtest(&status, true,
123 run_test(0, 33,
124 "GRID_T op(ivec2 idx, GRID_T x) {\n"
125 " imageAtomicMax(img, IMAGE_ADDR(idx), BASE_T(33));\n"
126 " return x;\n"
127 "}\n"),
128 "imageAtomicMax");
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"
134 " return x;\n"
135 "}\n"),
136 "imageAtomicAnd");
138 subtest(&status, true,
139 run_test(0, 33,
140 "GRID_T op(ivec2 idx, GRID_T x) {\n"
141 " imageAtomicOr(img, IMAGE_ADDR(idx), BASE_T(33));\n"
142 " return x;\n"
143 "}\n"),
144 "imageAtomicOr");
146 subtest(&status, true,
147 run_test(0, 33,
148 "GRID_T op(ivec2 idx, GRID_T x) {\n"
149 " imageAtomicXor(img, IMAGE_ADDR(idx), BASE_T(33));\n"
150 " return x;\n"
151 "}\n"),
152 "imageAtomicXor");
154 subtest(&status, true,
155 run_test(0, 33,
156 "GRID_T op(ivec2 idx, GRID_T x) {\n"
157 " imageAtomicExchange(img, IMAGE_ADDR(idx),"
158 " BASE_T(33));\n"
159 " return x;\n"
160 "}\n"),
161 "imageAtomicExchange");
163 subtest(&status, true,
164 run_test(0, 33,
165 "GRID_T op(ivec2 idx, GRID_T x) {\n"
166 " imageAtomicCompSwap(img, IMAGE_ADDR(idx),"
167 " BASE_T(0), BASE_T(33));\n"
168 " return x;\n"
169 "}\n"),
170 "imageAtomicCompSwap");
172 piglit_report_result(status);
175 enum piglit_result
176 piglit_display(void)
178 return PIGLIT_FAIL;