Files
GhostEngine/Ghost.Graphics/D3D12/D3D12GraphicsEngine.cs
Misaki a39f377533 Refactor GPU resource management and rendering pipeline
- Introduced `Handle<T>` and `Identifier<T>` for lightweight, strongly-typed resource identifiers.
- Replaced `BitSet` with `UnsafeBitSet` for improved performance and memory safety.
- Refactored `Mesh` and `Material` into `MeshClass` and `MaterialClass` for better GPU resource handling.
- Added `D3D12ResourceDatabase` to centralize GPU resource tracking and lifecycle management.
- Updated `D3D12ShaderCompiler` to load shaders from disk and dynamically populate constant buffers and textures.
- Enhanced `ICommandBuffer` with new upload operations for buffers and textures.
- Refactored `Vertex` struct for simplified memory layout and better performance.
- Updated `MeshBuilder` and rendering logic to align with new resource and shader structures.
- Added `BindlessDescriptor` support to `TextureHandle` and `BufferHandle`.
- Removed unused classes and performed general cleanup.
- Updated unit tests and demos to reflect the new architecture.
2025-09-19 23:20:15 +09:00

100 lines
2.6 KiB
C#

using Ghost.Graphics.RHI;
namespace Ghost.Graphics.D3D12;
internal unsafe class D3D12GraphicsEngine : IGraphicsEngine
{
#if DEBUG
private readonly D3D12DebugLayer _debugLayer;
#endif
private readonly D3D12RenderDevice _device;
private readonly D3D12PipelineStateController _stateController;
private readonly D3D12DescriptorAllocator _descriptorAllocator;
private readonly D3D12ResourceDatabase _resourceDatabase;
private readonly D3D12ResourceAllocator _resourceAllocator;
private readonly D3D12CommandBuffer _copyCommandBuffer;
public IRenderDevice Device => _device;
public IResourceDatabase ResourceDatabase => _resourceDatabase;
public IResourceAllocator ResourceAllocator => _resourceAllocator;
public IPipelineStateController PipelineStateController => _stateController;
public D3D12GraphicsEngine(RenderSystem renderSystem)
{
#if DEBUG
_debugLayer = new();
#endif
_device = new();
_descriptorAllocator = new(_device);
_resourceDatabase = new(_descriptorAllocator);
_resourceAllocator = new(renderSystem, _device, _descriptorAllocator, _resourceDatabase);
_stateController = new(_device, _resourceDatabase);
_copyCommandBuffer = new(
_device,
_stateController,
_resourceDatabase,
_resourceAllocator,
_descriptorAllocator,
CommandBufferType.Copy);
}
~D3D12GraphicsEngine()
{
Dispose();
}
public IRenderer CreateRenderer()
{
return new D3D12Renderer(this, _resourceAllocator);
}
public ICommandBuffer CreateCommandBuffer(CommandBufferType type = CommandBufferType.Graphics)
{
return new D3D12CommandBuffer(
_device,
_stateController,
_resourceDatabase,
_resourceAllocator,
_descriptorAllocator,
type);
}
public ISwapChain CreateSwapChain(SwapChainDesc desc)
{
return new D3D12SwapChain(_device.DXGIFactory, ((D3D12CommandQueue)_device.ComputeQueue).NativeQueue, desc);
}
public void BeginFrame()
{
throw new NotImplementedException();
}
public void EndFrame()
{
throw new NotImplementedException();
}
public void Dispose()
{
_copyCommandBuffer.Dispose();
_stateController.Dispose();
_resourceAllocator.Dispose();
_resourceDatabase.Dispose();
_descriptorAllocator.Dispose();
_device.Dispose();
#if DEBUG
_debugLayer.Dispose();
#endif
GC.SuppressFinalize(this);
}
}