Skip to content

Commit 658e0f6

Browse files
D3D12: Implement ISuperResolution using DirectSR
1 parent 6559b6c commit 658e0f6

10 files changed

Lines changed: 1111 additions & 34 deletions

Graphics/GraphicsEngineD3D12/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set(INCLUDE
4444
include/ShaderResourceCacheD3D12.hpp
4545
include/ShaderResourcesD3D12.hpp
4646
include/ShaderVariableManagerD3D12.hpp
47+
include/SuperResolutionD3D12Impl.hpp
4748
include/SwapChainD3D12Impl.hpp
4849
include/TextureD3D12Impl.hpp
4950
include/TextureViewD3D12Impl.hpp
@@ -108,6 +109,7 @@ set(SRC
108109
src/ShaderResourceCacheD3D12.cpp
109110
src/ShaderResourcesD3D12.cpp
110111
src/ShaderVariableManagerD3D12.cpp
112+
src/SuperResolutionD3D12Impl.cpp
111113
src/SwapChainD3D12Impl.cpp
112114
src/TextureD3D12Impl.cpp
113115
src/TextureViewD3D12Impl.cpp

Graphics/GraphicsEngineD3D12/include/D3D12Loader.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,6 +29,7 @@
2929

3030
#include <d3d12.h>
3131

32+
3233
namespace Diligent
3334
{
3435

@@ -48,9 +49,15 @@ using D3D12SerializeRootSignatureProcType = HRESULT(WINAPI*)(
4849
_Out_ ID3DBlob** ppBlob,
4950
_Always_(_Outptr_opt_result_maybenull_) ID3DBlob** ppErrorBlob);
5051

52+
using D3D12GetInterfaceProcType = HRESULT(WINAPI*)(
53+
_In_ REFCLSID rclsid,
54+
_In_ REFIID riid,
55+
_COM_Outptr_opt_ void** ppvDebug);
56+
5157
extern D3D12CreateDeviceProcType D3D12CreateDevice;
5258
extern D3D12GetDebugInterfaceProcType D3D12GetDebugInterface;
5359
extern D3D12SerializeRootSignatureProcType D3D12SerializeRootSignature;
60+
extern D3D12GetInterfaceProcType D3D12GetInterface;
5461

5562
HMODULE LoadD3D12Dll(const char* DLLPath = "d3d12.dll");
5663

Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include "DXCompiler.hpp"
4848
#include "RootSignature.hpp"
4949

50+
#include <directsr.h>
51+
5052

5153
// The macros below are only defined in Win SDK 19041+ and are missing in 17763
5254
#ifndef D3D12_RAYTRACING_MAX_RAY_GENERATION_SHADER_THREADS
@@ -223,6 +225,8 @@ class RenderDeviceD3D12Impl final : public RenderDeviceNextGenBase<RenderDeviceD
223225

224226
RootSignatureCacheD3D12& GetRootSignatureCache() { return m_RootSignatureCache; }
225227

228+
IDSRDevice* GetDSRDevice() const { return m_pDSRDevice; }
229+
226230
DescriptorHeapAllocation AllocateDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count = 1);
227231
DescriptorHeapAllocation AllocateGPUDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count = 1);
228232

@@ -345,6 +349,8 @@ class RenderDeviceD3D12Impl final : public RenderDeviceNextGenBase<RenderDeviceD
345349

346350
bool m_IsPSOCacheSupported = false;
347351

352+
CComPtr<IDSRDevice> m_pDSRDevice;
353+
348354
#ifdef DILIGENT_DEVELOPMENT
349355
Uint32 m_MaxD3D12DeviceVersion = 0;
350356
#endif
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
/// Declaration of Diligent::SuperResolutionD3D12Impl class
31+
32+
#include "EngineD3D12ImplTraits.hpp"
33+
#include "DeviceObjectBase.hpp"
34+
#include "SuperResolution.h"
35+
36+
#include <vector>
37+
38+
#include <directsr.h>
39+
40+
namespace Diligent
41+
{
42+
43+
/// Implementation of the ISuperResolution interface for Direct3D12 backend using DirectSR.
44+
class SuperResolutionD3D12Impl final : public DeviceObjectBase<ISuperResolution, RenderDeviceD3D12Impl, SuperResolutionDesc>
45+
{
46+
public:
47+
using TSRUpscalerBase = DeviceObjectBase<ISuperResolution, RenderDeviceD3D12Impl, SuperResolutionDesc>;
48+
49+
SuperResolutionD3D12Impl(IReferenceCounters* pRefCounters,
50+
RenderDeviceD3D12Impl* pDevice,
51+
const SuperResolutionDesc& Desc);
52+
53+
~SuperResolutionD3D12Impl();
54+
55+
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_SuperResolution, TSRUpscalerBase)
56+
57+
/// Implementation of ISuperResolution::GetOptimalJitterPattern().
58+
virtual void DILIGENT_CALL_TYPE GetOptimalJitterPattern(Uint32 Index,
59+
float* pJitterX,
60+
float* pJitterY) const override final;
61+
62+
/// Encodes the upscaling operation into the given command list.
63+
void Execute(const ExecuteSuperResolutionAttribs& Attribs);
64+
65+
private:
66+
CComPtr<IDSRSuperResEngine> m_pDSREngine;
67+
CComPtr<IDSRSuperResUpscaler> m_pDSRUpscaler;
68+
std::vector<DSR_FLOAT2> m_JitterPattern;
69+
};
70+
71+
} // namespace Diligent

0 commit comments

Comments
 (0)