Added RenderPipelineBase

This commit is contained in:
2026-03-02 19:06:19 +09:00
parent 5e42d699c3
commit b8af6e8c3a
13 changed files with 338 additions and 32 deletions

View File

@@ -3,13 +3,9 @@ using Ghost.Graphics.RHI;
namespace Ghost.Graphics.RenderPipeline;
public partial class GhostRenderPipeline : IRenderPipeline
public partial class GhostRenderPipeline : RenderPipelineBase
{
public void Render(RenderContext ctx, ReadOnlySpan<RenderRequest> requests)
{
}
public void Dispose()
public override void Render(RenderContext ctx, ReadOnlySpan<RenderRequest> requests)
{
}
}

View File

@@ -1,9 +0,0 @@
using Ghost.Graphics.Core;
using Ghost.Graphics.RHI;
namespace Ghost.Graphics.RenderPipeline;
public interface IRenderPipeline : IDisposable
{
void Render(RenderContext ctx, ReadOnlySpan<RenderRequest> requests);
}

View File

@@ -0,0 +1,70 @@
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)
{
}
}