From d313406e0d5d031915c3d3c35a8a9cb7bda02fcd Mon Sep 17 00:00:00 2001 From: cdozdil Date: Sat, 16 Mar 2024 02:35:24 +0300 Subject: [PATCH] 2.1.2 vulkan issue --- CyberXeSS/CyberXeSS.vcxproj | 2 +- .../backends/fsr2/FSR2Feature_Dx11On12.cpp | 84 ++++++++++++------- CyberXeSS/backends/fsr2_212/FSR2Feature_212.h | 5 -- .../fsr2_212/FSR2Feature_Dx11On12_212.cpp | 5 -- .../fsr2_212/FSR2Feature_Dx12_212.cpp | 5 -- .../backends/fsr2_212/FSR2Feature_Vk_212.cpp | 5 -- .../cas/include/backends/dx12/ffx_dx12.h | 11 ++- CyberXeSS/cas/include/ffx_cas.h | 6 +- .../dx12/shaders/ffx_fsr2_shaders_dx12.h | 10 +-- .../include/vk/shaders/ffx_fsr2_shaders_vk.h | 10 +-- nvngx.ini | 9 +- 11 files changed, 77 insertions(+), 75 deletions(-) diff --git a/CyberXeSS/CyberXeSS.vcxproj b/CyberXeSS/CyberXeSS.vcxproj index b4d22b1b..78843086 100644 --- a/CyberXeSS/CyberXeSS.vcxproj +++ b/CyberXeSS/CyberXeSS.vcxproj @@ -82,7 +82,7 @@ $(SolutionDir)external\vulkan\include;$(SolutionDir)external\nvngx_dlss_sdk;$(SolutionDir)external\xess\inc\xess;$(SolutionDir)external\simpleini;$(SolutionDir)external\unordered_dense\include;$(SolutionDir)external\spdlog\include;C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath) $(SolutionDir)CyberXess\cas\lib;$(SolutionDir)CyberXess\fsr2\lib;$(SolutionDir)CyberXess\fsr2_212\lib;$(SolutionDir)CyberXess\vulkan;$(SolutionDir)external\xess\lib;C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64;$(LibraryPath) nvngx - ..\..\..\Games\Nioh 2 The Complete Edition + E:\Games\No Man%27s Sky\Binaries .\x64\Debug diff --git a/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.cpp b/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.cpp index 075641f1..61429b32 100644 --- a/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.cpp +++ b/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.cpp @@ -109,17 +109,17 @@ void FSR2FeatureDx11on12::ReleaseSharedResources() spdlog::debug("FSR2FeatureDx11on12::ReleaseSharedResources start!"); SAFE_RELEASE(dx11Color.SharedTexture) - SAFE_RELEASE(dx11Mv.SharedTexture) - SAFE_RELEASE(dx11Out.SharedTexture) - SAFE_RELEASE(dx11Depth.SharedTexture) - SAFE_RELEASE(dx11Tm.SharedTexture) - SAFE_RELEASE(dx11Exp.SharedTexture) - SAFE_RELEASE(dx11Color.Dx12Resource) - SAFE_RELEASE(dx11Mv.Dx12Resource) - SAFE_RELEASE(dx11Out.Dx12Resource) - SAFE_RELEASE(dx11Depth.Dx12Resource) - SAFE_RELEASE(dx11Tm.Dx12Resource) - SAFE_RELEASE(dx11Exp.Dx12Resource) + SAFE_RELEASE(dx11Mv.SharedTexture) + SAFE_RELEASE(dx11Out.SharedTexture) + SAFE_RELEASE(dx11Depth.SharedTexture) + SAFE_RELEASE(dx11Tm.SharedTexture) + SAFE_RELEASE(dx11Exp.SharedTexture) + SAFE_RELEASE(dx11Color.Dx12Resource) + SAFE_RELEASE(dx11Mv.Dx12Resource) + SAFE_RELEASE(dx11Out.Dx12Resource) + SAFE_RELEASE(dx11Depth.Dx12Resource) + SAFE_RELEASE(dx11Tm.Dx12Resource) + SAFE_RELEASE(dx11Exp.Dx12Resource) } void FSR2FeatureDx11on12::GetHardwareAdapter(IDXGIFactory1* InFactory, IDXGIAdapter** InAdapter, D3D_FEATURE_LEVEL InFeatureLevel, bool InRequestHighPerformanceAdapter) @@ -358,31 +358,53 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N // fence operation results HRESULT fr; - ID3D11Fence* dx11fence_1; - fr = Dx11Device->CreateFence(0, D3D11_FENCE_FLAG_SHARED, IID_PPV_ARGS(&dx11fence_1)); - - if (fr != S_OK) - { - spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create dx11fence_1 {0:x}", fr); - return false; - } - + ID3D11Fence* dx11fence_1 = nullptr; + ID3D12Fence* dx12fence_1 = nullptr; HANDLE dx11_sharedHandle; - fr = dx11fence_1->CreateSharedHandle(nullptr, GENERIC_ALL, nullptr, &dx11_sharedHandle); - if (fr != S_OK) + D3D11_QUERY_DESC pQueryDesc; + pQueryDesc.Query = D3D11_QUERY_EVENT; + pQueryDesc.MiscFlags = 0; + ID3D11Query* query0 = nullptr; + + if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3) { - spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create sharedhandle for dx11fence_1 {0:x}", fr); - return false; + fr = Dx11Device->CreateFence(0, D3D11_FENCE_FLAG_SHARED, IID_PPV_ARGS(&dx11fence_1)); + + if (fr != S_OK) + { + spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create dx11fence_1 {0:x}", fr); + return false; + } + + fr = dx11fence_1->CreateSharedHandle(nullptr, GENERIC_ALL, nullptr, &dx11_sharedHandle); + + if (fr != S_OK) + { + spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create sharedhandle for dx11fence_1 {0:x}", fr); + return false; + } + + fr = Dx12on11Device->OpenSharedHandle(dx11_sharedHandle, IID_PPV_ARGS(&dx12fence_1)); + + if (fr != S_OK) + { + spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create open sharedhandle for dx12fence_1 {0:x}", fr); + return false; + } } - - ID3D12Fence* dx12fence_1; - fr = Dx12on11Device->OpenSharedHandle(dx11_sharedHandle, IID_PPV_ARGS(&dx12fence_1)); - - if (fr != S_OK) + else { - spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create open sharedhandle for dx12fence_1 {0:x}", fr); - return false; + result = Device->CreateQuery(&pQueryDesc, &query0); + + if (result != S_OK || query0 == nullptr) + { + spdlog::error("FeatureContext::FSR2FeatureDx11on12 can't create query1!"); + return false; + } + + // Associate the query with the copy operation + DeviceContext->Begin(query0); } #pragma region Texture copies diff --git a/CyberXeSS/backends/fsr2_212/FSR2Feature_212.h b/CyberXeSS/backends/fsr2_212/FSR2Feature_212.h index 75c868ec..231bd5d1 100644 --- a/CyberXeSS/backends/fsr2_212/FSR2Feature_212.h +++ b/CyberXeSS/backends/fsr2_212/FSR2Feature_212.h @@ -27,11 +27,6 @@ inline static std::string ResultToString212(Fsr212::FfxErrorCode result) } } -inline void FfxLogCallback(const char* message) -{ - spdlog::debug("FSR2Feature::LogCallback FSR Runtime: {0}", message); -} - class FSR2Feature212 : public virtual IFeature { private: diff --git a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.cpp b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.cpp index 95fe4398..18353746 100644 --- a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.cpp +++ b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.cpp @@ -878,11 +878,6 @@ bool FSR2FeatureDx11on12_212::InitFSR2(const NVSDK_NGX_Parameter* InParameters) spdlog::info("FSR2Feature::InitFSR2 contextDesc.initFlags (LowResMV) {0:b}", _contextDesc.flags); } -#if _DEBUG - _contextDesc.flags |= FFX_FSR2_ENABLE_DEBUG_CHECKING; - _contextDesc.fpMessage = FfxLogCallback; -#endif - spdlog::debug("FSR2Feature::InitFSR2 ffxFsr2ContextCreate!"); auto ret = Fsr212::ffxFsr2ContextCreate212(&_context, &_contextDesc); diff --git a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx12_212.cpp b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx12_212.cpp index c1780185..e570a8f1 100644 --- a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx12_212.cpp +++ b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx12_212.cpp @@ -366,11 +366,6 @@ bool FSR2FeatureDx12_212::InitFSR2(const NVSDK_NGX_Parameter* InParameters) spdlog::info("FSR2Feature::InitFSR2 contextDesc.initFlags (LowResMV) {0:b}", _contextDesc.flags); } -#if _DEBUG - _contextDesc.flags |= FFX_FSR2_ENABLE_DEBUG_CHECKING; - _contextDesc.fpMessage = FfxLogCallback; -#endif - spdlog::debug("FSR2Feature::InitFSR2 ffxFsr2ContextCreate!"); auto ret = Fsr212::ffxFsr2ContextCreate212(&_context, &_contextDesc); diff --git a/CyberXeSS/backends/fsr2_212/FSR2Feature_Vk_212.cpp b/CyberXeSS/backends/fsr2_212/FSR2Feature_Vk_212.cpp index 41e166e6..96442ebd 100644 --- a/CyberXeSS/backends/fsr2_212/FSR2Feature_Vk_212.cpp +++ b/CyberXeSS/backends/fsr2_212/FSR2Feature_Vk_212.cpp @@ -100,11 +100,6 @@ bool FSR2FeatureVk212::InitFSR2(const NVSDK_NGX_Parameter* InParameters) spdlog::info("FSR2FeatureVk::InitFSR2 contextDesc.initFlags (LowResMV) {0:b}", _contextDesc.flags); } -#if _DEBUG - _contextDesc.flags |= FFX_FSR2_ENABLE_DEBUG_CHECKING; - _contextDesc.fpMessage = FfxLogCallback; -#endif - spdlog::debug("FSR2FeatureVk::InitFSR2 ffxFsr2ContextCreate!"); auto ret = Fsr212::ffxFsr2ContextCreate212(&_context, &_contextDesc); diff --git a/CyberXeSS/cas/include/backends/dx12/ffx_dx12.h b/CyberXeSS/cas/include/backends/dx12/ffx_dx12.h index b2eec6a0..1ad1b8cd 100644 --- a/CyberXeSS/cas/include/backends/dx12/ffx_dx12.h +++ b/CyberXeSS/cas/include/backends/dx12/ffx_dx12.h @@ -45,7 +45,7 @@ namespace FfxCas /// @returns /// The size (in bytes) of the required scratch memory buffer for the DX12 backend. /// @ingroup DX12Backend - FFX_API size_t ffxGetScratchMemorySizeDX12Cas(size_t maxContexts); + size_t ffxGetScratchMemorySizeDX12Cas(size_t maxContexts); /// Create a FfxDevice from a ID3D12Device. /// @@ -55,7 +55,7 @@ namespace FfxCas /// An abstract FidelityFX device. /// /// @ingroup DX12Backend - FFX_API FfxDevice ffxGetDeviceDX12Cas(ID3D12Device* device); + FfxDevice ffxGetDeviceDX12Cas(ID3D12Device* device); /// Populate an interface with pointers for the DX12 backend. /// @@ -72,8 +72,7 @@ namespace FfxCas /// FFX_ERROR_CODE_INVALID_POINTER The interface pointer was NULL. /// /// @ingroup DX12Backend - FFX_API FfxErrorCode - ffxGetInterfaceDX12Cas(FfxInterface* backendInterface, FfxDevice device, void* scratchBuffer, size_t scratchBufferSize, size_t maxContexts); + FfxErrorCode ffxGetInterfaceDX12Cas(FfxInterface* backendInterface, FfxDevice device, void* scratchBuffer, size_t scratchBufferSize, size_t maxContexts); /// Create a FfxCommandList from a ID3D12CommandList. /// @@ -83,7 +82,7 @@ namespace FfxCas /// An abstract FidelityFX command list. /// /// @ingroup DX12Backend - FFX_API FfxCommandList ffxGetCommandListDX12Cas(ID3D12CommandList* cmdList); + FfxCommandList ffxGetCommandListDX12Cas(ID3D12CommandList* cmdList); /// Fetch a FfxResource from a GPUResource. /// @@ -96,7 +95,7 @@ namespace FfxCas /// An abstract FidelityFX resources. /// /// @ingroup DX12Backend - FFX_API FfxResource ffxGetResourceDX12Cas(ID3D12Resource* dx12Resource, + FfxResource ffxGetResourceDX12Cas(ID3D12Resource* dx12Resource, FfxResourceDescription ffxResDescription, wchar_t* ffxResName, FfxResourceStates state = FFX_RESOURCE_STATE_COMPUTE_READ); diff --git a/CyberXeSS/cas/include/ffx_cas.h b/CyberXeSS/cas/include/ffx_cas.h index d88a7855..35020ffb 100644 --- a/CyberXeSS/cas/include/ffx_cas.h +++ b/CyberXeSS/cas/include/ffx_cas.h @@ -172,7 +172,7 @@ namespace FfxCas /// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend. /// /// @ingroup ffxCas - FFX_API FfxErrorCode ffxCasContextCreate(FfxCasContext* pContext, const FfxCasContextDescription* pContextDescription); + FfxErrorCode ffxCasContextCreate(FfxCasContext* pContext, const FfxCasContextDescription* pContextDescription); /// @param [out] pContext A pointer to a FfxCasContext structure to populate. /// @param [in] pDispatchDescription A pointer to a FfxCasDispatchDescription structure. @@ -185,7 +185,7 @@ namespace FfxCas /// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend. /// /// @ingroup ffxCas - FFX_API FfxErrorCode ffxCasContextDispatch(FfxCasContext* pContext, const FfxCasDispatchDescription* pDispatchDescription); + FfxErrorCode ffxCasContextDispatch(FfxCasContext* pContext, const FfxCasDispatchDescription* pDispatchDescription); /// Destroy the FidelityFX CAS context. /// @@ -197,7 +197,7 @@ namespace FfxCas /// FFX_ERROR_CODE_NULL_POINTER The operation failed because either context was NULL. /// /// @ingroup ffxCas - FFX_API FfxErrorCode ffxCasContextDestroy(FfxCasContext* pContext); + FfxErrorCode ffxCasContextDestroy(FfxCasContext* pContext); #if defined(__cplusplus) } diff --git a/CyberXeSS/fsr2_212/include/dx12/shaders/ffx_fsr2_shaders_dx12.h b/CyberXeSS/fsr2_212/include/dx12/shaders/ffx_fsr2_shaders_dx12.h index 31e5d054..6de804f6 100644 --- a/CyberXeSS/fsr2_212/include/dx12/shaders/ffx_fsr2_shaders_dx12.h +++ b/CyberXeSS/fsr2_212/include/dx12/shaders/ffx_fsr2_shaders_dx12.h @@ -33,7 +33,7 @@ namespace Fsr212 #endif // #if defined(__cplusplus) // A single shader blob and a description of its resources. - typedef struct Fsr2ShaderBlobDX12 { + typedef struct Fsr2ShaderBlobDX12_212 { const uint8_t* data; // A pointer to the blob const uint32_t size; // Size in bytes. @@ -46,10 +46,10 @@ namespace Fsr212 const uint32_t* boundSRVResources; // Pointer to an array of bound SRV resources. const char** boundCBVResourceNames; const uint32_t* boundCBVResources; // Pointer to an array of bound ConstantBuffers. - } Fsr2ShaderBlobDX12; + } Fsr2ShaderBlobDX12_212; // The different options which contribute to permutations. - typedef enum Fs2ShaderPermutationOptionsDX12 { + typedef enum Fs2ShaderPermutationOptionsDX12_212 { FSR2_SHADER_PERMUTATION_USE_LANCZOS_TYPE = (1 << 0), // FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE. Off means reference, On means LUT FSR2_SHADER_PERMUTATION_HDR_COLOR_INPUT = (1 << 1), // FFX_FSR2_OPTION_HDR_COLOR_INPUT @@ -59,10 +59,10 @@ namespace Fsr212 FSR2_SHADER_PERMUTATION_ENABLE_SHARPENING = (1 << 5), // FFX_FSR2_OPTION_APPLY_SHARPENING FSR2_SHADER_PERMUTATION_FORCE_WAVE64 = (1 << 6), // doesn't map to a define, selects different table FSR2_SHADER_PERMUTATION_ALLOW_FP16 = (1 << 7), // FFX_USE_16BIT - } Fs2ShaderPermutationOptionsDX12; + } Fs2ShaderPermutationOptionsDX12_212; // Get a DX12 shader blob for the specified pass and permutation index. - Fsr2ShaderBlobDX12 fsr2GetPermutationBlobByIndex(FfxFsr2Pass passId, uint32_t permutationOptions); + Fsr2ShaderBlobDX12_212 fsr2GetPermutationBlobByIndex_212(FfxFsr2Pass passId, uint32_t permutationOptions); #if defined(__cplusplus) } diff --git a/CyberXeSS/fsr2_212/include/vk/shaders/ffx_fsr2_shaders_vk.h b/CyberXeSS/fsr2_212/include/vk/shaders/ffx_fsr2_shaders_vk.h index e5cb2a56..23f9de75 100644 --- a/CyberXeSS/fsr2_212/include/vk/shaders/ffx_fsr2_shaders_vk.h +++ b/CyberXeSS/fsr2_212/include/vk/shaders/ffx_fsr2_shaders_vk.h @@ -33,7 +33,7 @@ namespace Fsr212 #endif // #if defined(__cplusplus) // A single shader blob and a description of its resources. - typedef struct Fsr2ShaderBlobVK { + typedef struct Fsr2ShaderBlobVK212 { const uint8_t* data; // A pointer to the blob const uint32_t size; // Size in bytes. @@ -46,10 +46,10 @@ namespace Fsr212 const uint32_t* boundSampledImageBindings; // Pointer to an array of bound SRV resources. const char** boundUniformBufferNames; const uint32_t* boundUniformBufferBindings; // Pointer to an array of bound ConstantBuffers. - } Fsr2ShaderBlobVK; + } Fsr2ShaderBlobVK212; // The different options which contribute to permutations. - typedef enum Fs2ShaderPermutationOptionsVK { + typedef enum Fs2ShaderPermutationOptionsVK212 { FSR2_SHADER_PERMUTATION_REPROJECT_USE_LANCZOS_TYPE = (1 << 0), // FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE FSR2_SHADER_PERMUTATION_HDR_COLOR_INPUT = (1 << 1), // FFX_FSR2_OPTION_HDR_COLOR_INPUT @@ -59,10 +59,10 @@ namespace Fsr212 FSR2_SHADER_PERMUTATION_ENABLE_SHARPENING = (1 << 5), // FFX_FSR2_OPTION_APPLY_SHARPENING FSR2_SHADER_PERMUTATION_FORCE_WAVE64 = (1 << 6), // doesn't map to a define, selects different table FSR2_SHADER_PERMUTATION_ALLOW_FP16 = (1 << 7), // FFX_USE_16BIT - } Fs2ShaderPermutationOptionsVK; + } Fs2ShaderPermutationOptionsVK212; // Get a VK shader blob for the specified pass and permutation index. - Fsr2ShaderBlobVK fsr2GetPermutationBlobByIndex(FfxFsr2Pass passId, uint32_t permutationOptions); + Fsr2ShaderBlobVK212 fsr2GetPermutationBlobByIndex212(FfxFsr2Pass passId, uint32_t permutationOptions); #if defined(__cplusplus) } diff --git a/nvngx.ini b/nvngx.ini index 075dbf9b..c2a37f3c 100644 --- a/nvngx.ini +++ b/nvngx.ini @@ -16,13 +16,14 @@ VulkanUpscaler=auto ; Might be needed for Intel Arc cards or different Dx11 drivers ; ; Valid values are; -; 0 - Safe syncing is off +; 0 - Safe syncing is off (fastest) ; 1 - Flush after Dx11 texture copies -; 2 - Sync after output copy +; 2 - Sync after output copy +; 3 - No fences, all sync done with queries (slowest) ; -; 0 is fastest, 2 is slowest +; 0 is fastest, 3 is slowest ; -; 0 - 2 - Default (auto) is 0 +; 0 - 3 - Default (auto) is 0 UseSafeSyncQueries=auto [XeSS]