Skip to content

Commit a19144b

Browse files
MikhailGorobetsTheMostDiligent
authored andcommitted
Improve super resolution validation and provider API
1 parent 6e45e45 commit a19144b

File tree

9 files changed

+203
-142
lines changed

9 files changed

+203
-142
lines changed

Graphics/SuperResolution/include/SuperResolutionBase.hpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,17 @@ namespace Diligent
5050
} \
5151
} while (false)
5252

53-
54-
55-
/// Validates super resolution description and throws an exception in case of an error.
56-
void ValidateSuperResolutionDesc(const SuperResolutionDesc& Desc) noexcept(false);
57-
58-
/// Validates super resolution description for temporal upscaling and throws an exception in case of an error.
59-
void ValidateTemporalSuperResolutionDesc(const SuperResolutionDesc& Desc) noexcept(false);
60-
6153
/// Validates super resolution source settings attributes using DEV checks.
6254
void ValidateSourceSettingsAttribs(const SuperResolutionSourceSettingsAttribs& Attribs);
6355

56+
/// Validates super resolution description and throws an exception in case of an error.
57+
void ValidateSuperResolutionDesc(const SuperResolutionDesc& Desc, const SuperResolutionInfo& Info) noexcept(false);
58+
6459
/// Validates execute super resolution attributes using DEV checks.
6560
void ValidateExecuteSuperResolutionAttribs(const SuperResolutionDesc& Desc,
61+
const SuperResolutionInfo& Info,
6662
const ExecuteSuperResolutionAttribs& Attribs);
6763

68-
/// Validates execute super resolution attributes for temporal upscaling using DEV checks.
69-
void ValidateTemporalExecuteSuperResolutionAttribs(const SuperResolutionDesc& Desc,
70-
const ExecuteSuperResolutionAttribs& Attribs);
71-
7264
class SuperResolutionBase : public ObjectBase<ISuperResolution>
7365
{
7466
public:
@@ -81,15 +73,18 @@ class SuperResolutionBase : public ObjectBase<ISuperResolution>
8173
};
8274

8375
SuperResolutionBase(IReferenceCounters* pRefCounters,
84-
const SuperResolutionDesc& Desc) :
76+
const SuperResolutionDesc& Desc,
77+
const SuperResolutionInfo& Info) :
8578
TBase{pRefCounters},
86-
m_Desc{Desc}
79+
m_Desc{Desc},
80+
m_Info{Info}
8781
{
8882
if (Desc.Name != nullptr)
8983
{
9084
m_Name = Desc.Name;
9185
m_Desc.Name = m_Name.c_str();
9286
}
87+
ValidateSuperResolutionDesc(m_Desc, m_Info);
9388
}
9489

9590
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_SuperResolution, TBase)
@@ -116,6 +111,7 @@ class SuperResolutionBase : public ObjectBase<ISuperResolution>
116111

117112
protected:
118113
SuperResolutionDesc m_Desc;
114+
SuperResolutionInfo m_Info;
119115
std::string m_Name;
120116
std::vector<JitterOffset> m_JitterPattern;
121117
};

Graphics/SuperResolution/include/SuperResolutionProvider.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
#include "SuperResolutionFactory.h"
3030
#include "SuperResolution.h"
31+
#include "SuperResolutionBase.hpp"
3132

33+
#include <algorithm>
3234
#include <vector>
3335

3436
namespace Diligent
@@ -43,9 +45,31 @@ class SuperResolutionProvider
4345
virtual void EnumerateVariants(std::vector<SuperResolutionInfo>& Variants) = 0;
4446

