Skip to contentSkip to conversation

Nier:Automata - "if" in fragment shader incorrectly evaluated, causes artifacts

Bug 103743 [email protected] 1 participant 16 messages Nov 14, 2017 – Sep 17, 2019

lore
Share & tools
lore
#0 lore raw

https://bugs.freedesktop.org/show_bug.cgi?id=103743

Bug ID: 103743
Summary: Nier:Automata - "if" in fragment shader incorrectly
evaluated, causes artifacts
Product: Mesa
Version: git
Hardware: x86-64 (AMD64)
OS: Linux (All)
Status: NEW
Severity: normal
Priority: medium
Component: Drivers/Gallium/radeonsi
Assignee: [email protected]
Reporter: [email protected]
QA Contact: [email protected]

Created attachment 135457
--> https://bugs.freedesktop.org/attachment.cgi?id=135457&action=edit
Fragment shader with workaround

When compiling Mesa against LLVM >= 5.0, Nier:Automata shows lighting artifacts that are caused by a misbehaving 'if' in a fragment shader.

Apitrace that shows the issue (2.5G, bz2-compressed):
https://mega.nz/#!JaBD0IoT!yBekRb7ZmvsSY60mo0E7N6uwaYfp_KfRDlnQWL0-QOo

I attached a copy of the fragment shader that causes the problem, but also includes a workaround. The file name for MESA_SHADER_READ_PATH is FS_feba74122c9590d1522b92bbec52d662ecd99012.glsl.

The offending code is located at line 135:

    R1.x = uintBitsToFloat(floatBitsToUint(R0).y >= 0x4u ? 0xffffffffu : 0u);
    if (bool(floatBitsToUint(R1).x))

The artifacts go away when changing the original 'if' condition to the following:

    if (floatBitsToUint(R0).y >= 0x4u)

This happens with both Mesa 17.2 and latest Mesa-git when compiling against LLVM 5.0 or later. This does *not* happen with LLVM 4.0.1. My GPU is an RX 480.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #1 from Philip Rebohle <[email protected]> --- Created attachment 135458
--> https://bugs.freedesktop.org/attachment.cgi?id=135458&action=edit
Frame 2400 with artifacts

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #2 from Philip Rebohle <[email protected]> --- Created attachment 135459
--> https://bugs.freedesktop.org/attachment.cgi?id=135459&action=edit
Frame 2400 without artifacts

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #3 from Philip Rebohle <[email protected]> ---
PS: While bug 102218 is not directly related to this one, that's another case where two shaders that *should* be functionally equivalent yield different results. In the second screenshot, workarounds for both issues are applied in order to obtain correct rendering.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #4 from Nicolai Hähnle <[email protected]> --- Thanks for the very lucid bug report. I can reproduce this and am investigating.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #5 from Philip Rebohle <[email protected]> --- I found another pair of equivalent expressions that produce different results.

Working as expected:

    if ((floatBitsToUint(R0).y >= 0x4u ? 0xffffffffu : 0u) == 0xffffffffu)

Showing artifacts:

    if ((floatBitsToUint(R0).y >= 0x4u ? 0xffffffffu : 0u) != 0u)
Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #6 from Nicolai Hähnle <[email protected]> --- Thanks. To give you an update, this is a super subtle control flow handling bug in LLVM -- and the difference between the original shader and your modification at the LLVM input is merely that the sense of one branch is (correctly) inverted, leading LLVM down a subtly different path in the end.

A sledge-hammer fix is quite simple, but I'm still thinking about how to get a better fix which doesn't pessimize a bunch of cases.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #7 from Nicolai Hähnle <[email protected]> --- Created attachment 135749
--> https://bugs.freedesktop.org/attachment.cgi?id=135749&action=edit
patch for related issue

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #8 from Nicolai Hähnle <[email protected]> --- Created attachment 135750
--> https://bugs.freedesktop.org/attachment.cgi?id=135750&action=edit
patch to fix this issue

Two patches for LLVM attached that fix the issue for me.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #9 from Philip Rebohle <[email protected]> --- Thanks for looking into this. While these two patches certainly improve the situation significantly, they don't fix the issue entirely.

The remaining artifacts are hardly noticable in the original apitrace, so I created another one (2.9G, bz2-compressed):
https://mega.nz/#!FHxSgZjL!0MzRQhI6W6Lk0beTv9LrPxDWjNTQveDuXVq3Mz2s7-M

Note that my original workaround still works with the LLVM patches applied.

Tested with updated LLVM-git, revision accb337c76e.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #10 from Philip Rebohle <[email protected]> --- Created attachment 135780
--> https://bugs.freedesktop.org/attachment.cgi?id=135780&action=edit
Frame 2320 with patched LLVM

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #11 from Philip Rebohle <[email protected]> --- Created attachment 135781
--> https://bugs.freedesktop.org/attachment.cgi?id=135781&action=edit
Frame 2800 with patched LLVM

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #12 from Samuel Pitoiset <[email protected]> --- Any news on this? The two LLVM patches have been pushed ~2 weeks ago. Can you still reproduce the issue? Thanks!

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#13 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #13 from Fabian Maurer <[email protected]> --- Created attachment 139196
--> https://bugs.freedesktop.org/attachment.cgi?id=139196&action=edit
Video showing minor artifacts

While it's a lot better, it's not fully fixed yet. I added a video to show a few artifacts, just look at the top middle area where the lightning jumps around.

Created from this apitrace:
http://www.mediafire.com/file/cch4roemrd2gi1f/AutomataArtifacts.7z

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#14 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

--- Comment #14 from Timothy Arceri <[email protected]> --- (In reply to Fabian Maurer from comment #13)

Quoted 9 lines

Created attachment 139196 [details]
Video showing minor artifacts

While it's a lot better, it's not fully fixed yet. I added a video to show a few artifacts, just look at the top middle area where the lightning jumps around.

Created from this apitrace:
http://www.mediafire.com/file/cch4roemrd2gi1f/AutomataArtifacts.7z

Those artifacts from the video seem to be gone with recent Mesa (19.1-devel) and LLVM (9.0-devel). Can you confirm if that this is indeed fixed?

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#15 lore raw
In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=103743

Timothy Arceri <[email protected]> changed:

What |Removed |Added
----------------------------------------------------------------------------

         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel