Skip to content

Commit a22addd

Browse files
Implement SuperResolution: DLSS (D3D11/D3D12/Vulkan), DirectSR (D3D12), MetalFX (Metal)
1 parent baab22d commit a22addd

24 files changed

+2658
-129
lines changed

.github/workflows/msvc_analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
# Ruleset file that will determine what checks will be run
6161
ruleset: NativeRecommendedRules.ruleset
6262
# Paths to ignore analysis of CMake targets and includes
63-
ignoredPaths: '${{ github.workspace }}/ThirdParty'
63+
ignoredPaths: '${{ github.workspace }}/ThirdParty;${{ env.DILIGENT_BUILD_DIR }}/_deps'
6464

6565
# Upload SARIF file to GitHub Code Scanning Alerts
6666
- name: Upload SARIF to GitHub

Graphics/SuperResolution/CMakeLists.txt

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,50 @@ include(../../BuildTools/CMake/BuildUtils.cmake)
44

55
project(Diligent-SuperResolution CXX)
66

7+
set(DILIGENT_DLSS_SUPPORTED FALSE CACHE INTERNAL "DLSS is not supported")
8+
set(DILIGENT_DSR_SUPPORTED FALSE CACHE INTERNAL "DirectSR is not supported")
9+
10+
if(PLATFORM_WIN32)
11+
set(DILIGENT_DLSS_SUPPORTED TRUE CACHE INTERNAL "DLSS is supported on Win32 platform")
12+
set(DILIGENT_DSR_SUPPORTED TRUE CACHE INTERNAL "DirectSR is supported on Win32 platform")
13+
endif()
14+
15+
if(${DILIGENT_NO_DLSS})
16+
set(DILIGENT_DLSS_SUPPORTED FALSE CACHE INTERNAL "DLSS is forcibly disabled")
17+
endif()
18+
if(${DILIGENT_NO_DSR})
19+
set(DILIGENT_DSR_SUPPORTED FALSE CACHE INTERNAL "DirectSR is forcibly disabled")
20+
endif()
21+
22+
if(DILIGENT_DSR_SUPPORTED)
23+
# Fetch DirectSR headers
24+
FetchContent_DeclareShallowGit(DirectSR-Headers
25+
GIT_REPOSITORY https://github.com/MikhailGorobets/DirectSR-Headers.git
26+
GIT_TAG master
27+
)
28+
FetchContent_MakeAvailable(DirectSR-Headers)
29+
if(TARGET DirectSR-AgilitySDK)
30+
set_target_properties(DirectSR-AgilitySDK PROPERTIES FOLDER DiligentCore/ThirdParty)
31+
endif()
32+
endif()
33+
34+
if(DILIGENT_DLSS_SUPPORTED)
35+
# Fetch NVIDIA DLSS SDK headers
36+
FetchContent_DeclareShallowGit(DLSS-Headers
37+
GIT_REPOSITORY https://github.com/NVIDIA/DLSS.git
38+
GIT_TAG main
39+
)
40+
FetchContent_MakeAvailable(DLSS-Headers)
41+
endif()
42+
743
set(INCLUDE
844
include/SuperResolutionBase.hpp
945
include/SuperResolutionFactoryBase.hpp
46+
include/SuperResolutionVariants.hpp
47+
include/SuperResolutionFactoryD3D12_DLSS.hpp
48+
include/SuperResolutionFactoryD3D11_DLSS.hpp
49+
include/SuperResolutionFactoryVk_DLSS.hpp
50+
include/SuperResolutionFactoryD3D12_DSR.hpp
1051
)
1152

