Skip to content

Commit 4a5b89e

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

38 files changed

Lines changed: 1118 additions & 22 deletions

Graphics/Archiver/include/SerializationDeviceImpl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class SerializationDeviceImpl final : public RenderDeviceBase<SerializationEngin
7070
UNSUPPORTED_METHOD(void, CreateTLAS, const TopLevelASDesc& Desc, ITopLevelAS** ppTLAS)
7171
UNSUPPORTED_METHOD(void, CreateSBT, const ShaderBindingTableDesc& Desc, IShaderBindingTable** ppSBT)
7272
UNSUPPORTED_METHOD(void, CreatePipelineResourceSignature, const PipelineResourceSignatureDesc& Desc, IPipelineResourceSignature** ppSignature)
73+
UNSUPPORTED_METHOD(void, CreateSuperResolutionUpscaler, const SuperResolutionUpscalerDesc& Desc, ISuperResolutionUpscaler** ppUpscaler)
7374
UNSUPPORTED_METHOD(void, CreateDeviceMemory, const DeviceMemoryCreateInfo& CreateInfo, IDeviceMemory** ppMemory)
7475
UNSUPPORTED_METHOD(void, CreatePipelineStateCache, const PipelineStateCacheCreateInfo& CreateInfo, IPipelineStateCache** ppPSOCache)
7576
UNSUPPORTED_METHOD(void, CreateDeferredContext, IDeviceContext** ppContext)

Graphics/GraphicsEngine.NET/Mapping.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<include file="ShaderBindingTable.h" namespace="Diligent" attach="true"/>
5656
<include file="ShaderResourceBinding.h" namespace="Diligent" attach="true"/>
5757
<include file="ShaderResourceVariable.h" namespace="Diligent" attach="true"/>
58+
<include file="SuperResolutionUpscaler.h" namespace="Diligent" attach="true"/>
5859
<include file="SwapChain.h" namespace="Diligent" attach="true"/>
5960
<include file="Texture.h" namespace="Diligent" attach="true"/>
6061
<include file="TextureView.h" namespace="Diligent" attach="true"/>
@@ -299,6 +300,12 @@
299300
<!--Diligent::IQuery-->
300301
<map method="IQuery::GetData" visibility="private"/>
301302
<map param="IQuery::GetData::pData" type="void" keep-pointers="true"/>
303+
304+
<!--Diligent::ISuperResolutionUpscaler-->
305+
<map param="ISuperResolutionUpscaler::GetRenderResolution::pWidth" attribute="out"/>
306+
<map param="ISuperResolutionUpscaler::GetRenderResolution::pHeight" attribute="out"/>
307+
<map param="ISuperResolutionUpscaler::GetOptimalJitterPattern::pJitterX" attribute="out"/>
308+
<map param="ISuperResolutionUpscaler::GetOptimalJitterPattern::pJitterY" attribute="out"/>
302309
</mapping>
303310

304311
</config>

Graphics/GraphicsEngine/interface/Constants.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,19 @@ DILIGENT_BEGIN_NAMESPACE(Diligent)
6565
/// The maximum number of 4-byte inline constants in a pipeline state.
6666
#define DILIGENT_MAX_INLINE_CONSTANTS 64
6767

