2016-01-10

Civilization V on Ubuntu x64 with rv770 and open source drivers

I recently bought Civilization V on Linux and I'm having a lot of fun playing that game. However, it is always risky for me to buy a 3D game because AMD does not support my Radeon graphics card anymore, a Radeon HD4870, internally called rv770. I need to rely on the open source drivers (provided by the Mesa3d project and the default drivers installed with Ubuntu).

It does not mean the open source drivers are bad, but game developers usually only care about testing their game with official drivers provided by the graphics card vendor. If a piece of code is not tested, chances are high that it won't work.

I was pleased to observe that the game works fine on my system. But at one moment in the game, I faced a bug where some character appears completely black.

I opened a new bug ticket at the Mesa3d project, and one of the things that can help Mesa developers is a "apitrace" file. apitrace is a great tool that allows recording all OpenGL calls of a program and replay that calls as many times as you want. It makes possible debugging a graphics program with a predictive set of conditions, a very valuable method of debugging.

So I wanted to create such a trace file for Civilization, by starting the game and reaching the screen where the character is wrongly displayed. apitrace can be downloaded easily on Ubuntu from the software repository:

sudo apt-get install apitrace-gl-frontend

Then you can easily record a trace with that command:

apitrace trace /path/to/some-opengl-app

And open and replay the trace with a user-friendly GUI program called qapitrace:

qapitrace /path/to/some-opengl-app.trace

Unfortunately, I faced a problem when using apitrace with Civilization. The game is built as a 32-bit program, and the apitrace I installed is 64-bit, which lead to an incompatibility. To make it work, I need to use a 32-bit version of apitrace.

Usually, you can get the 32-bit version of a package in Ubuntu by using the ":i386" suffix to the package name. But it the case of apitrace, that leads to an error.

My only choice was to build a 32-bit version of apitrace from sources. I had to gather information from several locations to reach that goal. In order to make my life easier next time I have to do it again, and to help some other people that would be in the same situation, I will write the step-by-step guide as a next post.