Skip to content

Commit e2fde28

Browse files
Added ISuperResolutionUpscaler interface and SuperResolution device feature
1 parent acb6ac0 commit e2fde28

29 files changed

Lines changed: 388 additions & 25 deletions

Graphics/GraphicsEngine/interface/DeviceContext.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "ShaderBindingTable.h"
5959
#include "DeviceMemory.h"
6060
#include "CommandQueue.h"
61+
#include "SuperResolutionUpscaler.h"
6162

6263
DILIGENT_BEGIN_NAMESPACE(Diligent)
6364

@@ -3750,6 +3751,21 @@ DILIGENT_BEGIN_INTERFACE(IDeviceContext, IObject)
37503751

37513752
/// Returns the device context statistics, see Diligent::DeviceContextStats.
37523753
VIRTUAL const DeviceContextStats REF METHOD(GetStats)(THIS) CONST PURE;
3754+
3755+
3756+
/// Executes the hardware super resolution upscaler.
3757+
3758+
/// \param [in] Attribs - Upscale operation attributes, see Diligent::ExecuteSuperResolutionAttribs.
3759+
/// \param [in] pUpscaler - Super resolution upscaler object to execute.
3760+
///
3761+
/// \remarks The command must be called outside of a render pass.
3762+
/// All input textures must be in the appropriate states or
3763+
/// TransitionMode should be set to RESOURCE_STATE_TRANSITION_MODE_TRANSITION.
3764+
///
3765+
/// \remarks Supported contexts: graphics.
3766+
VIRTUAL void METHOD(ExecuteSuperResolution)(THIS_
3767+
const ExecuteSuperResolutionAttribs REF Attribs,
3768+
ISuperResolutionUpscaler* pUpscaler) PURE;
37533769
};
37543770
DILIGENT_END_INTERFACE
37553771

@@ -3829,6 +3845,7 @@ DILIGENT_END_INTERFACE
38293845
# define IDeviceContext_BindSparseResourceMemory(This, ...) CALL_IFACE_METHOD(DeviceContext, BindSparseResourceMemory, This, __VA_ARGS__)
38303846
# define IDeviceContext_ClearStats(This) CALL_IFACE_METHOD(DeviceContext, ClearStats, This)
38313847
# define IDeviceContext_GetStats(This) CALL_IFACE_METHOD(DeviceContext, GetStats, This)
3848+
# define IDeviceContext_ExecuteSuperResolution(This, ...) CALL_IFACE_METHOD(DeviceContext, ExecuteSuperResolution, This, __VA_ARGS__)
38323849

38333850
// clang-format on
38343851

Graphics/GraphicsEngine/interface/GraphicsTypes.h

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,10 @@ struct DeviceFeatures
18561856
/// Indicates if device supports formatted buffers.
18571857
DEVICE_FEATURE_STATE FormattedBuffers DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);
18581858

1859+
/// Indicates if the device supports hardware super resolution (upscaling).
1860+
/// MetalFX on Metal, DirectSR on D3D12.
1861+
DEVICE_FEATURE_STATE SuperResolution DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);
1862+
18591863
#if DILIGENT_CPP_INTERFACE
18601864
constexpr DeviceFeatures() noexcept {}
18611865

@@ -1906,11 +1910,12 @@ struct DeviceFeatures
19061910
Handler(TextureSubresourceViews) \
19071911
Handler(NativeMultiDraw) \
19081912
Handler(AsyncShaderCompilation) \
1909-
Handler(FormattedBuffers)
1913+
Handler(FormattedBuffers) \
1914+
Handler(SuperResolution)
19101915

