Bug 80018

Summary: [HSW] Ambient occlusion glitch in Planetary Annihilation on Intel HD4600
Product: Mesa Reporter: sxx.public
Component: Drivers/DRI/i965Assignee: Ian Romanick <idr>
Status: RESOLVED NOTOURBUG QA Contact: Intel 3D Bugs Mailing List <intel-3d-bugs>
Severity: normal    
Priority: medium CC: danylo.piliaiev, eero.t.tamminen
Version: git   
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 77449    
Attachments: Ambient occlusion on Intel: enabled
Ambient occlusion on Intel: disabled
Ambient occlusion on R600g: enabled
Ambient occlusion on R600g: disabled

Description sxx.public 2014-06-14 09:16:28 UTC
Created attachment 101033 [details]
Ambient occlusion on Intel: enabled

Here is some screenshots of incorrect rendering in Planetary Annihilation. If AO enabled I get really weird behavior when move or zoom camera: shadow is moving all the time. It's working fine on R600g with same version of Mesa

Here is video on youtube:
http://www.youtube.com/watch?v=gYk8p13sifA
http://www.youtube.com/watch?v=hVpHlZ6LNJE

I also will attach screenshots with correct (R600g, HD6950) and incorrect (i965, HD4600) rendering. I tested it on vanilla Ubuntu 14.04 drivers as well as Oibaf PPA.

GL trace using fairly recent build of APITrace (500MB unpacked):
https://drive.google.com/file/d/0B5LwC3WbdQ3DT2dUVHIxZmVQMmc/edit?usp=sharing
Comment 1 sxx.public 2014-06-14 09:17:08 UTC
Created attachment 101034 [details]
Ambient occlusion on Intel: disabled
Comment 2 sxx.public 2014-06-14 09:17:51 UTC
Created attachment 101035 [details]
Ambient occlusion on R600g: enabled
Comment 3 sxx.public 2014-06-14 09:18:16 UTC
Created attachment 101036 [details]
Ambient occlusion on R600g: disabled
Comment 4 Danylo 2018-07-30 15:32:37 UTC
I think I found the cause:

In sao_apply.fs random angle is calculated in the following way:
> ivec2 ssC = ivec2(gl_FragCoord.xy);
> float randomPatternRotationAngle = (3 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 10;
This means that randomPatternRotationAngle will have huge values thus sin and cos may give quite imprecise values. It is precise enough on Radeon and Nvidia but not enough on Intel GPUs.

The documentation Volume 7: 3D-Media-GPGPU states:
> Precision: 
> DirectX 10 and below Absolute error <= 0.0008 for the range of +/- 32767 * pi 
> Outside of the above range the function will remain periodic, 
> producing values between -1 and 1.
In practice passing values greater than 32767 * pi to cos or sin gives unusable output for most purposes (I'm not exactly sure if it is true for all Intel GPUs).

The easy fix will be calculating randomPatternRotationAngle like this:
> float randomPatternRotationAngle = mod(3 * ssC.x ^ ssC.y + ssC.x * ssC.y, 6.28318530718);

After the change there is no more artifacts.
Comment 5 Danylo 2018-07-31 08:15:22 UTC
To summarize, I think that is not a mesa issue. I notified http://support.uberent.com about it (#771156 ticket id in their internal system).

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.