From c4b59c7dc3a92aeacd9bc34c7b6e337c1c0a1c2b Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sun, 23 Mar 2025 22:38:28 +0100 Subject: [PATCH] Bunch of fixes to make ASR Quality somewhat work on PS5, without reactive mask still: - Define macros for various VS/FS binding intrinsics - Use pragmas to set output formats for render targets that aren't normal RGBA - Added alpha channel to color output targets, so that they're 4-channel instead of 3 - Pass FSR2 constant buffer to reactive mask shader (may not matter) --- .../Effects/Upscaling/ASR/Runtime/AsrContext.cs | 2 +- .../Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs | 5 +++-- .../Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc | 9 +++++++++ .../shaders/ffxm_fsr2_accumulate_pass_fs.hlsl | 12 +++++++----- .../shaders/ffxm_fsr2_autogen_reactive_pass_fs.hlsl | 2 ++ .../shaders/ffxm_fsr2_depth_clip_pass_fs.hlsl | 2 ++ .../ASR/Shaders/shaders/ffxm_fsr2_rcas_pass_fs.hlsl | 4 ++-- ...ffxm_fsr2_reconstruct_previous_depth_pass_fs.hlsl | 4 ++++ 8 files changed, 30 insertions(+), 10 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 9bd1cc0..d178599 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 @@ -96,7 +96,7 @@ namespace ArmASR _lockPass = new AsrLockPass(_contextDescription, _resources, _upscalerConstantsBuffer); _accumulatePass = new AsrAccumulatePass(_contextDescription, _resources, _upscalerConstantsBuffer); _sharpenPass = new AsrSharpenPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer); - _generateReactivePass = new AsrGenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer); + _generateReactivePass = new AsrGenerateReactivePass(_contextDescription, _resources, _upscalerConstantsBuffer, _generateReactiveConstantsBuffer); } public void Destroy() 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 7c7d191..d04be56 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 @@ -328,8 +328,8 @@ namespace ArmASR { private readonly ComputeBuffer _generateReactiveConstants; - public AsrGenerateReactivePass(Asr.ContextDescription contextDescription, AsrResources resources, ComputeBuffer generateReactiveConstants) - : base(contextDescription, resources, null) + public AsrGenerateReactivePass(Asr.ContextDescription contextDescription, AsrResources resources, ComputeBuffer constants, ComputeBuffer generateReactiveConstants) + : base(contextDescription, resources, constants) { _generateReactiveConstants = generateReactiveConstants; @@ -347,6 +347,7 @@ namespace ArmASR commandBuffer.SetGlobalResource(AsrShaderIDs.SrvOpaqueOnly, dispatchParams.ColorOpaqueOnly); commandBuffer.SetGlobalResource(AsrShaderIDs.SrvInputColor, dispatchParams.ColorPreUpscale); + FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride); FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbGenReactive, _generateReactiveConstants, 0, _generateReactiveConstants.stride); BlitFragment(commandBuffer, dispatchParams.OutReactive.RenderTarget); 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 895e4cf..a583e19 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 @@ -31,3 +31,12 @@ #define InterlockedMin(dest, val) { (dest) = min((dest), (val)); } #define InterlockedMax(dest, val) { (dest) = max((dest), (val)); } #endif + +#if defined(SHADER_API_PSSL) +#define SV_VERTEXID S_VERTEX_ID +#define SV_POSITION S_POSITION +#define SV_TARGET0 S_TARGET_OUTPUT0 +#define SV_TARGET1 S_TARGET_OUTPUT1 +#define SV_TARGET2 S_TARGET_OUTPUT2 +#define SV_TARGET3 S_TARGET_OUTPUT3 +#endif 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 5e846c4..4038324 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 @@ -56,6 +56,8 @@ #include "fsr2/ffxm_fsr2_reproject.h" #include "fsr2/ffxm_fsr2_accumulate.h" +#pragma PSSL_target_output_format(target 1 FMT_FP16_ABGR) + struct AccumulateOutputsFS { #if !FFXM_SHADER_QUALITY_BALANCED_OR_PERFORMANCE @@ -63,14 +65,14 @@ struct AccumulateOutputsFS FfxFloat32x2 fLockStatus : SV_TARGET1; FfxFloat32x4 fLumaHistory : SV_TARGET2; #if FFXM_FSR2_OPTION_APPLY_SHARPENING == 0 - FfxFloat32x3 fColor : SV_TARGET3; + FfxFloat32x4 fColor : SV_TARGET3; #endif #else // FFXM_SHADER_QUALITY_BALANCED_OR_PERFORMANCE - FfxFloat32x3 fUpscaledColor : SV_TARGET0; + FfxFloat32x4 fUpscaledColor : SV_TARGET0; FfxFloat32 fTemporalReactive : SV_TARGET1; FfxFloat32x2 fLockStatus : SV_TARGET2; #if FFXM_FSR2_OPTION_APPLY_SHARPENING == 0 - FfxFloat32x3 fColor : SV_TARGET3; + FfxFloat32x4 fColor : SV_TARGET3; #endif #endif }; @@ -84,12 +86,12 @@ AccumulateOutputsFS main(float4 SvPosition : SV_POSITION) output.fColorAndWeight = result.fColorAndWeight; output.fLumaHistory = result.fLumaHistory; #else - output.fUpscaledColor = result.fUpscaledColor; + output.fUpscaledColor = FfxFloat32x4(result.fUpscaledColor, 1.0f); output.fTemporalReactive = result.fTemporalReactive; #endif output.fLockStatus = result.fLockStatus; #if FFXM_FSR2_OPTION_APPLY_SHARPENING == 0 - output.fColor = result.fColor; + output.fColor = FfxFloat32x4(result.fColor, 1.0f); #endif return output; } \ No newline at end of file diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_autogen_reactive_pass_fs.hlsl b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_autogen_reactive_pass_fs.hlsl index 34fa02f..d87abd8 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_autogen_reactive_pass_fs.hlsl +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_autogen_reactive_pass_fs.hlsl @@ -36,6 +36,8 @@ #include "fsr2/ffxm_fsr2_callbacks_hlsl.h" #include "fsr2/ffxm_fsr2_common.h" +#pragma PSSL_target_output_format(default FMT_32_R) + struct GenReactiveMaskOutputs { FfxFloat32 fReactiveMask : SV_TARGET0; diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_depth_clip_pass_fs.hlsl b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_depth_clip_pass_fs.hlsl index 60c4dfa..ed78125 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_depth_clip_pass_fs.hlsl +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_depth_clip_pass_fs.hlsl @@ -45,6 +45,8 @@ #include "fsr2/ffxm_fsr2_sample.h" #include "fsr2/ffxm_fsr2_depth_clip.h" +#pragma PSSL_target_output_format(target 0 FMT_FP16_ABGR) + struct DepthClipOutputsFS { FfxFloat32x2 fDilatedReactiveMasks : SV_TARGET0; diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_rcas_pass_fs.hlsl b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_rcas_pass_fs.hlsl index 6031679..b5585ec 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_rcas_pass_fs.hlsl +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_rcas_pass_fs.hlsl @@ -39,7 +39,7 @@ struct RCASOutputsFS { - FfxFloat32x3 fUpscaledColor : SV_TARGET0; + FfxFloat32x4 fUpscaledColor : SV_TARGET0; }; RCASOutputsFS main(float4 SvPosition : SV_POSITION) @@ -47,6 +47,6 @@ RCASOutputsFS main(float4 SvPosition : SV_POSITION) uint2 uPixelCoord = uint2(SvPosition.xy); RCASOutputs result = RCAS(uPixelCoord); RCASOutputsFS output = (RCASOutputsFS)0; - output.fUpscaledColor = result.fUpscaledColor; + output.fUpscaledColor = FfxFloat32x4(result.fUpscaledColor, 1.0f); return output; } diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_reconstruct_previous_depth_pass_fs.hlsl b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_reconstruct_previous_depth_pass_fs.hlsl index 57e3e68..b67ff65 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_reconstruct_previous_depth_pass_fs.hlsl +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/ffxm_fsr2_reconstruct_previous_depth_pass_fs.hlsl @@ -41,6 +41,10 @@ #include "fsr2/ffxm_fsr2_sample.h" #include "fsr2/ffxm_fsr2_reconstruct_dilated_velocity_and_previous_depth.h" +#pragma PSSL_target_output_format(target 0 FMT_32_R) +#pragma PSSL_target_output_format(target 1 FMT_FP16_ABGR) +#pragma PSSL_target_output_format(target 2 FMT_32_R) + struct ReconstructPrevDepthOutputsFS { FfxFloat32 fDepth : SV_TARGET0;