using Ghost.Core; namespace Ghost.Graphics.RHI; public enum ResourceAllocationType { Default, Temporary, Suballocation, } public struct CreationOptions { public ResourceAllocationType AllocationType { get; set; } public Handle Heap { get; set; } public ulong Offset { get; set; } } public enum HeapType { Default, Upload, Readback } public enum HeapFlags { None = 0, AllowBuffers, AllowTextures, AllowRTAndDS, AlowBufferAndTexture, } public struct AllocationDesc { public ulong Size { get; set; } public ulong Alignment { get; set; } public HeapType HeapType { get; set; } public HeapFlags HeapFlags { get; set; } } public readonly struct ResourceSizeInfo { public ulong Size { get; init; } public ulong Alignment { get; init; } } public interface IResourceAllocator : IDisposable { ResourceSizeInfo GetSizeInfo(ResourceDesc desc); /// /// Allocates a block of memory on the GPU /// /// Allocation description /// Debug name of the allocation /// An point to the allocated memory Handle Allocate(ref readonly AllocationDesc desc, string name); /// /// Creates a texture resource /// /// Texture description /// Debug name of the resource /// Additional options of the resource allocation /// An point to the resource Handle CreateTexture(ref readonly TextureDesc desc, string name, CreationOptions options = default); /// /// Creates a render Target for off-screen rendering /// /// Render Target description /// Debug name of the resource /// Additional options of the resource allocation /// An point to the resource Handle CreateRenderTarget(ref readonly RenderTargetDesc desc, string name, CreationOptions options = default); /// /// Creates a buffer resource /// /// Buffer description /// Debug name of the resource /// Additional options of the resource allocation /// An point to the resource Handle CreateBuffer(ref readonly BufferDesc desc, string name, CreationOptions options = default); /// /// Creates a temporary upload buffer of the specified size in bytes. /// /// /// This method has been optimized for frequent calls during frame updates. It efficiently manages memory to minimize fragmentation and overhead. /// /// The size of the upload buffer to create, in bytes. /// The offset within the upload buffer where the allocation begins. /// An pointing to the created upload buffer. Handle CreateTempUploadBuffer(ulong sizeInBytes, out ulong offset); /// /// Creates a new sampler object using the specified sampler description. /// /// A read-only reference to a structure that defines the properties of the sampler to be created. /// An that uniquely identifies the created sampler object. Identifier CreateSampler(ref readonly SamplerDesc desc); }