<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 1, 2014 at 3:05 PM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div>On Tuesday, July 01, 2014 12:53:18 PM Cody Northrop wrote:<br>

> Add a test that ensures fragment discard while loading from<br>
> uniform buffer objects works correctly.  At time of submission,<br>
> this test fails on i965.<br>
><br>
> Test will work with the following patch, sent to mesa-dev:<br>
><br>
> i965/fs: Update discard jump to preserve uniform loads via sampler.<br>
><br>
> Signed-off-by: Cody Northrop <<a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a>><br>
> Reviewed-by:  Courtney Goeltzenleuchter <<a href="mailto:courtney@lunarg.com" target="_blank">courtney@lunarg.com</a>><br>
> ---<br>
>  tests/all.py                                       |   1 +<br>
>  .../arb_uniform_buffer_object/CMakeLists.gl.txt    |   1 +<br>
>  .../arb_uniform_buffer_object/rendering-discard.c  | 195<br>
+++++++++++++++++++++<br>
>  3 files changed, 197 insertions(+)<br>
>  create mode 100644 tests/spec/arb_uniform_buffer_object/rendering-discard.c<br>
><br>
> diff --git a/tests/all.py b/tests/all.py<br>
> index 17d5d9b..04ae9e5 100644<br>
> --- a/tests/all.py<br>
> +++ b/tests/all.py<br>
> @@ -2965,6 +2965,7 @@ arb_uniform_buffer_object['negative-<br>
getactiveuniformblockiv'] = concurrent_test(<br>
>  arb_uniform_buffer_object['negative-getactiveuniformsiv'] =<br>
concurrent_test('arb_uniform_buffer_object-negative-getactiveuniformsiv')<br>
>  arb_uniform_buffer_object['referenced-by-shader'] =<br>
concurrent_test('arb_uniform_buffer_object-referenced-by-shader')<br>
>  arb_uniform_buffer_object['rendering'] =<br>
concurrent_test('arb_uniform_buffer_object-rendering')<br>
> +arb_uniform_buffer_object['rendering-discard'] =<br>
concurrent_test('arb_uniform_buffer_object-rendering-discard')<br>
>  arb_uniform_buffer_object['row-major'] =<br>
concurrent_test('arb_uniform_buffer_object-row-major')<br>
>  arb_uniform_buffer_object['uniformblockbinding'] =<br>
concurrent_test('arb_uniform_buffer_object-uniformblockbinding')<br>
><br>
> diff --git a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt<br>
b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt<br>
> index 7d65e2d..6bc3976 100644<br>
> --- a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt<br>
> +++ b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt<br>
> @@ -39,6 +39,7 @@ piglit_add_executable (arb_uniform_buffer_object-negative-<br>
getactiveuniformblocki<br>
>  piglit_add_executable (arb_uniform_buffer_object-negative-<br>
getactiveuniformsiv negative-getactiveuniformsiv.c)<br>
>  piglit_add_executable (arb_uniform_buffer_object-referenced-by-shader<br>
referenced-by-shader.c)<br>
>  piglit_add_executable (arb_uniform_buffer_object-rendering rendering.c)<br>
> +piglit_add_executable (arb_uniform_buffer_object-rendering-discard<br>
rendering-discard.c)<br>
>  piglit_add_executable (arb_uniform_buffer_object-row-major row-major.c)<br>
>  piglit_add_executable (arb_uniform_buffer_object-uniformblockbinding<br>
uniformblockbinding.c)<br>
><br>
> diff --git a/tests/spec/arb_uniform_buffer_object/rendering-discard.c<br>
b/tests/spec/arb_uniform_buffer_object/rendering-discard.c<br>
> new file mode 100644<br>
> index 0000000..cf3624d<br>
> --- /dev/null<br>
> +++ b/tests/spec/arb_uniform_buffer_object/rendering-discard.c<br>
> @@ -0,0 +1,195 @@<br>
> +/*<br>
> + * Copyright (c) 2014 LunarG, Inc.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the<br>
"Software"),<br>
> + * to deal in the Software without restriction, including without<br>
limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the<br>
next<br>
> + * paragraph) shall be included in all copies or substantial portions of<br>
the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
> + * DEALINGS IN THE SOFTWARE.<br>
> + */<br>
> +<br>
> +/** @file rendering-discard.c<br>
> + *<br>
> + * Test rendering with UBOs in the presence of discard.  Draw a single<br>
square<br>
> + * with a fragment shader that conditionally discards along a boundary that<br>
can<br>
> + * cause problems when rendering multiple fragment quads at once.  Test<br>
should<br>
> + * render a single color, no texture should bleed through.<br>
> + */<br>
> +<br>
> +#include "piglit-util-gl-common.h"<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_BEGIN<br>
> +<br>
> +     config.supports_gl_core_version = 32;<br>
> +     config.supports_gl_compat_version = 32;<br>
> +     config.window_visual = PIGLIT_GL_VISUAL_DOUBLE |<br>
PIGLIT_GL_VISUAL_RGBA;<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_END<br>
> +<br>
> +static const char vertex_shader_text[] =<br>
> +     "#version 140\n"<br>
> +     "#extension GL_ARB_explicit_attrib_location: require\n"<br>
> +     "layout(location = 0) in vec4 piglit_vertex;\n"<br>
> +     "void main()\n"<br>
> +     "{\n"<br>
> +     "    gl_Position = piglit_vertex;\n"<br>
> +     "}\n"<br>
> +     ;<br>
> +<br>
> +static const char fragment_shader_text[] =<br>
> +     "#version 140\n"<br>
> +     "#extension GL_ARB_shading_language_420pack : enable\n"<br>
> +     "#extension GL_ARB_uniform_buffer_object : enable\n"<br>
> +     "\n"<br>
> +     "layout(std140, binding = 0) uniform globals \n"<br>
> +     "{\n"<br>
> +     "    vec3   global0; \n"<br>
> +     "    vec3   global1; \n"<br>
<br>
</div></div>These two UBO fields appear to be unused - are they necessary?<br></blockquote><div><br></div><div>Hmmm, they were in the original test case, but the test appears to still fail if I shrink the buffer back down to size.  I'll reduce it to just one vec4.</div>
<div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div><br>
> +     "    vec3   global2; \n"<br>
> +     "    float  global3; \n"<br>
> +     "}\n;"<br>
> +     "\n"<br>
> +     "layout(binding = 0) uniform sampler2D tex2;\n"<br>
> +     "\n"<br>
> +     "void main()\n"<br>
> +     "{\n"<br>
> +     "    vec3 foo = texture(tex2, vec2(0.5)).xyz ;\n"<br>
> +     ""<br>
> +     "    // This condition will discard fragments to the left \n"<br>
> +     "    // of a diagonal line.  It is designed to partially  \n"<br>
> +     "    // discard the contents of SIMD registers.           \n"<br>
> +     "    if ((gl_FragCoord.x - gl_FragCoord.y) < 0.0)         \n"<br>
> +     "        discard;                                         \n"<br>
> +     ""<br>
> +     "    gl_FragColor = vec4(foo * global2 * global3, 1.0 );\n"<br>
> +     "}\n"<br>
> +     ;<br>
> +<br>
> +/* Note that the expected color is set up to both match the clear color,<br>
> + * but also be multiplied in the fragment shader to generate the same<br>
> + * value.  The multiplication is critical to testing behavior on some<br>
> + * backends, so it should remain in the shader.<br>
> + */<br>
> +const float expected_color[4] = { 0.2, 0.2, 0.2, 1.0 };<br>
> +<br>
> +/*<br>
> + * Create a single-color image.<br>
> + */<br>
> +static GLubyte *<br>
> +create_image(GLint w, GLint h, const GLubyte color[4])<br>
> +{<br>
> +        GLubyte *buf = (GLubyte *) malloc(w * h * 4);<br>
> +        int i;<br>
> +        for (i = 0; i < w * h; i++) {<br>
> +                buf[i*4+0] = color[0];<br>
> +                buf[i*4+1] = color[1];<br>
> +                buf[i*4+2] = color[2];<br>
> +                buf[i*4+3] = color[3];<br>
> +        }<br>
> +        return buf;<br>
> +}<br>
> +<br>
> +static void<br>
> +setup_texture(void)<br>
> +{<br>
> +        GLubyte colors[4] = {255,   255,  255,  255};<br>
> +        GLuint tex1;<br>
> +        GLint width = 128, height = 64, levels = 1;<br>
> +        GLint level = 0;<br>
> +        GLubyte *colorBuf = create_image(width, height, colors);<br>
> +<br>
> +        /* Set up a texture to pull from, just fill it with solid white */<br>
> +        glGenTextures(1, &tex1);<br>
> +        glBindTexture(GL_TEXTURE_2D, tex1);<br>
> +        glTexStorage2D(GL_TEXTURE_2D, levels, GL_RGBA8, width, height);<br>
> +        piglit_check_gl_error(GL_NO_ERROR);<br>
> +        glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, GL_RGBA,<br>
GL_UNSIGNED_BYTE, colorBuf);<br>
> +        glActiveTexture(GL_TEXTURE0);<br>
> +        glBindTexture(GL_TEXTURE_2D, tex1);<br>
> +}<br>
> +<br>
> +static void<br>
> +setup_uniform_buffer(void)<br>
> +{<br>
> +        GLuint uBuffer;<br>
> +        GLfloat bufData[12] = {<br>
> +           expected_color[0], expected_color[1], expected_color[2],<br>
expected_color[3],<br>
> +           expected_color[0], expected_color[1], expected_color[2],<br>
expected_color[3],<br>
> +           expected_color[0], expected_color[1], expected_color[2],<br>
expected_color[3],<br>
> +        };<br>
> +<br>
> +        /* Set up a uniform buffer with data that, when processed by the<br>
> +         * fragment shader, should draw the same color as the clear color.<br>
> +         * This normally "bad" test behavior is designed to make it easier<br>
> +         * to see that any unwanted color has entered along the boundary<br>
> +         * condition.  In this case, it will usually be the contents of the<br>
> +         * texture, but it can also be random data.<br>
> +         * Note that the size of the buffer and the offsets of the values<br>
> +         * being loaded are important to trigger specific behavior in some<br>
> +         * backends that optimize loading of uniform values.<br>
> +         */<br>
> +        glGenBuffers(1, &uBuffer);<br>
> +        glBindBuffer(GL_UNIFORM_BUFFER, uBuffer);<br>
> +        glBufferData(GL_UNIFORM_BUFFER, sizeof(bufData), NULL,<br>
GL_STATIC_DRAW);<br>
> +        glBindBufferBase(GL_UNIFORM_BUFFER, 0, uBuffer);<br>
> +        glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(bufData), bufData);<br>
> +}<br>
> +<br>
> +void<br>
> +piglit_init(int argc, char **argv)<br>
> +{<br>
> +     GLint prog = 0;<br>
> +<br>
> +     piglit_require_extension("GL_ARB_uniform_buffer_object");<br>
> +     piglit_require_extension("GL_ARB_shading_language_420pack");<br>
> +     piglit_require_extension("GL_ARB_explicit_attrib_location");<br>
<br>
</div></div>As written, this test also requires GL_ARB_texture_storage.<br></blockquote><div><br></div><div>Thanks, I'll add that.  Did I miss some debug spew that could have caught this?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<br>
I didn't review the test too thoroughly, but it looks reasonable enough.  With<br>
the extra extension check added, this would get:<br>
<br>
Acked-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>><br>
<br>
(perhaps other people will want to review it, though)<br>
<br>
Thanks for doing this.<br></blockquote><div><br></div><div>I'll wait a bit before resubmitting, see if any other comments are made.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div><div><br>
> +<br>
> +     prog = piglit_build_simple_program(vertex_shader_text,<br>
fragment_shader_text);<br>
> +     assert(prog);<br>
> +     glUseProgram(prog);<br>
> +<br>
> +     setup_texture();<br>
> +     setup_uniform_buffer();<br>
> +<br>
> +     glClearColor(expected_color[0], expected_color[1], expected_color[2],<br>
expected_color[3]);<br>
> +}<br>
> +<br>
> +<br>
> +enum piglit_result<br>
> +piglit_display(void)<br>
> +{<br>
> +     int probe = 0;<br>
> +<br>
> +     glViewport(0, 0, piglit_width, piglit_height);<br>
> +<br>
> +     glClear(GL_COLOR_BUFFER_BIT);<br>
> +<br>
> +     if (!piglit_check_gl_error(GL_NO_ERROR))<br>
> +             return PIGLIT_FAIL;<br>
> +<br>
> +     piglit_draw_rect(-1, -1, 2, 2);<br>
> +<br>
> +     /* Probe a rect so we don't have to guess at which pixel is<br>
> +      * incorrect.  Just a small area in the corner should be sufficient,<br>
as<br>
> +      * long as the boundary condition exists within it.  The expected<br>
value<br>
> +      * should match both fragment shader output and the clear color.<br>
> +      */<br>
> +     probe = piglit_probe_rect_rgba(0, 0, piglit_width/4, piglit_height/4,<br>
expected_color);<br>
> +<br>
> +     piglit_present_results();<br>
> +<br>
> +     return probe == 1 ? PIGLIT_PASS : PIGLIT_FAIL;<br>
> +}</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div><font color="#999999"><font face="trebuchet ms, sans-serif"> Cody Northrop<br> Graphics Software Engineer<br> LunarG, Inc.- 3D Driver Innovations</font><font face="trebuchet ms, sans-serif" style="font-size:small"><br>

 Email: <a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a><br> Website: <a href="http://www.lunarg.com/" target="_blank">http://www.lunarg.com</a></font></font></div></div>
</div></div>