From ef8a19887bb4869b03d5c2d25ccca9a969b6f173 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sun, 11 May 2025 12:28:13 +0200 Subject: [PATCH] (FSR3) Clear new locks buffer ahead of the frame instead of at the end of the Accumulate pass. This makes more sense with NewLocks being an aliasable (temp RT) resource, and it avoids reading and writing to the same texture in the Accumulate pass. --- Runtime/FSR3/Fsr3UpscalerContext.cs | 3 +++ Runtime/FSR3/Fsr3UpscalerPass.cs | 1 + Shaders/shaders/ffx_fsr3upscaler_accumulate_pass.hlsl | 2 +- Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h | 4 ++-- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Runtime/FSR3/Fsr3UpscalerContext.cs b/Runtime/FSR3/Fsr3UpscalerContext.cs index 7d16e57..c82e60d 100644 --- a/Runtime/FSR3/Fsr3UpscalerContext.cs +++ b/Runtime/FSR3/Fsr3UpscalerContext.cs @@ -249,6 +249,9 @@ namespace FidelityFX.FSR3 commandBuffer.SetRenderTarget(_resources.ReconstructedPrevNearestDepth); commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); + commandBuffer.SetRenderTarget(Fsr3ShaderIDs.UavNewLocks); + commandBuffer.ClearRenderTarget(false, true, Color.clear); + // Auto exposure SetupSpdConstants(dispatchParams, out var dispatchThreadGroupCount); diff --git a/Runtime/FSR3/Fsr3UpscalerPass.cs b/Runtime/FSR3/Fsr3UpscalerPass.cs index 7444b95..af4ecc2 100644 --- a/Runtime/FSR3/Fsr3UpscalerPass.cs +++ b/Runtime/FSR3/Fsr3UpscalerPass.cs @@ -342,6 +342,7 @@ namespace FidelityFX.FSR3 commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvCurrentLuma, Resources.Luma[frameIndex]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLumaInstability, Fsr3ShaderIDs.UavIntermediate); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvNewLocks, Fsr3ShaderIDs.UavNewLocks); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavInternalUpscaled, Resources.InternalUpscaled[frameIndex]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); diff --git a/Shaders/shaders/ffx_fsr3upscaler_accumulate_pass.hlsl b/Shaders/shaders/ffx_fsr3upscaler_accumulate_pass.hlsl index c000624..ef8f6ca 100644 --- a/Shaders/shaders/ffx_fsr3upscaler_accumulate_pass.hlsl +++ b/Shaders/shaders/ffx_fsr3upscaler_accumulate_pass.hlsl @@ -34,10 +34,10 @@ #define FSR3UPSCALER_BIND_SRV_CURRENT_LUMA 6 #define FSR3UPSCALER_BIND_SRV_LUMA_INSTABILITY 7 #define FSR3UPSCALER_BIND_SRV_INPUT_COLOR 8 +#define FSR3UPSCALER_BIND_SRV_NEW_LOCKS 9 #define FSR3UPSCALER_BIND_UAV_INTERNAL_UPSCALED 0 #define FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT 1 -#define FSR3UPSCALER_BIND_UAV_NEW_LOCKS 2 #define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 0 diff --git a/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h b/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h index 1a231aa..a5124ba 100644 --- a/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h +++ b/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h @@ -79,7 +79,7 @@ void UpdateLockStatus(AccumulationPassCommonParams params, FFX_PARAMETER_INOUT A // Compute this frame lock contribution data.fLockContributionThisFrame = ffxSaturate(ffxSaturate(data.fLock - fLockThreshold) * (fLockMax - fLockThreshold)); - const FfxFloat32 fNewLockIntensity = LoadRwNewLocks(params.iPxHrPos) * (1.0f - ffxMax(params.fShadingChange * 0, params.fReactiveMask)); + const FfxFloat32 fNewLockIntensity = LoadNewLocks(params.iPxHrPos) * (1.0f - ffxMax(params.fShadingChange * 0, params.fReactiveMask)); data.fLock = ffxMax(0.0f, ffxMin(data.fLock + fNewLockIntensity, fLockMax)); // Preparing for next frame @@ -169,5 +169,5 @@ void Accumulate(FfxInt32x2 iPxHrPos) #if FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING == 0 StoreUpscaledOutput(iPxHrPos, data.fHistoryColor); #endif - StoreNewLocks(iPxHrPos, 0); + //StoreNewLocks(iPxHrPos, 0); }