Skip to content

Commit 7f8e230

Browse files
Add SuperResolution for D3D12
1 parent 1764aac commit 7f8e230

17 files changed

Lines changed: 1312 additions & 100 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: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
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

7+
if(D3D12_SUPPORTED)
8+
# Fetch DirectSR headers
9+
FetchContent_DeclareShallowGit(DirectSR-Headers
10+
GIT_REPOSITORY https://github.com/MikhailGorobets/DirectSR-Headers.git
11+
GIT_TAG dev
12+
)
13+
FetchContent_MakeAvailable(DirectSR-Headers)
14+
endif()
15+
716
set(INCLUDE
17+
include/SuperResolutionBase.hpp
18+
include/SuperResolutionInternal.hpp
819
)
920

1021
set(INTERFACE
@@ -18,6 +29,7 @@ set(SOURCE
1829
)
1930

2031
if(D3D12_SUPPORTED)
32+
list(APPEND INCLUDE include/SuperResolution_D3D12.hpp)
2133
list(APPEND SOURCE src/SuperResolution_D3D12.cpp)
2234
endif()
2335

@@ -29,6 +41,7 @@ set(DLL_SOURCE
2941
add_library(Diligent-SuperResolutionInterface INTERFACE)
3042
target_link_libraries (Diligent-SuperResolutionInterface INTERFACE Diligent-GraphicsEngineInterface)
3143
target_include_directories(Diligent-SuperResolutionInterface INTERFACE interface)
44+
target_compile_definitions(Diligent-SuperResolutionInterface INTERFACE SUPER_RESOLUTION_SUPPORTED=1)
3245

3346
add_library(Diligent-SuperResolution-static STATIC
3447
${SOURCE} ${INTERFACE} ${INCLUDE}
@@ -45,21 +58,25 @@ endif()
4558
target_include_directories(Diligent-SuperResolution-static
4659
PRIVATE
4760
include
61+
../GraphicsEngine/include
62+
../GraphicsEngineD3DBase/include
63+
../GraphicsEngineNextGenBase/include
4864
)
4965

5066
target_compile_definitions(Diligent-SuperResolution-shared PUBLIC DILIGENT_SUPER_RESOLUTION_SHARED=1)
5167

52-
5368
target_link_libraries(Diligent-SuperResolution-static
5469
PUBLIC
5570
Diligent-SuperResolutionInterface
5671
PRIVATE
5772
Diligent-BuildSettings
5873
Diligent-Common
74+
Diligent-GraphicsAccessories
75+
Diligent-ShaderTools
5976
)
6077

6178
if(D3D12_SUPPORTED)
62-
target_link_libraries(Diligent-SuperResolution-static PRIVATE Diligent-GraphicsEngineD3D12-static)
79+
target_link_libraries(Diligent-SuperResolution-static PRIVATE Diligent-GraphicsEngineD3D12-static DirectSR-Headers)
6380
target_include_directories(Diligent-SuperResolution-static PRIVATE ../GraphicsEngineD3D12/include)
6481
endif()
6582

@@ -86,7 +103,7 @@ endif()
86103
if (MINGW_BUILD)
87104
# Restrict export to GetSuperResolutionFactory
88105
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/export.map
89-
"{ global: *GetSuperResolutionFactory*; local: *; };"
106+
"{ global: *CreateSuperResolutionFactory*; local: *; };"
90107
)
91108
target_link_options(Diligent-SuperResolution-shared PRIVATE LINKER:--version-script=export.map)
92109
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
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 "SuperResolutionInternal.hpp"
30+
31+
#include "../../GraphicsEngineD3D12/include/pch.h"
32+
#include <directsr.h>
33+
34+
namespace Diligent
35+
{
36+
37+
CComPtr<IDSRDevice> CreateDSRDeviceD3D12(IRenderDevice* pDevice);
38+
39+
void EnumerateVariantsD3D12(IDSRDevice* pDSRDevice,
40+
std::vector<SuperResolutionInfo>& Variants);
41+
42+
void GetSourceSettingsD3D12(IDSRDevice* pDSRDevice,
43+
const SuperResolutionSourceSettingsAttribs& Attribs,
44+
SuperResolutionSourceSettings& Settings);
45+
46+
void CreateSuperResolutionD3D12(IRenderDevice* pDevice,
47+
IDSRDevice* pDSRDevice,
48+
const SuperResolutionDesc& Desc,
49+
ISuperResolution** ppUpscaler);
50+
51+
} // namespace Diligent

Graphics/SuperResolution/interface/SuperResolution.h

Lines changed: 10 additions & 10 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
///
@@ -263,21 +266,19 @@ typedef struct ExecuteSuperResolutionAttribs ExecuteSuperResolutionAttribs;
263266
#define DILIGENT_INTERFACE_NAME ISuperResolution
264267
#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
265268

266-
#define ISuperResolutionInclusiveMethods \
267-
IDeviceObjectInclusiveMethods; \
269+
#define ISuperResolutionInclusiveMethods \
270+
IObjectInclusiveMethods; \
268271
ISuperResolutionMethods SuperResolution
269272

270273
/// Super resolution upscaler interface.
271274
///
272275
/// The super resolution object encapsulates a hardware-accelerated or software-based super resolution
273276
/// effect (e.g., MetalFX on Metal, DirectSR on D3D12).
274277
/// It is created via ISuperResolutionFactory::CreateSuperResolution().
275-
DILIGENT_BEGIN_INTERFACE(ISuperResolution, IDeviceObject)
278+
DILIGENT_BEGIN_INTERFACE(ISuperResolution, IObject)
276279
{
277-
#if DILIGENT_CPP_INTERFACE
278280
/// Returns the super resolution description used to create the object.
279-
virtual const SuperResolutionDesc& METHOD(GetDesc)() const override = 0;
280-
#endif
281+
VIRTUAL const SuperResolutionDesc REF METHOD(GetDesc)(THIS) CONST PURE;
281282

282283
/// Returns the optimal jitter offset for the given frame index.
283284

@@ -315,8 +316,7 @@ DILIGENT_END_INTERFACE
315316
#if DILIGENT_C_INTERFACE
316317

317318
// clang-format off
318-
# define ISuperResolution_GetDesc(This) (const struct SuperResolutionDesc*)IDeviceObject_GetDesc(This)
319-
319+
# define ISuperResolution_GetDesc(This) CALL_IFACE_METHOD(SuperResolution, GetDesc, This)
320320
# define ISuperResolution_GetJitterOffset(This, ...) CALL_IFACE_METHOD(SuperResolution, GetJitterOffset, This, __VA_ARGS__)
321321
# define ISuperResolution_Execute(This, ...) CALL_IFACE_METHOD(SuperResolution, Execute, This, __VA_ARGS__)
322322

0 commit comments

Comments
 (0)