[Piglit] [PATCH 2/2] Make shader_runner add a #version directive to shaders lacking one.

Paul Berry stereotype441 at gmail.com
Fri Sep 14 10:24:45 PDT 2012


On 12 September 2012 11:18, Stuart Abercrombie <sabercrombie at chromium.org>wrote:

> This was a solitary patch.  I think the git submit feature decided
> there were two on account of an old patch file in the same directory.
> Sorry for the confusion.
>
> Stuart
>
> On Mon, Sep 10, 2012 at 5:55 PM, Stuart Abercrombie
> <sabercrombie at chromium.org> wrote:
> > The version number is taken from the GLSL version requirement, if there
> is one.
> >
> > This is part of the effort to make version handling more flexible for
> GLES.
> > ---
> >  tests/shaders/shader_runner.c |   41
> ++++++++++++++++++++++++++++++++++-------
> >  1 files changed, 34 insertions(+), 7 deletions(-)
> >
> > diff --git a/tests/shaders/shader_runner.c
> b/tests/shaders/shader_runner.c
> > index 6e3a470..88b36f8 100644
> > --- a/tests/shaders/shader_runner.c
> > +++ b/tests/shaders/shader_runner.c
> > @@ -48,6 +48,7 @@ extern float piglit_tolerance[4];
> >
> >  static float gl_version = 0.0;
> >  static float glsl_version = 0.0;
> > +static float glsl_req_version = 0.0;
> >  static int gl_max_fragment_uniform_components;
> >  static int gl_max_vertex_uniform_components;
> >
> > @@ -121,9 +122,29 @@ compile_glsl(GLenum target, bool release_text)
> >                 break;
> >         }
> >
> > -       piglit_ShaderSource(shader, 1,
> > -                           &shader_string,
> > -                           &shader_string_size);
> > +       if (glsl_req_version != 0.0f &&
> > +           !string_match("#version ", shader_string)) {
> > +               char *shader_strings[2];
> > +               char version_string[100];
> > +               GLint shader_string_sizes[2];
> > +
> > +               /* Add a #version directive based on the GLSL
> requirement. */
> > +               sprintf(version_string, "#version %ld\n",
> > +                       lround(100.0f * glsl_req_version));
> > +               shader_strings[0] = version_string;
> > +               shader_string_sizes[0] = strlen(version_string);
> > +               shader_strings[1] = shader_string;
> > +               shader_string_sizes[1] = shader_string_size;
> > +
> > +               piglit_ShaderSource(shader, 2,
> > +                                   shader_strings,
> > +                                   shader_string_sizes);
> > +
> > +       } else {
> > +               piglit_ShaderSource(shader, 1,
> > +                                   &shader_string,
> > +                                   &shader_string_size);
> > +       }
> >
> >         piglit_CompileShader(shader);
> >
> > @@ -416,18 +437,24 @@ process_requirement(const char *line)
> >                 piglit_require_not_extension(buffer);
> >         } else if (string_match("GLSL", line)) {
> >                 enum comparison cmp;
> > -               float version;
> >
> >                 line = eat_whitespace(line + 4);
> >
> >                 line = process_comparison(line, &cmp);
> >
> > -               version = strtod(line, NULL);
> > -               if (!compare(version, glsl_version, cmp)) {
> > +               /* We only allow >= because we potentially use the
> > +                * version number to insert a #version directive. */
> > +               if (cmp != greater_equal) {
> > +                       printf("Unsupported GLSL version comparison\n");
> > +                       piglit_report_result(PIGLIT_FAIL);
> > +               }
> > +
> > +               glsl_req_version = strtod(line, NULL);
> > +               if (!compare(glsl_req_version, glsl_version, cmp)) {
> >                         printf("Test requires GLSL version %s %.1f.  "
> >                                "Actual version is %.1f.\n",
> >                                comparison_string(cmp),
> > -                              version,
> > +                              glsl_req_version,
> >                                glsl_version);
> >                         piglit_report_result(PIGLIT_SKIP);
> >                 }
> > --
> > 1.7.7.3
> >
>

Whoops, I was just about to push this when I realized that it regresses
some piglit tests.  It seems that in some of our tests, the "#version"
directive isn't at the beginning of the shader (it comes after some
comments) so it isn't detected by string_match("#version ", shader_string).

I'll send out an updated patch that uses strstr() to search for "#version
".  In principle that could still be fooled (by a commented out #version
directive) but I think that's unlikely to be a problem.  Assuming my
revision looks good to you, I'll push it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20120914/1660ff13/attachment.html>


More information about the Piglit mailing list