From: Christoph Bumiller <e0425...@student.tuwien.ac.at> Wrote this to figure out the sample positions on NVC0. Didn't find any test that checks if the driver reported sample positions match the behaviour of rendering.
It's probably a bit too crazy, but I thought I'd just send it in case anyone wants to make use of it. --- .../spec/arb_texture_multisample/CMakeLists.gl.txt | 1 + .../spec/arb_texture_multisample/sample-position.c | 207 ++++++++++++++++++++ 2 files changed, 208 insertions(+), 0 deletions(-) create mode 100644 tests/spec/arb_texture_multisample/sample-position.c diff --git a/tests/spec/arb_texture_multisample/CMakeLists.gl.txt b/tests/spec/arb_texture_multisample/CMakeLists.gl.txt index 1339d62..642418f 100644 --- a/tests/spec/arb_texture_multisample/CMakeLists.gl.txt +++ b/tests/spec/arb_texture_multisample/CMakeLists.gl.txt @@ -18,5 +18,6 @@ piglit_add_executable (arb_texture_multisample-sample-mask sample-mask.c) piglit_add_executable (arb_texture_multisample-sample-mask-value sample-mask-value.c) piglit_add_executable (arb_texture_multisample-sample-mask-execution sample-mask-execution.c) piglit_add_executable (arb_texture_multisample-negative-max-samples negative-max-samples.c) +piglit_add_executable (arb_texture_multisample-sample-position sample-position.c) # vim: ft=cmake: diff --git a/tests/spec/arb_texture_multisample/sample-position.c b/tests/spec/arb_texture_multisample/sample-position.c new file mode 100644 index 0000000..d67ad5b --- /dev/null +++ b/tests/spec/arb_texture_multisample/sample-position.c @@ -0,0 +1,207 @@ +/* + * Copyright © The Piglit Project 2013 + * + * 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. + * + * Authors: Christoph Bumiller + */ +#include "piglit-util-gl-common.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_core_version = 31; + config.window_visual = PIGLIT_GL_VISUAL_RGB; + +PIGLIT_GL_TEST_CONFIG_END + +#define NUM_STEPS 32 +#define MAX_SAMPLES 32 + +static GLuint tfb; +static GLuint buf; +static GLuint tex; +static GLuint fbo; +static GLuint prog; + +static int samples = 0; + +enum piglit_result +piglit_display(void) +{ + float mspos[MAX_SAMPLES][2]; + float *res; + const float inc = 2.0f / (float)NUM_STEPS; + GLint u; + unsigned int i, s; + GLint test; + + glUseProgram(prog); + + u = glGetUniformLocation(prog, "pos"); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex); + + for (i = 0; i < samples; ++i) + glGetMultisamplefv(GL_SAMPLE_POSITION, i, &mspos[i][0]); + + glUniform1i(glGetUniformLocation(prog, "tex"), 0); + glUniform1i(glGetUniformLocation(prog, "num_samples"), samples); + + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + glBeginTransformFeedback(GL_POINTS); + for (i = 0; i < NUM_STEPS; ++i) { + glPauseTransformFeedback(); + glClear(GL_COLOR_BUFFER_BIT); + glUniform2f(u, -1.0f + inc * (float)i, -1.0f); + glDrawArrays(GL_TRIANGLES, 0, 3); + glResumeTransformFeedback(); + + glTextureBarrierNV(); + glEnable(GL_RASTERIZER_DISCARD); + glDrawArrays(GL_POINTS, 0, 1); + glDisable(GL_RASTERIZER_DISCARD); + } + for (i = 0; i < NUM_STEPS; ++i) { + glPauseTransformFeedback(); + glClear(GL_COLOR_BUFFER_BIT); + glUniform2f(u, -1.0f, -1.0f + inc * (float)i); + glDrawArrays(GL_TRIANGLES, 0, 3); + glResumeTransformFeedback(); + + glTextureBarrierNV(); + glEnable(GL_RASTERIZER_DISCARD); + glDrawArrays(GL_POINTS, 0, 1); + glDisable(GL_RASTERIZER_DISCARD); + } + glEndTransformFeedback(); + + res = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, GL_READ_ONLY); + + for (i = 0; i < NUM_STEPS; ++i) { + float p = (float)i / (float)NUM_STEPS; + + int base_x = i * MAX_SAMPLES; + int base_y = i * MAX_SAMPLES + NUM_STEPS * MAX_SAMPLES; + + fprintf(stderr, "x >= %f:", p); + for (s = 0; s < samples; ++s) + if (res[base_x + s] == 1.0f) + fprintf(stderr, " %u", s); + fprintf(stderr, "\n"); + fprintf(stderr, "y >= %f:", p); + for (s = 0; s < samples; ++s) + if (res[base_y + s] == 1.0f) + fprintf(stderr, " %u", s); + fprintf(stderr, "\n"); + + for (s = 0; s < samples; ++s) { + if ((p > mspos[s][0] && res[base_x + s] == 1.0f) || + (p <= mspos[s][0] && res[base_x + s] != 1.0f)) + fprintf(stderr, "sample %i x position (%f, %f) " + "incorrect !\n",s, + mspos[s][0], mspos[s][1]); + if ((p > mspos[s][1] && res[base_y + s] == 1.0f) || + (p <= mspos[s][1] && res[base_y + s] != 1.0f)) + fprintf(stderr, "sample %i y position (%f, %f) " + "incorrect !\n",s, + mspos[s][0], mspos[s][1]); + } + } + glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER); + + return PIGLIT_PASS; +} + +static const char *vsSource = "#version 140 \n" + "#extension GL_ARB_texture_multisample : require\n" + "uniform sampler2DMS tex; \n" + "uniform int num_samples; \n" + "uniform vec2 pos; \n" + "out float sample[32]; \n" /* MAX_SAMPLES */ + "void main() { \n" + " int v = int(gl_VertexID); \n" /* if I can't have immediate mode ... */ + " int i; \n" + " gl_Position.xy = pos + 8.0 * vec2(float(v & 1), float(v & 2)); \n" + " gl_Position.zw = vec2(0.0, 1.0); \n" + " for (i = 0; i < 32; ++i) \n" + " sample[i] = texelFetch(tex, ivec2(0, 0), i).g; \n" + "} \n"; + +static const char *fsSource = "#version 140 \n" + "void main() { \n" + " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); \n" + "} \n"; + +void +piglit_init(int argc, char **argv) +{ + static const char *varyings[] = { "sample" }; + GLuint vs, fs; + GLint test; + + piglit_require_extension("GL_ARB_texture_multisample"); + piglit_require_extension("GL_NV_texture_barrier"); + + if (argc < 2) { + fprintf(stderr, "texelFetch <sample_count>\n"); + exit(0); + } + samples = strtoul(argv[1], NULL, 0); + + vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vsSource); + fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fsSource); + prog = piglit_link_simple_program(vs, fs); + + glGenTransformFeedbacks(1, &tfb); + glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfb); + glTransformFeedbackVaryings(prog, 1, varyings, GL_INTERLEAVED_ATTRIBS); + glLinkProgram(prog); + glGenBuffers(1, &buf); + glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf); + glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, + MAX_SAMPLES * sizeof(float) * NUM_STEPS * 2, NULL, + GL_STREAM_DRAW); + glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf); + + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex); + glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, + GL_RGBA8, + 1, 1, GL_TRUE); + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D_MULTISAMPLE, tex, 0); + + glGetIntegerv(GL_SAMPLES, &test); + fprintf(stderr, "samples = %u\n", test); + + assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); + + glGetIntegerv(GL_SAMPLES, &test); + fprintf(stderr, "samples = %u (post check)\n", test); + + glViewport(0, 0, 1, 1); + + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); +} -- 1.7.3.4 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/piglit