Skip to content

Commit

Permalink
better organised aproach for cas & cs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdozdil committed Mar 26, 2024
1 parent e1e1fc5 commit b44b45f
Show file tree
Hide file tree
Showing 25 changed files with 2,022 additions and 913 deletions.
2 changes: 1 addition & 1 deletion CyberXeSS/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void Config::Reload()
BuildPipelines = readBool("XeSS", "BuildPipelines");
NetworkModel = readInt("XeSS", "NetworkModel");
OverrideQuality = readInt("XeSS", "OverrideQuality");
ColorSpaceFix = readBool("XeSS", "ColorSpaceFix");

// logging
LoggingEnabled = readBool("Log", "LoggingEnabled");
Expand Down Expand Up @@ -57,7 +58,6 @@ void Config::Reload()
// Color
AutoExposure = readBool("Color", "AutoExposure");
HDR = readBool("Color", "HDR");
ColorSpaceFix = readBool("Color", "ColorSpaceFix");

// MotionVectors
JitterCancellation = readBool("MotionVectors", "JitterCancellation");
Expand Down
3 changes: 2 additions & 1 deletion CyberXeSS/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Config

// Color
std::optional<bool> AutoExposure;
std::optional<bool> ColorSpaceFix;
std::optional<bool> HDR;

// Motion
Expand All @@ -43,6 +42,7 @@ class Config
std::optional<bool> BuildPipelines;
std::optional<int32_t> NetworkModel;
std::optional<int32_t> OverrideQuality;
std::optional<bool> ColorSpaceFix;

// CAS
std::optional<bool> CasEnabled;
Expand Down Expand Up @@ -94,6 +94,7 @@ class Config

bool changeBackend = false;
std::string newBackend = "";
bool xessDebug = false;


void Reload();
Expand Down
10 changes: 7 additions & 3 deletions CyberXeSS/CyberXeSS.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<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;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)CyberXess\cas\lib;$(SolutionDir)CyberXess\fsr2\lib;$(SolutionDir)CyberXess\fsr2_212\lib;$(SolutionDir)CyberXess\vulkan;$(SolutionDir)external\xess\lib;$(LibraryPath)</LibraryPath>
<LibraryPath>$(SolutionDir)CyberXess\cas\lib;$(SolutionDir)CyberXess\fsr2\lib;$(SolutionDir)CyberXess\fsr2_212\lib;$(SolutionDir)CyberXess\vulkan;$(SolutionDir)external\xess\lib;$(SolutionDir)CyberXess\d3dx;$(LibraryPath)</LibraryPath>
<TargetName>nvngx</TargetName>
<OutDir>D:\Games\Stranger of Paradise - Final Fantasy Origin\</OutDir>
<OutDir>D:\Folders\Games\Deep Rock Galactic\FSD\Binaries\Win64\</OutDir>
<IntDir>.\x64\Debug</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -142,7 +142,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>dxgi.lib;d3d11.lib;d3d12.lib;vulkan-1.lib;dxguid.lib;libxess.lib;ffx_fsr2_api_x64d.lib;ffx_fsr2_api_dx11_x64d.lib;ffx_fsr2_api_dx12_x64d.lib;ffx_fsr2_api_vk_x64d.lib;ffx_cas_backend_dx12_x64d.lib;ffx_cas_x64d.lib;ffx_fsr2_212_api_dx12_x64d.lib;ffx_fsr2_212_api_vk_x64d.lib;ffx_fsr2_212_api_x64d.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>dxgi.lib;d3d11.lib;d3d12.lib;vulkan-1.lib;dxguid.lib;libxess.lib;ffx_fsr2_api_x64d.lib;ffx_fsr2_api_dx11_x64d.lib;ffx_fsr2_api_dx12_x64d.lib;ffx_fsr2_api_vk_x64d.lib;ffx_cas_backend_dx12_x64d.lib;ffx_cas_x64d.lib;ffx_fsr2_212_api_dx12_x64d.lib;ffx_fsr2_212_api_vk_x64d.lib;ffx_fsr2_212_api_x64d.lib;d3dcompiler.lib;d3dx11.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -176,6 +176,7 @@ copy $(SolutionDir)nvngx.ini $(SolutionDir)x64\Release\a\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="cas\CAS_Dx12.h" />
<ClInclude Include="backends\fsr2_212\FSR2Feature_212.h" />
<ClInclude Include="backends\fsr2_212\FSR2Feature_Dx11On12_212.h" />
<ClInclude Include="backends\fsr2_212\FSR2Feature_Dx12_212.h" />
Expand All @@ -192,6 +193,7 @@ copy $(SolutionDir)nvngx.ini $(SolutionDir)x64\Release\a\</Command>
<ClInclude Include="backends\IFeature.h" />
<ClInclude Include="backends\IFeature_Vk.h" />
<ClInclude Include="detours\detours.h" />
<ClInclude Include="cs\CS_Dx12.h" />
<ClInclude Include="imgui\imgui\imconfig.h" />
<ClInclude Include="imgui\imgui\imgui.h" />
<ClInclude Include="imgui\imgui\imgui_impl_dx11.h" />
Expand All @@ -211,6 +213,7 @@ copy $(SolutionDir)nvngx.ini $(SolutionDir)x64\Release\a\</Command>
<ClInclude Include="backends\xess\XeSSFeature_Dx11.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="cas\CAS_Dx12.cpp" />
<ClCompile Include="backends\fsr2_212\FSR2Feature_212.cpp" />
<ClCompile Include="backends\fsr2_212\FSR2Feature_Dx11On12_212.cpp" />
<ClCompile Include="backends\fsr2_212\FSR2Feature_Dx12_212.cpp" />
Expand All @@ -226,6 +229,7 @@ copy $(SolutionDir)nvngx.ini $(SolutionDir)x64\Release\a\</Command>
<ClCompile Include="backends\fsr2\FSR2Feature_Vk.cpp" />
<ClCompile Include="backends\IFeature.cpp" />
<ClCompile Include="backends\IFeature_Dx12.cpp" />
<ClCompile Include="cs\CS_Dx12.cpp" />
<ClCompile Include="imgui\imgui\imgui.cpp" />
<ClCompile Include="imgui\imgui\imgui_demo.cpp" />
<ClCompile Include="imgui\imgui\imgui_draw.cpp" />
Expand Down
12 changes: 12 additions & 0 deletions CyberXeSS/CyberXeSS.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
<ClInclude Include="imgui\Imgui_Dx11.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="cas\CAS_Dx12.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="cs\CS_Dx12.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Config.cpp">
Expand Down Expand Up @@ -239,5 +245,11 @@
<ClCompile Include="backends\IFeature_Dx11.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cas\CAS_Dx12.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cs\CS_Dx12.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
54 changes: 29 additions & 25 deletions CyberXeSS/backends/IFeature_Dx11wDx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

