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 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<Asr.UpscalerConstants>();
_spdConstantsBuffer = CreateConstantBuffer<Asr.SpdConstants>();
@ -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;

5
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
/// </summary>
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);

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;
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);
}

Loading…
Cancel
Save