diff options
author | Stelios Tsampas | 2023-03-06 20:34:05 +0200 |
---|---|---|
committer | Stelios Tsampas | 2023-03-06 20:34:59 +0200 |
commit | e6e055beea40a4f2466da590945bd561ceb46032 (patch) | |
tree | 786847b03027039d9cf6050bd2db3a80385aa931 | |
download | aur-e6e055beea40a4f2466da590945bd561ceb46032.tar.gz |
[dxvk-nvapi-mingw-git] initial commit
-rw-r--r-- | .SRCINFO | 30 | ||||
-rw-r--r-- | PKGBUILD | 116 | ||||
-rw-r--r-- | dxvk-nvapi-extraopts.patch | 29 | ||||
-rw-r--r-- | setup_dxvk_nvapi | 2 | ||||
-rwxr-xr-x | setup_dxvk_nvapi.sh | 193 |
5 files changed, 370 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..61fecab6bec9 --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,30 @@ +pkgbase = dxvk-nvapi-mingw-git + pkgdesc = Alternative NVAPI implementation on top of DXVK. + pkgver = 0.6.1 + pkgrel = 1 + url = https://github.com/jp7677/dxvk-nvapi + arch = x86_64 + license = MIT + makedepends = ninja + makedepends = meson>=0.43 + makedepends = glslang + makedepends = git + makedepends = mingw-w64-gcc + depends = vulkan-icd-loader + depends = wine>=4.0rc1 + depends = lib32-vulkan-icd-loader + depends = dxvk + depends = bash + options = !lto + source = git+https://github.com/jp7677/dxvk-nvapi.git + source = git+https://github.com/KhronosGroup/Vulkan-Headers.git + source = dxvk-nvapi-extraopts.patch + source = setup_dxvk_nvapi.sh + source = setup_dxvk_nvapi + sha256sums = SKIP + sha256sums = SKIP + sha256sums = dff5ecd1a35a94a4dc1fa5fd08c10b5c88703797520d6b315207124ff1adeef8 + sha256sums = 62a14512ab32ff534d8b07f2cdefae17ee679c73465edeb11bfac1e88f0a7109 + sha256sums = 1f4934c5bfcf208e288a0eda2f385f82acc9e78a4b0ac2a77b5af14c64c8e21e + +pkgname = dxvk-nvapi-mingw-git diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..0edbbc3d1a62 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,116 @@ +# Maintainer: loathingkernel <loathingkernel @at gmail .dot com> + +pkgname=dxvk-nvapi-mingw-git +pkgver=0.6.1 +pkgrel=1 +pkgdesc='Alternative NVAPI implementation on top of DXVK. ' +arch=('x86_64') +url="https://github.com/jp7677/dxvk-nvapi" +license=('MIT') +depends=('vulkan-icd-loader' 'wine>=4.0rc1' 'lib32-vulkan-icd-loader' 'dxvk' 'bash') +makedepends=('ninja' 'meson>=0.43' 'glslang' 'git' 'mingw-w64-gcc') +options=(!lto) +source=( + "git+https://github.com/jp7677/dxvk-nvapi.git" + "git+https://github.com/KhronosGroup/Vulkan-Headers.git" + "dxvk-nvapi-extraopts.patch" + "setup_dxvk_nvapi.sh" + "setup_dxvk_nvapi" +) + +pkgver() { + cd dxvk-nvapi + printf "%s" "$(git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/v//g')" +} + +prepare() { + cd dxvk-nvapi + + git submodule init "external/Vulkan-Headers" + git submodule set-url "external/Vulkan-Headers" "$srcdir"/Vulkan-Headers + git -c protocol.file.allow=always submodule update "external/Vulkan-Headers" + + # By default export FLAGS used by proton and ignore makepkg + # This overrides FLAGS from makepkg.conf, if you comment these you are on your own + # If you want the "best" possible optimizations for your system you can use + # `-march=native` and remove the `-mtune=core-avx2` option. + # `-O2` is adjusted to `-O3` since AVX is disabled + export CFLAGS="-O2 -march=nocona -mtune=core-avx2 -pipe" + export CXXFLAGS="-O2 -march=nocona -mtune=core-avx2 -pipe" + export LDFLAGS="-Wl,-O1,--sort-common,--as-needed" + + # Uncomment to enable extra optimizations + # Patch crossfiles with extra optimizations from makepkg.conf + patch -p1 -i "$srcdir"/dxvk-nvapi-extraopts.patch + local cross_cflags="$CFLAGS" + local cross_cxxflags="$CXXFLAGS" + local cross_ldflags="$LDFLAGS" + + # If using -march=native and the CPU supports AVX, launching a d3d9 + # game can cause an Unhandled exception. The cause seems to be the + # combination of AVX instructions and tree vectorization (implied by O3), + # all tested archictures from sandybridge to haswell are affected. + # Disabling AVX (and AVX2 as a side-effect). + # Since Wine 5.16 AVX is supported. Testing showed 32bit applications + # crashing with AVX regardless, but 64bit applications worked just fine. + # So disable AVX only for the 32bit binaries and AVX2 for the 64bit. + # AVX2 seems to degrade performance. So disregard the above. + # Relevant Wine issues + # https://bugs.winehq.org/show_bug.cgi?id=45289 + # https://bugs.winehq.org/show_bug.cgi?id=43516 + cross_cflags+=" -mno-avx2" + cross_cxxflags+=" -mno-avx2" + + # These flags are taken from Proton, I don't know if there are issues with Arch wine. + cross_cflags+=" -mfpmath=sse -fwrapv -fno-strict-aliasing -gdwarf-2 -gstrict-dwarf" + cross_cxxflags+=" -mfpmath=sse -fwrapv -fno-strict-aliasing -gdwarf-2 -gstrict-dwarf -std=c++17" + cross_ldflags+=" -Wl,--file-alignment,4096" + + sed -i build-win64.txt \ + -e "s|@CARGS@|\'${cross_cflags// /\',\'}\'|g" \ + -e "s|@CXXARGS@|\'${cross_cxxflags// /\',\'}\'|g" \ + -e "s|@LDARGS@|\'${cross_ldflags// /\',\'}\'|g" + + cross_cflags+=" -mstackrealign -mno-avx" + cross_cxxflags+=" -mstackrealign -mno-avx" + sed -i build-win32.txt \ + -e "s|@CARGS@|\'${cross_cflags// /\',\'}\'|g" \ + -e "s|@CXXARGS@|\'${cross_cxxflags// /\',\'}\'|g" \ + -e "s|@LDARGS@|\'${cross_ldflags// /\',\'}\'|g" +} + +build() { + + meson setup dxvk-nvapi "build/x64" \ + --cross-file dxvk-nvapi/build-win64.txt \ + --prefix "/usr/share/dxvk-nvapi/x64" \ + --bindir "" --libdir "" \ + --buildtype "release" \ + --strip \ + -Denable_tests=false + ninja -C "build/x64" -v + + meson setup dxvk-nvapi "build/x32" \ + --cross-file dxvk-nvapi/build-win32.txt \ + --prefix "/usr/share/dxvk-nvapi/x32" \ + --bindir "" --libdir "" \ + --buildtype "release" \ + --strip \ + -Denable_tests=false + ninja -C "build/x32" -v +} + +package() { + DESTDIR="$pkgdir" ninja -C "build/x32" install + DESTDIR="$pkgdir" ninja -C "build/x64" install + install -Dm 755 -t "$pkgdir/usr/share/dxvk-nvapi" setup_dxvk_nvapi.sh + install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" dxvk-nvapi/README.md + install -Dm 644 -t "$pkgdir/usr/share/licenses/$pkgname" dxvk-nvapi/LICENSE + install -Dm 755 -t "$pkgdir/usr/bin" setup_dxvk_nvapi +} + +sha256sums=('SKIP' + 'SKIP' + 'dff5ecd1a35a94a4dc1fa5fd08c10b5c88703797520d6b315207124ff1adeef8' + '62a14512ab32ff534d8b07f2cdefae17ee679c73465edeb11bfac1e88f0a7109' + '1f4934c5bfcf208e288a0eda2f385f82acc9e78a4b0ac2a77b5af14c64c8e21e') diff --git a/dxvk-nvapi-extraopts.patch b/dxvk-nvapi-extraopts.patch new file mode 100644 index 000000000000..75f1e49aa3f7 --- /dev/null +++ b/dxvk-nvapi-extraopts.patch @@ -0,0 +1,29 @@ +diff --git a/build-win32.txt b/build-win32.txt +index 7d991cf..debc982 100644 +--- a/build-win32.txt ++++ b/build-win32.txt +@@ -4,8 +4,8 @@ strip = 'i686-w64-mingw32-strip' + ar = 'i686-w64-mingw32-ar' + + [built-in options] +-cpp_args=['-msse', '-msse2'] +-cpp_link_args = ['-static', '-static-libgcc', '-static-libstdc++'] ++cpp_args=['-msse', '-msse2', @CXXARGS@] ++cpp_link_args = ['-static', '-static-libgcc', '-static-libstdc++', @LDARGS@] + + [properties] + needs_exe_wrapper = true +diff --git a/build-win64.txt b/build-win64.txt +index 3b1d99d..6847d89 100644 +--- a/build-win64.txt ++++ b/build-win64.txt +@@ -4,7 +4,8 @@ strip = 'x86_64-w64-mingw32-strip' + ar = 'x86_64-w64-mingw32-ar' + + [built-in options] +-cpp_link_args = ['-static', '-static-libgcc', '-static-libstdc++'] ++cpp_args=[@CXXARGS@] ++cpp_link_args = ['-static', '-static-libgcc', '-static-libstdc++', @LDARGS@] + + [properties] + needs_exe_wrapper = true diff --git a/setup_dxvk_nvapi b/setup_dxvk_nvapi new file mode 100644 index 000000000000..2b8544e0f9b1 --- /dev/null +++ b/setup_dxvk_nvapi @@ -0,0 +1,2 @@ +#!/bin/sh +/usr/share/dxvk-nvapi/setup_dxvk_nvapi.sh $@ diff --git a/setup_dxvk_nvapi.sh b/setup_dxvk_nvapi.sh new file mode 100755 index 000000000000..8a5c60c4ecb5 --- /dev/null +++ b/setup_dxvk_nvapi.sh @@ -0,0 +1,193 @@ +#!/usr/bin/env bash + +# default directories +dxvk_nvapi_lib32=${dxvk_nvapi_lib32:-"x32"} +dxvk_nvapi_lib64=${dxvk_nvapi_lib64:-"x64"} + +# figure out where we are +basedir=$(dirname "$(readlink -f "$0")") + +# figure out which action to perform +action="$1" + +case "$action" in +install) + ;; +uninstall) + ;; +*) + echo "Unrecognized action: $action" + echo "Usage: $0 [install|uninstall] [--symlink]" + exit 1 +esac + +# process arguments +shift + +file_cmd="cp -v" + +while (($# > 0)); do + case "$1" in + "--symlink") + file_cmd="ln -s -v" + ;; + esac + shift +done + +# check wine prefix before invoking wine, so that we +# don't accidentally create one if the user screws up +if [ -n "$WINEPREFIX" ] && ! [ -f "$WINEPREFIX/system.reg" ]; then + echo "$WINEPREFIX:"' Not a valid wine prefix.' >&2 + exit 1 +fi + +# find wine executable +export WINEDEBUG=-all +# disable mscoree and mshtml to avoid downloading +# wine gecko and mono +export WINEDLLOVERRIDES="mscoree,mshtml=" + +wine="wine" +wine64="wine64" +wineboot="wineboot" + +# $PATH is the way for user to control where wine is located (including custom Wine versions). +# Pure 64-bit Wine (non Wow64) requries skipping 32-bit steps. +# In such case, wine64 and winebooot will be present, but wine binary will be missing, +# however it can be present in other PATHs, so it shouldn't be used, to avoid versions mixing. +wine_path=$(dirname "$(which $wineboot)") +wow64=true +if ! [ -f "$wine_path/$wine" ]; then + wine=$wine64 + wow64=false +fi + +# resolve 32-bit and 64-bit system32 path +winever=$($wine --version | grep wine) +if [ -z "$winever" ]; then + echo "$wine: Not a wine executable. Check your $wine." >&2 + exit 1 +fi + +# ensure wine placeholder dlls are recreated +# if they are missing +$wineboot -u + +win64_sys_path=$($wine64 winepath -u 'C:\windows\system32' 2> /dev/null) +win64_sys_path="${win64_sys_path/$'\r'/}" +if $wow64; then + win32_sys_path=$($wine winepath -u 'C:\windows\system32' 2> /dev/null) + win32_sys_path="${win32_sys_path/$'\r'/}" +fi + +if [ -z "$win32_sys_path" ] && [ -z "$win64_sys_path" ]; then + echo 'Failed to resolve C:\windows\system32.' >&2 + exit 1 +fi + +# create native dll override +overrideDll() { + if ! $wine reg add 'HKEY_CURRENT_USER\Software\Wine\DllOverrides' /v "$1" /d native /f >/dev/null 2>&1 + then + echo -e "Failed to add override for $1" + exit 1 + fi +} + +# remove dll override +restoreDll() { + if ! $wine reg delete 'HKEY_CURRENT_USER\Software\Wine\DllOverrides' /v "$1" /f > /dev/null 2>&1 + then + echo "Failed to remove override for $1" + fi +} + +# copy or link dxvk_nvapi dll, back up original file +installFile() { + dstfile="${1}/${3}.dll" + srcfile="${basedir}/${2}/${3}.dll" + + if ! [ -f "${srcfile}" ]; then + echo "${srcfile}: File not found. Skipping." >&2 + return 1 + fi + + if [ -n "$1" ]; then + if [ -f "${dstfile}" ] || [ -h "${dstfile}" ]; then + if ! [ -f "${dstfile}.old" ]; then + mv -v "${dstfile}" "${dstfile}.old" + else + rm -v "${dstfile}" + fi + else + touch "${dstfile}.old_none" + fi + $file_cmd "${srcfile}" "${dstfile}" + fi + return 0 +} + +# remove dxvk_nvapi dll, restore original file +uninstallFile() { + dstfile="${1}/${3}.dll" + srcfile="${basedir}/${2}/${3}.dll" + + if ! [ -f "${srcfile}" ]; then + echo "${srcfile}: File not found. Skipping." >&2 + return 1 + fi + + if ! [ -f "${dstfile}" ] && ! [ -h "${dstfile}" ]; then + echo "${dstfile}: File not found. Skipping." >&2 + return 1 + fi + + if [ -f "${dstfile}.old" ]; then + rm -v "${dstfile}" + mv -v "${dstfile}.old" "${dstfile}" + return 0 + elif [ -f "${dstfile}.old_none" ]; then + rm -v "${dstfile}.old_none" + rm -v "${dstfile}" + return 0 + else + return 1 + fi +} + +install() { + installFile "$win64_sys_path" "$dxvk_nvapi_lib64" "${1}64" + inst64_ret="$?" + if (( (inst64_ret == 0) )); then + overrideDll "${1}64" + fi + + inst32_ret=-1 + if $wow64; then + installFile "$win32_sys_path" "$dxvk_nvapi_lib32" "$1" + inst32_ret="$?" + if (( (inst32_ret == 0) )); then + overrideDll "$1" + fi + fi +} + +uninstall() { + uninstallFile "$win64_sys_path" "$dxvk_nvapi_lib64" "${1}64" + uninst64_ret="$?" + if (( (uninst64_ret == 0) )); then + restoreDll "${1}64" + fi + + uninst32_ret=-1 + if $wow64; then + uninstallFile "$win32_sys_path" "$dxvk_nvapi_lib32" "$1" + uninst32_ret="$?" + if (( (uninst32_ret == 0) )); then + restoreDll "$1" + fi + fi +} + +$action nvapi |