#define SAFE_RELEASE(p) \
do { \
if(p && p != nullptr && p != NULL) \
if(p && p != nullptr) \
{ \
(p)->Release(); \
(p) = nullptr; \
} \
} while((void)0, 0);
} while((void)0, 0)

void IFeature_Dx11wDx12::ResourceBarrier(ID3D12GraphicsCommandList * commandList, ID3D12Resource * resource, D3D12_RESOURCE_STATES beforeState, D3D12_RESOURCE_STATES afterState)
{
Expand All @@ -22,6 +22,7 @@ void IFeature_Dx11wDx12::ResourceBarrier(ID3D12GraphicsCommandList * commandList
barrier.Transition.Subresource = 0;
commandList->ResourceBarrier(1, &barrier);
}

bool IFeature_Dx11wDx12::CopyTextureFrom11To12(ID3D11Resource* InResource, D3D11_TEXTURE2D_RESOURCE_C* OutResource, bool InCopy)
{
ID3D11Texture2D* originalTexture = nullptr;
Expand Down Expand Up @@ -110,8 +111,6 @@ bool IFeature_Dx11wDx12::CopyTextureFrom11To12(ID3D11Resource* InResource, D3D11

void IFeature_Dx11wDx12::ReleaseSharedResources()
{
spdlog::debug("IFeature_Dx11wDx12::ReleaseSharedResources start!");

SAFE_RELEASE(dx11Color.SharedTexture);
SAFE_RELEASE(dx11Mv.SharedTexture);
SAFE_RELEASE(dx11Out.SharedTexture);
Expand Down Expand Up @@ -593,11 +592,7 @@ bool IFeature_Dx11wDx12::CopyBackOutput()
spdlog::error("IFeature_Dx11wDx12::CopyBackOutput Can't create open sharedhandle for dx11fence_2 {0:x}", fr);
return false;
}
}

// xess done
if (Config::Instance()->UseSafeSyncQueries.value_or(1) < 4)
{
if (Config::Instance()->UseSafeSyncQueries.value_or(1) > 0)
{
Dx12CommandQueue->Signal(dx12fence_2, 20);
Expand Down Expand Up @@ -745,34 +740,43 @@ bool IFeature_Dx11wDx12::BaseInit(ID3D11Device* InDevice, ID3D11DeviceContext* I
return true;
}

IFeature_Dx11wDx12::IFeature_Dx11wDx12(unsigned int InHandleId, const NVSDK_NGX_Parameter* InParameters) : IFeature_Dx11(InHandleId, InParameters), IFeature(InHandleId, InParameters)
IFeature_Dx11wDx12::IFeature_Dx11wDx12(unsigned int InHandleId, const NVSDK_NGX_Parameter* InParameters) : IFeature(InHandleId, InParameters), IFeature_Dx11(InHandleId, InParameters)
{
}

IFeature_Dx11wDx12::~IFeature_Dx11wDx12()
{
spdlog::debug("IFeature_Dx11wDx12::~IFeature_Dx11wDx12");

if (Dx12on11Device && Dx12CommandQueue && Dx12CommandList)
{
ID3D12Fence* d3d12Fence;
Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence));
Dx12CommandList->Close();
ID3D12CommandList* ppCommandLists[] = { Dx12CommandList };
Dx12CommandQueue->ExecuteCommandLists(1, ppCommandLists);
Dx12CommandQueue->Signal(d3d12Fence, 999);
ID3D12Fence* d3d12Fence = nullptr;

do
{
if (Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence)) != S_OK)
break;

auto fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (Dx12CommandList->Close() != S_OK)
break;

ID3D12CommandList* ppCommandLists[] = { Dx12CommandList };
Dx12CommandQueue->ExecuteCommandLists(1, ppCommandLists);
Dx12CommandQueue->Signal(d3d12Fence, 999);

HANDLE fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);

if (d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
if (fenceEvent != NULL && d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
{
WaitForSingleObject(fenceEvent, INFINITE);
CloseHandle(fenceEvent);
}

} while (false);

if (d3d12Fence != nullptr)
{
WaitForSingleObject(fenceEvent, INFINITE);
CloseHandle(fenceEvent);
d3d12Fence->Release();
d3d12Fence = nullptr;
}
else
spdlog::warn("IFeature_Dx11wDx12::~IFeature_Dx11wDx12 can't get fenceEvent handle");

d3d12Fence->Release();
}

ReleaseSharedResources();
Expand Down
40 changes: 24 additions & 16 deletions CyberXeSS/backends/IFeature_Dx12.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
#pragma once
#include "IFeature_Dx12.h"

void IFeature_Dx12::ResourceBarrier(ID3D12GraphicsCommandList* commandList, ID3D12Resource* resource, D3D12_RESOURCE_STATES beforeState, D3D12_RESOURCE_STATES afterState)
void IFeature_Dx12::ResourceBarrier(ID3D12GraphicsCommandList* InCommandList, ID3D12Resource* InResource, D3D12_RESOURCE_STATES InBeforeState, D3D12_RESOURCE_STATES InAfterState) const
{
D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Transition.pResource = resource;
barrier.Transition.StateBefore = beforeState;
barrier.Transition.StateAfter = afterState;
barrier.Transition.pResource = InResource;
barrier.Transition.StateBefore = InBeforeState;
barrier.Transition.StateAfter = InAfterState;
barrier.Transition.Subresource = 0;
commandList->ResourceBarrier(1, &barrier);
InCommandList->ResourceBarrier(1, &barrier);
}

IFeature_Dx12::~IFeature_Dx12()
{
if (Device)
{
ID3D12Fence* d3d12Fence;
Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence));
ID3D12Fence* d3d12Fence = nullptr;

d3d12Fence->Signal(999);
do
{
if (Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence)) != S_OK)
break;

d3d12Fence->Signal(999);

HANDLE fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);

