namespace Ghost.Graphics.RHI; /// /// D3D12-style descriptor allocator interface /// public interface IDescriptorAllocator : IDisposable { /// /// Allocates a render target view descriptor /// /// RTV descriptor handle DescriptorHandle AllocateRTV(); /// /// Allocates multiple render target view descriptors /// /// Number of descriptors to allocate /// Array of RTV descriptor handles DescriptorHandle[] AllocateRTVs(uint count); /// /// Allocates a depth stencil view descriptor /// /// DSV descriptor handle DescriptorHandle AllocateDSV(); /// /// Allocates a shader resource view descriptor /// /// SRV descriptor handle DescriptorHandle AllocateSRV(); /// /// Allocates a sampler descriptor /// /// Sampler descriptor handle DescriptorHandle AllocateSampler(); /// /// Allocates a bindless descriptor for SM 6.6 rendering /// /// Bindless descriptor handle DescriptorHandle AllocateBindless(); /// /// Releases a render target view descriptor /// /// RTV descriptor to release void ReleaseRTV(DescriptorHandle handle); /// /// Releases a depth stencil view descriptor /// /// DSV descriptor to release void ReleaseDSV(DescriptorHandle handle); /// /// Releases a shader resource view descriptor /// /// SRV descriptor to release void ReleaseSRV(DescriptorHandle handle); /// /// Releases a sampler descriptor /// /// Sampler descriptor to release void ReleaseSampler(DescriptorHandle handle); /// /// Releases a bindless descriptor /// /// Bindless descriptor to release void ReleaseBindless(DescriptorHandle handle); } /// /// D3D12-style descriptor heap interface /// public interface IDescriptorHeap : IDisposable { /// /// Type of descriptors this heap contains /// DescriptorHeapType Type { get; } /// /// Maximum number of descriptors in this heap /// uint MaxDescriptors { get; } /// /// Whether this heap is shader visible /// bool IsShaderVisible { get; } /// /// Gets a CPU descriptor handle at the specified index /// /// Index of the descriptor /// CPU descriptor handle DescriptorHandle GetCPUHandle(uint index); /// /// Gets a GPU descriptor handle at the specified index /// /// Index of the descriptor /// GPU descriptor handle DescriptorHandle GetGPUHandle(uint index); } /// /// Descriptor handle for D3D12-style descriptor management /// public struct DescriptorHandle : IEquatable { public uint Index; public bool IsValid; public DescriptorHandle(uint index) { Index = index; IsValid = true; } public static DescriptorHandle Invalid => new() { Index = uint.MaxValue, IsValid = false }; public bool Equals(DescriptorHandle other) => Index == other.Index && IsValid == other.IsValid; public override bool Equals(object? obj) => obj is DescriptorHandle other && Equals(other); public override int GetHashCode() => HashCode.Combine(Index, IsValid); public static bool operator ==(DescriptorHandle left, DescriptorHandle right) => left.Equals(right); public static bool operator !=(DescriptorHandle left, DescriptorHandle right) => !left.Equals(right); } /// /// D3D12 descriptor heap types /// public enum DescriptorHeapType { CBV_SRV_UAV, Sampler, RTV, DSV }