1253
set(INTERFACE
@@ -16,15 +57,22 @@ set(INTERFACE
1657
)
1758

1859
set(SOURCE
60+
src/SuperResolutionBase.cpp
1961
src/SuperResolutionFactoryBase.cpp
62+
src/SuperResolutionFactory.cpp
63+
src/SuperResolutionFactoryD3D12.cpp
64+
src/SuperResolutionFactoryD3D11.cpp
65+
src/SuperResolutionFactoryVk.cpp
66+
src/SuperResolutionFactoryMtl.cpp
67+
src/SuperResolutionFactoryD3D12_DLSS.cpp
68+
src/SuperResolutionFactoryD3D11_DLSS.cpp
69+
src/SuperResolutionFactoryVk_DLSS.cpp
70+
src/SuperResolutionFactoryD3D12_DSR.cpp
2071
)
2172

22-
if(D3D12_SUPPORTED)
23-
list(APPEND
24-
SOURCE
25-
src/SuperResolutionD3D12.cpp
26-
src/SuperResolutionFactoryD3D12.cpp
27-
)
73+
if(DILIGENT_DLSS_SUPPORTED)
74+
list(APPEND INCLUDE include/SuperResolutionDLSS.hpp)
75+
list(APPEND SOURCE src/SuperResolutionDLSS.cpp)
2876
endif()
2977

3078
set(DLL_SOURCE
@@ -57,6 +105,14 @@ PRIVATE
57105
../GraphicsEngineNextGenBase/include
58106
)
59107

108+
if(DILIGENT_DLSS_SUPPORTED)
109+
target_compile_definitions(Diligent-SuperResolution-static PRIVATE DILIGENT_DLSS_SUPPORTED=1)
110+
endif()
111+
112+
if(DILIGENT_DSR_SUPPORTED)
113+
target_compile_definitions(Diligent-SuperResolution-static PRIVATE DILIGENT_DSR_SUPPORTED=1)
114+
endif()
115+
60116
target_compile_definitions(Diligent-SuperResolution-shared PUBLIC DILIGENT_SUPER_RESOLUTION_SHARED=1)
61117

62118
target_link_libraries(Diligent-SuperResolution-static
@@ -69,11 +125,35 @@ PRIVATE
69125
Diligent-ShaderTools
70126
)
71127

72-
if(D3D12_SUPPORTED)
73-
target_link_libraries(Diligent-SuperResolution-static PRIVATE Diligent-GraphicsEngineD3D12-static)
128+
if(DILIGENT_DSR_SUPPORTED)
129+
target_link_libraries(Diligent-SuperResolution-static PRIVATE Diligent-GraphicsEngineD3D12-static DirectSR-Headers)
74130
target_include_directories(Diligent-SuperResolution-static PRIVATE ../GraphicsEngineD3D12/include)
75131
endif()
76132

133+
if(DILIGENT_DLSS_SUPPORTED)
134+
set(DLSS_SDK_DIR ${FETCHCONTENT_BASE_DIR}/dlss-headers-src)
135+
target_include_directories(Diligent-SuperResolution-static PRIVATE ${DLSS_SDK_DIR}/include)
136+
137+
# Link NGX static library (dynamic CRT /MD variant)
138+
target_link_libraries(Diligent-SuperResolution-static PRIVATE
139+
debug ${DLSS_SDK_DIR}/lib/Windows_x86_64/x64/nvsdk_ngx_d_dbg.lib
140+
optimized ${DLSS_SDK_DIR}/lib/Windows_x86_64/x64/nvsdk_ngx_d.lib
141+
)
142+
143+
if(D3D12_SUPPORTED)
144+
target_link_libraries(Diligent-SuperResolution-static PRIVATE Diligent-GraphicsEngineD3D12-static)
145+
target_include_directories(Diligent-SuperResolution-static PRIVATE ../GraphicsEngineD3D12/include)
146+
endif()
147+
if(D3D11_SUPPORTED)
148+
target_link_libraries(Diligent-SuperResolution-static PRIVATE Diligent-GraphicsEngineD3D11-static)
149+
target_include_directories(Diligent-SuperResolution-static PRIVATE ../GraphicsEngineD3D11/include)
150+
endif()
151+
if(VULKAN_SUPPORTED)
152+
target_link_libraries(Diligent-SuperResolution-static PRIVATE Diligent-GraphicsEngineVk-static Vulkan::Headers)
153+
target_include_directories(Diligent-SuperResolution-static PRIVATE ../GraphicsEngineVulkan/include)
154+
endif()
155+
endif()
156+
77157
target_link_libraries(Diligent-SuperResolution-shared
78158
PUBLIC
79159
Diligent-SuperResolutionInterface

Graphics/SuperResolution/include/SuperResolutionBase.hpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,66 @@
2626

2727
#pragma once
2828

29-
#include "SuperResolution.h"
3029
#include "ObjectBase.hpp"
30+
#include "SuperResolution.h"
31+
#include "SuperResolutionFactory.h"
32+
#include "GraphicsAccessories.hpp"
3133

3234
#include <vector>
3335
#include <string>
3436

3537
namespace Diligent
3638
{
3739

40+
#define LOG_SUPER_RESOLUTION_ERROR_AND_THROW(Name, ...) LOG_ERROR_AND_THROW("Super resolution upscaler '", ((Name) != nullptr ? (Name) : ""), "': ", ##__VA_ARGS__)
41+
42+
#define VERIFY_SUPER_RESOLUTION(Name, Expr, ...) \
43+
do \
44+
{ \
45+
if (!(Expr)) \
46+
{ \
47+
LOG_SUPER_RESOLUTION_ERROR_AND_THROW(Name, __VA_ARGS__); \
48+
} \
49+
} while (false)
50+
51+
/// Validates super resolution description and throws an exception in case of an error.
52+
void ValidateSuperResolutionDesc(const SuperResolutionDesc& Desc) noexcept(false);
53+
54+
/// Validates super resolution description for temporal upscaling and throws an exception in case of an error.
55+
void ValidateTemporalSuperResolutionDesc(const SuperResolutionDesc& Desc) noexcept(false);
56+
57+
/// Validates super resolution source settings attributes and throws an exception in case of an error.
58+
void ValidateSourceSettingsAttribs(const SuperResolutionSourceSettingsAttribs& Attribs) noexcept(false);
59+
60+
/// Validates execute super resolution attributes and throws an exception in case of an error.
61+
void ValidateExecuteSuperResolutionAttribs(const SuperResolutionDesc& Desc,
62+
const ExecuteSuperResolutionAttribs& Attribs) noexcept(false);
63+
64+
/// Validates execute super resolution attributes for temporal upscaling and throws an exception in case of an error.
65+
void ValidateTemporalExecuteSuperResolutionAttribs(const SuperResolutionDesc& Desc,
66+
const ExecuteSuperResolutionAttribs& Attribs) noexcept(false);
67+
3868
class SuperResolutionBase : public ObjectBase<ISuperResolution>
3969
{
4070
public:
4171
using TBase = ObjectBase<ISuperResolution>;
4272

73+
struct JitterOffset
74+
{
75+
float X = 0.0f;
76+
float Y = 0.0f;
77+
};
78+
4379
SuperResolutionBase(IReferenceCounters* pRefCounters,
4480
const SuperResolutionDesc& Desc) :
4581
TBase{pRefCounters},
46-
m_Name{Desc.Name != nullptr ? Desc.Name : ""},
4782
m_Desc{Desc}
4883
{
49-
m_Desc.Name = m_Name.c_str();
84+
if (Desc.Name != nullptr)
85+
{
86+
m_Name = Desc.Name;
87+
m_Desc.Name = m_Name.c_str();
88+
}
5089
}
5190

5291
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_SuperResolution, TBase)
@@ -72,15 +111,12 @@ class SuperResolutionBase : public ObjectBase<ISuperResolution>
72111
}
73112

74113
protected:
75-
struct JitterOffset
76-
{
77-
float X = 0.0f;
78-
float Y = 0.0f;
79-
};
80-
81-
const std::string m_Name;
82114
SuperResolutionDesc m_Desc;
115+
std::string m_Name;
83116
std::vector<JitterOffset> m_JitterPattern;
84117
};
85118

119+
/// Populates a Halton(2,3) jitter pattern centered at origin.
120+
void PopulateHaltonJitterPattern(std::vector<SuperResolutionBase::JitterOffset>& JitterPattern, Uint32 PatternSize);
121+
86122
} // namespace Diligent
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2026 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
#pragma once
28+
29+
/// \file
30+
/// Shared DLSS utilities used by per-API DLSS backend implementations.
31+
32+
#include <vector>
33+
34+
#include <nvsdk_ngx_defs.h>
35+
36+
#include "SuperResolutionFactory.h"
37+
#include "SuperResolution.h"
38+
39+
struct NVSDK_NGX_Parameter;
40+
41+
namespace Diligent
42+
{
43+
44+
extern const char* DLSSProjectId;
45+
extern const wchar_t* DLSSAppDataPath;
46+
47+
/// Maps Diligent optimization type to NGX performance/quality preset.
48+
NVSDK_NGX_PerfQuality_Value OptimizationTypeToNGXPerfQuality(SUPER_RESOLUTION_OPTIMIZATION_TYPE Type);
49+
50+
/// Maps Diligent super resolution flags to DLSS feature flags.
51+
Int32 SuperResolutionFlagsToDLSSFeatureFlags(SUPER_RESOLUTION_FLAGS Flags);
52+
53+
/// Populates DLSS variant info using NGX capability parameters.
54+
void EnumerateDLSSVariants(NVSDK_NGX_Parameter* pNGXParams, std::vector<SuperResolutionInfo>& Variants);
55+
56+
/// Queries DLSS optimal source settings using NGX capability parameters.
57+
void GetDLSSSourceSettings(NVSDK_NGX_Parameter* pNGXParams,
58+
const SuperResolutionSourceSettingsAttribs& Attribs,
59+
SuperResolutionSourceSettings& Settings);
60+
61+
} // namespace Diligent