4547
virtual void GetSourceSettings(const SuperResolutionSourceSettingsAttribs& Attribs,
46-
SuperResolutionSourceSettings& Settings) = 0;
48+
SuperResolutionSourceSettings& Settings)
49+
{
50+
Settings = {};
51+
52+
ValidateSourceSettingsAttribs(Attribs);
53+
54+
float ScaleFactor = 1.0f;
55+
switch (Attribs.OptimizationType)
56+
{
57+
// clang-format off
58+
case SUPER_RESOLUTION_OPTIMIZATION_TYPE_MAX_QUALITY: ScaleFactor = 1.0f / 1.3f; break;
59+
case SUPER_RESOLUTION_OPTIMIZATION_TYPE_HIGH_QUALITY: ScaleFactor = 1.0f / 1.5f; break;
60+
case SUPER_RESOLUTION_OPTIMIZATION_TYPE_BALANCED: ScaleFactor = 1.0f / 1.7f; break;
61+
case SUPER_RESOLUTION_OPTIMIZATION_TYPE_HIGH_PERFORMANCE: ScaleFactor = 0.5f; break;
62+
case SUPER_RESOLUTION_OPTIMIZATION_TYPE_MAX_PERFORMANCE: ScaleFactor = 1.0f / 3.0f; break;
63+
default: ScaleFactor = 1.0f / 1.7f; break;
64+
// clang-format on
65+
}
66+
67+
Settings.OptimalInputWidth = std::max(1u, static_cast<Uint32>(Attribs.OutputWidth * ScaleFactor));
68+
Settings.OptimalInputHeight = std::max(1u, static_cast<Uint32>(Attribs.OutputHeight * ScaleFactor));
69+
}
4770

4871
virtual void CreateSuperResolution(const SuperResolutionDesc& Desc,
72+
const SuperResolutionInfo& Info,
4973
ISuperResolution** ppUpscaler) = 0;
5074
};
5175

Graphics/SuperResolution/interface/SuperResolutionFactory.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_SPATIAL_CAP_FLAGS, Uint32)
6464
/// as opposed to a custom software fallback.
6565
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NATIVE = 1u << 0,
6666

67-
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_LAST = SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NATIVE
67+
/// The upscaler supports the sharpness control parameter.
68+
/// When set, the Sharpness field in ExecuteSuperResolutionAttribs is used.
69+
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_SHARPNESS = 1u << 1,
70+
71+
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_LAST = SUPER_RESOLUTION_SPATIAL_CAP_FLAG_SHARPNESS
6872
};
6973
DEFINE_FLAG_ENUM_OPERATORS(SUPER_RESOLUTION_SPATIAL_CAP_FLAGS)
7074

Graphics/SuperResolution/src/DLSSProviderD3D11.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase
4949
SuperResolutionD3D11_DLSS(IReferenceCounters* pRefCounters,
5050
IRenderDevice* pDevice,
5151
const SuperResolutionDesc& Desc,
52+
const SuperResolutionInfo& Info,
5253
NVSDK_NGX_Parameter* pNGXParams) :
53-
SuperResolutionBase{pRefCounters, Desc},
54+
SuperResolutionBase{pRefCounters, Desc, Info},
5455
m_pDevice{pDevice},
5556
m_pNGXParams{pNGXParams}
5657
{
57-
ValidateTemporalSuperResolutionDesc(m_Desc);
5858
PopulateHaltonJitterPattern(m_JitterPattern, 64);
5959
}
6060

@@ -66,7 +66,7 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase
6666

6767
virtual void DILIGENT_CALL_TYPE Execute(const ExecuteSuperResolutionAttribs& Attribs) override final
6868
{
69-
ValidateTemporalExecuteSuperResolutionAttribs(m_Desc, Attribs);
69+
ValidateExecuteSuperResolutionAttribs(m_Desc, m_Info, Attribs);
7070

7171
NVSDK_NGX_Handle* pDLSSFeature = AcquireFeature(Attribs);
7272
if (pDLSSFeature == nullptr)
@@ -188,12 +188,12 @@ class DLSSProviderD3D11 final : public SuperResolutionProvider
188188
GetDLSSSourceSettings(m_pNGXParams, Attribs, Settings);
189189
}
190190

