<div dir="ltr">I can lower the fragment shader to 1.3, but Nvidia closed source complains if I lower the vertex shader below 1.4.  It's not obvious to me why:<div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div>Failed to compile vertex shader: 0(3) : error C0000: syntax error, unexpected '(', expecting "::" at token "("</div></div><div><div><br></div></div><div><div>source:</div></div><div><div>
#version 130</div></div><div><div>#extension GL_ARB_explicit_attrib_location: require</div></div><div><div>layout(location = 0) in vec4 piglit_vertex;</div></div><div><div>void main()</div></div><div><div>{</div></div><div>
<div>    gl_Position = piglit_vertex;</div></div><div><div>}</div></div><div><div>PIGLIT: {"result": "fail" }</div></div></blockquote><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, Jul 1, 2014 at 4:28 PM, Chris Forbes <span dir="ltr"><<a href="mailto:chrisf@ijw.co.nz" target="_blank">chrisf@ijw.co.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Pick one of 1.40 and ARB_uniform_buffer_object -- you don't need both.<br>
1.30+ARB_ubo would allow you to drop the GL version requirement down a<br>
bit too.<br>
<br>
Acked-by: Chris Forbes <<a href="mailto:chrisf@ijw.co.nz">chrisf@ijw.co.nz</a>><br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, Jul 2, 2014 at 10:08 AM, Cody Northrop <<a href="mailto:cody@lunarg.com">cody@lunarg.com</a>> wrote:<br>
> Yes, the texture sample is important.  It may be affecting the timing of the<br>
> uniform loads via sampler.<br>
><br>
> If I remove use of the texture, or replace it with vec3(1.0), the problem is<br>
> very hard to detect.<br>
><br>
> I'm using white to make it very clear where the incorrect results creep in.<br>
><br>
> That being said, I'm sure there are other ways to get the bug to show up..<br>
><br>
> -C<br>
><br>
><br>
> On Tue, Jul 1, 2014 at 3:36 PM, Chris Forbes <<a href="mailto:chrisf@ijw.co.nz">chrisf@ijw.co.nz</a>> wrote:<br>
>><br>
>> The texture actually seems unnecessary -- are you using that to defeat<br>
>> some optimization?<br>
>><br>
>> On Wed, Jul 2, 2014 at 9:28 AM, Cody Northrop <<a href="mailto:cody@lunarg.com">cody@lunarg.com</a>> wrote:<br>
>> > On Tue, Jul 1, 2014 at 3:05 PM, Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
>> > wrote:<br>
>> >><br>
>> >> 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">cody@lunarg.com</a>><br>
>> >> > Reviewed-by:  Courtney Goeltzenleuchter <<a href="mailto:courtney@lunarg.com">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<br>
>> >> > 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>
>> >><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<br>
>> >> > (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<br>
>> >> > (arb_uniform_buffer_object-referenced-by-shader<br>
>> >> referenced-by-shader.c)<br>
>> >> >  piglit_add_executable (arb_uniform_buffer_object-rendering<br>
>> >> > 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<br>
>> >> > 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<br>
>> >> > 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,<br>
>> >> > sublicense,<br>
>> >> > + * and/or sell copies of the Software, and to permit persons to whom<br>
>> >> > the<br>
>> >> > + * Software is furnished to do so, subject to the following<br>
>> >> > conditions:<br>
>> >> > + *<br>
>> >> > + * The above copyright notice and this permission notice (including<br>
>> >> > the<br>
>> >> next<br>
>> >> > + * paragraph) shall be included in all copies or substantial<br>
>> >> > portions<br>
>> >> > of<br>
>> >> the<br>
>> >> > + * Software.<br>
>> >> > + *<br>
>> >> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br>
>> >> > EXPRESS<br>
>> >> OR<br>
>> >> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
>> >> > MERCHANTABILITY,<br>
>> >> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO<br>
>> >> > EVENT<br>
>> >> > SHALL<br>
>> >> > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES<br>
>> >> > OR<br>
>> >> OTHER<br>
>> >> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
>> >> > ARISING<br>
>> >> > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
>> >> > 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<br>
>> >> > single<br>
>> >> square<br>
>> >> > + * with a fragment shader that conditionally discards along a<br>
>> >> > boundary<br>
>> >> > that<br>
>> >> can<br>
>> >> > + * cause problems when rendering multiple fragment quads at once.<br>
>> >> > 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>
>> >> These two UBO fields appear to be unused - are they necessary?<br>
>> ><br>
>> ><br>
>> > Hmmm, they were in the original test case, but the test appears to still<br>
>> > fail if I shrink the buffer back down to size.  I'll reduce it to just<br>
>> > one<br>
>> > vec4.<br>
>> ><br>
>> >><br>
>> >><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<br>
>> >> > color,<br>
>> >> > + * but also be multiplied in the fragment shader to generate the<br>
>> >> > same<br>
>> >> > + * value.  The multiplication is critical to testing behavior on<br>
>> >> > 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<br>
>> >> > white<br>
>> >> > */<br>
>> >> > +        glGenTextures(1, &tex1);<br>
>> >> > +        glBindTexture(GL_TEXTURE_2D, tex1);<br>
>> >> > +        glTexStorage2D(GL_TEXTURE_2D, levels, GL_RGBA8, width,<br>
>> >> > height);<br>
>> >> > +        piglit_check_gl_error(GL_NO_ERROR);<br>
>> >> > +        glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height,<br>
>> >> > 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<br>
>> >> > the<br>
>> >> > +         * fragment shader, should draw the same color as the clear<br>
>> >> > color.<br>
>> >> > +         * This normally "bad" test behavior is designed to make it<br>
>> >> > easier<br>
>> >> > +         * to see that any unwanted color has entered along the<br>
>> >> > boundary<br>
>> >> > +         * condition.  In this case, it will usually be the contents<br>
>> >> > of<br>
>> >> > the<br>
>> >> > +         * texture, but it can also be random data.<br>
>> >> > +         * Note that the size of the buffer and the offsets of the<br>
>> >> > values<br>
>> >> > +         * being loaded are important to trigger specific behavior<br>
>> >> > in<br>
>> >> > 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),<br>
>> >> > 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>
>> >> As written, this test also requires GL_ARB_texture_storage.<br>
>> ><br>
>> ><br>
>> > Thanks, I'll add that.  Did I miss some debug spew that could have<br>
>> > caught<br>
>> > this?<br>
>> ><br>
>> >><br>
>> >> I didn't review the test too thoroughly, but it looks reasonable<br>
>> >> enough.<br>
>> >> With<br>
>> >> the extra extension check added, this would get:<br>
>> >><br>
>> >> Acked-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
>> >><br>
>> >> (perhaps other people will want to review it, though)<br>
>> >><br>
>> >> Thanks for doing this.<br>
>> ><br>
>> ><br>
>> > I'll wait a bit before resubmitting, see if any other comments are made.<br>
>> ><br>
>> >><br>
>> >><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],<br>
>> >> > 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<br>
>> >> > sufficient,<br>
>> >> as<br>
>> >> > +      * long as the boundary condition exists within it.  The<br>
>> >> > expected<br>
>> >> value<br>
>> >> > +      * should match both fragment shader output and the clear<br>
>> >> > color.<br>
>> >> > +      */<br>
>> >> > +     probe = piglit_probe_rect_rgba(0, 0, piglit_width/4,<br>
>> >> > piglit_height/4,<br>
>> >> expected_color);<br>
>> >> > +<br>
>> >> > +     piglit_present_results();<br>
>> >> > +<br>
>> >> > +     return probe == 1 ? PIGLIT_PASS : PIGLIT_FAIL;<br>
>> >> > +}<br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > --<br>
>> >  Cody Northrop<br>
>> >  Graphics Software Engineer<br>
>> >  LunarG, Inc.- 3D Driver Innovations<br>
>> >  Email: <a href="mailto:cody@lunarg.com">cody@lunarg.com</a><br>
>> >  Website: <a href="http://www.lunarg.com" target="_blank">http://www.lunarg.com</a><br>
>> ><br>
>> > _______________________________________________<br>
>> > Piglit mailing list<br>
>> > <a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
>> > <a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
>> ><br>
><br>
><br>
><br>
><br>
> --<br>
>  Cody Northrop<br>
>  Graphics Software Engineer<br>
>  LunarG, Inc.- 3D Driver Innovations<br>
>  Email: <a href="mailto:cody@lunarg.com">cody@lunarg.com</a><br>
>  Website: <a href="http://www.lunarg.com" target="_blank">http://www.lunarg.com</a><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>