Graphics/SuperResolution/include/SuperResolutionFactoryBase.hpp

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,91 @@
2727
#pragma once
2828

2929
#include "SuperResolutionFactory.h"
30+
#include "SuperResolution.h"
3031
#include "ObjectBase.hpp"
31-
#include "RefCntAutoPtr.hpp"
3232

3333
#include <vector>
34+
#include <memory>
3435

3536
namespace Diligent
3637
{
3738

39+
struct BackendEntry
40+
{
41+
struct IHolder
42+
{
43+
virtual ~IHolder() = default;
44+
45+
virtual void GetSourceSettings(const SuperResolutionSourceSettingsAttribs& Attribs, SuperResolutionSourceSettings& Settings) = 0;
46+
47+
virtual void CreateSuperResolution(const SuperResolutionDesc& Desc, ISuperResolution** ppUpscaler) = 0;
48+
};
49+
50+
template <typename T>
51+
struct Holder final : IHolder
52+
{
53+
T Instance;
54+
template <typename... Args>
55+
explicit Holder(Args&&... args) :
56+
Instance(std::forward<Args>(args)...) {}
57+
58+
void GetSourceSettings(const SuperResolutionSourceSettingsAttribs& Attribs, SuperResolutionSourceSettings& Settings) override { Instance.GetSourceSettings(Attribs, Settings); }
59+
60+
void CreateSuperResolution(const SuperResolutionDesc& Desc, ISuperResolution** ppUpscaler) override { Instance.CreateSuperResolution(Desc, ppUpscaler); }
61+
};
62+
63+
std::unique_ptr<IHolder> pBackend;
64+
std::vector<SuperResolutionInfo> Variants;
65+
};
66+
3867
class SuperResolutionFactoryBase : public ObjectBase<ISuperResolutionFactory>
3968
{
4069
public:
4170
using TBase = ObjectBase<ISuperResolutionFactory>;
4271

43-
SuperResolutionFactoryBase(IReferenceCounters* pRefCounters, IRenderDevice* pDevice);
72+
SuperResolutionFactoryBase(IReferenceCounters* pRefCounters);
4473

4574
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_SuperResolutionFactory, TBase)
4675

4776
virtual void DILIGENT_CALL_TYPE EnumerateVariants(Uint32& NumVariants, SuperResolutionInfo* Variants) override final;
4877

78+
virtual void DILIGENT_CALL_TYPE GetSourceSettings(const SuperResolutionSourceSettingsAttribs& Attribs, SuperResolutionSourceSettings& Settings) const override final;
79+
80+
virtual void DILIGENT_CALL_TYPE CreateSuperResolution(const SuperResolutionDesc& Desc, ISuperResolution** ppUpscaler) override final;
81+
4982
virtual void DILIGENT_CALL_TYPE SetMessageCallback(DebugMessageCallbackType MessageCallback) const override final;
5083

5184
virtual void DILIGENT_CALL_TYPE SetBreakOnError(bool BreakOnError) const override final;
5285

5386
virtual void DILIGENT_CALL_TYPE SetMemoryAllocator(IMemoryAllocator* pAllocator) const override final;
5487

88+
template <typename BackendType, typename... Args>
89+
void AddBackend(Args&&... args);
90+
5591
private:
56-
RefCntAutoPtr<IRenderDevice> m_pDevice;
57-
std::vector<SuperResolutionInfo> m_Variants{};
92+
BackendEntry* FindBackend(const INTERFACE_ID& VariantId) const;
93+
94+
std::vector<BackendEntry> m_Backends;
5895
};
5996

97+
template <typename BackendType, typename... Args>
98+
void SuperResolutionFactoryBase::AddBackend(Args&&... args)
99+
{
100+
try
101+
{
102+
auto pHolder = std::make_unique<BackendEntry::Holder<BackendType>>(std::forward<Args>(args)...);
103+
104+
BackendEntry Entry;
105+
pHolder->Instance.EnumerateVariants(Entry.Variants);
106+
if (Entry.Variants.empty())
107+
return;
108+
109+
Entry.pBackend = std::move(pHolder);
110+
m_Backends.push_back(std::move(Entry));
111+
}
112+
catch (...)
113+
{
114+
}
115+
}
116+
60117
} // namespace Diligent

0 commit comments

Comments
 (0)