Browse Source

Refactored resources classes to use common base class

fsr3framegen
Nico de Poel 2 years ago
parent
commit
097eaa960a
  1. 55
      Runtime/FrameInterpolation/FrameInterpolationResources.cs
  2. 38
      Runtime/OpticalFlow/OpticalFlowResources.cs

55
Runtime/FrameInterpolation/FrameInterpolationResources.cs

@ -5,7 +5,7 @@ using UnityEngine.Experimental.Rendering;
namespace FidelityFX.FrameGen namespace FidelityFX.FrameGen
{ {
internal class FrameInterpolationResources
internal class FrameInterpolationResources: FfxResourcesBase
{ {
public RenderTexture ReconstructedDepthInterpolatedFrame; public RenderTexture ReconstructedDepthInterpolatedFrame;
public RenderTexture GameMotionVectorFieldX; public RenderTexture GameMotionVectorFieldX;
@ -60,58 +60,5 @@ namespace FidelityFX.FrameGen
DestroyResource(ref GameMotionVectorFieldX); DestroyResource(ref GameMotionVectorFieldX);
DestroyResource(ref ReconstructedDepthInterpolatedFrame); DestroyResource(ref ReconstructedDepthInterpolatedFrame);
} }
private static RenderTexture CreateResource(string name, Vector2Int size, GraphicsFormat format)
{
var rt = new RenderTexture(size.x, size.y, 0, format) { name = name, enableRandomWrite = true };
rt.Create();
return rt;
}
private static RenderTexture CreateResourceMips(string name, Vector2Int size, GraphicsFormat format)
{
int mipCount = 1 + Mathf.FloorToInt(Mathf.Log(Math.Max(size.x, size.y), 2.0f));
var rt = new RenderTexture(size.x, size.y, 0, format, mipCount) { name = name, enableRandomWrite = true, useMipMap = true, autoGenerateMips = false };
rt.Create();
return rt;
}
private static ComputeBuffer CreateBuffer<TElem>(string name, int count)
{
return new ComputeBuffer(count, Marshal.SizeOf<TElem>());
}
private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format, int numElements = 2)
{
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();
}
}
private static void DestroyResource(ref RenderTexture resource)
{
if (resource == null)
return;
resource.Release();
resource = null;
}
private static void DestroyResource(ref ComputeBuffer resource)
{
if (resource == null)
return;
resource.Release();
resource = null;
}
private static void DestroyResource(RenderTexture[] resource)
{
for (int i = 0; i < resource.Length; ++i)
DestroyResource(ref resource[i]);
}
} }
} }

38
Runtime/OpticalFlow/OpticalFlowResources.cs

@ -3,7 +3,7 @@ using UnityEngine.Experimental.Rendering;
namespace FidelityFX.FrameGen namespace FidelityFX.FrameGen
{ {
internal class OpticalFlowResources
internal class OpticalFlowResources: FfxResourcesBase
{ {
public readonly RenderTexture[][] OpticalFlowInputLevels = public readonly RenderTexture[][] OpticalFlowInputLevels =
{ {
@ -36,11 +36,6 @@ namespace FidelityFX.FrameGen
Vector2Int opticalFlowInputTextureSize = contextDescription.resolution; Vector2Int opticalFlowInputTextureSize = contextDescription.resolution;
Vector2Int opticalFlowTextureSize = OpticalFlow.GetOpticalFlowTextureSize(contextDescription.resolution, OpticalFlow.MinBlockSize); Vector2Int opticalFlowTextureSize = OpticalFlow.GetOpticalFlowTextureSize(contextDescription.resolution, OpticalFlow.MinBlockSize);
// TODO: this seems useless, delete unless something comes up
Vector2Int opticalFlowHistogramTextureSize = OpticalFlow.GetOpticalFlowHistogramSize(0);
Vector2Int globalMotionSearchMaxDispatchSize = OpticalFlow.GetGlobalMotionSearchDispatchSize(0);
int globalMotionSearchTextureWidth = 4 + (globalMotionSearchMaxDispatchSize.x * globalMotionSearchMaxDispatchSize.y);
for (int level = 0; level < OpticalFlow.OpticalFlowMaxPyramidLevels; ++level) for (int level = 0; level < OpticalFlow.OpticalFlowMaxPyramidLevels; ++level)
{ {
CreateDoubleBufferedResource(OpticalFlowInputLevels[level], $"OPTICALFLOW_OpticalFlowInputLevel{level}-", opticalFlowInputTextureSize, GraphicsFormat.R8_UInt); CreateDoubleBufferedResource(OpticalFlowInputLevels[level], $"OPTICALFLOW_OpticalFlowInputLevel{level}-", opticalFlowInputTextureSize, GraphicsFormat.R8_UInt);
@ -77,36 +72,5 @@ namespace FidelityFX.FrameGen
{ {
return (x + (y - 1)) & ~(y - 1); return (x + (y - 1)) & ~(y - 1);
} }
private static RenderTexture CreateResource(string name, Vector2Int size, GraphicsFormat format)
{
var rt = new RenderTexture(size.x, size.y, 0, format) { name = name, enableRandomWrite = true };
rt.Create();
return rt;
}
private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format)
{
for (int i = 0; i < 2; ++i)
{
resource[i] = new RenderTexture(size.x, size.y, 0, format) { name = name + (i + 1), enableRandomWrite = true };
resource[i].Create();
}
}
private static void DestroyResource(ref RenderTexture resource)
{
if (resource == null)
return;
resource.Release();
resource = null;
}
private static void DestroyResource(RenderTexture[] resource)
{
for (int i = 0; i < resource.Length; ++i)
DestroyResource(ref resource[i]);
}
} }
} }
Loading…
Cancel
Save