From 943d11970695d501e25137cd8aee57eead0515c9 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 22 Mar 2025 23:02:44 +0100 Subject: [PATCH] Fixed a number of issues to make Quality variant work: - Removed "fix" to initialize params to 0, as that happens midway through the Accumulation process, resetting a lot of variables. Instead rewrote InitParams to take an inout parameter and clear the params first thing in the Accumulate function. - Bind first multi-render target as depth target, fixes RenderDoc errors about color/depth buffer size mismatch. - Ensure keywords that need a value are redefined using the correct value. - Removed obsolete auto-TCR constants struct. --- .../Effects/Upscaling/ASR/Runtime/Asr.cs | 10 +--------- .../Effects/Upscaling/ASR/Runtime/AsrPass.cs | 2 +- .../ASR/Shaders/ffxm_fsr2_common.cginc | 17 +++++++++++++++++ .../Shaders/shaders/fsr2/ffxm_fsr2_accumulate.h | 12 +++--------- .../fsr2/ffxm_fsr2_postprocess_lock_status.h | 2 +- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/Asr.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/Asr.cs index 88d441e..1074a9c 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/Asr.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/Asr.cs @@ -300,6 +300,7 @@ namespace ArmASR public float deltaTime; public float dynamicResChangeFactor; public float viewSpaceToMetersFactor; + public float padding; } @@ -320,15 +321,6 @@ namespace ArmASR public float binaryValue; public uint flags; } - - [Serializable, StructLayout(LayoutKind.Sequential)] - internal struct GenerateReactiveConstants2 - { - public float autoTcThreshold; - public float autoTcScale; - public float autoReactiveScale; - public float autoReactiveMax; - } [Serializable, StructLayout(LayoutKind.Sequential)] internal struct RcasConstants 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 c3a74e4..a413f46 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 @@ -109,7 +109,7 @@ namespace ArmASR [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void BlitFragment(CommandBuffer commandBuffer, RenderTargetIdentifier[] renderTargets) { - commandBuffer.SetRenderTarget(renderTargets, BuiltinRenderTextureType.None); + commandBuffer.SetRenderTarget(renderTargets, renderTargets[0]); BlitFragment(commandBuffer); } diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc index a108327..895e4cf 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc @@ -3,9 +3,26 @@ #pragma warning(disable: 3205) // Conversion from larger type to smaller, possible loss of data #pragma warning(disable: 3556) // Integer divides might be much slower, try using uints if possible +// If these keywords are set by Unity, redefine them to have a truthy value +#ifdef FFXM_FSR2_OPTION_SHADER_OPT_PERFORMANCE +#undef FFXM_FSR2_OPTION_SHADER_OPT_PERFORMANCE +#define FFXM_FSR2_OPTION_SHADER_OPT_PERFORMANCE 1 +#endif +#ifdef FFXM_FSR2_OPTION_SHADER_OPT_BALANCED +#undef FFXM_FSR2_OPTION_SHADER_OPT_BALANCED +#define FFXM_FSR2_OPTION_SHADER_OPT_BALANCED 1 +#endif + +// Ensure the correct value is defined for this keyword, as it is used to select one of multiple sampler functions +#ifdef FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE +#undef FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE +#define FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE 1 +#endif + // ASR has some special code paths for OpenGL ES 3.2 #if defined(SHADER_API_GLES3) #define FFXM_SHADER_PLATFORM_GLES_3_2 (1) +#define unorm #endif // Work around the lack of texture atomics on Metal 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 cb2ab5f..2b28504 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 @@ -244,8 +244,6 @@ FfxFloat32 ComputeTemporalReactiveFactor(const AccumulationPassCommonParams para void initReactiveMaskFactors(FFXM_PARAMETER_INOUT AccumulationPassCommonParams params) { - params = (AccumulationPassCommonParams)0; - const FFXM_MIN16_F2 fDilatedReactiveMasks = FFXM_MIN16_F2(SampleDilatedReactiveMasks(params.fLrUv_HwSampler)); params.fDilatedReactiveFactor = fDilatedReactiveMasks.x; params.fAccumulationMask = fDilatedReactiveMasks.y; @@ -262,11 +260,8 @@ void initIsNewSample(FFXM_PARAMETER_INOUT AccumulationPassCommonParams params) params.bIsNewSample = (params.bIsExistingSample == false || bIsResetFrame); } - -AccumulationPassCommonParams InitParams(FfxInt32x2 iPxHrPos) +void InitParams(FFXM_PARAMETER_INOUT AccumulationPassCommonParams params, FfxInt32x2 iPxHrPos) { - AccumulationPassCommonParams params; - params.iPxHrPos = iPxHrPos; const FfxFloat32x2 fHrUv = (iPxHrPos + 0.5f) / DisplaySize(); params.fHrUv = fHrUv; @@ -278,13 +273,12 @@ AccumulationPassCommonParams InitParams(FfxInt32x2 iPxHrPos) params.fHrVelocity = GetPxHrVelocity(params.fMotionVector); ComputeReprojectedUVs(params, params.fReprojectedHrUv, params.bIsExistingSample); - - return params; } AccumulateOutputs Accumulate(FfxInt32x2 iPxHrPos) { - AccumulationPassCommonParams params = InitParams(iPxHrPos); + AccumulationPassCommonParams params = (AccumulationPassCommonParams)0; + InitParams(params, iPxHrPos); FfxFloat32x3 fHistoryColor = FfxFloat32x3(0, 0, 0); FFXM_MIN16_F2 fLockStatus; diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_postprocess_lock_status.h b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_postprocess_lock_status.h index 8d6e0bf..eab63d3 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_postprocess_lock_status.h +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_postprocess_lock_status.h @@ -56,7 +56,7 @@ FfxFloat32 GetShadingChangeLuma(FfxInt32x2 iPxHrPos, FfxFloat32x2 fUvCoord) return fShadingChangeLuma; } -void UpdateLockStatus(AccumulationPassCommonParams params, +void UpdateLockStatus(const AccumulationPassCommonParams params, FFXM_PARAMETER_INOUT FfxFloat32 fReactiveFactor, LockState state, FFXM_PARAMETER_INOUT FfxFloat32x2 fLockStatus, FFXM_PARAMETER_OUT FfxFloat32 fLockContributionThisFrame,