diff --git a/OptiScaler/NVNGX_DLSS_Dx12.cpp b/OptiScaler/NVNGX_DLSS_Dx12.cpp index 6a7da507..74375fca 100644 --- a/OptiScaler/NVNGX_DLSS_Dx12.cpp +++ b/OptiScaler/NVNGX_DLSS_Dx12.cpp @@ -1206,7 +1206,16 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom // Record the first timestamp (before FSR2 upscaling) InCmdList->EndQuery(HooksDx::queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 0); + ID3D12Resource* output; + InParameters->Get(NVSDK_NGX_Parameter_Output, &output); + + auto frameIndex = FrameGen_Dx12::ClearFrameResources(); + FrameGen_Dx12::NewFrame(); + FrameGen_Dx12::fgUpscaledImage[frameIndex] = output; + bool evalResult = deviceContext->Evaluate(InCmdList, InParameters); + + FrameGen_Dx12::upscaleRan = true; // Record the second timestamp (after FSR2 upscaling) InCmdList->EndQuery(HooksDx::queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 1); @@ -1279,13 +1288,6 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom fgLastFrameTime = now; - ID3D12Resource* output; - InParameters->Get(NVSDK_NGX_Parameter_Output, &output); - - auto frameIndex = FrameGen_Dx12::ClearFrameResources(); - FrameGen_Dx12::NewFrame(); - FrameGen_Dx12::fgUpscaledImage[frameIndex] = output; - auto allocator = FrameGen_Dx12::fgCopyCommandAllocators[frameIndex]; auto result = allocator->Reset(); result = FrameGen_Dx12::fgCopyCommandList->Reset(allocator, nullptr); @@ -1356,22 +1358,22 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom if (Config::Instance()->CurrentFeature != nullptr) fgLastFGFrame = Config::Instance()->CurrentFeature->FrameCount(); - auto result = FfxApiProxy::D3D12_Dispatch()(reinterpret_cast(pUserCtx), ¶ms->header); + auto dispatchResult = FfxApiProxy::D3D12_Dispatch()(reinterpret_cast(pUserCtx), ¶ms->header); ID3D12CommandList* cl[1] = { nullptr }; - result = FrameGen_Dx12::fgCopyCommandList->Close(); + auto result = FrameGen_Dx12::fgCopyCommandList->Close(); cl[0] = FrameGen_Dx12::fgCopyCommandList; FrameGen_Dx12::gameCommandQueue->ExecuteCommandLists(1, cl); - if (result != FFX_API_RETURN_OK) - LOG_ERROR("(FG) D3D12_Dispatch error: {}({})", result, FfxApiProxy::ReturnCodeToString(result)); + if (dispatchResult != FFX_API_RETURN_OK || result != S_OK) + LOG_ERROR("(FG) D3D12_Dispatch result: {}({}, Close result: {})", (UINT)dispatchResult, FfxApiProxy::ReturnCodeToString(dispatchResult), (UINT)result); return result; #else - if (!Config::Instance()->FGEnabled.value_or(false) || Config::Instance()->FGChanged || Config::Instance()->CurrentFeature == nullptr || HooksDx::fgContext == nullptr) + if (!Config::Instance()->FGEnabled.value_or(false) || Config::Instance()->FGChanged || Config::Instance()->CurrentFeature == nullptr || FrameGen_Dx12::fgContext == nullptr) return FFX_API_RETURN_OK; - auto result = _dispatch(reinterpret_cast(pUserCtx), ¶ms->header); + auto result = FfxApiProxy::D3D12_Dispatch()(reinterpret_cast(pUserCtx), ¶ms->header); return result; #endif }; @@ -1430,6 +1432,10 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom if (CreateBufferResource(L"fgDepth", D3D12Device, paramDepth, D3D12_RESOURCE_STATE_COPY_DEST, &FrameGen_Dx12::paramDepth[frameIndex])) InCmdList->CopyResource(FrameGen_Dx12::paramDepth[frameIndex], paramDepth); + + dfgPrepare.motionVectors = ffxApiGetResourceDX12(FrameGen_Dx12::paramVelocity[frameIndex], FFX_API_RESOURCE_STATE_COMPUTE_READ); + dfgPrepare.depth = ffxApiGetResourceDX12(FrameGen_Dx12::paramDepth[frameIndex], FFX_API_RESOURCE_STATE_COMPUTE_READ); + #else ID3D12Resource* paramVelocity; if (InParameters->Get(NVSDK_NGX_Parameter_MotionVectors, ¶mVelocity) != NVSDK_NGX_Result_Success) @@ -1444,9 +1450,6 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom dfgPrepare.depth = ffxApiGetResourceDX12(paramDepth, FFX_API_RESOURCE_STATE_COMPUTE_READ); #endif - dfgPrepare.motionVectors = ffxApiGetResourceDX12(FrameGen_Dx12::paramVelocity[frameIndex], FFX_API_RESOURCE_STATE_COMPUTE_READ); - dfgPrepare.depth = ffxApiGetResourceDX12(FrameGen_Dx12::paramDepth[frameIndex], FFX_API_RESOURCE_STATE_COMPUTE_READ); - float MVScaleX = 1.0f; float MVScaleY = 1.0f; @@ -1491,8 +1494,6 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom } else { - FrameGen_Dx12::upscaleRan = true; - LOG_DEBUG("(HudFix) fgUpscaledImage[{}]", frameIndex); LOG_DEBUG("(HudFix) copy buffers running, frame: {0}", deviceContext->FrameCount()); diff --git a/OptiScaler/OptiScaler.vcxproj b/OptiScaler/OptiScaler.vcxproj index 4759ecc3..af7dc096 100644 --- a/OptiScaler/OptiScaler.vcxproj +++ b/OptiScaler/OptiScaler.vcxproj @@ -82,7 +82,7 @@ $(SolutionDir)external\vulkan\include;$(SolutionDir)external\nvngx_dlss_sdk;$(SolutionDir)external\xess\inc\xess;$(SolutionDir)external\FidelityFX-SDK\ffx-api\include\ffx_api;$(SolutionDir)external\simpleini;$(SolutionDir)external\unordered_dense\include;$(SolutionDir)external\spdlog\include;$(IncludePath) $(ProjectDir)fsr2\lib;$(ProjectDir)fsr2_212\lib;$(ProjectDir)fsr31\lib;$(ProjectDir)vulkan;$(ProjectDir)d3dx;$(ProjectDir)detours;$(SolutionDir)external\xess\lib;$(LibraryPath) dxgi - D:\Folders\Games\Cyberpunk 2077\bin\x64\ + E:\Games\Steam\steamapps\common\The Witcher 3\bin\x64_dx12\ .\x64\Debug diff --git a/OptiScaler/backends/xess/XeSSFeature_Dx12.cpp b/OptiScaler/backends/xess/XeSSFeature_Dx12.cpp index 17095744..682b1ce8 100644 --- a/OptiScaler/backends/xess/XeSSFeature_Dx12.cpp +++ b/OptiScaler/backends/xess/XeSSFeature_Dx12.cpp @@ -306,7 +306,7 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N return false; } - // apply rcas + // Apply RCAS if (Config::Instance()->RcasEnabled.value_or(true) && (sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or(false) && Config::Instance()->MotionSharpness.value_or(0.4) > 0.0f)) && RCAS->CanRender()) diff --git a/OptiScaler/hooks/HooksDx.cpp b/OptiScaler/hooks/HooksDx.cpp index 9edca239..b693dfaa 100644 --- a/OptiScaler/hooks/HooksDx.cpp +++ b/OptiScaler/hooks/HooksDx.cpp @@ -425,7 +425,7 @@ static void FillResourceInfo(ID3D12Resource* resource, ResourceInfo* info) static void GetHudless(ID3D12GraphicsCommandList* This) { auto fIndex = fgFrameIndex; - if (This != g_pd3dCommandList && fgCopySource[fIndex] != nullptr && Config::Instance()->CurrentFeature != nullptr && + if (This != g_pd3dCommandList && fgCopySource[fIndex] != nullptr && Config::Instance()->CurrentFeature != nullptr && !Config::Instance()->FGChanged && fgHudlessFrame != Config::Instance()->CurrentFeature->FrameCount() && FrameGen_Dx12::fgTarget <= Config::Instance()->CurrentFeature->FrameCount()) { LOG_DEBUG("FrameCount: {0}, fgHudlessFrame: {1}, CommandList: {2:X}", Config::Instance()->CurrentFeature->FrameCount(), fgHudlessFrame, (UINT64)This); @@ -501,6 +501,7 @@ static void GetHudless(ID3D12GraphicsCommandList* This) fgDispatchCalled = false; FrameGen_Dx12::fgSkipHudlessChecks = false; + //FrameGen_Dx12::upscaleRan = true; return dispatchResult; }; @@ -832,7 +833,7 @@ static void hkCopyResource(ID3D12GraphicsCommandList* This, ID3D12Resource* Dest return; if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || HooksDx::fgContext == nullptr || - HooksDx::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || + HooksDx::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || Config::Instance()->FGChanged || fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; @@ -865,7 +866,7 @@ static void hkCopyTextureRegion(ID3D12GraphicsCommandList* This, D3D12_TEXTURE_C return; if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || FrameGen_Dx12::fgContext == nullptr || - FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || + FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || Config::Instance()->FGChanged || fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; @@ -941,7 +942,7 @@ static void hkCopyDescriptors(ID3D12Device* This, LOG_DEBUG_ONLY("SrcRanges: {}, DestRanges: {}, Type: {}", NumSrcDescriptorRanges, NumDestDescriptorRanges, (UINT)DescriptorHeapsType); if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || FrameGen_Dx12::fgContext == nullptr || - FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || + FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || Config::Instance()->FGChanged || fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; @@ -1004,7 +1005,7 @@ static void hkCopyDescriptorsSimple(ID3D12Device* This, UINT NumDescriptors, D3D return; if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || FrameGen_Dx12::fgContext == nullptr || - FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || + FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || Config::Instance()->FGChanged || fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; @@ -1040,7 +1041,7 @@ static void hkSetGraphicsRootDescriptorTable(ID3D12GraphicsCommandList* This, UI return; if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || FrameGen_Dx12::fgContext == nullptr || - FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || + FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || Config::Instance()->FGChanged || fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; @@ -1089,7 +1090,7 @@ static void hkOMSetRenderTargets(ID3D12GraphicsCommandList* This, UINT NumRender return; if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || FrameGen_Dx12::fgContext == nullptr || - FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || + FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || Config::Instance()->FGChanged || fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; @@ -1146,7 +1147,7 @@ static void hkSetComputeRootDescriptorTable(ID3D12GraphicsCommandList* This, UIN return; if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || FrameGen_Dx12::fgContext == nullptr || - FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || + FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || Config::Instance()->FGChanged || fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; @@ -1190,7 +1191,7 @@ static void hkDrawInstanced(ID3D12GraphicsCommandList* This, UINT VertexCountPer return; if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || FrameGen_Dx12::fgContext == nullptr || - FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || + FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || Config::Instance()->FGChanged || fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; @@ -1243,7 +1244,7 @@ static void hkDrawIndexedInstanced(ID3D12GraphicsCommandList* This, UINT IndexCo return; if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || FrameGen_Dx12::fgContext == nullptr || - FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || + FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || Config::Instance()->FGChanged || fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; @@ -1299,8 +1300,8 @@ static void hkDispatch(ID3D12GraphicsCommandList* This, UINT ThreadGroupCountX, return; if (!Config::Instance()->FGEnabled.value_or(false) || !Config::Instance()->FGHUDFix.value_or(false) || FrameGen_Dx12::fgContext == nullptr || - FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || - fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) + FrameGen_Dx12::fgTarget > Config::Instance()->CurrentFeature->FrameCount() || !FrameGen_Dx12::fgIsActive || Config::Instance()->FGChanged || + fgHudlessFrame == Config::Instance()->CurrentFeature->FrameCount() && fgCopySource[fIndex] != nullptr) return; LOG_DEBUG_ONLY(" <-- {0:X}", (size_t)This); @@ -2750,8 +2751,21 @@ void FrameGen_Dx12::CreateFGContext(ID3D12Device* InDevice, IFeature* deviceCont ffxCreateContextDescFrameGeneration createFg{}; createFg.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION; - createFg.displaySize = { deviceContext->DisplayWidth(), deviceContext->DisplayHeight() }; - createFg.maxRenderSize = { deviceContext->DisplayWidth(), deviceContext->DisplayHeight() }; + + // use swapchain buffer info + DXGI_SWAP_CHAIN_DESC desc{}; + if (HooksDx::currentSwapchain->GetDesc(&desc) == S_OK) + { + createFg.displaySize = { desc.BufferDesc.Width, desc.BufferDesc.Height }; + createFg.maxRenderSize = { desc.BufferDesc.Width, desc.BufferDesc.Height }; + } + else + { + // this might cause issues + createFg.displaySize = { deviceContext->DisplayWidth(), deviceContext->DisplayHeight() }; + createFg.maxRenderSize = { deviceContext->DisplayWidth(), deviceContext->DisplayHeight() }; + } + createFg.flags = 0; if (deviceContext->GetFeatureFlags() & NVSDK_NGX_DLSS_Feature_Flags_IsHDR) diff --git a/OptiScaler/resource.h b/OptiScaler/resource.h index 4d794e12..ce0bf739 100644 --- a/OptiScaler/resource.h +++ b/OptiScaler/resource.h @@ -21,7 +21,7 @@ #define VER_MAJOR_VERSION 0 #define VER_MINOR_VERSION 7 #define VER_HOTFIX_VERSION 0 -#define VER_BUILD_NUMBER 26 +#define VER_BUILD_NUMBER 27 #define VER_PRE_RELEASE