forked from Misaki/GhostEngine
- Added new C# formatting rules in .editorconfig. - Introduced `IKeyType`, `Key<T>`, and `Ptr<T>` structs. - Updated `Result` and `Result<T>` for implicit conversions. - Added AOT compatibility to project files. - Introduced a `Camera` class and refactored namespaces. - Enhanced rendering with bindless support and pipeline state management. - Refactored `D3D12CommandBuffer` for new rendering features. - Improved `D3D12PipelineLibrary` with disk caching methods. - Added support for UAVs and raw buffers in `D3D12ResourceAllocator`. - Improved shader compilation and reflection in `D3D12ShaderCompiler`. - Refactored descriptor heap and swap chain initialization. - Added enums and structs for rendering configurations. - Expanded `ICommandBuffer` and `IPipelineLibrary` interfaces. - Updated `MeshRenderPass` to align with the new pipeline. - Consolidated namespaces and improved code maintainability.
103 lines
2.9 KiB
C#
103 lines
2.9 KiB
C#
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.Versioning;
|
|
using TerraFX.Interop.Windows;
|
|
|
|
namespace Ghost.Core.Utilities;
|
|
|
|
#if PLATEFORME_WIN64
|
|
[SupportedOSPlatform("windows10.0.19041.0")]
|
|
internal static unsafe class Win32Utility
|
|
{
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public readonly ref struct IID_PPV
|
|
{
|
|
public readonly Guid* iid;
|
|
public readonly void** ppv;
|
|
|
|
public IID_PPV(Guid* iid, void** ppv)
|
|
{
|
|
this.iid = iid;
|
|
this.ppv = ppv;
|
|
}
|
|
|
|
public void Deconstruct(out Guid* iid, out void** ppv)
|
|
{
|
|
iid = this.iid;
|
|
ppv = this.ppv;
|
|
}
|
|
}
|
|
|
|
public static Guid* IID_NULL
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get => (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in TerraFX.Interop.Windows.IID.IID_NULL));
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static IID_PPV IID_PPV_ARGS<T>(ComPtr<T> comPtr)
|
|
where T : unmanaged, IUnknown.Interface
|
|
{
|
|
return new IID_PPV(Windows.__uuidof<T>(), comPtr.PPV());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static IID_PPV IID_PPV_ARGS<T>(T** ppv)
|
|
where T : unmanaged, IUnknown.Interface
|
|
{
|
|
return new IID_PPV(Windows.__uuidof<T>(), (void**)ppv);
|
|
}
|
|
|
|
[Conditional("DEBUG")]
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void Assert(this HRESULT hr)
|
|
{
|
|
Debug.Assert(hr.SUCCEEDED, hr.ToString());
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void ThrowIfFailed(this HRESULT hr)
|
|
{
|
|
Windows.ThrowIfFailed(hr);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static Guid* IID<T>(this ComPtr<T> comPtr)
|
|
where T : unmanaged, IUnknown.Interface
|
|
{
|
|
return Windows.__uuidof<T>();
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void** PPV<T>(this ComPtr<T> comPtr)
|
|
where T : unmanaged, IUnknown.Interface
|
|
{
|
|
return (void**)comPtr.GetAddressOf();
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void** ReleaseAndGetVoidAddressOf<T>(this ComPtr<T> comPtr)
|
|
where T : unmanaged, IUnknown.Interface
|
|
{
|
|
return (void**)comPtr.ReleaseAndGetAddressOf();
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static ComPtr<T> Move<T>(ref this ComPtr<T> comPtr)
|
|
where T : unmanaged, IUnknown.Interface
|
|
{
|
|
var copy = default(ComPtr<T>);
|
|
comPtr.Swap(ref copy);
|
|
return copy;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool HasFlag<T>(this uint flags, T flag)
|
|
where T : Enum
|
|
{
|
|
return (flags & Unsafe.As<T, uint>(ref flag)) != 0;
|
|
}
|
|
}
|
|
#endif
|