mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-05-29 21:13:14 +00:00
improved dx11 stability
This commit is contained in:
@@ -82,7 +82,7 @@
|
||||
<IncludePath>$(SolutionDir)external\simpleini;$(SolutionDir)external\nvngx_dlss_sdk;$(SolutionDir)external\unordered_dense\include;$(SolutionDir)external\xess\inc\xess;$(SolutionDir)external\vulkan\include;$(SolutionDir)external\ffx-sdk\sdk\include;$(SolutionDir)external\fmt\include;$(SolutionDir)external\spdlog\include;C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)external\xess\lib;C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64;$(LibraryPath)</LibraryPath>
|
||||
<TargetName>nvngx</TargetName>
|
||||
<OutDir>D:\Folders\Games\Deep Rock Galactic\FSD\Binaries\Win64\</OutDir>
|
||||
<OutDir>E:\Games\God of War</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>$(SolutionDir)external\simpleini;$(SolutionDir)external\nvngx_dlss_sdk;$(SolutionDir)external\unordered_dense\include;$(SolutionDir)external\xess\inc\xess;$(SolutionDir)external\vulkan\include;$(SolutionDir)external\ffx-sdk\sdk\include;$(SolutionDir)external\fmt\include;$(SolutionDir)external\spdlog\include;C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
|
||||
|
||||
@@ -11,7 +11,6 @@ public:
|
||||
virtual bool Init(ID3D11Device* device, ID3D11DeviceContext* context, const NVSDK_NGX_Parameter* initParams) = 0;
|
||||
virtual bool Evaluate(ID3D11DeviceContext* DeviceContext, const NVSDK_NGX_Parameter* InParameters) = 0;
|
||||
virtual void ReInit(const NVSDK_NGX_Parameter* InParameters) = 0;
|
||||
static void Shutdown();
|
||||
|
||||
IFeature_Dx11(unsigned int handleId, const NVSDK_NGX_Parameter* InParameters) : IFeature(handleId, InParameters)
|
||||
{
|
||||
|
||||
@@ -63,7 +63,6 @@ NVSDK_NGX_Result NVSDK_CONV NVSDK_NGX_D3D11_Shutdown(void)
|
||||
|
||||
Dx11Contexts.clear();
|
||||
D3D11Device = nullptr;
|
||||
IFeature_Dx11::Shutdown();
|
||||
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
@@ -212,9 +211,6 @@ NVSDK_NGX_Result NVSDK_NGX_D3D11_ReleaseFeature(NVSDK_NGX_Handle* InHandle)
|
||||
Dx11Contexts.erase(it);
|
||||
}
|
||||
|
||||
if (Dx11Contexts.empty())
|
||||
IFeature_Dx11::Shutdown();
|
||||
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
@@ -225,6 +221,7 @@ NVSDK_NGX_Result NVSDK_NGX_D3D11_GetFeatureRequirements(IDXGIAdapter* Adapter, c
|
||||
*OutSupported = NVSDK_NGX_FeatureRequirement();
|
||||
OutSupported->FeatureSupported = NVSDK_NGX_FeatureSupportResult_Supported;
|
||||
OutSupported->MinHWArchitecture = 0;
|
||||
|
||||
//Some windows 10 os version
|
||||
strcpy_s(OutSupported->MinOSVersion, "10.0.10240.16384");
|
||||
return NVSDK_NGX_Result_Success;
|
||||
@@ -268,17 +265,6 @@ NVSDK_NGX_Result NVSDK_NGX_D3D11_EvaluateFeature(ID3D11DeviceContext* InDevCtx,
|
||||
}
|
||||
}
|
||||
|
||||
//if (!deviceContext->IsInited())
|
||||
//{
|
||||
// deviceContext->Init(D3D11Device, InDevCtx, InParameters);
|
||||
|
||||
// if (!deviceContext->IsInited())
|
||||
// {
|
||||
// spdlog::error("NVSDK_NGX_D3D11_EvaluateFeature deviceContext.XessInit is false, init failed!");
|
||||
// return NVSDK_NGX_Result_Fail;
|
||||
// }
|
||||
//}
|
||||
|
||||
NVSDK_NGX_Result evResult = NVSDK_NGX_Result_Success;
|
||||
if (!deviceContext->Evaluate(InDevCtx, InParameters))
|
||||
evResult = NVSDK_NGX_Result_Fail;
|
||||
|
||||
@@ -16,12 +16,6 @@ do { \
|
||||
} \
|
||||
} while((void)0, 0);
|
||||
|
||||
// D3D11with12
|
||||
ID3D12Device* Dx12on11Device = nullptr;
|
||||
ID3D12CommandQueue* Dx12CommandQueue = nullptr;
|
||||
ID3D12CommandAllocator* Dx12CommandAllocator = nullptr;
|
||||
ID3D12GraphicsCommandList* Dx12CommandList = nullptr;
|
||||
|
||||
bool XeSSFeatureDx11::CopyTextureFrom11To12(ID3D11Resource* d3d11texture, ID3D11Texture2D** pSharedTexture, D3D11_TEXTURE2D_DESC_C* sharedDesc, bool copy = true)
|
||||
{
|
||||
ID3D11Texture2D* originalTexture = nullptr;
|
||||
@@ -122,6 +116,8 @@ void XeSSFeatureDx11::ReleaseSharedResources()
|
||||
|
||||
void XeSSFeatureDx11::GetHardwareAdapter(IDXGIFactory1* pFactory, IDXGIAdapter** ppAdapter, D3D_FEATURE_LEVEL featureLevel, bool requestHighPerformanceAdapter)
|
||||
{
|
||||
spdlog::debug("XeSSFeatureDx11::GetHardwareAdapter");
|
||||
|
||||
*ppAdapter = nullptr;
|
||||
|
||||
IDXGIAdapter1* adapter;
|
||||
@@ -190,6 +186,8 @@ void XeSSFeatureDx11::GetHardwareAdapter(IDXGIFactory1* pFactory, IDXGIAdapter**
|
||||
|
||||
HRESULT XeSSFeatureDx11::CreateDx12Device(D3D_FEATURE_LEVEL featureLevel)
|
||||
{
|
||||
spdlog::debug("XeSSFeatureDx11::CreateDx12Device");
|
||||
|
||||
if (Dx12on11Device)
|
||||
return S_OK;
|
||||
|
||||
@@ -266,6 +264,8 @@ bool XeSSFeatureDx11::IsInited()
|
||||
|
||||
bool XeSSFeatureDx11::Init(ID3D11Device* device, ID3D11DeviceContext* context, const NVSDK_NGX_Parameter* initParams)
|
||||
{
|
||||
spdlog::debug("XeSSFeatureDx11::Init!");
|
||||
|
||||
if (IsInited())
|
||||
return true;
|
||||
|
||||
@@ -296,6 +296,18 @@ bool XeSSFeatureDx11::Init(ID3D11Device* device, ID3D11DeviceContext* context, c
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Dx12on11Device)
|
||||
{
|
||||
auto fl = Dx11Device->GetFeatureLevel();
|
||||
auto result = CreateDx12Device(fl);
|
||||
|
||||
if (result != S_OK || !Dx12on11Device)
|
||||
{
|
||||
spdlog::error("XeSSFeatureDx11::Init QueryInterface Dx12Device result: {0:x}", result);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
spdlog::debug("XeSSFeatureDx11::Init calling InitXeSS");
|
||||
|
||||
if (Dx12on11Device && !InitXeSS(Dx12on11Device, initParams))
|
||||
@@ -309,6 +321,11 @@ bool XeSSFeatureDx11::Init(ID3D11Device* device, ID3D11DeviceContext* context, c
|
||||
|
||||
bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
spdlog::debug("XeSSFeatureDx11::Evaluate");
|
||||
|
||||
if (!IsInited() || !_xessContext)
|
||||
return false;
|
||||
|
||||
ID3D11DeviceContext4* dc;
|
||||
auto result = InDeviceContext->QueryInterface(IID_PPV_ARGS(&dc));
|
||||
|
||||
@@ -325,29 +342,6 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
|
||||
Dx11DeviceContext = dc;
|
||||
}
|
||||
|
||||
if (!IsInited() || !_xessContext)
|
||||
{
|
||||
if (!Dx12on11Device)
|
||||
{
|
||||
auto fl = Dx11Device->GetFeatureLevel();
|
||||
result = CreateDx12Device(fl);
|
||||
|
||||
if (result != S_OK || !Dx12on11Device)
|
||||
{
|
||||
spdlog::error("XeSSFeatureDx11::Init QueryInterface Dx12Device result: {0:x}", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsInited() && Dx12on11Device && !InitXeSS(Dx12on11Device, InParameters))
|
||||
{
|
||||
spdlog::error("XeSSFeatureDx11::Init InitXeSS fail!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Fence for syncing
|
||||
ID3D12Fence* d3d12Fence;
|
||||
@@ -671,6 +665,8 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
|
||||
|
||||
void XeSSFeatureDx11::ReInit(const NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
spdlog::debug("XeSSFeatureDx11::ReInit!");
|
||||
|
||||
SetInit(false);
|
||||
|
||||
if (_xessContext)
|
||||
@@ -683,7 +679,7 @@ XeSSFeatureDx11::~XeSSFeatureDx11()
|
||||
{
|
||||
spdlog::debug("XeSSFeatureDx11::Destroy!");
|
||||
|
||||
if (Dx11Device && Dx12on11Device && Dx12CommandQueue && Dx12CommandList)
|
||||
if (Dx12on11Device && Dx12CommandQueue && Dx12CommandList)
|
||||
{
|
||||
ID3D12Fence* d3d12Fence;
|
||||
Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence));
|
||||
@@ -698,17 +694,13 @@ XeSSFeatureDx11::~XeSSFeatureDx11()
|
||||
WaitForSingleObject(fenceEvent, INFINITE);
|
||||
CloseHandle(fenceEvent);
|
||||
d3d12Fence->Release();
|
||||
|
||||
SAFE_RELEASE(Dx12CommandList);
|
||||
SAFE_RELEASE(Dx12CommandQueue);
|
||||
SAFE_RELEASE(Dx12CommandAllocator);
|
||||
SAFE_RELEASE(Dx12on11Device);
|
||||
}
|
||||
|
||||
ReleaseSharedResources();
|
||||
}
|
||||
|
||||
void IFeature_Dx11::Shutdown()
|
||||
{
|
||||
SAFE_RELEASE(Dx12CommandList);
|
||||
SAFE_RELEASE(Dx12CommandQueue);
|
||||
SAFE_RELEASE(Dx12CommandAllocator);
|
||||
SAFE_RELEASE(Dx12on11Device);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,9 +24,16 @@ using D3D11_TEXTURE2D_RESOURCE_C = struct D3D11_TEXTURE2D_RESOURCE_C
|
||||
class XeSSFeatureDx11 : public XeSSFeature, public IFeature_Dx11
|
||||
{
|
||||
private:
|
||||
// D3D11
|
||||
ID3D11Device5* Dx11Device = nullptr;
|
||||
ID3D11DeviceContext4* Dx11DeviceContext = nullptr;
|
||||
|
||||
// D3D11with12
|
||||
ID3D12Device* Dx12on11Device = nullptr;
|
||||
ID3D12CommandQueue* Dx12CommandQueue = nullptr;
|
||||
ID3D12CommandAllocator* Dx12CommandAllocator = nullptr;
|
||||
ID3D12GraphicsCommandList* Dx12CommandList = nullptr;
|
||||
|
||||
D3D11_TEXTURE2D_RESOURCE_C dx11Color = {};
|
||||
D3D11_TEXTURE2D_RESOURCE_C dx11Mv = {};
|
||||
D3D11_TEXTURE2D_RESOURCE_C dx11Depth = {};
|
||||
@@ -36,8 +43,8 @@ private:
|
||||
|
||||
bool CopyTextureFrom11To12(ID3D11Resource* d3d11texture, ID3D11Texture2D** pSharedTexture, D3D11_TEXTURE2D_DESC_C* sharedDesc, bool copy);
|
||||
void ReleaseSharedResources();
|
||||
static void GetHardwareAdapter(IDXGIFactory1* pFactory, IDXGIAdapter** ppAdapter, D3D_FEATURE_LEVEL featureLevel, bool requestHighPerformanceAdapter);
|
||||
static HRESULT CreateDx12Device(D3D_FEATURE_LEVEL featureLevel);
|
||||
void GetHardwareAdapter(IDXGIFactory1* pFactory, IDXGIAdapter** ppAdapter, D3D_FEATURE_LEVEL featureLevel, bool requestHighPerformanceAdapter);
|
||||
HRESULT CreateDx12Device(D3D_FEATURE_LEVEL featureLevel);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user