namespace Ghost.Graphics.RenderGraphModule; /// /// Blackboard for sharing data between render passes. /// Uses a dictionary with type keys to store different pass data types. /// Avoids allocations by reusing the same dictionary across frames. /// public sealed class RenderGraphBlackboard { private readonly Dictionary _data = new(16); /// /// Adds or updates pass data in the blackboard. /// public void Add(T data) where T : class, IPassData { var type = typeof(T); _data[type] = data; } /// /// Retrieves pass data from the blackboard. /// public T Get() where T : class, IPassData { var type = typeof(T); if (_data.TryGetValue(type, out var obj)) { return (T)obj; } throw new KeyNotFoundException($"Pass data of type {type.Name} not found in blackboard"); } /// /// Tries to get pass data from the blackboard. /// public bool TryGet(out T? data) where T : class, IPassData { var type = typeof(T); if (_data.TryGetValue(type, out var obj)) { data = (T)obj; return true; } data = null; return false; } /// /// Clears all data from the blackboard. /// Does not deallocate the backing dictionary to avoid allocations. /// public void Clear() { _data.Clear(); } }