191-
virtual void CreateSuperResolution(const SuperResolutionDesc& Desc, ISuperResolution** ppUpscaler) override final
191+
virtual void CreateSuperResolution(const SuperResolutionDesc& Desc, const SuperResolutionInfo& Info, ISuperResolution** ppUpscaler) override final
192192
{
193193
DEV_CHECK_ERR(m_pDevice != nullptr, "Render device must not be null");
194194
DEV_CHECK_ERR(ppUpscaler != nullptr, "ppUpscaler must not be null");
195195

196-
SuperResolutionD3D11_DLSS* pUpscaler = NEW_RC_OBJ(GetRawAllocator(), "SuperResolutionD3D11_DLSS instance", SuperResolutionD3D11_DLSS)(m_pDevice, Desc, m_pNGXParams);
196+
SuperResolutionD3D11_DLSS* pUpscaler = NEW_RC_OBJ(GetRawAllocator(), "SuperResolutionD3D11_DLSS instance", SuperResolutionD3D11_DLSS)(m_pDevice, Desc, Info, m_pNGXParams);
197197
pUpscaler->QueryInterface(IID_SuperResolution, reinterpret_cast<IObject**>(ppUpscaler));
198198
}
199199

Graphics/SuperResolution/src/DLSSProviderD3D12.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ class SuperResolutionD3D12_DLSS final : public SuperResolutionBase
4949
SuperResolutionD3D12_DLSS(IReferenceCounters* pRefCounters,
5050
IRenderDevice* pDevice,
5151
const SuperResolutionDesc& Desc,
52+
const SuperResolutionInfo& Info,
5253
NVSDK_NGX_Parameter* pNGXParams) :
53-
SuperResolutionBase{pRefCounters, Desc},
54+
SuperResolutionBase{pRefCounters, Desc, Info},
5455
m_pDevice{pDevice},
5556
m_pNGXParams{pNGXParams}
5657
{
57-
ValidateTemporalSuperResolutionDesc(m_Desc);
5858
PopulateHaltonJitterPattern(m_JitterPattern, 64);
5959
}
6060

@@ -66,7 +66,7 @@ class SuperResolutionD3D12_DLSS final : public SuperResolutionBase
6666

6767
virtual void DILIGENT_CALL_TYPE Execute(const ExecuteSuperResolutionAttribs& Attribs) override final
6868
{
69-
ValidateTemporalExecuteSuperResolutionAttribs(m_Desc, Attribs);
69+
ValidateExecuteSuperResolutionAttribs(m_Desc, m_Info, Attribs);
7070

7171
NVSDK_NGX_Handle* pDLSSFeature = AcquireFeature(Attribs);
7272
if (pDLSSFeature == nullptr)
@@ -203,12 +203,12 @@ class DLSSProviderD3D12 final : public SuperResolutionProvider
203203
GetDLSSSourceSettings(m_pNGXParams, Attribs, Settings);
204204
}
205205

206-
virtual void CreateSuperResolution(const SuperResolutionDesc& Desc, ISuperResolution** ppUpscaler) override final
206+
virtual void CreateSuperResolution(const SuperResolutionDesc& Desc, const SuperResolutionInfo& Info, ISuperResolution** ppUpscaler) override final
207207
{
208208
DEV_CHECK_ERR(m_pDevice != nullptr, "Render device must not be null");
209209
DEV_CHECK_ERR(ppUpscaler != nullptr, "ppUpscaler must not be null");
210210

211-
SuperResolutionD3D12_DLSS* pUpscaler = NEW_RC_OBJ(GetRawAllocator(), "SuperResolutionD3D12_DLSS instance", SuperResolutionD3D12_DLSS)(m_pDevice, Desc, m_pNGXParams);
211+
SuperResolutionD3D12_DLSS* pUpscaler = NEW_RC_OBJ(GetRawAllocator(), "SuperResolutionD3D12_DLSS instance", SuperResolutionD3D12_DLSS)(m_pDevice, Desc, Info, m_pNGXParams);
212212
pUpscaler->QueryInterface(IID_SuperResolution, reinterpret_cast<IObject**>(ppUpscaler));
213213
}
214214

