From 910621b0190344faed357d07191dbf8d59f0d0a4 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Fri, 26 Jul 2024 23:22:46 +0200 Subject: [PATCH] Couple of tweaks to facilitate integration --- .../FrameInterpolation/FrameInterpolation.cs | 23 +++++++++++++++++++ .../FrameInterpolationContext.cs | 1 + Runtime/OpticalFlow/OpticalFlow.cs | 2 +- Runtime/OpticalFlow/OpticalFlowContext.cs | 2 +- Runtime/OpticalFlow/OpticalFlowResources.cs | 2 +- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Runtime/FrameInterpolation/FrameInterpolation.cs b/Runtime/FrameInterpolation/FrameInterpolation.cs index 5bd8538..6ef37f6 100644 --- a/Runtime/FrameInterpolation/FrameInterpolation.cs +++ b/Runtime/FrameInterpolation/FrameInterpolation.cs @@ -7,6 +7,29 @@ namespace FidelityFX.FrameGen { public static class FrameInterpolation { + public static FrameInterpolationContext CreateContext(Vector2Int displaySize, Vector2Int maxRenderSize, FrameInterpolationShaders shaders, GraphicsFormat backBufferFormat, InitializationFlags flags = 0) + { + if (SystemInfo.usesReversedZBuffer) + flags |= InitializationFlags.EnableDepthInverted; + else + flags &= ~InitializationFlags.EnableDepthInverted; + + var contextDescription = new ContextDescription + { + flags = flags, + maxRenderSize = maxRenderSize, + displaySize = displaySize, + backBufferFormat = backBufferFormat, + shaders = shaders, + }; + + Debug.Log($"Setting up Frame Interpolation with render size: {maxRenderSize.x}x{maxRenderSize.y}, display size: {displaySize.x}x{displaySize.y}, backbuffer format: {backBufferFormat}, flags: {flags}"); + + var context = new FrameInterpolationContext(); + context.Create(contextDescription); + return context; + } + public struct ContextDescription { public InitializationFlags flags; diff --git a/Runtime/FrameInterpolation/FrameInterpolationContext.cs b/Runtime/FrameInterpolation/FrameInterpolationContext.cs index cc690d7..857635a 100644 --- a/Runtime/FrameInterpolation/FrameInterpolationContext.cs +++ b/Runtime/FrameInterpolation/FrameInterpolationContext.cs @@ -198,6 +198,7 @@ namespace FidelityFX.FrameGen // Schedule work for the interpolation command list _setupPass.ScheduleDispatch(commandBuffer, dispatchDescription, doubleBufferId, renderDispatchSizeX, renderDispatchSizeY); + // TODO delegates are reference types, i.e. this allocates some memory every frame Action dispatchGameVectorFieldInpaintingPyramid = () => { SetupSpdConstants(dispatchDescription.renderSize, out var dispatchThreadGroupCount); diff --git a/Runtime/OpticalFlow/OpticalFlow.cs b/Runtime/OpticalFlow/OpticalFlow.cs index 774434d..fd53982 100644 --- a/Runtime/OpticalFlow/OpticalFlow.cs +++ b/Runtime/OpticalFlow/OpticalFlow.cs @@ -6,7 +6,7 @@ namespace FidelityFX.FrameGen { public static class OpticalFlow { - internal const int MinBlockSize = 8; + public static readonly int MinBlockSize = 8; internal const int OpticalFlowMaxPyramidLevels = 7; internal const int HistogramBins = 256; internal const int HistogramsPerDim = 3; diff --git a/Runtime/OpticalFlow/OpticalFlowContext.cs b/Runtime/OpticalFlow/OpticalFlowContext.cs index 3263778..739a4d8 100644 --- a/Runtime/OpticalFlow/OpticalFlowContext.cs +++ b/Runtime/OpticalFlow/OpticalFlowContext.cs @@ -36,7 +36,7 @@ namespace FidelityFX.FrameGen private readonly Vector2Int[] _opticalFlowTextureSizes = new Vector2Int[OpticalFlow.OpticalFlowMaxPyramidLevels]; private readonly CustomSampler _sampler = CustomSampler.Create("Optical Flow"); - public void Create(OpticalFlow.ContextDescription contextDescription) + public void Create(in OpticalFlow.ContextDescription contextDescription) { _contextDescription = contextDescription; diff --git a/Runtime/OpticalFlow/OpticalFlowResources.cs b/Runtime/OpticalFlow/OpticalFlowResources.cs index 27e1cfd..24449fc 100644 --- a/Runtime/OpticalFlow/OpticalFlowResources.cs +++ b/Runtime/OpticalFlow/OpticalFlowResources.cs @@ -31,7 +31,7 @@ namespace FidelityFX.FrameGen public RenderTexture OpticalFlowSCDPreviousHistogram; public RenderTexture OpticalFlowSCDTemp; - public void Create(OpticalFlow.ContextDescription contextDescription) + public void Create(in OpticalFlow.ContextDescription contextDescription) { Vector2Int opticalFlowInputTextureSize = contextDescription.resolution; Vector2Int opticalFlowTextureSize = OpticalFlow.GetOpticalFlowTextureSize(contextDescription.resolution, OpticalFlow.MinBlockSize);