better organised aproach for cas & cs

This commit is contained in:
cdozdil
2024-03-26 19:13:04 +03:00
parent e1e1fc50d6
commit b44b45f9df
25 changed files with 2026 additions and 917 deletions
+1 -1
View File
@@ -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");
@@ -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");
+2 -1
View File
@@ -23,7 +23,6 @@ public:
// Color
std::optional<bool> AutoExposure;
std::optional<bool> ColorSpaceFix;
std::optional<bool> HDR;
// Motion
@@ -43,6 +42,7 @@ public:
std::optional<bool> BuildPipelines;
std::optional<int32_t> NetworkModel;
std::optional<int32_t> OverrideQuality;
std::optional<bool> ColorSpaceFix;
// CAS
std::optional<bool> CasEnabled;
@@ -94,6 +94,7 @@ public:
bool changeBackend = false;
std::string newBackend = "";
bool xessDebug = false;
void Reload();
+7 -3
View File
@@ -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'">
@@ -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'">
@@ -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" />
@@ -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" />
@@ -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" />
@@ -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" />
+12
View File
@@ -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">
@@ -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>
+30 -26
View File
@@ -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)
{
@@ -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;
@@ -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);
@@ -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);
@@ -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;
auto fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
do
{
WaitForSingleObject(fenceEvent, INFINITE);
CloseHandle(fenceEvent);
}
else
spdlog::warn("IFeature_Dx11wDx12::~IFeature_Dx11wDx12 can't get fenceEvent handle");
if (Dx12on11Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence)) != S_OK)
break;
d3d12Fence->Release();
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 (fenceEvent != NULL && d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
{
WaitForSingleObject(fenceEvent, INFINITE);
CloseHandle(fenceEvent);
}
} while (false);
if (d3d12Fence != nullptr)
{
d3d12Fence->Release();
d3d12Fence = nullptr;
}
}
ReleaseSharedResources();
+26 -18
View File
@@ -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);
auto fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
do
{
WaitForSingleObject(fenceEvent, INFINITE);
CloseHandle(fenceEvent);
}
else
spdlog::warn("XeSSFeatureDx12::~XeSSFeatureDx12 can't get fenceEvent handle");
if (Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence)) != S_OK)
break;
d3d12Fence->Release();
d3d12Fence->Signal(999);
HANDLE fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (fenceEvent != NULL && d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
{
WaitForSingleObject(fenceEvent, INFINITE);
CloseHandle(fenceEvent);
}
} while (false);
if (d3d12Fence != nullptr)
{
d3d12Fence->Release();
d3d12Fence = nullptr;
}
}
if (Imgui)
+1 -1
View File
@@ -12,7 +12,7 @@ protected:
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;
+23 -763
View File
@@ -1,281 +1,41 @@
#pragma once
#include "../../pch.h"
#include "../../Config.h"
#include "../../imgui/d3dx12.h"
#include "XeSSFeature.h"
#include <d3dcompiler.h>
struct Constants
{
float Multiplier;
};
// pixel.rgb = pow(abs(pixel.rgb) * 4.0, 2.4) * sign(pixel.rgb);
const std::string _recEncodeShaderCode = R"(
static const std::string outputEncodeShaderCode = R"(
Texture2D<float4> InputTexture : register(t0);
RWTexture2D<float4> OutputTexture : register(u0);
// Companding shader
[numthreads(16,16,1)]
void main(uint3 DTid : SV_DispatchThreadID)
{
float4 pixel = InputTexture[DTid.xy];
float4 pixel = InputTexture[DTid.xy];
pixel.rgb *= 10.0;
OutputTexture[DTid.xy] = pixel;
OutputTexture[DTid.xy] = pixel;
})";
//
// pixel.rgb = pow(abs(pixel.rgb), 0.4166666666666667) * sign(pixel.rgb) * 0.25;
const std::string _recDecodeShaderCode = R"(
static const std::string colorDecodeShaderCode = R"(
Texture2D<float4> InputTexture : register(t0);
RWTexture2D<float4> OutputTexture : register(u0);
// Inverse companding shader
[numthreads(16,16,1)]
void main(uint3 DTid : SV_DispatchThreadID)
{
float4 pixel = InputTexture[DTid.xy];
float4 pixel = InputTexture[DTid.xy];
pixel.rgb *= 0.1;
OutputTexture[DTid.xy] = pixel;
OutputTexture[DTid.xy] = pixel;
})";
inline static std::string ResultToString(FfxCas::FfxErrorCode result)
{
switch (result)
{
case FfxCas::FFX_OK: return "The operation completed successfully.";
case FfxCas::FFX_ERROR_INVALID_POINTER: return "The operation failed due to an invalid pointer.";
case FfxCas::FFX_ERROR_INVALID_ALIGNMENT: return "The operation failed due to an invalid alignment.";
case FfxCas::FFX_ERROR_INVALID_SIZE: return "The operation failed due to an invalid size.";
case FfxCas::FFX_EOF: return "The end of the file was encountered.";
case FfxCas::FFX_ERROR_INVALID_PATH: return "The operation failed because the specified path was invalid.";
case FfxCas::FFX_ERROR_EOF: return "The operation failed because end of file was reached.";
case FfxCas::FFX_ERROR_MALFORMED_DATA: return "The operation failed because of some malformed data.";
case FfxCas::FFX_ERROR_OUT_OF_MEMORY: return "The operation failed because it ran out memory.";
case FfxCas::FFX_ERROR_INCOMPLETE_INTERFACE: return "The operation failed because the interface was not fully configured.";
case FfxCas::FFX_ERROR_INVALID_ENUM: return "The operation failed because of an invalid enumeration value.";
case FfxCas::FFX_ERROR_INVALID_ARGUMENT: return "The operation failed because an argument was invalid.";
case FfxCas::FFX_ERROR_OUT_OF_RANGE: return "The operation failed because a value was out of range.";
case FfxCas::FFX_ERROR_NULL_DEVICE: return "The operation failed because a device was null.";
case FfxCas::FFX_ERROR_BACKEND_API_ERROR: return "The operation failed because the backend API returned an error code.";
case FfxCas::FFX_ERROR_INSUFFICIENT_MEMORY: return "The operation failed because there was not enough memory.";
default: return "Unknown";
}
}
inline void FfxCasLogCallback(const char* message)
{
spdlog::debug("XeSSFeature::LogCallback FSR Runtime: {0}", message);
}
FfxCas::FfxSurfaceFormat ffxGetSurfaceFormatDX12(DXGI_FORMAT format)
{
switch (format) {
case(DXGI_FORMAT_R32G32B32A32_TYPELESS):
return FfxCas::FFX_SURFACE_FORMAT_R32G32B32A32_TYPELESS;
case(DXGI_FORMAT_R32G32B32A32_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R32G32B32A32_FLOAT;
case DXGI_FORMAT_R32G32B32A32_UINT:
return FfxCas::FFX_SURFACE_FORMAT_R32G32B32A32_UINT;
//case DXGI_FORMAT_R32G32B32A32_SINT:
//case DXGI_FORMAT_R32G32B32_TYPELESS:
//case DXGI_FORMAT_R32G32B32_FLOAT:
//case DXGI_FORMAT_R32G32B32_UINT:
//case DXGI_FORMAT_R32G32B32_SINT:
case DXGI_FORMAT_R16G16B16A16_TYPELESS:
case(DXGI_FORMAT_R16G16B16A16_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT;
//case DXGI_FORMAT_R16G16B16A16_UNORM:
//case DXGI_FORMAT_R16G16B16A16_UINT:
//case DXGI_FORMAT_R16G16B16A16_SNORM:
//case DXGI_FORMAT_R16G16B16A16_SINT:
case DXGI_FORMAT_R32G32_TYPELESS:
case DXGI_FORMAT_R32G32_FLOAT:
return FfxCas::FFX_SURFACE_FORMAT_R32G32_FLOAT;
//case DXGI_FORMAT_R32G32_FLOAT:
//case DXGI_FORMAT_R32G32_UINT:
//case DXGI_FORMAT_R32G32_SINT:
case DXGI_FORMAT_R32G8X24_TYPELESS:
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
return FfxCas::FFX_SURFACE_FORMAT_R32_FLOAT;
case DXGI_FORMAT_R24G8_TYPELESS:
case DXGI_FORMAT_D24_UNORM_S8_UINT:
case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
return FfxCas::FFX_SURFACE_FORMAT_R32_UINT;
case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
return FfxCas::FFX_SURFACE_FORMAT_R8_UINT;
//case DXGI_FORMAT_R10G10B10A2_TYPELESS:
//case DXGI_FORMAT_R10G10B10A2_UNORM:
// return FfxCas::FFX_SURFACE_FORMAT_R10G10B10A2_UNORM;
//case DXGI_FORMAT_R10G10B10A2_UINT:
case (DXGI_FORMAT_R11G11B10_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R11G11B10_FLOAT;
case (DXGI_FORMAT_R8G8B8A8_TYPELESS):
return FfxCas::FFX_SURFACE_FORMAT_R8G8B8A8_TYPELESS;
case (DXGI_FORMAT_R8G8B8A8_UNORM):
return FfxCas::FFX_SURFACE_FORMAT_R8G8B8A8_UNORM;
case (DXGI_FORMAT_R8G8B8A8_UNORM_SRGB):
return FfxCas::FFX_SURFACE_FORMAT_R8G8B8A8_SRGB;
//case DXGI_FORMAT_R8G8B8A8_UINT:
case DXGI_FORMAT_R8G8B8A8_SNORM:
return FfxCas::FFX_SURFACE_FORMAT_R8G8B8A8_SNORM;
case DXGI_FORMAT_R16G16_TYPELESS:
case (DXGI_FORMAT_R16G16_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R16G16_FLOAT;
//case DXGI_FORMAT_R16G16_UNORM:
case (DXGI_FORMAT_R16G16_UINT):
return FfxCas::FFX_SURFACE_FORMAT_R16G16_UINT;
//case DXGI_FORMAT_R16G16_SNORM
//case DXGI_FORMAT_R16G16_SINT
//case DXGI_FORMAT_R32_SINT:
//case DXGI_FORMAT_R32_UINT:
// return FFX_SURFACE_FORMAT_R32_UINT;
case DXGI_FORMAT_R32_TYPELESS:
case(DXGI_FORMAT_D32_FLOAT):
case(DXGI_FORMAT_R32_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R32_FLOAT;
case DXGI_FORMAT_R8G8_TYPELESS:
//case (DXGI_FORMAT_R8G8_UINT):
// return FfxCas::FFX_SURFACE_FORMAT_R8G8_UINT;
//case DXGI_FORMAT_R8G8_UNORM:
//case DXGI_FORMAT_R8G8_SNORM:
//case DXGI_FORMAT_R8G8_SINT:
case DXGI_FORMAT_R16_TYPELESS:
case (DXGI_FORMAT_R16_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R16_FLOAT;
case (DXGI_FORMAT_R16_UINT):
return FfxCas::FFX_SURFACE_FORMAT_R16_UINT;
case DXGI_FORMAT_D16_UNORM:
case (DXGI_FORMAT_R16_UNORM):
return FfxCas::FFX_SURFACE_FORMAT_R16_UNORM;
case (DXGI_FORMAT_R16_SNORM):
return FfxCas::FFX_SURFACE_FORMAT_R16_SNORM;
//case DXGI_FORMAT_R16_SINT:
case DXGI_FORMAT_R8_TYPELESS:
case DXGI_FORMAT_R8_UNORM:
case DXGI_FORMAT_A8_UNORM:
return FfxCas::FFX_SURFACE_FORMAT_R8_UNORM;
//case DXGI_FORMAT_R8_UINT:
// return FFX_SURFACE_FORMAT_R8_UINT;
//case DXGI_FORMAT_R8_SNORM:
//case DXGI_FORMAT_R8_SINT:
//case DXGI_FORMAT_R1_UNORM:
case(DXGI_FORMAT_UNKNOWN):
return FfxCas::FFX_SURFACE_FORMAT_UNKNOWN;
default:
//FFX_ASSERT_MESSAGE(false, "Format not yet supported");
return FfxCas::FFX_SURFACE_FORMAT_UNKNOWN;
}
}
bool IsDepthDX12(DXGI_FORMAT format)
{
return (format == DXGI_FORMAT_D16_UNORM) ||
(format == DXGI_FORMAT_D32_FLOAT) ||
(format == DXGI_FORMAT_D24_UNORM_S8_UINT) ||
(format == DXGI_FORMAT_D32_FLOAT_S8X24_UINT);
}
FfxCas::FfxResourceDescription GetFfxResourceDescriptionDX12(ID3D12Resource* pResource)
{
FfxCas::FfxResourceDescription resourceDescription = {};
// This is valid
if (!pResource)
return resourceDescription;
if (pResource)
{
D3D12_RESOURCE_DESC desc = pResource->GetDesc();
// Set flags properly for resource registration
resourceDescription.flags = FfxCas::FFX_RESOURCE_FLAGS_NONE;
resourceDescription.usage = IsDepthDX12(desc.Format) ? FfxCas::FFX_RESOURCE_USAGE_DEPTHTARGET : FfxCas::FFX_RESOURCE_USAGE_READ_ONLY;
if ((desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS) == D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
resourceDescription.usage = (FfxCas::FfxResourceUsage)(resourceDescription.usage | FfxCas::FFX_RESOURCE_USAGE_UAV);
resourceDescription.width = (uint32_t)desc.Width;
resourceDescription.height = (uint32_t)desc.Height;
resourceDescription.depth = desc.DepthOrArraySize;
resourceDescription.mipCount = desc.MipLevels;
resourceDescription.format = ffxGetSurfaceFormatDX12(desc.Format);
resourceDescription.type = FfxCas::FFX_RESOURCE_TYPE_TEXTURE2D;
}
return resourceDescription;
}
inline void XeSSLogCallback(const char* Message, xess_logging_level_t Level)
{
spdlog::log((spdlog::level::level_enum)((int)Level + 1), "FeatureContext::LogCallback XeSS Runtime ({0})", Message);
}
static ID3DBlob* CompileShader(const char* shaderCode, const char* entryPoint, const char* target)
{
ID3DBlob* shaderBlob = nullptr;
ID3DBlob* errorBlob = nullptr;
HRESULT hr = D3DCompile(shaderCode, strlen(shaderCode), nullptr, nullptr, nullptr, entryPoint, target, 0, 0, &shaderBlob, &errorBlob);
if (FAILED(hr))
{
if (errorBlob)
{
OutputDebugStringA((char*)errorBlob->GetBufferPointer());
errorBlob->Release();
}
if (shaderBlob)
shaderBlob->Release();
return nullptr;
}
if (errorBlob)
errorBlob->Release();
return shaderBlob;
}
static bool CreateComputeShader(ID3D12Device* device, ID3D12RootSignature* rootSignature, ID3D12PipelineState** pipelineState, ID3DBlob* shaderBlob)
{
D3D12_COMPUTE_PIPELINE_STATE_DESC psoDesc = {};
psoDesc.pRootSignature = rootSignature;
psoDesc.CS = CD3DX12_SHADER_BYTECODE(const_cast<void*>(shaderBlob->GetBufferPointer()), shaderBlob->GetBufferSize());
//psoDesc.CS = { reinterpret_cast<UINT8*>(shaderBlob->GetBufferPointer()), shaderBlob->GetBufferSize() };
psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
HRESULT hr = device->CreateComputePipelineState(&psoDesc, IID_PPV_ARGS(pipelineState));
if (FAILED(hr))
{
// Handle error
return false;
}
return true;
}
bool XeSSFeature::InitXeSS(ID3D12Device* device, const NVSDK_NGX_Parameter* InParameters)
{
spdlog::debug("XeSSFeature::InitXeSS!");
@@ -375,7 +135,7 @@ bool XeSSFeature::InitXeSS(ID3D12Device* device, const NVSDK_NGX_Parameter* InPa
spdlog::info("XeSSFeature::InitXeSS xessParams.initFlags (DepthInverted) {0:b}", xessParams.initFlags);
}
if (Config::Instance()->AutoExposure.value_or(AutoExposure))
if (Config::Instance()->AutoExposure.value_or(AutoExposure) || Config::Instance()->ColorSpaceFix.value_or(false))
{
Config::Instance()->AutoExposure = true;
xessParams.initFlags |= XESS_INIT_FLAG_ENABLE_AUTOEXPOSURE;
@@ -449,10 +209,10 @@ bool XeSSFeature::InitXeSS(ID3D12Device* device, const NVSDK_NGX_Parameter* InPa
return false;
}
CasInit();
CreateCasContext(device);
CAS = std::make_unique<CAS_Dx12>(device, DisplayWidth(), DisplayHeight(), Config::Instance()->CasColorSpaceConversion.value_or(0));
RecInit(device);
ColorDecode = std::make_unique<CS_Dx12>(device, colorDecodeShaderCode.c_str(), "main", "cs_5_0");
OutputEncode = std::make_unique<CS_Dx12>(device, outputEncodeShaderCode.c_str(), "main", "cs_5_0");
SetInit(true);
@@ -461,529 +221,29 @@ bool XeSSFeature::InitXeSS(ID3D12Device* device, const NVSDK_NGX_Parameter* InPa
XeSSFeature::~XeSSFeature()
{
spdlog::debug("XeSSFeature::XeSSFeature");
if (_xessContext)
{
auto result = xessDestroyContext(_xessContext);
xessDestroyContext(_xessContext);
_xessContext = nullptr;
if (result != XESS_RESULT_SUCCESS)
spdlog::error("XeSSFeature::Destroy xessDestroyContext error: {0}", ResultToString(result));
}
DestroyCasContext();
if (CAS != nullptr)
CAS.reset();
if (casBuffer != nullptr)
{
casBuffer->Release();
casBuffer = nullptr;
}
if (ColorDecode != nullptr)
ColorDecode.reset();
if (OutputEncode != nullptr)
OutputEncode.reset();
}
void XeSSFeature::CasInit()
float XeSSFeature::GetSharpness(const NVSDK_NGX_Parameter* InParameters)
{
if (casInit)
return;
spdlog::debug("FeatureContext::CasInit Start!");
casSharpness = Config::Instance()->Sharpness.value_or(0.3);
if (casSharpness > 1 || casSharpness < 0)
casSharpness = 0.3f;
casInit = true;
}
bool XeSSFeature::CreateCasContext(ID3D12Device* device)
{
if (!casInit)
return false;
spdlog::debug("XeSSFeature::CreateCasContext Start!");
DestroyCasContext();
const size_t scratchBufferSize = FfxCas::ffxGetScratchMemorySizeDX12Cas(FFX_CAS_CONTEXT_COUNT);
void* casScratchBuffer = calloc(scratchBufferSize, 1);
auto errorCode = FfxCas::ffxGetInterfaceDX12Cas(&casContextDesc.backendInterface, device, casScratchBuffer, scratchBufferSize, FFX_CAS_CONTEXT_COUNT);
if (errorCode != FfxCas::FFX_OK)
{
spdlog::error("XeSSFeature::CreateCasContext ffxGetInterfaceDX12 error: {0}", ResultToString(errorCode));
free(casScratchBuffer);
return false;
}
casUpscale = false;
casContextDesc.flags |= FfxCas::FFX_CAS_SHARPEN_ONLY;
auto casCSC = Config::Instance()->CasColorSpaceConversion.value_or(FfxCas::FFX_CAS_COLOR_SPACE_LINEAR);
if (casCSC < 0 || casCSC > 4)
casCSC = 0;
casContextDesc.colorSpaceConversion = static_cast<FfxCas::FfxCasColorSpaceConversion>(casCSC);
casContextDesc.maxRenderSize.width = DisplayWidth() + 10;
casContextDesc.maxRenderSize.height = DisplayHeight() + 10;
casContextDesc.displaySize.width = DisplayWidth();
casContextDesc.displaySize.height = DisplayHeight();
errorCode = FfxCas::ffxCasContextCreate(&casContext, &casContextDesc);
if (errorCode != FfxCas::FFX_OK)
{
spdlog::error("XeSSFeature::CreateCasContext ffxCasContextCreate error: {0:x}", errorCode);
return false;
}
FfxCas::ffxAssertSetPrintingCallback(FfxCasLogCallback);
casContextCreated = true;
return true;
}
void XeSSFeature::DestroyCasContext()
{
spdlog::debug("XeSSFeature::DestroyCasContext Start!");
if (!casContextCreated)
return;
auto errorCode = FfxCas::ffxCasContextDestroy(&casContext);
if (errorCode != FfxCas::FFX_OK)
spdlog::error("FeatureContext::DestroyCasContext ffxCasContextDestroy error: {0:x}", errorCode);
free(casContextDesc.backendInterface.scratchBuffer);
casContextCreated = false;
}
bool XeSSFeature::CreateCasBufferResource(ID3D12Resource* source, ID3D12Device* device)
{
if (!casInit)
return false;
if (source == nullptr)
return false;
spdlog::debug("XeSSFeature::CreateCasBufferResource Start!");
D3D12_RESOURCE_DESC texDesc = source->GetDesc();
D3D12_HEAP_PROPERTIES heapProperties;
D3D12_HEAP_FLAGS heapFlags;
HRESULT hr = source->GetHeapProperties(&heapProperties, &heapFlags);
if (hr != S_OK)
{
spdlog::error("XeSSFeature::CreateBufferResource GetHeapProperties result: {0:x}", hr);
return false;
}
if (casBuffer != nullptr)
casBuffer->Release();
texDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
hr = device->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &texDesc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, IID_PPV_ARGS(&casBuffer));
if (hr != S_OK)
{
spdlog::error("XeSSFeature::CreateBufferResource CreateCommittedResource result: {0:x}", hr);
return false;
}
return true;
}
bool XeSSFeature::CasDispatch(ID3D12CommandList* commandList, const NVSDK_NGX_Parameter* initParams, ID3D12Resource* input, ID3D12Resource* output)
{
if (!casInit)
return false;
spdlog::debug("XeSSFeature::CasDispatch Start!");
FfxCas::FfxCasDispatchDescription dispatchParameters = {};
dispatchParameters.commandList = FfxCas::ffxGetCommandListDX12Cas(commandList);
dispatchParameters.renderSize = { DisplayWidth(), DisplayHeight() };
float dlssSharpness = 0.0f;
initParams->Get(NVSDK_NGX_Parameter_Sharpness, &dlssSharpness);
_sharpness = dlssSharpness;
if (Config::Instance()->OverrideSharpness.value_or(false))
casSharpness = Config::Instance()->Sharpness.value_or(0.3f);
else
casSharpness = dlssSharpness;
return Config::Instance()->Sharpness.value_or(0.3);
if (casSharpness <= 0.0f)
return true;
else if (casSharpness > 1.0f)
casSharpness = 1.0f;
float sharpness = 0.0f;
InParameters->Get(NVSDK_NGX_Parameter_Sharpness, &sharpness);
dispatchParameters.sharpness = casSharpness;
dispatchParameters.color = FfxCas::ffxGetResourceDX12Cas(input, GetFfxResourceDescriptionDX12(input), nullptr, FfxCas::FFX_RESOURCE_STATE_PIXEL_COMPUTE_READ);
dispatchParameters.output = FfxCas::ffxGetResourceDX12Cas(output, GetFfxResourceDescriptionDX12(output), nullptr, FfxCas::FFX_RESOURCE_STATE_UNORDERED_ACCESS);
if (auto errorCode = FfxCas::ffxCasContextDispatch(&casContext, &dispatchParameters); errorCode != FfxCas::FFX_OK)
{
spdlog::error("FeatureContext::CasDispatch ffxCasContextDispatch error: {0}", ResultToString(errorCode));
return false;
}
return true;
return sharpness;
}
bool XeSSFeature::RecInit(ID3D12Device* InDevice)
{
// Describe and create the root signature
// ---------------------------------------------------
D3D12_DESCRIPTOR_RANGE descriptorRange[2];
// SRV Range (Input Texture)
descriptorRange[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
descriptorRange[0].NumDescriptors = 1;
descriptorRange[0].BaseShaderRegister = 0; // Assuming t0 register in HLSL for SRV
descriptorRange[0].RegisterSpace = 0;
descriptorRange[0].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
// UAV Range (Output Texture)
descriptorRange[1].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
descriptorRange[1].NumDescriptors = 1;
descriptorRange[1].BaseShaderRegister = 0; // Assuming u0 register in HLSL for UAV
descriptorRange[1].RegisterSpace = 0;
descriptorRange[1].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
// Define the root parameter (descriptor table)
// ---------------------------------------------------
D3D12_ROOT_PARAMETER rootParameters[2];
// Root Parameter for SRV
rootParameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParameters[0].DescriptorTable.NumDescriptorRanges = 1; // One range (SRV)
rootParameters[0].DescriptorTable.pDescriptorRanges = &descriptorRange[0]; // Point to the SRV range
rootParameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
// Root Parameter for UAV
rootParameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParameters[1].DescriptorTable.NumDescriptorRanges = 1; // One range (UAV)
rootParameters[1].DescriptorTable.pDescriptorRanges = &descriptorRange[1]; // Point to the UAV range
rootParameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
// A root signature is an array of root parameters
// ---------------------------------------------------
D3D12_ROOT_SIGNATURE_DESC rootSigDesc;
rootSigDesc.NumParameters = 2; // Two root parameters
rootSigDesc.pParameters = rootParameters;
rootSigDesc.NumStaticSamplers = 0;
rootSigDesc.pStaticSamplers = nullptr;
rootSigDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE;
ID3DBlob* errorBlob;
ID3DBlob* signatureBlob;
do
{
auto hr = D3D12SerializeRootSignature(&rootSigDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signatureBlob, &errorBlob);
if (FAILED(hr))
{
break;
}
hr = InDevice->CreateRootSignature(0, signatureBlob->GetBufferPointer(), signatureBlob->GetBufferSize(), IID_PPV_ARGS(&_recRootSignatureDecode));
if (FAILED(hr))
{
break;
}
} while (false);
if (errorBlob != nullptr)
{
errorBlob->Release();
errorBlob = nullptr;
}
if (signatureBlob != nullptr)
{
signatureBlob->Release();
signatureBlob = nullptr;
}
if (_recRootSignatureDecode == nullptr)
return false;
ID3DBlob* errorBlob2;
ID3DBlob* signatureBlob2;
do
{
auto hr = D3D12SerializeRootSignature(&rootSigDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signatureBlob2, &errorBlob2);
if (FAILED(hr))
{
break;
}
hr = InDevice->CreateRootSignature(0, signatureBlob2->GetBufferPointer(), signatureBlob2->GetBufferSize(), IID_PPV_ARGS(&_recRootSignatureEncode));
if (FAILED(hr))
{
break;
}
} while (false);
if (errorBlob2 != nullptr)
{
errorBlob2->Release();
errorBlob2 = nullptr;
}
if (signatureBlob2 != nullptr)
{
signatureBlob2->Release();
signatureBlob2 = nullptr;
}
if (_recRootSignatureEncode == nullptr)
return false;
// Compile shader blobs
auto _recEncodeShader = CompileShader(_recEncodeShaderCode.c_str(), "main", "cs_5_0");
if (_recEncodeShader == nullptr)
{
return false;
}
auto _recDecodeShader = CompileShader(_recDecodeShaderCode.c_str(), "main", "cs_5_0");
if (_recDecodeShader == nullptr)
{
return false;
}
do
{
// create pso objects
if (!CreateComputeShader(InDevice, _recRootSignatureEncode, &_recPSOEncode, _recEncodeShader))
{
break;
}
if (!CreateComputeShader(InDevice, _recRootSignatureDecode, &_recPSODecode, _recDecodeShader))
{
break;
}
} while (false);
if (_recEncodeShader != nullptr)
{
_recEncodeShader->Release();
_recEncodeShader = nullptr;
}
if (_recDecodeShader != nullptr)
{
_recDecodeShader->Release();
_recDecodeShader = nullptr;
}
_recInit = _recPSOEncode != nullptr && _recPSODecode != nullptr;
return _recInit;
}
bool XeSSFeature::RecDecode(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* input, ID3D12Resource* output)
{
if (!_recInit)
return false;
ID3D12DescriptorHeap* srvHeap;
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
heapDesc.NumDescriptors = 2; // One for SRV and one for UAV
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
auto hr = InDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&srvHeap));
if (FAILED(hr))
{
return false;
}
auto srvHandle = srvHeap->GetCPUDescriptorHandleForHeapStart();
auto uavHandle = srvHandle;
uavHandle.ptr += InDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
D3D12_GPU_DESCRIPTOR_HANDLE gpuSrvHandle = srvHeap->GetGPUDescriptorHandleForHeapStart();
D3D12_GPU_DESCRIPTOR_HANDLE gpuUavHandle = gpuSrvHandle;
gpuUavHandle.ptr += InDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
// Create SRV for Input Texture
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srvDesc.Format = input->GetDesc().Format;
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = 1;
InDevice->CreateShaderResourceView(input, &srvDesc, srvHandle);
// Create UAV for Output Texture
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.Format = output->GetDesc().Format;
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
uavDesc.Texture2D.MipSlice = 0;
InDevice->CreateUnorderedAccessView(output, nullptr, &uavDesc, uavHandle);
ID3D12DescriptorHeap* heaps[] = { srvHeap };
InCmdList->SetDescriptorHeaps(_countof(heaps), heaps);
InCmdList->SetComputeRootSignature(_recRootSignatureDecode);
InCmdList->SetPipelineState(_recPSODecode);
InCmdList->SetComputeRootDescriptorTable(0, gpuSrvHandle);
InCmdList->SetComputeRootDescriptorTable(1, gpuUavHandle);
UINT dispatchWidth = (input->GetDesc().Width + 7) / 16;
UINT dispatchHeight = (input->GetDesc().Height + 7) / 16;
InCmdList->Dispatch(dispatchWidth, dispatchHeight, 1);
//ID3D12Fence* d3d12Fence;
//InDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence));
//d3d12Fence->Signal(999);
//auto fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
//if (d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
//{
// WaitForSingleObject(fenceEvent, INFINITE);
// CloseHandle(fenceEvent);
//}
//else
// spdlog::warn("IFeature_Dx11wDx12::~IFeature_Dx11wDx12 can't get fenceEvent handle");
//d3d12Fence->Release();
return true;
}
bool XeSSFeature::RecEncode(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* input, ID3D12Resource* output)
{
if (!_recInit)
return false;
ID3D12DescriptorHeap* srvHeap;
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
heapDesc.NumDescriptors = 2; // One for SRV and one for UAV
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
auto hr = InDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&srvHeap));
if (FAILED(hr))
{
return false;
}
auto srvHandle = srvHeap->GetCPUDescriptorHandleForHeapStart();
auto uavHandle = srvHandle;
uavHandle.ptr += InDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
D3D12_GPU_DESCRIPTOR_HANDLE gpuSrvHandle = srvHeap->GetGPUDescriptorHandleForHeapStart();
D3D12_GPU_DESCRIPTOR_HANDLE gpuUavHandle = gpuSrvHandle;
gpuUavHandle.ptr += InDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
// Create SRV for Input Texture
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srvDesc.Format = input->GetDesc().Format;
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = 1;
InDevice->CreateShaderResourceView(input, &srvDesc, srvHandle);
// Create UAV for Output Texture
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.Format = output->GetDesc().Format;
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
uavDesc.Texture2D.MipSlice = 0;
InDevice->CreateUnorderedAccessView(output, nullptr, &uavDesc, uavHandle);
ID3D12DescriptorHeap* heaps[] = { srvHeap };
InCmdList->SetDescriptorHeaps(_countof(heaps), heaps);
InCmdList->SetComputeRootSignature(_recRootSignatureEncode);
InCmdList->SetPipelineState(_recPSOEncode);
InCmdList->SetComputeRootDescriptorTable(0, gpuSrvHandle);
InCmdList->SetComputeRootDescriptorTable(1, gpuUavHandle);
UINT dispatchWidth = (input->GetDesc().Width + 7) / 16;
UINT dispatchHeight = (input->GetDesc().Height + 7) / 16;
InCmdList->Dispatch(dispatchWidth, dispatchHeight, 1);
return true;
}
bool XeSSFeature::CreateRecBufferResource(ID3D12Resource* source, ID3D12Device* device, ID3D12Resource** output)
{
if (!_recInit)
return false;
if (source == nullptr)
return false;
D3D12_RESOURCE_DESC texDesc = source->GetDesc();
if (*output != nullptr)
{
D3D12_RESOURCE_DESC outDesc = (*output)->GetDesc();
if (outDesc.Width != texDesc.Width || outDesc.Height != texDesc.Height || outDesc.Format != texDesc.Format)
{
(*output)->Release();
(*output) = nullptr;
}
else
{
return true;
}
}
spdlog::debug("XeSSFeature::CreateRecBufferResource Start!");
D3D12_HEAP_PROPERTIES heapProperties;
D3D12_HEAP_FLAGS heapFlags;
HRESULT hr = source->GetHeapProperties(&heapProperties, &heapFlags);
if (hr != S_OK)
{
spdlog::error("XeSSFeature::CreateRecBufferResource GetHeapProperties result: {0:x}", hr);
return false;
}
if (*output != nullptr)
(*output)->Release();
texDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
hr = device->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &texDesc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, IID_PPV_ARGS(output));
if (hr != S_OK)
{
spdlog::error("XeSSFeature::CreateRecBufferResource CreateCommittedResource result: {0:x}", hr);
return false;
}
return true;
}
+7 -37
View File
@@ -1,17 +1,12 @@
#pragma once
#include "../IFeature.h"
#include "../../cas/CAS_Dx12.h"
#include "../../cs/CS_Dx12.h"
#include "xess_d3d12.h"
#include "xess_debug.h"
#include <string>
#include "../../cas/include/ffx_cas.h"
#include "../../cas/include/backends/dx12/ffx_dx12.h"
//dumpParams.frame_count = 1;
//dumpParams.frame_idx = cnt++;
//dumpParams.path = "F:\\";
//xessStartDump(deviceContext->XessContext, &dumpParams);
inline static std::string ResultToString(xess_result_t result)
{
switch (result)
@@ -41,37 +36,12 @@ private:
protected:
xess_context_handle_t _xessContext = nullptr;
// cas
FfxCas::FfxCasContext casContext;
bool casInit = false;
bool casContextCreated = false;
bool casUpscale = false;
float casSharpness = 0.3f;
ID3D12Resource* casBuffer = nullptr;
FfxCas::FfxCasContextDescription casContextDesc = {};
//rec709
bool _recInit = false;
ID3D12RootSignature* _recRootSignatureEncode = nullptr;
ID3D12RootSignature* _recRootSignatureDecode = nullptr;
ID3D12PipelineState* _recPSOEncode = nullptr;
ID3D12PipelineState* _recPSODecode = nullptr;
ID3D12Resource* _recBufferEncode = nullptr;
ID3D12Resource* _recBufferDecode = nullptr;
std::unique_ptr<CAS_Dx12> CAS = nullptr;
std::unique_ptr<CS_Dx12> ColorDecode = nullptr;
std::unique_ptr<CS_Dx12> OutputEncode = nullptr;
bool InitXeSS(ID3D12Device* device, const NVSDK_NGX_Parameter* InParameters);
void CasInit();
bool CreateCasContext(ID3D12Device* device);
void DestroyCasContext();
bool CreateCasBufferResource(ID3D12Resource* source, ID3D12Device* device);
bool CasDispatch(ID3D12CommandList* commandList, const NVSDK_NGX_Parameter* initParams, ID3D12Resource* input, ID3D12Resource* output);
bool RecInit(ID3D12Device* InDevice);
bool RecDecode(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* input, ID3D12Resource* output);
bool RecEncode(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* input, ID3D12Resource* output);
bool CreateRecBufferResource(ID3D12Resource* source, ID3D12Device* device, ID3D12Resource** output);
float GetSharpness(const NVSDK_NGX_Parameter* InParameters);
public:
+44 -37
View File
@@ -4,6 +4,10 @@
#include "XeSSFeature_Dx11.h"
#if _DEBUG
#include "../../d3dx/D3DX11tex.h"
#endif
XeSSFeatureDx11::XeSSFeatureDx11(unsigned int InHandleId, const NVSDK_NGX_Parameter* InParameters) : XeSSFeature(InHandleId, InParameters), IFeature_Dx11wDx12(InHandleId, InParameters), IFeature_Dx11(InHandleId, InParameters), IFeature(InHandleId, InParameters)
{
}
@@ -56,6 +60,17 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
Dx11DeviceContext = dc;
}
if (Config::Instance()->xessDebug)
{
xess_dump_parameters_t dumpParams{};
dumpParams.frame_count = 3;
dumpParams.frame_idx = 1;
dumpParams.path = ".";
dumpParams.dump_elements_mask = XESS_DUMP_INPUT_COLOR | XESS_DUMP_INPUT_VELOCITY | XESS_DUMP_INPUT_DEPTH | XESS_DUMP_OUTPUT | XESS_DUMP_EXECUTION_PARAMETERS;
xessStartDump(_xessContext, &dumpParams);
Config::Instance()->xessDebug = false;
}
// creatimg params for XeSS
xess_result_t xessResult;
xess_d3d12_execute_params_t params{};
@@ -69,6 +84,7 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
InParameters->Get(NVSDK_NGX_Parameter_Reset, &params.resetHistory);
GetRenderResolution(InParameters, &params.inputWidth, &params.inputHeight);
auto sharpness = GetSharpness(InParameters);
spdlog::debug("XeSSFeatureDx11::Evaluate Input Resolution: {0}x{1}", params.inputWidth, params.inputHeight);
@@ -86,26 +102,24 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
return false;
}
if (Config::Instance()->ColorSpaceFix.value_or(false))
if (Config::Instance()->ColorSpaceFix.value_or(false) &&
ColorDecode->CreateBufferResource(Dx12on11Device, dx11Color.Dx12Resource, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE) &&
ColorDecode->Dispatch(Dx12on11Device, Dx12CommandList, dx11Color.Dx12Resource, ColorDecode->Buffer(), 16, 16))
{
CreateRecBufferResource(dx11Color.Dx12Resource, Dx12on11Device, &_recBufferDecode);
ResourceBarrier(Dx12CommandList, _recBufferDecode, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
if (RecDecode(Dx12on11Device, Dx12CommandList, dx11Color.Dx12Resource, _recBufferDecode))
params.pColorTexture = _recBufferDecode;
else
params.pColorTexture = dx11Color.Dx12Resource;
params.pColorTexture = ColorDecode->Buffer();
}
else
{
params.pColorTexture = dx11Color.Dx12Resource;
}
_hasColor = params.pColorTexture != nullptr;
params.pVelocityTexture = dx11Mv.Dx12Resource;
_hasMV = params.pVelocityTexture != nullptr;
if (Config::Instance()->CasEnabled.value_or(true) && casSharpness > 0.0f)
if (Config::Instance()->CasEnabled.value_or(true) && sharpness > 0.0f)
{
if (casBuffer == nullptr && !CreateCasBufferResource(dx11Out.Dx12Resource, Dx12on11Device))
if (CAS->Buffer() == nullptr && !CAS->CreateBufferResource(Dx12on11Device, dx11Out.Dx12Resource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
{
spdlog::error("XeSSFeatureDx12::Evaluate Can't create cas buffer!");
@@ -119,26 +133,17 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
return false;
}
params.pOutputTexture = casBuffer;
params.pOutputTexture = CAS->Buffer();
}
else
{
if (Config::Instance()->ColorSpaceFix.value_or(false))
{
if (CreateRecBufferResource(dx11Out.Dx12Resource, Dx12on11Device, &_recBufferEncode))
{
ResourceBarrier(Dx12CommandList, dx11Out.Dx12Resource, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
params.pOutputTexture = _recBufferEncode;
}
else
params.pOutputTexture = dx11Out.Dx12Resource;
}
if (Config::Instance()->ColorSpaceFix.value_or(false) && OutputEncode->CreateBufferResource(Dx12on11Device, dx11Out.Dx12Resource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
params.pOutputTexture = OutputEncode->Buffer();
else
params.pOutputTexture = dx11Out.Dx12Resource;
}
_hasOutput = params.pOutputTexture != nullptr;
params.pDepthTexture = dx11Depth.Dx12Resource;
_hasDepth = params.pDepthTexture != nullptr;
params.pExposureScaleTexture = dx11Exp.Dx12Resource;
@@ -182,14 +187,13 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
}
//apply cas
if (Config::Instance()->CasEnabled.value_or(true) && casSharpness > 0.0f)
if (Config::Instance()->CasEnabled.value_or(true) && sharpness > 0.0f)
{
if (Config::Instance()->ColorSpaceFix.value_or(false))
{
CreateRecBufferResource(casBuffer, Dx12on11Device, &_recBufferEncode);
ResourceBarrier(Dx12CommandList, _recBufferEncode, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
ResourceBarrier(Dx12CommandList, params.pOutputTexture, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
if (!CasDispatch(Dx12CommandList, InParameters, casBuffer, _recBufferEncode))
if (Config::Instance()->ColorSpaceFix.value_or(false) && OutputEncode->CreateBufferResource(Dx12on11Device, params.pOutputTexture, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
{
if (!CAS->Dispatch(Dx12CommandList, sharpness, params.pOutputTexture, OutputEncode->Buffer()))
{
Config::Instance()->CasEnabled = false;
@@ -205,7 +209,7 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
}
else
{
if (!CasDispatch(Dx12CommandList, InParameters, casBuffer, dx11Out.Dx12Resource))
if (!CAS->Dispatch(Dx12CommandList, sharpness, CAS->Buffer(), dx11Out.Dx12Resource))
{
Config::Instance()->CasEnabled = false;
@@ -221,18 +225,22 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
}
}
if (OutputEncode->Buffer() && Config::Instance()->ColorSpaceFix.value_or(false))
{
OutputEncode->SetBufferState(Dx12CommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
OutputEncode->Dispatch(Dx12on11Device, Dx12CommandList, OutputEncode->Buffer(), dx11Out.Dx12Resource, 16, 16);
#if _DEBUG
D3DX11SaveTextureToFile(InDeviceContext, dx11Out.SharedTexture, D3DX11_IFF_JPG, L"D:\\aaaa.jpg");
#endif // _DEBUG
}
// Execute dx12 commands to process xess
Dx12CommandList->Close();
ID3D12CommandList* ppCommandLists[] = { Dx12CommandList };
Dx12CommandQueue->ExecuteCommandLists(1, ppCommandLists);
if (Config::Instance()->ColorSpaceFix.value_or(false))
{
ResourceBarrier(Dx12CommandList, _recBufferEncode, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
ResourceBarrier(Dx12CommandList, dx11Out.Dx12Resource, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
RecEncode(Dx12on11Device, Dx12CommandList, _recBufferEncode, dx11Out.Dx12Resource);
}
if (!CopyBackOutput())
{
spdlog::error("XeSSFeatureDx11::Evaluate Can't copy output texture back!");
@@ -254,7 +262,6 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK
else
Imgui = std::make_unique<Imgui_Dx11>(GetForegroundWindow(), Device);
Dx12CommandAllocator->Reset();
Dx12CommandList->Reset(Dx12CommandAllocator, nullptr);
+24 -27
View File
@@ -41,6 +41,7 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
InParameters->Get(NVSDK_NGX_Parameter_Reset, &params.resetHistory);
GetRenderResolution(InParameters, &params.inputWidth, &params.inputHeight);
auto sharpness = GetSharpness(InParameters);
spdlog::debug("XeSSFeatureDx12::Evaluate Input Resolution: {0}x{1}", params.inputWidth, params.inputHeight);
@@ -48,6 +49,7 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
if (InParameters->Get(NVSDK_NGX_Parameter_Color, &paramColor) != NVSDK_NGX_Result_Success)
InParameters->Get(NVSDK_NGX_Parameter_Color, (void**)&paramColor);
if (paramColor)
{
spdlog::debug("XeSSFeatureDx12::Evaluate Color exist..");
@@ -66,17 +68,15 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
}
if (Config::Instance()->ColorSpaceFix.value_or(false) &&
CreateRecBufferResource(paramColor, Device, &_recBufferDecode) &&
RecDecode(Device, InCommandList, paramColor, _recBufferDecode))
ColorDecode->CreateBufferResource(Device, paramColor, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE) &&
ColorDecode->Dispatch(Device, InCommandList, paramColor, ColorDecode->Buffer(), 16, 16))
{
ResourceBarrier(InCommandList, _recBufferDecode,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
params.pColorTexture = _recBufferDecode;
params.pColorTexture = ColorDecode->Buffer();
}
else
{
params.pColorTexture = paramColor;
}
}
else
{
@@ -115,23 +115,20 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
(D3D12_RESOURCE_STATES)Config::Instance()->OutputResourceBarrier.value(),
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
if (Config::Instance()->CasEnabled.value_or(true) && casSharpness > 0.0f)
if (Config::Instance()->CasEnabled.value_or(true) && sharpness > 0.0f)
{
if (casBuffer == nullptr && !CreateCasBufferResource(paramOutput, Device))
if (CAS->Buffer() == nullptr && !CAS->CreateBufferResource(Device, paramOutput, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
{
spdlog::error("XeSSFeatureDx12::Evaluate Can't create cas buffer!");
return false;
}
params.pOutputTexture = casBuffer;
params.pOutputTexture = CAS->Buffer();
}
else
{
if (Config::Instance()->ColorSpaceFix.value_or(false))
{
CreateRecBufferResource(paramOutput, Device, &_recBufferEncode);
params.pOutputTexture = _recBufferEncode;
}
if (Config::Instance()->ColorSpaceFix.value_or(false) && OutputEncode->CreateBufferResource(Device, paramOutput, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
params.pOutputTexture = OutputEncode->Buffer();
else
params.pOutputTexture = paramOutput;
}
@@ -232,11 +229,13 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
}
//apply cas
if (Config::Instance()->CasEnabled.value_or(true) && casSharpness > 0.0f)
if (Config::Instance()->CasEnabled.value_or(true) && sharpness > 0.0f)
{
if (Config::Instance()->ColorSpaceFix.value_or(false))
ResourceBarrier(InCommandList, params.pOutputTexture, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
if (Config::Instance()->ColorSpaceFix.value_or(false) && OutputEncode->CreateBufferResource(Device, params.pOutputTexture, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
{
if (!CreateRecBufferResource(casBuffer, Device, &_recBufferEncode) || !CasDispatch(InCommandList, InParameters, casBuffer, _recBufferEncode))
if (!CAS->Dispatch(InCommandList, sharpness, params.pOutputTexture, OutputEncode->Buffer()))
{
Config::Instance()->CasEnabled = false;
return true;
@@ -244,7 +243,7 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
}
else
{
if (!CasDispatch(InCommandList, InParameters, casBuffer, paramOutput))
if (!CAS->Dispatch(InCommandList, sharpness, params.pOutputTexture, paramOutput))
{
Config::Instance()->CasEnabled = false;
return true;
@@ -259,8 +258,8 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
Imgui.reset();
else
{
if (Config::Instance()->ColorSpaceFix.value_or(false))
Imgui->Render(InCommandList, _recBufferEncode);
if (OutputEncode->Buffer() != nullptr && Config::Instance()->ColorSpaceFix.value_or(false))
Imgui->Render(InCommandList, OutputEncode->Buffer());
else
Imgui->Render(InCommandList, paramOutput);
}
@@ -268,10 +267,10 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
else
Imgui = std::make_unique<Imgui_Dx12>(GetForegroundWindow(), Device);
if (Config::Instance()->ColorSpaceFix.value_or(false))
if (OutputEncode->Buffer() && Config::Instance()->ColorSpaceFix.value_or(false))
{
ResourceBarrier(InCommandList, _recBufferEncode, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
RecEncode(Device, InCommandList, _recBufferEncode, paramOutput);
OutputEncode->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
OutputEncode->Dispatch(Device, InCommandList, OutputEncode->Buffer(), paramOutput, 16, 16);
}
// restore resource states
@@ -308,6 +307,4 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
return true;
}
XeSSFeatureDx12::~XeSSFeatureDx12()
{
}
XeSSFeatureDx12::~XeSSFeatureDx12() = default;
+1 -1
View File
@@ -10,7 +10,7 @@ private:
protected:
public:
XeSSFeatureDx12(unsigned int InHandleId, const NVSDK_NGX_Parameter* InParameters) : XeSSFeature(InHandleId, InParameters), IFeature_Dx12(InHandleId, InParameters), IFeature(InHandleId, InParameters)
XeSSFeatureDx12(unsigned int InHandleId, const NVSDK_NGX_Parameter* InParameters) : IFeature(InHandleId, InParameters), IFeature_Dx12(InHandleId, InParameters), XeSSFeature(InHandleId, InParameters)
{
}
+297
View File
@@ -0,0 +1,297 @@
#include "CAS_Dx12.h"
inline static std::string ResultToString(FfxCas::FfxErrorCode result)
{
switch (result)
{
case FfxCas::FFX_OK: return "The operation completed successfully.";
case FfxCas::FFX_ERROR_INVALID_POINTER: return "The operation failed due to an invalid pointer.";
case FfxCas::FFX_ERROR_INVALID_ALIGNMENT: return "The operation failed due to an invalid alignment.";
case FfxCas::FFX_ERROR_INVALID_SIZE: return "The operation failed due to an invalid size.";
case FfxCas::FFX_EOF: return "The end of the file was encountered.";
case FfxCas::FFX_ERROR_INVALID_PATH: return "The operation failed because the specified path was invalid.";
case FfxCas::FFX_ERROR_EOF: return "The operation failed because end of file was reached.";
case FfxCas::FFX_ERROR_MALFORMED_DATA: return "The operation failed because of some malformed data.";
case FfxCas::FFX_ERROR_OUT_OF_MEMORY: return "The operation failed because it ran out memory.";
case FfxCas::FFX_ERROR_INCOMPLETE_INTERFACE: return "The operation failed because the interface was not fully configured.";
case FfxCas::FFX_ERROR_INVALID_ENUM: return "The operation failed because of an invalid enumeration value.";
case FfxCas::FFX_ERROR_INVALID_ARGUMENT: return "The operation failed because an argument was invalid.";
case FfxCas::FFX_ERROR_OUT_OF_RANGE: return "The operation failed because a value was out of range.";
case FfxCas::FFX_ERROR_NULL_DEVICE: return "The operation failed because a device was null.";
case FfxCas::FFX_ERROR_BACKEND_API_ERROR: return "The operation failed because the backend API returned an error code.";
case FfxCas::FFX_ERROR_INSUFFICIENT_MEMORY: return "The operation failed because there was not enough memory.";
default: return "Unknown";
}
}
inline static void FfxCasLogCallback(const char* message)
{
spdlog::debug("XeSSFeature::LogCallback FSR Runtime: {0}", message);
}
inline static FfxCas::FfxSurfaceFormat ffxGetSurfaceFormatDX12(DXGI_FORMAT format)
{
switch (format) {
case(DXGI_FORMAT_R32G32B32A32_TYPELESS):
return FfxCas::FFX_SURFACE_FORMAT_R32G32B32A32_TYPELESS;
case(DXGI_FORMAT_R32G32B32A32_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R32G32B32A32_FLOAT;
case DXGI_FORMAT_R32G32B32A32_UINT:
return FfxCas::FFX_SURFACE_FORMAT_R32G32B32A32_UINT;
case DXGI_FORMAT_R16G16B16A16_TYPELESS:
case(DXGI_FORMAT_R16G16B16A16_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT;
case DXGI_FORMAT_R32G32_TYPELESS:
case DXGI_FORMAT_R32G32_FLOAT:
return FfxCas::FFX_SURFACE_FORMAT_R32G32_FLOAT;
case DXGI_FORMAT_R32G8X24_TYPELESS:
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
return FfxCas::FFX_SURFACE_FORMAT_R32_FLOAT;
case DXGI_FORMAT_R24G8_TYPELESS:
case DXGI_FORMAT_D24_UNORM_S8_UINT:
case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
return FfxCas::FFX_SURFACE_FORMAT_R32_UINT;
case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
return FfxCas::FFX_SURFACE_FORMAT_R8_UINT;
case (DXGI_FORMAT_R11G11B10_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R11G11B10_FLOAT;
case (DXGI_FORMAT_R8G8B8A8_TYPELESS):
return FfxCas::FFX_SURFACE_FORMAT_R8G8B8A8_TYPELESS;
case (DXGI_FORMAT_R8G8B8A8_UNORM):
return FfxCas::FFX_SURFACE_FORMAT_R8G8B8A8_UNORM;
case (DXGI_FORMAT_R8G8B8A8_UNORM_SRGB):
return FfxCas::FFX_SURFACE_FORMAT_R8G8B8A8_SRGB;
case DXGI_FORMAT_R8G8B8A8_SNORM:
return FfxCas::FFX_SURFACE_FORMAT_R8G8B8A8_SNORM;
case DXGI_FORMAT_R16G16_TYPELESS:
case (DXGI_FORMAT_R16G16_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R16G16_FLOAT;
case (DXGI_FORMAT_R16G16_UINT):
return FfxCas::FFX_SURFACE_FORMAT_R16G16_UINT;
case DXGI_FORMAT_R32_TYPELESS:
case(DXGI_FORMAT_D32_FLOAT):
case(DXGI_FORMAT_R32_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R32_FLOAT;
case DXGI_FORMAT_R8G8_TYPELESS:
return FfxCas::FFX_SURFACE_FORMAT_R8G8_UNORM;
case DXGI_FORMAT_R16_TYPELESS:
case (DXGI_FORMAT_R16_FLOAT):
return FfxCas::FFX_SURFACE_FORMAT_R16_FLOAT;
case (DXGI_FORMAT_R16_UINT):
return FfxCas::FFX_SURFACE_FORMAT_R16_UINT;
case DXGI_FORMAT_D16_UNORM:
case (DXGI_FORMAT_R16_UNORM):
return FfxCas::FFX_SURFACE_FORMAT_R16_UNORM;
case (DXGI_FORMAT_R16_SNORM):
return FfxCas::FFX_SURFACE_FORMAT_R16_SNORM;
//case DXGI_FORMAT_R16_SINT:
case DXGI_FORMAT_R8_TYPELESS:
case DXGI_FORMAT_R8_UNORM:
case DXGI_FORMAT_A8_UNORM:
return FfxCas::FFX_SURFACE_FORMAT_R8_UNORM;
case(DXGI_FORMAT_UNKNOWN):
return FfxCas::FFX_SURFACE_FORMAT_UNKNOWN;
default:
return FfxCas::FFX_SURFACE_FORMAT_UNKNOWN;
}
}
inline static bool IsDepthDX12(DXGI_FORMAT format)
{
return (format == DXGI_FORMAT_D16_UNORM) ||
(format == DXGI_FORMAT_D32_FLOAT) ||
(format == DXGI_FORMAT_D24_UNORM_S8_UINT) ||
(format == DXGI_FORMAT_D32_FLOAT_S8X24_UINT);
}
inline static FfxCas::FfxResourceDescription GetFfxResourceDescriptionDX12(ID3D12Resource* pResource)
{
FfxCas::FfxResourceDescription resourceDescription = {};
// This is valid
if (!pResource)
return resourceDescription;
if (pResource)
{
D3D12_RESOURCE_DESC desc = pResource->GetDesc();
// Set flags properly for resource registration
resourceDescription.flags = FfxCas::FFX_RESOURCE_FLAGS_NONE;
resourceDescription.usage = IsDepthDX12(desc.Format) ? FfxCas::FFX_RESOURCE_USAGE_DEPTHTARGET : FfxCas::FFX_RESOURCE_USAGE_READ_ONLY;
if ((desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS) == D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
resourceDescription.usage = (FfxCas::FfxResourceUsage)(resourceDescription.usage | FfxCas::FFX_RESOURCE_USAGE_UAV);
resourceDescription.width = desc.Width;
resourceDescription.height = desc.Height;
resourceDescription.depth = desc.DepthOrArraySize;
resourceDescription.mipCount = desc.MipLevels;
resourceDescription.format = ffxGetSurfaceFormatDX12(desc.Format);
resourceDescription.type = FfxCas::FFX_RESOURCE_TYPE_TEXTURE2D;
}
return resourceDescription;
}
bool CAS_Dx12::CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InSource, D3D12_RESOURCE_STATES InState)
{
if (InDevice == nullptr || InSource == nullptr)
return false;
D3D12_RESOURCE_DESC texDesc = InSource->GetDesc();
if (_buffer != nullptr)
{
auto bufDesc = _buffer->GetDesc();
if (bufDesc.Width != texDesc.Width || bufDesc.Height != texDesc.Height || bufDesc.Format != texDesc.Format)
{
_buffer->Release();
_buffer = nullptr;
}
else
return true;
}
spdlog::debug("CAS_Dx12::CreateCasBufferResource Start!");
D3D12_HEAP_PROPERTIES heapProperties;
D3D12_HEAP_FLAGS heapFlags;
HRESULT hr = InSource->GetHeapProperties(&heapProperties, &heapFlags);
if (hr != S_OK)
{
spdlog::error("CAS_Dx12::CreateBufferResource GetHeapProperties result: {0:x}", hr);
return false;
}
texDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS;
hr = InDevice->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &texDesc, InState, nullptr, IID_PPV_ARGS(&_buffer));
if (hr != S_OK)
{
spdlog::error("CAS_Dx12::CreateBufferResource CreateCommittedResource result: {0:x}", hr);
return false;
}
_bufferState = InState;
return true;
}
bool CAS_Dx12::Dispatch(ID3D12CommandList* InCommandList, float InSharpness, ID3D12Resource* InResource, ID3D12Resource* OutResource)
{
if (!_init || InCommandList == nullptr || InResource == nullptr || OutResource == nullptr || InSharpness <= 0.0f)
return false;
spdlog::debug("CAS_Dx12::CasDispatch Start!");
FfxCas::FfxCasDispatchDescription dispatchParameters = {};
dispatchParameters.commandList = FfxCas::ffxGetCommandListDX12Cas(InCommandList);
dispatchParameters.renderSize = { _width, _height };
dispatchParameters.sharpness = InSharpness;
dispatchParameters.color = FfxCas::ffxGetResourceDX12Cas(InResource, GetFfxResourceDescriptionDX12(InResource), nullptr, FfxCas::FFX_RESOURCE_STATE_PIXEL_COMPUTE_READ);
dispatchParameters.output = FfxCas::ffxGetResourceDX12Cas(OutResource, GetFfxResourceDescriptionDX12(OutResource), nullptr, FfxCas::FFX_RESOURCE_STATE_UNORDERED_ACCESS);
if (auto errorCode = FfxCas::ffxCasContextDispatch(&_context, &dispatchParameters); errorCode != FfxCas::FFX_OK)
{
spdlog::error("CAS_Dx12::CasDispatch ffxCasContextDispatch error: {0}", ResultToString(errorCode));
return false;
}
return true;
}
void CAS_Dx12::SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState)
{
D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Transition.pResource = _buffer;
barrier.Transition.StateBefore = _bufferState;
barrier.Transition.StateAfter = InState;
barrier.Transition.Subresource = 0;
InCommandList->ResourceBarrier(1, &barrier);
_bufferState = InState;
}
CAS_Dx12::CAS_Dx12(ID3D12Device* InDevice, uint32_t InWidth, uint32_t InHeight, int colorSpace = 0)
{
spdlog::debug("CAS_Dx12::CAS_Dx12 Start!");
const size_t scratchBufferSize = FfxCas::ffxGetScratchMemorySizeDX12Cas(FFX_CAS_CONTEXT_COUNT);
void* casScratchBuffer = calloc(scratchBufferSize, 1);
auto errorCode = FfxCas::ffxGetInterfaceDX12Cas(&_contextDesc.backendInterface, InDevice, casScratchBuffer, scratchBufferSize, FFX_CAS_CONTEXT_COUNT);
if (errorCode != FfxCas::FFX_OK)
{
spdlog::error("CAS_Dx12::CAS_Dx12 ffxGetInterfaceDX12 error: {0}", ResultToString(errorCode));
_init = false;
return;
}
_contextDesc.flags |= FfxCas::FFX_CAS_SHARPEN_ONLY;
auto casCSC = colorSpace;
if (casCSC < 0 || casCSC > 4)
casCSC = 0;
_width = InWidth;
_height = InHeight;
_contextDesc.colorSpaceConversion = static_cast<FfxCas::FfxCasColorSpaceConversion>(casCSC);
_contextDesc.maxRenderSize.width = InWidth + 16; // Sometimes when using DLAA mode
_contextDesc.maxRenderSize.height = InHeight + 16; // internal resolution is higher then display resolution
_contextDesc.displaySize.width = InWidth;
_contextDesc.displaySize.height = InHeight;
errorCode = FfxCas::ffxCasContextCreate(&_context, &_contextDesc);
if (errorCode != FfxCas::FFX_OK)
{
spdlog::error("CAS_Dx12::CAS_Dx12 ffxCasContextCreate error: {0}", ResultToString(errorCode));
_init = false;
return;
}
FfxCas::ffxAssertSetPrintingCallback(FfxCasLogCallback);
_init = true;
}
CAS_Dx12::~CAS_Dx12()
{
if (!_init)
return;
FfxCas::ffxCasContextDestroy(&_context);
free(_contextDesc.backendInterface.scratchBuffer);
if (_buffer != nullptr)
{
_buffer->Release();
_buffer = nullptr;
}
}
+36
View File
@@ -0,0 +1,36 @@
#pragma once
#include "../pch.h"
#include "include/ffx_cas.h"
#include "include/backends/dx12/ffx_dx12.h"
#include <d3d12.h>
#include <string>
class CAS_Dx12
{
private:
bool _init = false;
uint32_t _width = 0;
uint32_t _height = 0;
FfxCas::FfxCasContext _context{};
FfxCas::FfxCasContextDescription _contextDesc{};
ID3D12Resource* _buffer = nullptr;
D3D12_RESOURCE_STATES _bufferState = D3D12_RESOURCE_STATE_COMMON;
public:
bool CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InSource, D3D12_RESOURCE_STATES InState);
void SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState);
bool Dispatch(ID3D12CommandList* InCommandList, float InSharpness, ID3D12Resource* InResource, ID3D12Resource* OutResource);
ID3D12Resource* Buffer() { return _buffer; }
bool IsInit() const { return _init; }
CAS_Dx12(ID3D12Device* InDevice, uint32_t InWidth, uint32_t InHeight, int colorSpace);
~CAS_Dx12();
};
+328
View File
@@ -0,0 +1,328 @@
#include "CS_Dx12.h"
ID3DBlob* CompileShader(const char* shaderCode, const char* entryPoint, const char* target)
{
ID3DBlob* shaderBlob = nullptr;
ID3DBlob* errorBlob = nullptr;
HRESULT hr = D3DCompile(shaderCode, strlen(shaderCode), nullptr, nullptr, nullptr, entryPoint, target, 0, 0, &shaderBlob, &errorBlob);
if (FAILED(hr))
{
if (errorBlob)
{
OutputDebugStringA((char*)errorBlob->GetBufferPointer());
errorBlob->Release();
}
if (shaderBlob)
shaderBlob->Release();
return nullptr;
}
if (errorBlob)
errorBlob->Release();
return shaderBlob;
}
bool CreateComputeShader(ID3D12Device* device, ID3D12RootSignature* rootSignature, ID3D12PipelineState** pipelineState, ID3DBlob* shaderBlob)
{
D3D12_COMPUTE_PIPELINE_STATE_DESC psoDesc = {};
psoDesc.pRootSignature = rootSignature;
psoDesc.CS = CD3DX12_SHADER_BYTECODE(const_cast<void*>(shaderBlob->GetBufferPointer()), shaderBlob->GetBufferSize());
psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
HRESULT hr = device->CreateComputePipelineState(&psoDesc, IID_PPV_ARGS(pipelineState));
if (FAILED(hr))
{
// Handle error
return false;
}
return true;
}
bool CS_Dx12::CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InSource, D3D12_RESOURCE_STATES InState)
{
if (InDevice == nullptr || InSource == nullptr)
return false;
D3D12_RESOURCE_DESC texDesc = InSource->GetDesc();
if (_buffer != nullptr)
{
auto bufDesc = _buffer->GetDesc();
if (bufDesc.Width != texDesc.Width || bufDesc.Height != texDesc.Height || bufDesc.Format != texDesc.Format)
{
_buffer->Release();
_buffer = nullptr;
}
else
return true;
}
spdlog::debug("CS_Dx12::CreateBufferResource Start!");
D3D12_HEAP_PROPERTIES heapProperties;
D3D12_HEAP_FLAGS heapFlags;
HRESULT hr = InSource->GetHeapProperties(&heapProperties, &heapFlags);
if (hr != S_OK)
{
spdlog::error("CS_Dx12::CreateBufferResource GetHeapProperties result: {0:x}", hr);
return false;
}
texDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS;
hr = InDevice->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &texDesc, InState, nullptr, IID_PPV_ARGS(&_buffer));
if (hr != S_OK)
{
spdlog::error("CS_Dx12::CreateBufferResource CreateCommittedResource result: {0:x}", hr);
return false;
}
_bufferState = InState;
return true;
}
void CS_Dx12::SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState)
{
D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Transition.pResource = _buffer;
barrier.Transition.StateBefore = _bufferState;
barrier.Transition.StateAfter = InState;
barrier.Transition.Subresource = 0;
InCommandList->ResourceBarrier(1, &barrier);
_bufferState = InState;
}
bool CS_Dx12::Dispatch(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource, uint32_t InNumThreadsX, uint32_t InNumThreadsY)
{
if (!_init || InDevice == nullptr || InCmdList == nullptr || InResource == nullptr || OutResource == nullptr || InNumThreadsX == 0 || InNumThreadsY == 0)
return false;
ID3D12DescriptorHeap* _srvHeap = nullptr;
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
heapDesc.NumDescriptors = 2; // One for SRV and one for UAV
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
auto hr = InDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&_srvHeap));
if (FAILED(hr))
{
return false;
}
auto srvHandle = _srvHeap->GetCPUDescriptorHandleForHeapStart();
auto uavHandle = srvHandle;
uavHandle.ptr += InDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
D3D12_GPU_DESCRIPTOR_HANDLE gpuSrvHandle = _srvHeap->GetGPUDescriptorHandleForHeapStart();
D3D12_GPU_DESCRIPTOR_HANDLE gpuUavHandle = gpuSrvHandle;
gpuUavHandle.ptr += InDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
// Create SRV for Input Texture
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srvDesc.Format = InResource->GetDesc().Format;
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = 1;
InDevice->CreateShaderResourceView(InResource, &srvDesc, srvHandle);
// Create UAV for Output Texture
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.Format = OutResource->GetDesc().Format;
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
uavDesc.Texture2D.MipSlice = 0;
InDevice->CreateUnorderedAccessView(OutResource, nullptr, &uavDesc, uavHandle);
ID3D12DescriptorHeap* heaps[] = { _srvHeap };
InCmdList->SetDescriptorHeaps(_countof(heaps), heaps);
InCmdList->SetComputeRootSignature(_rootSignature);
InCmdList->SetPipelineState(_pipelineState);
InCmdList->SetComputeRootDescriptorTable(0, gpuSrvHandle);
InCmdList->SetComputeRootDescriptorTable(1, gpuUavHandle);
UINT dispatchWidth = (InResource->GetDesc().Width + InNumThreadsX - 1) / InNumThreadsX;
UINT dispatchHeight = (InResource->GetDesc().Height + InNumThreadsY - 1) / InNumThreadsY;
InCmdList->Dispatch(dispatchWidth, dispatchHeight, 1);
/*ID3D12Fence* d3d12Fence = nullptr;
do
{
if (InDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d12Fence)) != S_OK)
break;
d3d12Fence->Signal(999);
HANDLE fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (fenceEvent != NULL && d3d12Fence->SetEventOnCompletion(999, fenceEvent) == S_OK)
{
WaitForSingleObject(fenceEvent, INFINITE);
CloseHandle(fenceEvent);
}
} while (false);
if (d3d12Fence != nullptr)
{
d3d12Fence->Release();
d3d12Fence = nullptr;
}*/
_srvHeap->Release();
_srvHeap = nullptr;
return true;
}
CS_Dx12::CS_Dx12(ID3D12Device* InDevice, const char* InShaderCode, const char* InEntry, const char* InTarget)
{
// Describe and create the root signature
// ---------------------------------------------------
D3D12_DESCRIPTOR_RANGE descriptorRange[2];
// SRV Range (Input Texture)
descriptorRange[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
descriptorRange[0].NumDescriptors = 1;
descriptorRange[0].BaseShaderRegister = 0; // Assuming t0 register in HLSL for SRV
descriptorRange[0].RegisterSpace = 0;
descriptorRange[0].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
// UAV Range (Output Texture)
descriptorRange[1].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
descriptorRange[1].NumDescriptors = 1;
descriptorRange[1].BaseShaderRegister = 0; // Assuming u0 register in HLSL for UAV
descriptorRange[1].RegisterSpace = 0;
descriptorRange[1].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
// Define the root parameter (descriptor table)
// ---------------------------------------------------
D3D12_ROOT_PARAMETER rootParameters[2];
// Root Parameter for SRV
rootParameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParameters[0].DescriptorTable.NumDescriptorRanges = 1; // One range (SRV)
rootParameters[0].DescriptorTable.pDescriptorRanges = &descriptorRange[0]; // Point to the SRV range
rootParameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
// Root Parameter for UAV
rootParameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParameters[1].DescriptorTable.NumDescriptorRanges = 1; // One range (UAV)
rootParameters[1].DescriptorTable.pDescriptorRanges = &descriptorRange[1]; // Point to the UAV range
rootParameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
// A root signature is an array of root parameters
// ---------------------------------------------------
D3D12_ROOT_SIGNATURE_DESC rootSigDesc;
rootSigDesc.NumParameters = 2; // Two root parameters
rootSigDesc.pParameters = rootParameters;
rootSigDesc.NumStaticSamplers = 0;
rootSigDesc.pStaticSamplers = nullptr;
rootSigDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE;
ID3DBlob* errorBlob;
ID3DBlob* signatureBlob;
do
{
auto hr = D3D12SerializeRootSignature(&rootSigDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signatureBlob, &errorBlob);
if (FAILED(hr))
{
break;
}
hr = InDevice->CreateRootSignature(0, signatureBlob->GetBufferPointer(), signatureBlob->GetBufferSize(), IID_PPV_ARGS(&_rootSignature));
if (FAILED(hr))
{
break;
}
} while (false);
if (errorBlob != nullptr)
{
errorBlob->Release();
errorBlob = nullptr;
}
if (signatureBlob != nullptr)
{
signatureBlob->Release();
signatureBlob = nullptr;
}
if (_rootSignature == nullptr)
{
return;
}
// Compile shader blobs
auto _recEncodeShader = CompileShader(InShaderCode, InEntry, InTarget);
if (_recEncodeShader == nullptr)
{
return;
}
// create pso objects
if (!CreateComputeShader(InDevice, _rootSignature, &_pipelineState, _recEncodeShader))
{
return;
}
if (_recEncodeShader != nullptr)
{
_recEncodeShader->Release();
_recEncodeShader = nullptr;
}
_init = _pipelineState != nullptr;
}
CS_Dx12::~CS_Dx12()
{
if (!_init)
return;
if (_rootSignature != nullptr)
{
_rootSignature->Release();
_rootSignature = nullptr;
}
if (_pipelineState != nullptr)
{
_pipelineState->Release();
_pipelineState = nullptr;
}
//if (_srvHeap != nullptr)
//{
// _srvHeap->Release();
// _srvHeap = nullptr;
//}
if (_buffer != nullptr)
{
_buffer->Release();
_buffer = nullptr;
}
}
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include "../pch.h"
#include <d3d12.h>
#include <d3dcompiler.h>
#include "../d3dx/d3dx12.h"
class CS_Dx12
{
private:
bool _init = false;
ID3D12RootSignature* _rootSignature = nullptr;
ID3D12PipelineState* _pipelineState = nullptr;
ID3D12Resource* _buffer = nullptr;
D3D12_RESOURCE_STATES _bufferState = D3D12_RESOURCE_STATE_COMMON;
public:
bool CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InSource, D3D12_RESOURCE_STATES InState);
void SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState);
bool Dispatch(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource, uint32_t InNumThreadsX, uint32_t InNumThreadsY);
ID3D12Resource* Buffer() { return _buffer; }
bool IsInit() const { return _init; }
CS_Dx12(ID3D12Device* InDevice, const char* InShaderCode, const char* InEntry, const char* InTarget);
~CS_Dx12();
};
+74
View File
@@ -0,0 +1,74 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
// File: d3dx11.h
// Content: D3DX11 utility library
//
//////////////////////////////////////////////////////////////////////////////
#ifdef __D3DX11_INTERNAL__
#error Incorrect D3DX11 header used
#endif
#ifndef __D3DX11_H__
#define __D3DX11_H__
// Defines
#include <limits.h>
#include <float.h>
#ifdef ALLOW_THROWING_NEW
#include <new>
#endif
#define D3DX11_DEFAULT ((UINT) -1)
#define D3DX11_FROM_FILE ((UINT) -3)
#define DXGI_FORMAT_FROM_FILE ((DXGI_FORMAT) -3)
#ifndef D3DX11INLINE
#ifdef _MSC_VER
#if (_MSC_VER >= 1200)
#define D3DX11INLINE __forceinline
#else
#define D3DX11INLINE __inline
#endif
#else
#ifdef __cplusplus
#define D3DX11INLINE inline
#else
#define D3DX11INLINE
#endif
#endif
#endif
// Includes
#include "d3d11.h"
#include "d3dx11.h"
#include "d3dx11core.h"
#include "d3dx11tex.h"
#include "d3dx11async.h"
// Errors
#define _FACDD 0x876
#define MAKE_DDHRESULT( code ) MAKE_HRESULT( 1, _FACDD, code )
enum _D3DX11_ERR {
D3DX11_ERR_CANNOT_MODIFY_INDEX_BUFFER = MAKE_DDHRESULT(2900),
D3DX11_ERR_INVALID_MESH = MAKE_DDHRESULT(2901),
D3DX11_ERR_CANNOT_ATTR_SORT = MAKE_DDHRESULT(2902),
D3DX11_ERR_SKINNING_NOT_SUPPORTED = MAKE_DDHRESULT(2903),
D3DX11_ERR_TOO_MANY_INFLUENCES = MAKE_DDHRESULT(2904),
D3DX11_ERR_INVALID_DATA = MAKE_DDHRESULT(2905),
D3DX11_ERR_LOADED_MESH_HAS_NO_DATA = MAKE_DDHRESULT(2906),
D3DX11_ERR_DUPLICATE_NAMED_FRAGMENT = MAKE_DDHRESULT(2907),
D3DX11_ERR_CANNOT_REMOVE_LAST_ITEM = MAKE_DDHRESULT(2908),
};
#endif //__D3DX11_H__
+164
View File
@@ -0,0 +1,164 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: D3DX11Async.h
// Content: D3DX11 Asynchronous Shader loaders / compilers
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __D3DX11ASYNC_H__
#define __D3DX11ASYNC_H__
#include "d3dx11.h"
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
//----------------------------------------------------------------------------
// D3DX11Compile:
// ------------------
// Compiles an effect or shader.
//
// Parameters:
// pSrcFile
// Source file name.
// hSrcModule
// Module handle. if NULL, current module will be used.
// pSrcResource
// Resource name in module.
// pSrcData
// Pointer to source code.
// SrcDataLen
// Size of source code, in bytes.
// pDefines
// Optional NULL-terminated array of preprocessor macro definitions.
// pInclude
// Optional interface pointer to use for handling #include directives.
// If this parameter is NULL, #includes will be honored when compiling
// from file, and will error when compiling from resource or memory.
// pFunctionName
// Name of the entrypoint function where execution should begin.
// pProfile
// Instruction set to be used when generating code. Currently supported
// profiles are "vs_1_1", "vs_2_0", "vs_2_a", "vs_2_sw", "vs_3_0",
// "vs_3_sw", "vs_4_0", "vs_4_1",
// "ps_2_0", "ps_2_a", "ps_2_b", "ps_2_sw", "ps_3_0",
// "ps_3_sw", "ps_4_0", "ps_4_1",
// "gs_4_0", "gs_4_1",
// "tx_1_0",
// "fx_4_0", "fx_4_1"
// Note that this entrypoint does not compile fx_2_0 targets, for that
// you need to use the D3DX9 function.
// Flags1
// See D3D10_SHADER_xxx flags.
// Flags2
// See D3D10_EFFECT_xxx flags.
// ppShader
// Returns a buffer containing the created shader. This buffer contains
// the compiled shader code, as well as any embedded debug and symbol
// table info. (See D3D10GetShaderConstantTable)
// ppErrorMsgs
// Returns a buffer containing a listing of errors and warnings that were
// encountered during the compile. If you are running in a debugger,
// these are the same messages you will see in your debug output.
// pHResult
// Pointer to a memory location to receive the return value upon completion.
// Maybe NULL if not needed.
// If pPump != NULL, pHResult must be a valid memory location until the
// the asynchronous execution completes.
//----------------------------------------------------------------------------
HRESULT WINAPI D3DX11CompileFromFileA(LPCSTR pSrcFile,CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
HRESULT WINAPI D3DX11CompileFromFileW(LPCWSTR pSrcFile, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
#ifdef UNICODE
#define D3DX11CompileFromFile D3DX11CompileFromFileW
#else
#define D3DX11CompileFromFile D3DX11CompileFromFileA
#endif
HRESULT WINAPI D3DX11CompileFromResourceA(HMODULE hSrcModule, LPCSTR pSrcResource, LPCSTR pSrcFileName, CONST D3D10_SHADER_MACRO* pDefines,
LPD3D10INCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
HRESULT WINAPI D3DX11CompileFromResourceW(HMODULE hSrcModule, LPCWSTR pSrcResource, LPCWSTR pSrcFileName, CONST D3D10_SHADER_MACRO* pDefines,
LPD3D10INCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
#ifdef UNICODE
#define D3DX11CompileFromResource D3DX11CompileFromResourceW
#else
#define D3DX11CompileFromResource D3DX11CompileFromResourceA
#endif
HRESULT WINAPI D3DX11CompileFromMemory(LPCSTR pSrcData, SIZE_T SrcDataLen, LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
HRESULT WINAPI D3DX11PreprocessShaderFromFileA(LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines,
LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
HRESULT WINAPI D3DX11PreprocessShaderFromFileW(LPCWSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines,
LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
HRESULT WINAPI D3DX11PreprocessShaderFromMemory(LPCSTR pSrcData, SIZE_T SrcDataSize, LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines,
LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
HRESULT WINAPI D3DX11PreprocessShaderFromResourceA(HMODULE hModule, LPCSTR pResourceName, LPCSTR pSrcFileName, CONST D3D10_SHADER_MACRO* pDefines,
LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
HRESULT WINAPI D3DX11PreprocessShaderFromResourceW(HMODULE hModule, LPCWSTR pResourceName, LPCWSTR pSrcFileName, CONST D3D10_SHADER_MACRO* pDefines,
LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
#ifdef UNICODE
#define D3DX11PreprocessShaderFromFile D3DX11PreprocessShaderFromFileW
#define D3DX11PreprocessShaderFromResource D3DX11PreprocessShaderFromResourceW
#else
#define D3DX11PreprocessShaderFromFile D3DX11PreprocessShaderFromFileA
#define D3DX11PreprocessShaderFromResource D3DX11PreprocessShaderFromResourceA
#endif
//----------------------------------------------------------------------------
// Async processors
//----------------------------------------------------------------------------
HRESULT WINAPI D3DX11CreateAsyncCompilerProcessor(LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2,
ID3D10Blob **ppCompiledShader, ID3D10Blob **ppErrorBuffer, ID3DX11DataProcessor **ppProcessor);
HRESULT WINAPI D3DX11CreateAsyncShaderPreprocessProcessor(LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
ID3D10Blob** ppShaderText, ID3D10Blob **ppErrorBuffer, ID3DX11DataProcessor **ppProcessor);
//----------------------------------------------------------------------------
// D3DX11 Asynchronous texture I/O (advanced mode)
//----------------------------------------------------------------------------
HRESULT WINAPI D3DX11CreateAsyncFileLoaderW(LPCWSTR pFileName, ID3DX11DataLoader **ppDataLoader);
HRESULT WINAPI D3DX11CreateAsyncFileLoaderA(LPCSTR pFileName, ID3DX11DataLoader **ppDataLoader);
HRESULT WINAPI D3DX11CreateAsyncMemoryLoader(LPCVOID pData, SIZE_T cbData, ID3DX11DataLoader **ppDataLoader);
HRESULT WINAPI D3DX11CreateAsyncResourceLoaderW(HMODULE hSrcModule, LPCWSTR pSrcResource, ID3DX11DataLoader **ppDataLoader);
HRESULT WINAPI D3DX11CreateAsyncResourceLoaderA(HMODULE hSrcModule, LPCSTR pSrcResource, ID3DX11DataLoader **ppDataLoader);
#ifdef UNICODE
#define D3DX11CreateAsyncFileLoader D3DX11CreateAsyncFileLoaderW
#define D3DX11CreateAsyncResourceLoader D3DX11CreateAsyncResourceLoaderW
#else
#define D3DX11CreateAsyncFileLoader D3DX11CreateAsyncFileLoaderA
#define D3DX11CreateAsyncResourceLoader D3DX11CreateAsyncResourceLoaderA
#endif
HRESULT WINAPI D3DX11CreateAsyncTextureProcessor(ID3D11Device *pDevice, D3DX11_IMAGE_LOAD_INFO *pLoadInfo, ID3DX11DataProcessor **ppDataProcessor);
HRESULT WINAPI D3DX11CreateAsyncTextureInfoProcessor(D3DX11_IMAGE_INFO *pImageInfo, ID3DX11DataProcessor **ppDataProcessor);
HRESULT WINAPI D3DX11CreateAsyncShaderResourceViewProcessor(ID3D11Device *pDevice, D3DX11_IMAGE_LOAD_INFO *pLoadInfo, ID3DX11DataProcessor **ppDataProcessor);
#ifdef __cplusplus
}
#endif //__cplusplus
#endif //__D3DX11ASYNC_H__
+128
View File
@@ -0,0 +1,128 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
// File: d3dx11core.h
// Content: D3DX11 core types and functions
//
///////////////////////////////////////////////////////////////////////////
#include "d3dx11.h"
#ifndef __D3DX11CORE_H__
#define __D3DX11CORE_H__
// Current name of the DLL shipped in the same SDK as this header.
#define D3DX11_DLL_W L"d3dx11_43.dll"
#define D3DX11_DLL_A "d3dx11_43.dll"
#ifdef UNICODE
#define D3DX11_DLL D3DX11_DLL_W
#else
#define D3DX11_DLL D3DX11_DLL_A
#endif
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
///////////////////////////////////////////////////////////////////////////
// D3DX11_SDK_VERSION:
// -----------------
// This identifier is passed to D3DX11CheckVersion in order to ensure that an
// application was built against the correct header files and lib files.
// This number is incremented whenever a header (or other) change would
// require applications to be rebuilt. If the version doesn't match,
// D3DX11CreateVersion will return FALSE. (The number itself has no meaning.)
///////////////////////////////////////////////////////////////////////////
#define D3DX11_SDK_VERSION 43
#ifdef D3D_DIAG_DLL
BOOL WINAPI D3DX11DebugMute(BOOL Mute);
#endif
HRESULT WINAPI D3DX11CheckVersion(UINT D3DSdkVersion, UINT D3DX11SdkVersion);
#ifdef __cplusplus
}
#endif //__cplusplus
//////////////////////////////////////////////////////////////////////////////
// ID3DX11ThreadPump:
//////////////////////////////////////////////////////////////////////////////
#undef INTERFACE
#define INTERFACE ID3DX11DataLoader
DECLARE_INTERFACE(ID3DX11DataLoader)
{
STDMETHOD(Load)(THIS) PURE;
STDMETHOD(Decompress)(THIS_ void **ppData, SIZE_T *pcBytes) PURE;
STDMETHOD(Destroy)(THIS) PURE;
};
#undef INTERFACE
#define INTERFACE ID3DX11DataProcessor
DECLARE_INTERFACE(ID3DX11DataProcessor)
{
STDMETHOD(Process)(THIS_ void *pData, SIZE_T cBytes) PURE;
STDMETHOD(CreateDeviceObject)(THIS_ void **ppDataObject) PURE;
STDMETHOD(Destroy)(THIS) PURE;
};
// {C93FECFA-6967-478a-ABBC-402D90621FCB}
DEFINE_GUID(IID_ID3DX11ThreadPump,
0xc93fecfa, 0x6967, 0x478a, 0xab, 0xbc, 0x40, 0x2d, 0x90, 0x62, 0x1f, 0xcb);
#undef INTERFACE
#define INTERFACE ID3DX11ThreadPump
DECLARE_INTERFACE_(ID3DX11ThreadPump, IUnknown)
{
// IUnknown
STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
STDMETHOD_(ULONG, AddRef)(THIS) PURE;
STDMETHOD_(ULONG, Release)(THIS) PURE;
// ID3DX11ThreadPump
STDMETHOD(AddWorkItem)(THIS_ ID3DX11DataLoader *pDataLoader, ID3DX11DataProcessor *pDataProcessor, HRESULT *pHResult, void **ppDeviceObject) PURE;
STDMETHOD_(UINT, GetWorkItemCount)(THIS) PURE;
STDMETHOD(WaitForAllItems)(THIS) PURE;
STDMETHOD(ProcessDeviceWorkItems)(THIS_ UINT iWorkItemCount);
STDMETHOD(PurgeAllItems)(THIS) PURE;
STDMETHOD(GetQueueStatus)(THIS_ UINT *pIoQueue, UINT *pProcessQueue, UINT *pDeviceQueue) PURE;
};
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
HRESULT WINAPI D3DX11CreateThreadPump(UINT cIoThreads, UINT cProcThreads, ID3DX11ThreadPump **ppThreadPump);
HRESULT WINAPI D3DX11UnsetAllDeviceObjects(ID3D11DeviceContext *pContext);
#ifdef __cplusplus
}
#endif //__cplusplus
///////////////////////////////////////////////////////////////////////////
#define _FACD3D 0x876
#define MAKE_D3DHRESULT( code ) MAKE_HRESULT( 1, _FACD3D, code )
#define MAKE_D3DSTATUS( code ) MAKE_HRESULT( 0, _FACD3D, code )
#define D3DERR_INVALIDCALL MAKE_D3DHRESULT(2156)
#define D3DERR_WASSTILLDRAWING MAKE_D3DHRESULT(540)
#endif //__D3DX11CORE_H__
+772
View File
@@ -0,0 +1,772 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
// File: d3dx11tex.h
// Content: D3DX11 texturing APIs
//
//////////////////////////////////////////////////////////////////////////////
#include "d3dx11.h"
#ifndef __D3DX11TEX_H__
#define __D3DX11TEX_H__
//----------------------------------------------------------------------------
// D3DX11_FILTER flags:
// ------------------
//
// A valid filter must contain one of these values:
//
// D3DX11_FILTER_NONE
// No scaling or filtering will take place. Pixels outside the bounds
// of the source image are assumed to be transparent black.
// D3DX11_FILTER_POINT
// Each destination pixel is computed by sampling the nearest pixel
// from the source image.
// D3DX11_FILTER_LINEAR
// Each destination pixel is computed by linearly interpolating between
// the nearest pixels in the source image. This filter works best
// when the scale on each axis is less than 2.
// D3DX11_FILTER_TRIANGLE
// Every pixel in the source image contributes equally to the
// destination image. This is the slowest of all the filters.
// D3DX11_FILTER_BOX
// Each pixel is computed by averaging a 2x2(x2) box pixels from
// the source image. Only works when the dimensions of the
// destination are half those of the source. (as with mip maps)
//
// And can be OR'd with any of these optional flags:
//
// D3DX11_FILTER_MIRROR_U
// Indicates that pixels off the edge of the texture on the U-axis
// should be mirrored, not wraped.
// D3DX11_FILTER_MIRROR_V
// Indicates that pixels off the edge of the texture on the V-axis
// should be mirrored, not wraped.
// D3DX11_FILTER_MIRROR_W
// Indicates that pixels off the edge of the texture on the W-axis
// should be mirrored, not wraped.
// D3DX11_FILTER_MIRROR
// Same as specifying D3DX11_FILTER_MIRROR_U | D3DX11_FILTER_MIRROR_V |
// D3DX11_FILTER_MIRROR_V
// D3DX11_FILTER_DITHER
// Dithers the resulting image using a 4x4 order dither pattern.
// D3DX11_FILTER_SRGB_IN
// Denotes that the input data is in sRGB (gamma 2.2) colorspace.
// D3DX11_FILTER_SRGB_OUT
// Denotes that the output data is in sRGB (gamma 2.2) colorspace.
// D3DX11_FILTER_SRGB
// Same as specifying D3DX11_FILTER_SRGB_IN | D3DX11_FILTER_SRGB_OUT
//
//----------------------------------------------------------------------------
typedef enum D3DX11_FILTER_FLAG
{
D3DX11_FILTER_NONE = (1 << 0),
D3DX11_FILTER_POINT = (2 << 0),
D3DX11_FILTER_LINEAR = (3 << 0),
D3DX11_FILTER_TRIANGLE = (4 << 0),
D3DX11_FILTER_BOX = (5 << 0),
D3DX11_FILTER_MIRROR_U = (1 << 16),
D3DX11_FILTER_MIRROR_V = (2 << 16),
D3DX11_FILTER_MIRROR_W = (4 << 16),
D3DX11_FILTER_MIRROR = (7 << 16),
D3DX11_FILTER_DITHER = (1 << 19),
D3DX11_FILTER_DITHER_DIFFUSION= (2 << 19),
D3DX11_FILTER_SRGB_IN = (1 << 21),
D3DX11_FILTER_SRGB_OUT = (2 << 21),
D3DX11_FILTER_SRGB = (3 << 21),
} D3DX11_FILTER_FLAG;
//----------------------------------------------------------------------------
// D3DX11_NORMALMAP flags:
// ---------------------
// These flags are used to control how D3DX11ComputeNormalMap generates normal
// maps. Any number of these flags may be OR'd together in any combination.
//
// D3DX11_NORMALMAP_MIRROR_U
// Indicates that pixels off the edge of the texture on the U-axis
// should be mirrored, not wraped.
// D3DX11_NORMALMAP_MIRROR_V
// Indicates that pixels off the edge of the texture on the V-axis
// should be mirrored, not wraped.
// D3DX11_NORMALMAP_MIRROR
// Same as specifying D3DX11_NORMALMAP_MIRROR_U | D3DX11_NORMALMAP_MIRROR_V
// D3DX11_NORMALMAP_INVERTSIGN
// Inverts the direction of each normal
// D3DX11_NORMALMAP_COMPUTE_OCCLUSION
// Compute the per pixel Occlusion term and encodes it into the alpha.
// An Alpha of 1 means that the pixel is not obscured in anyway, and
// an alpha of 0 would mean that the pixel is completly obscured.
//
//----------------------------------------------------------------------------
typedef enum D3DX11_NORMALMAP_FLAG
{
D3DX11_NORMALMAP_MIRROR_U = (1 << 16),
D3DX11_NORMALMAP_MIRROR_V = (2 << 16),
D3DX11_NORMALMAP_MIRROR = (3 << 16),
D3DX11_NORMALMAP_INVERTSIGN = (8 << 16),
D3DX11_NORMALMAP_COMPUTE_OCCLUSION = (16 << 16),
} D3DX11_NORMALMAP_FLAG;
//----------------------------------------------------------------------------
// D3DX11_CHANNEL flags:
// -------------------
// These flags are used by functions which operate on or more channels
// in a texture.
//
// D3DX11_CHANNEL_RED
// Indicates the red channel should be used
// D3DX11_CHANNEL_BLUE
// Indicates the blue channel should be used
// D3DX11_CHANNEL_GREEN
// Indicates the green channel should be used
// D3DX11_CHANNEL_ALPHA
// Indicates the alpha channel should be used
// D3DX11_CHANNEL_LUMINANCE
// Indicates the luminaces of the red green and blue channels should be
// used.
//
//----------------------------------------------------------------------------
typedef enum D3DX11_CHANNEL_FLAG
{
D3DX11_CHANNEL_RED = (1 << 0),
D3DX11_CHANNEL_BLUE = (1 << 1),
D3DX11_CHANNEL_GREEN = (1 << 2),
D3DX11_CHANNEL_ALPHA = (1 << 3),
D3DX11_CHANNEL_LUMINANCE = (1 << 4),
} D3DX11_CHANNEL_FLAG;
//----------------------------------------------------------------------------
// D3DX11_IMAGE_FILE_FORMAT:
// ---------------------
// This enum is used to describe supported image file formats.
//
//----------------------------------------------------------------------------
typedef enum D3DX11_IMAGE_FILE_FORMAT
{
D3DX11_IFF_BMP = 0,
D3DX11_IFF_JPG = 1,
D3DX11_IFF_PNG = 3,
D3DX11_IFF_DDS = 4,
D3DX11_IFF_TIFF = 10,
D3DX11_IFF_GIF = 11,
D3DX11_IFF_WMP = 12,
D3DX11_IFF_FORCE_DWORD = 0x7fffffff
} D3DX11_IMAGE_FILE_FORMAT;
//----------------------------------------------------------------------------
// D3DX11_SAVE_TEXTURE_FLAG:
// ---------------------
// This enum is used to support texture saving options.
//
//----------------------------------------------------------------------------
typedef enum D3DX11_SAVE_TEXTURE_FLAG
{
D3DX11_STF_USEINPUTBLOB = 0x0001,
} D3DX11_SAVE_TEXTURE_FLAG;
//----------------------------------------------------------------------------
// D3DX11_IMAGE_INFO:
// ---------------
// This structure is used to return a rough description of what the
// the original contents of an image file looked like.
//
// Width
// Width of original image in pixels
// Height
// Height of original image in pixels
// Depth
// Depth of original image in pixels
// ArraySize
// Array size in textures
// MipLevels
// Number of mip levels in original image
// MiscFlags
// Miscellaneous flags
// Format
// D3D format which most closely describes the data in original image
// ResourceDimension
// D3D11_RESOURCE_DIMENSION representing the dimension of texture stored in the file.
// D3D11_RESOURCE_DIMENSION_TEXTURE1D, 2D, 3D
// ImageFileFormat
// D3DX11_IMAGE_FILE_FORMAT representing the format of the image file.
//----------------------------------------------------------------------------
typedef struct D3DX11_IMAGE_INFO
{
UINT Width;
UINT Height;
UINT Depth;
UINT ArraySize;
UINT MipLevels;
UINT MiscFlags;
DXGI_FORMAT Format;
D3D11_RESOURCE_DIMENSION ResourceDimension;
D3DX11_IMAGE_FILE_FORMAT ImageFileFormat;
} D3DX11_IMAGE_INFO;
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
//////////////////////////////////////////////////////////////////////////////
// Image File APIs ///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// D3DX11_IMAGE_LOAD_INFO:
// ---------------
// This structure can be optionally passed in to texture loader APIs to
// control how textures get loaded. Pass in D3DX11_DEFAULT for any of these
// to have D3DX automatically pick defaults based on the source file.
//
// Width
// Rescale texture to Width texels wide
// Height
// Rescale texture to Height texels high
// Depth
// Rescale texture to Depth texels deep
// FirstMipLevel
// First mip level to load
// MipLevels
// Number of mip levels to load after the first level
// Usage
// D3D11_USAGE flag for the new texture
// BindFlags
// D3D11 Bind flags for the new texture
// CpuAccessFlags
// D3D11 CPU Access flags for the new texture
// MiscFlags
// Reserved. Must be 0
// Format
// Resample texture to the specified format
// Filter
// Filter the texture using the specified filter (only when resampling)
// MipFilter
// Filter the texture mip levels using the specified filter (only if
// generating mips)
// pSrcInfo
// (optional) pointer to a D3DX11_IMAGE_INFO structure that will get
// populated with source image information
//----------------------------------------------------------------------------
typedef struct D3DX11_IMAGE_LOAD_INFO
{
UINT Width;
UINT Height;
UINT Depth;
UINT FirstMipLevel;
UINT MipLevels;
D3D11_USAGE Usage;
UINT BindFlags;
UINT CpuAccessFlags;
UINT MiscFlags;
DXGI_FORMAT Format;
UINT Filter;
UINT MipFilter;
D3DX11_IMAGE_INFO* pSrcInfo;
#ifdef __cplusplus
D3DX11_IMAGE_LOAD_INFO()
{
Width = D3DX11_DEFAULT;
Height = D3DX11_DEFAULT;
Depth = D3DX11_DEFAULT;
FirstMipLevel = D3DX11_DEFAULT;
MipLevels = D3DX11_DEFAULT;
Usage = (D3D11_USAGE) D3DX11_DEFAULT;
BindFlags = D3DX11_DEFAULT;
CpuAccessFlags = D3DX11_DEFAULT;
MiscFlags = D3DX11_DEFAULT;
Format = DXGI_FORMAT_FROM_FILE;
Filter = D3DX11_DEFAULT;
MipFilter = D3DX11_DEFAULT;
pSrcInfo = NULL;
}
#endif
} D3DX11_IMAGE_LOAD_INFO;
//-------------------------------------------------------------------------------
// GetImageInfoFromFile/Resource/Memory:
// ------------------------------
// Fills in a D3DX11_IMAGE_INFO struct with information about an image file.
//
// Parameters:
// pSrcFile
// File name of the source image.
// pSrcModule
// Module where resource is located, or NULL for module associated
// with image the os used to create the current process.
// pSrcResource
// Resource name.
// pSrcData
// Pointer to file in memory.
// SrcDataSize
// Size in bytes of file in memory.
// pPump
// Optional pointer to a thread pump object to use.
// pSrcInfo
// Pointer to a D3DX11_IMAGE_INFO structure to be filled in with the
// description of the data in the source image file.
// pHResult
// Pointer to a memory location to receive the return value upon completion.
// Maybe NULL if not needed.
// If pPump != NULL, pHResult must be a valid memory location until the
// the asynchronous execution completes.
//-------------------------------------------------------------------------------
HRESULT WINAPI
D3DX11GetImageInfoFromFileA(
LPCSTR pSrcFile,
ID3DX11ThreadPump* pPump,
D3DX11_IMAGE_INFO* pSrcInfo,
HRESULT* pHResult);
HRESULT WINAPI
D3DX11GetImageInfoFromFileW(
LPCWSTR pSrcFile,
ID3DX11ThreadPump* pPump,
D3DX11_IMAGE_INFO* pSrcInfo,
HRESULT* pHResult);
#ifdef UNICODE
#define D3DX11GetImageInfoFromFile D3DX11GetImageInfoFromFileW
#else
#define D3DX11GetImageInfoFromFile D3DX11GetImageInfoFromFileA
#endif
HRESULT WINAPI
D3DX11GetImageInfoFromResourceA(
HMODULE hSrcModule,
LPCSTR pSrcResource,
ID3DX11ThreadPump* pPump,
D3DX11_IMAGE_INFO* pSrcInfo,
HRESULT* pHResult);
HRESULT WINAPI
D3DX11GetImageInfoFromResourceW(
HMODULE hSrcModule,
LPCWSTR pSrcResource,
ID3DX11ThreadPump* pPump,
D3DX11_IMAGE_INFO* pSrcInfo,
HRESULT* pHResult);
#ifdef UNICODE
#define D3DX11GetImageInfoFromResource D3DX11GetImageInfoFromResourceW
#else
#define D3DX11GetImageInfoFromResource D3DX11GetImageInfoFromResourceA
#endif
HRESULT WINAPI
D3DX11GetImageInfoFromMemory(
LPCVOID pSrcData,
SIZE_T SrcDataSize,
ID3DX11ThreadPump* pPump,
D3DX11_IMAGE_INFO* pSrcInfo,
HRESULT* pHResult);
//////////////////////////////////////////////////////////////////////////////
// Create/Save Texture APIs //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// D3DX11CreateTextureFromFile/Resource/Memory:
// D3DX11CreateShaderResourceViewFromFile/Resource/Memory:
// -----------------------------------
// Create a texture object from a file or resource.
//
// Parameters:
//
// pDevice
// The D3D device with which the texture is going to be used.
// pSrcFile
// File name.
// hSrcModule
// Module handle. if NULL, current module will be used.
// pSrcResource
// Resource name in module
// pvSrcData
// Pointer to file in memory.
// SrcDataSize
// Size in bytes of file in memory.
// pLoadInfo
// Optional pointer to a D3DX11_IMAGE_LOAD_INFO structure that
// contains additional loader parameters.
// pPump
// Optional pointer to a thread pump object to use.
// ppTexture
// [out] Created texture object.
// ppShaderResourceView
// [out] Shader resource view object created.
// pHResult
// Pointer to a memory location to receive the return value upon completion.
// Maybe NULL if not needed.
// If pPump != NULL, pHResult must be a valid memory location until the
// the asynchronous execution completes.
//
//----------------------------------------------------------------------------
// FromFile
HRESULT WINAPI
D3DX11CreateShaderResourceViewFromFileA(
ID3D11Device* pDevice,
LPCSTR pSrcFile,
D3DX11_IMAGE_LOAD_INFO *pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11ShaderResourceView** ppShaderResourceView,
HRESULT* pHResult);
HRESULT WINAPI
D3DX11CreateShaderResourceViewFromFileW(
ID3D11Device* pDevice,
LPCWSTR pSrcFile,
D3DX11_IMAGE_LOAD_INFO *pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11ShaderResourceView** ppShaderResourceView,
HRESULT* pHResult);
#ifdef UNICODE
#define D3DX11CreateShaderResourceViewFromFile D3DX11CreateShaderResourceViewFromFileW
#else
#define D3DX11CreateShaderResourceViewFromFile D3DX11CreateShaderResourceViewFromFileA
#endif
HRESULT WINAPI
D3DX11CreateTextureFromFileA(
ID3D11Device* pDevice,
LPCSTR pSrcFile,
D3DX11_IMAGE_LOAD_INFO *pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11Resource** ppTexture,
HRESULT* pHResult);
HRESULT WINAPI
D3DX11CreateTextureFromFileW(
ID3D11Device* pDevice,
LPCWSTR pSrcFile,
D3DX11_IMAGE_LOAD_INFO *pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11Resource** ppTexture,
HRESULT* pHResult);
#ifdef UNICODE
#define D3DX11CreateTextureFromFile D3DX11CreateTextureFromFileW
#else
#define D3DX11CreateTextureFromFile D3DX11CreateTextureFromFileA
#endif
// FromResource (resources in dll/exes)
HRESULT WINAPI
D3DX11CreateShaderResourceViewFromResourceA(
ID3D11Device* pDevice,
HMODULE hSrcModule,
LPCSTR pSrcResource,
D3DX11_IMAGE_LOAD_INFO* pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11ShaderResourceView** ppShaderResourceView,
HRESULT* pHResult);
HRESULT WINAPI
D3DX11CreateShaderResourceViewFromResourceW(
ID3D11Device* pDevice,
HMODULE hSrcModule,
LPCWSTR pSrcResource,
D3DX11_IMAGE_LOAD_INFO* pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11ShaderResourceView** ppShaderResourceView,
HRESULT* pHResult);
#ifdef UNICODE
#define D3DX11CreateShaderResourceViewFromResource D3DX11CreateShaderResourceViewFromResourceW
#else
#define D3DX11CreateShaderResourceViewFromResource D3DX11CreateShaderResourceViewFromResourceA
#endif
HRESULT WINAPI
D3DX11CreateTextureFromResourceA(
ID3D11Device* pDevice,
HMODULE hSrcModule,
LPCSTR pSrcResource,
D3DX11_IMAGE_LOAD_INFO *pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11Resource** ppTexture,
HRESULT* pHResult);
HRESULT WINAPI
D3DX11CreateTextureFromResourceW(
ID3D11Device* pDevice,
HMODULE hSrcModule,
LPCWSTR pSrcResource,
D3DX11_IMAGE_LOAD_INFO* pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11Resource** ppTexture,
HRESULT* pHResult);
#ifdef UNICODE
#define D3DX11CreateTextureFromResource D3DX11CreateTextureFromResourceW
#else
#define D3DX11CreateTextureFromResource D3DX11CreateTextureFromResourceA
#endif
// FromFileInMemory
HRESULT WINAPI
D3DX11CreateShaderResourceViewFromMemory(
ID3D11Device* pDevice,
LPCVOID pSrcData,
SIZE_T SrcDataSize,
D3DX11_IMAGE_LOAD_INFO* pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11ShaderResourceView** ppShaderResourceView,
HRESULT* pHResult);
HRESULT WINAPI
D3DX11CreateTextureFromMemory(
ID3D11Device* pDevice,
LPCVOID pSrcData,
SIZE_T SrcDataSize,
D3DX11_IMAGE_LOAD_INFO* pLoadInfo,
ID3DX11ThreadPump* pPump,
ID3D11Resource** ppTexture,
HRESULT* pHResult);
//////////////////////////////////////////////////////////////////////////////
// Misc Texture APIs /////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// D3DX11_TEXTURE_LOAD_INFO:
// ------------------------
//
//----------------------------------------------------------------------------
typedef struct _D3DX11_TEXTURE_LOAD_INFO
{
D3D11_BOX *pSrcBox;
D3D11_BOX *pDstBox;
UINT SrcFirstMip;
UINT DstFirstMip;
UINT NumMips;
UINT SrcFirstElement;
UINT DstFirstElement;
UINT NumElements;
UINT Filter;
UINT MipFilter;
#ifdef __cplusplus
_D3DX11_TEXTURE_LOAD_INFO()
{
pSrcBox = NULL;
pDstBox = NULL;
SrcFirstMip = 0;
DstFirstMip = 0;
NumMips = D3DX11_DEFAULT;
SrcFirstElement = 0;
DstFirstElement = 0;
NumElements = D3DX11_DEFAULT;
Filter = D3DX11_DEFAULT;
MipFilter = D3DX11_DEFAULT;
}
#endif
} D3DX11_TEXTURE_LOAD_INFO;
//----------------------------------------------------------------------------
// D3DX11LoadTextureFromTexture:
// ----------------------------
// Load a texture from a texture.
//
// Parameters:
//
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DX11LoadTextureFromTexture(
ID3D11DeviceContext *pContext,
ID3D11Resource *pSrcTexture,
D3DX11_TEXTURE_LOAD_INFO *pLoadInfo,
ID3D11Resource *pDstTexture);
//----------------------------------------------------------------------------
// D3DX11FilterTexture:
// ------------------
// Filters mipmaps levels of a texture.
//
// Parameters:
// pBaseTexture
// The texture object to be filtered
// SrcLevel
// The level whose image is used to generate the subsequent levels.
// MipFilter
// D3DX11_FILTER flags controlling how each miplevel is filtered.
// Or D3DX11_DEFAULT for D3DX11_FILTER_BOX,
//
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DX11FilterTexture(
ID3D11DeviceContext *pContext,
ID3D11Resource *pTexture,
UINT SrcLevel,
UINT MipFilter);
//----------------------------------------------------------------------------
// D3DX11SaveTextureToFile:
// ----------------------
// Save a texture to a file.
//
// Parameters:
// pDestFile
// File name of the destination file
// DestFormat
// D3DX11_IMAGE_FILE_FORMAT specifying file format to use when saving.
// pSrcTexture
// Source texture, containing the image to be saved
//
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DX11SaveTextureToFileA(
ID3D11DeviceContext *pContext,
ID3D11Resource *pSrcTexture,
D3DX11_IMAGE_FILE_FORMAT DestFormat,
LPCSTR pDestFile);
HRESULT WINAPI
D3DX11SaveTextureToFileW(
ID3D11DeviceContext *pContext,
ID3D11Resource *pSrcTexture,
D3DX11_IMAGE_FILE_FORMAT DestFormat,
LPCWSTR pDestFile);
#ifdef UNICODE
#define D3DX11SaveTextureToFile D3DX11SaveTextureToFileW
#else
#define D3DX11SaveTextureToFile D3DX11SaveTextureToFileA
#endif
//----------------------------------------------------------------------------
// D3DX11SaveTextureToMemory:
// ----------------------
// Save a texture to a blob.
//
// Parameters:
// pSrcTexture
// Source texture, containing the image to be saved
// DestFormat
// D3DX11_IMAGE_FILE_FORMAT specifying file format to use when saving.
// ppDestBuf
// address of a d3dxbuffer pointer to return the image data
// Flags
// optional flags
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DX11SaveTextureToMemory(
ID3D11DeviceContext *pContext,
ID3D11Resource* pSrcTexture,
D3DX11_IMAGE_FILE_FORMAT DestFormat,
ID3D10Blob** ppDestBuf,
UINT Flags);
//----------------------------------------------------------------------------
// D3DX11ComputeNormalMap:
// ---------------------
// Converts a height map into a normal map. The (x,y,z) components of each
// normal are mapped to the (r,g,b) channels of the output texture.
//
// Parameters
// pSrcTexture
// Pointer to the source heightmap texture
// Flags
// D3DX11_NORMALMAP flags
// Channel
// D3DX11_CHANNEL specifying source of height information
// Amplitude
// The constant value which the height information is multiplied by.
// pDestTexture
// Pointer to the destination texture
//---------------------------------------------------------------------------
HRESULT WINAPI
D3DX11ComputeNormalMap(
ID3D11DeviceContext *pContext,
ID3D11Texture2D *pSrcTexture,
UINT Flags,
UINT Channel,
FLOAT Amplitude,
ID3D11Texture2D *pDestTexture);
//----------------------------------------------------------------------------
// D3DX11SHProjectCubeMap:
// ----------------------
// Projects a function represented in a cube map into spherical harmonics.
//
// Parameters:
// Order
// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
// pCubeMap
// CubeMap that is going to be projected into spherical harmonics
// pROut
// Output SH vector for Red.
// pGOut
// Output SH vector for Green
// pBOut
// Output SH vector for Blue
//
//---------------------------------------------------------------------------
HRESULT WINAPI
D3DX11SHProjectCubeMap(
ID3D11DeviceContext *pContext,
__in_range(2,6) UINT Order,
ID3D11Texture2D *pCubeMap,
__out_ecount(Order*Order) FLOAT *pROut,
__out_ecount_opt(Order*Order) FLOAT *pGOut,
__out_ecount_opt(Order*Order) FLOAT *pBOut);
#ifdef __cplusplus
}
#endif //__cplusplus
#endif //__D3DX11TEX_H__
Binary file not shown.
+10 -1
View File
@@ -450,9 +450,18 @@ void Imgui_Base::RenderMenu()
ImGui::BeginDisabled(currentBackend != "xess");
ImGui::SeparatorText("XeSS Settings");
if (bool cas = Config::Instance()->CasEnabled.value_or(true); ImGui::Checkbox("CAS", &cas))
Config::Instance()->CasEnabled = cas;
ImGui::SameLine(0.0f, 6.0f);
if (bool csf = Config::Instance()->ColorSpaceFix.value_or(true); ImGui::Checkbox("ColorSpace Fix", &csf))
Config::Instance()->ColorSpaceFix = csf;
ImGui::SameLine(0.0f, 6.0f);
if (bool dbg = Config::Instance()->xessDebug; ImGui::Checkbox("Debug Dump", &dbg))
Config::Instance()->xessDebug = dbg;
ImGui::BeginDisabled(!Config::Instance()->CasEnabled.value_or(true));
const char* cs[] = { "LINEAR", "GAMMA20", "GAMMA22", "SRGB_OUTPUT", "SRGB_INPUT_OUTPUT" };
@@ -741,7 +750,7 @@ Imgui_Base::Imgui_Base(HWND handle)
context = ImGui::CreateContext();
ImGui::SetCurrentContext(context);
ImGui::StyleColorsDark();
auto style = ImGui::GetStyle();
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.1f, 0.1f, 0.1f, 0.20f);
+1 -1
View File
@@ -1,5 +1,5 @@
#include "Imgui_Dx12.h"
#include "d3dx12.h"
#include "../d3dx/d3dx12.h"
#include "imgui/imgui_impl_dx12.h"
long frameCounter = 0;
+5
View File
@@ -41,6 +41,11 @@ BuildPipelines=auto
; Default (auto) is XeSS quality matching DLSS value
OverrideQuality=auto
; Enable colorspace fix for AW2
; true or false - Default (auto) is false
ColorSpaceFix=auto
[FSR]
; 0.0 to 180.0 - Default (auto) is 60.0
VerticalFov=auto