i965: Make fs gl_PrimitiveID input work even when there's no gs.
authorPaul Berry <stereotype441@gmail.com>
Wed, 23 Oct 2013 03:34:30 +0000 (20:34 -0700)
committerPaul Berry <stereotype441@gmail.com>
Sun, 27 Oct 2013 17:23:39 +0000 (10:23 -0700)
commite79e6c591186fe96c8097209d4f95f70cf691de6
tree8b466a6895a1c3ce222a4348cab676b3dfa4f8c6
parent7f7636830514ae37b9df9969c44637f55323d608
i965: Make fs gl_PrimitiveID input work even when there's no gs.

When a geometry shader is present, the fragment shader gl_PrimitiveID
input acts like an ordinary varying, receiving data from the gs
gl_PrimitiveID output.  When there's no geometry shader, we have to
ask the fixed function SF hardware to provide the primitive ID to the
fragment shader instead.

Previously, the SF setup code would handle this situation by
recognizing that the FS gl_PrimitiveID input didn't match to any VS
output; since normally an FS input with no corresponding VS output
leads to undefined data, the SF setup code used to just arbitrarily
assign it to receive data from attribute 0.

This patch changes the SF setup code so that instead of arbitrarily
using attribute 0, it assigns the unmatched FS input to receive
gl_PrimitiveID.  In the case where the FS input really is
gl_PrimitiveID, this produces the intended result.  In all other
cases, no harm is done since GL specifies that the behaviour is
undefined.

Fixes piglit test primitive-id-no-gs.

v2: If an attribute is already being overridden with point
coordinates, don't try to also override it with gl_PrimitiveID.  This
is necessary to avoid regressing piglit tests such as
shaders/glsl-fs-pointcoord.

Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_defines.h
src/mesa/drivers/dri/i965/gen6_sf_state.c