Skip to content

Commit a43a3fc

Browse files
Add ISuperResolution interface and SuperResolution device feature
1 parent df94019 commit a43a3fc

5 files changed

Lines changed: 556 additions & 40 deletions

File tree

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
@@ -1867,6 +1867,10 @@ struct DeviceFeatures
18671867
/// Not supported by D3D11, D3D12, OpenGL, or Metal backends.
18681868
DEVICE_FEATURE_STATE SpecializationConstants DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);
18691869

1870+
/// Indicates if the device supports hardware super resolution (upscaling).
1871+
/// MetalFX on Metal, DirectSR on D3D12.
1872+
DEVICE_FEATURE_STATE SuperResolution DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);
1873+
18701874
#if DILIGENT_CPP_INTERFACE
18711875
constexpr DeviceFeatures() noexcept {}
18721876

@@ -1918,11 +1922,12 @@ struct DeviceFeatures
19181922
Handler(NativeMultiDraw) \
19191923
Handler(AsyncShaderCompilation) \
19201924
Handler(FormattedBuffers) \
1921-
Handler(SpecializationConstants)
1925+
Handler(SpecializationConstants) \
1926+
Handler(SuperResolution)
19221927

19231928
explicit constexpr DeviceFeatures(DEVICE_FEATURE_STATE State) noexcept
19241929
{
1925-
static_assert(sizeof(*this) == 48, "Did you add a new feature to DeviceFeatures? Please add it to ENUMERATE_DEVICE_FEATURES.");
1930+
static_assert(sizeof(*this) == 49, "Did you add a new feature to DeviceFeatures? Please add it to ENUMERATE_DEVICE_FEATURES.");
19261931
#define INIT_FEATURE(Feature) Feature = State;
19271932
ENUMERATE_DEVICE_FEATURES(INIT_FEATURE)
19281933
#undef INIT_FEATURE
@@ -3263,6 +3268,165 @@ struct SparseResourceProperties
32633268
typedef struct SparseResourceProperties SparseResourceProperties;
32643269

32653270

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

3521+
/// Super resolution upscaler properties, see Diligent::SuperResolutionProperties.
3522+
SuperResolutionProperties SuperResolution;
3523+
33573524
/// Supported device features, see Diligent::DeviceFeatures.
33583525

33593526
/// The feature state indicates:
@@ -3400,6 +3567,7 @@ struct GraphicsAdapterInfo
34003567
ComputeShader == RHS.ComputeShader &&
34013568
DrawCommand == RHS.DrawCommand &&
34023569
SparseResources == RHS.SparseResources &&
3570+
SuperResolution == RHS.SuperResolution &&
34033571
Features == RHS.Features &&
34043572
memcmp(Description, RHS.Description, sizeof(Description)) == 0;
34053573
}

0 commit comments

Comments
 (0)