From 76d0ee54259ab56d541bf76046647b8b2b86aef7 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sun, 4 Aug 2024 17:16:42 +0200 Subject: [PATCH] Changed all dispatch descriptions into structs, renamed some fields, cleaned up some unused code. Changing to lowercase field names for public struct members now, which follows the C# naming conventions. FSR2/3 won't follow suit for now, because too much code already makes use of the capitalized names. --- .../FrameInterpolation/FrameInterpolation.cs | 11 ++++----- .../FrameInterpolationContext.cs | 18 ++++----------- Runtime/OpticalFlow/OpticalFlow.cs | 14 +++++------ Runtime/OpticalFlow/OpticalFlowContext.cs | 23 ++++++------------- Runtime/OpticalFlow/OpticalFlowPass.cs | 10 ++++---- 5 files changed, 28 insertions(+), 48 deletions(-) diff --git a/Runtime/FrameInterpolation/FrameInterpolation.cs b/Runtime/FrameInterpolation/FrameInterpolation.cs index 861c36a..d83f4f2 100644 --- a/Runtime/FrameInterpolation/FrameInterpolation.cs +++ b/Runtime/FrameInterpolation/FrameInterpolation.cs @@ -39,7 +39,7 @@ namespace FidelityFX.FrameGen public FrameInterpolationShaders shaders; } - public class PrepareDescription + public struct PrepareDescription { public DispatchFlags flags; public Vector2Int renderSize; @@ -57,8 +57,7 @@ namespace FidelityFX.FrameGen public ulong frameID; } - // TODO: turn all of these into structs - public class DispatchDescription + public struct DispatchDescription { public DispatchFlags flags; public Vector2Int displaySize; @@ -87,14 +86,14 @@ namespace FidelityFX.FrameGen public Vector2 minMaxLuminance; public ulong frameID; - public ref ResourceView InterpolationSource + public ResourceView InterpolationSource { get { if (currentBackBuffer_HUDLess.IsValid) - return ref currentBackBuffer_HUDLess; + return currentBackBuffer_HUDLess; - return ref currentBackBuffer; + return currentBackBuffer; } } } diff --git a/Runtime/FrameInterpolation/FrameInterpolationContext.cs b/Runtime/FrameInterpolation/FrameInterpolationContext.cs index 1a436d5..d4f2c95 100644 --- a/Runtime/FrameInterpolation/FrameInterpolationContext.cs +++ b/Runtime/FrameInterpolation/FrameInterpolationContext.cs @@ -93,7 +93,7 @@ namespace FidelityFX.FrameGen _frameInterpolationConstants.Destroy(); } - public void Prepare(CommandBuffer commandBuffer, FrameInterpolation.PrepareDescription prepareDescription) + public void Prepare(CommandBuffer commandBuffer, in FrameInterpolation.PrepareDescription prepareDescription) { commandBuffer.BeginSample(_prepareSampler); @@ -125,7 +125,7 @@ namespace FidelityFX.FrameGen commandBuffer.EndSample(_prepareSampler); } - public void Dispatch(CommandBuffer commandBuffer, FrameInterpolation.DispatchDescription dispatchDescription) + public void Dispatch(CommandBuffer commandBuffer, in FrameInterpolation.DispatchDescription dispatchDescription) { commandBuffer.BeginSample(_sampler); @@ -226,13 +226,12 @@ namespace FidelityFX.FrameGen } // Store current buffer - ref var backBuf = ref dispatchDescription.InterpolationSource; - commandBuffer.CopyTexture(backBuf.RenderTarget, _resources.PreviousInterpolationSource); + commandBuffer.CopyTexture(dispatchDescription.InterpolationSource.RenderTarget, _resources.PreviousInterpolationSource); commandBuffer.EndSample(_sampler); } - private void DispatchGameVectorFieldInpaintingPyramid(CommandBuffer commandBuffer, FrameInterpolation.DispatchDescription dispatchDescription, int doubleBufferId) + private void DispatchGameVectorFieldInpaintingPyramid(CommandBuffer commandBuffer, in FrameInterpolation.DispatchDescription dispatchDescription, int doubleBufferId) { SetupSpdConstants(dispatchDescription.renderSize, out var dispatchThreadGroupCount); _spdConstants.UpdateBufferData(commandBuffer); @@ -257,14 +256,5 @@ namespace FidelityFX.FrameGen 0.0f, 1.0f, 0.1f, // green 1.0f, 1.0f, 0.48f // bright yellow }; - - private static void DestroyPass(ref FrameInterpolationPass pass) - { - if (pass == null) - return; - - pass.Dispose(); - pass = null; - } } } diff --git a/Runtime/OpticalFlow/OpticalFlow.cs b/Runtime/OpticalFlow/OpticalFlow.cs index 3d895fb..3b3c15d 100644 --- a/Runtime/OpticalFlow/OpticalFlow.cs +++ b/Runtime/OpticalFlow/OpticalFlow.cs @@ -33,15 +33,15 @@ namespace FidelityFX.FrameGen public OpticalFlowShaders shaders; } - public class DispatchDescription + public struct DispatchDescription { - public ResourceView Color; - public ResourceView OpticalFlowVector; - public ResourceView OpticalFlowSCD; - public bool Reset; + public ResourceView color; + public ResourceView opticalFlowVector; + public ResourceView opticalFlowSCD; + public bool reset; - public BackbufferTransferFunction BackbufferTransferFunction; - public Vector2 MinMaxLuminance; + public BackbufferTransferFunction backbufferTransferFunction; + public Vector2 minMaxLuminance; } internal static Vector2Int GetOpticalFlowTextureSize(Vector2Int displaySize, int opticalFlowBlockSize) diff --git a/Runtime/OpticalFlow/OpticalFlowContext.cs b/Runtime/OpticalFlow/OpticalFlowContext.cs index a106451..02f4c16 100644 --- a/Runtime/OpticalFlow/OpticalFlowContext.cs +++ b/Runtime/OpticalFlow/OpticalFlowContext.cs @@ -82,11 +82,11 @@ namespace FidelityFX.FrameGen const int opticalFlowBlockSize = 8; ref var constants = ref _opticalFlowConstants.Value; - constants.backbufferTransferFunction = (uint)dispatchDescription.BackbufferTransferFunction; - constants.minMaxLuminance = dispatchDescription.MinMaxLuminance; + constants.backbufferTransferFunction = (uint)dispatchDescription.backbufferTransferFunction; + constants.minMaxLuminance = dispatchDescription.minMaxLuminance; int frameIndex = _resourceFrameIndex % 2; - bool resetAccumulation = dispatchDescription.Reset || _firstExecution; + bool resetAccumulation = dispatchDescription.reset || _firstExecution; _firstExecution = false; if (resetAccumulation) @@ -100,7 +100,7 @@ namespace FidelityFX.FrameGen { commandBuffer.SetRenderTarget(_resources.OpticalFlowSCDTemp); commandBuffer.ClearRenderTarget(false, true, Color.clear); - commandBuffer.SetRenderTarget(dispatchDescription.OpticalFlowSCD.RenderTarget); + commandBuffer.SetRenderTarget(dispatchDescription.opticalFlowSCD.RenderTarget); commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.SetRenderTarget(_resources.OpticalFlowSCDHistogram); commandBuffer.ClearRenderTarget(false, true, Color.clear); @@ -135,7 +135,7 @@ namespace FidelityFX.FrameGen { const int threadGroupSizeX = 32; - const int threadGroupSizeY = 8; + //const int threadGroupSizeY = 8; int strataWidth = (_contextDescription.resolution.x / 4) / OpticalFlow.HistogramsPerDim; int strataHeight = _contextDescription.resolution.y / OpticalFlow.HistogramsPerDim; int dispatchX = (strataWidth + threadGroupSizeX - 1) / threadGroupSizeX; @@ -173,7 +173,7 @@ namespace FidelityFX.FrameGen const int threadPixels = 4; Assert.IsTrue(opticalFlowBlockSize >= threadPixels); - const int threadGroupSizeX = 4; + //const int threadGroupSizeX = 4; const int threadGroupSizeY = 16; const int threadGroupSize = 64; int dispatchX = ((inputLumaWidth + threadPixels - 1) / threadPixels * threadGroupSizeY + (threadGroupSize - 1)) / threadGroupSize; @@ -201,7 +201,7 @@ namespace FidelityFX.FrameGen const int threadGroupSizeX = opticalFlowBlockSize / 2; const int threadGroupSizeY = opticalFlowBlockSize / 2; - const int threadGroupSizeZ = 4; + //const int threadGroupSizeZ = 4; int dispatchX = (nextLevelWidth + threadGroupSizeX - 1) / threadGroupSizeX; int dispatchY = (nextLevelHeight + threadGroupSizeY - 1) / threadGroupSizeY; const int dispatchZ = 1; @@ -223,14 +223,5 @@ namespace FidelityFX.FrameGen FfxSpd.SetupSpdConstants(_contextDescription.resolution * resolutionMultiplier, ref spdConstants.spd, out dispatchThreadGroupCount); spdConstants.numWorkGroupsOpticalFlowInputPyramid = spdConstants.spd.numWorkGroups; } - - private static void DestroyPass(ref OpticalFlowPass pass) - { - if (pass == null) - return; - - pass.Dispose(); - pass = null; - } } } diff --git a/Runtime/OpticalFlow/OpticalFlowPass.cs b/Runtime/OpticalFlow/OpticalFlowPass.cs index fd7efbc..1fe56f2 100644 --- a/Runtime/OpticalFlow/OpticalFlowPass.cs +++ b/Runtime/OpticalFlow/OpticalFlowPass.cs @@ -43,7 +43,7 @@ namespace FidelityFX.FrameGen protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in OpticalFlow.DispatchDescription dispatchParams, int bufferIndex, int level, int dispatchX, int dispatchY, int dispatchZ) { - commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvInputColor, dispatchParams.Color); + commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvInputColor, dispatchParams.color); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowInput, Resources.OpticalFlowInputLevels[0][bufferIndex]); @@ -113,7 +113,7 @@ namespace FidelityFX.FrameGen commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdHistogram, Resources.OpticalFlowSCDHistogram); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdPreviousHistogram, Resources.OpticalFlowSCDPreviousHistogram); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdTemp, Resources.OpticalFlowSCDTemp); - commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.OpticalFlowSCD); + commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.opticalFlowSCD); commandBuffer.SetComputeConstantBufferParam(ComputeShader, OpticalFlowShaderIDs.CbOpticalFlow, Constants); @@ -136,7 +136,7 @@ namespace FidelityFX.FrameGen commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvOpticalFlowInput, Resources.OpticalFlowInputLevels[level][bufferIndex]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvOpticalFlowPreviousInput, Resources.OpticalFlowInputLevels[level][bufferIndex ^ 1]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlow, Resources.OpticalFlowLevels[level][levelIndex]); - commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.OpticalFlowSCD); + commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.opticalFlowSCD); commandBuffer.SetComputeConstantBufferParam(ComputeShader, OpticalFlowShaderIDs.CbOpticalFlow, Constants); @@ -161,7 +161,7 @@ namespace FidelityFX.FrameGen if (level == 0) { // Final output (levels are counted in reverse) - commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlow, dispatchParams.OpticalFlowVector); + commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlow, dispatchParams.opticalFlowVector); } else { @@ -194,7 +194,7 @@ namespace FidelityFX.FrameGen commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvOpticalFlow, Resources.OpticalFlowLevels[level][levelIndex ^ 1]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowNextLevel, Resources.OpticalFlowLevels[level - 1][levelIndex ^ 1]); - commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.OpticalFlowSCD); + commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.opticalFlowSCD); commandBuffer.SetComputeConstantBufferParam(ComputeShader, OpticalFlowShaderIDs.CbOpticalFlow, Constants);