ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_shader_atomic_counters / respecify-buffer.c
blobe601ff87814f918decaf7d0e12a1de8c8df5163e
1 /*
2 * Copyright © 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 respecify-buffer.c
26 * Tests that the required state is reemitted when the buffer backing
27 * an atomic counter is respecified; taking care not to dirty too much
28 * other state which would mask flagging problems.
30 * This demonstrates a mesa bug.
33 #include "common.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_core_version = 31;
39 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
40 config.khr_no_error_support = PIGLIT_NO_ERRORS;
42 PIGLIT_GL_TEST_CONFIG_END
44 int data[] = { 0, 1, 2, 3 };
46 float red[] = { 1, 0, 0 };
47 float green[] = { 0, 1, 0 };
48 float blue[] = { 0, 0, 1 };
49 float white[] = { 1, 1, 1 };
51 enum piglit_result
52 piglit_display(void)
54 bool pass;
55 int i;
57 glViewport(0, 0, piglit_width, piglit_height);
59 glClearColor(0.2, 0.2, 0.2, 0.2);
60 glClear(GL_COLOR_BUFFER_BIT);
62 for (i = 0; i < 4; i++) {
63 /* respecify the buffer */
64 glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(*data),
65 &data[i], GL_STATIC_DRAW);
67 piglit_draw_rect(i % 2 - 1, i / 2 - 1, 1, 1);
70 pass = piglit_probe_pixel_rgb(piglit_width / 4,
71 piglit_height / 4, red);
72 pass = piglit_probe_pixel_rgb(3 * piglit_width / 4,
73 piglit_height / 4, green) && pass;
74 pass = piglit_probe_pixel_rgb(piglit_width / 4,
75 3 * piglit_height / 4, blue) && pass;
76 pass = piglit_probe_pixel_rgb(3 * piglit_width / 4,
77 3 * piglit_height / 4, white) && pass;
79 piglit_present_results();
81 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
84 void
85 piglit_init(int argc, char **argv)
87 GLuint prog;
88 GLuint abo;
90 piglit_require_extension("GL_ARB_shader_atomic_counters");
92 prog = piglit_build_simple_program(
93 "#version 140\n"
94 "in vec4 piglit_vertex;\n"
95 "void main() {\n"
96 " gl_Position = piglit_vertex;\n"
97 "}\n",
99 "#version 140\n"
100 "#extension GL_ARB_shader_atomic_counters: require\n"
101 "layout(binding=0) uniform atomic_uint x;\n"
102 "void main() {\n"
103 " uint n = atomicCounter(x);\n"
104 " if (n == 0u) gl_FragColor = vec4(1,0,0,0);\n"
105 " else if (n == 1u) gl_FragColor = vec4(0,1,0,0);\n"
106 " else if (n == 2u) gl_FragColor = vec4(0,0,1,0);\n"
107 " else gl_FragColor = vec4(1,1,1,0);\n"
108 "}\n");
110 glUseProgram(prog);
112 glGenBuffers(1, &abo);
113 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, abo);
114 glBufferData(GL_ATOMIC_COUNTER_BUFFER, 4, NULL, GL_STATIC_DRAW);
115 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, abo);