From 52bda52fe5c0b5d6798f602bf2bad9cfada85257 Mon Sep 17 00:00:00 2001 From: cdozdil Date: Tue, 20 Jan 2026 20:44:19 +0300 Subject: [PATCH] Fix Output Scaling, now < 1.0 values work too --- OptiScaler/upscalers/dlss/DLSSFeature_Vk.cpp | 35 ++++----- .../upscalers/dlssd/DLSSDFeature_Vk.cpp | 35 ++++----- OptiScaler/upscalers/fsr2/FSR2Feature_Vk.cpp | 75 +++++++++++-------- .../upscalers/fsr2_212/FSR2Feature_Vk_212.cpp | 75 +++++++++++-------- .../upscalers/fsr31/FSR31Feature_Vk.cpp | 75 +++++++++++-------- OptiScaler/upscalers/xess/XeSSFeature_Vk.cpp | 22 +++--- 6 files changed, 179 insertions(+), 138 deletions(-) diff --git a/OptiScaler/upscalers/dlss/DLSSFeature_Vk.cpp b/OptiScaler/upscalers/dlss/DLSSFeature_Vk.cpp index 143f7c19..a56002a2 100644 --- a/OptiScaler/upscalers/dlss/DLSSFeature_Vk.cpp +++ b/OptiScaler/upscalers/dlss/DLSSFeature_Vk.cpp @@ -123,6 +123,7 @@ bool DLSSFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I paramOutput == nullptr) { rcasEnabled = false; + useSS = false; } if (rcasEnabled) @@ -138,6 +139,10 @@ bool DLSSFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I paramOutput->Resource.ImageViewInfo.Height, paramOutput->Resource.ImageViewInfo.Format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == paramOutput->Resource.ImageViewInfo.Image) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + paramOutput->Resource.ImageViewInfo.Image = RCAS->GetImage(); paramOutput->Resource.ImageViewInfo.ImageView = RCAS->GetImageView(); @@ -148,11 +153,6 @@ bool DLSSFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == paramOutput->Resource.ImageViewInfo.Image) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - RCAS->SetImageLayout(InCmdBuffer, paramOutput->Resource.ImageViewInfo.Image, oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } @@ -164,13 +164,22 @@ bool DLSSFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I if (useSS) { + if (finalOutputImage != RCAS->GetImage()) + { + finalOutputView = paramOutput->Resource.ImageViewInfo.ImageView; + finalOutputImage = paramOutput->Resource.ImageViewInfo.Image; + } + VkImage oldImage = OS->GetImage(); if (OS->CreateImageResource( - Device, PhysicalDevice, paramOutput->Resource.ImageViewInfo.Width, - paramOutput->Resource.ImageViewInfo.Height, paramOutput->Resource.ImageViewInfo.Format, + Device, PhysicalDevice, TargetWidth(), TargetHeight(), paramOutput->Resource.ImageViewInfo.Format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == paramOutput->Resource.ImageViewInfo.Image) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + paramOutput->Resource.ImageViewInfo.Image = OS->GetImage(); paramOutput->Resource.ImageViewInfo.ImageView = OS->GetImageView(); @@ -181,11 +190,6 @@ bool DLSSFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == paramOutput->Resource.ImageViewInfo.Image) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - OS->SetImageLayout(InCmdBuffer, paramOutput->Resource.ImageViewInfo.Image, oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } @@ -209,7 +213,7 @@ bool DLSSFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I OS->SetImageLayout(InCmdBuffer, OS->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, range); - VkExtent2D outExtent = { TargetWidth(), TargetHeight() }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; if (!rcasEnabled) OS->Dispatch(Device, InCmdBuffer, OS->GetImageView(), finalOutputView, outExtent); @@ -239,8 +243,6 @@ bool DLSSFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I RCAS->SetImageLayout(InCmdBuffer, RCAS->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, range); - RCAS->SetImageLayout(InCmdBuffer, finalOutputImage, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, - range); RcasConstants rcasConstants {}; rcasConstants.Sharpness = _sharpness; @@ -252,8 +254,7 @@ bool DLSSFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I rcasConstants.RenderHeight = RenderHeight(); rcasConstants.RenderWidth = RenderWidth(); - VkExtent2D outExtent = { paramOutput->Resource.ImageViewInfo.Width, - paramOutput->Resource.ImageViewInfo.Height }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; RCAS->Dispatch(Device, InCmdBuffer, rcasConstants, RCAS->GetImageView(), paramVelocity->Resource.ImageViewInfo.ImageView, finalOutputView, outExtent); diff --git a/OptiScaler/upscalers/dlssd/DLSSDFeature_Vk.cpp b/OptiScaler/upscalers/dlssd/DLSSDFeature_Vk.cpp index e4f61a1e..d1cc1a40 100644 --- a/OptiScaler/upscalers/dlssd/DLSSDFeature_Vk.cpp +++ b/OptiScaler/upscalers/dlssd/DLSSDFeature_Vk.cpp @@ -127,6 +127,7 @@ bool DLSSDFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* paramOutput == nullptr) { rcasEnabled = false; + useSS = false; } if (rcasEnabled) @@ -142,6 +143,10 @@ bool DLSSDFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* paramOutput->Resource.ImageViewInfo.Height, paramOutput->Resource.ImageViewInfo.Format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == paramOutput->Resource.ImageViewInfo.Image) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + paramOutput->Resource.ImageViewInfo.Image = RCAS->GetImage(); paramOutput->Resource.ImageViewInfo.ImageView = RCAS->GetImageView(); @@ -152,11 +157,6 @@ bool DLSSDFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == paramOutput->Resource.ImageViewInfo.Image) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - RCAS->SetImageLayout(InCmdBuffer, paramOutput->Resource.ImageViewInfo.Image, oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } @@ -168,13 +168,22 @@ bool DLSSDFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* if (useSS) { + if (finalOutputImage != RCAS->GetImage()) + { + finalOutputView = paramOutput->Resource.ImageViewInfo.ImageView; + finalOutputImage = paramOutput->Resource.ImageViewInfo.Image; + } + VkImage oldImage = OS->GetImage(); if (OS->CreateImageResource( - Device, PhysicalDevice, paramOutput->Resource.ImageViewInfo.Width, - paramOutput->Resource.ImageViewInfo.Height, paramOutput->Resource.ImageViewInfo.Format, + Device, PhysicalDevice, TargetWidth(), TargetHeight(), paramOutput->Resource.ImageViewInfo.Format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == paramOutput->Resource.ImageViewInfo.Image) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + paramOutput->Resource.ImageViewInfo.Image = OS->GetImage(); paramOutput->Resource.ImageViewInfo.ImageView = OS->GetImageView(); @@ -185,11 +194,6 @@ bool DLSSDFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == paramOutput->Resource.ImageViewInfo.Image) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - OS->SetImageLayout(InCmdBuffer, paramOutput->Resource.ImageViewInfo.Image, oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } @@ -219,7 +223,7 @@ bool DLSSDFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* OS->SetImageLayout(InCmdBuffer, OS->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, range); - VkExtent2D outExtent = { TargetWidth(), TargetHeight() }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; if (!rcasEnabled) OS->Dispatch(Device, InCmdBuffer, OS->GetImageView(), finalOutputView, outExtent); @@ -243,8 +247,6 @@ bool DLSSDFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* RCAS->SetImageLayout(InCmdBuffer, RCAS->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, range); - RCAS->SetImageLayout(InCmdBuffer, finalOutputImage, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, - range); RcasConstants rcasConstants {}; rcasConstants.Sharpness = _sharpness; @@ -256,8 +258,7 @@ bool DLSSDFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* rcasConstants.RenderHeight = RenderHeight(); rcasConstants.RenderWidth = RenderWidth(); - VkExtent2D outExtent = { paramOutput->Resource.ImageViewInfo.Width, - paramOutput->Resource.ImageViewInfo.Height }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; RCAS->Dispatch(Device, InCmdBuffer, rcasConstants, RCAS->GetImageView(), paramVelocity->Resource.ImageViewInfo.ImageView, finalOutputView, outExtent); diff --git a/OptiScaler/upscalers/fsr2/FSR2Feature_Vk.cpp b/OptiScaler/upscalers/fsr2/FSR2Feature_Vk.cpp index 2c812d3c..b9328304 100644 --- a/OptiScaler/upscalers/fsr2/FSR2Feature_Vk.cpp +++ b/OptiScaler/upscalers/fsr2/FSR2Feature_Vk.cpp @@ -36,19 +36,19 @@ bool FSR2FeatureVk::InitFSR2(const NVSDK_NGX_Parameter* InParameters) _contextDesc.device = ffxGetDeviceVK(Device); - if (Config::Instance()->OutputScalingEnabled.value_or(false) && LowResMV()) + if (Config::Instance()->OutputScalingEnabled.value_or_default() && LowResMV()) { - float ssMulti = Config::Instance()->OutputScalingMultiplier.value_or(1.5f); + float ssMulti = Config::Instance()->OutputScalingMultiplier.value_or_default(); if (ssMulti < 0.5f) { ssMulti = 0.5f; - Config::Instance()->OutputScalingMultiplier = ssMulti; + Config::Instance()->OutputScalingMultiplier.set_volatile_value(ssMulti); } else if (ssMulti > 3.0f) { ssMulti = 3.0f; - Config::Instance()->OutputScalingMultiplier = ssMulti; + Config::Instance()->OutputScalingMultiplier.set_volatile_value(ssMulti); } _targetWidth = static_cast(DisplayWidth() * ssMulti); @@ -60,21 +60,39 @@ bool FSR2FeatureVk::InitFSR2(const NVSDK_NGX_Parameter* InParameters) _targetHeight = DisplayHeight(); } - if (Config::Instance()->ExtendedLimits.value_or(false) && RenderWidth() > DisplayWidth()) + // extended limits changes how resolution + if (Config::Instance()->ExtendedLimits.value_or_default() && RenderWidth() > DisplayWidth()) { - _targetWidth = RenderWidth(); - _targetHeight = RenderHeight(); + _contextDesc.maxRenderSize.width = RenderWidth(); + _contextDesc.maxRenderSize.height = RenderHeight(); - // enable output scaling to restore image - if (LowResMV()) + Config::Instance()->OutputScalingMultiplier.set_volatile_value(1.0f); + + // if output scaling active let it to handle downsampling + if (Config::Instance()->OutputScalingEnabled.value_or_default() && LowResMV()) { - Config::Instance()->OutputScalingMultiplier.set_volatile_value(1.0f); - Config::Instance()->OutputScalingEnabled.set_volatile_value(true); + + _contextDesc.displaySize.width = _contextDesc.maxRenderSize.width; + _contextDesc.displaySize.height = _contextDesc.maxRenderSize.height; + + // update target res + _targetWidth = _contextDesc.maxRenderSize.width; + _targetHeight = _contextDesc.maxRenderSize.height; + } + else + { + _contextDesc.displaySize.width = DisplayWidth(); + _contextDesc.displaySize.height = DisplayHeight(); } } + else + { + _contextDesc.maxRenderSize.width = TargetWidth() > DisplayWidth() ? TargetWidth() : DisplayWidth(); + _contextDesc.maxRenderSize.height = TargetHeight() > DisplayHeight() ? TargetHeight() : DisplayHeight(); + _contextDesc.displaySize.width = TargetWidth(); + _contextDesc.displaySize.height = TargetHeight(); + } - _contextDesc.displaySize.width = TargetWidth(); - _contextDesc.displaySize.height = TargetHeight(); _contextDesc.flags = 0; if (DepthInverted()) @@ -372,6 +390,10 @@ bool FSR2FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == params.output.resource) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + params.output = ffxGetTextureResourceVK(&_context, RCAS->GetImage(), RCAS->GetImageView(), ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Width, @@ -386,11 +408,6 @@ bool FSR2FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == RCAS->GetImage()) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - RCAS->SetImageLayout(InCmdBuffer, RCAS->GetImage(), oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } else @@ -403,12 +420,15 @@ bool FSR2FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I { VkImage oldImage = OS->GetImage(); - if (OS->CreateImageResource( - Device, PhysicalDevice, ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Width, - ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Height, - ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Format, - VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) + if (OS->CreateImageResource(Device, PhysicalDevice, TargetWidth(), TargetHeight(), + ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Format, + VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == params.output.resource) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + params.output = ffxGetTextureResourceVK(&_context, OS->GetImage(), OS->GetImageView(), ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Width, @@ -423,11 +443,6 @@ bool FSR2FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == OS->GetImage()) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - OS->SetImageLayout(InCmdBuffer, OS->GetImage(), oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } else @@ -542,7 +557,7 @@ bool FSR2FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I OS->SetImageLayout(InCmdBuffer, OS->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, range); - VkExtent2D outExtent = { TargetWidth(), TargetHeight() }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; if (!rcasEnabled) OS->Dispatch(Device, InCmdBuffer, OS->GetImageView(), finalOutputView, outExtent); @@ -572,7 +587,7 @@ bool FSR2FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* I rcasConstants.RenderHeight = RenderHeight(); rcasConstants.RenderWidth = RenderWidth(); - VkExtent2D outExtent = { params.output.description.width, params.output.description.height }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; RCAS->Dispatch(Device, InCmdBuffer, rcasConstants, RCAS->GetImageView(), ((NVSDK_NGX_Resource_VK*) paramVelocity)->Resource.ImageViewInfo.ImageView, finalOutputView, diff --git a/OptiScaler/upscalers/fsr2_212/FSR2Feature_Vk_212.cpp b/OptiScaler/upscalers/fsr2_212/FSR2Feature_Vk_212.cpp index 674b77bb..7cf7b4c9 100644 --- a/OptiScaler/upscalers/fsr2_212/FSR2Feature_Vk_212.cpp +++ b/OptiScaler/upscalers/fsr2_212/FSR2Feature_Vk_212.cpp @@ -36,19 +36,19 @@ bool FSR2FeatureVk212::InitFSR2(const NVSDK_NGX_Parameter* InParameters) _contextDesc.device = Fsr212::ffxGetDeviceVK212(Device); - if (Config::Instance()->OutputScalingEnabled.value_or(false) && LowResMV()) + if (Config::Instance()->OutputScalingEnabled.value_or_default() && LowResMV()) { - float ssMulti = Config::Instance()->OutputScalingMultiplier.value_or(1.5f); + float ssMulti = Config::Instance()->OutputScalingMultiplier.value_or_default(); if (ssMulti < 0.5f) { ssMulti = 0.5f; - Config::Instance()->OutputScalingMultiplier = ssMulti; + Config::Instance()->OutputScalingMultiplier.set_volatile_value(ssMulti); } else if (ssMulti > 3.0f) { ssMulti = 3.0f; - Config::Instance()->OutputScalingMultiplier = ssMulti; + Config::Instance()->OutputScalingMultiplier.set_volatile_value(ssMulti); } _targetWidth = static_cast(DisplayWidth() * ssMulti); @@ -60,21 +60,37 @@ bool FSR2FeatureVk212::InitFSR2(const NVSDK_NGX_Parameter* InParameters) _targetHeight = DisplayHeight(); } - if (Config::Instance()->ExtendedLimits.value_or(false) && RenderWidth() > DisplayWidth()) + // extended limits changes how resolution + if (Config::Instance()->ExtendedLimits.value_or_default() && RenderWidth() > DisplayWidth()) { - _targetWidth = RenderWidth(); - _targetHeight = RenderHeight(); + _contextDesc.maxRenderSize.width = RenderWidth(); + _contextDesc.maxRenderSize.height = RenderHeight(); - // enable output scaling to restore image - if (LowResMV()) + Config::Instance()->OutputScalingMultiplier.set_volatile_value(1.0f); + + // if output scaling active let it to handle downsampling + if (Config::Instance()->OutputScalingEnabled.value_or_default() && LowResMV()) { - Config::Instance()->OutputScalingMultiplier.set_volatile_value(1.0f); - Config::Instance()->OutputScalingEnabled.set_volatile_value(true); + _contextDesc.displaySize.width = _contextDesc.maxRenderSize.width; + _contextDesc.displaySize.height = _contextDesc.maxRenderSize.height; + + // update target res + _targetWidth = _contextDesc.maxRenderSize.width; + _targetHeight = _contextDesc.maxRenderSize.height; + } + else + { + _contextDesc.displaySize.width = DisplayWidth(); + _contextDesc.displaySize.height = DisplayHeight(); } } - - _contextDesc.displaySize.width = TargetWidth(); - _contextDesc.displaySize.height = TargetHeight(); + else + { + _contextDesc.maxRenderSize.width = TargetWidth() > DisplayWidth() ? TargetWidth() : DisplayWidth(); + _contextDesc.maxRenderSize.height = TargetHeight() > DisplayHeight() ? TargetHeight() : DisplayHeight(); + _contextDesc.displaySize.width = TargetWidth(); + _contextDesc.displaySize.height = TargetHeight(); + } _contextDesc.flags = 0; @@ -397,6 +413,10 @@ bool FSR2FeatureVk212::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == RCAS->GetImage()) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + params.output = Fsr212::ffxGetTextureResourceVK212( &_context, RCAS->GetImage(), RCAS->GetImageView(), ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Width, @@ -411,11 +431,6 @@ bool FSR2FeatureVk212::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == RCAS->GetImage()) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - RCAS->SetImageLayout(InCmdBuffer, RCAS->GetImage(), oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } else @@ -428,12 +443,15 @@ bool FSR2FeatureVk212::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter { VkImage oldImage = OS->GetImage(); - if (OS->CreateImageResource( - Device, PhysicalDevice, ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Width, - ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Height, - ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Format, - VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) + if (OS->CreateImageResource(Device, PhysicalDevice, TargetWidth(), TargetHeight(), + ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Format, + VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == OS->GetImage()) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + params.output = Fsr212::ffxGetTextureResourceVK212( &_context, OS->GetImage(), OS->GetImageView(), ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Width, @@ -448,11 +466,6 @@ bool FSR2FeatureVk212::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == OS->GetImage()) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - OS->SetImageLayout(InCmdBuffer, OS->GetImage(), oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } else @@ -567,7 +580,7 @@ bool FSR2FeatureVk212::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter OS->SetImageLayout(InCmdBuffer, OS->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, range); - VkExtent2D outExtent = { TargetWidth(), TargetHeight() }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; if (!rcasEnabled) OS->Dispatch(Device, InCmdBuffer, OS->GetImageView(), finalOutputView, outExtent); @@ -597,7 +610,7 @@ bool FSR2FeatureVk212::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter rcasConstants.RenderHeight = RenderHeight(); rcasConstants.RenderWidth = RenderWidth(); - VkExtent2D outExtent = { params.output.description.width, params.output.description.height }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; RCAS->Dispatch(Device, InCmdBuffer, rcasConstants, RCAS->GetImageView(), ((NVSDK_NGX_Resource_VK*) paramVelocity)->Resource.ImageViewInfo.ImageView, finalOutputView, diff --git a/OptiScaler/upscalers/fsr31/FSR31Feature_Vk.cpp b/OptiScaler/upscalers/fsr31/FSR31Feature_Vk.cpp index 956b0f8a..ef17a40a 100644 --- a/OptiScaler/upscalers/fsr31/FSR31Feature_Vk.cpp +++ b/OptiScaler/upscalers/fsr31/FSR31Feature_Vk.cpp @@ -193,19 +193,19 @@ bool FSR31FeatureVk::InitFSR3(const NVSDK_NGX_Parameter* InParameters) LOG_INFO("contextDesc.initFlags (NonLinearColorSpace) {0:b}", _contextDesc.flags); } - if (Config::Instance()->OutputScalingEnabled.value_or(false) && LowResMV()) + if (Config::Instance()->OutputScalingEnabled.value_or_default() && LowResMV()) { - float ssMulti = Config::Instance()->OutputScalingMultiplier.value_or(1.5f); + float ssMulti = Config::Instance()->OutputScalingMultiplier.value_or_default(); if (ssMulti < 0.5f) { ssMulti = 0.5f; - Config::Instance()->OutputScalingMultiplier = ssMulti; + Config::Instance()->OutputScalingMultiplier.set_volatile_value(ssMulti); } else if (ssMulti > 3.0f) { ssMulti = 3.0f; - Config::Instance()->OutputScalingMultiplier = ssMulti; + Config::Instance()->OutputScalingMultiplier.set_volatile_value(ssMulti); } _targetWidth = static_cast(DisplayWidth() * ssMulti); @@ -217,21 +217,37 @@ bool FSR31FeatureVk::InitFSR3(const NVSDK_NGX_Parameter* InParameters) _targetHeight = DisplayHeight(); } - if (Config::Instance()->ExtendedLimits.value_or(false) && RenderWidth() > DisplayWidth()) + // extended limits changes how resolution + if (Config::Instance()->ExtendedLimits.value_or_default() && RenderWidth() > DisplayWidth()) { - _targetWidth = RenderWidth(); - _targetHeight = RenderHeight(); + _contextDesc.maxRenderSize.width = RenderWidth(); + _contextDesc.maxRenderSize.height = RenderHeight(); - // enable output scaling to restore image - if (LowResMV()) + Config::Instance()->OutputScalingMultiplier.set_volatile_value(1.0f); + + // if output scaling active let it to handle downsampling + if (Config::Instance()->OutputScalingEnabled.value_or_default() && LowResMV()) { - Config::Instance()->OutputScalingMultiplier.set_volatile_value(1.0f); - Config::Instance()->OutputScalingEnabled.set_volatile_value(true); + _contextDesc.maxUpscaleSize.width = _contextDesc.maxRenderSize.width; + _contextDesc.maxUpscaleSize.height = _contextDesc.maxRenderSize.height; + + // update target res + _targetWidth = _contextDesc.maxRenderSize.width; + _targetHeight = _contextDesc.maxRenderSize.height; + } + else + { + _contextDesc.maxUpscaleSize.width = DisplayWidth(); + _contextDesc.maxUpscaleSize.height = DisplayHeight(); } } - - _contextDesc.maxUpscaleSize.width = TargetWidth(); - _contextDesc.maxUpscaleSize.height = TargetHeight(); + else + { + _contextDesc.maxRenderSize.width = TargetWidth() > DisplayWidth() ? TargetWidth() : DisplayWidth(); + _contextDesc.maxRenderSize.height = TargetHeight() > DisplayHeight() ? TargetHeight() : DisplayHeight(); + _contextDesc.maxUpscaleSize.width = TargetWidth(); + _contextDesc.maxUpscaleSize.height = TargetHeight(); + } ffxCreateBackendVKDesc backendDesc = { 0 }; backendDesc.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK; @@ -517,6 +533,10 @@ bool FSR31FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == params.output.resource) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + params.output = ffxApiGetResourceVK( RCAS->GetImage(), ffxApiGetImageResourceDescriptionVKLocal((NVSDK_NGX_Resource_VK*) paramOutput), FFX_API_RESOURCE_STATE_UNORDERED_ACCESS); @@ -528,11 +548,6 @@ bool FSR31FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == RCAS->GetImage()) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - RCAS->SetImageLayout(InCmdBuffer, RCAS->GetImage(), oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } else @@ -545,12 +560,15 @@ bool FSR31FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* { VkImage oldImage = OS->GetImage(); - if (OS->CreateImageResource( - Device, PhysicalDevice, ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Width, - ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Height, - ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Format, - VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) + if (OS->CreateImageResource(Device, PhysicalDevice, TargetWidth(), TargetHeight(), + ((NVSDK_NGX_Resource_VK*) paramOutput)->Resource.ImageViewInfo.Format, + VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == params.output.resource) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + params.output = ffxApiGetResourceVK( OS->GetImage(), ffxApiGetImageResourceDescriptionVKLocal((NVSDK_NGX_Resource_VK*) paramOutput), FFX_API_RESOURCE_STATE_UNORDERED_ACCESS); @@ -562,11 +580,6 @@ bool FSR31FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == OS->GetImage()) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - OS->SetImageLayout(InCmdBuffer, OS->GetImage(), oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } else @@ -763,7 +776,7 @@ bool FSR31FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* OS->SetImageLayout(InCmdBuffer, OS->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, range); - VkExtent2D outExtent = { TargetWidth(), TargetHeight() }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; if (!rcasEnabled) OS->Dispatch(Device, InCmdBuffer, OS->GetImageView(), finalOutputView, outExtent); @@ -793,7 +806,7 @@ bool FSR31FeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* rcasConstants.RenderHeight = RenderHeight(); rcasConstants.RenderWidth = RenderWidth(); - VkExtent2D outExtent = { params.output.description.width, params.output.description.height }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; RCAS->Dispatch(Device, InCmdBuffer, rcasConstants, RCAS->GetImageView(), ((NVSDK_NGX_Resource_VK*) paramVelocity)->Resource.ImageViewInfo.ImageView, finalOutputView, diff --git a/OptiScaler/upscalers/xess/XeSSFeature_Vk.cpp b/OptiScaler/upscalers/xess/XeSSFeature_Vk.cpp index 5c318ddf..022bc75e 100644 --- a/OptiScaler/upscalers/xess/XeSSFeature_Vk.cpp +++ b/OptiScaler/upscalers/xess/XeSSFeature_Vk.cpp @@ -511,6 +511,10 @@ bool XeSSFeature_Vk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == params.outputTexture.image) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + params.outputTexture.image = RCAS->GetImage(); params.outputTexture.imageView = RCAS->GetImageView(); @@ -521,11 +525,6 @@ bool XeSSFeature_Vk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == params.outputTexture.image) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - RCAS->SetImageLayout(InCmdBuffer, params.outputTexture.image, oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } else @@ -542,6 +541,10 @@ bool XeSSFeature_Vk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { + VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (oldImage != VK_NULL_HANDLE && oldImage == params.outputTexture.image) + oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + params.outputTexture.image = OS->GetImage(); params.outputTexture.imageView = OS->GetImageView(); @@ -552,11 +555,6 @@ bool XeSSFeature_Vk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* range.baseArrayLayer = 0; range.layerCount = 1; - VkImageLayout oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - if (oldImage != VK_NULL_HANDLE && oldImage == params.outputTexture.image) - oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - OS->SetImageLayout(InCmdBuffer, params.outputTexture.image, oldLayout, VK_IMAGE_LAYOUT_GENERAL, range); } else @@ -586,7 +584,7 @@ bool XeSSFeature_Vk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* OS->SetImageLayout(InCmdBuffer, OS->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, range); - VkExtent2D outExtent = { TargetWidth(), TargetHeight() }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; if (!rcasEnabled) OS->Dispatch(Device, InCmdBuffer, OS->GetImageView(), finalOutputView, outExtent); @@ -616,7 +614,7 @@ bool XeSSFeature_Vk::Evaluate(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Parameter* rcasConstants.RenderHeight = RenderHeight(); rcasConstants.RenderWidth = RenderWidth(); - VkExtent2D outExtent = { params.outputTexture.width, params.outputTexture.height }; + VkExtent2D outExtent = { DisplayWidth(), DisplayHeight() }; RCAS->Dispatch(Device, InCmdBuffer, rcasConstants, RCAS->GetImageView(), params.velocityTexture.imageView, finalOutputView, outExtent);