How to run Rage and other newest ID games on Mesa

Newest ID games like Rage  or Wolfenstein: The New Order does not work on mesa ( FATAL ERROR: wglCreateContextAttribsARB failed,  missed compatibility profile context GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB).
So for run this games we need

  1. Disable WGL_CONTEXT_PROFILE_MASK_ARB attribute(patch for wine).
diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c
index 932b217..0b218bc 100644                                                                                                                                
--- a/dlls/opengl32/wgl.c                                                                                                                                    
+++ b/dlls/opengl32/wgl.c                                                                                                                                    
@@ -261,6 +261,31 @@ BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)                                                                                        
     return ret;                                                                                                                                             
 }                                                                                                                                                           
 
+static
+const int* remove_profile_mask(const int *attribs)
+{
+    int* ret = NULL;
+    int i = 0;
+    int j = 0;
+    int attr_num = 0;
+    int profile_mask = 0;
+    for (i = 0; attribs[i] != NULL; i += 2) {
+        if (attribs[i] == WGL_CONTEXT_PROFILE_MASK_ARB)
+            profile_mask = 1;
+        ++attr_num;
+    }
+    if (profile_mask == 0) return attribs;
+    ret = calloc(attr_num*2 - 1, sizeof(int));
+    for (i = 0; attribs[i] != NULL; i += 2) {
+        if (attribs[i] != WGL_CONTEXT_PROFILE_MASK_ARB) {
+            ret[j] = attribs[i];
+            ret[j+1] = attribs[i+1];
+            j += 2;
+        }
+    }
+    return ret;
+}
+
 /***********************************************************************
  *             wglCreateContextAttribsARB
  *
@@ -274,6 +299,8 @@ HGLRC WINAPI wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *attrib
     struct opengl_context *context;
     struct opengl_funcs *funcs = get_dc_funcs( hdc );
 
+    attribs = remove_profile_mask(attribs);
+
     if (!funcs || !funcs->ext.p_wglCreateContextAttribsARB) return 0;
     if (share && !(share_ptr = get_handle_ptr( share, HANDLE_CONTEXT ))) return 0;
     if ((drv_ctx = funcs->ext.p_wglCreateContextAttribsARB( hdc,

2. Run game and dump shader

MESA_SHADER_READ_PATH=/shader/read/  MESA_SHADER_DUMP_PATH=/shader/dump/  MESA_GL_VERSION_OVERRIDE=4.3COMPAT wine ./Rage.exe

3. Fix the vertex shader and copy shaders to /shader/read

cd /shader/dump/
sed -i 's/out vec4 gl_Position;//g' VS* && cp /shader/dump/* /shader/read/

4. Repeat step 2 and 3 until game does not start

5. Or just use my shaders dump (download and unpack)

MESA_SHADER_READ_PATH=/patch/to/read/dir/   MESA_GL_VERSION_OVERRIDE=4.3COMPAT wine ./Rage.exe

GL_INTEL_map_texture is unavailable in mesa

Mesa: User error: GL_INVALID_OPERATION in unsupported function called (unsupported extension or deprecated function?)
Mesa: User error: GL_INVALID_ENUM in glTexParameter(pname=GL_TEXTURE_MEMORY_LAYOUT_INTEL)
Mesa: User error: GL_INVALID_ENUM in glTexParameter(pname=GL_TEXTURE_MEMORY_LAYOUT_INTEL)

and game looks like

How to run Divinity Original Sin Enhanced Edition on Mesa (r600\radeonsi)

Fix from Stil on linux.org.ru

For r600 and old Mesa you will need

export MESA_GL_VERSION_OVERRIDE=4.2 
export MESA_GLSL_VERSION_OVERRIDE=420

for all cards you need

export allow_glsl_extension_directive_midshader=true

or in drirc

 <application name="Divinity Original Sin Enhanced Edition" executable="EoCApp">
            <option name="allow_glsl_extension_directive_midshader" value="true" />
        </application>

In game directory create dir workaround
In workaround dir create file dos_ee_workaround.c (glXGetProcAddressARB and vendor string workaround)

#define _GNU_SOURCE
#include <GL/gl.h>
#include <string.h>
#include <dlfcn.h>

const char* vendor = "ATI Technologies Inc.";
const GLubyte* (*o_glGetString)(GLenum name);
void (*(*o_glXGetProcAddressARB)(const GLubyte*)) (void);
 
void _init(void)
{
    o_glGetString = dlsym(RTLD_NEXT, "glGetString");
    o_glXGetProcAddressARB = dlsym(RTLD_NEXT, "glXGetProcAddressARB");
}

const GLubyte* glGetString(GLenum name)
{
    if (name == GL_VENDOR)
        return (const GLubyte*) vendor;
    return o_glGetString(name);
}

void (*glXGetProcAddressARB(const GLubyte* procName)) (void)
{
    if (strcmp((const char*)procName, "glNamedStringARB") == 0 ||
        strcmp((const char*)procName, "glDeleteNamedStringARB") == 0 ||
        strcmp((const char*)procName, "glCompileShaderIncludeARB") == 0 ||
        strcmp((const char*)procName, "glIsNamedStringARB") == 0 ||
        strcmp((const char*)procName, "glGetNamedStringARB") == 0 ||
        strcmp((const char*)procName, "glGetNamedStringivARB") == 0)
        return NULL;
    return o_glXGetProcAddressARB(procName);
}

compile file

gcc -Wall -fPIC -DPIC -c dos_ee_workaround.c
ld -shared -o dos_ee_workaround.so dos_ee_workaround.o -ldl -lGL

Create new shell script newrun.sh

#!/bin/bash

GAME_DIR="/path/to/DivinityOriginalSinEnhancedEdition"
export allow_glsl_extension_directive_midshader=true
#MESA_SHADER_READ_PATH="${GAME_DIR}/workaround/read" \
#MESA_SHADER_DUMP_PATH="${GAME_DIR}/workaround/dump" \
LD_PRELOAD="${GAME_DIR}/workaround/dos_ee_workaround.so" \
LD_LIBRARY_PATH="${GAME_DIR}/game" \
${GAME_DIR}/game/EoCApp

Run newrun.sh and enjoy the game.


 

Fix for shaders if something wrong.

Uncomment in newrun.sh

MESA_SHADER_READ_PATH 
MESA_SHADER_DUMP_PATH

run newrun.sh(dump_shader to dir) and after segfault or graphics artifacts
create fix_shader.py in workaroud dir

#!/usr/bin/env python3

import sys
import os
import re

def fix_shaders(src_dir, dst_dir, ATI_PADDINGBUG=None):
    ati_re = re.compile(r'^\s*#define\sATI_PADDINGBUG')
    if ATI_PADDINGBUG != None:
        ati_str = '#define ATI_PADDINGBUG {:d}'.format(ATI_PADDINGBUG)
    ext_re = re.compile(r'^\s*#extension GL_ARB_gpu_shader5\s+:\s+enable')
    ext_str = '#extension GL_ARB_gpu_shader5 : enable\n'

    for filename in os.listdir(src_dir):
        src_file = '{:s}/{:s}'.format(src_dir, filename)
        with open(src_file, 'r') as f:
            src = f.readlines()
        dst = []
        for line in src:
            if ATI_PADDINGBUG != None and ati_re.match(line):
                dst.append(ati_str)
                continue
            if ext_re.match(line):
                dst.insert(2, ext_str)
                continue
            dst.append(line)
        dst_file = '{:s}/{:s}'.format(dst_dir, filename)
        with open(dst_file, 'w') as f:
            f.writelines(dst)

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print('usage: ', file=sys.stderr)
        print('{:s} src_dir dst_dir [ATI_PADDINGBUG]'.format(sys.argv[0]),
              file=sys.stderr)
        exit(1)
    ATI_PADDINGBUG = None
    if len(sys.argv) > 3:
        ATI_PADDINGBUG = int(sys.argv[3])
    fix_shaders(sys.argv[1], sys.argv[2], ATI_PADDINGBUG)

run fix_shader.py

GAME_DIR="/path/to/DivinityOriginalSinEnhancedEdition"

${GAME_DIR}/workaround/fix-shaders.py "${GAME_DIR}/workaround/dump" "${GAME_DIR}/workaround/read" 0

run newrun.sh (comment only MESA_SHADER_DUMP_PATH for best berformance)

Fix for segmentation fault in libcrypto (steam-beta)

To fix this bug on openSUSE mesa must be compiled with libnettle

--with-sha1=libnettle

For openSUSE mesa-git+libnettle
http://download.opensuse.org/repositories/home:/pontostroy:/X11/

Max Payne 3 on radeonsi (hd 7970 gallium-nine)

Armello gallium-nine vs native vs windows 8.1

Gallium-nine

nine

Native

native

windows 8.1

2016-07-01 18_23_08-Armello

Packages for AMD Polaris on openSUSE

Mesa, llvm, libdrm – git
http://download.opensuse.org/repositories/home:/pontostroy:/X11/

Kernel 4.7-rcX
http://download.opensuse.org/repositories/home:/pontostroy:/drm-next/

Special kernel for polaris (only openSUSE 42.1)
http://www.gearsongallium.com/download/kernel/kernel-vanilla-4.7.rc2-0.x86_64.rpm

amd_05

Gears on Gallium 2016.06.29 Polaris Edition

Updated iso link
Released an updated Gears on Gallium iso image with new Radeon RX480 (Polaris) support:
openSUSE – Leap 42.1
Mesa-git – 12.1_git2016.06.29
Kernel – 4.7-rc2(https://cgit.freedesktop.org/~agd5f/linux/log/?h=polaris-test) + updated firmware
libdrm – 2.4.99_git2016.06.20
Mesa-demos – 9.1.0_git2016.04.05
wine – 1.9.13-gallium-nine+staging (use WINEARCH=win32 winecfg)
xorg-server – 1.18.99 with threaded input
xf86-video-ati – 7.99.99_2016.06.29
xf86-video-amdgpu – 1.0.0_2016.06.29
xf86-video-intel – 2.9.99_2016.06.21
xf86-video-nouveau – 1.1.99_2016.06.14
KDE – 5.24.0 (5.6.90git) + plasma5 wayland session
LLVM – 3.9svn
Phoronix Test Suite – 6.4
Steam – 1.0.0.48
LXDE – 0.8.0

Users root and gog has empty password.
The image is the hybrid iso, can be written as the CD and as USB flash drive (use dd for writing).
Download 910 mb
md5 31c92de282e5e06c407f8ead6129dcd5
fd90d294b094efb3d6b67ae53afa3fc39905e1540e8e2a8968b5271d1951dace

How to use wine on livecd:
It’s better make /home/gog/.wine as symlink to external hdd\usb (ram disk is only 700 mb) or add ramdisk_size=1024000 (1gb) to kernel parameters to increase ramdisk size.

For VAAPI and VDPAU use
VDAPAU_DRIVER=radeonsi | r600 | nouveau
LIBVA_DRIVER_NAME=radeonsi | r600 | nouveau | i965

MX vs. ATV on radeonsi (hd 7970 gallium-nine)

Subnautica on radeonsi (hd 7970 gallium-nine)

Bare metal(host) vs qemu virgl benchmark

Host
openSUSE 42.1
Kernel 4.7-rc4
Qemu 2.6.0
Mesa-git 12.1
Radeon HD 7970
Intel I5 3330

Guest
openSUSE 42.1
Mesa-git 12.1
Kernel 4.7-rc4

qemu-system-x86_64 -m 4000 --enable-kvm -display gtk,gl=on -vga virtio -cpu host -smp 2 -drive file=/var/lib/libvirt/images/generic.qcow2,if=virtio -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no
bare-metal virgl
Xonotic Normal 267 131
Unigine Valley Ultra 2282 602
Lightsmark 571 104
Furmark 5344 5227
Plot3D 62828 23735
Volplosion 2211 2139

 

qemu