19111916
explicit constexpr DeviceFeatures(DEVICE_FEATURE_STATE State) noexcept
19121917
{
1913-
static_assert(sizeof(*this) == 47, "Did you add a new feature to DeviceFeatures? Please add it to ENUMERATE_DEVICE_FEATURES.");
1918+
static_assert(sizeof(*this) == 48, "Did you add a new feature to DeviceFeatures? Please add it to ENUMERATE_DEVICE_FEATURES.");
19141919
#define INIT_FEATURE(Feature) Feature = State;
19151920
ENUMERATE_DEVICE_FEATURES(INIT_FEATURE)
19161921
#undef INIT_FEATURE
@@ -3251,6 +3256,38 @@ struct SparseResourceProperties
32513256
typedef struct SparseResourceProperties SparseResourceProperties;
32523257

32533258

3259+
/// Super resolution capability flags
3260+
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_FLAGS, Uint32)
3261+
{
3262+
SUPER_RESOLUTION_FLAG_NONE = 0u,
3263+
3264+
/// Supports spatial-only upscaling (single frame).
3265+
SUPER_RESOLUTION_FLAG_SPATIAL = 1u << 0,
3266+
3267+
/// Supports temporal upscaling (uses motion vectors and history).
3268+
SUPER_RESOLUTION_FLAG_TEMPORAL = 1u << 1,
3269+
3270+
SUPER_RESOLUTION_FLAG_LAST = SUPER_RESOLUTION_FLAG_TEMPORAL
3271+
};
3272+
DEFINE_FLAG_ENUM_OPERATORS(SUPER_RESOLUTION_FLAGS)
3273+
3274+
3275+
/// Super resolution properties, reported via GraphicsAdapterInfo
3276+
struct SuperResolutionProperties
3277+
{
3278+
/// Capability flags indicating supported upscaler types, see Diligent::SUPER_RESOLUTION_FLAGS.
3279+
SUPER_RESOLUTION_FLAGS Flags DEFAULT_INITIALIZER(SUPER_RESOLUTION_FLAG_NONE);
3280+
3281+
#if DILIGENT_CPP_INTERFACE
3282+
constexpr bool operator==(const SuperResolutionProperties& RHS) const
3283+
{
3284+
return Flags == RHS.Flags;
3285+
}
3286+
#endif
3287+
};
3288+
typedef struct SuperResolutionProperties SuperResolutionProperties;
3289+
3290+
32543291
/// Command queue properties
32553292
struct CommandQueueInfo
32563293
{
@@ -3342,6 +3379,9 @@ struct GraphicsAdapterInfo
33423379
/// Sparse resource properties, see Diligent::SparseResourceProperties.
33433380
SparseResourceProperties SparseResources;
33443381

3382+
/// Super resolution upscaler properties, see Diligent::SuperResolutionProperties.
3383+
SuperResolutionProperties SuperResolution;
3384+
33453385
/// Supported device features, see Diligent::DeviceFeatures.
33463386

33473387
/// The feature state indicates:
@@ -3372,23 +3412,24 @@ struct GraphicsAdapterInfo
33723412
if (!(Queues[i] == RHS.Queues[i]))
33733413
return false;
33743414

3375-
return Type == RHS.Type &&
3376-
Vendor == RHS.Vendor &&
3377-
VendorId == RHS.VendorId &&
3378-
DeviceId == RHS.DeviceId &&
3379-
NumOutputs == RHS.NumOutputs &&
3380-
Memory == RHS.Memory &&
3381-
RayTracing == RHS.RayTracing &&
3382-
WaveOp == RHS.WaveOp &&
3383-
Buffer == RHS.Buffer &&
3384-
Texture == RHS.Texture &&
3385-
Sampler == RHS.Sampler &&
3386-
MeshShader == RHS.MeshShader &&
3387-
ShadingRate == RHS.ShadingRate &&
3388-
ComputeShader == RHS.ComputeShader &&
3389-
DrawCommand == RHS.DrawCommand &&
3390-
SparseResources == RHS.SparseResources &&
3391-
Features == RHS.Features &&
3415+
return Type == RHS.Type &&
3416+
Vendor == RHS.Vendor &&
3417+
VendorId == RHS.VendorId &&
3418+
DeviceId == RHS.DeviceId &&
3419+
NumOutputs == RHS.NumOutputs &&
3420+
Memory == RHS.Memory &&
3421+
RayTracing == RHS.RayTracing &&
3422+
WaveOp == RHS.WaveOp &&
3423+
Buffer == RHS.Buffer &&
3424+
Texture == RHS.Texture &&
3425+
Sampler == RHS.Sampler &&
3426+
MeshShader == RHS.MeshShader &&
3427+
ShadingRate == RHS.ShadingRate &&
3428+
ComputeShader == RHS.ComputeShader &&
3429+
DrawCommand == RHS.DrawCommand &&
3430+
SparseResources == RHS.SparseResources &&
3431+
SuperResolution == RHS.SuperResolution &&
3432+
Features == RHS.Features &&
33923433
memcmp(Description, RHS.Description, sizeof(Description)) == 0;
33933434
}
33943435
#endif

