Bug 104602 - [apitrace] Graphical artifacts in Civilization VI on RX Vega
Summary: [apitrace] Graphical artifacts in Civilization VI on RX Vega
Status: REOPENED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Drivers/Gallium/radeonsi (show other bugs)
Version: 17.3
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Default DRI bug account
QA Contact: Default DRI bug account
URL:
Whiteboard:
Keywords:
: 105353 (view as bug list)
Depends on:
Blocks: 77449
  Show dependency treegraph
 
Reported: 2018-01-12 15:58 UTC by Zach Tibbitts
Modified: 2018-12-01 11:26 UTC (History)
6 users (show)

See Also:
i915 platform:
i915 features:


Attachments
image showing the bad triangles (4.35 MB, image/png)
2018-01-20 13:10 UTC, Jason Playne
Details
Hack around issue (833 bytes, patch)
2018-11-01 00:30 UTC, Timothy Arceri
Details | Splinter Review
Renderdoc capture (275.19 MB, application/x-xz)
2018-11-01 00:37 UTC, Timothy Arceri
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zach Tibbitts 2018-01-12 15:58:09 UTC
System is Arch Linux running kernel 4.15-rc7 with Mesa 17.3.1

When playing Civilization VI and zooming the camera out to view more of the map, I experience a large number of black, flickering, triangle-shaped artifacts across the screen. While this doesn't seem to crash the game (I'm able to play for an extended period without the application crashing still), it is distracting.

I've had this issue since switching to a Vega card from Polaris, running first the amd-staging branch of the kernel, then the 4.15 RCs, and from mesa-git through 17.3 stable. The game updated today and the issue is still present.

As far as I've noticed, no other game experiences the same bug, so I can't be certain if the fault lies in the driver or the game itself. If needed, I can attempt to capture some screenshots or video of the bug.
Comment 1 Jason Playne 2018-01-20 13:04:17 UTC
I am seeing the same with my vega64 on KDE Neon with the oibaf ppa.

packages are marked as 17.4~git1801200730.436ed6~oibaf~x

kernel: 4.15.0-041500rc5-generic

You can easily reproduce this by running the graphics benchmark.

