using System;
using System.Collections.Generic;
namespace UnityEngine.Rendering.RenderGraphModule
{
///
/// Helper class provided in the RenderGraphContext to all Render Passes.
/// It allows you to do temporary allocations of various objects during a Render Pass.
///
public sealed class RenderGraphObjectPool
{
// Only used to clear all existing pools at once from here when needed
static DynamicArray s_AllocatedPools = new DynamicArray();
// Non abstract class instead of an interface to store it in a DynamicArray
class SharedObjectPoolBase
{
public SharedObjectPoolBase() {}
public virtual void Clear() {}
}
class SharedObjectPool : SharedObjectPoolBase where T : class, new()
{
private static readonly Pool.ObjectPool s_Pool = AllocatePool();
private static Pool.ObjectPool AllocatePool()
{
var newPool = new Pool.ObjectPool(() => new T(), null, null);
// Storing instance to clear the static pool of the same type if needed
s_AllocatedPools.Add(new SharedObjectPool());
return newPool;
}
///
/// Clear the pool using SharedObjectPool instance.
///
///
public override void Clear()
{
s_Pool.Clear();
}
///
/// Get a new instance from the pool.
///
///
public static T Get() => s_Pool.Get();
///
/// Release an object to the pool.
///
/// instance to release.
public static void Release(T toRelease) => s_Pool.Release(toRelease);
}
Dictionary<(Type, int), Stack