68-
static DILIGENT_CONSTEXPR Uint32 MAX_BUFFER_SLOTS = DILIGENT_MAX_BUFFER_SLOTS;
69-
static DILIGENT_CONSTEXPR Uint32 MAX_RENDER_TARGETS = DILIGENT_MAX_RENDER_TARGETS;
70-
static DILIGENT_CONSTEXPR Uint32 MAX_VIEWPORTS = DILIGENT_MAX_VIEWPORTS;
71-
static DILIGENT_CONSTEXPR Uint32 MAX_RESOURCE_SIGNATURES = DILIGENT_MAX_RESOURCE_SIGNATURES;
72-
static DILIGENT_CONSTEXPR Uint32 MAX_ADAPTER_QUEUES = DILIGENT_MAX_ADAPTER_QUEUES;
73-
static DILIGENT_CONSTEXPR Uint32 DEFAULT_ADAPTER_ID = DILIGENT_DEFAULT_ADAPTER_ID;
74-
static DILIGENT_CONSTEXPR Uint8 DEFAULT_QUEUE_ID = DILIGENT_DEFAULT_QUEUE_ID;
75-
static DILIGENT_CONSTEXPR Uint32 MAX_SHADING_RATES = DILIGENT_MAX_SHADING_RATES;
76-
static DILIGENT_CONSTEXPR Uint32 SHADING_RATE_X_SHIFT = DILIGENT_SHADING_RATE_X_SHIFT;
77-
static DILIGENT_CONSTEXPR Uint32 MAX_INLINE_CONSTANTS = DILIGENT_MAX_INLINE_CONSTANTS;
68+
/// The maximum number of super resolution upscaler variants.
69+
#define DILIGENT_MAX_SUPER_RESOLUTION_UPSCALERS 8
70+
71+
static DILIGENT_CONSTEXPR Uint32 MAX_BUFFER_SLOTS = DILIGENT_MAX_BUFFER_SLOTS;
72+
static DILIGENT_CONSTEXPR Uint32 MAX_RENDER_TARGETS = DILIGENT_MAX_RENDER_TARGETS;
73+
static DILIGENT_CONSTEXPR Uint32 MAX_VIEWPORTS = DILIGENT_MAX_VIEWPORTS;
74+
static DILIGENT_CONSTEXPR Uint32 MAX_RESOURCE_SIGNATURES = DILIGENT_MAX_RESOURCE_SIGNATURES;
75+
static DILIGENT_CONSTEXPR Uint32 MAX_ADAPTER_QUEUES = DILIGENT_MAX_ADAPTER_QUEUES;
76+
static DILIGENT_CONSTEXPR Uint32 DEFAULT_ADAPTER_ID = DILIGENT_DEFAULT_ADAPTER_ID;
77+
static DILIGENT_CONSTEXPR Uint8 DEFAULT_QUEUE_ID = DILIGENT_DEFAULT_QUEUE_ID;
78+
static DILIGENT_CONSTEXPR Uint32 MAX_SHADING_RATES = DILIGENT_MAX_SHADING_RATES;
79+
static DILIGENT_CONSTEXPR Uint32 SHADING_RATE_X_SHIFT = DILIGENT_SHADING_RATE_X_SHIFT;
80+
static DILIGENT_CONSTEXPR Uint32 MAX_INLINE_CONSTANTS = DILIGENT_MAX_INLINE_CONSTANTS;
81+
static DILIGENT_CONSTEXPR Uint32 MAX_SUPER_RESOLUTION_UPSCALERS = DILIGENT_MAX_SUPER_RESOLUTION_UPSCALERS;
7882

7983
DILIGENT_END_NAMESPACE // namespace Diligent

Graphics/GraphicsEngine/interface/DeviceContext.h

Lines changed: 22 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,26 @@ 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+
/// \param [in] TimeDeltaInSeconds - Time elapsed since the previous frame, in seconds.
3761+
/// Used by some upscalers to adjust temporal accumulation behavior.
3762+
/// \param [in] ResetHistory - Set to true to reset temporal history (e.g., on camera cut).
3763+
///
3764+
/// \remarks The command must be called outside of a render pass.
3765+
/// All input textures must be in the appropriate states or
3766+
/// TransitionMode should be set to RESOURCE_STATE_TRANSITION_MODE_TRANSITION.
3767+
///
3768+
/// \remarks Supported contexts: graphics.
3769+
VIRTUAL void METHOD(ExecuteSuperResolution)(THIS_
3770+
const ExecuteSuperResolutionAttribs REF Attribs,
3771+
ISuperResolutionUpscaler* pUpscaler,
3772+
float TimeDeltaInSeconds DEFAULT_VALUE(0.0f),
3773+
Bool ResetHistory DEFAULT_VALUE(False)) PURE;
37533774
};
37543775
DILIGENT_END_INTERFACE
37553776

