|
| 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 |
0 commit comments