Browse Source

Created an abstract base class for context objects, with a few common helper methods

framework
Nico de Poel 2 years ago
parent
commit
19a74fee45
  1. 34
      Runtime/Common/FfxContextBase.cs
  2. 11
      Runtime/Common/FfxContextBase.cs.meta
  3. 25
      Runtime/FSR2/Fsr2Context.cs
  4. 25
      Runtime/FSR3/Fsr3UpscalerContext.cs

34
Runtime/Common/FfxContextBase.cs

@ -0,0 +1,34 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
namespace FidelityFX
{
public abstract class FfxContextBase
{
protected static ComputeBuffer CreateConstantBuffer<TBuf>()
where TBuf: struct
{
return new ComputeBuffer(1, Marshal.SizeOf<TBuf>(), ComputeBufferType.Constant);
}
protected static void DestroyConstantBuffer(ref ComputeBuffer bufferRef)
{
if (bufferRef == null)
return;
bufferRef.Release();
bufferRef = null;
}
protected static void DestroyPass<TPass>(ref TPass pass)
where TPass: class, IDisposable
{
if (pass == null)
return;
pass.Dispose();
pass = null;
}
}
}

11
Runtime/Common/FfxContextBase.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f4aeccbeb6e61434eb2e50b7190fda8d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

25
Runtime/FSR2/Fsr2Context.cs

@ -31,7 +31,7 @@ namespace FidelityFX.FSR2
/// Note that this class does not know anything about Unity render pipelines; all it knows is CommandBuffers and RenderTargetIdentifiers.
/// This should make it suitable for integration with any of the available Unity render pipelines.
/// </summary>
public class Fsr2Context
public class Fsr2Context: FfxContextBase
{
private const int MaxQueuedFrames = 16;
@ -591,28 +591,5 @@ namespace FidelityFX.FSR2
new Fsr2.RcasConstants(1064229695u, 997604214u),
new Fsr2.RcasConstants(1065353216u, 1006648320),
};
private static ComputeBuffer CreateConstantBuffer<TConstants>() where TConstants: struct
{
return new ComputeBuffer(1, Marshal.SizeOf<TConstants>(), ComputeBufferType.Constant);
}
private static void DestroyConstantBuffer(ref ComputeBuffer bufferRef)
{
if (bufferRef == null)
return;
bufferRef.Release();
bufferRef = null;
}
private static void DestroyPass(ref Fsr2Pass pass)
{
if (pass == null)
return;
pass.Dispose();
pass = null;
}
}
}

25
Runtime/FSR3/Fsr3UpscalerContext.cs

@ -31,7 +31,7 @@ namespace FidelityFX.FSR3
/// Note that this class does not know anything about Unity render pipelines; all it knows is CommandBuffers and RenderTargetIdentifiers.
/// This should make it suitable for integration with any of the available Unity render pipelines.
/// </summary>
public class Fsr3UpscalerContext
public class Fsr3UpscalerContext: FfxContextBase
{
private const int MaxQueuedFrames = 16;
@ -630,28 +630,5 @@ namespace FidelityFX.FSR3
new Fsr3Upscaler.RcasConstants(1064229695u, 997604214u),
new Fsr3Upscaler.RcasConstants(1065353216u, 1006648320),
};
private static ComputeBuffer CreateConstantBuffer<TConstants>() where TConstants: struct
{
return new ComputeBuffer(1, Marshal.SizeOf<TConstants>(), ComputeBufferType.Constant);
}
private static void DestroyConstantBuffer(ref ComputeBuffer bufferRef)
{
if (bufferRef == null)
return;
bufferRef.Release();
bufferRef = null;
}
private static void DestroyPass(ref Fsr3UpscalerPass pass)
{
if (pass == null)
return;
pass.Dispose();
pass = null;
}
}
}
Loading…
Cancel
Save