From bf58a7f4be7449e573d7dad2017d3b6798aeddf5 Mon Sep 17 00:00:00 2001 From: cdozdil Date: Sun, 26 Apr 2026 21:16:18 +0300 Subject: [PATCH] Added display res motion vector checks to RCAS/DA shaders --- OptiScaler/shaders/rcas/RCAS_Dx11.cpp | 16 +++++++++++----- OptiScaler/shaders/rcas/RCAS_Dx12.cpp | 14 +++++++++++--- OptiScaler/shaders/rcas/RCAS_Vk.cpp | 25 +++++++++++-------------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/OptiScaler/shaders/rcas/RCAS_Dx11.cpp b/OptiScaler/shaders/rcas/RCAS_Dx11.cpp index 1b529905..583ac18a 100644 --- a/OptiScaler/shaders/rcas/RCAS_Dx11.cpp +++ b/OptiScaler/shaders/rcas/RCAS_Dx11.cpp @@ -67,7 +67,14 @@ void RCAS_Dx11::FillMotionConstants(InternalConstants& OutConstants, const RcasC OutConstants.Threshold = Config::Instance()->MotionThreshold.value_or_default(); OutConstants.ScaleLimit = Config::Instance()->MotionScaleLimit.value_or_default(); - OutConstants.MotionTextureScale = (float) feature->RenderWidth() / (float) feature->TargetWidth(); + if (feature->LowResMV()) + { + OutConstants.MotionTextureScale = (float) feature->RenderWidth() / (float) feature->TargetWidth(); + } + else + { + OutConstants.MotionTextureScale = 1.0f; + } } void RCAS_Dx11::FillMotionConstants(InternalConstantsDA& OutConstants, const RcasConstants& InConstants) @@ -116,7 +123,7 @@ void RCAS_Dx11::FillMotionConstants(InternalConstantsDA& OutConstants, const Rca OutConstants.DepthWidth = feature->RenderWidth(); OutConstants.DepthHeight = feature->RenderHeight(); - OutConstants.MotionTextureScale = (float) feature->RenderWidth() / (float) feature->TargetWidth(); + OutConstants.MotionTextureScale = (float) OutConstants.MotionWidth / (float) feature->TargetWidth(); } bool RCAS_Dx11::CreateBufferResource(ID3D11Device* InDevice, ID3D11Resource* InResource) @@ -359,9 +366,8 @@ bool RCAS_Dx11::DispatchDepthAdaptive(ID3D11Device* InDevice, ID3D11DeviceContex InContext->CSSetShaderResources(0, 3, srvs); InContext->CSSetUnorderedAccessViews(0, 1, &_uavOutput, nullptr); - auto feature = State::Instance().currentFeature; - UINT dispatchWidth = (feature->TargetWidth() + InNumThreadsX - 1) / InNumThreadsX; - UINT dispatchHeight = (feature->TargetHeight() + InNumThreadsY - 1) / InNumThreadsY; + UINT dispatchWidth = (constants.DisplayWidth + InNumThreadsX - 1) / InNumThreadsX; + UINT dispatchHeight = (constants.DisplayHeight + InNumThreadsY - 1) / InNumThreadsY; InContext->Dispatch(dispatchWidth, dispatchHeight, 1); diff --git a/OptiScaler/shaders/rcas/RCAS_Dx12.cpp b/OptiScaler/shaders/rcas/RCAS_Dx12.cpp index ae021361..87307881 100644 --- a/OptiScaler/shaders/rcas/RCAS_Dx12.cpp +++ b/OptiScaler/shaders/rcas/RCAS_Dx12.cpp @@ -59,8 +59,15 @@ void RCAS_Dx12::FillMotionConstants(InternalConstants& OutConstants, const RcasC OutConstants.Threshold = Config::Instance()->MotionThreshold.value_or_default(); OutConstants.ScaleLimit = Config::Instance()->MotionScaleLimit.value_or_default(); + if (feature->LowResMV()) + { OutConstants.MotionTextureScale = (float) feature->RenderWidth() / (float) feature->TargetWidth(); } + else + { + OutConstants.MotionTextureScale = 1.0f; + } +} void RCAS_Dx12::FillMotionConstants(InternalConstantsDA& OutConstants, const RcasConstants& InConstants) { @@ -97,11 +104,13 @@ void RCAS_Dx12::FillMotionConstants(InternalConstantsDA& OutConstants, const Rca { OutConstants.MotionWidth = feature->RenderWidth(); OutConstants.MotionHeight = feature->RenderHeight(); + OutConstants.MotionTextureScale = (float) OutConstants.MotionWidth / (float) feature->TargetWidth(); } else { OutConstants.MotionWidth = feature->TargetWidth(); OutConstants.MotionHeight = feature->TargetHeight(); + OutConstants.MotionTextureScale = 1.0f; } OutConstants.DepthWidth = feature->RenderWidth(); @@ -172,9 +181,8 @@ bool RCAS_Dx12::DispatchDepthAdaptive(ID3D12GraphicsCommandList* InCmdList, ID3D InCmdList->SetPipelineState(_pipelineStateDA); InCmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); - auto inDesc = InResource->GetDesc(); - UINT dispatchWidth = static_cast((inDesc.Width + InNumThreadsX - 1) / InNumThreadsX); - UINT dispatchHeight = (inDesc.Height + InNumThreadsY - 1) / InNumThreadsY; + UINT dispatchWidth = static_cast((constants.DisplayWidth + InNumThreadsX - 1) / InNumThreadsX); + UINT dispatchHeight = (constants.DisplayHeight + InNumThreadsY - 1) / InNumThreadsY; InCmdList->Dispatch(dispatchWidth, dispatchHeight, 1); return true; diff --git a/OptiScaler/shaders/rcas/RCAS_Vk.cpp b/OptiScaler/shaders/rcas/RCAS_Vk.cpp index 5a37498c..15ff7b92 100644 --- a/OptiScaler/shaders/rcas/RCAS_Vk.cpp +++ b/OptiScaler/shaders/rcas/RCAS_Vk.cpp @@ -502,10 +502,14 @@ void RCAS_Vk::FillMotionConstants(InternalConstants& OutConstants, const RcasCon OutConstants.Threshold = Config::Instance()->MotionThreshold.value_or_default(); OutConstants.ScaleLimit = Config::Instance()->MotionScaleLimit.value_or_default(); - if (feature->TargetWidth() == 0) - OutConstants.MotionTextureScale = 1.0f; - else + if (feature->LowResMV()) + { OutConstants.MotionTextureScale = (float) feature->RenderWidth() / (float) feature->TargetWidth(); + } + else + { + OutConstants.MotionTextureScale = 1.0f; + } } void RCAS_Vk::FillMotionConstants(InternalConstantsDA& OutConstants, const RcasConstants& InConstants) @@ -535,11 +539,7 @@ void RCAS_Vk::FillMotionConstants(InternalConstantsDA& OutConstants, const RcasC OutConstants.DepthLinearA = InConstants.CameraNear * InConstants.CameraFar; OutConstants.DepthLinearB = InConstants.CameraFar; OutConstants.DepthLinearC = InConstants.CameraFar - InConstants.CameraNear; - - if (feature->DisplayWidth() == 0) - OutConstants.DepthTextureScale = 1.0f; - else - OutConstants.DepthTextureScale = (float) feature->RenderWidth() / (float) feature->DisplayWidth(); + OutConstants.DepthTextureScale = (float) feature->RenderWidth() / (float) feature->DisplayWidth(); OutConstants.ClampOutput = Config::Instance()->DAClampOutput.value_or(feature->IsHdr()) ? 0 : 1; @@ -550,17 +550,14 @@ void RCAS_Vk::FillMotionConstants(InternalConstantsDA& OutConstants, const RcasC } else { - OutConstants.MotionWidth = feature->DisplayWidth(); - OutConstants.MotionHeight = feature->DisplayHeight(); + OutConstants.MotionWidth = feature->TargetWidth(); + OutConstants.MotionHeight = feature->TargetHeight(); } OutConstants.DepthWidth = feature->RenderWidth(); OutConstants.DepthHeight = feature->RenderHeight(); - if (feature->TargetWidth() == 0) - OutConstants.MotionTextureScale = 1.0f; - else - OutConstants.MotionTextureScale = (float) feature->RenderWidth() / (float) feature->TargetWidth(); + OutConstants.MotionTextureScale = (float) OutConstants.MotionWidth / (float) feature->TargetWidth(); } bool RCAS_Vk::DispatchRCAS(VkDevice InDevice, VkCommandBuffer InCmdList, RcasConstants InConstants,