Skip to content

Commit 65bacb2

Browse files
Implement SuperResolution API and factory infrastructure
1 parent 1764aac commit 65bacb2

14 files changed

Lines changed: 425 additions & 110 deletions

CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ set(VULKAN_SUPPORTED FALSE CACHE INTERNAL "Vulkan is not supported")
5959
set(METAL_SUPPORTED FALSE CACHE INTERNAL "Metal is not supported")
6060
set(WEBGPU_SUPPORTED FALSE CACHE INTERNAL "WebGPU is not supported")
6161
set(ARCHIVER_SUPPORTED FALSE CACHE INTERNAL "Archiver is not supported")
62+
set(SUPER_RESOLUTION_SUPPORTED FALSE CACHE INTERNAL "Super resolution is not supported")
6263

6364
set(DILIGENT_CORE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "DiligentCore module source directory")
6465

@@ -180,10 +181,11 @@ if(MINGW)
180181
endif()
181182

182183
if(PLATFORM_WIN32)
183-
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on Win32 platform")
184-
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is supported on Win32 platform")
185-
set(WEBGPU_SUPPORTED TRUE CACHE INTERNAL "WebGPU is supported on Win32 platform")
186-
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Win32 platform")
184+
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on Win32 platform")
185+
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is supported on Win32 platform")
186+
set(WEBGPU_SUPPORTED TRUE CACHE INTERNAL "WebGPU is supported on Win32 platform")
187+
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Win32 platform")
188+
set(SUPER_RESOLUTION_SUPPORTED TRUE CACHE INTERNAL "Super resolution is supported on Win32 platform")
187189
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_WIN32=1)
188190
elseif(PLATFORM_UNIVERSAL_WINDOWS)
189191
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Universal Windows platform")
@@ -303,6 +305,7 @@ else()
303305
option(DILIGENT_NO_WEBGPU "Disable WebGPU backend" ON)
304306
endif()
305307
option(DILIGENT_NO_ARCHIVER "Do not build archiver" OFF)
308+
option(DILIGENT_NO_SUPER_RESOLUTION "Do not build super resolution" OFF)
306309

307310
option(DILIGENT_EMSCRIPTEN_STRIP_DEBUG_INFO "Strip debug information from WebAsm binaries" OFF)
308311

@@ -329,6 +332,9 @@ endif()
329332
if(${DILIGENT_NO_ARCHIVER})
330333
set(ARCHIVER_SUPPORTED FALSE CACHE INTERNAL "Archiver is forcibly disabled")
331334
endif()
335+
if(${DILIGENT_NO_SUPER_RESOLUTION})
336+
set(SUPER_RESOLUTION_SUPPORTED FALSE CACHE INTERNAL "Super resolution is forcibly disabled")
337+
endif()
332338

333339
if(NOT (${D3D11_SUPPORTED} OR ${D3D12_SUPPORTED} OR ${GL_SUPPORTED} OR ${GLES_SUPPORTED} OR ${VULKAN_SUPPORTED} OR ${METAL_SUPPORTED} OR ${WEBGPU_SUPPORTED}))
334340
message(FATAL_ERROR "No rendering backends are select to build")

Graphics/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,7 @@ if(ARCHIVER_SUPPORTED)
5656
endif()
5757

5858
add_subdirectory(GraphicsTools)
59-
add_subdirectory(SuperResolution)
59+
60+
if(SUPER_RESOLUTION_SUPPORTED)
61+
add_subdirectory(SuperResolution)
62+
endif()

Graphics/SuperResolution/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
cmake_minimum_required (VERSION 3.10)
1+
cmake_minimum_required (VERSION 3.11)
22

33
include(../../BuildTools/CMake/BuildUtils.cmake)
44

55
project(Diligent-SuperResolution CXX)
66

77
set(INCLUDE
8+
include/SuperResolutionBase.hpp
9+
include/SuperResolutionInternal.hpp
810
)
911