I tried to capture an API trace but the game slowed down so much that the benchmark did not get far enough along to show it :( 

(it is entirely possible that I am holding it wrong too)
Comment 2 Jason Playne 2018-01-20 13:10:01 UTC
Created attachment 136866 [details]
image showing the bad triangles

These triangles are not static, they flicker around the screen a fair bit
Comment 3 Jason Playne 2018-01-22 06:33:49 UTC
So I was able to get an API trace of the problem!

(I am rather happy to now be holding apitrace correctly!)

it does weigh in at 1.5GiB compressed but it does show all the badly rendered triangles and how zooming in stops them

it is available here: https://jasonplayne.com/share/Civ6.trace.bz2

I hope this is helpful
Comment 4 matombo 2018-03-18 22:44:44 UTC
*** Bug 105353 has been marked as a duplicate of this bug. ***
Comment 5 matombo 2018-03-18 22:47:41 UTC
I have the same issue,
i captured a video showing the flickering triangles which i had posted in the duplicate bug 105353
https://bugs.freedesktop.org/attachment.cgi?id=137806
Comment 6 Jason Playne 2018-04-09 12:15:05 UTC
Can Confirm that this problem still persists on Kernel 4.16.1 and Mesa 18
Comment 7 Zach Tibbitts 2018-04-09 13:26:41 UTC
This issue is also persisting with the latest update to Civ VI, including the Rise and Fall expansion.
Comment 8 peetipablo 2018-09-16 16:11:20 UTC
Just want to comment that this issue is still occuring on mesa 18.2, arch linux kernel 4.18.6.
Comment 9 Timothy Arceri 2018-09-21 03:28:36 UTC
I'm not sure why yet but both the black triangles and the incorrect rendering behind the chinese emperor on the loading screen go away when I run the trace on the NIR backend.

Until we figure out what is going on here you can try running the game with the following environment variable:

R600_DEBUG=nir
Comment 10 Jason Playne 2018-09-21 10:36:38 UTC
(In reply to Timothy Arceri from comment #9)
> I'm not sure why yet but both the black triangles and the incorrect
> rendering behind the chinese emperor on the loading screen go away when I
> run the trace on the NIR backend.
> 
> Until we figure out what is going on here you can try running the game with
> the following environment variable:
> 
> R600_DEBUG=nir

Can confirm! The initial red+black triangles in the game seem to have disappeared using the nir backend.

(I may be a little excited!)
Comment 11 Jason Playne 2018-09-21 12:25:39 UTC
(In reply to Jason Playne from comment #10)
> (In reply to Timothy Arceri from comment #9)
> > I'm not sure why yet but both the black triangles and the incorrect
> > rendering behind the chinese emperor on the loading screen go away when I
> > run the trace on the NIR backend.
> > 
> > Until we figure out what is going on here you can try running the game with
> > the following environment variable:
> > 
> > R600_DEBUG=nir
> 
> Can confirm! The initial red+black triangles in the game seem to have
> disappeared using the nir backend.
> 
> (I may be a little excited!)

After a couple of hours of game time, I have not seen the triangles.

nir solves the problem

Thanks Timothy!
Comment 12 michael.mansell 2018-09-22 01:18:11 UTC
This fixes the issue for me as well. Its great to finally have a work-around!
Comment 13 Juan A. Suarez 2018-10-05 10:50:43 UTC
As this is fixed, and published in mesa 18.2.2, I'm closing it.
Comment 14 Timothy Arceri 2018-10-05 10:57:30 UTC
(In reply to Juan A. Suarez from comment #13)
> As this is fixed, and published in mesa 18.2.2, I'm closing it.

This isn't fixed yet :)

Another bug was found using the trace from this bug, as per the commit message that fix does not fix the primary issue of back triangles from this bug.
Comment 15 Timothy Arceri 2018-11-01 00:30:59 UTC
Created attachment 142313 [details] [review]
Hack around issue

I've found the source of the problem. It seems that the tgsi indirect indexing optimisation is causing issues on Vega for some reason. I've attached a hack which disables it resulting in correct rendering.
Comment 16 Timothy Arceri 2018-11-01 00:37:59 UTC
Created attachment 142314 [details]
Renderdoc capture

Also attaching a renderdoc capture of the issue.
Comment 17 Timothy Arceri 2018-11-01 06:39:55 UTC
After talking this over with Marek here is a summary of the problem.

LLVM's VGPR indexing code on gfx9+ is broken for immediate arrays. Usually this is not a problem as GLSL IR in mesa will lower these to Uniforms via lower_const_arrays_to_uniforms(). However this does not work for the shaders in Civ6 because these arrays are not actually defined as constant arrays for example the original shader looks like this:

	vec4 x0[3];
	vec4 x1[6];
	vec4 x2[6];
	vec4 x3[6];

	x0[0].xy = vec2(0.031250, 0.500000);
	x0[1].xy = vec2(0.968750, 0.031250);
	x0[2].xy = vec2(0.968750, 0.968750);
	x1[0].xy = vec2(1.000000, 1.000000);
	x1[1].xy = vec2(0.000000, 1.000000);
	x1[2].xy = vec2(-1.000000, 0.000000);
	x1[3].xy = vec2(-1.000000, -1.000000);
	x1[4].xy = vec2(0.000000, -1.000000);
	x1[5].xy = vec2(1.000000, 0.000000);
	x2[0].xy = vec2(1.000000, -1.000000);
	x2[1].xy = vec2(2.000000, 1.000000);
	x2[2].xy = vec2(1.000000, 2.000000);
	x2[3].xy = vec2(-1.000000, 1.000000);
	x2[4].xy = vec2(-2.000000, -1.000000);
	x2[5].xy = vec2(-1.000000, -2.000000);

Without SSA I don't see any way for GLSL IR to easily recognise this as a constant array. Unfortunately by the time LLVM is done it is recognised and is exposed to the buggy indexing support.
Comment 18 Sergio Marcelo 2018-12-01 11:26:15 UTC
Video of problem happening:
https://www.youtube.com/watch?v=E4oy8tqaYs0

My set up: Ubuntu 18.10, AMD Ryzen 2700X, RX Vega 56

This is the workaround that worked for me:

* Beyond adding "R600_DEBUG=nir" to game launcher options (in steam client), also  start "Steam Launcher" in a terminal with "R600_DEBUG=nir" environment variable set. And it will work.

When bugfix is published let me know to test it.


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.