Merge pull request #175851 from reckenrode/dxvk-refactor

dxvk: refactor derivation and Darwin support
This commit is contained in:
Sandro 2022-06-11 15:11:41 +02:00 committed by GitHub
commit 1ec895fd1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 140 deletions

View File

@ -1,35 +1,48 @@
Source: https://github.com/marzent/dxvk/commit/65247afe2de5dd6b555b8fdd46dddcdc6325e1d6
---
src/d3d11/d3d11_device.cpp | 12 +-
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp
index 21f0d1b4a..5b1d05335 100644 index 09f3559a..215787f9 100644
--- a/src/d3d11/d3d11_device.cpp --- a/src/d3d11/d3d11_device.cpp
+++ b/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp
@@ -799,8 +799,12 @@ namespace dxvk { @@ -801,8 +801,12 @@ namespace dxvk {
InitReturnPtr(ppGeometryShader); InitReturnPtr(ppGeometryShader);
D3D11CommonShader module; D3D11CommonShader module;
- if (!m_dxvkDevice->features().extTransformFeedback.transformFeedback) - if (!m_dxvkDevice->features().extTransformFeedback.transformFeedback)
- return DXGI_ERROR_INVALID_CALL; - return DXGI_ERROR_INVALID_CALL;
+ if (!m_dxvkDevice->features().extTransformFeedback.transformFeedback) { + if (!m_dxvkDevice->features().extTransformFeedback.transformFeedback) {
+ Logger::err( + Logger::err(
+ "D3D11: CreateGeometryShaderWithStreamOutput:" + "D3D11: CreateGeometryShaderWithStreamOutput:"
+ "\n Transform feedback not supported by device"); + "\n Transform feedback not supported by device");
+ return S_OK; + return S_OK;
+ } + }
// Zero-init some counterss so that we can increment // Zero-init some counterss so that we can increment
// them while walking over the stream output entries // them while walking over the stream output entries
@@ -1973,8 +1977,8 @@ namespace dxvk { @@ -1920,7 +1924,7 @@ namespace dxvk {
DxvkDeviceFeatures supported = adapter->features();
DxvkDeviceFeatures enabled = {};
- enabled.core.features.geometryShader = VK_TRUE;
+ enabled.core.features.geometryShader = supported.core.features.geometryShader;
enabled.core.features.robustBufferAccess = VK_TRUE;
enabled.core.features.shaderStorageImageWriteWithoutFormat = VK_TRUE;
enabled.core.features.depthBounds = supported.core.features.depthBounds;
@@ -1951,7 +1955,7 @@ namespace dxvk {
enabled.core.features.sampleRateShading = VK_TRUE;
enabled.core.features.samplerAnisotropy = supported.core.features.samplerAnisotropy;
enabled.core.features.shaderClipDistance = VK_TRUE;
- enabled.core.features.shaderCullDistance = VK_TRUE;
+ enabled.core.features.shaderCullDistance = supported.core.features.shaderCullDistance;
enabled.core.features.textureCompressionBC = VK_TRUE;
enabled.extDepthClipEnable.depthClipEnable = supported.extDepthClipEnable.depthClipEnable;
enabled.extHostQueryReset.hostQueryReset = VK_TRUE;
@@ -1971,8 +1975,8 @@ namespace dxvk {
enabled.core.features.logicOp = supported.core.features.logicOp; enabled.core.features.logicOp = supported.core.features.logicOp;
enabled.core.features.shaderImageGatherExtended = VK_TRUE; enabled.core.features.shaderImageGatherExtended = VK_TRUE;
enabled.core.features.variableMultisampleRate = supported.core.features.variableMultisampleRate; enabled.core.features.variableMultisampleRate = supported.core.features.variableMultisampleRate;
- enabled.extTransformFeedback.transformFeedback = VK_TRUE; - enabled.extTransformFeedback.transformFeedback = VK_TRUE;
- enabled.extTransformFeedback.geometryStreams = VK_TRUE; - enabled.extTransformFeedback.geometryStreams = VK_TRUE;
+ enabled.extTransformFeedback.transformFeedback = supported.extTransformFeedback.transformFeedback; + enabled.extTransformFeedback.transformFeedback = supported.extTransformFeedback.transformFeedback;
+ enabled.extTransformFeedback.geometryStreams = supported.extTransformFeedback.geometryStreams; + enabled.extTransformFeedback.geometryStreams = supported.extTransformFeedback.geometryStreams;
} }
if (featureLevel >= D3D_FEATURE_LEVEL_10_1) { if (featureLevel >= D3D_FEATURE_LEVEL_10_1) {

View File

@ -6,29 +6,31 @@
, pkgsCross , pkgsCross
}: }:
let stdenvNoCC.mkDerivation (finalAttrs:
inherit (hostPlatform.uname) system; let
inherit (hostPlatform.uname) system;
# DXVK needs to be a separate derivation because its actually a set of DLLs for Windows that # DXVK needs to be a separate derivation because its actually a set of DLLs for Windows that
# needs to be built with a cross-compiler. # needs to be built with a cross-compiler.
dxvk32 = pkgsCross.mingw32.callPackage ./dxvk.nix { inherit (self) src version dxvkPatches; }; dxvk32 = pkgsCross.mingw32.callPackage ./dxvk.nix {
dxvk64 = pkgsCross.mingwW64.callPackage ./dxvk.nix { inherit (self) src version dxvkPatches; }; inherit (finalAttrs) src version dxvkPatches;
};
# Split out by platform to make maintenance easy in case supported versions on Darwin and other dxvk64 = pkgsCross.mingwW64.callPackage ./dxvk.nix {
# platforms diverge (due to the need for Darwin-specific patches that would fail to apply). inherit (finalAttrs) src version dxvkPatches;
# Should that happen, set `darwin` to the last working `rev` and `hash`.
srcs = rec {
darwin = { inherit (default) rev hash version; };
default = {
rev = "v${self.version}";
hash = "sha256-+6PkrkamSvhCaGj2tq+RXri/yQ7vs0cAqgdRAFtU8UA=";
version = "1.10.1";
}; };
};
# Use the self pattern to support overriding `src` and `version` via `overrideAttrs`. A recursive # Split out by platform to make maintenance easy in case supported versions on Darwin and other
# attrset wouldnt work. # platforms diverge (due to the need for Darwin-specific patches that would fail to apply).
self = stdenvNoCC.mkDerivation { # Should that happen, set `darwin` to the last working `rev` and `hash`.
srcs = rec {
darwin = { inherit (default) rev hash version; };
default = {
rev = "v${finalAttrs.version}";
hash = "sha256-+6PkrkamSvhCaGj2tq+RXri/yQ7vs0cAqgdRAFtU8UA=";
version = "1.10.1";
};
};
in
{
name = "dxvk"; name = "dxvk";
inherit (srcs."${system}" or srcs.default) version; inherit (srcs."${system}" or srcs.default) version;
@ -70,32 +72,12 @@ let
done done
''; '';
# DXVK with MoltenVK requires a patched MoltenVK in addition to its own patches. Provide a
# convenience function to handle the necessary patching.
#
# Usage:
# let
# patchedMoltenVK = dxvk.patchMoltenVK darwin.moltenvk;
# in
# wine64Packages.full.override { moltenvk = patchedMoltenVK; vkd3dSupport = false; }
passthru.patchMoltenVK = moltenvk:
moltenvk.overrideAttrs (old: {
patches = old.patches or [ ] ++ [
# Apply MoltenVKs DXVK compatability patch. This is needed to fake support for certain
# extensions. There is no package for a patched MoltenVK to avoid any confusion by users
# whether they should use it. Except with DXVK, the answer is always no.
old.passthru.dxvkPatch
];
});
meta = { meta = {
description = "A Vulkan-based translation layer for Direct3D 9/10/11"; description = "A Vulkan-based translation layer for Direct3D 9/10/11";
homepage = "https://github.com/doitsujin/dxvk"; homepage = "https://github.com/doitsujin/dxvk";
changelog = "https://github.com/doitsujin/dxvk/releases"; changelog = "https://github.com/doitsujin/dxvk/releases";
maintainers = [ lib.maintainers.reckenrode ]; maintainers = [ lib.maintainers.reckenrode ];
license = lib.licenses.zlib; license = lib.licenses.zlib;
platforms = lib.platforms.unix; platforms = [ "x86_64-darwin" "i686-linux" "x86_64-linux" ];
}; };
}; })
in
self

View File

@ -27,7 +27,7 @@
let let
libcxx.dev = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr"; libcxx.dev = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr";
in in
stdenvNoCC.mkDerivation rec { stdenvNoCC.mkDerivation (finalAttrs: {
pname = "MoltenVK"; pname = "MoltenVK";
version = "1.1.9"; version = "1.1.9";
@ -43,10 +43,6 @@ stdenvNoCC.mkDerivation rec {
# MoltenVK requires specific versions of its dependencies. # MoltenVK requires specific versions of its dependencies.
# Pin them here except for cereal, which is four years old and has several CVEs. # Pin them here except for cereal, which is four years old and has several CVEs.
passthru = { passthru = {
# The patch required to support DXVK may different from version to version. This should never
# be used except with DXVK, so theres no package for it. To emphasize that this patch should
# never be used except with DXVK, `dxvk` provides a function for applying this patch.
dxvkPatch = ./dxvk-moltenvk-compat.patch;
glslang = (glslang.overrideAttrs (old: { glslang = (glslang.overrideAttrs (old: {
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "KhronosGroup"; owner = "KhronosGroup";
@ -55,7 +51,7 @@ stdenvNoCC.mkDerivation rec {
hash = "sha256-YLn/Mxuk6mXPGtBBgfwky5Nl1TCAW6i2g+AZLzqVz+A="; hash = "sha256-YLn/Mxuk6mXPGtBBgfwky5Nl1TCAW6i2g+AZLzqVz+A=";
}; };
})).override { })).override {
inherit (passthru) spirv-headers spirv-tools; inherit (finalAttrs.passthru) spirv-headers spirv-tools;
}; };
spirv-cross = spirv-cross.overrideAttrs (old: { spirv-cross = spirv-cross.overrideAttrs (old: {
cmakeFlags = (old.cmakeFlags or [ ]) ++ [ cmakeFlags = (old.cmakeFlags or [ ]) ++ [
@ -84,7 +80,7 @@ stdenvNoCC.mkDerivation rec {
hash = "sha256-2Mr3HbhRslLpRfwHascl7e/UoPijhrij9Bjg3aCiqBM="; hash = "sha256-2Mr3HbhRslLpRfwHascl7e/UoPijhrij9Bjg3aCiqBM=";
}; };
})).override { })).override {
inherit (passthru) spirv-headers; inherit (finalAttrs.passthru) spirv-headers;
}; };
vulkan-headers = vulkan-headers.overrideAttrs (old: { vulkan-headers = vulkan-headers.overrideAttrs (old: {
src = fetchFromGitHub { src = fetchFromGitHub {
@ -99,7 +95,7 @@ stdenvNoCC.mkDerivation rec {
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "KhronosGroup"; owner = "KhronosGroup";
repo = "MoltenVK"; repo = "MoltenVK";
rev = "v${version}"; rev = "v${finalAttrs.version}";
hash = "sha256-5ie1IGzZqaYbciFnrBJ1/9V0LEuz7JsEOFXXkG3hJzg="; hash = "sha256-5ie1IGzZqaYbciFnrBJ1/9V0LEuz7JsEOFXXkG3hJzg=";
}; };
@ -117,24 +113,24 @@ stdenvNoCC.mkDerivation rec {
substituteInPlace MoltenVKShaderConverter/MoltenVKShaderConverter.xcodeproj/project.pbxproj \ substituteInPlace MoltenVKShaderConverter/MoltenVKShaderConverter.xcodeproj/project.pbxproj \
--replace @@sourceRoot@@ $(pwd) \ --replace @@sourceRoot@@ $(pwd) \
--replace @@libcxx@@ "${libcxx.dev}" \ --replace @@libcxx@@ "${libcxx.dev}" \
--replace @@glslang@@ "${passthru.glslang}" \ --replace @@glslang@@ "${finalAttrs.passthru.glslang}" \
--replace @@spirv-cross@@ "${passthru.spirv-cross}" \ --replace @@spirv-cross@@ "${finalAttrs.passthru.spirv-cross}" \
--replace @@spirv-tools@@ "${passthru.glslang.spirv-tools}" \ --replace @@spirv-tools@@ "${finalAttrs.passthru.glslang.spirv-tools}" \
--replace @@spirv-headers@@ "${passthru.glslang.spirv-headers}" --replace @@spirv-headers@@ "${finalAttrs.passthru.glslang.spirv-headers}"
substituteInPlace MoltenVK/MoltenVK.xcodeproj/project.pbxproj \ substituteInPlace MoltenVK/MoltenVK.xcodeproj/project.pbxproj \
--replace @@sourceRoot@@ $(pwd) \ --replace @@sourceRoot@@ $(pwd) \
--replace @@libcxx@@ "${libcxx.dev}" \ --replace @@libcxx@@ "${libcxx.dev}" \
--replace @@cereal@@ "${cereal}" \ --replace @@cereal@@ "${cereal}" \
--replace @@spirv-cross@@ "${passthru.spirv-cross}" \ --replace @@spirv-cross@@ "${finalAttrs.passthru.spirv-cross}" \
--replace @@vulkan-headers@@ "${passthru.vulkan-headers}" --replace @@vulkan-headers@@ "${finalAttrs.passthru.vulkan-headers}"
substituteInPlace Scripts/create_dylib.sh \ substituteInPlace Scripts/create_dylib.sh \
--replace @@sourceRoot@@ $(pwd) \ --replace @@sourceRoot@@ $(pwd) \
--replace @@glslang@@ "${passthru.glslang}" \ --replace @@glslang@@ "${finalAttrs.passthru.glslang}" \
--replace @@spirv-tools@@ "${passthru.glslang.spirv-tools}" \ --replace @@spirv-tools@@ "${finalAttrs.passthru.glslang.spirv-tools}" \
--replace @@spirv-cross@@ "${passthru.spirv-cross}" --replace @@spirv-cross@@ "${finalAttrs.passthru.spirv-cross}"
substituteInPlace Scripts/gen_moltenvk_rev_hdr.sh \ substituteInPlace Scripts/gen_moltenvk_rev_hdr.sh \
--replace @@sourceRoot@@ $(pwd) \ --replace @@sourceRoot@@ $(pwd) \
--replace '$(git rev-parse HEAD)' ${src.rev} --replace '$(git rev-parse HEAD)' ${finalAttrs.src.rev}
''; '';
dontConfigure = true; dontConfigure = true;
@ -197,4 +193,4 @@ stdenvNoCC.mkDerivation rec {
license = lib.licenses.asl20; license = lib.licenses.asl20;
platforms = lib.platforms.darwin; platforms = lib.platforms.darwin;
}; };
} })

View File

@ -1,59 +0,0 @@
Source: https://github.com/Gcenx/MoltenVK/commit/1f268bd45f6c928784d7cb90dedce382895f10ae
Fake extensions for DXVK;
- _features.geometryShader
- _features.tessellationShader
- _features.shaderCullDistance
Enabled defaults;
- MVK_ALLOW_METAL_FENCES=1
- MVK_CONFIG_RESUME_LOST_DEVICE=1
---
MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 3 +++
MoltenVK/MoltenVK/Utility/MVKEnvironment.h | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
index bc6d19df..e1959c6e 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
@@ -1656,6 +1656,8 @@
_features.robustBufferAccess = true; // XXX Required by Vulkan spec
_features.fullDrawIndexUint32 = true;
_features.independentBlend = true;
+ _features.geometryShader = true; // XXX Required by DXVK for D3D10
+ _features.tessellationShader = true; // XXX Required by DXVK for D3D11
_features.sampleRateShading = true;
_features.depthBiasClamp = true;
_features.fillModeNonSolid = true;
@@ -1669,6 +1671,7 @@
_features.shaderUniformBufferArrayDynamicIndexing = true;
_features.shaderStorageBufferArrayDynamicIndexing = true;
_features.shaderClipDistance = true;
+ _features.shaderCullDistance = true; // XXX Required by DXVK for 10level9
_features.shaderInt16 = true;
_features.multiDrawIndirect = true;
_features.inheritedQueries = true;
diff --git a/MoltenVK/MoltenVK/Utility/MVKEnvironment.h b/MoltenVK/MoltenVK/Utility/MVKEnvironment.h
index 81d0defc..80c414d3 100644
--- a/MoltenVK/MoltenVK/Utility/MVKEnvironment.h
+++ b/MoltenVK/MoltenVK/Utility/MVKEnvironment.h
@@ -240,7 +240,7 @@ void mvkSetConfig(const MVKConfiguration& mvkConfig);
# define MVK_ALLOW_METAL_EVENTS 1
#endif
#ifndef MVK_ALLOW_METAL_FENCES
-# define MVK_ALLOW_METAL_FENCES 0
+# define MVK_ALLOW_METAL_FENCES 1 // XXX Required by DXVK for Apple/NVidia GPUs (better FPS than CPU Emulation)
#endif
/** Substitute Metal 2D textures for Vulkan 1D images. Enabled by default. */
@@ -275,7 +275,7 @@ void mvkSetConfig(const MVKConfiguration& mvkConfig);
/** Resume MVKDevice VK_ERROR_DEVICE_LOST errors that do not cause MVKPhysicalDevice errors. Disabled by default. */
#ifndef MVK_CONFIG_RESUME_LOST_DEVICE
-# define MVK_CONFIG_RESUME_LOST_DEVICE 0
+# define MVK_CONFIG_RESUME_LOST_DEVICE 1
#endif
/** Support Metal argument buffers. Disabled by default. */