From 3ef31fac65cb6269154332a733608cf1f9f1d8d6 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 22 Mar 2025 14:09:37 +0100 Subject: [PATCH] Some cleanup and minor fixes --- .../Upscaling/ASR/Runtime/AsrContext.cs | 38 +++---------------- .../Effects/Upscaling/ASR/Runtime/AsrPass.cs | 5 +-- .../Runtime/Effects/Upscaling/ASRUpscaler.cs | 1 + 3 files changed, 8 insertions(+), 36 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 4857108..a63ac5c 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 @@ -36,7 +36,6 @@ namespace ArmASR private const int MaxQueuedFrames = 16; private Asr.ContextDescription _contextDescription; - private CommandBuffer _commandBuffer; private AsrPass _computeLuminancePyramidPass; private AsrPass _reconstructPreviousDepthPass; @@ -48,6 +47,7 @@ namespace ArmASR private AsrPass _tcrAutogeneratePass; private readonly AsrResources _resources = new AsrResources(); + private readonly AsrKeywords _keywords = new AsrKeywords(); private ComputeBuffer _upscalerConstantsBuffer; private readonly Asr.UpscalerConstants[] _upscalerConstantsArray = { new Asr.UpscalerConstants() }; @@ -65,8 +65,6 @@ namespace ArmASR private readonly Asr.GenerateReactiveConstants[] _generateReactiveConstantsArray = { new Asr.GenerateReactiveConstants() }; private ref Asr.GenerateReactiveConstants GenReactiveConsts => ref _generateReactiveConstantsArray[0]; - private AsrKeywords _keywords = new(); - private bool _firstExecution; private Vector2 _previousJitterOffset; private int _resourceFrameIndex; @@ -74,7 +72,6 @@ namespace ArmASR public void Create(in Asr.ContextDescription contextDescription) { _contextDescription = contextDescription; - _commandBuffer = new CommandBuffer { name = "ASR" }; _upscalerConstantsBuffer = CreateConstantBuffer(); _spdConstantsBuffer = CreateConstantBuffer(); @@ -119,19 +116,6 @@ namespace ArmASR DestroyConstantBuffer(ref _rcasConstantsBuffer); DestroyConstantBuffer(ref _spdConstantsBuffer); DestroyConstantBuffer(ref _upscalerConstantsBuffer); - - if (_commandBuffer != null) - { - _commandBuffer.Dispose(); - _commandBuffer = null; - } - } - - public void Dispatch(in Asr.DispatchDescription dispatchParams) - { - _commandBuffer.Clear(); - Dispatch(dispatchParams, _commandBuffer); - Graphics.ExecuteCommandBuffer(_commandBuffer); } public void Dispatch(Asr.DispatchDescription dispatchParams, CommandBuffer commandBuffer) @@ -174,8 +158,6 @@ namespace ArmASR const int threadGroupWorkRegionDim = 8; int dispatchSrcX = (UpscalerConsts.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchSrcY = (UpscalerConsts.renderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; - int dispatchDstX = (_contextDescription.DisplaySize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; - int dispatchDstY = (_contextDescription.DisplaySize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; // Clear reconstructed depth for max depth store if (resetAccumulation) @@ -214,16 +196,16 @@ namespace ArmASR _computeLuminancePyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y); // Reconstruct previous depth - _reconstructPreviousDepthPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); + _reconstructPreviousDepthPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex); // Depth clip - _depthClipPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); + _depthClipPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex); // Create locks _lockPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); // Accumulate - _accumulatePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY); + _accumulatePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex); if (dispatchParams.EnableSharpening) { @@ -232,10 +214,7 @@ namespace ArmASR commandBuffer.SetBufferData(_rcasConstantsBuffer, _rcasConstantsArray); // Dispatch RCAS - const int threadGroupWorkRegionDimRcas = 16; - int threadGroupsX = (_contextDescription.DisplaySize.x + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas; - int threadGroupsY = (_contextDescription.DisplaySize.y + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas; - _sharpenPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY); + _sharpenPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex); } _resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames; @@ -245,13 +224,6 @@ namespace ArmASR commandBuffer.DisableShaderKeyword("UNITY_FFXM_TEXTURE2D_X_ARRAY"); } - public void GenerateReactiveMask(in Asr.GenerateReactiveDescription dispatchParams) - { - _commandBuffer.Clear(); - GenerateReactiveMask(dispatchParams, _commandBuffer); - Graphics.ExecuteCommandBuffer(_commandBuffer); - } - public void GenerateReactiveMask(in Asr.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer) { GenReactiveConsts.scale = dispatchParams.Scale; 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 d22b383..0fc44f2 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 @@ -19,7 +19,6 @@ // THE SOFTWARE. using System; -using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; using UnityEngine; @@ -35,7 +34,7 @@ namespace ArmASR /// internal abstract class AsrPass: IDisposable { - internal const int ShadingChangeMipLevel = 4; // This matches the FFXM_FSR2_SHADING_CHANGE_MIP_LEVEL define + internal const int ShadingChangeMipLevel = 4; // This matches the FFXM_FSR2_SHADING_CHANGE_MIP_LEVEL define // TODO: still relevant? protected readonly Asr.ContextDescription ContextDescription; protected readonly AsrResources Resources; @@ -66,7 +65,7 @@ namespace ArmASR } } - public void ScheduleDispatch(CommandBuffer commandBuffer, Asr.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + public void ScheduleDispatch(CommandBuffer commandBuffer, Asr.DispatchDescription dispatchParams, int frameIndex, int dispatchX = 0, int dispatchY = 0) { BeginSample(commandBuffer); DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY); diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASRUpscaler.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASRUpscaler.cs index 9833510..47107cc 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASRUpscaler.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASRUpscaler.cs @@ -49,6 +49,7 @@ namespace UnityEngine.Rendering.PostProcessing var scaledRenderSize = _genReactiveDescription.RenderSize; cmd.GetTemporaryRT(AsrShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); + _genReactiveDescription.OutReactive = new ResourceView(AsrShaderIDs.UavAutoReactive); _asrContext.GenerateReactiveMask(_genReactiveDescription, cmd); _dispatchDescription.Reactive = new ResourceView(AsrShaderIDs.UavAutoReactive); }