You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
using System;
|
|
using System.Runtime.InteropServices;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
|
|
namespace FidelityFX
|
|
{
|
|
public abstract class FfxContextBase
|
|
{
|
|
protected static void DestroyPass<TPass>(ref TPass pass)
|
|
where TPass: class, IDisposable
|
|
{
|
|
if (pass == null)
|
|
return;
|
|
|
|
pass.Dispose();
|
|
pass = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convenience class for handling a constants buffer containing a single struct item.
|
|
/// This wraps the compute buffer and the value array, as well as providing easy access to both.
|
|
/// </summary>
|
|
protected class ConstantsBuffer<TConst>
|
|
where TConst: struct
|
|
{
|
|
private ComputeBuffer _computeBuffer;
|
|
|
|
private readonly TConst[] _constArray = { new TConst() };
|
|
public ref TConst Value => ref _constArray[0];
|
|
|
|
public void Create()
|
|
{
|
|
_computeBuffer = new ComputeBuffer(1, Marshal.SizeOf<TConst>(), ComputeBufferType.Constant);
|
|
}
|
|
|
|
public void UpdateBufferData(CommandBuffer commandBuffer)
|
|
{
|
|
commandBuffer.SetBufferData(_computeBuffer, _constArray);
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
if (_computeBuffer == null)
|
|
return;
|
|
|
|
_computeBuffer.Release();
|
|
_computeBuffer = null;
|
|
}
|
|
|
|
public static implicit operator ComputeBuffer(ConstantsBuffer<TConst> constants)
|
|
{
|
|
return constants._computeBuffer;
|
|
}
|
|
}
|
|
}
|
|
}
|