Graphics/GraphicsEngine/interface/RenderDevice.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,21 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject)
343343
IPipelineStateCache** ppPSOCache) PURE;
344344

345345

346+
/// Creates a new super resolution upscaler object.
347+
348+
/// \param [in] Desc - Super resolution upscaler description, see Diligent::SuperResolutionUpscalerDesc for details.
349+
/// \param [out] ppUpscaler - Address of the memory location where a pointer to the
350+
/// super resolution upscaler interface will be written.
351+
/// The function calls AddRef(), so that the new object will have
352+
/// one reference.
353+
///
354+
/// \remarks On backends that don't support hardware upscaling, the method will
355+
/// return nullptr.
356+
VIRTUAL void METHOD(CreateSuperResolutionUpscaler)(THIS_
357+
const SuperResolutionUpscalerDesc REF Desc,
358+
ISuperResolutionUpscaler** ppUpscaler) PURE;
359+
360+
346361
/// Creates a deferred context.
347362

348363
/// \param [out] ppContext - Address of the memory location where a pointer to the
@@ -475,6 +490,7 @@ DILIGENT_END_INTERFACE
475490
# define IRenderDevice_CreatePipelineResourceSignature(This, ...) CALL_IFACE_METHOD(RenderDevice, CreatePipelineResourceSignature, This, __VA_ARGS__)
476491
# define IRenderDevice_CreateDeviceMemory(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateDeviceMemory, This, __VA_ARGS__)
477492
# define IRenderDevice_CreatePipelineStateCache(This, ...) CALL_IFACE_METHOD(RenderDevice, CreatePipelineStateCache, This, __VA_ARGS__)
493+
# define IRenderDevice_CreateSuperResolutionUpscaler(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateSuperResolutionUpscaler, This, __VA_ARGS__)
478494
# define IRenderDevice_CreateDeferredContext(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateDeferredContext, This, __VA_ARGS__)
479495
# define IRenderDevice_GetAdapterInfo(This) CALL_IFACE_METHOD(RenderDevice, GetAdapterInfo, This)
480496
# define IRenderDevice_GetDeviceInfo(This) CALL_IFACE_METHOD(RenderDevice, GetDeviceInfo, This)
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
/// Defines Diligent::ISuperResolutionUpscaler interface and related data structures
31+
32+
#include "DeviceObject.h"
33+
#include "GraphicsTypes.h"
34+
#include "TextureView.h"
35+
36+
DILIGENT_BEGIN_NAMESPACE(Diligent)
37+
38+
// {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}
39+
static DILIGENT_CONSTEXPR INTERFACE_ID IID_SuperResolutionUpscaler =
40+
{0xa1b2c3d4, 0xe5f6, 0x7890, {0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90}};
41+
42+
43+
/// Super resolution upscaler type
44+
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_UPSCALER_TYPE, Uint8)
45+
{
46+
/// Spatial upscaling only (single frame, no motion vectors required).
47+
SUPER_RESOLUTION_UPSCALER_TYPE_SPATIAL = 0,
48+
49+
/// Temporal upscaling (uses motion vectors and history accumulation).
50+
SUPER_RESOLUTION_UPSCALER_TYPE_TEMPORAL = 1,
51+
52+
SUPER_RESOLUTION_UPSCALER_TYPE_LAST = SUPER_RESOLUTION_UPSCALER_TYPE_TEMPORAL
53+
};
54+
55+
56+
/// Super resolution upscaler description
57+
58+
/// This structure describes the super resolution upscaler object and is part of the creation
59+
/// parameters given to IRenderDevice::CreateSuperResolutionUpscaler().
60+
struct SuperResolutionUpscalerDesc DILIGENT_DERIVE(DeviceObjectAttribs)
61+
62+
/// Upscaler type, see Diligent::SUPER_RESOLUTION_UPSCALER_TYPE.
63+
SUPER_RESOLUTION_UPSCALER_TYPE Type DEFAULT_INITIALIZER(SUPER_RESOLUTION_UPSCALER_TYPE_TEMPORAL);
64+
65+
/// Target (output) texture width.
66+
Uint32 OutputWidth DEFAULT_INITIALIZER(0);
67+
68+
/// Target (output) texture height.
69+
Uint32 OutputHeight DEFAULT_INITIALIZER(0);
70+
71+
/// Output texture format.
72+
TEXTURE_FORMAT OutputFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA16_FLOAT);
73+
74+
/// Color input texture format.
75+
TEXTURE_FORMAT ColorFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA16_FLOAT);
76+
77+
/// Depth input texture format.
78+
/// Required for temporal upscaling.
79+
TEXTURE_FORMAT DepthFormat DEFAULT_INITIALIZER(TEX_FORMAT_D32_FLOAT);
80+
81+
/// Motion vectors texture format.
82+
/// Required for temporal upscaling.
83+
TEXTURE_FORMAT MotionFormat DEFAULT_INITIALIZER(TEX_FORMAT_RG16_FLOAT);
84+
85+
/// Input (render) width.
86+
/// If zero, the upscaler will calculate optimal render resolution.
87+
Uint32 InputWidth DEFAULT_INITIALIZER(0);
88+
89+
/// Input (render) height.
90+
/// If zero, the upscaler will calculate optimal render resolution.
91+
Uint32 InputHeight DEFAULT_INITIALIZER(0);
92+
93+
/// Indicates if depth buffer uses reversed-Z (1 at near, 0 at far).
94+
Bool ReversedDepth DEFAULT_INITIALIZER(False);
95+
};
96+
typedef struct SuperResolutionUpscalerDesc SuperResolutionUpscalerDesc;
97+
98+
99+
/// Super resolution upscaler execute attributes
100+
101+
/// This structure is used by IDeviceContext::ExecuteSuperResolution().
102+
struct ExecuteSuperResolutionAttribs
103+
{
104+
/// Low-resolution color texture (shader resource view).
105+
/// This is the input image to be upscaled.
106+
ITextureView* pColorTextureSRV DEFAULT_INITIALIZER(nullptr);
107+
108+
/// Depth buffer of the low-resolution render (shader resource view).
109+
/// Required for temporal upscaling (SUPER_RESOLUTION_UPSCALER_TYPE_TEMPORAL).
110+
ITextureView* pDepthTextureSRV DEFAULT_INITIALIZER(nullptr);
111+
112+
/// Motion vectors texture (shader resource view).
113+
/// Required for temporal upscaling (SUPER_RESOLUTION_UPSCALER_TYPE_TEMPORAL).
114+
/// Expected to contain per-pixel 2D motion vectors in pixel space.
115+
ITextureView* pMotionVectorsSRV DEFAULT_INITIALIZER(nullptr);
116+
117+
/// Output (upscaled) texture (unordered access view or render target view).
118+
/// Must match SuperResolutionUpscalerDesc::OutputWidth x OutputHeight.
119+
ITextureView* pOutputTextureRTV DEFAULT_INITIALIZER(nullptr);
120+
121+
/// Jitter offset X applied to the projection matrix (in pixels).
122+
/// Used for temporal upscaling.
123+
float JitterX DEFAULT_INITIALIZER(0.0f);
124+
125+
/// Jitter offset Y applied to the projection matrix (in pixels).
126+
/// Used for temporal upscaling.
127+
float JitterY DEFAULT_INITIALIZER(0.0f);
128+
129+
/// Set to true to reset temporal history (e.g., on camera cut).
130+
Bool Reset DEFAULT_INITIALIZER(False);
131+
};
132+
typedef struct ExecuteSuperResolutionAttribs ExecuteSuperResolutionAttribs;
133+
134+
135+
// clang-format off
136+
137+
#define DILIGENT_INTERFACE_NAME ISuperResolutionUpscaler
138+
#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
139+
140+
#define ISuperResolutionUpscalerInclusiveMethods \
141+
IDeviceObjectInclusiveMethods; \
142+
ISuperResolutionUpscalerMethods SuperResolutionUpscaler
143+
144+
/// Hardware super resolution upscaler interface.
145+
///
146+
/// The super resolution upscaler object encapsulates a hardware-accelerated super resolution
147+
/// effect (e.g., MetalFX on Metal, DirectSR on D3D12).
148+
/// It is created via IRenderDevice::CreateSuperResolutionUpscaler() and executed
149+
/// via IDeviceContext::ExecuteSuperResolution().
150+
DILIGENT_BEGIN_INTERFACE(ISuperResolutionUpscaler, IDeviceObject)
151+
{
152+
#if DILIGENT_CPP_INTERFACE
153+
/// Returns the super resolution upscaler description used to create the object.
154+
virtual const SuperResolutionUpscalerDesc& METHOD(GetDesc)() const override = 0;
155+
#endif
156+
157+
/// Returns the recommended render resolution for the current configuration.
158+
///
159+
/// \param [out] pWidth - Recommended render width.
160+
/// \param [out] pHeight - Recommended render height.
161+
///
162+
/// The upscaler calculates the optimal input resolution based on the
163+
/// target resolution specified in SuperResolutionUpscalerDesc.
164+
VIRTUAL void METHOD(GetRenderResolution)(THIS_
165+
Uint32* pWidth,
166+
Uint32* pHeight) CONST PURE;
167+
};
168+
DILIGENT_END_INTERFACE
169+
170+
#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h"
171+
172+
#if DILIGENT_C_INTERFACE
173+
174+
// clang-format off
175+
176+
# define ISuperResolutionUpscaler_GetDesc(This) CALL_IFACE_METHOD(SuperResolutionUpscaler, GetDesc, This)
177+
# define ISuperResolutionUpscaler_GetRenderResolution(This, ...) CALL_IFACE_METHOD(SuperResolutionUpscaler, GetRenderResolution, This, __VA_ARGS__)
178+
179+
// clang-format on
180+
181+
#endif
182+
183+
DILIGENT_END_NAMESPACE // namespace Diligent

