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

@@ -758,6 +758,15 @@ public struct SwapChainDesc
get; set;
}
public float ScaleX
{
get; set;
}
public float ScaleY
{
get; set;
}
/// <summary>
/// Back buffer Format

View File

@@ -0,0 +1,6 @@
namespace Ghost.Graphics.RHI;
public interface ICommandAllocator : IDisposable
{
void Reset();
}

View File

@@ -35,7 +35,7 @@ public interface ICommandBuffer : IDisposable
/// <summary>
/// Begins recording commands into this command buffer
/// </summary>
void Begin();
void Begin(ICommandAllocator allocator);
/// <summary>
/// Ends recording commands and prepares for submission

View File

@@ -30,10 +30,32 @@ public interface IGraphicsEngine : IDisposable
get;
}
/// <summary>
/// Creates a new instance of an object that implements the IRenderer interface.
/// </summary>
/// <returns>An object that provides rendering functionality through the IRenderer interface.</returns>
IRenderer CreateRenderer();
/// <summary>
/// Removes the specified renderer from the collection of active renderers.
/// </summary>
/// <param name="renderer">The renderer instance to remove. Cannot be null.</param>
void RemoveRenderer(IRenderer renderer);
/// <summary>
/// Removes all registered renderers from the collection.
/// </summary>
/// <remarks>Call this method to reset the renderer collection to an empty state. After calling this
/// method, no renderers will be available until new ones are added.</remarks>
void ClearRenderers();
/// <summary>
/// Creates a new command allocator for the specified command buffer type.
/// </summary>
/// <param name="type">The type of command buffer for which to create the allocator. The default is CommandBufferType.Graphics.</param>
/// <returns>An <see cref="ICommandAllocator"/> instance configured for the specified command buffer type.</returns>
ICommandAllocator CreateCommandAllocator(CommandBufferType type = CommandBufferType.Graphics);
/// <summary>
/// Creates a command buffer for recording rendering commands
/// </summary>
@@ -51,5 +73,7 @@ public interface IGraphicsEngine : IDisposable
/// <summary>
/// Renders the current frame.
/// </summary>
void RenderFrame(ICommandBuffer commandBuffer);
/// <param name="commandAllocator">Command allocator to use for rendering</param>
/// <returns>Result of the rendering operation</returns>
Result RenderFrame(ICommandAllocator commandAllocator);
}

View File

@@ -1,5 +1,5 @@
using Ghost.Core;
using Ghost.Graphics.Core;
using Ghost.Graphics.Contracts;
namespace Ghost.Graphics.RHI;
@@ -8,21 +8,15 @@ namespace Ghost.Graphics.RHI;
/// </summary>
public interface IRenderer : IDisposable
{
Handle<Texture> RenderTarget
IRenderTargetStrategy? RenderTargetStrategy
{
get;
get; set;
}
/// <summary>
/// Sets the render Target for this renderer
/// </summary>
/// <param name="renderTarget">Render Target to render into</param>
public void SetRenderTarget(Handle<Texture> renderTarget);
/// <summary>
/// Renders a frame
/// </summary>
/// <param name="commandBuffer">Command buffer to record rendering commands into</param>
/// <param name="commandAllocator">Command allocator to use for rendering</param>
/// <returns>Result of the rendering operation</returns>
public Result Render(ICommandBuffer commandBuffer);
}
Result Render(ICommandAllocator commandAllocator);
}

View File

@@ -11,7 +11,7 @@ public interface ISwapChain : IDisposable
/// <summary>
/// Width of the swap chain back buffers
/// </summary>
public uint Width
uint Width
{
get;
}
@@ -19,7 +19,23 @@ public interface ISwapChain : IDisposable
/// <summary>
/// Height of the swap chain back buffers
/// </summary>
public uint Height
uint Height
{
get;
}
/// <summary>
/// Gets the horizontal scaling factor applied to the object. This is used for DPI scaling.
/// </summary>
float ScaleX
{
get;
}
/// <summary>
/// Gets the vertical scale factor applied to the object. This is used for DPI scaling.
/// </summary>
float ScaleY
{
get;
}
@@ -28,18 +44,31 @@ public interface ISwapChain : IDisposable
/// Gets the current back buffer texture
/// </summary>
/// <returns>Current back buffer texture</returns>
public Handle<Texture> GetCurrentBackBuffer();
Handle<Texture> GetCurrentBackBuffer();
/// <summary>
/// Gets all back buffer textures
/// </summary>
/// <returns>All back buffer textures</returns>
ReadOnlySpan<Handle<Texture>> GetBackBuffers();
/// <summary>
/// Presents the rendered frame
/// </summary>
/// <param name="vsync">Enable vertical synchronization</param>
public void Present(bool vsync = true);
void Present(bool vsync = true);
/// <summary>
/// Resizes the swap chain back buffers
/// </summary>
/// <param name="width">New Width</param>
/// <param name="height">New Height</param>
public void Resize(uint width, uint height);
void Resize(uint width, uint height);
/// <summary>
/// Sets the horizontal and vertical scaling factors for the object.
/// </summary>
/// <param name="scaleX">The factor by which to scale the object along the X-axis.</param>
/// <param name="scaleY">The factor by which to scale the object along the Y-axis.</param>
void SetScale(float scaleX, float scaleY);
}