[Piglit] [PATCH] gl-3.2-depth-tex-sampling: test OpenGL 3.2 core depth texture sampling

Marek Olšák maraeo at gmail.com
Sat Dec 21 16:01:23 PST 2013


This test is wrong. The section 3.8.7 (page 160) of the GL 3.2 core
specification says:

"Depth textures and the depth components of depth/stencil textures can
be treated as RED textures during texture filtering and application
(see section 3.8.15). The initial state for depth and depth/stencil
textures treats them as RED textures."

Your cited text from Appendix E is confusing and can be ignored. Sorry
that I didn't review this earlier.

I fixed this in Mesa some time ago:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a6b1a7c0d269256ffbaf2300710601cde8ac872c

Marek

On Thu, Dec 5, 2013 at 11:26 PM, Brian Paul <brianp at vmware.com> wrote:
> The spec says (d,d,d,1) should be returned.  NVIDIA's current driver fails.
> ---
>  tests/all.tests                        |    1 +
>  tests/spec/gl-3.2/CMakeLists.gl.txt    |    1 +
>  tests/spec/gl-3.2/depth-tex-sampling.c |  211 ++++++++++++++++++++++++++++++++
>  3 files changed, 213 insertions(+)
>  create mode 100644 tests/spec/gl-3.2/depth-tex-sampling.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 014f8d9..5f0ceb2 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -729,6 +729,7 @@ gl31['required-texture-attachment-formats'] = concurrent_test('gl-3.0-required-t
>
>  spec['!OpenGL 3.2/minmax'] = concurrent_test('gl-3.2-minmax')
>  spec['!OpenGL 3.2/clear-no-buffers'] = concurrent_test('gl-3.2-clear-no-buffers')
> +spec['!OpenGL 3.2/depth-tex-sampling'] = concurrent_test('gl-3.2-depth-tex-sampling')
>  spec['!OpenGL 3.2/get-buffer-parameter-i64v'] = concurrent_test('gl-3.2-get-buffer-parameter-i64v')
>  spec['!OpenGL 3.2/get-integer-64iv'] = concurrent_test('gl-3.2-get-integer-64iv')
>  spec['!OpenGL 3.2/get-integer-64v'] = concurrent_test('gl-3.2-get-integer-64v')
> diff --git a/tests/spec/gl-3.2/CMakeLists.gl.txt b/tests/spec/gl-3.2/CMakeLists.gl.txt
> index c8725be..595cc10 100644
> --- a/tests/spec/gl-3.2/CMakeLists.gl.txt
> +++ b/tests/spec/gl-3.2/CMakeLists.gl.txt
> @@ -11,6 +11,7 @@ link_libraries (
>
>  piglit_add_executable (gl-3.2-minmax minmax.c)
>  piglit_add_executable (gl-3.2-clear-no-buffers clear-no-buffers.c)
> +piglit_add_executable (gl-3.2-depth-tex-sampling depth-tex-sampling.c)
>  piglit_add_executable (gl-3.2-get-buffer-parameter-i64v get-buffer-parameter-i64v.c)
>  piglit_add_executable (gl-3.2-get-integer-64iv get-integer-64iv.c)
>  piglit_add_executable (gl-3.2-get-integer-64v get-integer-64v.c)
> diff --git a/tests/spec/gl-3.2/depth-tex-sampling.c b/tests/spec/gl-3.2/depth-tex-sampling.c
> new file mode 100644
> index 0000000..7d2988c
> --- /dev/null
> +++ b/tests/spec/gl-3.2/depth-tex-sampling.c
> @@ -0,0 +1,211 @@
> +/*
> + * Copyright (c) 2013 VMware, Inc.
> + *
> + * 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.
> + */
> +
> +/*
> + * In the GL 3.2 core profile, GL_DEPTH_TEXTURE_MODE is deprecated.
> + * Sampling a depth texture should always return (d, d, d, 1) which
> + * corresponds to the legacy GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE.
> + *
> + * NVIDIA's driver, however, seems to return (d, 0, 0, 1).
> + *
> + * From the OpenGL 3.2 specification, page 332:
> + *  "Depth texture mode - DEPTH_TEXTURE_MODE. Section 3.8.15 is to be
> + *   changed so that r is returned to texture samplers directly, and
> + *   the OpenGL Shading Language 1.30 Specification is to be changed
> + *   so that (r,r,r,1) is always returned from depth texture samplers
> + *   in this case."
> + *
> + * Brian Paul
> + * 5 Dec 2013
> + */
> +
> +
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +       config.supports_gl_core_version = 32;
> +       config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +
> +#define TEX_SIZE 64
> +
> +static GLuint tex, prog, vao;
> +
> +
> +static GLuint
> +make_depth_texture(void)
> +{
> +       GLfloat texels[TEX_SIZE][TEX_SIZE];
> +       GLuint tex, i, j;
> +       GLenum format = GL_DEPTH_COMPONENT;
> +
> +       /* Z = 0 at bottom, Z = 1 at top */
> +       for (i = 0; i < TEX_SIZE; i++) {
> +               for (j = 0; j < TEX_SIZE; j++) {
> +                       float z = i / (float) (TEX_SIZE - 1);
> +                       texels[i][j] = z;
> +               }
> +       }
> +
> +       glGenTextures(1, &tex);
> +       glBindTexture(GL_TEXTURE_2D, tex);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
> +
> +       glTexImage2D(GL_TEXTURE_2D, 0, format,
> +                    TEX_SIZE, TEX_SIZE, 0,
> +                    format, GL_FLOAT, texels);
> +
> +       piglit_check_gl_error(GL_NO_ERROR);
> +
> +       /* this call should generate an error in the core profile */
> +       glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
> +       if (!piglit_check_gl_error(GL_INVALID_ENUM)) {
> +               piglit_report_result(PIGLIT_FAIL);
> +       }
> +
> +       return tex;
> +}
> +
> +
> +static GLuint
> +make_shader_program(void)
> +{
> +       static const char *vs_text =
> +               "#version 150\n"
> +               "in vec4 pos_in;\n"
> +               "in vec2 texcoord_in;\n"
> +               "smooth out vec2 texcoord;\n"
> +               "void main()\n"
> +               "{\n"
> +               "   gl_Position = pos_in;\n"
> +               "   texcoord = texcoord_in;\n"
> +               "}\n";
> +       static const char *fs_text =
> +               "#version 150\n"
> +               "uniform sampler2D tex;\n"
> +               "smooth in vec2 texcoord;\n"
> +               "out vec4 color;\n"
> +               "void main()\n"
> +               "{\n"
> +               "   color = texture(tex, texcoord);\n"
> +               "   // enabling the next line fixes NVIDIA failure\n"
> +               "   // color = vec4(vec3(color.x), 1.0);\n"
> +               "}\n";
> +
> +       GLuint prog;
> +       GLint u;
> +
> +       prog = piglit_build_simple_program(vs_text, fs_text);
> +       glUseProgram(prog);
> +
> +       u = glGetUniformLocation(prog, "tex");
> +       glUniform1i(u, 0);  /* bind tex unit 0, just to be safe */
> +
> +       glBindAttribLocation(prog, 0, "pos_in");
> +       glBindAttribLocation(prog, 1, "texcoord_in");
> +
> +       glLinkProgram(prog);
> +
> +       piglit_check_gl_error(GL_NO_ERROR);
> +
> +       return prog;
> +}
> +
> +
> +static GLuint
> +make_vao(void)
> +{
> +       static const float pos_tc[4][4] = {
> +               { -1.0, -1.0,  0.0, 0.0 },
> +               {  1.0, -1.0,  1.0, 0.0 },
> +               {  1.0,  1.0,  1.0, 1.0 },
> +               { -1.0,  1.0,  0.0, 1.0 }
> +       };
> +       const int stride = sizeof(pos_tc[0]);
> +       GLuint vbo, vao;
> +
> +       glGenVertexArrays(1, &vao);
> +       glBindVertexArray(vao);
> +
> +       glGenBuffers(1, &vbo);
> +       glBindBuffer(GL_ARRAY_BUFFER, vbo);
> +       glBufferData(GL_ARRAY_BUFFER, sizeof(pos_tc), pos_tc, GL_STATIC_DRAW);
> +       piglit_check_gl_error(GL_NO_ERROR);
> +
> +       glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, stride, (void *) 0);
> +       glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, stride, (void *) 8);
> +
> +       glEnableVertexAttribArray(0);
> +       glEnableVertexAttribArray(1);
> +
> +       piglit_check_gl_error(GL_NO_ERROR);
> +
> +       return vbo;
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +       tex = make_depth_texture();
> +       prog = make_shader_program();
> +       vao = make_vao();
> +}
> +
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +       static const float black[4] = { 0.0, 0.0, 0.0, 1.0 };
> +       static const float white[4] = { 1.0, 1.0, 1.0, 1.0 };
> +       static const float gray[4] = { 0.5, 0.5, 0.5, 1.0 };
> +       bool pass = true;
> +
> +       glViewport(0, 0, piglit_width, piglit_height);
> +
> +       /* This should draw a grayscale gradient ranging from black
> +        * at the bottom of the window to white at the top.
> +        */
> +       glClearColor(0.2, 0.2, 0.8, 1.0);
> +       glClear(GL_COLOR_BUFFER_BIT);
> +       glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
> +
> +       if (!piglit_probe_pixel_rgba(0, 0, black))
> +               pass = false;
> +
> +       if (!piglit_probe_pixel_rgba(0, piglit_height/2, gray))
> +               pass = false;
> +
> +       if (!piglit_probe_pixel_rgba(0, piglit_height-1, white))
> +               pass = false;
> +
> +       piglit_present_results();
> +
> +       piglit_check_gl_error(GL_NO_ERROR);
> +
> +       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> --
> 1.7.10.4
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list