using Ghost.Core; using Ghost.Core.Graphics; using Ghost.Graphics.Core; using Misaki.HighPerformance.LowLevel.Collections; 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); /// /// Creates a new mesh from the specified vertex and index data. /// /// A UnsafeList containing the vertices that define the geometry of the mesh. Must contain at least one vertex. /// A UnsafeList containing the indices that specify how vertices are connected to form primitives. Must contain at least one index. /// An representing the newly created mesh. Handle CreateMesh(UnsafeList vertices, UnsafeList indices); /// /// Creates a new material instance using the specified shader. /// /// The identifier of the shader to associate with the new material. Cannot be null. /// An representing the newly created material. Handle CreateMaterial(Identifier shader); /// /// Creates a new shader and returns its unique identifier. /// /// An representing the newly created shader. /// The viewGroup containing the shader's properties and passes. Identifier CreateGraphicsShader(ShaderDescriptor descriptor); }