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
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 * Common utility functions for the ARB_shader_atomic_counters tests.
32 atomic_counters_probe_buffer(unsigned base
, unsigned count
,
33 const uint32_t *expected
)
35 uint32_t *p
= glMapBufferRange(
36 GL_ATOMIC_COUNTER_BUFFER
, base
* sizeof(uint32_t),
37 count
* sizeof(uint32_t), GL_MAP_READ_BIT
);
42 printf("Couldn't map atomic counter buffer for read-back.\n");
46 for (i
= 0; i
< count
; ++i
) {
47 uint32_t found
= p
[i
];
48 if (found
!= expected
[i
]) {
49 printf("Probe value at (%i)\n", i
);
50 printf(" Expected: 0x%08x\n", expected
[i
]);
51 printf(" Observed: 0x%08x\n", found
);
57 glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER
);
62 atomic_counters_compile(GLuint prog
, GLuint stage
, const char *src
)
64 GLuint shader
= glCreateShader(stage
);
68 glShaderSource(shader
, 1, (const GLchar
**)&src
, NULL
);
69 glCompileShader(shader
);
71 glGetShaderiv(shader
, GL_COMPILE_STATUS
, &status
);
74 glAttachShader(prog
, shader
);
76 glGetShaderiv(shader
, GL_INFO_LOG_LENGTH
, &log_size
);
77 log
= malloc(log_size
);
78 glGetShaderInfoLog(shader
, log_size
, NULL
, log
);
80 printf("Failed to compile shader: %s\n", log
);
81 printf("source:\n%s", src
);
86 glDeleteShader(shader
);
92 atomic_counters_link(GLuint prog
)
96 glGetProgramiv(prog
, GL_LINK_STATUS
, &status
);
99 glGetProgramiv(prog
, GL_LINK_STATUS
, &status
);
106 atomic_counters_draw_point(GLuint prog
, unsigned buf_size
,
111 /* Initialize the atomic counter buffer. */
112 glBufferData(GL_ATOMIC_COUNTER_BUFFER
,
113 buf_size
* sizeof(uint32_t),
114 buf
, GL_STATIC_DRAW
);
116 /* Link and set the current shader program. */
117 atomic_counters_link(prog
);
121 glClearColor(0.5, 0.5, 0.5, 0.5);
122 glClear(GL_COLOR_BUFFER_BIT
);
124 glGenVertexArrays(1, &vao
);
125 glBindVertexArray(vao
);
126 glVertexAttrib4f(0, 0, 0, 0, 1);
128 glDrawArrays(GL_POINTS
, 0, 1);
130 glDeleteVertexArrays(1, &vao
);
132 return piglit_check_gl_error(GL_NO_ERROR
);
136 atomic_counters_draw_rect(GLuint prog
, unsigned buf_size
, const uint32_t *buf
)
138 /* Initialize the atomic counter buffer. */
139 glBufferData(GL_ATOMIC_COUNTER_BUFFER
,
140 buf_size
* sizeof(uint32_t),
141 buf
, GL_STATIC_DRAW
);
143 /* Set current shader program. */
148 glClearColor(0.5, 0.5, 0.5, 0.5);
149 glClear(GL_COLOR_BUFFER_BIT
);
151 piglit_draw_rect(-1, -1, 2, 2);
153 return piglit_check_gl_error(GL_NO_ERROR
);
157 atomic_counters_draw_patch(GLuint prog
, unsigned buf_size
,
161 const GLfloat verts
[3][4] = { { 0.0, 0.0, 0.0, 1.0 },
162 { 1.0, 0.0, 0.0, 1.0 },
163 { 0.0, 1.0, 0.0, 1.0 } };
166 /* Initialize the atomic counter buffer. */
167 glBufferData(GL_ATOMIC_COUNTER_BUFFER
,
168 buf_size
* sizeof(uint32_t),
169 buf
, GL_STATIC_DRAW
);
171 /* Set current shader program. */
175 /* Initialize a vertex array object and a vertex buffer object. */
176 glGenVertexArrays(1, &vao
);
177 glBindVertexArray(vao
);
178 glGenBuffers(1, &vbo
);
179 glBindBuffer(GL_ARRAY_BUFFER
, vbo
);
180 glBufferData(GL_ARRAY_BUFFER
, sizeof(verts
), verts
, GL_STATIC_DRAW
);
182 /* Set up the current vertex attributes. */
183 glVertexAttribPointer(PIGLIT_ATTRIB_POS
, 4, GL_FLOAT
,
185 glEnableVertexAttribArray(PIGLIT_ATTRIB_POS
);
188 glClearColor(0.5, 0.5, 0.5, 0.5);
189 glClear(GL_COLOR_BUFFER_BIT
);
191 glDrawArrays(GL_PATCHES
, 0, 3);
194 glDisableVertexAttribArray(PIGLIT_ATTRIB_POS
);
195 glDeleteBuffers(1, &vbo
);
196 glDeleteVertexArrays(1, &vao
);
198 return piglit_check_gl_error(GL_NO_ERROR
);
202 atomic_counters_supported(GLenum shader_stage
)
206 switch (shader_stage
) {
208 case GL_FRAGMENT_SHADER
:
211 case GL_VERTEX_SHADER
:
212 glGetIntegerv(GL_MAX_VERTEX_ATOMIC_COUNTERS
, &n
);
215 case GL_GEOMETRY_SHADER
:
216 if (piglit_get_gl_version() >= 32)
217 glGetIntegerv(GL_MAX_GEOMETRY_ATOMIC_COUNTERS
, &n
);
220 case GL_TESS_CONTROL_SHADER
:
221 if (piglit_is_extension_supported("GL_ARB_tessellation_shader"))
222 glGetIntegerv(GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS
, &n
);
225 case GL_TESS_EVALUATION_SHADER
:
226 if (piglit_is_extension_supported("GL_ARB_tessellation_shader"))
227 glGetIntegerv(GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS
,
232 assert(!"Unreachable");
237 struct atomic_counters_limits
238 atomic_counters_get_limits()
240 struct atomic_counters_limits ls
= { 0 };
242 piglit_require_extension("GL_ARB_shader_atomic_counters");
244 glGetIntegerv(GL_MAX_FRAGMENT_ATOMIC_COUNTERS
,
245 &ls
.fragment_counters
);
246 glGetIntegerv(GL_MAX_VERTEX_ATOMIC_COUNTERS
,
247 &ls
.vertex_counters
);
248 glGetIntegerv(GL_MAX_COMBINED_ATOMIC_COUNTERS
,
249 &ls
.combined_counters
);
250 glGetIntegerv(GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS
,
251 &ls
.fragment_buffers
);
252 glGetIntegerv(GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS
,
254 glGetIntegerv(GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS
,
255 &ls
.combined_buffers
);
256 glGetIntegerv(GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS
,
258 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS
,
259 &ls
.uniform_components
);