diff --git a/Runtime/FrameInterpolation/FrameInterpolationResources.cs b/Runtime/FrameInterpolation/FrameInterpolationResources.cs index 443a374..84d0474 100644 --- a/Runtime/FrameInterpolation/FrameInterpolationResources.cs +++ b/Runtime/FrameInterpolation/FrameInterpolationResources.cs @@ -36,10 +36,12 @@ namespace FidelityFX.FrameGen OpticalFlowMotionVectorFieldY = CreateResource("FI_OpticalFlowMotionVectorFieldY", maxRenderSize, GraphicsFormat.R32_UInt); PreviousInterpolationSource = CreateResource("FI_PreviousInterpolationSource", displaySize, contextDescription.backBufferFormat); DisocclusionMask = CreateResource("FI_DisocclusionMask", maxRenderSize, GraphicsFormat.R8G8_UNorm); - - CreateDoubleBufferedResource(DilatedDepth, "FI_DilatedDepth_", maxRenderSize, GraphicsFormat.R32_SFloat); - CreateDoubleBufferedResource(DilatedMotionVectors, "FI_DilatedMVs_", maxRenderSize, GraphicsFormat.R16G16_SFloat); - CreateDoubleBufferedResource(ReconstructedDepth, "FI_ReconstructedDepth_", maxRenderSize, GraphicsFormat.R32_UInt); + + // Double buffering is used only when async support is enabled + int numBuffers = (contextDescription.flags & FrameInterpolation.InitializationFlags.EnableAsyncSupport) != 0 ? 2 : 1; + CreateDoubleBufferedResource(DilatedDepth, "FI_DilatedDepth_", maxRenderSize, GraphicsFormat.R32_SFloat, numBuffers); + CreateDoubleBufferedResource(DilatedMotionVectors, "FI_DilatedMVs_", maxRenderSize, GraphicsFormat.R16G16_SFloat, numBuffers); + CreateDoubleBufferedResource(ReconstructedDepth, "FI_ReconstructedDepth_", maxRenderSize, GraphicsFormat.R32_UInt, numBuffers); } public void Destroy() @@ -79,9 +81,9 @@ namespace FidelityFX.FrameGen return new ComputeBuffer(count, Marshal.SizeOf()); } - private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format) + private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format, int numElements = 2) { - for (int i = 0; i < 2; ++i) + for (int i = 0; i < numElements; ++i) { resource[i] = new RenderTexture(size.x, size.y, 0, format) { name = name + (i + 1), enableRandomWrite = true }; resource[i].Create();