Skip to content

Commit 4b9cddf

Browse files
MikhailGorobetsTheMostDiligent
authored andcommitted
Implement SuperResolution API and factory infrastructure
1 parent 9c44db2 commit 4b9cddf

File tree

14 files changed

+439
-115
lines changed

14 files changed

+439
-115
lines changed

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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 "SuperResolution.h"
30+
#include "ObjectBase.hpp"
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_Name{Desc.Name != nullptr ? Desc.Name : ""},
47+
m_Desc{Desc}
48+
{
49+
m_Desc.Name = m_Name.c_str();
50+
}
51+
52+
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_SuperResolution, TBase)
53+
54+
virtual const SuperResolutionDesc& DILIGENT_CALL_TYPE GetDesc() const override final
55+
{
56+
return m_Desc;
57+
}
58+
59+
virtual void DILIGENT_CALL_TYPE GetJitterOffset(Uint32 Index, float& JitterX, float& JitterY) const override final
60+
{
61+
if (!m_JitterPattern.empty())
62+
{
63+
const Uint32 WrappedIndex = Index % static_cast<Uint32>(m_JitterPattern.size());
64+
JitterX = m_JitterPattern[WrappedIndex].X;
65+
JitterY = m_JitterPattern[WrappedIndex].Y;
66+
}
67+
else
68+
{
69+
JitterX = 0.0f;
70+
JitterY = 0.0f;
71+
}
72+
}
73+
74+
protected:
75+
struct JitterOffset
76+
{
77+
float X = 0.0f;
78+
float Y = 0.0f;
79+
};
80+
81+
const std::string m_Name;
82+
SuperResolutionDesc m_Desc;
83+
std::vector<JitterOffset> m_JitterPattern;
84+
};
85+
86+
} // 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: 16 additions & 23 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,35 +259,33 @@ 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

284-
/// \param [in] Index - Frame index. The sequence wraps automatically.
285-
/// \param [out] pJitterX - Jitter offset X in pixel space, typically in [-0.5, 0.5] range.
286-
/// \param [out] pJitterY - Jitter offset Y in pixel space, typically in [-0.5, 0.5] range.
278+
/// \param [in] Index - Frame index. The sequence wraps automatically.
279+
/// \param [out] JitterX - Jitter offset X in pixel space, typically in [-0.5, 0.5] range.
280+
/// \param [out] JitterY - Jitter offset Y in pixel space, typically in [-0.5, 0.5] range.
287281
///
288282
/// For temporal upscaling, the upscaler provides a recommended jitter pattern
289283
/// (e.g. Halton sequence) that should be applied to the projection matrix each frame.
290284
/// For spatial upscaling, both values are set to zero.
291285
VIRTUAL void METHOD(GetJitterOffset)(THIS_
292286
Uint32 Index,
293-
float* pJitterX,
294-
float* pJitterY) CONST PURE;
287+
float REF JitterX,
288+
float REF JitterY) CONST PURE;
295289

296290

297291
/// Executes the super resolution upscaler.
@@ -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

0 commit comments

Comments
 (0)