Skip to content

Commit b9e176c

Browse files
Add ISuperResolution interface and SuperResolution device feature
1 parent 52d8dca commit b9e176c

File tree

5 files changed

+555
-40
lines changed

5 files changed

+555
-40
lines changed

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: 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 "SuperResolution.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+
ISuperResolution* 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: 170 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,165 @@ 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+
/// Super resolution optimization type.
3271+
/// Defines the quality/performance trade-off for super resolution upscaling.
3272+
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_OPTIMIZATION_TYPE, Uint8)
3273+
{
3274+
/// Maximum quality, lowest performance.
3275+
SUPER_RESOLUTION_OPTIMIZATION_TYPE_MAX_QUALITY = 0u,
3276+
3277+
/// Favor quality over performance.
3278+
SUPER_RESOLUTION_OPTIMIZATION_TYPE_HIGH_QUALITY,
3279+
3280+
/// Balanced quality/performance trade-off.
3281+
SUPER_RESOLUTION_OPTIMIZATION_TYPE_BALANCED,
3282+
3283+
/// Favor performance over quality.
3284+
SUPER_RESOLUTION_OPTIMIZATION_TYPE_HIGH_PERFORMANCE,
3285+
3286+
/// Maximum performance, lowest quality.
3287+
SUPER_RESOLUTION_OPTIMIZATION_TYPE_MAX_PERFORMANCE,
3288+
3289+
SUPER_RESOLUTION_OPTIMIZATION_TYPE_COUNT
3290+
};
3291+
3292+
3293+
/// Capability flags for spatial super resolution upscaling.
3294+
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_SPATIAL_CAP_FLAGS, Uint32)
3295+
{
3296+
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NONE = 0u,
3297+
3298+
/// The upscaler is a native hardware-accelerated implementation (e.g. MetalFX, DirectSR)
3299+
/// as opposed to a custom software fallback.
3300+
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NATIVE = 1u << 0,
3301+
3302+
SUPER_RESOLUTION_SPATIAL_CAP_FLAG_LAST = SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NATIVE
3303+
};
3304+
DEFINE_FLAG_ENUM_OPERATORS(SUPER_RESOLUTION_SPATIAL_CAP_FLAGS)
3305+
3306+
3307+
/// Capability flags for temporal super resolution upscaling.
3308+
DILIGENT_TYPED_ENUM(SUPER_RESOLUTION_TEMPORAL_CAP_FLAGS, Uint32)
3309+
{
3310+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_NONE = 0u,
3311+
3312+
/// The upscaler is a native hardware-accelerated implementation (e.g. MetalFX, DirectSR)
3313+
/// as opposed to a custom software fallback.
3314+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_NATIVE = 1u << 0,
3315+
3316+
/// The upscaler supports exposure scale texture input.
3317+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_EXPOSURE_SCALE_TEXTURE = 1u << 1,
3318+
3319+
/// The upscaler supports ignore history mask texture input.
3320+
/// When set, the backend processes the pIgnoreHistoryMaskTextureSRV field
3321+
/// in ExecuteSuperResolutionAttribs.
3322+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_IGNORE_HISTORY_MASK = 1u << 2,
3323+
3324+
/// The upscaler supports reactive mask texture input.
3325+
/// When set, the backend processes the pReactiveMaskTextureSRV field
3326+
/// in ExecuteSuperResolutionAttribs.
3327+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_REACTIVE_MASK = 1u << 3,
3328+
3329+
/// The upscaler supports the sharpness control parameter.
3330+
/// When set, the Sharpness field in ExecuteSuperResolutionAttribs is used.
3331+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_SHARPNESS = 1u << 4,
3332+
3333+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_LAST = SUPER_RESOLUTION_TEMPORAL_CAP_FLAG_SHARPNESS
3334+
};
3335+
DEFINE_FLAG_ENUM_OPERATORS(SUPER_RESOLUTION_TEMPORAL_CAP_FLAGS)
3336+
3337+
3338+
/// Information about a supported super resolution upscaler variant
3339+
struct SuperResolutionInfo
3340+
{
3341+
/// Human-readable name of the upscaler variant (e.g. "MetalFX Spatial", "MetalFX Temporal").
3342+
Char Name[128] DEFAULT_INITIALIZER({});
3343+
3344+
/// Unique identifier for this upscaler variant.
3345+
/// Pass this VariantId to SuperResolutionDesc when creating an upscaler.
3346+
INTERFACE_ID VariantId DEFAULT_INITIALIZER({});
3347+
3348+
/// Upscaler type. Determines which input textures and parameters are required.
3349+
SUPER_RESOLUTION_UPSCALER_TYPE Type DEFAULT_INITIALIZER(SUPER_RESOLUTION_UPSCALER_TYPE_SPATIAL);
3350+
3351+
#if defined(DILIGENT_SHARP_GEN)
3352+
Uint32 CapFlags DEFAULT_INITIALIZER(0);
3353+
#else
3354+
union
3355+
{
3356+
/// Capability flags for SUPER_RESOLUTION_UPSCALER_TYPE_SPATIAL.
3357+
SUPER_RESOLUTION_SPATIAL_CAP_FLAGS SpatialCapFlags DEFAULT_INITIALIZER(SUPER_RESOLUTION_SPATIAL_CAP_FLAG_NONE);
3358+
3359+
/// Capability flags for SUPER_RESOLUTION_UPSCALER_TYPE_TEMPORAL.
3360+
SUPER_RESOLUTION_TEMPORAL_CAP_FLAGS TemporalCapFlags;
3361+
};
3362+
#endif
3363+
3364+
#if DILIGENT_CPP_INTERFACE
3365+
constexpr Uint32 SpatialOrTemporalCapFlags() const
3366+
{
3367+
#if defined(DILIGENT_SHARP_GEN)
3368+
return CapFlags;
3369+
#else
3370+
return SpatialCapFlags;
3371+
#endif
3372+
}
3373+
3374+
/// Comparison operator tests if two structures are equivalent
3375+
3376+
/// \param [in] RHS - reference to the structure to perform comparison with
3377+
/// \return
3378+
/// - True if all members of the two structures are equal.
3379+
/// - False otherwise.
3380+
bool operator==(const SuperResolutionInfo& RHS) const noexcept
3381+
{
3382+
return VariantId == RHS.VariantId &&
3383+
Type == RHS.Type &&
3384+
SpatialOrTemporalCapFlags() == RHS.SpatialOrTemporalCapFlags() &&
3385+
memcmp(Name, RHS.Name, sizeof(Name)) == 0;
3386+
}
3387+
#endif
3388+
};
3389+
typedef struct SuperResolutionInfo SuperResolutionInfo;
3390+
3391+
3392+
/// Super resolution properties, reported via GraphicsAdapterInfo
3393+
struct SuperResolutionProperties
3394+
{
3395+
/// Array of supported upscaler variants and their capabilities.
3396+
SuperResolutionInfo Upscalers[DILIGENT_MAX_SUPER_RESOLUTION_UPSCALERS] DEFAULT_INITIALIZER({});
3397+
3398+
/// The number of valid elements in the Upscalers array.
3399+
Uint8 NumUpscalers DEFAULT_INITIALIZER(0);
3400+
3401+
#if DILIGENT_CPP_INTERFACE
3402+
bool operator==(const SuperResolutionProperties& RHS) const
3403+
{
3404+
if (NumUpscalers != RHS.NumUpscalers)
3405+
return false;
3406+
3407+
for (Uint8 i = 0; i < NumUpscalers; ++i)
3408+
if (!(Upscalers[i] == RHS.Upscalers[i]))
3409+
return false;
3410+
3411+
return true;
3412+
}
3413+
#endif
3414+
};
3415+
typedef struct SuperResolutionProperties SuperResolutionProperties;
3416+
3417+
32543418
/// Command queue properties
32553419
struct CommandQueueInfo
32563420
{
@@ -3342,6 +3506,9 @@ struct GraphicsAdapterInfo
33423506
/// Sparse resource properties, see Diligent::SparseResourceProperties.
33433507
SparseResourceProperties SparseResources;
33443508

3509+
/// Super resolution upscaler properties, see Diligent::SuperResolutionProperties.
3510+
SuperResolutionProperties SuperResolution;
3511+
33453512
/// Supported device features, see Diligent::DeviceFeatures.
33463513

33473514
/// The feature state indicates:
@@ -3388,6 +3555,7 @@ struct GraphicsAdapterInfo
33883555
ComputeShader == RHS.ComputeShader &&
33893556
DrawCommand == RHS.DrawCommand &&
33903557
SparseResources == RHS.SparseResources &&
3558+
SuperResolution == RHS.SuperResolution &&
33913559
Features == RHS.Features &&
33923560
memcmp(Description, RHS.Description, sizeof(Description)) == 0;
33933561
}

0 commit comments

Comments
 (0)