auto fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (fenceEvent != NULL && d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
{
WaitForSingleObject(fenceEvent, INFINITE);
CloseHandle(fenceEvent);
}

if (d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
} while (false);

if (d3d12Fence != nullptr)
{
WaitForSingleObject(fenceEvent, INFINITE);
CloseHandle(fenceEvent);
d3d12Fence->Release();
d3d12Fence = nullptr;
}
else
spdlog::warn("XeSSFeatureDx12::~XeSSFeatureDx12 can't get fenceEvent handle");

d3d12Fence->Release();
}

if (Imgui)
Expand Down
2 changes: 1 addition & 1 deletion CyberXeSS/backends/IFeature_Dx12.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class IFeature_Dx12 : public virtual IFeature
ID3D12Device* Device = nullptr;
std::unique_ptr<Imgui_Dx12> Imgui = nullptr;

void ResourceBarrier(ID3D12GraphicsCommandList* InCommandList, ID3D12Resource* InResource, D3D12_RESOURCE_STATES InBeforeState, D3D12_RESOURCE_STATES InAfterState);
void ResourceBarrier(ID3D12GraphicsCommandList* InCommandList, ID3D12Resource* InResource, D3D12_RESOURCE_STATES InBeforeState, D3D12_RESOURCE_STATES InAfterState) const;

public:
virtual bool Init(ID3D12Device* InDevice, const NVSDK_NGX_Parameter* InParameters) = 0;
Expand Down
Loading

0 comments on commit b44b45f

Please sign in to comment.