Add new interfaces and refactor rendering logic

Added a new `ConstPtr<T>` struct for type-safe pointers.
Added a new `ICommandBuffer` interface for resource copying.
Added a new `IRenderPass` interface to define render passes.
Added a new `IResource` interface for GPU resources.
Added a new `IResourceAllocator` interface for resource management.
Added a new `ISwapChainPanelNative` struct for native interactions.
Added a new `D3D12Utility` class for Direct3D 12 utilities.
Added a new package reference for `Vortice.Win32.Graphics.D3D12MemoryAllocator`.

Changed project file to allow unsafe code blocks.
Changed `Result` struct methods to improve clarity.
Changed error handling in `ProjectService` and `AssetDatabase` to use `Result.Failure()`.
Changed `launchSettings.json` to enable native debugging.
Changed rendering logic in `ScenePage.xaml.cs` to use `IRenderer`.
Changed `IGraphicsDevice` interface to include renderer properties.
Changed `IRenderView` to `IRenderer` and updated its methods.
Changed `Mesh` class to use the new `IResource` interface for buffers.
Changed `GraphicsAPI` enum to include a `None` value.
Changed various aspects of the `GraphicsPipeline` class for new architecture.

Removed the old `DX12RenderView` class and replaced it with `DX12Renderer`.
Removed unnecessary code in the `ResourceView` class.
This commit is contained in:
2025-06-30 13:50:06 +09:00
parent 8fd1222780
commit 300ae7251b
27 changed files with 765 additions and 486 deletions

View File

@@ -1,18 +1,23 @@
using Ghost.Graphics.Contracts;
using Ghost.Core;
using Ghost.Graphics.Contracts;
using Ghost.Graphics.Data;
using Ghost.Graphics.DX12;
using System.Runtime.CompilerServices;
namespace Ghost.Graphics;
public static class GraphicsPipeline
{
internal const int FRAME_COUNT = 2;
internal const int _FRAME_COUNT = 2;
private static IGraphicsDevice? _graphicsDevice;
private static IResourceAllocator? _resourceAllocator;
private static Thread? _renderThread;
private static bool _isRunning;
public static IGraphicsDevice GraphicsDevice
internal static IGraphicsDevice GraphicsDevice
{
get
{
@@ -20,26 +25,61 @@ public static class GraphicsPipeline
{
throw new InvalidOperationException("Graphics pipeline is not initialized.");
}
return _graphicsDevice;
}
}
internal static IResourceAllocator ResourceAllocator
{
get
{
if (_resourceAllocator == null)
{
throw new InvalidOperationException("Resource allocator is not initialized.");
}
return _resourceAllocator;
}
}
public static GraphicsAPI CurrentAPI
{
get;
private set;
}
internal static void Initialize(GraphicsAPI api)
{
_graphicsDevice = api switch
switch (api)
{
GraphicsAPI.DX12 => DX12.DX12GraphicsDevice.Create(),
_ => throw new NotSupportedException($"Graphics API {api} is not supported.")
};
case GraphicsAPI.DX12:
_graphicsDevice = new DX12GraphicsDevice();
_resourceAllocator = new DX12ResourceAllocator();
break;
default:
throw new NotSupportedException($"Graphics API {api} is not supported.");
}
_renderThread = new Thread(RenderLoop);
CurrentAPI = api;
}
private static void RenderLoop()
{
while (_isRunning)
{
GraphicsDevice.OnRender();
if (_graphicsDevice == null)
{
throw new ArgumentException("Renderer has been disposed or is not initialized.");
}
foreach (var renderer in _graphicsDevice.Renderers)
{
renderer.ExecutePendingResize();
renderer.Render();
}
}
}
@@ -70,8 +110,32 @@ public static class GraphicsPipeline
Stop();
_graphicsDevice?.Dispose();
_resourceAllocator?.Dispose();
_graphicsDevice = null;
_renderThread = null;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static T GetRenderer<T>()
where T : class, IGraphicsDevice
{
if (T.TargetAPI != CurrentAPI)
{
throw new InvalidOperationException($"No graphics device of type {typeof(T)} available for the current API.");
}
return Unsafe.As<T>(GraphicsDevice);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Result CheckAPI(GraphicsAPI expectedAPI)
{
if (CurrentAPI != expectedAPI)
{
return Result.Failure($"Expected API {expectedAPI}, but got {CurrentAPI}.");
}
return Result.Success();
}
}