Browse Source

Some cleanup and minor fixes

asr-console
Nico de Poel 11 months ago
parent
commit
3ef31fac65
  1. 38
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs
  2. 5
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs
  3. 1
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASRUpscaler.cs

38
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 const int MaxQueuedFrames = 16;
private Asr.ContextDescription _contextDescription; private Asr.ContextDescription _contextDescription;
private CommandBuffer _commandBuffer;
private AsrPass _computeLuminancePyramidPass; private AsrPass _computeLuminancePyramidPass;
private AsrPass _reconstructPreviousDepthPass; private AsrPass _reconstructPreviousDepthPass;
@ -48,6 +47,7 @@ namespace ArmASR
private AsrPass _tcrAutogeneratePass; private AsrPass _tcrAutogeneratePass;
private readonly AsrResources _resources = new AsrResources(); private readonly AsrResources _resources = new AsrResources();
private readonly AsrKeywords _keywords = new AsrKeywords();
private ComputeBuffer _upscalerConstantsBuffer; private ComputeBuffer _upscalerConstantsBuffer;
private readonly Asr.UpscalerConstants[] _upscalerConstantsArray = { new Asr.UpscalerConstants() }; private readonly Asr.UpscalerConstants[] _upscalerConstantsArray = { new Asr.UpscalerConstants() };
@ -65,8 +65,6 @@ namespace ArmASR
private readonly Asr.GenerateReactiveConstants[] _generateReactiveConstantsArray = { new Asr.GenerateReactiveConstants() }; private readonly Asr.GenerateReactiveConstants[] _generateReactiveConstantsArray = { new Asr.GenerateReactiveConstants() };
private ref Asr.GenerateReactiveConstants GenReactiveConsts => ref _generateReactiveConstantsArray[0]; private ref Asr.GenerateReactiveConstants GenReactiveConsts => ref _generateReactiveConstantsArray[0];
private AsrKeywords _keywords = new();
private bool _firstExecution; private bool _firstExecution;
private Vector2 _previousJitterOffset; private Vector2 _previousJitterOffset;
private int _resourceFrameIndex; private int _resourceFrameIndex;
@ -74,7 +72,6 @@ namespace ArmASR
public void Create(in Asr.ContextDescription contextDescription) public void Create(in Asr.ContextDescription contextDescription)
{ {
_contextDescription = contextDescription; _contextDescription = contextDescription;
_commandBuffer = new CommandBuffer { name = "ASR" };
_upscalerConstantsBuffer = CreateConstantBuffer<Asr.UpscalerConstants>(); _upscalerConstantsBuffer = CreateConstantBuffer<Asr.UpscalerConstants>();
_spdConstantsBuffer = CreateConstantBuffer<Asr.SpdConstants>(); _spdConstantsBuffer = CreateConstantBuffer<Asr.SpdConstants>();
@ -119,19 +116,6 @@ namespace ArmASR
DestroyConstantBuffer(ref _rcasConstantsBuffer); DestroyConstantBuffer(ref _rcasConstantsBuffer);
DestroyConstantBuffer(ref _spdConstantsBuffer); DestroyConstantBuffer(ref _spdConstantsBuffer);
DestroyConstantBuffer(ref _upscalerConstantsBuffer); 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) public void Dispatch(Asr.DispatchDescription dispatchParams, CommandBuffer commandBuffer)
@ -174,8 +158,6 @@ namespace ArmASR
const int threadGroupWorkRegionDim = 8; const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (UpscalerConsts.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchSrcX = (UpscalerConsts.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchSrcY = (UpscalerConsts.renderSize.y + (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 // Clear reconstructed depth for max depth store
if (resetAccumulation) if (resetAccumulation)
@ -214,16 +196,16 @@ namespace ArmASR
_computeLuminancePyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y); _computeLuminancePyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y);
// Reconstruct previous depth // Reconstruct previous depth
_reconstructPreviousDepthPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_reconstructPreviousDepthPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex);
// Depth clip // Depth clip
_depthClipPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_depthClipPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex);
// Create locks // Create locks
_lockPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); _lockPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
// Accumulate // Accumulate
_accumulatePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY);
_accumulatePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex);
if (dispatchParams.EnableSharpening) if (dispatchParams.EnableSharpening)
{ {
@ -232,10 +214,7 @@ namespace ArmASR
commandBuffer.SetBufferData(_rcasConstantsBuffer, _rcasConstantsArray); commandBuffer.SetBufferData(_rcasConstantsBuffer, _rcasConstantsArray);
// Dispatch RCAS // 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; _resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames;
@ -245,13 +224,6 @@ namespace ArmASR
commandBuffer.DisableShaderKeyword("UNITY_FFXM_TEXTURE2D_X_ARRAY"); 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) public void GenerateReactiveMask(in Asr.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer)
{ {
GenReactiveConsts.scale = dispatchParams.Scale; GenReactiveConsts.scale = dispatchParams.Scale;

5
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs

@ -19,7 +19,6 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using UnityEngine; using UnityEngine;
@ -35,7 +34,7 @@ namespace ArmASR
/// </summary> /// </summary>
internal abstract class AsrPass: IDisposable 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 Asr.ContextDescription ContextDescription;
protected readonly AsrResources Resources; 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); BeginSample(commandBuffer);
DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY); DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY);

1
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; var scaledRenderSize = _genReactiveDescription.RenderSize;
cmd.GetTemporaryRT(AsrShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); 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); _asrContext.GenerateReactiveMask(_genReactiveDescription, cmd);
_dispatchDescription.Reactive = new ResourceView(AsrShaderIDs.UavAutoReactive); _dispatchDescription.Reactive = new ResourceView(AsrShaderIDs.UavAutoReactive);
} }

Loading…
Cancel
Save