# UE4 -opengl3: buggy shader on mesa/Radeon

**URL:** <https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386>\
**Category:** Platform & Builds\
**Tags:** Linux, unreal-engine, question\
**Created:** [August 9, 2017, 10:18am UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386 "2017-08-09T10:18:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gewo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gewo](https://forums.unrealengine.com/u/Gewo)\
**Post date:** [August 9, 2017, 10:18am UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/1 "2017-08-09T10:18:05Z")

</div>

Hello,

one of the precompiled shaders in the Unreal editor comes in the form of very bad TGSI that can not be properly translated to R600 byte code ( Radeon HD 6870 graphics card on mesa-git) [Bad TGSI code][1]: I get error messages

```
src/gallium/drivers/r600/r600_shader.c:183 r600_pipe_shader_create - translation from TGSI failed !
src/gallium/drivers/r600/r600_state_common.c:787 r600_shader_select - Failed to build shader variant (type=1) -1

```

and the colours are messed up

 ![203955-shader-bug.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/3/5/b3539aa246639f61ed054285b4189dc7d97daac1.jpeg)

.

Looking at the TGSI one can see that it allocates 151 temporary registers, but to most of these registers only a value is written, i.e. it is not used and could be optimized away. Now since this problem is bugging me for quite some time, I’ve implemented an [improved register merger][3] that would merge these registers and eliminate the problem (it fixes some similar bugs with the same error message). However, even with this patch applied I see the problem, which makes me suspect that the TGSI for this shader is not compiled on my machine but comes with some of the content that is downloaded.

I have [another patch][4] to work around this problem and gives me the expected output:

 ![203958-expected.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/5/b/f5b1985863984e0f59fe6b2c03f1b8ba286c15d7.jpeg)

However, the patch is a hack that tricks the translation from TGSI to byte code to pass, also by degrading an error to a warning, and then let the byte code optimizer clean up. It will never be accepted by mesa-upstream, since it hits some assertions in debug mode and the only use case I’ve come accross so far is this bug in UE4.

Hence it would be really nice if that buggy precompiled shader could be fixed.

many thanks,  
Gert Wollny

---

<div class="post-metadata">

**Author:** ![wws22](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wws22](https://forums.unrealengine.com/u/wws22)\
**Post date:** [October 5, 2017, 8:36pm UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/2 "2017-10-05T20:36:17Z")

</div>

````

```

Many thanks, Gewo and Gert Wollny

I use the Linux openSUSE & old MSI notebook with ATI Mobility Radeon HD 5870 card.

This patch doesn’t work with last openSUSE Leap 42.3 - Kernel 4.4.87-25 because system has a very old Mesa-17.0.3. The version of mesa above 17.1.0 can’t work properly on openSUSE Leap 42.3 because require libLLVM 3.9.0 or above. But latest Suse release precompiled with libLLVM 3.8.0-5.1. I tried to build llvm-3.9.0 from sources and new Mesa, but it’s no way. You will have too short enjoy. Because we should get a broken system after first reboot. System has too many depedencies to libLLVM 3.8.0.

The described Gewo patch isn’t so easy for use. I made the adoptation of these changes for Mesa-17.0.3.
It can be useful for lot of UE4 and Steam users.

I would like present one patch and short introduction for repairing your Radeon driven and OpenGL.

$uname -a
$cat /etc/issue
For check your system. If You use old openSUSE, update system from repo through Yast2.

Check your Radeon driver driver. You must have loaded ‘radeon’ module.
It’s a very strong condition!
$sudo /sbin/lsmod |grep radeon
radeon 1597440 26
i2c_algo_bit 16384 1 radeon
drm_kms_helper 167936 1 radeon
ttm 110592 1 radeon
drm 397312 15 ttm,drm_kms_helper,radeon

If you don’t have loaded radeon module
PLEASE STOPPED!

Please make a double check
$sudo /sbin/lspci |grep Radeon

01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Broadway XT [Mobility Radeon HD 5870]
01:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Juniper HDMI Audio [Radeon HD 5700 Series]

#and find your controller at these list
SDB:Radeon — openSUSE Wiki
I’m sorry. I found only russian version of these list.

Check your current OpenGL profile
$glxinfo |egrep -i ‘OpenGL|profile version’

The first 4 rows can say about used hardware gear
You need Max core profile version more than 3.2
-------------------------------
Max core profile version: 3.3
Max compat profile version: 3.0
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.0

OpenGL vendor string: X.Org
OpenGL renderer string: Gallium 0.4 on AMD JUNIPER (DRM 2.49.0 / 4.4.87-25-default, LLVM 3.8.0)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 17.0.3 (git-ca5fef94b2)
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 17.0.3 (git-ca5fef94b2)
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 17.0.3 (git-ca5fef94b2)
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
OpenGL ES profile extensions:

Also You can use glxgears for check your current mesa
$glxgears

Please check your python-Mako
$zypper se python-Mako

And install it if needed
$sudo zypper in python-Mako

Prepare Your build directory
$mkdir /home/your_user_name/something

$cd /home/your_user_name/something
Place attached patch file ‘Mesa-ATI-17.0.3-git-7f34ecae7f.patch’ here
$wget http://metalki.ru/files/Mesa-ATI-17.0.3-git-7f34ecae7f.patch

$git clone git://anongit.freedesktop.org/git/mesa/mesa
Be patient
More info available at Source Code Repository — The Mesa 3D Graphics Library latest documentation

$cd mesa # It should be /home/your_user_name/something/mesa

$git checkout mesa-17.0.3

$patch -p1 -i ../Mesa-ATI-17.0.3-git-7f34ecae7f.patch

$./autogen.sh
$./configure --enable-texture-float
–enable-texture-float - The very important secret key for build openGL more than 2.1 version

It should be like this
#…
prefix: /usr/local
exec_prefix: ${prefix}
libdir: ${exec_prefix}/lib64
includedir: ${prefix}/include

OpenGL: yes (ES1: yes ES2: yes)

OSMesa: no

DRI platform: drm
DRI drivers: i915 i965 nouveau r200 radeon swrast
DRI driver dir: ${libdir}/dri
GLX: DRI-based

EGL: yes
EGL platforms: x11 drm
EGL drivers: builtin:egl_dri2 builtin:egl_dri3
GBM: yes

Vulkan drivers: no

llvm: yes
llvm-config: /usr/bin/llvm-config
llvm-version: 3.8.0

Gallium drivers: r300 r600 svga swrast
Gallium st: mesa xvmc vdpau va

HUD extra stats: no
HUD lmsensors: no

Shared libs: yes
Static libs: no
Shared-glapi: yes
#…

$make
Be patient

$sudo make install

$ls /usr/local/lib64
for check new libGL.so and another files
3
Turn switch to the new libraries
$sudo ldconfig

And check
$ldd $(which glxgears) |grep /local
libGL.so.1 => /usr/local/lib64/libGL.so.1 (0x00007f7e40454000)
libglapi.so.0 => /usr/local/lib64/libglapi.so.0 (0x00007f7e3e5eb000)
Where ‘/usr/local’ are most important part

Check your openGL version (>= 3.0)
$glxinfo |egrep -i ‘OpenGL|profile version’
and
$glxgears

After it you can check the your UE 4.17 with a new color world

If something will be wrong you have to restore original Mesa
$cd /home/your_user_name/something/mesa
$sudo make uninstall
$sudo ldconfig

THE LAST IMPORTANT STEP !!!
$sudo mkinitrd

#Please do reboot for last check your new configuration

ENJOY

If something will be wrong use these instruction
SDB:Configuring graphics cards - openSUSE Wiki

################ Another HELP for You ##################

If you doesn’t have kernel sources and kernel-firmware
$sudo zypper in kernel-source
$sudo zypper in kernel-firmware

Your RADEON firmware must be placed in directory
$echo /lib/firmware/$(uname -r)/radeon

Please check the firmware for your card
$ls /lib/firmware/$(uname -r)/radeon |grep $(glxinfo |egrep -i ‘renderer string’ |sed -e s/.*AMD// |awk ‘{print $1}’)

If you doesn’t have it, try to find it in another firmware directories
$find /lib/firmware -name $(glxinfo |egrep -i ‘renderer string’ |sed -e s/.AMD// |awk ‘{print $1}’)
#In my case I found it in:

/lib/firmware/radeon/JUNIPER_rlc.bin
/lib/firmware/radeon/JUNIPER_smc.bin
/lib/firmware/radeon/JUNIPER_pfp.bin
/lib/firmware/radeon/JUNIPER_me.bin

You should copy these .bin files into /lib/firmware/$(uname -r)/radeon directory
Like a
/lib/firmware/4.4.87-25-default/radeon/JUNIPER_rlc.bin
/lib/firmware/4.4.87-25-default/radeon/JUNIPER_smc.bin
/lib/firmware/4.4.87-25-default/radeon/JUNIPER_pfp.bin
/lib/firmware/4.4.87-25-default/radeon/JUNIPER_me.bin

```

---

<div class="post-metadata">

**Author:** ![Gewo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gewo](https://forums.unrealengine.com/u/Gewo)\
**Post date:** [October 6, 2017, 1:42pm UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/3 "2017-10-06T13:42:53Z")

</div>

Hi wws22,

while I don’t need it, I think you didn’t attach the patch, and BTW: gewo = GErt Wollny 😉

Now about the shader creating the bad TGSI: I think it is created from ACES.ush, On can see in the created TGSI that the compiler creates code that copies many constants into temporaries (even though they are not used), and this way the shader occupies more temporaries then the r600g graphics cards support, and in that driver no register spilling is implemented, hence the error messages.

---

<div class="post-metadata">

**Author:** ![wws22](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wws22](https://forums.unrealengine.com/u/wws22)\
**Post date:** [October 6, 2017, 1:58pm UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/4 "2017-10-06T13:58:09Z")

</div>

1. Thank You.

2. Patch are presented inside the script. Please look to $wget cmd 🙂  
[http://metalki.ru/files/Mesa-ATI-17.0.3-git-7f34ecae7f.patch](http://metalki.ru/files/Mesa-ATI-17.0.3-git-7f34ecae7f.patch)  
.  
I made the link to Your original post from [another report](https://answers.unrealengine.com/questions/712958/ue4-buggy-shader-workaround-for-opensuse.html)  
After it, I wrote text again in this thread… And did not make attach too  
_‘This attachment is not permitted because the file type is invalid.’_  
.  
I tried to rename the file with same result :(((

3. Unfortunally, I don’t know nothing about shaders programming.  
I am newbie in 3D ☹

---

<div class="post-metadata">

**Author:** ![elmtreecomputers](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@elmtreecomputers](https://forums.unrealengine.com/u/elmtreecomputers)\
**Post date:** [February 27, 2018, 2:36am UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/5 "2018-02-27T02:36:01Z")

</div>

I am havin exactly the same graphic outcome with Radeon HD 5850.  
How do I apply your patch on Linux Arch?

It keeps complaining about OpenGL4.3. And running it with -opengl3 option just skewed the whole color pallate very similar to above screen shots.

---

<div class="post-metadata">

**Author:** ![Gewo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gewo](https://forums.unrealengine.com/u/Gewo)\
**Post date:** [February 27, 2018, 8:22am UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/6 "2018-02-27T08:22:02Z")

</div>

There are actually two ways to work around the problem: One is an now [updated patch](https://patchwork.freedesktop.org/series/37991/) for mesa, this has to be applied to mesa-git and then you have to recompile it, Since I don’t use arch I don’t know how you could apply this patch to the package version though.  
The other option is to patch the Unreal Engine code [with this pull request](https://github.com/EpicGames/UnrealEngine/pull/4102), the according [patch](https://patch-diff.githubusercontent.com/raw/EpicGames/UnrealEngine/pull/4102.patch?token=ACqGmVIgAtvT1jrlUrtqu7_VHXDd8Tflks5alRTXwA%3D%3D) is probably easier to use, because you don’t have to recompile anything.

Hope that helps,  
Gert

---

<div class="post-metadata">

**Author:** ![Gewo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gewo](https://forums.unrealengine.com/u/Gewo)\
**Post date:** [February 27, 2018, 8:51am UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/7 "2018-02-27T08:51:52Z")

</div>

Be aware that the patch against the Unreal Engine results in an endless loop in older versions of Mesa, there is a workaround in mesa 17.2,5 and a final fix landed in 17.3.

---

<div class="post-metadata">

**Author:** ![elmtreecomputers](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@elmtreecomputers](https://forums.unrealengine.com/u/elmtreecomputers)\
**Post date:** [February 27, 2018, 11:19am UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/8 "2018-02-27T11:19:27Z")

</div>

how did you apply that patch in your linux? I got:  
OpenGL version string: 3.0 Mesa 17.3.5

---

<div class="post-metadata">

**Author:** ![Gewo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gewo](https://forums.unrealengine.com/u/Gewo)\
**Post date:** [February 27, 2018, 11:46am UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/9 "2018-02-27T11:46:32Z")

</div>

Which patch? Usually, you just go to the root directory of the source code and do

```
patch -p1 < [patch file]

```

and with mesa you would also have to compile and install (but I wouldn’t really recommend it like this, because it would interfere with the arch packaging).

---

<div class="post-metadata">

**Author:** ![elmtreecomputers](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@elmtreecomputers](https://forums.unrealengine.com/u/elmtreecomputers)\
**Post date:** [February 27, 2018, 12:37pm UTC](https://forums.unrealengine.com/t/ue4-opengl3-buggy-shader-on-mesa-radeon/401386/10 "2018-02-27T12:37:47Z")

</div>

I am havin exactly the same graphic outcome with Radeon HD 5850.  
How do I apply your patch on Linux Arch?

It keeps complaining about OpenGL4.3. And running it with -opengl3 option just skewed the whole color pallate very similar to above screen shots.
