[Mesa-dev] [PATCH 5/9] i965: Implement NIR intrinsics for loading VS system values.

Jason Ekstrand jason at jlekstrand.net
Wed Mar 11 18:52:40 PDT 2015


On Wed, Mar 11, 2015 at 5:13 PM, Kenneth Graunke <kenneth at whitecape.org>
wrote:

> On Wednesday, March 11, 2015 03:33:24 PM Jason Ekstrand wrote:
> > I'm not terribly happy with how this worked out, I'm not going to NAK it
> as
> > I think it's the best we can do at the moment.
> >
> > The reason why Connor (and others) have chosen to emit these things at
> the
> > top of the shader is because they frequently require some computation and
> > we don't want to duplicate that if we don't have to.  However, it also
> > leads to variables with very long live ranges which we don't want either.
> > Once we have GVN, we can value-number system value intrinsics.  This will
> > ensure that we only do the (potentially expensive) caluculation once and
> > GCM will ensure that they land as far down the program as we can put
> them.
> > However, until we have GVN, this seems like as good as we're going to get
> > at the moment.
> > --Jason
>
> I think this code is fine.
>
> The built-in variables handled here are gl_VertexID and gl_InstanceID.
> Here, gl_VertexID = gl_VertexIDMESA (0-based) + gl_BaseVertex.
>
> All three values show up as an incoming vec4 vertex attribute, supplied
> by the vertex fetcher like any other vertex data.  This means that they
> inherently occupy registers starting at the beginning of the program.
>
> The only computation we could delay is the ADD for gl_VertexID.
> However, in SIMD8 VS, it appears that gl_VertexIDMESA and gl_BaseVertex
> occupy separate registers.  So doing the ADD up front actually makes 2
> GRFs available, at the cost of 1 GRF.  It's actually better up front.
>
> For the FS system values - gl_SampleID and the like - you have a point.
> The inputs to the calculation tend to come from g0/g1, which usually
> live for the whole shader anyway.  So we can compute the value whenever
> we like - moving it closer to the use would reduce live ranges, and
> potentially put it inside control flow, so it might be skipped
> altogether on some invocations.
>
> That's just not the case for the VS system values.
>

Sure, and I'm not picky about where the math happens.  I just don't like
this two-step emit process where we put a bunch of stuff at the top of the
shader and then mov's down below.  I'd rather we just put the system value
intrinsic at the top where we want it and emit it when we hit it in the
emit pass.  I'm not super-picky about it but that just seems to make mores
sense to me.
--Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150311/22f393c9/attachment.html>


More information about the mesa-dev mailing list