From e600f003ca9c3867efdc19fe9ef8e42523960245 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 8 Mar 2026 23:32:02 -0700 Subject: [PATCH] Fix FG disable state reset and FSR3 context compatibility for SDK variants --- src/rendering/amd_fsr3_runtime.cpp | 23 +++++++++++++++++++++-- src/rendering/renderer.cpp | 14 +++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/rendering/amd_fsr3_runtime.cpp b/src/rendering/amd_fsr3_runtime.cpp index e2b10bdc..7663c873 100644 --- a/src/rendering/amd_fsr3_runtime.cpp +++ b/src/rendering/amd_fsr3_runtime.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include "core/logger.hpp" @@ -48,6 +50,24 @@ FfxErrorCode vkSwapchainConfigureNoop(const FfxFrameGenerationConfig*) { return FFX_OK; } +template +struct HasUpscaleOutputSize : std::false_type {}; + +template +struct HasUpscaleOutputSize().upscaleOutputSize)>> : std::true_type {}; + +template +inline void setUpscaleOutputSizeIfPresent(T& ctxDesc, uint32_t width, uint32_t height) { + if constexpr (HasUpscaleOutputSize::value) { + ctxDesc.upscaleOutputSize.width = width; + ctxDesc.upscaleOutputSize.height = height; + } else { + (void)ctxDesc; + (void)width; + (void)height; + } +} + FfxSurfaceFormat mapVkFormatToFfxSurfaceFormat(VkFormat format, bool isDepth) { if (isDepth) { switch (format) { @@ -233,8 +253,7 @@ bool AmdFsr3Runtime::initialize(const AmdFsr3RuntimeInitDesc& desc) { if (desc.depthInverted) ctxDesc.flags |= FFX_FSR3_ENABLE_DEPTH_INVERTED; ctxDesc.maxRenderSize.width = desc.maxRenderWidth; ctxDesc.maxRenderSize.height = desc.maxRenderHeight; - ctxDesc.upscaleOutputSize.width = desc.displayWidth; - ctxDesc.upscaleOutputSize.height = desc.displayHeight; + setUpscaleOutputSizeIfPresent(ctxDesc, desc.displayWidth, desc.displayHeight); ctxDesc.displaySize.width = desc.displayWidth; ctxDesc.displaySize.height = desc.displayHeight; if (!backendShared.fpSwapChainConfigureFrameGeneration) { diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index a3b160b6..6fff9dc0 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -4413,6 +4413,10 @@ void Renderer::dispatchAmdFsr2() { void Renderer::dispatchAmdFsr3Framegen() { #if WOWEE_HAS_AMD_FSR3_FRAMEGEN + if (!fsr2_.amdFsr3FramegenEnabled) { + fsr2_.amdFsr3FramegenRuntimeActive = false; + return; + } if (!fsr2_.amdFsr3Runtime || !fsr2_.amdFsr3FramegenRuntimeReady) { fsr2_.amdFsr3FramegenRuntimeActive = false; return; @@ -4517,7 +4521,7 @@ void Renderer::renderFSR2Sharpen() { VkDescriptorImageInfo imgInfo{}; imgInfo.sampler = fsr2_.linearSampler; if (fsr2_.useAmdBackend) { - imgInfo.imageView = (fsr2_.amdFsr3FramegenRuntimeActive && fsr2_.framegenOutput.imageView) + imgInfo.imageView = (fsr2_.amdFsr3FramegenEnabled && fsr2_.amdFsr3FramegenRuntimeActive && fsr2_.framegenOutput.imageView) ? fsr2_.framegenOutput.imageView : fsr2_.history[outputIdx].imageView; } else { @@ -4583,24 +4587,32 @@ void Renderer::setFSR2DebugTuning(float jitterSign, float motionVecScaleX, float } void Renderer::setAmdFsr3FramegenEnabled(bool enabled) { + if (fsr2_.amdFsr3FramegenEnabled == enabled) return; fsr2_.amdFsr3FramegenEnabled = enabled; #if WOWEE_HAS_AMD_FSR3_FRAMEGEN if (enabled) { fsr2_.amdFsr3FramegenRuntimeActive = false; + fsr2_.framegenOutputValid = false; fsr2_.needsRecreate = true; + fsr2_.needsHistoryReset = true; fsr2_.amdFsr3FramegenRuntimeReady = false; LOG_INFO("FSR3 framegen requested; runtime will initialize on next FSR2 resource creation."); } else { fsr2_.amdFsr3FramegenRuntimeActive = false; fsr2_.amdFsr3FramegenRuntimeReady = false; + fsr2_.framegenOutputValid = false; + fsr2_.needsHistoryReset = true; + fsr2_.needsRecreate = true; if (fsr2_.amdFsr3Runtime) { fsr2_.amdFsr3Runtime->shutdown(); fsr2_.amdFsr3Runtime.reset(); } + LOG_INFO("FSR3 framegen disabled; forcing FSR2-only path rebuild."); } #else fsr2_.amdFsr3FramegenRuntimeActive = false; fsr2_.amdFsr3FramegenRuntimeReady = false; + fsr2_.framegenOutputValid = false; if (enabled) { LOG_WARNING("FSR3 framegen requested, but AMD FSR3 framegen SDK headers are unavailable in this build."); }