using System;
using System.Collections.Generic;
namespace UnityEngine.Experimental.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
{
abstract class SharedObjectPoolBase
{
protected static List s_AllocatedPools = new List();
protected abstract void Clear();
public static void ClearAll()
{
foreach (var pool in s_AllocatedPools)
pool.Clear();
}
}
class SharedObjectPool : SharedObjectPoolBase where T : new()
{
Stack m_Pool = new Stack();
public T Get()
{
var result = m_Pool.Count == 0 ? new T() : m_Pool.Pop();
return result;
}
public void Release(T value)
{
m_Pool.Push(value);
}
static SharedObjectPool AllocatePool()
{
var pool = new SharedObjectPool();
s_AllocatedPools.Add(pool);
return pool;
}
override protected void Clear()
{
m_Pool.Clear();
}
static readonly Lazy> s_Instance = new Lazy>(AllocatePool);
public static SharedObjectPool sharedPool => s_Instance.Value;
}
Dictionary<(Type, int), Stack