forked from Misaki/GhostEngine
feat: Implement D3D12 resource factory and improve swap chain management
- Added D3D12ResourceFactory for creating render targets, textures, and buffers. - Enhanced D3D12SwapChain to manage back buffer render targets and provide access to them. - Updated D3D12Texture to utilize resource handles for better resource management. - Removed legacy ResourceAllocator and integrated improvements for resource handling. - Introduced new interfaces for resource factory and swap chain to streamline resource creation. - Added support for mip levels and texture dimensions in render target and texture descriptions. - Created new markdown files to document allocator and swap chain improvements.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using Ghost.Graphics.Data;
|
||||
using Ghost.Graphics.RHI;
|
||||
using Win32;
|
||||
using Win32.Graphics.Direct3D12;
|
||||
|
||||
namespace Ghost.Graphics.D3D12;
|
||||
|
||||
@@ -13,12 +12,27 @@ internal unsafe class D3D12RenderTarget : IRenderTarget
|
||||
private readonly D3D12Texture _target;
|
||||
private bool _disposed;
|
||||
|
||||
public uint Width { get; }
|
||||
public uint Height { get; }
|
||||
public RenderTargetType Type { get; }
|
||||
public uint Width
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public uint Height
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public RenderTargetType Type
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public ITexture Target => _target;
|
||||
|
||||
public D3D12RenderTarget(ComPtr<ID3D12Device14> device, D3D12DescriptorAllocator descriptorAllocator, RenderTargetDesc desc)
|
||||
/// <summary>
|
||||
/// Create a new render target with its own texture
|
||||
/// </summary>
|
||||
public D3D12RenderTarget(TextureHandle handle, ref readonly RenderTargetDesc desc)
|
||||
{
|
||||
Width = desc.Width;
|
||||
Height = desc.Height;
|
||||
@@ -26,13 +40,27 @@ internal unsafe class D3D12RenderTarget : IRenderTarget
|
||||
|
||||
// Create the target texture based on type
|
||||
var usage = Type == RenderTargetType.Color ? TextureUsage.RenderTarget : TextureUsage.DepthStencil;
|
||||
var textureDesc = new TextureDesc(desc.Width, desc.Height, desc.Format, 1, usage);
|
||||
_target = new D3D12Texture(device, textureDesc);
|
||||
var textureDesc = new TextureDesc(desc.Width, desc.Height, desc.Format, desc.Dimension, desc.MipLevels, usage);
|
||||
_target = new D3D12Texture(handle, in textureDesc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap an existing texture as a render target (for swap chain back buffers)
|
||||
/// </summary>
|
||||
public D3D12RenderTarget(D3D12Texture existingTexture, RenderTargetType type)
|
||||
{
|
||||
_target = existingTexture;
|
||||
Width = existingTexture.Width;
|
||||
Height = existingTexture.Height;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_target?.Dispose();
|
||||
_disposed = true;
|
||||
|
||||
Reference in New Issue
Block a user