From 0d6444684e62775eb8d6ea3d538cbcb295ab93e4 Mon Sep 17 00:00:00 2001 From: FakeMichau <49685661+FakeMichau@users.noreply.github.com> Date: Fri, 15 Aug 2025 14:22:42 +0200 Subject: [PATCH] Add resource base position --- OptiScaler/framegen/IFGFeature.cpp | 6 +++ OptiScaler/framegen/IFGFeature.h | 1 + OptiScaler/framegen/IFGFeature_Dx12.h | 2 + .../framegen/Streamline_Inputs_Dx12.cpp | 10 ++++ OptiScaler/framegen/ffx/FSRFG_Dx12.cpp | 2 + OptiScaler/framegen/xefg/XeFG_Dx12.cpp | 53 +++++-------------- OptiScaler/framegen/xefg/XeFG_Dx12.h | 2 +- OptiScaler/hudfix/Hudfix_Dx12.cpp | 36 +++++++++++-- 8 files changed, 67 insertions(+), 45 deletions(-) diff --git a/OptiScaler/framegen/IFGFeature.cpp b/OptiScaler/framegen/IFGFeature.cpp index b1334b33..1c46f5e2 100644 --- a/OptiScaler/framegen/IFGFeature.cpp +++ b/OptiScaler/framegen/IFGFeature.cpp @@ -99,6 +99,12 @@ void IFGFeature::SetInterpolationRect(UINT width, UINT height) _interpolationHeight = height; } +void IFGFeature::GetInterpolationRect(UINT& width, UINT& height) +{ + width = _interpolationWidth; + height = _interpolationHeight; +} + void IFGFeature::ResetCounters() { _frameCount = 0; diff --git a/OptiScaler/framegen/IFGFeature.h b/OptiScaler/framegen/IFGFeature.h index b8c6e32a..4072a1a8 100644 --- a/OptiScaler/framegen/IFGFeature.h +++ b/OptiScaler/framegen/IFGFeature.h @@ -115,6 +115,7 @@ class IFGFeature void SetFrameTimeDelta(float delta); void SetReset(UINT reset); void SetInterpolationRect(UINT width, UINT height); + void GetInterpolationRect(UINT& width, UINT& height); void ResetCounters(); void UpdateTarget(); diff --git a/OptiScaler/framegen/IFGFeature_Dx12.h b/OptiScaler/framegen/IFGFeature_Dx12.h index 4415c77b..c8cd0c60 100644 --- a/OptiScaler/framegen/IFGFeature_Dx12.h +++ b/OptiScaler/framegen/IFGFeature_Dx12.h @@ -14,6 +14,8 @@ typedef struct Dx12Resource { FG_ResourceType type; ID3D12Resource* resource = nullptr; + UINT top = 0; + UINT left = 0; UINT width = 0; UINT height = 0; ID3D12GraphicsCommandList* cmdList = nullptr; diff --git a/OptiScaler/framegen/Streamline_Inputs_Dx12.cpp b/OptiScaler/framegen/Streamline_Inputs_Dx12.cpp index 639802f2..41eb81cc 100644 --- a/OptiScaler/framegen/Streamline_Inputs_Dx12.cpp +++ b/OptiScaler/framegen/Streamline_Inputs_Dx12.cpp @@ -204,6 +204,8 @@ bool Sl_Inputs_Dx12::reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCo setResource.type = FG_ResourceType::HudlessColor; setResource.cmdList = cmdBuffer; setResource.resource = hudlessResource; + setResource.top = tag.extent.top; + setResource.left = tag.extent.left; setResource.width = width; setResource.height = height; setResource.state = (D3D12_RESOURCE_STATES) tag.resource->state; @@ -253,6 +255,8 @@ bool Sl_Inputs_Dx12::reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCo setResource.type = FG_ResourceType::Depth; setResource.cmdList = cmdBuffer; setResource.resource = depthResource; + setResource.top = tag.extent.top; + setResource.left = tag.extent.left; setResource.width = width; setResource.height = height; setResource.state = (D3D12_RESOURCE_STATES) tag.resource->state; @@ -288,6 +292,8 @@ bool Sl_Inputs_Dx12::reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCo setResource.type = FG_ResourceType::Velocity; setResource.cmdList = cmdBuffer; setResource.resource = mvResource; + setResource.top = tag.extent.top; + setResource.left = tag.extent.left; setResource.width = width; setResource.height = height; setResource.state = (D3D12_RESOURCE_STATES) tag.resource->state; @@ -322,6 +328,8 @@ bool Sl_Inputs_Dx12::reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCo setResource.type = FG_ResourceType::UIColor; setResource.cmdList = cmdBuffer; setResource.resource = uiResource; + setResource.top = tag.extent.top; + setResource.left = tag.extent.left; setResource.width = width; setResource.height = height; setResource.state = (D3D12_RESOURCE_STATES) tag.resource->state; @@ -355,6 +363,8 @@ bool Sl_Inputs_Dx12::reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCo setResource.type = FG_ResourceType::Distortion; setResource.cmdList = cmdBuffer; setResource.resource = distortionFieldResource; + setResource.top = tag.extent.top; + setResource.left = tag.extent.left; setResource.width = width; setResource.height = height; setResource.state = (D3D12_RESOURCE_STATES) tag.resource->state; diff --git a/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp b/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp index 38f7e897..75f388c8 100644 --- a/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp +++ b/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp @@ -272,6 +272,8 @@ bool FSRFG_Dx12::Dispatch() if (State::Instance().currentFeature && State::Instance().activeFgInput == FGInput::Upscaler) dfgPrepare.renderSize = { State::Instance().currentFeature->RenderWidth(), State::Instance().currentFeature->RenderHeight() }; + else if (depth != nullptr) + dfgPrepare.renderSize = { depth->width, depth->height }; else dfgPrepare.renderSize = { dfgPrepare.depth.description.width, dfgPrepare.depth.description.height }; diff --git a/OptiScaler/framegen/xefg/XeFG_Dx12.cpp b/OptiScaler/framegen/xefg/XeFG_Dx12.cpp index 0b259a44..fe8f18eb 100644 --- a/OptiScaler/framegen/xefg/XeFG_Dx12.cpp +++ b/OptiScaler/framegen/xefg/XeFG_Dx12.cpp @@ -154,6 +154,7 @@ xefg_swapchain_d3d12_resource_data_t XeFG_Dx12::GetResourceData(FG_ResourceType ? XEFG_SWAPCHAIN_RV_ONLY_NOW : XEFG_SWAPCHAIN_RV_UNTIL_NEXT_PRESENT; + resourceParam.resourceBase = { fResource->left, fResource->top }; resourceParam.resourceSize = { fResource->width, fResource->height }; resourceParam.pResource = fResource->GetResource(); resourceParam.incomingState = fResource->state; @@ -180,36 +181,6 @@ xefg_swapchain_d3d12_resource_data_t XeFG_Dx12::GetResourceData(FG_ResourceType return xefg_swapchain_d3d12_resource_data_t {}; } - if (type == FG_ResourceType::UIColor || type == FG_ResourceType::HudlessColor) - { - uint32_t left = 0; - uint32_t top = 0; - - // use swapchain buffer info - DXGI_SWAP_CHAIN_DESC scDesc1 {}; - if (State::Instance().currentSwapchain->GetDesc(&scDesc1) == S_OK) - { - LOG_DEBUG("SwapChain Res: {}x{}, Upscaler Display Res: {}x{}", scDesc1.BufferDesc.Width, - scDesc1.BufferDesc.Height, _interpolationWidth, _interpolationHeight); - - auto calculatedLeft = ((int) scDesc1.BufferDesc.Width - (int) _interpolationWidth) / 2; - if (calculatedLeft > 0) - left = Config::Instance()->FGRectLeft.value_or(calculatedLeft); - - auto calculatedTop = ((int) scDesc1.BufferDesc.Height - (int) _interpolationHeight) / 2; - if (calculatedTop > 0) - top = Config::Instance()->FGRectTop.value_or(calculatedTop); - } - else - { - left = Config::Instance()->FGRectLeft.value_or(0); - top = Config::Instance()->FGRectTop.value_or(0); - } - - resourceParam.resourceBase = { left, top }; - resourceParam.resourceSize = { _interpolationWidth, _interpolationHeight }; - } - return resourceParam; } @@ -438,8 +409,8 @@ bool XeFG_Dx12::Dispatch() Config::Instance()->FGXeFGDebugView.value_or_default(), nullptr); XeFGProxy::EnableDebugFeature()(_swapChainContext, XEFG_SWAPCHAIN_DEBUG_FEATURE_SHOW_ONLY_INTERPOLATION, State::Instance().FGonlyGenerated, nullptr); - XeFGProxy::EnableDebugFeature()(_swapChainContext, XEFG_SWAPCHAIN_DEBUG_FEATURE_PRESENT_FAILED_INTERPOLATION, - State::Instance().FGonlyGenerated, nullptr); + // XeFGProxy::EnableDebugFeature()(_swapChainContext, XEFG_SWAPCHAIN_DEBUG_FEATURE_PRESENT_FAILED_INTERPOLATION, + // State::Instance().FGonlyGenerated, nullptr); xefg_swapchain_frame_constant_data_t constData = {}; @@ -465,6 +436,11 @@ bool XeFG_Dx12::Dispatch() if (Config::Instance()->FGXeFGDepthInverted.value_or_default()) std::swap(_cameraNear, _cameraFar); + if (_infiniteDepth && _cameraFar > _cameraNear) + _cameraFar = INFINITE; + else if (_infiniteDepth && _cameraNear > _cameraFar) + _cameraNear = INFINITE; + // Cyberpunk seems to be sending LH so do the same // it also sends some extra data in usually empty spots but no idea what that is if (_cameraNear > 0.f && _cameraFar > 0.f) @@ -509,7 +485,7 @@ bool XeFG_Dx12::Dispatch() DXGI_SWAP_CHAIN_DESC scDesc1 {}; if (State::Instance().currentSwapchain->GetDesc(&scDesc1) == S_OK) { - LOG_DEBUG("SwapChain Res: {}x{}, Upscaler Display Res: {}x{}", scDesc1.BufferDesc.Width, + LOG_DEBUG("SwapChain Res: {}x{}, Interpolation Res: {}x{}", scDesc1.BufferDesc.Width, scDesc1.BufferDesc.Height, _interpolationWidth, _interpolationHeight); auto calculatedLeft = ((int) scDesc1.BufferDesc.Width - (int) _interpolationWidth) / 2; @@ -556,14 +532,7 @@ void XeFG_Dx12::EvaluateState(ID3D12Device* device, FG_Constants& fgConstants) if (!Config::Instance()->OverlayMenu.value_or_default()) return; - static bool lastInfiniteDepth = false; - bool currentInfiniteDepth = static_cast(fgConstants.flags & FG_Flags::InfiniteDepth); - if (lastInfiniteDepth != currentInfiniteDepth) - { - lastInfiniteDepth = currentInfiniteDepth; - LOG_DEBUG("Infinite Depth changed: {}", currentInfiniteDepth); - State::Instance().FGchanged = true; - } + _infiniteDepth = static_cast(fgConstants.flags & FG_Flags::InfiniteDepth); if (!State::Instance().FGchanged && Config::Instance()->FGEnabled.value_or_default() && !IsPaused() && XeFGProxy::InitXeFG() && _fgContext == nullptr && HooksDx::CurrentSwapchainFormat() != DXGI_FORMAT_UNKNOWN) @@ -667,6 +636,8 @@ void XeFG_Dx12::SetResource(Dx12Resource* inputResource) fResource->state = inputResource->state; fResource->validity = inputResource->validity; fResource->resource = inputResource->resource; + fResource->top = inputResource->top; + fResource->left = inputResource->left; fResource->width = inputResource->width; fResource->height = inputResource->height; fResource->cmdList = inputResource->cmdList; diff --git a/OptiScaler/framegen/xefg/XeFG_Dx12.h b/OptiScaler/framegen/xefg/XeFG_Dx12.h index fe0fc268..d44558f0 100644 --- a/OptiScaler/framegen/xefg/XeFG_Dx12.h +++ b/OptiScaler/framegen/xefg/XeFG_Dx12.h @@ -21,7 +21,7 @@ class XeFG_Dx12 : public virtual IFGFeature_Dx12 uint32_t _width = 0; uint32_t _height = 0; - int _featureFlags = 0; + bool _infiniteDepth = false; static void xefgLogCallback(const char* message, xefg_swapchain_logging_level_t level, void* userData); diff --git a/OptiScaler/hudfix/Hudfix_Dx12.cpp b/OptiScaler/hudfix/Hudfix_Dx12.cpp index 5b1d256b..ffd914df 100644 --- a/OptiScaler/hudfix/Hudfix_Dx12.cpp +++ b/OptiScaler/hudfix/Hudfix_Dx12.cpp @@ -658,6 +658,35 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL } } + auto fg = reinterpret_cast(State::Instance().currentFG); + UINT interpolationRectWidth, interpolationRectHeight = 0; + if (fg != nullptr) + fg->GetInterpolationRect(interpolationRectWidth, interpolationRectHeight); + + uint32_t left = 0; + uint32_t top = 0; + + // use swapchain buffer info + DXGI_SWAP_CHAIN_DESC scDesc1 {}; + if (State::Instance().currentSwapchain->GetDesc(&scDesc1) == S_OK) + { + LOG_DEBUG("SwapChain Res: {}x{}, Upscaler Display Res: {}x{}", scDesc1.BufferDesc.Width, + scDesc1.BufferDesc.Height, interpolationRectWidth, interpolationRectHeight); + + auto calculatedLeft = ((int) scDesc1.BufferDesc.Width - (int) interpolationRectWidth) / 2; + if (calculatedLeft > 0) + left = Config::Instance()->FGRectLeft.value_or(calculatedLeft); + + auto calculatedTop = ((int) scDesc1.BufferDesc.Height - (int) interpolationRectHeight) / 2; + if (calculatedTop > 0) + top = Config::Instance()->FGRectTop.value_or(calculatedTop); + } + else + { + left = Config::Instance()->FGRectLeft.value_or(0); + top = Config::Instance()->FGRectTop.value_or(0); + } + // needs conversion? if (resource->format != scDesc.BufferDesc.Format) { @@ -693,14 +722,14 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL LOG_TRACE("Using _formatTransfer->Buffer()"); - auto fg = reinterpret_cast(State::Instance().currentFG); - if (fg != nullptr) { Dx12Resource setResource {}; setResource.type = FG_ResourceType::HudlessColor; setResource.cmdList = cmdList; setResource.resource = _formatTransfer[fIndex]->Buffer(); + setResource.left = left; + setResource.top = top; setResource.width = scDesc.BufferDesc.Width; setResource.height = scDesc.BufferDesc.Height; setResource.state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; @@ -722,7 +751,6 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL // Will reset after FG dispatch _skipHudlessChecks = true; LOG_DEBUG("Using _captureBuffer"); - auto fg = reinterpret_cast(State::Instance().currentFG); if (fg != nullptr) { @@ -730,6 +758,8 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL setResource.type = FG_ResourceType::HudlessColor; setResource.cmdList = cmdList; setResource.resource = _captureBuffer[fIndex]; + setResource.left = left; + setResource.top = top; setResource.width = scDesc.BufferDesc.Width; setResource.height = scDesc.BufferDesc.Height; setResource.state = D3D12_RESOURCE_STATE_COPY_DEST;