Bug 100242 - radeon buffer allocation failure during startup of Factorio
Summary: radeon buffer allocation failure during startup of Factorio
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Drivers/Gallium/r600 (show other bugs)
Version: git
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Default DRI bug account
QA Contact: Default DRI bug account
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-16 22:55 UTC by tnmailinglists
Modified: 2017-07-03 10:41 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
terminal output when running the executable (2.21 KB, text/x-log)
2017-03-16 22:55 UTC, tnmailinglists
Details
strace (593.82 KB, text/x-log)
2017-03-16 22:56 UTC, tnmailinglists
Details
gdb bt (5.42 KB, text/plain)
2017-03-16 22:56 UTC, tnmailinglists
Details
likely fix (1.45 KB, patch)
2017-06-27 07:53 UTC, Nicolai Hähnle
Details | Splinter Review

Description tnmailinglists 2017-03-16 22:55:11 UTC
Created attachment 130277 [details]
terminal output when running the executable

The game Factorio crashes during startup with the following message printed on the CLI:
radeon: Failed to allocate a buffer:
radeon:    size      : 268435456 bytes
radeon:    alignment : 16384 bytes
radeon:    domains   : 4
radeon:    flags     : 20

The crash occurs during the pre-game loading procedure, before reaching the main menu, at the same spot every time. I'm on Lubuntu 16.10 using the up-to-date drivers provided by https://launchpad.net/~oibaf/+archive/ubuntu/graphics-drivers , my GPU is a Radeon HD 4670 with AGP. I believe this is a driver issue since the game starts up normally with 16.10's default drivers (12.0.6). I unfortunately cannot provide a specific date or build for when this behavior started occurring, but it has been happening for several months.

Of note is that the demo version provided by the developer on their website does not have this problem and starts up fine.

Attached are the terminal output, an strace and a gdb bt log.
Comment 1 tnmailinglists 2017-03-16 22:56:24 UTC
Created attachment 130278 [details]
strace
Comment 2 tnmailinglists 2017-03-16 22:56:52 UTC
Created attachment 130279 [details]
gdb bt
Comment 3 tnmailinglists 2017-03-17 12:07:35 UTC
I retested the game with mesa 12.0.6 and xserver-xorg-video-radeon 1:7.7.1 (the current versions for default Lubuntu 16.10) and noticed that while the game doesn't crash, it still produces buffer allocation failures during startup:

   2.969 Initial atlas bitmap size is 8192
radeon: Failed to allocate a buffer:
radeon:    size      : 268435456 bytes
radeon:    alignment : 16384 bytes
radeon:    domains   : 4
radeon:    flags     : 20
radeon: Failed to allocate a buffer:
radeon:    size      : 268435456 bytes
radeon:    alignment : 16384 bytes
radeon:    domains   : 4
radeon:    flags     : 20
radeon: Failed to allocate a buffer:
radeon:    size      : 268435456 bytes
radeon:    alignment : 16384 bytes
radeon:    domains   : 4
radeon:    flags     : 20
radeon: Failed to allocate a buffer:
radeon:    size      : 268435456 bytes
radeon:    alignment : 16384 bytes
radeon:    domains   : 4
radeon:    flags     : 20
   3.029 Couldn't create atlas bitmap (size 8192x8182), will try again
   3.094 Created atlas bitmap 4096x4096
Comment 4 Christian König 2017-03-17 12:21:19 UTC
The maximum size for allocations in VRAM on radeon are usually 256MB minus pinned system resources like GART.

The game tries to allocate something which is 256MB in size, so that won't fit.

Either the driver tries to allocate a temporary buffer which is way to large or the game tries to allocate a texture which is way to large.
Comment 5 Michel Dänzer 2017-03-21 02:22:52 UTC
(In reply to tnmailinglists from comment #3)
>    3.029 Couldn't create atlas bitmap (size 8192x8182), will try again
>    3.094 Created atlas bitmap 4096x4096

Looks like the game now gracefully handles the failure to allocate an 8192x8192 (= 256MB) atlas texture and falls back to a 4096x4096 one. The crash before was probably a game bug.
Comment 6 tnmailinglists 2017-03-21 14:41:28 UTC
(In reply to Michel Dänzer from comment #5)
> (In reply to tnmailinglists from comment #3)
> >    3.029 Couldn't create atlas bitmap (size 8192x8182), will try again
> >    3.094 Created atlas bitmap 4096x4096
> 
> Looks like the game now gracefully handles the failure to allocate an
> 8192x8192 (= 256MB) atlas texture and falls back to a 4096x4096 one. The
> crash before was probably a game bug.

I think you are misreading my comment, I was using an older stable version of mesa there to make sure that it still worked as described in the original post. I did not change the game version. It does not crash with mesa 12.0.6 and radeon 1:7.7.1, but it does crash on mesa 17.1 git with radeon 1:7.9.0. It could still be a game bug, but I'd guess something has changed in the way the driver does buffer allocation if it crashes in one case but not the other with the same game executable.

I've reopened for now since the crash still happens on git mesa, feel free to close again if I misunderstood what you meant.
Comment 7 Michel Dänzer 2017-03-22 01:57:42 UTC
I indeed misread your comment, sorry. Can you bisect Mesa?
Comment 8 tnmailinglists 2017-06-25 10:46:50 UTC
I managed to bisect mesa and got this result:

https://cgit.freedesktop.org/mesa/mesa/commit/?id=fb827c055cb1bdd2b18d0687c06c56b537d805f3 is the first bad commit
commit fb827c055cb1bdd2b18d0687c06c56b537d805f3
Author: Nicolai Hähnle <nicolai.haehnle@amd.com>
Date:   Mon Sep 12 12:19:47 2016 +0200

    winsys/radeon: enable buffer allocation from slabs
    
    Only enable for chips with GPUVM, because older driver paths do not take the
    required offset into account.
    
    Reviewed-by: Marek Olšák <marek.olsak@amd.com>

:040000 040000 4e1327d4b72890178a2057d2341971001f2de54d d162404a219307e5f6cda1009b864e66f23f4e63 M	src


I have also noticed that after a recent update the game now gives some more information, so when it does run like described in comment #3, it now also tells me that it detected an error by adding the following line right after the four driver error blocks:

   2.321 glTexImage2D for format ARGB_8888, size 8192x8185 failed (GL_OUT_OF_MEMORY)
Comment 9 Michel Dänzer 2017-06-26 03:06:01 UTC
Looks like Nicolai's change caused a regression for non-VM GPUs.
Comment 10 Nicolai Hähnle 2017-06-27 07:53:41 UTC
Created attachment 132275 [details] [review]
likely fix

It is a silly bug. The attached patch should fix the crash you're seeing. Please let me know if the game runs fine with this or if there is any other crash you're running into. Thanks!
Comment 11 tnmailinglists 2017-06-27 15:28:35 UTC
The game starts up fine without a crash now and handles the out of memory error gracefully like before. Thanks!
Comment 12 Nicolai Hähnle 2017-07-03 10:41:17 UTC
Thanks for testing again. The fix is in Mesa master, commit b0b4b5e8f7a25dd11c1662d339d68c9733e9b2dc.


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.