ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_shader_atomic_counters / buffer-binding.c
blobde4e9d16a358acbf8aac4d69e753c36c50d7538f
1 /*
2 * Copyright © 2013 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 buffer-binding.c
26 * Test that glBindBufferBase() and glBindBufferRange() have the
27 * necessary error checking for atomic counter buffers and that they
28 * update the buffer metadata correctly.
31 #include "common.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_core_version = 31;
37 config.window_width = 1;
38 config.window_height = 1;
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 static bool
45 run_test_bind_at(unsigned i)
47 GLuint buffer;
49 glGenBuffers(1, &buffer);
51 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, i, buffer);
52 if (glGetError())
53 return false;
55 glBufferData(GL_ATOMIC_COUNTER_BUFFER, 4, NULL, GL_STATIC_DRAW);
56 glDeleteBuffers(1, &buffer);
58 return !glGetError();
61 static bool
62 run_test_bind_range(unsigned i)
64 GLuint buffer;
65 GLint binding;
66 GLint start, size;
68 glGenBuffers(1, &buffer);
70 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, i, buffer);
71 if (!piglit_check_gl_error(GL_NO_ERROR)) {
72 printf("Initial buffer binding failed.\n");
73 return false;
76 glBufferData(GL_ATOMIC_COUNTER_BUFFER, 16, NULL, GL_STATIC_DRAW);
78 if (!piglit_khr_no_error) {
79 glBindBufferRange(GL_ATOMIC_COUNTER_BUFFER, i, buffer, 6, 5);
80 if (!piglit_check_gl_error(GL_INVALID_VALUE)) {
81 printf("Misaligned buffer range binding didn't "
82 "generate a GL_INVALID_VALUE error.\n");
83 return false;
87 glBindBufferRange(GL_ATOMIC_COUNTER_BUFFER, i, buffer, 8, 5);
88 if (!piglit_check_gl_error(GL_NO_ERROR)) {
89 printf("Buffer range binding failed.\n");
90 return false;
93 glGetIntegerv(GL_ATOMIC_COUNTER_BUFFER_BINDING, &binding);
94 if (!piglit_check_gl_error(GL_NO_ERROR) ||
95 binding != buffer) {
96 printf("Unexpected generic counter buffer binding: 0x%x.\n",
97 binding);
98 return false;
101 glGetIntegeri_v(GL_ATOMIC_COUNTER_BUFFER_BINDING, i, &binding);
102 if (!piglit_check_gl_error(GL_NO_ERROR) ||
103 binding != buffer) {
104 printf("Unexpected counter buffer binding %d: 0x%x.\n",
105 i, binding);
106 return false;
109 glGetIntegeri_v(GL_ATOMIC_COUNTER_BUFFER_START, i, &start);
110 if (!piglit_check_gl_error(GL_NO_ERROR) ||
111 start != 8) {
112 printf("Unexpected counter buffer offset 0x%x.\n",
113 (unsigned)start);
114 return false;
117 glGetIntegeri_v(GL_ATOMIC_COUNTER_BUFFER_SIZE, i, &size);
118 if (!piglit_check_gl_error(GL_NO_ERROR) ||
119 size != 5) {
120 printf("Unexpected counter buffer size: 0x%x.\n",
121 (unsigned)size);
122 return false;
125 glDeleteBuffers(1, &buffer);
127 return true;
130 void
131 piglit_init(int argc, char **argv)
133 struct atomic_counters_limits ls = atomic_counters_get_limits();
134 enum piglit_result status = PIGLIT_PASS;
136 piglit_require_gl_version(31);
137 piglit_require_extension("GL_ARB_shader_atomic_counters");
139 atomic_counters_subtest(&status, GL_NONE,
140 "Atomic buffer binding below the "
141 "implementation limit",
142 run_test_bind_at, ls.bindings - 1);
144 if (!piglit_khr_no_error) {
145 atomic_counters_subtest(&status, GL_NONE,
146 "Atomic buffer binding above the "
147 "implementation limit",
148 !run_test_bind_at, ls.bindings);
151 atomic_counters_subtest(&status, GL_NONE,
152 "Atomic buffer range binding",
153 run_test_bind_range, ls.bindings - 1);
155 piglit_report_result(status);
158 enum piglit_result
159 piglit_display(void)
161 return PIGLIT_PASS;