Graphics/SuperResolution/src/DLSSProviderVk.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ class SuperResolutionVk_DLSS final : public SuperResolutionBase
5050
SuperResolutionVk_DLSS(IReferenceCounters* pRefCounters,
5151
IRenderDevice* pDevice,
5252
const SuperResolutionDesc& Desc,
53+
const SuperResolutionInfo& Info,
5354
NVSDK_NGX_Parameter* pNGXParams) :
54-
SuperResolutionBase{pRefCounters, Desc},
55+
SuperResolutionBase{pRefCounters, Desc, Info},
5556
m_pDevice{pDevice},
5657
m_pNGXParams{pNGXParams}
5758
{
58-
ValidateTemporalSuperResolutionDesc(m_Desc);
5959
PopulateHaltonJitterPattern(m_JitterPattern, 64);
6060
}
6161

@@ -67,7 +67,7 @@ class SuperResolutionVk_DLSS final : public SuperResolutionBase
6767

6868
virtual void DILIGENT_CALL_TYPE Execute(const ExecuteSuperResolutionAttribs& Attribs) override final
6969
{
70-
ValidateTemporalExecuteSuperResolutionAttribs(m_Desc, Attribs);
70+
ValidateExecuteSuperResolutionAttribs(m_Desc, m_Info, Attribs);
7171

7272
NVSDK_NGX_Handle* pDLSSFeature = AcquireFeature(Attribs);
7373
if (pDLSSFeature == nullptr)
@@ -242,12 +242,12 @@ class DLSSProviderVk final : public SuperResolutionProvider
242242
GetDLSSSourceSettings(m_pNGXParams, Attribs, Settings);
243243
}
244244

245-
void CreateSuperResolution(const SuperResolutionDesc& Desc, ISuperResolution** ppUpscaler)
245+
void CreateSuperResolution(const SuperResolutionDesc& Desc, const SuperResolutionInfo& Info, ISuperResolution** ppUpscaler)
246246
{
247247
DEV_CHECK_ERR(m_pDevice != nullptr, "Render device must not be null");
248248
DEV_CHECK_ERR(ppUpscaler != nullptr, "ppUpscaler must not be null");
249249

250-
SuperResolutionVk_DLSS* pUpscaler = NEW_RC_OBJ(GetRawAllocator(), "SuperResolutionVk_DLSS instance", SuperResolutionVk_DLSS)(m_pDevice, Desc, m_pNGXParams);
250+
SuperResolutionVk_DLSS* pUpscaler = NEW_RC_OBJ(GetRawAllocator(), "SuperResolutionVk_DLSS instance", SuperResolutionVk_DLSS)(m_pDevice, Desc, Info, m_pNGXParams);
251251
pUpscaler->QueryInterface(IID_SuperResolution, reinterpret_cast<IObject**>(ppUpscaler));
252252
}
253253

Graphics/SuperResolution/src/DSRProviderD3D12.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class SuperResolutionD3D12_DSR final : public SuperResolutionBase
9696
SuperResolutionD3D12_DSR(IReferenceCounters* pRefCounters,
9797
RenderDeviceD3D12Impl* pDevice,
9898
const SuperResolutionDesc& Desc,
99+
const SuperResolutionInfo& Info,
99100
IDSRDevice* pDSRDevice);
100101

