Refactor: add command allocator & render target strategies

Major refactor of graphics infrastructure:
- Introduce ICommandAllocator and D3D12CommandAllocator for explicit command buffer management.
- Change ICommandBuffer.Begin to require an allocator.
- Add IRenderTargetStrategy abstraction with swap chain and texture implementations.
- Update IRenderer to use RenderTargetStrategy instead of direct handle.
- Add DPI scaling support to swap chains (ScaleX/ScaleY, SetScale).
- RenderSystem now supports thread-safe swap chain resize requests.
- Remove persistent copy command buffer; use per-frame allocators.
- Make Logger public/static and clean up API visibility.
- Update .editorconfig and debug layer enablement.
These changes improve modularity, DPI-awareness, and future extensibility.
This commit is contained in:
2025-12-23 00:35:34 +09:00
parent d23e701f0a
commit aa3d9c749b
24 changed files with 456 additions and 242 deletions

View File

@@ -0,0 +1,62 @@
using Ghost.Core;
using Ghost.Graphics.Contracts;
using Ghost.Graphics.RHI;
namespace Ghost.Graphics.Core;
internal class SwapChainTargetStrategy : IRenderTargetStrategy
{
private readonly ISwapChain _swapChain;
public SwapChainTargetStrategy(ISwapChain swapChain)
{
_swapChain = swapChain;
}
public Handle<Texture> GetRenderTarget()
{
return _swapChain.GetCurrentBackBuffer();
}
public void BeginRender(ICommandBuffer cmd)
{
cmd.ResourceBarrier(GetRenderTarget().AsResource(), ResourceState.Present, ResourceState.RenderTarget);
}
public void EndRender(ICommandBuffer cmd)
{
cmd.ResourceBarrier(GetRenderTarget().AsResource(), ResourceState.RenderTarget, ResourceState.Present);
}
public void Present()
{
_swapChain.Present();
}
}
internal class TextureTargetStrategy : IRenderTargetStrategy
{
private readonly Handle<Texture> _texture;
public TextureTargetStrategy(Handle<Texture> texture)
{
_texture = texture;
}
public Handle<Texture> GetRenderTarget()
{
return _texture;
}
public void BeginRender(ICommandBuffer cmd)
{
}
public void EndRender(ICommandBuffer cmd)
{
}
public void Present()
{
}
}

View File

@@ -12,28 +12,18 @@ public readonly unsafe ref struct RenderingContext
{
private readonly IGraphicsEngine _engine;
private readonly ICommandBuffer _directCmd;
private readonly ICommandBuffer _copyCmd;
private readonly ICommandBuffer _computeCmd;
public ICommandBuffer DirectCommandBuffer => _directCmd;
public ICommandBuffer CopyCommandBuffer => _copyCmd;
public ICommandBuffer ComputeCommandBuffer => _computeCmd;
public IShaderCompiler ShaderCompiler => _engine.ShaderCompiler;
public IResourceAllocator ResourceAllocator => _engine.ResourceAllocator;
public IResourceDatabase ResourceDatabase => _engine.ResourceDatabase;
public IPipelineLibrary PipelineLibrary => _engine.PipelineLibrary;
internal RenderingContext(
IGraphicsEngine engine,
ICommandBuffer directCmd,
ICommandBuffer copyCmd,
ICommandBuffer computeCmd)
internal RenderingContext(IGraphicsEngine engine, ICommandBuffer directCmd)
{
_engine = engine;
_directCmd = directCmd;
_copyCmd = copyCmd;
_computeCmd = computeCmd;
}
public ICommandBuffer CrearteCommandBuffer(CommandBufferType type)

View File

@@ -1,5 +1,4 @@
using Ghost.Graphics.Contracts;
using Ghost.Graphics.Core;
namespace Ghost.Graphics.Core;