using Ghost.Core;
namespace Ghost.Graphics.RHI;
public interface IResourceReleasable
{
///
/// A method to release GPU resources.
///
void ReleaseResource(IResourceDatabase database);
}
public struct ResourceBarrierData
{
public BarrierLayout layout;
public BarrierAccess access;
public BarrierSync sync;
public ResourceBarrierData(BarrierLayout layout, BarrierAccess access, BarrierSync sync)
{
this.layout = layout;
this.access = access;
this.sync = sync;
}
}
public enum BindlessAccess
{
ShaderResource,
ConstantBuffer,
UnorderedAccess,
}
// TODO: Consider adding methods for resource enumeration, statistics, and bulk operations.
// TODO: Consider adding async resource loading and streaming support.
public interface IResourceDatabase : IDisposable
{
/*
///
/// Imports an external unmanaged resource and returns a handle for use within the resource management system.
///
/// The space of the unmanaged resource pointer to import.
/// A pointer to the external unmanaged resource to be imported. Must remain valid for the duration of the resource's usage.
/// The initial state to assign to the imported resource.
/// A handle representing the imported resource, which can be used for subsequent operations.
unsafe Handle ImportExternalResource(T resourcePtr, ResourceState initialState, string? name = null)
where T : unmanaged;
*/
///
/// Checks if a resource with the specified handle exists in the database.
///
/// The handle of the resource to check for existence.
bool HasResource(Handle handle);
///
/// Retrieves the current barrier data of the specified resource.
///
/// The handle that uniquely identifies the resource.
/// A ResourceBarrierData value representing the current barrier state.
Result GetResourceBarrierData(Handle handle);
///
/// Sets the barrier data of the specified resource handle.
///
/// The handle that identifies the resource.
/// The new barrier data.
/// An Error indicating the success or failure of the operation.
Error SetResourceBarrierData(Handle handle, ResourceBarrierData data);
///
/// Retrieves the description of a GPU resource associated with the specified handle.
///
/// A handle that identifies the GPU resource for which to obtain the description. Must reference a valid resource.
/// A ResourceDesc structure containing details about the specified GPU resource.
Result GetResourceDescription(Handle handle);
///
/// Retrieves the bindless index associated with the specified GPU resource handle.
///
/// A handle to the GPU resource for which to obtain the bindless index. Must reference a valid, currently registered resource.
/// The type of bindless access for which to obtain the index.
/// The bindless index corresponding to the specified GPU resource handle. ~0 if the resource does not support bindless access or is not found.
uint GetBindlessIndex(Handle handle, BindlessAccess access = BindlessAccess.ShaderResource);
///
/// Retrieves the name of the GPU resource associated with the specified handle.
///
///
/// You should only use this method in debug builds or inside engine editor.
///
/// A handle to the GPU resource for which to obtain the name. Must reference a valid resource.
/// The name of the GPU resource associated with the specified handle, or null if the resource does not have a name.
string? GetResourceName(Handle handle);
///
/// Releases the GPU resource associated with the specified handle, freeing any resources allocated to it.
///
/// The handle of the resource to be removed.
void ReleaseResource(Handle handle);
///
/// Releases the GPU resource associated with the specified handle immediately, freeing any resources allocated to it.
///
/// The handle of the resource to be removed.
void ReleaseResourceImmediately(Handle handle);
///
/// Retrieves an existing sampler identifier that matches the specified description, or creates a new one if none
/// exists.
///
/// A read-only reference to a structure that defines the properties of the sampler to retrieve or create.
/// An integer identifier to associate with the sampler.
/// An representing the sampler that matches the specified description.
/// If a matching sampler does not exist, a new sampler is created and its identifier is returned.
Identifier AddSampler(ref readonly SamplerDesc desc, int id);
///
/// Determines whether a sampler with the specified identifier exists.
///
/// The identifier of the sampler to check for existence.
/// true if a sampler with the given identifier exists; otherwise, false.
bool TryGetSampler(ref readonly SamplerDesc desc, out Identifier id);
///
/// Releases the sampler associated with the specified identifier and frees any resources allocated to it.
///
/// The identifier of the sampler to release. Must reference a valid, existing sampler.
void ReleaseSampler(Identifier id);
///
/// Swaps the resources associated with the two specified handles, effectively exchanging their identities and all associated data.
///
/// The first handle whose associated resource is to be swapped.
/// The second handle whose associated resource is to be swapped.
/// An Error indicating the success or failure of the swap operation.
Error Swap(Handle handleA, Handle handleB);
}