Graphics/GraphicsEngine/src/RenderDeviceBase.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ DeviceFeatures EnableDeviceFeatures(const DeviceFeatures& SupportedFeatures,
120120
ENABLE_FEATURE(NativeMultiDraw, "Native multi-draw commands are");
121121
ENABLE_FEATURE(AsyncShaderCompilation, "Async shader compilation is");
122122
ENABLE_FEATURE(FormattedBuffers, "Formatted buffers are");
123+
ENABLE_FEATURE(SuperResolutionUpscaler, "Super resolution upscaler is");
123124
// clang-format on
124125

125-
ASSERT_SIZEOF(DeviceFeatures, 47, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");
126+
ASSERT_SIZEOF(DeviceFeatures, 48, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");
126127

127128
return EnabledFeatures;
128129
}

Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ class DeviceContextD3D11Impl final : public DeviceContextBase<EngineD3D11ImplTra
284284
SHADING_RATE_COMBINER PrimitiveCombiner,
285285
SHADING_RATE_COMBINER TextureCombiner) override final;
286286

287+
/// Implementation of IDeviceContext::ExecuteSuperResolution() in Direct3D11 backend.
288+
virtual void DILIGENT_CALL_TYPE ExecuteSuperResolution(const ExecuteSuperResolutionAttribs& Attribs,
289+
ISuperResolutionUpscaler* pUpscaler) override final;
290+
287291
/// Implementation of IDeviceContext::BindSparseResourceMemory() in Direct3D11 backend.
288292
virtual void DILIGENT_CALL_TYPE BindSparseResourceMemory(const BindSparseResourceMemoryAttribs& Attribs) override final;
289293

0 commit comments

Comments
 (0)