#!/bin/bash set -euo pipefail if (( EUID == 0 )); then echo "run setup.sh as your normal user, not with sudo: the build uses systemd-run --user and must not leave root-owned files in the checkout" exit 1 fi source "$(dirname "$(readlink -f "$0")")/env.sh" deps=$root/deps sys=$WINEPREFIX/drive_c/windows/system32 MESA=(https://gitlab.freedesktop.org/mesa/mesa.git mesa-26.3.1) VKD3D=(https://github.com/HansKristian-Work/vkd3d-proton 71cae091b06571e51446cf2a937f0b04c237c04d) WINE=(https://gitlab.winehq.org/wine/wine.git) XWIN=(https://github.com/Jake-Shadle/xwin/releases/download/0.10.0/xwin-0.10.0-x86_64-unknown-linux-musl.tar.gz d870eb4b2f390878af6da1ccd3cf321d22fcb72720984853b4be732ae597fc88) DXC=(https://github.com/microsoft/DirectXShaderCompiler/releases/download/v1.9.2609/dxc_2026_09_29.zip ad31b1fc8443175d204f77a611fdb3ef2ec42759bdc2f1167368de24a4a7e7f1) DXVK=(https://github.com/doitsujin/dxvk/releases/download/v3.1.1/dxvk-3.1.1.tar.gz 40565b4a724aadc4433fa4e010b4b23916d9b1f1baeee64e17186db94f54e608) D3DCOMPILER=(https://raw.githubusercontent.com/mozilla/fxc2/9aba9b11079303d5577e0e3eb455f4d00f3b5946/dll/d3dcompiler_47.dll 4432bbd1a390874f3f0a503d45cc48d346abc3a8c0213c289f4b615bf0ee84f3) FSR4=(https://raw.githubusercontent.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/v2.4.0/Kits/FidelityFX/signedbin/amd_fidelityfx_upscaler_dx12.dll aad4fccccb29084a655f9a4f9f613bd22c8c03fb4a0f8840148cc6543b4ccace) FSR4_FG=(https://raw.githubusercontent.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/v2.4.0/Kits/FidelityFX/signedbin/amd_fidelityfx_framegeneration_dx12.dll e6843252f58b0341a0d80f6a20bc0d840643ee95bc48c22cac08745344577bb6) FSR4_DRIVER=(https://loathingKernel.github.io/proton-upscalers/amdxcffx64_v4.1.1_398EA93C15D554EFB7ECE1F4CD057554.xz 4e7dc37aebea3a90e3d3cc43e24cb2b54176b2535315f20dbe63b3b7cfc56b1e) logged() { local log=$deps/$1.log shift if ! "$@" >>"$log" 2>&1; then tail -n 30 "$log" exit 1 fi } fetch() { local url=$1 sum=$2 to=$3 if [ -f "$to" ] && echo "$sum $to" | sha256sum -c --status; then return; fi mkdir -p "$(dirname "$to")" echo "fetching $(basename "$to")" curl -fL --retry 3 -sS -o "$to.part" "$url" if ! echo "$sum $to.part" | sha256sum -c --status; then echo "$url is not the file expected"; exit 1; fi mv "$to.part" "$to" } source_of() { local name=$1 url=$2 ref=$3 dir=$deps/$1 patch=$root/patches/$1.patch sub local subs=() for sub in "$root/patches/$name".*.patch; do if [ -f "$sub" ]; then subs+=("$sub"); fi done local stamp="$ref $(cat "$patch" ${subs[@]+"${subs[@]}"} | sha256sum)" if [ ! -d "$dir/.git" ]; then git init -q "$dir" fi if git -C "$dir" remote get-url origin >/dev/null 2>&1; then git -C "$dir" remote set-url origin "$url" else git -C "$dir" remote add origin "$url" fi if [ "$(cat "$dir/.git/um-stamp" 2>/dev/null)" = "$stamp" ]; then return; fi local saved_patch if [ -f "$dir/.git/um-patch" ]; then saved_patch=$(sha256sum < "$dir/.git/um-patch"); fi if [ -f "$dir/.git/um-patch" ] && [ "$(patched "$dir" | sha256sum)" != "$saved_patch" ] && [ "$(patched "$dir" --abbrev=7 | sha256sum)" != "$saved_patch" ]; then echo "deps/$name has changes the patch does not: keep them with tools/patch.sh $name" exit 1 fi echo "fetching $name $ref" git -C "$dir" fetch -q --depth 1 origin "$ref" git -C "$dir" submodule -q foreach --recursive 'git reset -q --hard' git -C "$dir" reset -q --hard git -C "$dir" checkout -q --detach FETCH_HEAD git -C "$dir" submodule update -q --init --recursive --depth 1 git -C "$dir" apply --index "$patch" for sub in ${subs[@]+"${subs[@]}"}; do git -C "$dir/$(submodule_of "$dir" "$sub")" apply --index "$sub" done patched "$dir" > "$dir/.git/um-patch" echo "$stamp" > "$dir/.git/um-stamp" } step_tools() { local missing=() pc=() need_mesa_deps=0 step rustup_init=0 if ! command -v rustup >/dev/null; then if command -v rustup-init >/dev/null; then rustup_init=1 else missing+=(rustup) fi fi for t in git curl unzip tar xz python3 pkg-config ninja glslangValidator clang-cl lld-link llvm-lib x86_64-w64-mingw32-gcc x86_64-w64-mingw32-g++ x86_64-w64-mingw32-strip widl cargo make flex bison systemd-run unshare; do if [ "$t" = cargo ] && (( rustup_init )); then continue; fi command -v "$t" >/dev/null || missing+=("$t") done if [ -z "${PROTON_DIR:-}" ]; then command -v wine >/dev/null || missing+=(wine) fi if (( ${#missing[@]} )); then echo "install first: ${missing[*]}"; fi if (( rustup_init )); then echo "rustup is installed but not set up: run rustup-init once (Fedora's rustup package installs rustup-init), then open a new shell or put ~/.cargo/bin on PATH" fi if (( ${#missing[@]} || rustup_init )); then exit 1; fi for step in "$@"; do if [ "$step" = mesa ]; then need_mesa_deps=1; fi done if (( need_mesa_deps )); then for p in "libdrm >= 2.4.133" "libdrm_amdgpu >= 2.4.133" xcb xcb-randr x11-xcb \ "xcb-dri3 >= 1.13" "xcb-present >= 1.13" xcb-shm xcb-sync "xshmfence >= 1.1" xcb-xfixes \ "xrandr >= 1.3" "wayland-client >= 1.18" "wayland-server >= 1.18" \ "wayland-protocols >= 1.49"; do pkg-config --exists "$p" 2>/dev/null || pc+=("$p") done if (( ${#pc[@]} )); then echo "install first: ${pc[*]}" echo " Fedora/Nobara: libdrm-devel libxcb-devel libX11-devel libXrandr-devel libxshmfence-devel wayland-devel wayland-protocols-devel" echo " Debian/Ubuntu: libdrm-dev libxcb1-dev libx11-dev libx11-xcb-dev libxrandr-dev libxshmfence-dev libwayland-dev wayland-protocols" echo " Arch/CachyOS: libdrm libxcb libx11 libxrandr libxshmfence wayland wayland-protocols" exit 1 fi fi if ! "$deps/venv/bin/meson" --version >/dev/null 2>&1; then python3 -m venv --clear "$deps/venv" "$deps/venv/bin/pip" install -q --disable-pip-version-check meson mako pyyaml packaging fi } source "$root/tools/sdk.sh" step_dlls() { if [ ! -f "$deps/dxc/dxil.dll" ]; then fetch "${DXC[@]}" "$deps/dxc.zip" unzip -q -o -j "$deps/dxc.zip" 'bin?x64?dxcompiler.dll' 'bin?x64?dxil.dll' -d "$deps/dxc" 2>/dev/null || [ -f "$deps/dxc/dxil.dll" ] rm "$deps/dxc.zip" fi if [ ! -f "$deps/dxgi.dll" ]; then fetch "${DXVK[@]}" "$deps/dxvk.tar.gz" tar -xzf "$deps/dxvk.tar.gz" -C "$deps" --strip-components 2 --wildcards '*/x64/dxgi.dll' rm "$deps/dxvk.tar.gz" fi fetch "${D3DCOMPILER[@]}" "$deps/d3dcompiler_47.dll" } step_mesa() { source_of mesa "${MESA[@]}" local b=$deps/mesa/build if [ ! -f "$b/build.ninja" ]; then logged mesa meson setup "$b" "$deps/mesa" --prefix "$deps/mesa-inst" --buildtype release -Db_ndebug=true \ -Dvulkan-drivers=amd -Dgallium-drivers= -Dplatforms=x11,wayland -Dllvm=disabled \ -Dgles1=disabled -Dgles2=disabled -Dopengl=false -Dgbm=disabled -Dglx=disabled -Degl=disabled \ -Dvideo-codecs= -Dvulkan-layers= -Dtools= fi echo "building mesa" logged mesa meson install -C "$b" } step_vkd3d() { source_of vkd3d "${VKD3D[@]}" local b=$deps/vkd3d/build if [ ! -f "$b/build.ninja" ]; then logged vkd3d meson setup "$b" "$deps/vkd3d" --cross-file "$deps/vkd3d/build-win64.txt" --buildtype release \ -Denable_tests=false -Denable_extras=false fi echo "building vkd3d" logged vkd3d meson compile -C "$b" # A prefix made earlier runs the DLLs it was given: hand it the new ones. if [ -d "$sys" ]; then install_vkd3d; fi } install_vkd3d() { x86_64-w64-mingw32-strip -o "$sys/d3d12.dll" "$deps/vkd3d/build/libs/d3d12/d3d12.dll" x86_64-w64-mingw32-strip -o "$sys/d3d12core.dll" "$deps/vkd3d/build/libs/d3d12core/d3d12core.dll" } step_wine() { if [ -n "${PROTON_DIR:-}" ]; then echo "using Proton (${PROTON_DIR}); skipping vanilla wineserver patch build" return fi local ver dir=$deps/wine patch=$root/patches/wine.patch b=$deps/wineserver ver=$("$WINE_BIN" --version) local ref="${ver%% *}" if [ ! -d "$dir/.git" ]; then git init -q "$dir" git -C "$dir" remote add origin "${WINE[0]}" fi local stamp="$ref $(sha256sum < "$patch")" if [ "$(cat "$dir/.git/um-stamp" 2>/dev/null)" != "$stamp" ]; then echo "fetching wine $ref" git -C "$dir" fetch -q --depth 1 origin "$ref" || { echo "note: could not fetch tag $ref; using system wineserver"; return; } git -C "$dir" reset -q --hard git -C "$dir" checkout -q --detach FETCH_HEAD if ! git -C "$dir" apply --index "$patch" 2>/dev/null; then echo "note: patches/wine.patch does not apply to $ref (newer Wine 11.x already refactored mapped views); using system wineserver" git -C "$dir" reset -q --hard rm -rf "$b" return fi git -C "$dir" diff HEAD > "$dir/.git/um-patch" echo "$stamp" > "$dir/.git/um-stamp" fi if [ "$(cat "$b/version" 2>/dev/null)" != "$ver" ]; then rm -rf "$b"; fi mkdir -p "$b" if [ ! -f "$b/Makefile" ]; then (cd "$b" && logged wineserver "$deps/wine/configure" --enable-win64 --without-x --without-wayland --without-freetype --without-vulkan --disable-tests) fi echo "building wineserver" logged wineserver make -C "$b" -j"$(nproc)" server/wineserver echo "$ver" > "$b/version" } step_prefix() { if [ ! -f "$WINEPREFIX/system.reg" ]; then echo "creating the prefix (runtime: ${PROTON_DIR:-$WINE_BIN})" mkdir -p "$state" WINEDLLOVERRIDES='mscoree,mshtml=d;winemenubuilder.exe=d' WINESERVER="$WINESERVER_BIN" "$WINE_BIN" wineboot -u "$WINESERVER_BIN" -w fi mkdir -p "$sys" install_vkd3d install -m 644 "$deps/dxgi.dll" "$deps/d3dcompiler_47.dll" "$sys/" if [ -d "$deps/fsr4/system32" ]; then install -m 644 "$deps/fsr4/system32"/*.dll "$sys/"; fi } # The driver's ML frame generation checks the version RtlGetVersion reports. step_win11() { if [ ! -f "$WINEPREFIX/system.reg" ]; then echo "no prefix: run ./setup.sh prefix first"; exit 1; fi if ! awk '/^\[/ { s = /^\[Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\]/ } s && /^"CurrentBuildNumber"="2[2-9][0-9][0-9][0-9]"/ { f = 1 } END { exit !f }' "$WINEPREFIX/system.reg"; then echo "setting the prefix to Windows 11" WINEDLLOVERRIDES='mscoree,mshtml=d;winemenubuilder.exe=d' WINESERVER="$WINESERVER_BIN" "$WINE_BIN" winecfg -v win11 "$WINESERVER_BIN" -w fi } step_victory() { echo "building victory" "$root/build.sh" } step_fsr4() { local bridge="" proton dll local -a protons if [ -n "${PROTON:-}" ]; then protons=("$PROTON") else mapfile -t protons < <(ls -d /usr/share/steam/compatibilitytools.d/*/ "$HOME"/.local/share/Steam/compatibilitytools.d/*/ 2>/dev/null | sort -Vr) protons=("$PROTON_DIR" "${protons[@]}" "$HOME/.local/share/Steam/steamapps/common/Proton - Experimental" "$HOME"/.local/share/Steam/steamapps/common/Proton*) fi for proton in "${protons[@]}"; do dll=$proton/files/lib/wine/x86_64-windows/amdxc64.dll [ -f "$dll" ] || continue [ -n "$bridge" ] || bridge=$dll # Only shims with the MLFG patch let amdxcffx64 offer the ML generator. if grep -aq UpdateFfxApiProviderEx "$dll"; then bridge=$dll; break; fi done if [ ! -f "$bridge" ]; then echo "amdxc64.dll comes from proton: point at one with PROTON=/path/to/proton"; exit 1; fi echo "amdxc64.dll from $bridge" if ! grep -aq UpdateFfxApiProviderEx "$bridge"; then echo "warning: this amdxc64.dll can't expose ML frame generation (VICTORY_FIDELITYFX_FRAMEGEN=4 falls back to 3.x); use GE-Proton 11, Proton-EM 10.0-33+ or proton-cachyos (PROTON=/path/to/proton)" fi fetch "${FSR4[@]}" "$deps/fsr4/amd_fidelityfx_upscaler_dx12.dll" fetch "${FSR4_FG[@]}" "$deps/fsr4/amd_fidelityfx_framegeneration_dx12.dll" if ! echo "${FSR4_DRIVER[1]} $deps/fsr4/system32/amdxcffx64.dll" | sha256sum -c --status 2>/dev/null; then mkdir -p "$deps/fsr4/system32" echo "fetching amdxcffx64.dll" curl -fL --retry 3 -sS "${FSR4_DRIVER[0]}" | xz -d > "$deps/fsr4/system32/amdxcffx64.dll.part" if ! echo "${FSR4_DRIVER[1]} $deps/fsr4/system32/amdxcffx64.dll.part" | sha256sum -c --status; then echo "${FSR4_DRIVER[0]} is not the file expected"; exit 1; fi mv "$deps/fsr4/system32/amdxcffx64.dll.part" "$deps/fsr4/system32/amdxcffx64.dll" fi install -m 644 "$bridge" "$deps/fsr4/system32/amdxc64.dll" if [ -d "$sys" ]; then install -m 644 "$deps/fsr4/system32"/*.dll "$sys/"; fi } mkdir -p "$deps" export PATH=$deps/venv/bin:$PATH if (( $# == 0 )); then set -- sdk dlls mesa vkd3d wine prefix victory; fi step_tools "$@" for step in "$@"; do case "$step" in sdk|dlls|mesa|vkd3d|wine|prefix|victory|fsr4|win11) "step_$step";; *) echo "usage: setup.sh [sdk|dlls|mesa|vkd3d|wine|prefix|victory|fsr4|win11]..."; exit 1;; esac done