101102
~SuperResolutionD3D12_DSR();
@@ -111,13 +112,13 @@ class SuperResolutionD3D12_DSR final : public SuperResolutionBase
111112
SuperResolutionD3D12_DSR::SuperResolutionD3D12_DSR(IReferenceCounters* pRefCounters,
112113
RenderDeviceD3D12Impl* pDevice,
113114
const SuperResolutionDesc& Desc,
115+
const SuperResolutionInfo& Info,
114116
IDSRDevice* pDSRDevice) :
115-
SuperResolutionBase{pRefCounters, Desc},
117+
SuperResolutionBase{pRefCounters, Desc, Info},
116118
m_pDevice{pDevice},
117119
m_DSRUpscalers(pDevice->GetCommandQueueCount())
118120
{
119121

120-
ValidateTemporalSuperResolutionDesc(m_Desc);
121122
VERIFY_SUPER_RESOLUTION(m_Desc.Name, Desc.MotionFormat == TEX_FORMAT_RG16_FLOAT, "MotionFormat must be TEX_FORMAT_RG16_FLOAT. Got: ", GetTextureFormatAttribs(Desc.MotionFormat).Name);
122123
VERIFY_SUPER_RESOLUTION(m_Desc.Name, (Desc.Flags & SUPER_RESOLUTION_FLAG_AUTO_EXPOSURE) != 0 || Desc.ExposureFormat != TEX_FORMAT_UNKNOWN,
123124
"ExposureFormat must not be TEX_FORMAT_UNKNOWN when SUPER_RESOLUTION_FLAG_AUTO_EXPOSURE is not set. "
@@ -169,7 +170,7 @@ SuperResolutionD3D12_DSR::~SuperResolutionD3D12_DSR() = default;
169170

170171
void DILIGENT_CALL_TYPE SuperResolutionD3D12_DSR::Execute(const ExecuteSuperResolutionAttribs& Attribs)
171172
{
172-
ValidateTemporalExecuteSuperResolutionAttribs(m_Desc, Attribs);
173+
ValidateExecuteSuperResolutionAttribs(m_Desc, m_Info, Attribs);
173174
DEV_CHECK_SUPER_RESOLUTION(m_Desc.Name, Attribs.CameraNear > 0, "CameraNear must be greater than zero for temporal upscaling");
174175
DEV_CHECK_SUPER_RESOLUTION(m_Desc.Name, Attribs.CameraFar > 0, "CameraFar must be greater than zero for temporal upscaling.");
175176
DEV_CHECK_SUPER_RESOLUTION(m_Desc.Name, Attribs.CameraFovAngleVert > 0, "CameraFovAngleVert must be greater than zero for temporal upscaling.");
@@ -361,13 +362,14 @@ class DSRProviderD3D12 final : public SuperResolutionProvider
361362
}
362363

363364
virtual void CreateSuperResolution(const SuperResolutionDesc& Desc,
365+
const SuperResolutionInfo& Info,
364366
ISuperResolution** ppUpscaler) override final
365367
{
366368
DEV_CHECK_ERR(m_pDSRDevice != nullptr, "DirectSR device must not be null");
367369
DEV_CHECK_ERR(m_pDevice != nullptr, "Render device must not be null");
368370

369371
RenderDeviceD3D12Impl* pDeviceD3D12 = ClassPtrCast<RenderDeviceD3D12Impl>(m_pDevice.RawPtr());
370-
SuperResolutionD3D12_DSR* pUpscaler = NEW_RC_OBJ(GetRawAllocator(), "SuperResolutionD3D12_DSR instance", SuperResolutionD3D12_DSR)(pDeviceD3D12, Desc, m_pDSRDevice);
372+
SuperResolutionD3D12_DSR* pUpscaler = NEW_RC_OBJ(GetRawAllocator(), "SuperResolutionD3D12_DSR instance", SuperResolutionD3D12_DSR)(pDeviceD3D12, Desc, Info, m_pDSRDevice);
371373
pUpscaler->QueryInterface(IID_SuperResolution, reinterpret_cast<IObject**>(ppUpscaler));
372374
}
373375

0 commit comments

Comments
 (0)