[Mesa-dev] [PATCH 28/46] glsl: don't lower variable indexing on non-patch tessellation inputs/outputs

Marek Olšák maraeo at gmail.com
Thu Jul 16 12:57:14 PDT 2015


On Tue, Jun 23, 2015 at 2:04 AM, Kenneth Graunke <kenneth at whitecape.org> wrote:
> On Wednesday, June 17, 2015 01:01:24 AM Marek Olšák wrote:
>> From: Marek Olšák <marek.olsak at amd.com>
>>
>> There is no way to lower them, because the array sizes are unknown
>> at compile time.
>>
>> Based on a patch from: Fabian Bieler <fabianbieler at fastmail.fm>
>
> I'm a bit confused by the justification given for this patch.
>
> TCS/TES per-vertex inputs:
> --------------------------
>
> ...are always fixed-size arrays of length gl_MaxPatchVertices, because:
>
> "The length of gl_in is equal to the implementation-dependent maximum
>  patch size (gl_MaxPatchVertices)."
>
> "Similarly to the built-in inputs, each user-defined input variable has
>  a value for each vertex and thus needs to be declared as arrays or
>  inside input blocks declared as arrays.  Declaring an array size is
>  optional.  If no size is specified, it will be taken from the
>  implementation-dependent maximum patch size (gl_MaxPatchVertices).
>  If a size is specified, it must match the maximum patch size;
>  otherwise, a link-error will occur."
>
> This same text exists for both TCS inputs and TES inputs.  Since we
> always know the array size, I don't see why we can't do lowering in
> this case.
>
> I'm pretty new to tessellation shaders, so am I missing something?
>
> TCS per-patch inputs:
> ---------------------
>
> ...don't exist AFAICT.
>
> TES per-patch inputs:
> ---------------------
>
> ...do exist, require no special handling.
>
> TCS per-vertex outputs:
> -----------------------
>
> ...are arrays whose size is known at link time, but not necessarily
> compile time.
>
> "The length of gl_out is equal to the output patch size specified in the
>  tessellation control shader output layout declaration."
>
> "A tessellation control shader may also declare user-defined per-vertex
>  output variables. User-defined per-vertex output variables are declared
>  with the qualifier out and have a value for each vertex in the output
>  patch. Such variables must be declared as arrays or inside output blocks
>  declared as arrays. Declaring an array size is optional. If no size is
>  specified, it will be taken from the output patch size declared in the
>  shader."
>
> Apparently, the index must also be gl_InvocationID when writing:
>
> "While per-vertex output variables are declared as arrays indexed by
>  vertex number, each tessellation control shader invocation may write only
>  to those outputs corresponding to its output patch vertex. Tessellation
>  control shaders must use the input variable gl_InvocationID as the
>  vertex number index when writing to per-vertex output variables."
>
> So we clearly don't want to do lowering on writes.  But for reads, it
> seems like we could do lowering when the array size is known (such as
> post-linking).  I'm not sure whether or not it's beneficial...
>
> It might be nice to add a comment explaining why it makes no sense to
> lower variable indexing on TCS output writes (with the above spec
> citation).

gl_MaxPatchVertices (typically 32) is the implementation-dependent
maximum limit. The real size is unknown at compile time. It's usually
3 or 4 in most apps though.

For TCS inputs, the size is specified by glPatchParameteri(GL_PATCH_VERTICES).
For TES inputs, the size is specified by the "vertices" output layout
qualifier in TCS.

The gl_PatchVerticesIn built-in uniform contains the real size.

I'll add a comment that explains it.

Marek


More information about the mesa-dev mailing list