1012
set(INTERFACE
@@ -29,6 +31,7 @@ set(DLL_SOURCE
2931
add_library(Diligent-SuperResolutionInterface INTERFACE)
3032
target_link_libraries (Diligent-SuperResolutionInterface INTERFACE Diligent-GraphicsEngineInterface)
3133
target_include_directories(Diligent-SuperResolutionInterface INTERFACE interface)
34+
target_compile_definitions(Diligent-SuperResolutionInterface INTERFACE SUPER_RESOLUTION_SUPPORTED=1)
3235

3336
add_library(Diligent-SuperResolution-static STATIC
3437
${SOURCE} ${INTERFACE} ${INCLUDE}
@@ -45,17 +48,21 @@ endif()
4548
target_include_directories(Diligent-SuperResolution-static
4649
PRIVATE
4750
include
51+
../GraphicsEngine/include
52+
../GraphicsEngineD3DBase/include
53+
../GraphicsEngineNextGenBase/include
4854
)
4955

5056
target_compile_definitions(Diligent-SuperResolution-shared PUBLIC DILIGENT_SUPER_RESOLUTION_SHARED=1)
5157

52-
5358
target_link_libraries(Diligent-SuperResolution-static
5459
PUBLIC
5560
Diligent-SuperResolutionInterface
5661
PRIVATE
5762
Diligent-BuildSettings
5863
Diligent-Common
64+
Diligent-GraphicsAccessories
65+
Diligent-ShaderTools
5966
)
6067

6168
if(D3D12_SUPPORTED)
@@ -86,7 +93,7 @@ endif()
8693
if (MINGW_BUILD)
8794
# Restrict export to GetSuperResolutionFactory
8895
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/export.map
89-
"{ global: *GetSuperResolutionFactory*; local: *; };"
96+
"{ global: *CreateSuperResolutionFactory*; local: *; };"
9097
)
9198
target_link_options(Diligent-SuperResolution-shared PRIVATE LINKER:--version-script=export.map)
9299
endif()
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
#include "ObjectBase.hpp"
30+
#include "SuperResolution.h"
31+
32+
#include <vector>
33+
#include <string>
34+
35+
namespace Diligent
36+
{
37+
38+
class SuperResolutionBase : public ObjectBase<ISuperResolution>
39+
{
40+
public:
41+
using TBase = ObjectBase<ISuperResolution>;
42+
43+
SuperResolutionBase(IReferenceCounters* pRefCounters,
44+
const SuperResolutionDesc& Desc) :
45+
TBase{pRefCounters},
46+
m_Desc{Desc}
47+
{
48+
if (Desc.Name != nullptr)
49+
{
50+
m_Name = Desc.Name;
51+
m_Desc.Name = m_Name.c_str();
52+
}
53+
}
54+
55+
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_SuperResolution, TBase)
56+
57+
virtual const SuperResolutionDesc& DILIGENT_CALL_TYPE GetDesc() const override final
58+
{
59+
return m_Desc;
60+
}
61+
62+
virtual void DILIGENT_CALL_TYPE GetJitterOffset(Uint32 Index, float* pJitterX, float* pJitterY) const override final
63+
{
64+
DEV_CHECK_ERR(pJitterX != nullptr && pJitterY != nullptr, "pJitterX and pJitterY must not be null");
65+
66+
if (!m_JitterPattern.empty())
67+
{
68+
const Uint32 WrappedIndex = Index % static_cast<Uint32>(m_JitterPattern.size());
69+
*pJitterX = m_JitterPattern[WrappedIndex].X;
70+
*pJitterY = m_JitterPattern[WrappedIndex].Y;
71+
}
72+
else
73+
{
74+
*pJitterX = 0.0f;
75+
*pJitterY = 0.0f;
76+
}
77+
}
78+
79+
protected:
80+
struct JitterOffset
81+
{
82+
float X = 0.0f;
83+
float Y = 0.0f;
84+
};
85+
86+
SuperResolutionDesc m_Desc;
87+
std::string m_Name;
88+
std::vector<JitterOffset> m_JitterPattern;
89+
};
90+
91+
} // namespace Diligent
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
#include "SuperResolutionFactory.h"
30+
31+
#include <array>
32+
#include <vector>
33+
34+
namespace Diligent
35+
{
36+
37+
enum SUPER_RESOLUTION_BACKEND : Uint8
38+
{
39+
SUPER_RESOLUTION_BACKEND_D3D12_DSR,
40+
SUPER_RESOLUTION_BACKEND_METAL_FX,
41+
SUPER_RESOLUTION_BACKEND_SOFTWARE,
42+
SUPER_RESOLUTION_BACKEND_COUNT
43+
};
44+
45+
using SuperResolutionVariants = std::array<std::vector<SuperResolutionInfo>, SUPER_RESOLUTION_BACKEND_COUNT>;
46+
47+
} // namespace Diligent

Graphics/SuperResolution/interface/SuperResolution.h

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/// \file
3030
/// Defines Diligent::ISuperResolution interface and related data structures
3131

32-
#include "../../GraphicsEngine/interface/DeviceObject.h"
32+
#include "../../../Primitives/interface/Object.h"
3333
#include "../../GraphicsEngine/interface/GraphicsTypes.h"
3434
#include "../../GraphicsEngine/interface/TextureView.h"
3535
#include "../../GraphicsEngine/interface/DeviceContext.h"
@@ -62,7 +62,10 @@ DEFINE_FLAG_ENUM_OPERATORS(SUPER_RESOLUTION_FLAGS)
6262

6363
/// This structure describes the super resolution upscaler object and is part of the creation
6464
/// parameters given to ISuperResolutionFactory::CreateSuperResolution().
65-
struct SuperResolutionDesc DILIGENT_DERIVE(DeviceObjectAttribs)
65+
struct SuperResolutionDesc
66+
{
67+
/// Object name.
68+
const Char* Name DEFAULT_INITIALIZER(nullptr);
6669

6770
/// Unique identifier of the super resolution variant to create.
6871
///
@@ -107,13 +110,6 @@ struct SuperResolutionDesc DILIGENT_DERIVE(DeviceObjectAttribs)
107110
/// Optional. Used for temporal upscaling to guide the denoiser for areas with inaccurate motion information (e.g., alpha-blended objects).
108111
TEXTURE_FORMAT ReactiveMaskFormat DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN);
109112

110-
/// Ignore history mask texture format.
111-
///
112-
/// Optional. Used for temporal upscaling to indicate regions where temporal history
113-
/// should be completely discarded (binary mask: 0 = use history, 1 = ignore history).
114-
/// Unlike the reactive mask which provides proportional control, this is a binary decision.
115-
TEXTURE_FORMAT IgnoreHistoryMaskFormat DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN);
116-
117113
/// Exposure scale texture format.
118114
///
119115
/// Optional. When auto-exposure is disabled, specifies the format of the 1x1 exposure
@@ -178,7 +174,7 @@ struct ExecuteSuperResolutionAttribs
178174
/// where temporal history should be completely discarded.
179175
/// Unlike the reactive mask which provides proportional control,
180176
/// this is a binary decision (discard or keep).
181-
/// Only used when SuperResolutionDesc::IgnoreHistoryMaskFormat != TEX_FORMAT_UNKNOWN.
177+
/// Format must be TEX_FORMAT_R8_UINT.
182178
ITextureView* pIgnoreHistoryMaskTextureSRV DEFAULT_INITIALIZER(nullptr);
183179

