GhostEngine Render Graph: major refactor & Unity RG ref
- Major architectural refactor for performance, extensibility, and feature completeness: resource pooling, pass culling, aliasing, and compilation caching. - Introduces type-safe builder and context APIs, blackboard pattern, and unified resource management. - Adds detailed documentation and cleans up obsolete files and APIs. - Includes (commented) Unity Render Graph source for reference; not compiled, for parity and future extension.
This commit is contained in:
@@ -1,26 +1,43 @@
|
||||
namespace Ghost.RenderGraph.Concept;
|
||||
|
||||
public class RenderGraphBlackboard
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public sealed class RenderGraphBlackboard
|
||||
{
|
||||
private readonly Dictionary<Type, object> _data = new();
|
||||
private readonly Dictionary<Type, object> _data = new(16);
|
||||
|
||||
public void Add<T>(T data) where T : class
|
||||
/// <summary>
|
||||
/// Adds or updates pass data in the blackboard.
|
||||
/// </summary>
|
||||
public void Add<T>(T data) where T : class, IPassData
|
||||
{
|
||||
_data[typeof(T)] = data;
|
||||
var type = typeof(T);
|
||||
_data[type] = data;
|
||||
}
|
||||
|
||||
public T Get<T>() where T : class
|
||||
/// <summary>
|
||||
/// Retrieves pass data from the blackboard.
|
||||
/// </summary>
|
||||
public T Get<T>() where T : class, IPassData
|
||||
{
|
||||
if (_data.TryGetValue(typeof(T), out var data))
|
||||
var type = typeof(T);
|
||||
if (_data.TryGetValue(type, out var obj))
|
||||
{
|
||||
return (T)data;
|
||||
return (T)obj;
|
||||
}
|
||||
throw new KeyNotFoundException($"Data of type {typeof(T).Name} not found in blackboard.");
|
||||
throw new KeyNotFoundException($"Pass data of type {type.Name} not found in blackboard");
|
||||
}
|
||||
|
||||
public bool TryGet<T>(out T? data) where T : class
|
||||
/// <summary>
|
||||
/// Tries to get pass data from the blackboard.
|
||||
/// </summary>
|
||||
public bool TryGet<T>(out T? data) where T : class, IPassData
|
||||
{
|
||||
if (_data.TryGetValue(typeof(T), out var obj))
|
||||
var type = typeof(T);
|
||||
if (_data.TryGetValue(type, out var obj))
|
||||
{
|
||||
data = (T)obj;
|
||||
return true;
|
||||
@@ -29,6 +46,10 @@ public class RenderGraphBlackboard
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all data from the blackboard.
|
||||
/// Does not deallocate the backing dictionary to avoid allocations.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
_data.Clear();
|
||||
|
||||
Reference in New Issue
Block a user