3030#include " SuperResolutionBase.hpp"
3131#include " SuperResolutionVariants.hpp"
3232
33+ #include < d3d11.h>
34+ #include < atlbase.h>
3335#include < nvsdk_ngx_helpers.h>
3436
35- #include " ../../GraphicsEngineD3D11/include/pch .h"
36- #include " RenderDeviceD3D11Impl.hpp "
37- #include " DeviceContextD3D11Impl.hpp "
38- #include " TextureBaseD3D11.hpp "
37+ #include " RenderDeviceD3D11 .h"
38+ #include " DeviceContextD3D11.h "
39+ #include " TextureD3D11.h "
40+ #include " EngineMemory.h "
3941
4042namespace Diligent
4143{
@@ -47,12 +49,10 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase
4749{
4850public:
4951 SuperResolutionD3D11_DLSS (IReferenceCounters* pRefCounters,
50- IRenderDevice* pDevice,
5152 const SuperResolutionDesc& Desc,
5253 const SuperResolutionInfo& Info,
5354 NVSDK_NGX_Parameter* pNGXParams) :
5455 SuperResolutionBase{pRefCounters, Desc, Info},
55- m_pDevice{pDevice},
5656 m_pNGXParams{pNGXParams}
5757 {
5858 PopulateHaltonJitterPattern (m_JitterPattern, 64 );
@@ -72,17 +72,15 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase
7272 if (pDLSSFeature == nullptr )
7373 return ;
7474
75- DeviceContextD3D11Impl* pCtxImpl = ClassPtrCast<DeviceContextD3D11Impl>(Attribs.pContext );
76-
7775 auto GetD3D11Resource = [](ITextureView* pView) -> ID3D11Resource* {
78- if ( pView != nullptr )
79- return ClassPtrCast<TextureBaseD3D11 >(pView->GetTexture ())->GetD3D11Texture ();
80- return nullptr ;
76+ return pView != nullptr ?
77+ ClassPtrCast<ITextureD3D11 >(pView->GetTexture ())->GetD3D11Texture () :
78+ nullptr ;
8179 };
8280
83- ID3D11DeviceContext* pd3d11DeviceContext = pCtxImpl ->GetD3D11DeviceContext ();
81+ ID3D11DeviceContext* pd3d11Ctx = ClassPtrCast<IDeviceContextD3D11>(Attribs. pContext ) ->GetD3D11DeviceContext ();
8482
85- NVSDK_NGX_D3D11_DLSS_Eval_Params EvalParams = {};
83+ NVSDK_NGX_D3D11_DLSS_Eval_Params EvalParams{};
8684 EvalParams.Feature .pInColor = GetD3D11Resource (Attribs.pColorTextureSRV );
8785 EvalParams.Feature .pInOutput = GetD3D11Resource (Attribs.pOutputTextureView );
8886 EvalParams.pInDepth = GetD3D11Resource (Attribs.pDepthTextureSRV );
@@ -101,7 +99,7 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase
10199 EvalParams.InPreExposure = Attribs.PreExposure ;
102100 EvalParams.InExposureScale = Attribs.ExposureScale ;
103101
104- NVSDK_NGX_Result Result = NGX_D3D11_EVALUATE_DLSS_EXT (pd3d11DeviceContext , pDLSSFeature, m_pNGXParams, &EvalParams);
102+ NVSDK_NGX_Result Result = NGX_D3D11_EVALUATE_DLSS_EXT (pd3d11Ctx , pDLSSFeature, m_pNGXParams, &EvalParams);
105103 if (NVSDK_NGX_FAILED (Result))
106104 LOG_ERROR_MESSAGE (" DLSS D3D11 evaluation failed. NGX Result: " , static_cast <Uint32>(Result));
107105 }
@@ -120,15 +118,15 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase
120118 }
121119 m_DLSSFeatureFlags = DLSSCreateFeatureFlags;
122120
123- NVSDK_NGX_DLSS_Create_Params DLSSCreateParams = {};
124- DLSSCreateParams.Feature .InWidth = m_Desc.InputWidth ;
125- DLSSCreateParams.Feature .InHeight = m_Desc.InputHeight ;
126- DLSSCreateParams.Feature .InTargetWidth = m_Desc.OutputWidth ;
127- DLSSCreateParams.Feature .InTargetHeight = m_Desc.OutputHeight ;
128- DLSSCreateParams.InFeatureCreateFlags = DLSSCreateFeatureFlags;
121+ NVSDK_NGX_DLSS_Create_Params DLSSCreateParams{};
122+ DLSSCreateParams.Feature .InWidth = m_Desc.InputWidth ;
123+ DLSSCreateParams.Feature .InHeight = m_Desc.InputHeight ;
124+ DLSSCreateParams.Feature .InTargetWidth = m_Desc.OutputWidth ;
125+ DLSSCreateParams.Feature .InTargetHeight = m_Desc.OutputHeight ;
126+ DLSSCreateParams.InFeatureCreateFlags = DLSSCreateFeatureFlags;
129127
130128 NVSDK_NGX_Handle* pFeature = nullptr ;
131- ID3D11DeviceContext* pd3d11Ctx = ClassPtrCast<DeviceContextD3D11Impl >(Attribs.pContext )->GetD3D11DeviceContext ();
129+ ID3D11DeviceContext* pd3d11Ctx = ClassPtrCast<IDeviceContextD3D11 >(Attribs.pContext )->GetD3D11DeviceContext ();
132130 NVSDK_NGX_Result Result = NGX_D3D11_CREATE_DLSS_EXT (pd3d11Ctx, &pFeature, m_pNGXParams, &DLSSCreateParams);
133131
134132 if (NVSDK_NGX_FAILED (Result))
@@ -140,20 +138,28 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase
140138 return m_pDLSSFeature;
141139 }
142140
143- RefCntAutoPtr<IRenderDevice> m_pDevice;
144- NVSDK_NGX_Handle* m_pDLSSFeature = nullptr ;
145- NVSDK_NGX_Parameter* m_pNGXParams = nullptr ;
146- Int32 m_DLSSFeatureFlags = 0 ;
141+ NVSDK_NGX_Handle* m_pDLSSFeature = nullptr ;
142+ NVSDK_NGX_Parameter* m_pNGXParams = nullptr ;
143+ Int32 m_DLSSFeatureFlags = 0 ;
147144};
148145
149146class DLSSProviderD3D11 final : public SuperResolutionProvider
150147{
151148public:
152- DLSSProviderD3D11 (IRenderDevice* pDevice) :
153- m_pDevice{pDevice}
149+ DLSSProviderD3D11 (IRenderDevice* pDevice)
154150 {
155- ID3D11Device* pd3d11Device = ClassPtrCast<RenderDeviceD3D11Impl>(pDevice)->GetD3D11Device ();
156- NVSDK_NGX_Result Result = NVSDK_NGX_D3D11_Init_with_ProjectID (DLSSProjectId, NVSDK_NGX_ENGINE_TYPE_CUSTOM, " 0" , DLSSAppDataPath, pd3d11Device);
151+ if (pDevice == nullptr )
152+ LOG_ERROR_AND_THROW (" Device must not be null" );
153+ if (RefCntAutoPtr<IRenderDeviceD3D11> pDeviceD3D11{pDevice, IID_RenderDeviceD3D11})
154+ {
155+ m_pd3d11Device = pDeviceD3D11->GetD3D11Device ();
156+ }
157+ else
158+ {
159+ LOG_ERROR_AND_THROW (" Device must be of type RENDER_DEVICE_TYPE_D3D11" );
160+ }
161+
162+ NVSDK_NGX_Result Result = NVSDK_NGX_D3D11_Init_with_ProjectID (DLSSProjectId, NVSDK_NGX_ENGINE_TYPE_CUSTOM, " 0" , DLSSAppDataPath, m_pd3d11Device);
157163 if (NVSDK_NGX_FAILED (Result))
158164 {
159165 LOG_WARNING_MESSAGE (" NVIDIA NGX D3D11 initialization failed. DLSS will not be available. Result: " , static_cast <Uint32>(Result));
@@ -165,7 +171,7 @@ class DLSSProviderD3D11 final : public SuperResolutionProvider
165171 {
166172 LOG_WARNING_MESSAGE (" Failed to get NGX D3D11 capability parameters. DLSS will not be available. Result: " , static_cast <Uint32>(Result));
167173 m_pNGXParams = nullptr ;
168- NVSDK_NGX_D3D11_Shutdown1 (pd3d11Device );
174+ NVSDK_NGX_D3D11_Shutdown1 (m_pd3d11Device );
169175 }
170176 }
171177
@@ -174,7 +180,7 @@ class DLSSProviderD3D11 final : public SuperResolutionProvider
174180 if (m_pNGXParams != nullptr )
175181 {
176182 NVSDK_NGX_D3D11_DestroyParameters (m_pNGXParams);
177- NVSDK_NGX_D3D11_Shutdown1 (ClassPtrCast<RenderDeviceD3D11Impl>(m_pDevice. RawPtr ())-> GetD3D11Device () );
183+ NVSDK_NGX_D3D11_Shutdown1 (m_pd3d11Device );
178184 }
179185 }
180186
@@ -190,16 +196,15 @@ class DLSSProviderD3D11 final : public SuperResolutionProvider
190196
191197 virtual void CreateSuperResolution (const SuperResolutionDesc& Desc, const SuperResolutionInfo& Info, ISuperResolution** ppUpscaler) override final
192198 {
193- DEV_CHECK_ERR (m_pDevice != nullptr , " Render device must not be null" );
194199 DEV_CHECK_ERR (ppUpscaler != nullptr , " ppUpscaler must not be null" );
195200
196- SuperResolutionD3D11_DLSS* pUpscaler = NEW_RC_OBJ (GetRawAllocator (), " SuperResolutionD3D11_DLSS instance" , SuperResolutionD3D11_DLSS)(m_pDevice, Desc, Info, m_pNGXParams);
201+ SuperResolutionD3D11_DLSS* pUpscaler = NEW_RC_OBJ (GetRawAllocator (), " SuperResolutionD3D11_DLSS instance" , SuperResolutionD3D11_DLSS)(Desc, Info, m_pNGXParams);
197202 pUpscaler->QueryInterface (IID_SuperResolution, reinterpret_cast <IObject**>(ppUpscaler));
198203 }
199204
200205private:
201- RefCntAutoPtr<IRenderDevice> m_pDevice ;
202- NVSDK_NGX_Parameter* m_pNGXParams = nullptr ;
206+ CComPtr<ID3D11Device> m_pd3d11Device ;
207+ NVSDK_NGX_Parameter* m_pNGXParams = nullptr ;
203208};
204209
205210} // anonymous namespace
0 commit comments