184180
/// Jitter offset X applied to the projection matrix (in pixels).
@@ -263,21 +259,19 @@ typedef struct ExecuteSuperResolutionAttribs ExecuteSuperResolutionAttribs;
263259
#define DILIGENT_INTERFACE_NAME ISuperResolution
264260
#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
265261

266-
#define ISuperResolutionInclusiveMethods \
267-
IDeviceObjectInclusiveMethods; \
262+
#define ISuperResolutionInclusiveMethods \
263+
IObjectInclusiveMethods; \
268264
ISuperResolutionMethods SuperResolution
269265

270266
/// Super resolution upscaler interface.
271267
///
272268
/// The super resolution object encapsulates a hardware-accelerated or software-based super resolution
273269
/// effect (e.g., MetalFX on Metal, DirectSR on D3D12).
274270
/// It is created via ISuperResolutionFactory::CreateSuperResolution().
275-
DILIGENT_BEGIN_INTERFACE(ISuperResolution, IDeviceObject)
271+
DILIGENT_BEGIN_INTERFACE(ISuperResolution, IObject)
276272
{
277-
#if DILIGENT_CPP_INTERFACE
278273
/// Returns the super resolution description used to create the object.
279-
virtual const SuperResolutionDesc& METHOD(GetDesc)() const override = 0;
280-
#endif
274+
VIRTUAL const SuperResolutionDesc REF METHOD(GetDesc)(THIS) CONST PURE;
281275

282276
/// Returns the optimal jitter offset for the given frame index.
283277

@@ -315,8 +309,7 @@ DILIGENT_END_INTERFACE
315309
#if DILIGENT_C_INTERFACE
316310

317311
// clang-format off
318-
# define ISuperResolution_GetDesc(This) (const struct SuperResolutionDesc*)IDeviceObject_GetDesc(This)
319-
312+
# define ISuperResolution_GetDesc(This) CALL_IFACE_METHOD(SuperResolution, GetDesc, This)
320313
# define ISuperResolution_GetJitterOffset(This, ...) CALL_IFACE_METHOD(SuperResolution, GetJitterOffset, This, __VA_ARGS__)
321314
# define ISuperResolution_Execute(This, ...) CALL_IFACE_METHOD(SuperResolution, Execute, This, __VA_ARGS__)
322315

Graphics/SuperResolution/interface/SuperResolutionFactory.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,14 @@ typedef struct SuperResolutionSourceSettingsAttribs SuperResolutionSourceSetting
233233
// clang-format off
234234

235235
/// SuperResolution factory interface
236+
///
237+
/// The factory is created per render device using CreateSuperResolutionFactory().
238+
/// It enumerates available super resolution backends, queries optimal settings,
239+
/// and creates upscaler instances for the device it was created with.
236240
DILIGENT_BEGIN_INTERFACE(ISuperResolutionFactory, IObject)
237241
{
238-
/// Enumerates the supported super resolution variants for the given render device.
242+
/// Enumerates the supported super resolution variants.
239243

240-
/// \param [in] pDevice - Render device to query the supported super resolution variants for.
241244
/// \param [in, out] NumVariants - Number of super resolution variants. If `Variants` is null, this
242245
/// parameter is used to return the number of supported variants.
243246
/// If `Variants` is not null, this parameter should contain the maximum number
@@ -246,14 +249,12 @@ DILIGENT_BEGIN_INTERFACE(ISuperResolutionFactory, IObject)
246249
/// \param [out] Variants - Array to receive the supported super resolution variants.
247250
/// Each variant is described by SuperResolutionInfo structure.
248251
VIRTUAL void METHOD(EnumerateVariants)(THIS_
249-
IRenderDevice* pDevice,
250252
Uint32 REF NumVariants,
251253
SuperResolutionInfo* Variants) PURE;
252254

253255

254256
/// Returns the optimal source (input) settings for super resolution upscaling.
255257

256-
/// \param [in] pDevice - Render device to query the optimal source settings for.
257258
/// \param [in] Attribs - Attributes, see Diligent::SuperResolutionSourceSettingsAttribs for details.
258259
/// \param [out] Settings - On success, receives the optimal source settings,
259260
/// see Diligent::SuperResolutionSourceSettings for details.
@@ -262,14 +263,12 @@ DILIGENT_BEGIN_INTERFACE(ISuperResolutionFactory, IObject)
262263
/// Use this method to determine the optimal render resolution before creating
263264
/// the upscaler object.
264265
VIRTUAL void METHOD(GetSourceSettings)(THIS_
265-
IRenderDevice* pDevice,
266266
const SuperResolutionSourceSettingsAttribs REF Attribs,
267267
SuperResolutionSourceSettings REF Settings) CONST PURE;
268268

269269

270-
/// Creates a new upscaler object.
270+
/// Creates a new upscaler object.
271271

272-
/// \param [in] pDevice - Render device to create the upscaler for.
273272
/// \param [in] Desc - Super resolution upscaler description, see Diligent::SuperResolutionDesc for details.
274273
/// \param [out] ppUpscaler - Address of the memory location where a pointer to the
275274
/// super resolution upscaler interface will be written.
@@ -279,7 +278,6 @@ DILIGENT_BEGIN_INTERFACE(ISuperResolutionFactory, IObject)
279278
/// \remarks On backends that don't support hardware upscaling, the method will
280279
/// return nullptr.
281280
VIRTUAL void METHOD(CreateSuperResolution)(THIS_
282-
IRenderDevice* pDevice,
283281
const SuperResolutionDesc REF Desc,
284282
ISuperResolution** ppUpscaler) PURE;
285283

@@ -324,4 +322,12 @@ DILIGENT_END_INTERFACE
324322

325323
#endif
326324

325+
/// Creates a super resolution factory for the specified render device.
326+
327+
/// \param [in] pDevice - Render device to create the factory for.
328+
/// \param [out] ppFactory - Address of the memory location where a pointer to the
329+
/// super resolution factory interface will be written.
330+
void DILIGENT_GLOBAL_FUNCTION(CreateSuperResolutionFactory)(IRenderDevice* pDevice,
331+
ISuperResolutionFactory** ppFactory);
332+
327333
DILIGENT_END_NAMESPACE // namespace Diligent

0 commit comments

Comments
 (0)