forked from Misaki/GhostEngine
Added a new `Ref<T>` struct for reference semantics. Added the `RenderGraph` system for managing rendering passes. Added the `RenderTexture` class for encapsulating GPU resources. Added `GraphicsBuffer` class for effective GPU resource management. Changed `CommandList` methods from public to internal for visibility control. Changed `IRenderPass` interface from internal to public for accessibility. Changed `GetData<T>()` in `ComponentObject.cs` to return `CompRef<T>`. Changed `GetComponent<T>()` in `EntityManager.cs` to return `CompRef<T>`. Changed `GetSingleton<T>()` in `World.cs` to use `CompRef<T>`. Changed `IQueryTypeParameter` to use `CompRef<T>` for consistency. Changed `QueryItem<T0>` and related structs to use `CompRef<T>`. Changed `Material` class to support bindless textures. Changed `Shader` class to support bindless rendering. Changed `Mesh` class to support bindless vertex and index buffer access. Updated documentation to reflect the new bindless rendering architecture.
75 lines
1.5 KiB
C#
75 lines
1.5 KiB
C#
using Ghost.Core;
|
|
using Ghost.Graphics.Data;
|
|
using System.Runtime.CompilerServices;
|
|
using Win32.Graphics.Direct3D12;
|
|
|
|
namespace Ghost.Graphics.D3D12;
|
|
|
|
public unsafe class GraphicsResource : IDisposable
|
|
{
|
|
private readonly ResourceHandle _handle;
|
|
private string _name = string.Empty;
|
|
|
|
internal ConstPtr<ID3D12Resource> NativeResource
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get => new(_handle.GetAllocation().Resource);
|
|
}
|
|
|
|
internal ulong GPUAddress
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get => NativeResource.Ptr->GetGPUVirtualAddress();
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get => _name;
|
|
set
|
|
{
|
|
_name = value;
|
|
NativeResource.Ptr->SetName(_name);
|
|
}
|
|
}
|
|
|
|
public bool TempResource
|
|
{
|
|
get;
|
|
}
|
|
|
|
public ulong Size => _handle.GetAllocation().Size;
|
|
|
|
internal GraphicsResource(in ResourceHandle handle, bool tempResource = false)
|
|
{
|
|
_handle = handle;
|
|
TempResource = tempResource;
|
|
}
|
|
|
|
~GraphicsResource()
|
|
{
|
|
DisposeInternal();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Throws an exception if the resource has been disposed.
|
|
/// </summary>
|
|
protected void ThrowIfDisposed()
|
|
{
|
|
ObjectDisposedException.ThrowIf(!_handle.IsValid, this);
|
|
}
|
|
|
|
internal void DisposeInternal()
|
|
{
|
|
_handle.Dispose();
|
|
}
|
|
|
|
public virtual void Dispose()
|
|
{
|
|
if (!TempResource)
|
|
{
|
|
DisposeInternal();
|
|
}
|
|
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
} |