From 308c2da133316c0d126bf8880451a71e70ae1a39 Mon Sep 17 00:00:00 2001 From: MikhailGorobets Date: Fri, 20 Mar 2026 14:20:53 +0600 Subject: [PATCH 1/4] Rework super-resolution validation --- .../include/SuperResolutionBase.hpp | 16 +- .../SuperResolution/src/DSRProviderD3D12.cpp | 8 +- .../src/SuperResolutionBase.cpp | 146 +++++++++--------- 3 files changed, 89 insertions(+), 81 deletions(-) diff --git a/Graphics/SuperResolution/include/SuperResolutionBase.hpp b/Graphics/SuperResolution/include/SuperResolutionBase.hpp index 24c0d5c66..f665342d5 100644 --- a/Graphics/SuperResolution/include/SuperResolutionBase.hpp +++ b/Graphics/SuperResolution/include/SuperResolutionBase.hpp @@ -39,6 +39,8 @@ namespace Diligent #define LOG_SUPER_RESOLUTION_ERROR_AND_THROW(Name, ...) LOG_ERROR_AND_THROW("Super resolution upscaler '", ((Name) != nullptr ? (Name) : ""), "': ", ##__VA_ARGS__) +#define DEV_CHECK_SUPER_RESOLUTION(Name, Expr, ...) DEV_CHECK_ERR(Expr, "Super resolution upscaler '", ((Name) != nullptr ? (Name) : ""), "': ", ##__VA_ARGS__) + #define VERIFY_SUPER_RESOLUTION(Name, Expr, ...) \ do \ { \ @@ -48,22 +50,24 @@ namespace Diligent } \ } while (false) + + /// Validates super resolution description and throws an exception in case of an error. void ValidateSuperResolutionDesc(const SuperResolutionDesc& Desc) noexcept(false); /// Validates super resolution description for temporal upscaling and throws an exception in case of an error. void ValidateTemporalSuperResolutionDesc(const SuperResolutionDesc& Desc) noexcept(false); -/// Validates super resolution source settings attributes and throws an exception in case of an error. -void ValidateSourceSettingsAttribs(const SuperResolutionSourceSettingsAttribs& Attribs) noexcept(false); +/// Validates super resolution source settings attributes using DEV checks. +void ValidateSourceSettingsAttribs(const SuperResolutionSourceSettingsAttribs& Attribs); -/// Validates execute super resolution attributes and throws an exception in case of an error. +/// Validates execute super resolution attributes using DEV checks. void ValidateExecuteSuperResolutionAttribs(const SuperResolutionDesc& Desc, - const ExecuteSuperResolutionAttribs& Attribs) noexcept(false); + const ExecuteSuperResolutionAttribs& Attribs); -/// Validates execute super resolution attributes for temporal upscaling and throws an exception in case of an error. +/// Validates execute super resolution attributes for temporal upscaling using DEV checks. void ValidateTemporalExecuteSuperResolutionAttribs(const SuperResolutionDesc& Desc, - const ExecuteSuperResolutionAttribs& Attribs) noexcept(false); + const ExecuteSuperResolutionAttribs& Attribs); class SuperResolutionBase : public ObjectBase { diff --git a/Graphics/SuperResolution/src/DSRProviderD3D12.cpp b/Graphics/SuperResolution/src/DSRProviderD3D12.cpp index 2f0b0447c..b3f75bd77 100644 --- a/Graphics/SuperResolution/src/DSRProviderD3D12.cpp +++ b/Graphics/SuperResolution/src/DSRProviderD3D12.cpp @@ -170,10 +170,10 @@ SuperResolutionD3D12_DSR::~SuperResolutionD3D12_DSR() = default; void DILIGENT_CALL_TYPE SuperResolutionD3D12_DSR::Execute(const ExecuteSuperResolutionAttribs& Attribs) { ValidateTemporalExecuteSuperResolutionAttribs(m_Desc, Attribs); - VERIFY_SUPER_RESOLUTION(m_Desc.Name, Attribs.CameraNear > 0, "CameraNear must be greater than zero for temporal upscaling"); - VERIFY_SUPER_RESOLUTION(m_Desc.Name, Attribs.CameraFar > 0, "CameraFar must be greater than zero for temporal upscaling."); - VERIFY_SUPER_RESOLUTION(m_Desc.Name, Attribs.CameraFovAngleVert > 0, "CameraFovAngleVert must be greater than zero for temporal upscaling."); - VERIFY_SUPER_RESOLUTION(m_Desc.Name, Attribs.TimeDeltaInSeconds >= 0, "TimeDeltaInSeconds must be non-negative."); + DEV_CHECK_SUPER_RESOLUTION(m_Desc.Name, Attribs.CameraNear > 0, "CameraNear must be greater than zero for temporal upscaling"); + DEV_CHECK_SUPER_RESOLUTION(m_Desc.Name, Attribs.CameraFar > 0, "CameraFar must be greater than zero for temporal upscaling."); + DEV_CHECK_SUPER_RESOLUTION(m_Desc.Name, Attribs.CameraFovAngleVert > 0, "CameraFovAngleVert must be greater than zero for temporal upscaling."); + DEV_CHECK_SUPER_RESOLUTION(m_Desc.Name, Attribs.TimeDeltaInSeconds >= 0, "TimeDeltaInSeconds must be non-negative."); DeviceContextD3D12Impl* pCtx = ClassPtrCast(Attribs.pContext); diff --git a/Graphics/SuperResolution/src/SuperResolutionBase.cpp b/Graphics/SuperResolution/src/SuperResolutionBase.cpp index 4e0c2bcba..384ce5e58 100644 --- a/Graphics/SuperResolution/src/SuperResolutionBase.cpp +++ b/Graphics/SuperResolution/src/SuperResolutionBase.cpp @@ -58,12 +58,12 @@ void PopulateHaltonJitterPattern(std::vector& } } -void ValidateSourceSettingsAttribs(const SuperResolutionSourceSettingsAttribs& Attribs) noexcept(false) +void ValidateSourceSettingsAttribs(const SuperResolutionSourceSettingsAttribs& Attribs) { - if (Attribs.OutputWidth == 0 || Attribs.OutputHeight == 0) - LOG_ERROR_AND_THROW("Output resolution must be greater than zero"); - if (Attribs.OptimizationType >= SUPER_RESOLUTION_OPTIMIZATION_TYPE_COUNT) - LOG_ERROR_AND_THROW("Invalid optimization type"); +#ifdef DILIGENT_DEVELOPMENT + DEV_CHECK_ERR(Attribs.OutputWidth > 0 && Attribs.OutputHeight > 0, "Output resolution must be greater than zero"); + DEV_CHECK_ERR(Attribs.OptimizationType < SUPER_RESOLUTION_OPTIMIZATION_TYPE_COUNT, "Invalid optimization type"); +#endif } void ValidateSuperResolutionDesc(const SuperResolutionDesc& Desc) noexcept(false) @@ -84,25 +84,26 @@ void ValidateTemporalSuperResolutionDesc(const SuperResolutionDesc& Desc) noexce } void ValidateExecuteSuperResolutionAttribs(const SuperResolutionDesc& Desc, - const ExecuteSuperResolutionAttribs& Attribs) noexcept(false) + const ExecuteSuperResolutionAttribs& Attribs) { - VERIFY_SUPER_RESOLUTION(Desc.Name, Attribs.pContext != nullptr, "Device context must not be null"); - VERIFY_SUPER_RESOLUTION(Desc.Name, Attribs.pColorTextureSRV != nullptr, "Color texture SRV must not be null"); - VERIFY_SUPER_RESOLUTION(Desc.Name, Attribs.pOutputTextureView != nullptr, "Output texture view must not be null"); +#ifdef DILIGENT_DEVELOPMENT + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, Attribs.pContext != nullptr, "Device context must not be null"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, Attribs.pColorTextureSRV != nullptr, "Color texture SRV must not be null"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, Attribs.pOutputTextureView != nullptr, "Output texture view must not be null"); // Validate color texture if (Attribs.pColorTextureSRV != nullptr) { const TextureDesc& TexDesc = Attribs.pColorTextureSRV->GetTexture()->GetDesc(); const TextureViewDesc& ViewDesc = Attribs.pColorTextureSRV->GetDesc(); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, - "Color texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); - VERIFY_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, - "Color texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, - ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.ColorFormat, - "Color texture view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, - ") does not match the expected ColorFormat (", GetTextureFormatAttribs(Desc.ColorFormat).Name, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, + "Color texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, + "Color texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, + ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.ColorFormat, + "Color texture view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, + ") does not match the expected ColorFormat (", GetTextureFormatAttribs(Desc.ColorFormat).Name, ")"); } // Validate output texture @@ -110,34 +111,36 @@ void ValidateExecuteSuperResolutionAttribs(const SuperResolutionDesc& { const TextureDesc& TexDesc = Attribs.pOutputTextureView->GetTexture()->GetDesc(); const TextureViewDesc& ViewDesc = Attribs.pOutputTextureView->GetDesc(); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET || ViewDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, - "Output texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_RENDER_TARGET or TEXTURE_VIEW_UNORDERED_ACCESS"); - VERIFY_SUPER_RESOLUTION(Desc.Name, TexDesc.Width == Desc.OutputWidth && TexDesc.Height == Desc.OutputHeight, - "Output texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, - ") must match the upscaler output resolution (", Desc.OutputWidth, "x", Desc.OutputHeight, ")"); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.OutputFormat, - "Output texture view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, - ") does not match the expected OutputFormat (", GetTextureFormatAttribs(Desc.OutputFormat).Name, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET || ViewDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, + "Output texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_RENDER_TARGET or TEXTURE_VIEW_UNORDERED_ACCESS"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, TexDesc.Width == Desc.OutputWidth && TexDesc.Height == Desc.OutputHeight, + "Output texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, + ") must match the upscaler output resolution (", Desc.OutputWidth, "x", Desc.OutputHeight, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.OutputFormat, + "Output texture view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, + ") does not match the expected OutputFormat (", GetTextureFormatAttribs(Desc.OutputFormat).Name, ")"); } +#endif } void ValidateTemporalExecuteSuperResolutionAttribs(const SuperResolutionDesc& Desc, - const ExecuteSuperResolutionAttribs& Attribs) noexcept(false) + const ExecuteSuperResolutionAttribs& Attribs) { +#ifdef DILIGENT_DEVELOPMENT ValidateExecuteSuperResolutionAttribs(Desc, Attribs); - VERIFY_SUPER_RESOLUTION(Desc.Name, Attribs.pDepthTextureSRV != nullptr, "Depth texture SRV must not be null for temporal upscaling"); - VERIFY_SUPER_RESOLUTION(Desc.Name, Attribs.pMotionVectorsSRV != nullptr, "Motion vectors SRV must not be null for temporal upscaling"); - VERIFY_SUPER_RESOLUTION(Desc.Name, (Desc.Flags & SUPER_RESOLUTION_FLAG_AUTO_EXPOSURE) != 0 || Attribs.pExposureTextureSRV != nullptr, - "Exposure texture SRV must not be null when SUPER_RESOLUTION_FLAG_AUTO_EXPOSURE is not set"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, Attribs.pDepthTextureSRV != nullptr, "Depth texture SRV must not be null for temporal upscaling"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, Attribs.pMotionVectorsSRV != nullptr, "Motion vectors SRV must not be null for temporal upscaling"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, (Desc.Flags & SUPER_RESOLUTION_FLAG_AUTO_EXPOSURE) != 0 || Attribs.pExposureTextureSRV != nullptr, + "Exposure texture SRV must not be null when SUPER_RESOLUTION_FLAG_AUTO_EXPOSURE is not set"); // Validate output texture view type (DirectSR requires UAV) if (Attribs.pOutputTextureView != nullptr) { const TextureDesc& TexDesc = Attribs.pOutputTextureView->GetTexture()->GetDesc(); const TextureViewDesc& ViewDesc = Attribs.pOutputTextureView->GetDesc(); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, - "Output texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_UNORDERED_ACCESS"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, + "Output texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_UNORDERED_ACCESS"); } // Validate depth texture @@ -145,14 +148,14 @@ void ValidateTemporalExecuteSuperResolutionAttribs(const SuperResolutionDesc& { const TextureDesc& TexDesc = Attribs.pDepthTextureSRV->GetTexture()->GetDesc(); const TextureViewDesc& ViewDesc = Attribs.pDepthTextureSRV->GetDesc(); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, - "Depth texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); - VERIFY_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, - "Depth texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, - ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.DepthFormat, - "Depth texture view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, - ") does not match the expected DepthFormat (", GetTextureFormatAttribs(Desc.DepthFormat).Name, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, + "Depth texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, + "Depth texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, + ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.DepthFormat, + "Depth texture view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, + ") does not match the expected DepthFormat (", GetTextureFormatAttribs(Desc.DepthFormat).Name, ")"); } // Validate motion vectors texture @@ -160,14 +163,14 @@ void ValidateTemporalExecuteSuperResolutionAttribs(const SuperResolutionDesc& { const TextureDesc& TexDesc = Attribs.pMotionVectorsSRV->GetTexture()->GetDesc(); const TextureViewDesc& ViewDesc = Attribs.pMotionVectorsSRV->GetDesc(); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, - "Motion vectors view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); - VERIFY_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, - "Motion vectors texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, - ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.MotionFormat, - "Motion vectors view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, - ") does not match the expected MotionFormat (", GetTextureFormatAttribs(Desc.MotionFormat).Name, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, + "Motion vectors view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, + "Motion vectors texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, + ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.MotionFormat, + "Motion vectors view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, + ") does not match the expected MotionFormat (", GetTextureFormatAttribs(Desc.MotionFormat).Name, ")"); } // Validate exposure texture @@ -175,14 +178,14 @@ void ValidateTemporalExecuteSuperResolutionAttribs(const SuperResolutionDesc& { const TextureDesc& TexDesc = Attribs.pExposureTextureSRV->GetTexture()->GetDesc(); const TextureViewDesc& ViewDesc = Attribs.pExposureTextureSRV->GetDesc(); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, - "Exposure texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); - VERIFY_SUPER_RESOLUTION(Desc.Name, TexDesc.Width == 1 && TexDesc.Height == 1, - "Exposure texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, - ") must be 1x1"); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.ExposureFormat, - "Exposure texture view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, - ") does not match the expected ExposureFormat (", GetTextureFormatAttribs(Desc.ExposureFormat).Name, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, + "Exposure texture view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, TexDesc.Width == 1 && TexDesc.Height == 1, + "Exposure texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, + ") must be 1x1"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.ExposureFormat, + "Exposure texture view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, + ") does not match the expected ExposureFormat (", GetTextureFormatAttribs(Desc.ExposureFormat).Name, ")"); } // Validate reactive mask texture @@ -190,16 +193,16 @@ void ValidateTemporalExecuteSuperResolutionAttribs(const SuperResolutionDesc& { const TextureDesc& TexDesc = Attribs.pReactiveMaskTextureSRV->GetTexture()->GetDesc(); const TextureViewDesc& ViewDesc = Attribs.pReactiveMaskTextureSRV->GetDesc(); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, - "Reactive mask view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); - VERIFY_SUPER_RESOLUTION(Desc.Name, Desc.ReactiveMaskFormat != TEX_FORMAT_UNKNOWN, - "Reactive mask texture '", TexDesc.Name, "' provided but ReactiveMaskFormat was not set in SuperResolutionDesc"); - VERIFY_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, - "Reactive mask texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, - ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.ReactiveMaskFormat, - "Reactive mask view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, - ") does not match the expected ReactiveMaskFormat (", GetTextureFormatAttribs(Desc.ReactiveMaskFormat).Name, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, + "Reactive mask view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, Desc.ReactiveMaskFormat != TEX_FORMAT_UNKNOWN, + "Reactive mask texture '", TexDesc.Name, "' provided but ReactiveMaskFormat was not set in SuperResolutionDesc"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, + "Reactive mask texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, + ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.Format == Desc.ReactiveMaskFormat, + "Reactive mask view '", TexDesc.Name, "' format (", GetTextureFormatAttribs(ViewDesc.Format).Name, + ") does not match the expected ReactiveMaskFormat (", GetTextureFormatAttribs(Desc.ReactiveMaskFormat).Name, ")"); } // Validate ignore history mask texture @@ -207,12 +210,13 @@ void ValidateTemporalExecuteSuperResolutionAttribs(const SuperResolutionDesc& { const TextureDesc& TexDesc = Attribs.pIgnoreHistoryMaskTextureSRV->GetTexture()->GetDesc(); const TextureViewDesc& ViewDesc = Attribs.pIgnoreHistoryMaskTextureSRV->GetDesc(); - VERIFY_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, - "Ignore history mask view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); - VERIFY_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, - "Ignore history mask texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, - ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, + "Ignore history mask view '", TexDesc.Name, "' must be TEXTURE_VIEW_SHADER_RESOURCE"); + DEV_CHECK_SUPER_RESOLUTION(Desc.Name, TexDesc.Width >= Desc.InputWidth && TexDesc.Height >= Desc.InputHeight, + "Ignore history mask texture '", TexDesc.Name, "' dimensions (", TexDesc.Width, "x", TexDesc.Height, + ") must be at least the upscaler input resolution (", Desc.InputWidth, "x", Desc.InputHeight, ")"); } +#endif } } // namespace Diligent From 8242d2ad30f05aedb1bce1f1acb84a4d58ab3db5 Mon Sep 17 00:00:00 2001 From: MikhailGorobets Date: Fri, 20 Mar 2026 14:32:38 +0600 Subject: [PATCH 2/4] Switch DLSS SDK to custom DLSS-Headers repository --- Graphics/SuperResolution/CMakeLists.txt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Graphics/SuperResolution/CMakeLists.txt b/Graphics/SuperResolution/CMakeLists.txt index a830da3cb..6124bf755 100644 --- a/Graphics/SuperResolution/CMakeLists.txt +++ b/Graphics/SuperResolution/CMakeLists.txt @@ -38,8 +38,8 @@ endif() if(DILIGENT_DLSS_SUPPORTED) # Fetch NVIDIA DLSS SDK headers FetchContent_DeclareShallowGit(DLSS-Headers - GIT_REPOSITORY https://github.com/NVIDIA/DLSS.git - GIT_TAG main + GIT_REPOSITORY https://github.com/MikhailGorobets/DLSS-Headers.git + GIT_TAG master ) FetchContent_MakeAvailable(DLSS-Headers) endif() @@ -147,14 +147,7 @@ if(DILIGENT_DSR_SUPPORTED) endif() if(DILIGENT_DLSS_SUPPORTED) - set(DLSS_SDK_DIR ${FETCHCONTENT_BASE_DIR}/dlss-headers-src) - target_include_directories(Diligent-SuperResolution-static PRIVATE ${DLSS_SDK_DIR}/include) - - # Link NGX static library (dynamic CRT /MD variant) - target_link_libraries(Diligent-SuperResolution-static PRIVATE - debug ${DLSS_SDK_DIR}/lib/Windows_x86_64/x64/nvsdk_ngx_d_dbg.lib - optimized ${DLSS_SDK_DIR}/lib/Windows_x86_64/x64/nvsdk_ngx_d.lib - ) + target_link_libraries(Diligent-SuperResolution-static PRIVATE DLSS-Headers DLSS-NGX) if(D3D12_SUPPORTED) target_link_libraries(Diligent-SuperResolution-static PRIVATE Diligent-GraphicsEngineD3D12-static) From 6ee53c6a4bdb90826258cd90b857a5499938e190 Mon Sep 17 00:00:00 2001 From: MikhailGorobets Date: Fri, 20 Mar 2026 14:59:24 +0600 Subject: [PATCH 3/4] Disable DLSS and DSR on 32-bit Windows; Fix unused provider warning --- Graphics/SuperResolution/CMakeLists.txt | 2 +- Graphics/SuperResolution/src/SuperResolutionFactory.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Graphics/SuperResolution/CMakeLists.txt b/Graphics/SuperResolution/CMakeLists.txt index 6124bf755..4d1a12432 100644 --- a/Graphics/SuperResolution/CMakeLists.txt +++ b/Graphics/SuperResolution/CMakeLists.txt @@ -7,7 +7,7 @@ project(Diligent-SuperResolution CXX) set(DILIGENT_DLSS_SUPPORTED FALSE CACHE INTERNAL "DLSS is not supported") set(DILIGENT_DSR_SUPPORTED FALSE CACHE INTERNAL "DirectSR is not supported") -if(PLATFORM_WIN32 AND NOT MINGW_BUILD) +if(PLATFORM_WIN32 AND NOT MINGW_BUILD AND CMAKE_SIZEOF_VOID_P EQUAL 8) if (D3D11_SUPPORTED OR D3D12_SUPPORTED OR VULKAN_SUPPORTED) set(DILIGENT_DLSS_SUPPORTED TRUE CACHE INTERNAL "DLSS is supported on Win32 platform") endif() diff --git a/Graphics/SuperResolution/src/SuperResolutionFactory.cpp b/Graphics/SuperResolution/src/SuperResolutionFactory.cpp index c0600c4c1..fa1ff59a2 100644 --- a/Graphics/SuperResolution/src/SuperResolutionFactory.cpp +++ b/Graphics/SuperResolution/src/SuperResolutionFactory.cpp @@ -31,6 +31,8 @@ #include "EngineMemory.h" #include "PlatformDebug.hpp" +#include + namespace Diligent { @@ -103,6 +105,7 @@ class SuperResolutionFactory : public ObjectBase #ifdef DILIGENT_METALFX_SUPPORTED AddProvider(pDevice, CreateMetalFXProvider, "MetalFX"); #endif + (void)AddProvider; } IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_SuperResolutionFactory, TBase) From 23f1898cf65583749b67ed023c50a5f3f126d3ef Mon Sep 17 00:00:00 2001 From: MikhailGorobets Date: Fri, 20 Mar 2026 17:06:56 +0600 Subject: [PATCH 4/4] Improve DLSS provider initialization and feature lifecycle --- .../include/SuperResolutionDLSS.hpp | 4 +- .../SuperResolution/src/DLSSProviderD3D11.cpp | 52 +++++++++++++----- .../SuperResolution/src/DLSSProviderD3D12.cpp | 52 +++++++++++++----- .../SuperResolution/src/DLSSProviderVk.cpp | 54 +++++++++++++------ .../src/SuperResolutionDLSS.cpp | 7 ++- 5 files changed, 122 insertions(+), 47 deletions(-) diff --git a/Graphics/SuperResolution/include/SuperResolutionDLSS.hpp b/Graphics/SuperResolution/include/SuperResolutionDLSS.hpp index 2534a30f2..d386f18e8 100644 --- a/Graphics/SuperResolution/include/SuperResolutionDLSS.hpp +++ b/Graphics/SuperResolution/include/SuperResolutionDLSS.hpp @@ -47,8 +47,8 @@ extern const wchar_t* DLSSAppDataPath; /// Maps Diligent optimization type to NGX performance/quality preset. NVSDK_NGX_PerfQuality_Value OptimizationTypeToNGXPerfQuality(SUPER_RESOLUTION_OPTIMIZATION_TYPE Type); -/// Maps Diligent super resolution flags to DLSS feature flags. -Int32 SuperResolutionFlagsToDLSSFeatureFlags(SUPER_RESOLUTION_FLAGS Flags); +/// Computes the full set of DLSS feature flags from the description and execution attributes. +Int32 ComputeDLSSFeatureFlags(SUPER_RESOLUTION_FLAGS Flags, const ExecuteSuperResolutionAttribs& Attribs); /// Populates DLSS variant info using NGX capability parameters. void EnumerateDLSSVariants(NVSDK_NGX_Parameter* pNGXParams, std::vector& Variants); diff --git a/Graphics/SuperResolution/src/DLSSProviderD3D11.cpp b/Graphics/SuperResolution/src/DLSSProviderD3D11.cpp index 39bf79d9c..b3d202dbb 100644 --- a/Graphics/SuperResolution/src/DLSSProviderD3D11.cpp +++ b/Graphics/SuperResolution/src/DLSSProviderD3D11.cpp @@ -68,8 +68,9 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase { ValidateTemporalExecuteSuperResolutionAttribs(m_Desc, Attribs); - if (m_pDLSSFeature == nullptr) - CreateFeature(Attribs); + NVSDK_NGX_Handle* pDLSSFeature = AcquireFeature(Attribs); + if (pDLSSFeature == nullptr) + return; DeviceContextD3D11Impl* pCtxImpl = ClassPtrCast(Attribs.pContext); @@ -100,17 +101,24 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase EvalParams.InPreExposure = Attribs.PreExposure; EvalParams.InExposureScale = Attribs.ExposureScale; - NVSDK_NGX_Result Result = NGX_D3D11_EVALUATE_DLSS_EXT(pd3d11DeviceContext, m_pDLSSFeature, m_pNGXParams, &EvalParams); + NVSDK_NGX_Result Result = NGX_D3D11_EVALUATE_DLSS_EXT(pd3d11DeviceContext, pDLSSFeature, m_pNGXParams, &EvalParams); if (NVSDK_NGX_FAILED(Result)) LOG_ERROR_MESSAGE("DLSS D3D11 evaluation failed. NGX Result: ", static_cast(Result)); } private: - void CreateFeature(const ExecuteSuperResolutionAttribs& Attribs) + NVSDK_NGX_Handle* AcquireFeature(const ExecuteSuperResolutionAttribs& Attribs) { - Int32 DLSSCreateFeatureFlags = SuperResolutionFlagsToDLSSFeatureFlags(m_Desc.Flags); - if (Attribs.CameraNear > Attribs.CameraFar) - DLSSCreateFeatureFlags |= NVSDK_NGX_DLSS_Feature_Flags_DepthInverted; + const Int32 DLSSCreateFeatureFlags = ComputeDLSSFeatureFlags(m_Desc.Flags, Attribs); + if (m_pDLSSFeature != nullptr && m_DLSSFeatureFlags == DLSSCreateFeatureFlags) + return m_pDLSSFeature; + + if (m_pDLSSFeature != nullptr) + { + NVSDK_NGX_D3D11_ReleaseFeature(m_pDLSSFeature); + m_pDLSSFeature = nullptr; + } + m_DLSSFeatureFlags = DLSSCreateFeatureFlags; NVSDK_NGX_DLSS_Create_Params DLSSCreateParams = {}; DLSSCreateParams.Feature.InWidth = m_Desc.InputWidth; @@ -119,16 +127,23 @@ class SuperResolutionD3D11_DLSS final : public SuperResolutionBase DLSSCreateParams.Feature.InTargetHeight = m_Desc.OutputHeight; DLSSCreateParams.InFeatureCreateFlags = DLSSCreateFeatureFlags; + NVSDK_NGX_Handle* pFeature = nullptr; ID3D11DeviceContext* pd3d11Ctx = ClassPtrCast(Attribs.pContext)->GetD3D11DeviceContext(); - NVSDK_NGX_Result Result = NGX_D3D11_CREATE_DLSS_EXT(pd3d11Ctx, &m_pDLSSFeature, m_pNGXParams, &DLSSCreateParams); + NVSDK_NGX_Result Result = NGX_D3D11_CREATE_DLSS_EXT(pd3d11Ctx, &pFeature, m_pNGXParams, &DLSSCreateParams); if (NVSDK_NGX_FAILED(Result)) - LOG_ERROR_AND_THROW("Failed to create DLSS D3D11 feature. NGX Result: ", static_cast(Result)); + { + LOG_ERROR_MESSAGE("Failed to create DLSS D3D11 feature. NGX Result: ", static_cast(Result)); + return nullptr; + } + m_pDLSSFeature = pFeature; + return m_pDLSSFeature; } RefCntAutoPtr m_pDevice; - NVSDK_NGX_Handle* m_pDLSSFeature = nullptr; - NVSDK_NGX_Parameter* m_pNGXParams = nullptr; + NVSDK_NGX_Handle* m_pDLSSFeature = nullptr; + NVSDK_NGX_Parameter* m_pNGXParams = nullptr; + Int32 m_DLSSFeatureFlags = 0; }; class DLSSProviderD3D11 final : public SuperResolutionProvider @@ -140,18 +155,27 @@ class DLSSProviderD3D11 final : public SuperResolutionProvider ID3D11Device* pd3d11Device = ClassPtrCast(pDevice)->GetD3D11Device(); NVSDK_NGX_Result Result = NVSDK_NGX_D3D11_Init_with_ProjectID(DLSSProjectId, NVSDK_NGX_ENGINE_TYPE_CUSTOM, "0", DLSSAppDataPath, pd3d11Device); if (NVSDK_NGX_FAILED(Result)) - LOG_ERROR_AND_THROW("NVIDIA NGX D3D11 initialization failed. Result: ", static_cast(Result)); + { + LOG_WARNING_MESSAGE("NVIDIA NGX D3D11 initialization failed. DLSS will not be available. Result: ", static_cast(Result)); + return; + } Result = NVSDK_NGX_D3D11_GetCapabilityParameters(&m_pNGXParams); if (NVSDK_NGX_FAILED(Result) || m_pNGXParams == nullptr) - LOG_ERROR_AND_THROW("Failed to get NGX D3D11 capability parameters. Result: ", static_cast(Result)); + { + LOG_WARNING_MESSAGE("Failed to get NGX D3D11 capability parameters. DLSS will not be available. Result: ", static_cast(Result)); + m_pNGXParams = nullptr; + NVSDK_NGX_D3D11_Shutdown1(pd3d11Device); + } } ~DLSSProviderD3D11() { if (m_pNGXParams != nullptr) + { NVSDK_NGX_D3D11_DestroyParameters(m_pNGXParams); - NVSDK_NGX_D3D11_Shutdown1(ClassPtrCast(m_pDevice.RawPtr())->GetD3D11Device()); + NVSDK_NGX_D3D11_Shutdown1(ClassPtrCast(m_pDevice.RawPtr())->GetD3D11Device()); + } } virtual void EnumerateVariants(std::vector& Variants) override final diff --git a/Graphics/SuperResolution/src/DLSSProviderD3D12.cpp b/Graphics/SuperResolution/src/DLSSProviderD3D12.cpp index 083cc1f25..1ce0dc2ef 100644 --- a/Graphics/SuperResolution/src/DLSSProviderD3D12.cpp +++ b/Graphics/SuperResolution/src/DLSSProviderD3D12.cpp @@ -68,8 +68,9 @@ class SuperResolutionD3D12_DLSS final : public SuperResolutionBase { ValidateTemporalExecuteSuperResolutionAttribs(m_Desc, Attribs); - if (m_pDLSSFeature == nullptr) - CreateFeature(Attribs); + NVSDK_NGX_Handle* pDLSSFeature = AcquireFeature(Attribs); + if (pDLSSFeature == nullptr) + return; DeviceContextD3D12Impl* pCtxImpl = ClassPtrCast(Attribs.pContext); @@ -111,7 +112,7 @@ class SuperResolutionD3D12_DLSS final : public SuperResolutionBase EvalParams.InPreExposure = Attribs.PreExposure; EvalParams.InExposureScale = Attribs.ExposureScale; - NVSDK_NGX_Result Result = NGX_D3D12_EVALUATE_DLSS_EXT(pCmdList, m_pDLSSFeature, m_pNGXParams, &EvalParams); + NVSDK_NGX_Result Result = NGX_D3D12_EVALUATE_DLSS_EXT(pCmdList, pDLSSFeature, m_pNGXParams, &EvalParams); if (NVSDK_NGX_FAILED(Result)) LOG_ERROR_MESSAGE("DLSS D3D12 evaluation failed. NGX Result: ", static_cast(Result)); @@ -120,11 +121,18 @@ class SuperResolutionD3D12_DLSS final : public SuperResolutionBase } private: - void CreateFeature(const ExecuteSuperResolutionAttribs& Attribs) + NVSDK_NGX_Handle* AcquireFeature(const ExecuteSuperResolutionAttribs& Attribs) { - Int32 DLSSCreateFeatureFlags = SuperResolutionFlagsToDLSSFeatureFlags(m_Desc.Flags); - if (Attribs.CameraNear > Attribs.CameraFar) - DLSSCreateFeatureFlags |= NVSDK_NGX_DLSS_Feature_Flags_DepthInverted; + const Int32 DLSSCreateFeatureFlags = ComputeDLSSFeatureFlags(m_Desc.Flags, Attribs); + if (m_pDLSSFeature != nullptr && m_DLSSFeatureFlags == DLSSCreateFeatureFlags) + return m_pDLSSFeature; + + if (m_pDLSSFeature != nullptr) + { + NVSDK_NGX_D3D12_ReleaseFeature(m_pDLSSFeature); + m_pDLSSFeature = nullptr; + } + m_DLSSFeatureFlags = DLSSCreateFeatureFlags; NVSDK_NGX_DLSS_Create_Params DLSSCreateParams = {}; DLSSCreateParams.Feature.InWidth = m_Desc.InputWidth; @@ -133,16 +141,23 @@ class SuperResolutionD3D12_DLSS final : public SuperResolutionBase DLSSCreateParams.Feature.InTargetHeight = m_Desc.OutputHeight; DLSSCreateParams.InFeatureCreateFlags = DLSSCreateFeatureFlags; + NVSDK_NGX_Handle* pFeature = nullptr; ID3D12GraphicsCommandList* pCmdList = ClassPtrCast(Attribs.pContext)->GetD3D12CommandList(); - NVSDK_NGX_Result Result = NGX_D3D12_CREATE_DLSS_EXT(pCmdList, 1, 1, &m_pDLSSFeature, m_pNGXParams, &DLSSCreateParams); + NVSDK_NGX_Result Result = NGX_D3D12_CREATE_DLSS_EXT(pCmdList, 1, 1, &pFeature, m_pNGXParams, &DLSSCreateParams); if (NVSDK_NGX_FAILED(Result)) - LOG_ERROR_AND_THROW("Failed to create DLSS D3D12 feature. NGX Result: ", static_cast(Result)); + { + LOG_ERROR_MESSAGE("Failed to create DLSS D3D12 feature. NGX Result: ", static_cast(Result)); + return nullptr; + } + m_pDLSSFeature = pFeature; + return m_pDLSSFeature; } RefCntAutoPtr m_pDevice; - NVSDK_NGX_Handle* m_pDLSSFeature = nullptr; - NVSDK_NGX_Parameter* m_pNGXParams = nullptr; + NVSDK_NGX_Handle* m_pDLSSFeature = nullptr; + NVSDK_NGX_Parameter* m_pNGXParams = nullptr; + Int32 m_DLSSFeatureFlags = 0; }; @@ -155,18 +170,27 @@ class DLSSProviderD3D12 final : public SuperResolutionProvider ID3D12Device* pd3d12Device = ClassPtrCast(pDevice)->GetD3D12Device(); NVSDK_NGX_Result Result = NVSDK_NGX_D3D12_Init_with_ProjectID(DLSSProjectId, NVSDK_NGX_ENGINE_TYPE_CUSTOM, "0", DLSSAppDataPath, pd3d12Device); if (NVSDK_NGX_FAILED(Result)) - LOG_ERROR_AND_THROW("NVIDIA NGX D3D12 initialization failed. Result: ", static_cast(Result)); + { + LOG_WARNING_MESSAGE("NVIDIA NGX D3D12 initialization failed. DLSS will not be available. Result: ", static_cast(Result)); + return; + } Result = NVSDK_NGX_D3D12_GetCapabilityParameters(&m_pNGXParams); if (NVSDK_NGX_FAILED(Result) || m_pNGXParams == nullptr) - LOG_ERROR_AND_THROW("Failed to get NGX D3D12 capability parameters. Result: ", static_cast(Result)); + { + LOG_WARNING_MESSAGE("Failed to get NGX D3D12 capability parameters. DLSS will not be available. Result: ", static_cast(Result)); + m_pNGXParams = nullptr; + NVSDK_NGX_D3D12_Shutdown1(pd3d12Device); + } } ~DLSSProviderD3D12() { if (m_pNGXParams != nullptr) + { NVSDK_NGX_D3D12_DestroyParameters(m_pNGXParams); - NVSDK_NGX_D3D12_Shutdown1(ClassPtrCast(m_pDevice.RawPtr())->GetD3D12Device()); + NVSDK_NGX_D3D12_Shutdown1(ClassPtrCast(m_pDevice.RawPtr())->GetD3D12Device()); + } } virtual void EnumerateVariants(std::vector& Variants) override final diff --git a/Graphics/SuperResolution/src/DLSSProviderVk.cpp b/Graphics/SuperResolution/src/DLSSProviderVk.cpp index f1c3ef9bc..b96e34d4f 100644 --- a/Graphics/SuperResolution/src/DLSSProviderVk.cpp +++ b/Graphics/SuperResolution/src/DLSSProviderVk.cpp @@ -69,8 +69,9 @@ class SuperResolutionVk_DLSS final : public SuperResolutionBase { ValidateTemporalExecuteSuperResolutionAttribs(m_Desc, Attribs); - if (m_pDLSSFeature == nullptr) - CreateFeature(Attribs); + NVSDK_NGX_Handle* pDLSSFeature = AcquireFeature(Attribs); + if (pDLSSFeature == nullptr) + return; DeviceContextVkImpl* pCtxImpl = ClassPtrCast(Attribs.pContext); @@ -127,17 +128,24 @@ class SuperResolutionVk_DLSS final : public SuperResolutionBase EvalParams.InPreExposure = Attribs.PreExposure; EvalParams.InExposureScale = Attribs.ExposureScale; - NVSDK_NGX_Result Result = NGX_VULKAN_EVALUATE_DLSS_EXT(vkCmdBuffer, m_pDLSSFeature, m_pNGXParams, &EvalParams); + NVSDK_NGX_Result Result = NGX_VULKAN_EVALUATE_DLSS_EXT(vkCmdBuffer, pDLSSFeature, m_pNGXParams, &EvalParams); if (NVSDK_NGX_FAILED(Result)) LOG_ERROR_MESSAGE("DLSS Vulkan evaluation failed. NGX Result: ", static_cast(Result)); } private: - void CreateFeature(const ExecuteSuperResolutionAttribs& Attribs) + NVSDK_NGX_Handle* AcquireFeature(const ExecuteSuperResolutionAttribs& Attribs) { - Int32 DLSSCreateFeatureFlags = SuperResolutionFlagsToDLSSFeatureFlags(m_Desc.Flags); - if (Attribs.CameraNear > Attribs.CameraFar) - DLSSCreateFeatureFlags |= NVSDK_NGX_DLSS_Feature_Flags_DepthInverted; + const Int32 DLSSCreateFeatureFlags = ComputeDLSSFeatureFlags(m_Desc.Flags, Attribs); + if (m_pDLSSFeature != nullptr && m_DLSSFeatureFlags == DLSSCreateFeatureFlags) + return m_pDLSSFeature; + + if (m_pDLSSFeature != nullptr) + { + NVSDK_NGX_VULKAN_ReleaseFeature(m_pDLSSFeature); + m_pDLSSFeature = nullptr; + } + m_DLSSFeatureFlags = DLSSCreateFeatureFlags; NVSDK_NGX_DLSS_Create_Params DLSSCreateParams = {}; DLSSCreateParams.Feature.InWidth = m_Desc.InputWidth; @@ -146,16 +154,23 @@ class SuperResolutionVk_DLSS final : public SuperResolutionBase DLSSCreateParams.Feature.InTargetHeight = m_Desc.OutputHeight; DLSSCreateParams.InFeatureCreateFlags = DLSSCreateFeatureFlags; - VkCommandBuffer vkCmdBuffer = ClassPtrCast(Attribs.pContext)->GetVkCommandBuffer(); - NVSDK_NGX_Result Result = NGX_VULKAN_CREATE_DLSS_EXT(vkCmdBuffer, 1, 1, &m_pDLSSFeature, m_pNGXParams, &DLSSCreateParams); + NVSDK_NGX_Handle* pFeature = nullptr; + VkCommandBuffer vkCmdBuffer = ClassPtrCast(Attribs.pContext)->GetVkCommandBuffer(); + NVSDK_NGX_Result Result = NGX_VULKAN_CREATE_DLSS_EXT(vkCmdBuffer, 1, 1, &pFeature, m_pNGXParams, &DLSSCreateParams); if (NVSDK_NGX_FAILED(Result)) - LOG_ERROR_AND_THROW("Failed to create DLSS Vulkan feature. NGX Result: ", static_cast(Result)); + { + LOG_ERROR_MESSAGE("Failed to create DLSS Vulkan feature. NGX Result: ", static_cast(Result)); + return nullptr; + } + m_pDLSSFeature = pFeature; + return m_pDLSSFeature; } RefCntAutoPtr m_pDevice; - NVSDK_NGX_Handle* m_pDLSSFeature = nullptr; - NVSDK_NGX_Parameter* m_pNGXParams = nullptr; + NVSDK_NGX_Handle* m_pDLSSFeature = nullptr; + NVSDK_NGX_Parameter* m_pNGXParams = nullptr; + Int32 m_DLSSFeatureFlags = 0; }; @@ -195,18 +210,27 @@ class DLSSProviderVk final : public SuperResolutionProvider } if (NVSDK_NGX_FAILED(Result)) - LOG_ERROR_AND_THROW("NVIDIA NGX Vulkan initialization failed. Result: ", static_cast(Result)); + { + LOG_WARNING_MESSAGE("NVIDIA NGX Vulkan initialization failed. DLSS will not be available. Result: ", static_cast(Result)); + return; + } Result = NVSDK_NGX_VULKAN_GetCapabilityParameters(&m_pNGXParams); if (NVSDK_NGX_FAILED(Result) || m_pNGXParams == nullptr) - LOG_ERROR_AND_THROW("Failed to get NGX Vulkan capability parameters. Result: ", static_cast(Result)); + { + LOG_WARNING_MESSAGE("Failed to get NGX Vulkan capability parameters. DLSS will not be available. Result: ", static_cast(Result)); + m_pNGXParams = nullptr; + NVSDK_NGX_VULKAN_Shutdown1(vkDevice); + } } ~DLSSProviderVk() { if (m_pNGXParams != nullptr) + { NVSDK_NGX_VULKAN_DestroyParameters(m_pNGXParams); - NVSDK_NGX_VULKAN_Shutdown1(ClassPtrCast(m_pDevice.RawPtr())->GetVkDevice()); + NVSDK_NGX_VULKAN_Shutdown1(ClassPtrCast(m_pDevice.RawPtr())->GetVkDevice()); + } } void EnumerateVariants(std::vector& Variants) diff --git a/Graphics/SuperResolution/src/SuperResolutionDLSS.cpp b/Graphics/SuperResolution/src/SuperResolutionDLSS.cpp index e2a7b9cce..7d92b7dc3 100644 --- a/Graphics/SuperResolution/src/SuperResolutionDLSS.cpp +++ b/Graphics/SuperResolution/src/SuperResolutionDLSS.cpp @@ -54,7 +54,7 @@ NVSDK_NGX_PerfQuality_Value OptimizationTypeToNGXPerfQuality(SUPER_RESOLUTION_OP } } -Int32 SuperResolutionFlagsToDLSSFeatureFlags(SUPER_RESOLUTION_FLAGS Flags) +Int32 ComputeDLSSFeatureFlags(SUPER_RESOLUTION_FLAGS Flags, const ExecuteSuperResolutionAttribs& Attribs) { Int32 DLSSFlags = NVSDK_NGX_DLSS_Feature_Flags_None; @@ -62,6 +62,8 @@ Int32 SuperResolutionFlagsToDLSSFeatureFlags(SUPER_RESOLUTION_FLAGS Flags) DLSSFlags |= NVSDK_NGX_DLSS_Feature_Flags_AutoExposure; if (Flags & SUPER_RESOLUTION_FLAG_ENABLE_SHARPENING) DLSSFlags |= NVSDK_NGX_DLSS_Feature_Flags_DoSharpening; + if (Attribs.CameraNear > Attribs.CameraFar) + DLSSFlags |= NVSDK_NGX_DLSS_Feature_Flags_DepthInverted; DLSSFlags |= NVSDK_NGX_DLSS_Feature_Flags_MVLowRes; DLSSFlags |= NVSDK_NGX_DLSS_Feature_Flags_IsHDR; @@ -71,7 +73,8 @@ Int32 SuperResolutionFlagsToDLSSFeatureFlags(SUPER_RESOLUTION_FLAGS Flags) void EnumerateDLSSVariants(NVSDK_NGX_Parameter* pNGXParams, std::vector& Variants) { - DEV_CHECK_ERR(pNGXParams != nullptr, "NGX parameters must not be null"); + if (pNGXParams == nullptr) + return; Int32 NeedsUpdatedDriver = 0; NVSDK_NGX_Parameter_GetI(pNGXParams, NVSDK_NGX_Parameter_SuperSampling_NeedsUpdatedDriver, &NeedsUpdatedDriver);