[Mesa-dev] [PATCH v2 1/7] glsl: parse invocations layout qualifier for ARB_gpu_shader5

Paul Berry stereotype441 at gmail.com
Fri Jan 31 14:40:37 PST 2014


On 28 January 2014 11:22, Jordan Justen <jordan.l.justen at intel.com> wrote:

> _mesa_glsl_parse_state::gs_invocations will store the
> invocation count.
>
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
>

This looks like it will work if the shader contains a line like this:

   layout(triangles, invocations=6) in;

But it won't handle this:

   layout(triangles) in;
   layout(invocations=6) in;

Although it's not explicitly mentioned in the GLSL spec, I believe that
this should be allowed too.  (The spec does explicitly allow similar
splitting of geometry shader output layout qualifiers.)

Note that the way we handle geometry shader input primitive types is
unusual, so it might not have been the best to imitate.  For other types of
shader-global layout qualifiers (i.e. geometry shader output primitive
count and geometry shader max_vertices), the code in glsl_parser.yy simply
merges the qualifiers into the global state->out_qualifier object at the
time that they are parsed.  The reason we handle geometry shader input
primitive types specially is because they have additional semantics (they
cause geometry shader input arrays to be resized), so we can't process them
until ast-to-hir time.  But that doesn't apply to the invocation count.

I'd recommend an in_qualifier field to _mesa_glsl_parse_state, and handling
invocations the same way that geometry shader output qualifiers are handled
(grep for "->out_qualifier" to how this works).  Unfortuneatly, because of
the extra semantics associated with input primitive types, we'll still have
to process them specially.

So I think the code in glsl_parser.yy will need to look something like this:

   | layout_qualifier IN_TOK ';'
   {
      void *ctx = state;
      $$ = NULL;
      if (state->stage != MESA_SHADER_GEOMETRY) {
         _mesa_glsl_error(& @1, state,
                          "input layout qualifiers only valid in "
                          "geometry shaders");
      } else {
         if ($1.flags.q.prim_type) {
            /* Make sure this is a valid input primitive type. */
            switch ($1.prim_type) {
            case GL_POINTS:
            case GL_LINES:
            case GL_LINES_ADJACENCY:
            case GL_TRIANGLES:
            case GL_TRIANGLES_ADJACENCY:
               $$ = new(ctx) ast_gs_input_layout(@1, $1);
               break;
            default:
               _mesa_glsl_error(&@1, state,
                                "invalid geometry shader input primitive
type");
               break;
            }
         }
         if (!state->in_qualifier->merge_qualifier(& @1, state, $1))
            YYERROR;
      }
   }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140131/2dc417c6/attachment-0001.html>


More information about the mesa-dev mailing list