From c4df3d45aaee9ba2b78e572e9a1fdf064b39601f Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 22 Mar 2025 17:49:16 +0100 Subject: [PATCH] Got UAV bindings in fragment shaders to work in what I think is the correct way --- .../Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs | 10 ++++++---- .../Shaders/shaders/ffxm_fsr2_accumulate_pass_fs.hlsl | 2 +- .../ffxm_fsr2_reconstruct_previous_depth_pass_fs.hlsl | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) 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 ba503ee..c3a74e4 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 @@ -177,8 +177,8 @@ namespace ArmASR commandBuffer.SetGlobalResource(AsrShaderIDs.SrvInputMotionVectors, dispatchParams.MotionVectors); commandBuffer.SetGlobalResource(AsrShaderIDs.SrvInputExposure, dispatchParams.Exposure); - // TODO UAVs in fragment shaders? That seems like it might be a problem... - commandBuffer.SetGlobalTexture(AsrShaderIDs.UavReconstructedPrevNearestDepth, AsrShaderIDs.UavReconstructedPrevNearestDepth); + // UAV binding in fragment shader, index needs to match the register binding in HLSL + commandBuffer.SetRandomWriteTarget(3, AsrShaderIDs.UavReconstructedPrevNearestDepth); _mrt[0] = AsrShaderIDs.RtDilatedDepth; // fDepth _mrt[1] = Resources.DilatedMotionVectors[frameIndex]; // fMotionVector @@ -186,6 +186,7 @@ namespace ArmASR FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride); BlitFragment(commandBuffer, _mrt); + commandBuffer.ClearRandomWriteTargets(); } } @@ -276,8 +277,8 @@ namespace ArmASR commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]); commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvInternalTemporalReactive, Resources.InternalReactive[frameIndex ^ 1]); - // TODO UAVs in fragment shaders? That seems like it might be a problem... - commandBuffer.SetGlobalTexture(AsrShaderIDs.UavNewLocks, AsrShaderIDs.UavNewLocks); + // UAV binding in fragment shader, index needs to match the register binding in HLSL + commandBuffer.SetRandomWriteTarget(4, AsrShaderIDs.UavNewLocks); if (ContextDescription.Variant == Asr.Variant.Quality) { @@ -296,6 +297,7 @@ namespace ArmASR FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride); BlitFragment(commandBuffer, _mrt); + commandBuffer.ClearRandomWriteTargets(); } } 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 7f78bbb..49dbed7 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 @@ -36,7 +36,7 @@ #define FSR2_BIND_SRV_LUMA_HISTORY 10 #define FSR2_BIND_SRV_TEMPORAL_REACTIVE 11 -#define FSR2_BIND_UAV_NEW_LOCKS 12 +#define FSR2_BIND_UAV_NEW_LOCKS 4 #define FSR2_BIND_CB_FSR2 0 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 5a71c68..ff65021 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 @@ -24,7 +24,7 @@ #define FSR2_BIND_SRV_INPUT_COLOR 2 #define FSR2_BIND_SRV_INPUT_EXPOSURE 3 -#define FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH 4 +#define FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH 3 #define FSR2_BIND_CB_FSR2 0