1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
/*
* Copyright © 2015 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/**
* \file atomic.c
*
* Test atomic counters with when a framebuffer with no attachments is bound.
*/
#include "piglit-util-gl.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_core_version = 31;
config.khr_no_error_support = PIGLIT_NO_ERRORS;
PIGLIT_GL_TEST_CONFIG_END
const char *vs_source =
"#version 140\n"
"in vec4 piglit_vertex;\n"
"void main() {\n"
" gl_Position = piglit_vertex;\n"
"}\n";
const char *fs_source =
"#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"layout(binding = 0, offset = 0) uniform atomic_uint counter;\n"
"void main() {\n"
" atomicCounterIncrement(counter);\n"
"}\n";
enum piglit_result
piglit_display(void)
{
return PIGLIT_FAIL;
}
static void
reset_counter()
{
/* Reset value of atomic counter. */
uint32_t *ptr =
(uint32_t *) glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0,
sizeof(uint32_t), GL_MAP_WRITE_BIT);
*ptr = 0;
glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
}
static bool
compare_counter(uint32_t value, const char *subtest)
{
/* Map atomic buffer and check that we have expected results. */
bool result = false;
uint32_t *ptr =
(uint32_t *) glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0,
sizeof(uint32_t), GL_MAP_READ_BIT);
result = (*ptr == value);
if (!result)
fprintf(stderr, "%s (subtest %s): expected %u, got %u\n",
__func__, subtest, value, *ptr);
glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
piglit_report_subtest_result(result ? PIGLIT_PASS : PIGLIT_FAIL,
"%s", subtest);
return result;
}
void
piglit_init(int argc, char **argv)
{
GLuint buffer, fbo, vao;
GLint prog;
bool pass = true;
uint32_t counter = 0;
piglit_require_gl_version(31);
piglit_require_extension("GL_ARB_framebuffer_no_attachments");
piglit_require_extension("GL_ARB_shader_atomic_counters");
/* Create fbo with no attachments. */
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
/* Setup default width and height. */
glFramebufferParameteri(GL_FRAMEBUFFER,
GL_FRAMEBUFFER_DEFAULT_WIDTH, piglit_width);
glFramebufferParameteri(GL_FRAMEBUFFER,
GL_FRAMEBUFFER_DEFAULT_HEIGHT, piglit_height);
/* Check that fbo is marked complete. */
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
GL_FRAMEBUFFER_COMPLETE)
piglit_report_result(PIGLIT_FAIL);
prog = piglit_build_simple_program(vs_source, fs_source);
/* Check that there are no errors. */
if (!prog || !piglit_check_gl_error(GL_NO_ERROR))
piglit_report_result(PIGLIT_FAIL);
glUseProgram(prog);
/* Create atomic counter buffer. */
glGenBuffers(1, &buffer);
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, buffer);
glBufferData(GL_ATOMIC_COUNTER_BUFFER,
sizeof(uint32_t), &counter, GL_DYNAMIC_DRAW);
if (!piglit_check_gl_error(GL_NO_ERROR))
piglit_report_result(PIGLIT_FAIL);
/* Render rectangle using our program. */
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
piglit_draw_rect(-1, -1, 2, 2);
pass &= compare_counter(piglit_width * piglit_height, "Basic");
/* Reset counter and set 1x1 scissor rectangle. */
reset_counter();
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, 1, 1);
piglit_draw_rect(-1, -1, 2, 2);
glDisable(GL_SCISSOR_TEST);
pass &= compare_counter(1, "glScissor");
/* Reset counter and set 2x2 viewport. */
reset_counter();
glViewport(0, 0, 2, 2);
piglit_draw_rect(-1, -1, 2, 2);
pass &= compare_counter(4, "glViewport");
/* Reset counter and add samples to the default fb */
reset_counter();
glViewport(0, 0, piglit_width, piglit_height);
glFramebufferParameteri(GL_FRAMEBUFFER,
GL_FRAMEBUFFER_DEFAULT_SAMPLES, 4);
piglit_draw_rect(-1, -1, 2, 2);
if (piglit_width == piglit_height) {
/* The seam gets double-drawn */
pass &= compare_counter((piglit_width + 1) * piglit_height,
"MS4");
} else {
piglit_report_subtest_result(PIGLIT_SKIP, "MS4");
}
if (piglit_is_extension_supported("GL_ARB_sample_shading")) {
/* Reset counter and enable per-sample shading */
reset_counter();
glEnable(GL_SAMPLE_SHADING_ARB);
glMinSampleShadingARB(1.0);
piglit_draw_rect(-1, -1, 2, 2);
pass &= compare_counter(piglit_width * piglit_height * 4,
"Per-sample");
} else {
piglit_report_subtest_result(PIGLIT_SKIP, "Per-sample");
}
glDeleteFramebuffers(1, &fbo);
glDeleteVertexArrays(1, &vao);
glDeleteBuffers(1, &buffer);
glDeleteProgram(prog);
piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
|