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

Kenneth Graunke kenneth at whitecape.org
Wed Mar 11 17:13:38 PDT 2015

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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150311/3f379499/attachment.sig>

More information about the mesa-dev mailing list