Whoops, fat-fingered submit button before I filled this in. Sorry.
Mesa version is 17.2.1
If I play this trace on an i915 Skylake system, the lighting on the landscape is flickery and weird when the camera moves. If I export LIBGL_ALWAYS_SOFTWARE=1 and play the trace, everything renders as it should.
Here's the apitrace output:
https://www.uplinklabs.net/files/darwinia-trace.log.gz

The demo repros the issue for me. You have to fly around a bit and most importantly tilt the camera around in order to observe the broken behavior. Long strips of landscape will flicker with different lighting.
I could record another apitrace, but that'd be redundant, the one I posted earlier shows the issue nicely.

(In reply to Steven Noonan from comment #9)
> The demo repros the issue for me. You have to fly around a bit and most
> importantly tilt the camera around in order to observe the broken behavior.
> Long strips of landscape will flicker with different lighting.
>
> I could record another apitrace, but that'd be redundant, the one I posted
> earlier shows the issue nicely.
Yep, now I see it. I can reproduce it when rotating the camera to clockwise direction.

I've also confirmed it works on Broadwell. I have no idea what is different between Broadwell and Sky Lake that would cause the failure. It looks like something is going wrong with the normals in the vertex shader or something like that.

I found that the underlying cause of the issue lies in the combination of flat shading, provoking vertex and clipped polygons.
Reproducing the issue is easy:
- Have glShadeModel set to GL_FLAT, smooth doesn't have such issue
- Have glProvokingVertexEXT set to GL_LAST_VERTEX_CONVENTION_EXT, first vertex mode seems not to exhibit the issue
- Create triangle strip with 3 vertices out of screen with blue color, two vertices on screen where the last one has red color (colors themself don’t
- Expected color of the triangle is red because color should be taken from last vertex but on Intel GPU triangle is blue
I asked Jason to help me, I'll quote his answer:
> I think what you've found is a hardware bug. :-(
> It appears that the clipper is messing up provoking vertex whenever entire
> polygons are clipped.> What do we do about it? That's an interesting question.
> The most obvious thing that jumps out to me would be to do a shader
> workaround where we tell the hardware that flat inputs are not flat
> (so it passes in all three vertices) and then manually grab the correct
> one of the three interpolants based on which provoking vertex is set.
> I don't think provoking vertex is something that applications change
> frequently so having a bit in the FS shader key probably isn't too
> bad for this.
I've sent a patch to Piglit which reproduces the bug - https://patchwork.freedesktop.org/patch/229260/

Wow, thanks for digging into this!
I can confirm that using glShadingModel(GL_SMOOTH) *or* glProvokingVertexEXT(GL_FIRST_VERTEX_CONVENTION_EXT) both eliminate the issue in the Darwinia landscape/water renderers. The glProvokingVertexEXT change looks better for Darwinia's case because it doesn't appear to negatively impact the intended appearance.

Hi Steven,
It turns out that this is a known hardware issue with provoking vertices not working right in some circumstances. The good news is that there's a simple workaround. The bad news is that it's going to take a kernel patch to fix it. :(
Patch from Chris Wilson and I:
https://lists.freedesktop.org/archives/intel-gfx/2018-June/168389.html
In the meantime, if you have intel-gpu-tools installed, you may be able to work around the issue by running these commands:
$ sudo intel_reg write 0x2090 0x10001000
$ sudo intel_reg write 0x2088 0x20002
(That should fix the issue, but I'm not clear whether the values will stick or if they'll get reset when the GPU goes into a low power state...)
Thank you for the report! And huge thanks to Danil for tracking this down to a provoking vertex problem.

Mesa's i965 CI updated kernels to get this fix. We found that it only works on a subset of SKL hardware:
fails: HD520 (gt2)
passes: HD530 (gt2), HD580 (gt4e)
Apparently a hardware bug was not fixed until a very late stepping.