Browse Source

Turned dispatch descriptions into structs, using in-parameters where applicable

asr-console
Nico de Poel 11 months ago
parent
commit
d320a76b89
  1. 22
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/Asr.cs
  2. 28
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs
  3. 2
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs

22
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/Asr.cs

@ -44,7 +44,7 @@ namespace ArmASR
flags |= InitializationFlags.EnableDebugChecking; flags |= InitializationFlags.EnableDebugChecking;
#endif #endif
Debug.Log($"Setting up Arm ASR with render size: {maxRenderSize.x}x{maxRenderSize.y}, display size: {displaySize.x}x{displaySize.y}, flags: {flags}");
Debug.Log($"Setting up ASR with render size: {maxRenderSize.x}x{maxRenderSize.y}, display size: {displaySize.x}x{displaySize.y}, flags: {flags}");
var contextDescription = new ContextDescription var contextDescription = new ContextDescription
{ {
@ -211,7 +211,7 @@ namespace ArmASR
/// <summary> /// <summary>
/// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 2. /// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 2.
/// </summary> /// </summary>
public class DispatchDescription // TODO: make into struct
public struct DispatchDescription
{ {
public ResourceView Color; public ResourceView Color;
public ResourceView Depth; public ResourceView Depth;
@ -239,16 +239,24 @@ namespace ArmASR
/// <summary> /// <summary>
/// A structure encapsulating the parameters for automatic generation of a reactive mask. /// A structure encapsulating the parameters for automatic generation of a reactive mask.
/// </summary> /// </summary>
public class GenerateReactiveDescription // TODO: make into struct (with static readonly Default property)
public struct GenerateReactiveDescription
{ {
public ResourceView ColorOpaqueOnly; public ResourceView ColorOpaqueOnly;
public ResourceView ColorPreUpscale; public ResourceView ColorPreUpscale;
public ResourceView OutReactive; public ResourceView OutReactive;
public Vector2Int RenderSize; public Vector2Int RenderSize;
public float Scale = 0.5f;
public float CutoffThreshold = 0.2f;
public float BinaryValue = 0.9f;
public GenerateReactiveFlags Flags = GenerateReactiveFlags.ApplyTonemap | GenerateReactiveFlags.ApplyThreshold | GenerateReactiveFlags.UseComponentsMax;
public float Scale;
public float CutoffThreshold;
public float BinaryValue;
public GenerateReactiveFlags Flags;
public static readonly GenerateReactiveDescription Default = new GenerateReactiveDescription
{
Scale = 0.5f,
CutoffThreshold = 0.2f,
BinaryValue = 0.9f,
Flags = GenerateReactiveFlags.ApplyTonemap | GenerateReactiveFlags.ApplyThreshold | GenerateReactiveFlags.UseComponentsMax,
};
} }
[Flags] [Flags]

28
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs

@ -71,10 +71,10 @@ namespace ArmASR
private Vector2 _previousJitterOffset; private Vector2 _previousJitterOffset;
private int _resourceFrameIndex; private int _resourceFrameIndex;
public void Create(Asr.ContextDescription contextDescription)
public void Create(in Asr.ContextDescription contextDescription)
{ {
_contextDescription = contextDescription; _contextDescription = contextDescription;
_commandBuffer = new CommandBuffer { name = "Arm ASR" };
_commandBuffer = new CommandBuffer { name = "ASR" };
_upscalerConstantsBuffer = CreateConstantBuffer<Asr.UpscalerConstants>(); _upscalerConstantsBuffer = CreateConstantBuffer<Asr.UpscalerConstants>();
_spdConstantsBuffer = CreateConstantBuffer<Asr.SpdConstants>(); _spdConstantsBuffer = CreateConstantBuffer<Asr.SpdConstants>();
@ -127,7 +127,7 @@ namespace ArmASR
} }
} }
public void Dispatch(Asr.DispatchDescription dispatchParams)
public void Dispatch(in Asr.DispatchDescription dispatchParams)
{ {
_commandBuffer.Clear(); _commandBuffer.Clear();
Dispatch(dispatchParams, _commandBuffer); Dispatch(dispatchParams, _commandBuffer);
@ -198,7 +198,7 @@ namespace ArmASR
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
} }
// FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option
// Need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option
bool depthInverted = (_contextDescription.Flags & Asr.InitializationFlags.EnableDepthInverted) == Asr.InitializationFlags.EnableDepthInverted; bool depthInverted = (_contextDescription.Flags & Asr.InitializationFlags.EnableDepthInverted) == Asr.InitializationFlags.EnableDepthInverted;
commandBuffer.SetRenderTarget(AsrShaderIDs.UavReconstructedPrevNearestDepth); commandBuffer.SetRenderTarget(AsrShaderIDs.UavReconstructedPrevNearestDepth);
commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white);
@ -245,29 +245,25 @@ namespace ArmASR
commandBuffer.DisableShaderKeyword("UNITY_FFXM_TEXTURE2D_X_ARRAY"); commandBuffer.DisableShaderKeyword("UNITY_FFXM_TEXTURE2D_X_ARRAY");
} }
public void GenerateReactiveMask(Asr.GenerateReactiveDescription dispatchParams)
public void GenerateReactiveMask(in Asr.GenerateReactiveDescription dispatchParams)
{ {
_commandBuffer.Clear(); _commandBuffer.Clear();
GenerateReactiveMask(dispatchParams, _commandBuffer); GenerateReactiveMask(dispatchParams, _commandBuffer);
Graphics.ExecuteCommandBuffer(_commandBuffer); Graphics.ExecuteCommandBuffer(_commandBuffer);
} }
public void GenerateReactiveMask(Asr.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer)
public void GenerateReactiveMask(in Asr.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer)
{ {
const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchSrcY = (dispatchParams.RenderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
GenReactiveConsts.scale = dispatchParams.Scale; GenReactiveConsts.scale = dispatchParams.Scale;
GenReactiveConsts.threshold = dispatchParams.CutoffThreshold; GenReactiveConsts.threshold = dispatchParams.CutoffThreshold;
GenReactiveConsts.binaryValue = dispatchParams.BinaryValue; GenReactiveConsts.binaryValue = dispatchParams.BinaryValue;
GenReactiveConsts.flags = (uint)dispatchParams.Flags; GenReactiveConsts.flags = (uint)dispatchParams.Flags;
commandBuffer.SetBufferData(_generateReactiveConstantsBuffer, _generateReactiveConstantsArray); commandBuffer.SetBufferData(_generateReactiveConstantsBuffer, _generateReactiveConstantsArray);
((AsrGenerateReactivePass)_generateReactivePass).ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY);
((AsrGenerateReactivePass)_generateReactivePass).ScheduleDispatch(commandBuffer, dispatchParams);
} }
private void SetupConstants(Asr.DispatchDescription dispatchParams, bool resetAccumulation)
private void SetupConstants(in Asr.DispatchDescription dispatchParams, bool resetAccumulation)
{ {
ref Asr.UpscalerConstants constants = ref UpscalerConsts; ref Asr.UpscalerConstants constants = ref UpscalerConsts;
@ -331,7 +327,7 @@ namespace ArmASR
constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv); constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv);
} }
private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Asr.DispatchDescription dispatchParams)
private Vector4 SetupDeviceDepthToViewSpaceDepthParams(in Asr.DispatchDescription dispatchParams)
{ {
bool inverted = (_contextDescription.Flags & Asr.InitializationFlags.EnableDepthInverted) != 0; bool inverted = (_contextDescription.Flags & Asr.InitializationFlags.EnableDepthInverted) != 0;
bool infinite = (_contextDescription.Flags & Asr.InitializationFlags.EnableDepthInfinite) != 0; bool infinite = (_contextDescription.Flags & Asr.InitializationFlags.EnableDepthInfinite) != 0;
@ -364,13 +360,13 @@ namespace ArmASR
1.0f / cotHalfFovY); 1.0f / cotHalfFovY);
} }
private void SetupRcasConstants(Asr.DispatchDescription dispatchParams)
private void SetupRcasConstants(in Asr.DispatchDescription dispatchParams)
{ {
int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1)); int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1));
RcasConsts = RcasConfigs[sharpnessIndex]; RcasConsts = RcasConfigs[sharpnessIndex];
} }
private void SetupSpdConstants(Asr.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount)
private void SetupSpdConstants(in Asr.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount)
{ {
RectInt rectInfo = new RectInt(0, 0, dispatchParams.RenderSize.x, dispatchParams.RenderSize.y); RectInt rectInfo = new RectInt(0, 0, dispatchParams.RenderSize.x, dispatchParams.RenderSize.y);
SpdSetup(rectInfo, out dispatchThreadGroupCount, out var workGroupOffset, out var numWorkGroupsAndMips); SpdSetup(rectInfo, out dispatchThreadGroupCount, out var workGroupOffset, out var numWorkGroupsAndMips);
@ -402,7 +398,7 @@ namespace ArmASR
} }
} }
private void DebugCheckDispatch(Asr.DispatchDescription dispatchParams)
private void DebugCheckDispatch(in Asr.DispatchDescription dispatchParams)
{ {
if (!dispatchParams.Color.IsValid) if (!dispatchParams.Color.IsValid)
{ {

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

@ -313,7 +313,7 @@ namespace ArmASR
{ {
} }
public void ScheduleDispatch(CommandBuffer commandBuffer, Asr.GenerateReactiveDescription dispatchParams, int dispatchX, int dispatchY)
public void ScheduleDispatch(CommandBuffer commandBuffer, in Asr.GenerateReactiveDescription dispatchParams)
{ {
BeginSample(commandBuffer); BeginSample(commandBuffer);

Loading…
Cancel
Save