Refactor descriptor handling and shader compilation

Refactored descriptor allocation and release logic by introducing `IDescriptorAllocator` and replacing `DescriptorHeapAllocator` with `D3D12DescriptorHeap`. Updated descriptor structs to include validation properties and improved memory management with `ReadOnlySpan`.

Enhanced shader compilation by introducing `ShaderStage` and `CompilerVersion` enums, enabling more flexible and maintainable shader handling.

Refactored `Mesh` to use `IBuffer` for vertex and index buffers, added bindless descriptor support, and improved resource cleanup.

Updated `RenderSystem` and other components for better initialization, error handling, and disposal logic. General improvements to code readability and maintainability.
This commit is contained in:
2025-09-13 20:07:29 +09:00
parent 1dfed83e38
commit 74bb2ccda5
23 changed files with 561 additions and 403 deletions

View File

@@ -3,7 +3,7 @@ using Win32.Graphics.D3D12MemoryAllocator;
namespace Ghost.Graphics.Data;
public readonly struct ResourceHandle : IEquatable<ResourceHandle>, IDisposable
public readonly struct ResourceHandle : IEquatable<ResourceHandle>
{
private const int _INVALID_ID = -1;
@@ -20,17 +20,6 @@ public readonly struct ResourceHandle : IEquatable<ResourceHandle>, IDisposable
public bool IsValid => id != _INVALID_ID && generation >= 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Allocation GetAllocation()
{
if (!IsValid)
{
throw new InvalidOperationException("Cannot get allocation from an invalid AllocationHandle.");
}
return GraphicsPipeline.ResourceAllocator.GetResource(this);
}
public bool Equals(ResourceHandle other)
{
return id == other.id && generation == other.generation;
@@ -49,21 +38,6 @@ public readonly struct ResourceHandle : IEquatable<ResourceHandle>, IDisposable
return obj is ResourceHandle handle && Equals(handle);
}
public void Dispose()
{
GraphicsPipeline.ResourceAllocator.ReleaseResource(this);
}
public static implicit operator Allocation(ResourceHandle handle)
{
if (!handle.IsValid)
{
throw new InvalidOperationException("Cannot convert an invalid AllocationHandle to Allocation.");
}
return handle.GetAllocation();
}
public static bool operator ==(ResourceHandle left, ResourceHandle right)
{
return left.Equals(right);
@@ -75,7 +49,7 @@ public readonly struct ResourceHandle : IEquatable<ResourceHandle>, IDisposable
}
}
public readonly struct TextureHandle : IEquatable<TextureHandle>, IDisposable
public readonly struct TextureHandle : IEquatable<TextureHandle>
{
private readonly ResourceHandle _resourceHandle;
@@ -104,11 +78,6 @@ public readonly struct TextureHandle : IEquatable<TextureHandle>, IDisposable
return _resourceHandle.GetHashCode();
}
public void Dispose()
{
_resourceHandle.Dispose();
}
public static bool operator ==(TextureHandle left, TextureHandle right)
{
return left.Equals(right);
@@ -120,16 +89,26 @@ public readonly struct TextureHandle : IEquatable<TextureHandle>, IDisposable
}
}
public readonly struct BufferHandle : IEquatable<BufferHandle>, IDisposable
public readonly struct BufferHandle : IEquatable<BufferHandle>
{
private readonly ResourceHandle _resourceHandle;
private readonly BindlessDescriptor _bindlessDescriptor;
public static BufferHandle Invalid => new(ResourceHandle.Invalid);
public ResourceHandle ResourceHandle => _resourceHandle;
public static BufferHandle Invalid => new(ResourceHandle.Invalid);
public BindlessDescriptor BindlessDescriptor => _bindlessDescriptor;
internal BufferHandle(ResourceHandle resourceHandle)
{
_resourceHandle = resourceHandle;
_bindlessDescriptor = BindlessDescriptor.Invalid;
}
internal BufferHandle(ResourceHandle resourceHandle, BindlessDescriptor descriptor)
{
_resourceHandle = resourceHandle;
_bindlessDescriptor = descriptor;
}
public bool IsValid => _resourceHandle.IsValid;
@@ -149,11 +128,6 @@ public readonly struct BufferHandle : IEquatable<BufferHandle>, IDisposable
return _resourceHandle.GetHashCode();
}
public void Dispose()
{
_resourceHandle.Dispose();
}
public static bool operator ==(BufferHandle left, BufferHandle right)
{
return left.Equals(right);