Refactor render pipeline and resource management APIs
Split IFenceSynchronizer/IRenderSystem interfaces for clarity. Refactor D3D12GraphicsEngine to use IFenceSynchronizer. Update RenderGraph and context to use explicit resource manager/database/allocator references. Add multi-buffering methods to IRGBuilder (stub). Support history access for multi-frame resources. Remove legacy RenderPipelineBase; introduce IRenderPipelineSettings and sealed GhostRenderPipeline. Clean up resource aliasing and pool logic. Improve modularity and future extensibility.
This commit is contained in:
@@ -1,11 +1,65 @@
|
||||
using Ghost.Graphics.Core;
|
||||
using Ghost.Graphics.RenderGraphModule;
|
||||
using Ghost.Graphics.RHI;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ghost.Graphics.RenderPipeline;
|
||||
|
||||
public partial class GhostRenderPipeline : RenderPipelineBase
|
||||
public sealed class GhostRenderPipelineSettings : IRenderPipelineSettings
|
||||
{
|
||||
public override void Render(RenderContext ctx, ReadOnlySpan<RenderRequest> requests)
|
||||
public static IRenderPipeline CreatePipeline(IRenderSystem renderSystem)
|
||||
{
|
||||
return new GhostRenderPipeline(renderSystem);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe partial class GhostRenderPipeline : IRenderPipeline
|
||||
{
|
||||
private readonly RenderGraph _renderGraph;
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
~GhostRenderPipeline()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected void ThrowIfDisposed()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
}
|
||||
|
||||
internal GhostRenderPipeline(IRenderSystem renderSystem)
|
||||
{
|
||||
_renderGraph = new RenderGraph(renderSystem.ResourceManager,
|
||||
renderSystem.GraphicsEngine.ResourceAllocator,
|
||||
renderSystem.GraphicsEngine.ResourceDatabase,
|
||||
renderSystem.GraphicsEngine.PipelineLibrary,
|
||||
renderSystem.GraphicsEngine.ShaderCompiler);
|
||||
}
|
||||
|
||||
public void Render(RenderContext ctx, ReadOnlySpan<RenderRequest> requests)
|
||||
{
|
||||
for (int i = 0; i < requests.Length; i++)
|
||||
{
|
||||
ref readonly var request = ref requests[i];
|
||||
|
||||
if (request.renderFunc != null)
|
||||
{
|
||||
request.renderFunc(in ctx, in request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
14
src/Runtime/Ghost.Graphics/RenderPipeline/IRenderPipeline.cs
Normal file
14
src/Runtime/Ghost.Graphics/RenderPipeline/IRenderPipeline.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Ghost.Graphics.Core;
|
||||
using Ghost.Graphics.RHI;
|
||||
|
||||
namespace Ghost.Graphics.RenderPipeline;
|
||||
|
||||
public interface IRenderPipelineSettings
|
||||
{
|
||||
static abstract IRenderPipeline CreatePipeline(IRenderSystem renderSystem);
|
||||
}
|
||||
|
||||
public interface IRenderPipeline : IDisposable
|
||||
{
|
||||
void Render(RenderContext ctx, ReadOnlySpan<RenderRequest> requests);
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using Ghost.Graphics.Core;
|
||||
using Ghost.Graphics.RHI;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ghost.Graphics.RenderPipeline;
|
||||
|
||||
public interface IRenderPipeline : IDisposable
|
||||
{
|
||||
void AddRenderList(RenderList renderList, string key);
|
||||
|
||||
void Render(RenderContext ctx, ReadOnlySpan<RenderRequest> requests);
|
||||
}
|
||||
|
||||
public abstract class RenderPipelineBase : IRenderPipeline
|
||||
{
|
||||
protected readonly Dictionary<string, RenderList> _renderLists = new();
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
~RenderPipelineBase()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected void ThrowIfDisposed()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
}
|
||||
|
||||
public void AddRenderList(RenderList renderList, string key)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
ref var existingList = ref CollectionsMarshal.GetValueRefOrAddDefault(_renderLists, key, out var exists);
|
||||
if (!exists)
|
||||
{
|
||||
existingList = renderList;
|
||||
}
|
||||
else
|
||||
{
|
||||
existingList.Append(renderList);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void Render(RenderContext ctx, ReadOnlySpan<RenderRequest> requests);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Dispose(true);
|
||||
|
||||
foreach (var list in _renderLists.Values)
|
||||
{
|
||||
list.Dispose();
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public virtual void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user