forked from Misaki/GhostEngine
Refactor core systems and improve resource management
- Updated dependencies, including `Misaki.HighPerformance` and `TerraFX.Interop`. - Refactored `Result` struct for better error handling and chaining. - Removed `Ptr<T>` struct as it was no longer necessary. - Enhanced `Win32Utility` with `Attach` and `Dispose` methods. - Improved `ProjectService` and `AppStateMachine` with `Result` integration. - Refactored `IShaderCompiler` to support SPIR-V cross-compilation and pass-level compilation. - Standardized Direct3D12 resource management with `UniquePtr` and added `D3D12Object` base class. - Improved shader reflection validation and pipeline creation in `D3D12PipelineLibrary`. - Updated `SDLCompiler` for better error handling during shader generation. - Enhanced logging, debugging, and code readability across the codebase. - Performed general code cleanup, including unused namespace removal and naming consistency.
This commit is contained in:
132
Ghost.Graphics/D3D12/D3D12Object.cs
Normal file
132
Ghost.Graphics/D3D12/D3D12Object.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using Ghost.Core.Utilities;
|
||||
using Ghost.Graphics.D3D12.Utilities;
|
||||
using Ghost.Graphics.RHI;
|
||||
using Misaki.HighPerformance.LowLevel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace Ghost.Graphics.D3D12;
|
||||
|
||||
internal abstract class D3D12RHIObject : IRHIObject
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
}
|
||||
|
||||
internal abstract unsafe class D3D12Object<T> : IRHIObject, IDisposable
|
||||
where T : unmanaged, ID3D12Object.Interface
|
||||
{
|
||||
private bool _disposed;
|
||||
private string _name = string.Empty;
|
||||
|
||||
protected UniquePtr<T> nativeObject;
|
||||
|
||||
protected bool Disposed => _disposed;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set
|
||||
{
|
||||
if (_name == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_name = value;
|
||||
if (nativeObject.Get() != null)
|
||||
{
|
||||
nativeObject.Get()->SetName(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~D3D12Object()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected void ThrowIfDisposed()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nativeObject.Dispose();
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal abstract class IUnknownObject<T> : IRHIObject, IDisposable
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
private bool _disposed;
|
||||
private string _name = string.Empty;
|
||||
|
||||
protected UniquePtr<T> nativeObject;
|
||||
|
||||
protected bool Disposed => _disposed;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set
|
||||
{
|
||||
if (_name == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_name = value;
|
||||
}
|
||||
}
|
||||
|
||||
~IUnknownObject()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected void ThrowIfDisposed()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nativeObject.Dispose();
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user