mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-08-25 15:46:45 +00:00
added only dx11 queries option for w/Dx12 backends
This commit is contained in:
@@ -82,7 +82,7 @@
|
||||
<IncludePath>$(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)</IncludePath>
|
||||
<LibraryPath>$(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)</LibraryPath>
|
||||
<TargetName>nvngx</TargetName>
|
||||
<OutDir>E:\Games\No Man%27s Sky\Binaries</OutDir>
|
||||
<OutDir>E:\Games\God of War</OutDir>
|
||||
<IntDir>.\x64\Debug</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
||||
@@ -198,11 +198,11 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_CreateFeature(ID3D11DeviceContext
|
||||
// Create feature
|
||||
auto handleId = IFeature::GetNextHandleId();
|
||||
|
||||
if (Config::Instance()->Dx11Upscaler.value_or("fsr") == "fsr")
|
||||
if (Config::Instance()->Dx11Upscaler.value_or("fsr22") == "fsr22")
|
||||
Dx11Contexts[handleId] = std::make_unique<FSR2FeatureDx11>(handleId, InParameters);
|
||||
else if (Config::Instance()->Dx11Upscaler.value_or("fsr") == "fsr22_12")
|
||||
else if (Config::Instance()->Dx11Upscaler.value_or("fsr22") == "fsr22_12")
|
||||
Dx11Contexts[handleId] = std::make_unique<FSR2FeatureDx11on12>(handleId, InParameters);
|
||||
else if (Config::Instance()->Dx11Upscaler.value_or("fsr") == "fsr21_12")
|
||||
else if (Config::Instance()->Dx11Upscaler.value_or("fsr22") == "fsr21_12")
|
||||
Dx11Contexts[handleId] = std::make_unique<FSR2FeatureDx11on12_212>(handleId, InParameters);
|
||||
else
|
||||
Dx11Contexts[handleId] = std::make_unique<XeSSFeatureDx11>(handleId, InParameters);
|
||||
|
||||
@@ -357,7 +357,6 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N
|
||||
|
||||
// fence operation results
|
||||
HRESULT fr;
|
||||
|
||||
ID3D11Fence* dx11fence_1 = nullptr;
|
||||
ID3D12Fence* dx12fence_1 = nullptr;
|
||||
HANDLE dx11_sharedHandle;
|
||||
@@ -367,6 +366,7 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N
|
||||
pQueryDesc.MiscFlags = 0;
|
||||
ID3D11Query* query0 = nullptr;
|
||||
|
||||
// 3 is query sync
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
fr = Dx11Device->CreateFence(0, D3D11_FENCE_FLAG_SHARED, IID_PPV_ARGS(&dx11fence_1));
|
||||
@@ -395,6 +395,14 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N
|
||||
}
|
||||
else
|
||||
{
|
||||
auto result = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&dx12fence_1));
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
spdlog::debug("FeatureContext::FSR2FeatureDx11on12 CreateFence d3d12fence error: {0:x}", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = Device->CreateQuery(&pQueryDesc, &query0);
|
||||
|
||||
if (result != S_OK || query0 == nullptr)
|
||||
@@ -506,11 +514,30 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N
|
||||
spdlog::warn("FSR2FeatureDx11on12::Evaluate bias mask not exist and its enabled in config, it may cause problems!!");
|
||||
}
|
||||
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 0)
|
||||
Dx11DeviceContext->Flush();
|
||||
#pragma endregion
|
||||
|
||||
Dx11DeviceContext->Signal(dx11fence_1, 10);
|
||||
Dx12CommandQueue->Wait(dx12fence_1, 10);
|
||||
// 3 is query sync
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 0)
|
||||
Dx11DeviceContext->Flush();
|
||||
|
||||
Dx11DeviceContext->Signal(dx11fence_1, 10);
|
||||
Dx12CommandQueue->Wait(dx12fence_1, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceContext->End(query0);
|
||||
DeviceContext->Flush();
|
||||
|
||||
// Wait for the query to be ready
|
||||
while (Dx11DeviceContext->GetData(query0, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
|
||||
// Release the query
|
||||
query0->Release();
|
||||
}
|
||||
|
||||
#pragma region shared handles
|
||||
|
||||
if (paramColor)
|
||||
{
|
||||
@@ -644,7 +671,7 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N
|
||||
float shapness = 0.0f;
|
||||
if (InParameters->Get(NVSDK_NGX_Parameter_Sharpness, &shapness) == NVSDK_NGX_Result_Success)
|
||||
{
|
||||
params.enableSharpening = !(shapness == 0.0f || shapness == -1.0f);
|
||||
params.enableSharpening = !(shapness == 0.0f || shapness == -1.0f) && shapness >= -1.0f && shapness <= 1.0f;
|
||||
|
||||
if (params.enableSharpening)
|
||||
{
|
||||
@@ -686,31 +713,36 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N
|
||||
return false;
|
||||
}
|
||||
|
||||
ID3D12Fence* dx12fence_2;
|
||||
fr = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_SHARED, IID_PPV_ARGS(&dx12fence_2));
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
ID3D12Fence* dx12fence_2 = nullptr;
|
||||
ID3D11Fence* dx11fence_2 = nullptr;
|
||||
HANDLE dx12_sharedHandle;
|
||||
fr = Dx12on11Device->CreateSharedHandle(dx12fence_2, nullptr, GENERIC_ALL, nullptr, &dx12_sharedHandle);
|
||||
|
||||
if (fr != S_OK)
|
||||
// dispatch fences
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create sharedhandle for dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
fr = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_SHARED, IID_PPV_ARGS(&dx12fence_2));
|
||||
|
||||
ID3D11Fence* dx11fence_2;
|
||||
fr = Dx11Device->OpenSharedFence(dx12_sharedHandle, IID_PPV_ARGS(&dx11fence_2));
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create open sharedhandle for dx11fence_2 {0:x}", fr);
|
||||
return false;
|
||||
fr = Dx12on11Device->CreateSharedHandle(dx12fence_2, nullptr, GENERIC_ALL, nullptr, &dx12_sharedHandle);
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create sharedhandle for dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
fr = Dx11Device->OpenSharedFence(dx12_sharedHandle, IID_PPV_ARGS(&dx11fence_2));
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create open sharedhandle for dx11fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute dx12 commands to process fsr
|
||||
@@ -719,51 +751,99 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N
|
||||
Dx12CommandQueue->ExecuteCommandLists(1, ppCommandLists);
|
||||
|
||||
// fsr done
|
||||
Dx12CommandQueue->Signal(dx12fence_2, 20);
|
||||
|
||||
// wait for fsr on dx12
|
||||
Dx11DeviceContext->Wait(dx11fence_2, 20);
|
||||
|
||||
// copy back output
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 1)
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
// intel arc fix
|
||||
D3D11_QUERY_DESC pQueryDesc{};
|
||||
pQueryDesc.Query = D3D11_QUERY_EVENT;
|
||||
pQueryDesc.MiscFlags = 0;
|
||||
ID3D11Query* query1 = nullptr;
|
||||
result = Dx11Device->CreateQuery(&pQueryDesc, &query1);
|
||||
Dx12CommandQueue->Signal(dx12fence_2, 20);
|
||||
|
||||
if (result != S_OK || !query1)
|
||||
// wait for fsr on dx12
|
||||
Dx11DeviceContext->Wait(dx11fence_2, 20);
|
||||
|
||||
// copy back output
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 1)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate can't create query1!");
|
||||
ID3D11Query* query1 = nullptr;
|
||||
result = Dx11Device->CreateQuery(&pQueryDesc, &query1);
|
||||
|
||||
if (result != S_OK || !query1)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate can't create query1!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Dx11DeviceContext->Begin(query1);
|
||||
|
||||
// copy back output
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
Dx11DeviceContext->End(query1);
|
||||
|
||||
// Execute dx11 commands
|
||||
Dx11DeviceContext->Flush();
|
||||
|
||||
// wait for completion
|
||||
while (Dx11DeviceContext->GetData(query1, nullptr, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
|
||||
// Release the query
|
||||
query1->Release();
|
||||
}
|
||||
else
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dx12CommandQueue->Signal(dx12fence_1, 20);
|
||||
|
||||
// wait for end of operation
|
||||
if (dx12fence_1->GetCompletedValue() < 20)
|
||||
{
|
||||
auto fenceEvent12 = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
|
||||
if (fenceEvent12)
|
||||
{
|
||||
dx12fence_1->SetEventOnCompletion(20, fenceEvent12);
|
||||
WaitForSingleObject(fenceEvent12, INFINITE);
|
||||
CloseHandle(fenceEvent12);
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11Query* query2 = nullptr;
|
||||
result = Dx11Device->CreateQuery(&pQueryDesc, &query2);
|
||||
|
||||
if (result != S_OK || query2 == nullptr)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate can't create query2!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Dx11DeviceContext->Begin(query1);
|
||||
|
||||
// copy back output
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
Dx11DeviceContext->End(query1);
|
||||
// Associate the query with the copy operation
|
||||
DeviceContext->Begin(query2);
|
||||
|
||||
//copy output back
|
||||
DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
// Execute dx11 commands
|
||||
//Dx11DeviceContext->Flush();
|
||||
DeviceContext->End(query2);
|
||||
Dx11DeviceContext->Flush();
|
||||
|
||||
// wait for completion
|
||||
while (Dx11DeviceContext->GetData(query1, nullptr, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
// Wait for the query to be ready
|
||||
while (Dx11DeviceContext->GetData(query2, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
|
||||
// Release the query
|
||||
query1->Release();
|
||||
query2->Release();
|
||||
}
|
||||
else
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
// release fences
|
||||
dx11fence_1->Release();
|
||||
dx11fence_2->Release();
|
||||
dx12fence_1->Release();
|
||||
dx12fence_2->Release();
|
||||
if (dx11fence_1)
|
||||
dx11fence_1->Release();
|
||||
|
||||
if (dx11fence_2)
|
||||
dx11fence_2->Release();
|
||||
|
||||
if (dx12fence_1)
|
||||
dx12fence_1->Release();
|
||||
|
||||
if (dx12fence_2)
|
||||
dx12fence_2->Release();
|
||||
|
||||
Dx12CommandAllocator->Reset();
|
||||
Dx12CommandList->Reset(Dx12CommandAllocator, nullptr);
|
||||
@@ -862,7 +942,7 @@ bool FSR2FeatureDx11on12::InitFSR2(const NVSDK_NGX_Parameter* InParameters)
|
||||
Config::Instance()->AutoExposure = true;
|
||||
_contextDesc.flags |= FFX_FSR2_ENABLE_AUTO_EXPOSURE;
|
||||
spdlog::info("FSR2Feature::InitFSR2 contextDesc.initFlags (AutoExposure) {0:b}", _contextDesc.flags);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Config::Instance()->AutoExposure = false;
|
||||
|
||||
@@ -357,33 +357,64 @@ bool FSR2FeatureDx11on12_212::Evaluate(ID3D11DeviceContext* InDeviceContext, con
|
||||
|
||||
// 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;
|
||||
|
||||
// 3 is query sync
|
||||
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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto result = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&dx12fence_1));
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
spdlog::debug("FeatureContext::FSR2FeatureDx11on12 CreateFence d3d12fence error: {0:x}", result);
|
||||
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);
|
||||
}
|
||||
|
||||
ID3D12Fence* dx12fence_1;
|
||||
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;
|
||||
}
|
||||
|
||||
#pragma region Texture copies
|
||||
|
||||
@@ -483,12 +514,30 @@ bool FSR2FeatureDx11on12_212::Evaluate(ID3D11DeviceContext* InDeviceContext, con
|
||||
else
|
||||
spdlog::warn("FSR2FeatureDx11on12::Evaluate bias mask not exist and its enabled in config, it may cause problems!!");
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 0)
|
||||
Dx11DeviceContext->Flush();
|
||||
// 3 is query sync
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 0)
|
||||
Dx11DeviceContext->Flush();
|
||||
|
||||
Dx11DeviceContext->Signal(dx11fence_1, 10);
|
||||
Dx12CommandQueue->Wait(dx12fence_1, 10);
|
||||
Dx11DeviceContext->Signal(dx11fence_1, 10);
|
||||
Dx12CommandQueue->Wait(dx12fence_1, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceContext->End(query0);
|
||||
DeviceContext->Flush();
|
||||
|
||||
// Wait for the query to be ready
|
||||
while (Dx11DeviceContext->GetData(query0, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
|
||||
// Release the query
|
||||
query0->Release();
|
||||
}
|
||||
|
||||
#pragma region shared handles
|
||||
|
||||
if (paramColor)
|
||||
{
|
||||
@@ -664,31 +713,36 @@ bool FSR2FeatureDx11on12_212::Evaluate(ID3D11DeviceContext* InDeviceContext, con
|
||||
return false;
|
||||
}
|
||||
|
||||
ID3D12Fence* dx12fence_2;
|
||||
fr = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_SHARED, IID_PPV_ARGS(&dx12fence_2));
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
ID3D12Fence* dx12fence_2 = nullptr;
|
||||
ID3D11Fence* dx11fence_2 = nullptr;
|
||||
HANDLE dx12_sharedHandle;
|
||||
fr = Dx12on11Device->CreateSharedHandle(dx12fence_2, nullptr, GENERIC_ALL, nullptr, &dx12_sharedHandle);
|
||||
|
||||
if (fr != S_OK)
|
||||
// dispatch fences
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create sharedhandle for dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
fr = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_SHARED, IID_PPV_ARGS(&dx12fence_2));
|
||||
|
||||
ID3D11Fence* dx11fence_2;
|
||||
fr = Dx11Device->OpenSharedFence(dx12_sharedHandle, IID_PPV_ARGS(&dx11fence_2));
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create open sharedhandle for dx11fence_2 {0:x}", fr);
|
||||
return false;
|
||||
fr = Dx12on11Device->CreateSharedHandle(dx12fence_2, nullptr, GENERIC_ALL, nullptr, &dx12_sharedHandle);
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create sharedhandle for dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
fr = Dx11Device->OpenSharedFence(dx12_sharedHandle, IID_PPV_ARGS(&dx11fence_2));
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create open sharedhandle for dx11fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute dx12 commands to process fsr
|
||||
@@ -697,51 +751,99 @@ bool FSR2FeatureDx11on12_212::Evaluate(ID3D11DeviceContext* InDeviceContext, con
|
||||
Dx12CommandQueue->ExecuteCommandLists(1, ppCommandLists);
|
||||
|
||||
// fsr done
|
||||
Dx12CommandQueue->Signal(dx12fence_2, 20);
|
||||
|
||||
// wait for fsr on dx12
|
||||
Dx11DeviceContext->Wait(dx11fence_2, 20);
|
||||
|
||||
// copy back output
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 1)
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
// intel arc fix
|
||||
D3D11_QUERY_DESC pQueryDesc{};
|
||||
pQueryDesc.Query = D3D11_QUERY_EVENT;
|
||||
pQueryDesc.MiscFlags = 0;
|
||||
ID3D11Query* query1 = nullptr;
|
||||
result = Dx11Device->CreateQuery(&pQueryDesc, &query1);
|
||||
Dx12CommandQueue->Signal(dx12fence_2, 20);
|
||||
|
||||
if (result != S_OK || !query1)
|
||||
// wait for fsr on dx12
|
||||
Dx11DeviceContext->Wait(dx11fence_2, 20);
|
||||
|
||||
// copy back output
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 1)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate can't create query1!");
|
||||
ID3D11Query* query1 = nullptr;
|
||||
result = Dx11Device->CreateQuery(&pQueryDesc, &query1);
|
||||
|
||||
if (result != S_OK || !query1)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate can't create query1!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Dx11DeviceContext->Begin(query1);
|
||||
|
||||
// copy back output
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
Dx11DeviceContext->End(query1);
|
||||
|
||||
// Execute dx11 commands
|
||||
Dx11DeviceContext->Flush();
|
||||
|
||||
// wait for completion
|
||||
while (Dx11DeviceContext->GetData(query1, nullptr, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
|
||||
// Release the query
|
||||
query1->Release();
|
||||
}
|
||||
else
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dx12CommandQueue->Signal(dx12fence_1, 20);
|
||||
|
||||
// wait for end of operation
|
||||
if (dx12fence_1->GetCompletedValue() < 20)
|
||||
{
|
||||
auto fenceEvent12 = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
|
||||
if (fenceEvent12)
|
||||
{
|
||||
dx12fence_1->SetEventOnCompletion(20, fenceEvent12);
|
||||
WaitForSingleObject(fenceEvent12, INFINITE);
|
||||
CloseHandle(fenceEvent12);
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11Query* query2 = nullptr;
|
||||
result = Dx11Device->CreateQuery(&pQueryDesc, &query2);
|
||||
|
||||
if (result != S_OK || query2 == nullptr)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate can't create query2!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Dx11DeviceContext->Begin(query1);
|
||||
// Associate the query with the copy operation
|
||||
DeviceContext->Begin(query2);
|
||||
|
||||
// copy back output
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
Dx11DeviceContext->End(query1);
|
||||
//copy output back
|
||||
DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
// Execute dx11 commands
|
||||
//Dx11DeviceContext->Flush();
|
||||
DeviceContext->End(query2);
|
||||
Dx11DeviceContext->Flush();
|
||||
|
||||
// wait for completion
|
||||
while (Dx11DeviceContext->GetData(query1, nullptr, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
// Wait for the query to be ready
|
||||
while (Dx11DeviceContext->GetData(query2, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
|
||||
// Release the query
|
||||
query1->Release();
|
||||
query2->Release();
|
||||
}
|
||||
else
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
// release fences
|
||||
dx11fence_1->Release();
|
||||
dx11fence_2->Release();
|
||||
dx12fence_1->Release();
|
||||
dx12fence_2->Release();
|
||||
if (dx11fence_1)
|
||||
dx11fence_1->Release();
|
||||
|
||||
if (dx11fence_2)
|
||||
dx11fence_2->Release();
|
||||
|
||||
if (dx12fence_1)
|
||||
dx12fence_1->Release();
|
||||
|
||||
if (dx12fence_2)
|
||||
dx12fence_2->Release();
|
||||
|
||||
Dx12CommandAllocator->Reset();
|
||||
Dx12CommandList->Reset(Dx12CommandAllocator, nullptr);
|
||||
|
||||
@@ -340,17 +340,6 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
|
||||
Dx11DeviceContext = dc;
|
||||
}
|
||||
|
||||
|
||||
// Fence for syncing
|
||||
ID3D12Fence* d3d12Fence;
|
||||
result = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence));
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
spdlog::error("XeSSFeatureDx11::Evaluate CreateFence d3d12fence error: {0:x}", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
// creatimg params for XeSS
|
||||
xess_result_t xessResult;
|
||||
xess_d3d12_execute_params_t params{};
|
||||
@@ -367,34 +356,66 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
|
||||
|
||||
spdlog::debug("XeSSFeatureDx11::Evaluate Input Resolution: {0}x{1}", params.inputWidth, params.inputHeight);
|
||||
|
||||
// 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("XeSSFeatureDx11::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;
|
||||
|
||||
// 3 is query sync
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
spdlog::error("XeSSFeatureDx11::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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto result = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&dx12fence_1));
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
spdlog::debug("FeatureContext::FSR2FeatureDx11on12 CreateFence d3d12fence error: {0:x}", result);
|
||||
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);
|
||||
}
|
||||
|
||||
ID3D12Fence* dx12fence_1;
|
||||
fr = Dx12on11Device->OpenSharedHandle(dx11_sharedHandle, IID_PPV_ARGS(&dx12fence_1));
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("XeSSFeatureDx11::Evaluate Can't create open sharedhandle for dx12fence_1 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
#pragma region Texture copies
|
||||
|
||||
@@ -494,11 +515,30 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
|
||||
spdlog::warn("XeSSFeatureDx11::Evaluate bias mask not exist and its enabled in config, it may cause problems!!");
|
||||
}
|
||||
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 0)
|
||||
Dx11DeviceContext->Flush();
|
||||
#pragma endregion
|
||||
|
||||
Dx11DeviceContext->Signal(dx11fence_1, 10);
|
||||
Dx12CommandQueue->Wait(dx12fence_1, 10);
|
||||
// 3 is query sync
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 0)
|
||||
Dx11DeviceContext->Flush();
|
||||
|
||||
Dx11DeviceContext->Signal(dx11fence_1, 10);
|
||||
Dx12CommandQueue->Wait(dx12fence_1, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceContext->End(query0);
|
||||
DeviceContext->Flush();
|
||||
|
||||
// Wait for the query to be ready
|
||||
while (Dx11DeviceContext->GetData(query0, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
|
||||
// Release the query
|
||||
query0->Release();
|
||||
}
|
||||
|
||||
#pragma region shared handles
|
||||
|
||||
if (paramColor)
|
||||
{
|
||||
@@ -652,31 +692,36 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
|
||||
if (casActive && casSharpness > 0.0f && !CasDispatch(Dx12CommandList, InParameters, casBuffer, dx11Out.Dx12Resource))
|
||||
return false;
|
||||
|
||||
ID3D12Fence* dx12fence_2;
|
||||
fr = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_SHARED, IID_PPV_ARGS(&dx12fence_2));
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("XeSSFeatureDx11::Evaluate Can't create dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
ID3D12Fence* dx12fence_2 = nullptr;
|
||||
ID3D11Fence* dx11fence_2 = nullptr;
|
||||
HANDLE dx12_sharedHandle;
|
||||
fr = Dx12on11Device->CreateSharedHandle(dx12fence_2, nullptr, GENERIC_ALL, nullptr, &dx12_sharedHandle);
|
||||
|
||||
if (fr != S_OK)
|
||||
// dispatch fences
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
spdlog::error("XeSSFeatureDx11::Evaluate Can't create sharedhandle for dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
fr = Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_SHARED, IID_PPV_ARGS(&dx12fence_2));
|
||||
|
||||
ID3D11Fence* dx11fence_2;
|
||||
fr = Dx11Device->OpenSharedFence(dx12_sharedHandle, IID_PPV_ARGS(&dx11fence_2));
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("XeSSFeatureDx11::Evaluate Can't create open sharedhandle for dx11fence_2 {0:x}", fr);
|
||||
return false;
|
||||
fr = Dx12on11Device->CreateSharedHandle(dx12fence_2, nullptr, GENERIC_ALL, nullptr, &dx12_sharedHandle);
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create sharedhandle for dx12fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
|
||||
fr = Dx11Device->OpenSharedFence(dx12_sharedHandle, IID_PPV_ARGS(&dx11fence_2));
|
||||
|
||||
if (fr != S_OK)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate Can't create open sharedhandle for dx11fence_2 {0:x}", fr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute dx12 commands to process xess
|
||||
@@ -685,51 +730,99 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
|
||||
Dx12CommandQueue->ExecuteCommandLists(1, ppCommandLists);
|
||||
|
||||
// xess done
|
||||
Dx12CommandQueue->Signal(dx12fence_2, 20);
|
||||
|
||||
// wait for xess on dx12
|
||||
Dx11DeviceContext->Wait(dx11fence_2, 20);
|
||||
|
||||
|
||||
// copy back output
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 1)
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) < 3)
|
||||
{
|
||||
D3D11_QUERY_DESC pQueryDesc{};
|
||||
pQueryDesc.Query = D3D11_QUERY_EVENT;
|
||||
pQueryDesc.MiscFlags = 0;
|
||||
ID3D11Query* query1 = nullptr;
|
||||
result = Dx11Device->CreateQuery(&pQueryDesc, &query1);
|
||||
Dx12CommandQueue->Signal(dx12fence_2, 20);
|
||||
|
||||
if (result != S_OK || !query1)
|
||||
// wait for fsr on dx12
|
||||
Dx11DeviceContext->Wait(dx11fence_2, 20);
|
||||
|
||||
// copy back output
|
||||
if (Config::Instance()->UseSafeSyncQueries.value_or(0) > 1)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate can't create query1!");
|
||||
ID3D11Query* query1 = nullptr;
|
||||
result = Dx11Device->CreateQuery(&pQueryDesc, &query1);
|
||||
|
||||
if (result != S_OK || !query1)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate can't create query1!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Dx11DeviceContext->Begin(query1);
|
||||
|
||||
// copy back output
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
Dx11DeviceContext->End(query1);
|
||||
|
||||
// Execute dx11 commands
|
||||
Dx11DeviceContext->Flush();
|
||||
|
||||
// wait for completion
|
||||
while (Dx11DeviceContext->GetData(query1, nullptr, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
|
||||
// Release the query
|
||||
query1->Release();
|
||||
}
|
||||
else
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dx12CommandQueue->Signal(dx12fence_1, 20);
|
||||
|
||||
// wait for end of operation
|
||||
if (dx12fence_1->GetCompletedValue() < 20)
|
||||
{
|
||||
auto fenceEvent12 = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
|
||||
if (fenceEvent12)
|
||||
{
|
||||
dx12fence_1->SetEventOnCompletion(20, fenceEvent12);
|
||||
WaitForSingleObject(fenceEvent12, INFINITE);
|
||||
CloseHandle(fenceEvent12);
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11Query* query2 = nullptr;
|
||||
result = Dx11Device->CreateQuery(&pQueryDesc, &query2);
|
||||
|
||||
if (result != S_OK || query2 == nullptr)
|
||||
{
|
||||
spdlog::error("FSR2FeatureDx11on12::Evaluate can't create query2!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Dx11DeviceContext->Begin(query1);
|
||||
// Associate the query with the copy operation
|
||||
DeviceContext->Begin(query2);
|
||||
|
||||
// copy back output
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
Dx11DeviceContext->End(query1);
|
||||
//copy output back
|
||||
DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
// Execute dx11 commands
|
||||
DeviceContext->End(query2);
|
||||
Dx11DeviceContext->Flush();
|
||||
|
||||
// wait for completion
|
||||
while (Dx11DeviceContext->GetData(query1, nullptr, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
// Wait for the query to be ready
|
||||
while (Dx11DeviceContext->GetData(query2, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_FALSE);
|
||||
|
||||
// Release the query
|
||||
query1->Release();
|
||||
query2->Release();
|
||||
}
|
||||
else
|
||||
Dx11DeviceContext->CopyResource(paramOutput, dx11Out.SharedTexture);
|
||||
|
||||
// release fences
|
||||
dx11fence_1->Release();
|
||||
dx11fence_2->Release();
|
||||
dx12fence_1->Release();
|
||||
dx12fence_2->Release();
|
||||
if (dx11fence_1)
|
||||
dx11fence_1->Release();
|
||||
|
||||
if (dx11fence_2)
|
||||
dx11fence_2->Release();
|
||||
|
||||
if (dx12fence_1)
|
||||
dx12fence_1->Release();
|
||||
|
||||
if (dx12fence_2)
|
||||
dx12fence_2->Release();
|
||||
|
||||
Dx12CommandAllocator->Reset();
|
||||
Dx12CommandList->Reset(Dx12CommandAllocator, nullptr);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[Upscalers]
|
||||
; Select upscaler for Dx11 games
|
||||
; xess, fsr (native dx11), fsr21_12 (dx11 with dx12) or fsr22_12 (dx11 with dx12) - Default (auto) is fsr
|
||||
; xess, fsr22 (native dx11), fsr21_12 (dx11 with dx12) or fsr22_12 (dx11 with dx12) - Default (auto) is fsr
|
||||
Dx11Upscaler=auto
|
||||
|
||||
; Select upscaler for Dx12 games
|
||||
|
||||
Reference in New Issue
Block a user