Bug 94341

Summary: Incorrect results with dFdx / dFdy
Product: Mesa Reporter: Ian Kerr <ikerr>
Component: Mesa coreAssignee: mesa-dev
Status: RESOLVED NOTABUG QA Contact: mesa-dev
Severity: normal    
Priority: medium    
Version: 11.1   
Hardware: Other   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: Correct result (left) and incorrect result (right)

Description Ian Kerr 2016-02-29 20:38:07 UTC
Created attachment 122036 [details]
Correct result (left) and incorrect result (right)

Context: I am using Chrome and osmesa to perform "headless" WebGL rendering. Many of the Three.js examples (http://threejs.org/examples/) do not render correctly. I think I have narrowed the problem down to incorrect results produced by dFdx / dFdy. Three.js uses these functions for several things including: flat-shading and bump / normal mapping.

I have created a JSFiddle that demonstrates the problem:

https://jsfiddle.net/iangkerr/08x72ge9/

The fiddle renders two triangles, rotated 45 degrees, with a perspective projection. The fragment shader attempts to compute the surface normal and assigns the result to gl_FragColor. I expect a purplish colour, due to the normal having positive X and Z components (R and B), and I get this result on my Mac. However, when running Chrome + osmesa on Ubuntu, I get a bluish colour (positive Z component). I have attached a screenshot of the correct result and the incorrect result.
Comment 1 Brian Paul 2016-02-29 22:36:07 UTC
Are you using the old "swrast" driver?  If so, the derivative functions only work correctly for some values (the interpolated texcoords, colors, etc.).

If you can switch to the llvmpipe driver you shouldn't have that problem (and your code should run faster).
Comment 2 Ian Kerr 2016-03-01 22:21:12 UTC
Thanks Brian! Yes, I was using the old "swrast". Recompiling osmesa with llvmpipe support seems to have fixed the issue.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.