From 3912c66b0d2f77926a1ea858c933974c58364b55 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 25 Mar 2025 13:58:41 +0100 Subject: [PATCH] Bind new locks to the accumulate shader as a regular SRV (read-only), and clear the locks buffer ahead of time instead of at the end of the accumulate shader. This simplifies the shader binding setup, as well as being "more correct" because we're using a temporary RT for the locks buffer, meaning it makes no sense to clear it for the next frame. --- .../Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs | 3 +++ .../Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs | 4 +--- .../ASR/Shaders/shaders/ffxm_fsr2_accumulate_pass_fs.hlsl | 4 +--- .../Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_accumulate.h | 1 - .../Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_reproject.h | 4 ++-- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs index c180165..0d50ed9 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs @@ -198,6 +198,9 @@ namespace ArmASR commandBuffer.SetRenderTarget(AsrShaderIDs.UavReconstructedPrevNearestDepth); commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); + commandBuffer.SetRenderTarget(AsrShaderIDs.UavNewLocks); + commandBuffer.ClearRenderTarget(false, true, Color.clear); + // Auto exposure SetupSpdConstants(dispatchParams, out var dispatchThreadGroupCount); diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs index 4ad1628..764e02b 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs @@ -277,9 +277,7 @@ namespace ArmASR commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvAutoExposure, Resources.AutoExposure[frameIndex]); commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]); commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvInternalTemporalReactive, Resources.InternalReactive[frameIndex ^ 1]); - - // UAV binding in fragment shader, index needs to match the register binding in HLSL - commandBuffer.SetRandomWriteTarget(4, AsrShaderIDs.UavNewLocks); + commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvNewLocks, AsrShaderIDs.UavNewLocks); if (ContextDescription.Variant == Asr.Variant.Quality) { diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_accumulate_pass_fs.hlsl b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_accumulate_pass_fs.hlsl index e3ba114..8c23aab 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_accumulate_pass_fs.hlsl +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_accumulate_pass_fs.hlsl @@ -35,8 +35,7 @@ #define FSR2_BIND_SRV_AUTO_EXPOSURE 9 #define FSR2_BIND_SRV_LUMA_HISTORY 10 #define FSR2_BIND_SRV_TEMPORAL_REACTIVE 11 - -#define FSR2_BIND_UAV_NEW_LOCKS 4 +#define FSR2_BIND_SRV_NEW_LOCKS 12 #define FSR2_BIND_CB_FSR2 0 @@ -60,7 +59,6 @@ #pragma PSSL_target_output_format(target 0 FMT_FP16_ABGR) #pragma PSSL_target_output_format(target 1 FMT_FP16_ABGR) #pragma PSSL_target_output_format(target 2 FMT_FP16_ABGR) -#pragma PSSL_target_output_format(target 4 FMT_32_R) #endif struct AccumulateOutputsFS diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_accumulate.h b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_accumulate.h index 73404b5..35769f0 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_accumulate.h +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_accumulate.h @@ -372,7 +372,6 @@ AccumulateOutputs Accumulate(FfxInt32x2 iPxHrPos) #if FFXM_FSR2_OPTION_APPLY_SHARPENING == 0 results.fColor = fHistoryColor; #endif - //StoreNewLocks(iPxHrPos, 0); return results; } diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_reproject.h b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_reproject.h index 752a39a..b6d20b6 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_reproject.h +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_reproject.h @@ -331,7 +331,7 @@ void ReprojectHistoryColor(const AccumulationPassCommonParams params, FFXM_PARAM LockState ReprojectHistoryLockStatus(const AccumulationPassCommonParams params, FFXM_PARAMETER_OUT FfxFloat32x2 fReprojectedLockStatus) { LockState state = { FFXM_FALSE, FFXM_FALSE }; - const FfxFloat32 fNewLockIntensity = LoadRwNewLocks(params.iPxHrPos); + const FfxFloat32 fNewLockIntensity = LoadNewLocks(params.iPxHrPos); state.NewLock = fNewLockIntensity > (127.0f / 255.0f); FfxFloat32 fInPlaceLockLifetime = state.NewLock ? fNewLockIntensity : 0; @@ -368,7 +368,7 @@ void ReprojectHistoryColor(const AccumulationPassCommonParams params, FFXM_PARAM LockState ReprojectHistoryLockStatus(const AccumulationPassCommonParams params, FFXM_PARAMETER_OUT FfxFloat16x2 fReprojectedLockStatus) { LockState state = { FFXM_FALSE, FFXM_FALSE }; - const FfxFloat16 fNewLockIntensity = FfxFloat16(LoadRwNewLocks(params.iPxHrPos)); + const FfxFloat16 fNewLockIntensity = FfxFloat16(LoadNewLocks(params.iPxHrPos)); state.NewLock = fNewLockIntensity > (127.0f / 255.0f); FfxFloat16 fInPlaceLockLifetime = state.NewLock ? fNewLockIntensity : FfxFloat16(0);