[Piglit] [PATCH] glsl-1.10/fragdepth: add new, simple test of gl_FragDepth

Brian Paul brianp at vmware.com
Fri Aug 8 05:30:04 PDT 2014


On 08/07/2014 04:17 PM, Anuj Phogat wrote:
> On Tue, Aug 5, 2014 at 3:07 PM, Brian Paul <brianp at vmware.com> wrote:
>> ---
>>   tests/all.py                                     |    1 +
>>   tests/spec/glsl-1.10/execution/CMakeLists.gl.txt |    1 +
>>   tests/spec/glsl-1.10/execution/fragdepth.c       |  115 ++++++++++++++++++++++
>>   3 files changed, 117 insertions(+)
>>   create mode 100644 tests/spec/glsl-1.10/execution/fragdepth.c
>>
>> diff --git a/tests/all.py b/tests/all.py
>> index 9d7a861..36436b8 100644
>> --- a/tests/all.py
>> +++ b/tests/all.py
>> @@ -1002,6 +1002,7 @@ add_shader_test_dir(spec['glsl-1.10']['execution'],
>>                       os.path.join(testsDir, 'spec', 'glsl-1.10', 'execution'),
>>                       recursive=True)
>>   add_concurrent_test(spec['glsl-1.10']['execution'], 'glsl-render-after-bad-attach')
>> +add_concurrent_test(spec['glsl-1.10']['execution'], 'glsl-1.10-fragdepth')
>>   spec['glsl-1.10']['execution']['clipping'] = {}
>>   for mode in ['fixed', 'pos_clipvert', 'clipvert_pos']:
>>       cmdline = 'clip-plane-transformation ' + mode
>> diff --git a/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt b/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt
>> index 311fe01..0ddc221 100644
>> --- a/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt
>> +++ b/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt
>> @@ -12,3 +12,4 @@ link_libraries (
>>   )
>>
>>   piglit_add_executable (glsl-render-after-bad-attach glsl-render-after-bad-attach.c)
>> +piglit_add_executable (glsl-1.10-fragdepth fragdepth.c)
>> diff --git a/tests/spec/glsl-1.10/execution/fragdepth.c b/tests/spec/glsl-1.10/execution/fragdepth.c
>> new file mode 100644
>> index 0000000..61521ca
>> --- /dev/null
>> +++ b/tests/spec/glsl-1.10/execution/fragdepth.c
>> @@ -0,0 +1,115 @@
>> +/*
>> + * Copyright 2014 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.
>> + */
>> +
>> +/**
>> + * Test GLSL gl_FragDepth output.
>> + * We draw overlapping red and green quads.  The red quad is at Z=0
>> + * while the green quad's fragment depths vary from left to right.
>> + * Should see intersecting quads.
>> + *
>> + * Brian Paul
>> + * 5 August 2014
>> + */
>> +
>> +
>> +#include "piglit-util-gl.h"
>> +
>> +PIGLIT_GL_TEST_CONFIG_BEGIN
>> +       config.supports_gl_compat_version = 20;
>> +       config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
> Also use PIGLIT_GL_VISUAL_DEPTH. Without it test fails on i965. I
> don't know why but it passed
> on NVIDIA as it is.
>
>> +PIGLIT_GL_TEST_CONFIG_END
>> +
>> +
>> +static const char *vs_text =
>> +       "varying float z; \n"
>> +       "void main() {\n"
>> +       "   gl_FrontColor = gl_Color; \n"
>> +       "   gl_Position = gl_Vertex;\n"
>> +       "   // convert Z from [-1, 1] to [0, 1] \n"
>> +       "   z = gl_Vertex.x * 0.5 + 0.5; \n"
>> +       "}\n";
>> +static const char *fs_text =
>> +       "varying float z; \n"
>> +       "void main() { \n"
>> +       "   gl_FragDepth = z; \n"
>> +       "   gl_FragColor = gl_Color; \n"
>> +       "}\n";
>> +
>> +static GLuint program;
>> +
>> +
>> +enum piglit_result
>> +piglit_display(void)
>> +{
>> +       static const float red[3] = {1.0, 0.0, 0.0};
>> +       static const float green[3] = {0.0, 1.0, 0.0};
>> +       int x = piglit_width / 2;
>> +       int y = piglit_height / 2;
>> +
>> +       glViewport(0, 0, piglit_width, piglit_height);
>> +       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>> +
>> +       /* Draw a red quad at z = 0 */
> It took me a minute to realize that z = 0 will be actually z = 0.5
> after converting
> from range [-1, 1] to [0, 1]. I'll leave it to you if you want to add
> this to the comment.
>
>> +       glUseProgram(0);
>> +       glColor3f(1, 0, 0);
>> +       glBegin(GL_TRIANGLE_FAN);
>> +       glVertex2f(-0.5, -0.5);
>> +       glVertex2f( 0.5, -0.5);
>> +       glVertex2f( 0.5,  0.5);
>> +       glVertex2f(-0.5,  0.5);
>> +       glEnd();
>> +
>> +       /* Draw green quad w/ fragment shader which writes gl_FragDepth*/
>> +       glUseProgram(program);
>> +       glColor3f(0, 1, 0);
>> +       glBegin(GL_TRIANGLE_FAN);
>> +       glVertex2f(-0.75, -0.25);
>> +       glVertex2f( 0.75, -0.25);
>> +       glVertex2f( 0.75,  0.25);
>> +       glVertex2f(-0.75,  0.25);
>> +       glEnd();
>> +
>> +       if (!piglit_probe_pixel_rgb(x-10, y, green)) {
>> +               return PIGLIT_FAIL;
>> +       }
>> +
>> +       if (!piglit_probe_pixel_rgb(x+10, y, red)) {
>> +               return PIGLIT_FAIL;
>> +       }
> In case of failure, returning here will show nothing on the screen. Use a flag
> to track pass/fail status and return at the end of the function?
>
>> +
>> +       piglit_present_results();
>> +
>> +       return PIGLIT_PASS;
>> +}
>> +
>> +
>> +void
>> +piglit_init(int argc, char **argv)
>> +{
>> +       piglit_require_GLSL();
>> +
>> +       program = piglit_build_simple_program(vs_text, fs_text);
>> +
>> +       glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
>> +       glEnable(GL_DEPTH_TEST);
>> +}
>> --
>> 1.7.10.4
>>
>> _______________________________________________
>> Piglit mailing list
>> Piglit at lists.freedesktop.org
>> https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/piglit&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=lGQMzzTgII0I7jefp2FHq7WtZ%2BTLs8wadB%2BiIj9xpBY%3D%0A&m=P471L5imjyqJtj55LUFTdT9JotOplKEksZEXUqUxyhU%3D%0A&s=b7a245664ae41e862a3af9b592ff6ea7d4e0b855a17427a6c5a0bc425fdfcad0
>
> With above comments fixed, patch is:
> Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>

Thanks.  I've made the fixes you suggested.

-Brian




More information about the Piglit mailing list