@@ -3829,6 +3850,7 @@ DILIGENT_END_INTERFACE
38293850
# define IDeviceContext_BindSparseResourceMemory(This, ...) CALL_IFACE_METHOD(DeviceContext, BindSparseResourceMemory, This, __VA_ARGS__)
38303851
# define IDeviceContext_ClearStats(This) CALL_IFACE_METHOD(DeviceContext, ClearStats, This)
38313852
# define IDeviceContext_GetStats(This) CALL_IFACE_METHOD(DeviceContext, GetStats, This)
3853+
# define IDeviceContext_ExecuteSuperResolution(This, ...) CALL_IFACE_METHOD(DeviceContext, ExecuteSuperResolution, This, __VA_ARGS__)
38323854

38333855
// clang-format on
38343856

Graphics/GraphicsEngine/interface/GraphicsTypes.h

Lines changed: 125 additions & 2 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,120 @@ struct SparseResourceProperties
32513256
typedef struct SparseResourceProperties SparseResourceProperties;
32523257

32533258

3259+
/// Super resolution upscaler type
3260+
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_UPSCALER_TYPE, Uint8)
3261+
{
3262+
/// Spatial upscaling only (single frame, no motion vectors required).
3263+
SUPER_RESOLUTION_UPSCALER_TYPE_SPATIAL = 0u,
3264+
3265+
/// Temporal upscaling (uses motion vectors and history accumulation).
3266+
SUPER_RESOLUTION_UPSCALER_TYPE_TEMPORAL
3267+
};
3268+
3269+
3270+
/// Capability flags for spatial super resolution upscaling.
3271+
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_SPATIAL_CAP_FLAGS, Uint32)
3272+
{
3273+
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NONE = 0u,
3274+
3275+
/// The upscaler is a native hardware-accelerated implementation (e.g. MetalFX, DirectSR)
3276+
/// as opposed to a custom software fallback.
3277+
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NATIVE = 1u << 0,
3278+
3279+
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_LAST = SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NATIVE
3280+
};
3281+
DEFINE_FLAG_ENUM_OPERATORS(SUPER_RESOLUTION_SPATIAL_CAP_FLAGS)
3282+
3283+
3284+
/// Capability flags for temporal super resolution upscaling.
3285+
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_TEMPORAL_CAP_FLAGS, Uint32)
3286+
{
3287+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_NONE = 0u,
3288+
3289+
/// The upscaler is a native hardware-accelerated implementation (e.g. MetalFX, DirectSR)
3290+
/// as opposed to a custom software fallback.
3291+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_NATIVE = 1u << 0,
3292+
3293+
/// The upscaler supports exposure scale texture input.
3294+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_EXPOSURE_SCALE_TEXTURE = 1u << 1,
3295+
3296+
/// The upscaler supports ignore history mask texture input.
3297+
/// When set, the backend processes the pIgnoreHistoryMaskTextureSRV field
3298+
/// in ExecuteSuperResolutionAttribs.
3299+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_IGNORE_HISTORY_MASK = 1u << 2,
3300+
3301+
/// The upscaler supports reactive mask texture input.
3302+
/// When set, the backend processes the pReactiveMaskTextureSRV field
3303+
/// in ExecuteSuperResolutionAttribs.
3304+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_REACTIVE_MASK = 1u << 3,
3305+
3306+
/// The upscaler supports the sharpness control parameter.
3307+
/// When set, the Sharpness field in ExecuteSuperResolutionAttribs is used.
3308+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_SHARPNESS = 1u << 4,
3309+
3310+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_LAST = SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_SHARPNESS
3311+
};
3312+
DEFINE_FLAG_ENUM_OPERATORS(SUPER_RESOLUTION_TEMPORAL_CAP_FLAGS)
3313+
3314+
3315+
/// Information about a supported super resolution upscaler variant
3316+
struct SuperResolutionUpscalerInfo
3317+
{
3318+
/// Human-readable name of the upscaler variant (e.g. "MetalFX Spatial", "MetalFX Temporal").
3319+
Char Name[128] DEFAULT_INITIALIZER({});
3320+
3321+
/// Unique identifier for this upscaler variant.
3322+
/// Pass this VariantId to SuperResolutionUpscalerDesc when creating an upscaler.
3323+
INTERFACE_ID VariantId DEFAULT_INITIALIZER({});
3324+
3325+
/// Upscaler type. Determines which input textures and parameters are required.
3326+
SUPER_RESOLUTION_UPSCALER_TYPE Type DEFAULT_INITIALIZER(SUPER_RESOLUTION_UPSCALER_TYPE_SPATIAL);
3327+
3328+
#if defined(DILIGENT_SHARP_GEN)
3329+
Uint32 CapFlags DEFAULT_INITIALIZER(0);
3330+
#else
3331+
union
3332+
{
3333+
/// Capability flags for SUPER_RESOLUTION_UPSCALER_TYPE_SPATIAL.
3334+
SUPER_RESOLUTION_SPATIAL_CAP_FLAGS SpatialCapFlags DEFAULT_INITIALIZER(SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NONE);
3335+
3336+
/// Capability flags for SUPER_RESOLUTION_UPSCALER_TYPE_TEMPORAL.
3337+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAGS TemporalCapFlags;
3338+
};
3339+
#endif
3340+
};
3341+
typedef struct SuperResolutionUpscalerInfo SuperResolutionUpscalerInfo;
3342+
3343+
3344+
/// Super resolution properties, reported via GraphicsAdapterInfo
3345+
struct SuperResolutionProperties
3346+
{
3347+
/// Array of supported upscaler variants and their capabilities.
3348+
SuperResolutionUpscalerInfo Upscalers[DILIGENT_MAX_SUPER_RESOLUTION_UPSCALERS] DEFAULT_INITIALIZER({});
3349+
3350+
/// The number of valid elements in the Upscalers array.
3351+
Uint8 NumUpscalers DEFAULT_INITIALIZER(0);
3352+
3353+
#if DILIGENT_CPP_INTERFACE && !defined(DILIGENT_SHARP_GEN)
3354+
bool operator==(const SuperResolutionProperties& RHS) const
3355+
{
3356+
if (NumUpscalers != RHS.NumUpscalers)
3357+
return false;
3358+
for (Uint8 i = 0; i < NumUpscalers; ++i)
3359+
{
3360+
if (!(Upscalers[i].VariantId == RHS.Upscalers[i].VariantId &&
3361+
Upscalers[i].Type == RHS.Upscalers[i].Type &&
3362+
Upscalers[i].SpatialCapFlags == RHS.Upscalers[i].SpatialCapFlags &&
3363+
memcmp(Upscalers[i].Name, RHS.Upscalers[i].Name, sizeof(Upscalers[i].Name)) == 0))
3364+
return false;
3365+
}
3366+
return true;
3367+
}
3368+
#endif
3369+
};
3370+
typedef struct SuperResolutionProperties SuperResolutionProperties;
3371+
3372+
32543373
/// Command queue properties
32553374
struct CommandQueueInfo
32563375
{
@@ -3342,6 +3461,9 @@ struct GraphicsAdapterInfo
33423461
/// Sparse resource properties, see Diligent::SparseResourceProperties.
33433462
SparseResourceProperties SparseResources;
33443463

3464+
/// Super resolution upscaler properties, see Diligent::SuperResolutionProperties.
3465+
SuperResolutionProperties SuperResolution;
3466+
33453467
/// Supported device features, see Diligent::DeviceFeatures.
33463468

33473469
/// The feature state indicates:
@@ -3388,6 +3510,7 @@ struct GraphicsAdapterInfo
33883510
ComputeShader == RHS.ComputeShader &&
33893511
DrawCommand == RHS.DrawCommand &&
33903512
SparseResources == RHS.SparseResources &&
3513+
SuperResolution == RHS.SuperResolution &&
33913514
Features == RHS.Features &&
33923515
memcmp(Description, RHS.Description, sizeof(Description)) == 0;
33933516
}

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)

0 commit comments

Comments
 (0)