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.
165 lines
2.6 KiB
C#
165 lines
2.6 KiB
C#
using Ghost.Graphics.Data;
|
|
|
|
namespace Ghost.Graphics.RHI;
|
|
|
|
/// <summary>
|
|
/// Base interface for all graphics resources
|
|
/// </summary>
|
|
public interface IResource : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// Current resource state
|
|
/// </summary>
|
|
ResourceState CurrentState
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resource name for debugging
|
|
/// </summary>
|
|
string Name
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Size of the resource in bytes
|
|
/// </summary>
|
|
ulong Size
|
|
{
|
|
get;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Texture resource interface
|
|
/// </summary>
|
|
public interface ITexture : IResource
|
|
{
|
|
/// <summary>
|
|
/// Width of the texture in pixels
|
|
/// </summary>
|
|
uint Width
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Height of the texture in pixels
|
|
/// </summary>
|
|
uint Height
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Texture format
|
|
/// </summary>
|
|
TextureFormat Format
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Number of mip levels
|
|
/// </summary>
|
|
uint MipLevels
|
|
{
|
|
get;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Buffer resource interface
|
|
/// </summary>
|
|
public interface IBuffer : IResource
|
|
{
|
|
/// <summary>
|
|
/// Buffer usage type
|
|
/// </summary>
|
|
public BufferUsage Usage
|
|
{
|
|
get;
|
|
}
|
|
|
|
public BufferHandle Handle
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Maps the buffer for CPU access
|
|
/// </summary>
|
|
/// <returns>Pointer to mapped memory</returns>
|
|
public unsafe void* Map();
|
|
|
|
/// <summary>
|
|
/// Unmaps the buffer from CPU access
|
|
/// </summary>
|
|
public void Unmap();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Render target interface for rendering operations
|
|
/// Supports either color OR depth rendering, not both
|
|
/// </summary>
|
|
public interface IRenderTarget : ITexture
|
|
{
|
|
/// <summary>
|
|
/// Type of render target (color or depth)
|
|
/// </summary>
|
|
RenderTargetType Type
|
|
{
|
|
get;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Type of render target
|
|
/// </summary>
|
|
public enum RenderTargetType
|
|
{
|
|
Color,
|
|
Depth
|
|
}
|
|
|
|
/// <summary>
|
|
/// Texture format enumeration
|
|
/// </summary>
|
|
public enum TextureFormat
|
|
{
|
|
Unknown,
|
|
R8G8B8A8_UNorm,
|
|
B8G8R8A8_UNorm,
|
|
R16G16B16A16_Float,
|
|
R32G32B32A32_Float,
|
|
D24_UNorm_S8_UInt,
|
|
D32_Float
|
|
}
|
|
|
|
/// <summary>
|
|
/// Buffer usage flags
|
|
/// </summary>
|
|
[Flags]
|
|
public enum BufferUsage
|
|
{
|
|
None = 0,
|
|
Vertex = 1 << 0,
|
|
Index = 1 << 1,
|
|
Constant = 1 << 2,
|
|
Structured = 1 << 3,
|
|
Raw = 1 << 4,
|
|
Upload = 1 << 5,
|
|
Readback = 1 << 6,
|
|
IndirectArgument = 1 << 7,
|
|
|
|
ShaderResource = Vertex | Index | Constant
|
|
}
|
|
|
|
[Flags]
|
|
public enum BufferCreationFlags
|
|
{
|
|
None = 0,
|
|
Bindless = 1 << 0
|
|
} |