Browse Source

Allocate double buffers only when async compute support is enabled

fsr3framegen
Nico de Poel 2 years ago
parent
commit
279edd4429
  1. 14
      Runtime/FrameInterpolation/FrameInterpolationResources.cs

14
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<TElem>());
}
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();

Loading…
Cancel
Save