forked from Misaki/GhostEngine
Enhance graphics engine and code organization
Added `InternalsVisibleTo` attribute for "Ghost.Graphics" and "Ghost.Editor" in `AssemblyInfo.cs`. Added a new `EngineAssemblyAttribute` in `EngineAssemblyAttribute.cs`. Added a reference to `Misaki.HighPerformance.Unsafe` in `Ghost.Core.csproj`. Added a new `Bounds` struct to represent axis-aligned bounding boxes in `Bounds.cs`. Added new `Color32` and `Color128` structs for color representation in `Color.cs`. Changed the namespace from `Ghost.Editor.Controls` to `Ghost.Editor.Core.Controls` in multiple files. Changed the implicit conversion operator in `ConstPtr<T>` to use a more descriptive parameter name in `ConstPtr.cs`. Changed the `Mesh` class to use `Color128` instead of `Color32` for color representation. Enhanced the `TypeCache` class to load types from assemblies marked with `EngineAssemblyAttribute`. Enhanced the `ProjectService` class to improve the `GetAllProjectAsync` method by filtering out bad projects. Enhanced the `GraphicsPipeline` class to support both DX12 and D3D12 graphics APIs. Enhanced the `Shader` class to include methods for compiling HLSL shaders and managing root signatures. Enhanced the `MeshRenderPass` class to utilize the new shader compilation methods. Refactored the `AppStateMachine` class to use private fields instead of static fields for state management. Refactored the `ComponentDataView` class to use the new namespace and improve organization. Refactored project references in `Ghost.Graphics.csproj` to include new dependencies and remove outdated ones. Made various adjustments to ensure consistency and improve code quality across multiple files.
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
namespace Ghost.Graphics.Contracts;
|
||||
using Ghost.Graphics.Data;
|
||||
using Win32.Graphics.Direct3D12;
|
||||
|
||||
namespace Ghost.Graphics.Contracts;
|
||||
|
||||
public interface ICommandBuffer
|
||||
{
|
||||
public void DrawMesh(Mesh mesh);
|
||||
public void CopyResource(IResource dstResource, uint dstOffset, IResource srcResource, uint srcOffset, uint size);
|
||||
public void BarrierTransition(IResource resource, ResourceStates beforeState, ResourceStates afterState);
|
||||
}
|
||||
@@ -15,4 +15,6 @@ internal interface IGraphicsDevice : IDisposable
|
||||
}
|
||||
|
||||
public IRenderer CreateRenderer(in SwapChainPresenter swapChainSurface);
|
||||
public void RemoveRenderer(IRenderer renderer);
|
||||
public void InitializePendingRenderers();
|
||||
}
|
||||
5
Ghost.Graphics/Contracts/IPipelineResource.cs
Normal file
5
Ghost.Graphics/Contracts/IPipelineResource.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace Ghost.Graphics.Contracts;
|
||||
|
||||
internal interface IPipelineResource : IDisposable
|
||||
{
|
||||
}
|
||||
@@ -22,6 +22,7 @@ internal interface IRenderer : IDisposable
|
||||
/// </summary>
|
||||
public void ExecutePendingResize();
|
||||
|
||||
public void Initialize();
|
||||
/// <summary>
|
||||
/// Renders the current content to the output target.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,6 +13,11 @@ public interface IResource : IDisposable
|
||||
set;
|
||||
}
|
||||
|
||||
public bool TempResource
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public void SetData<T>(Span<T> data)
|
||||
where T : unmanaged;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
using Vortice.Direct3D12;
|
||||
using Win32.Graphics.Direct3D12;
|
||||
|
||||
namespace Ghost.Graphics.Contracts;
|
||||
|
||||
internal unsafe interface IResourceAllocator : IDisposable
|
||||
{
|
||||
public abstract static IResourceAllocator Create();
|
||||
public IResource CreateUploadBuffer(uint sizeInBytes, bool tempResource = false, ResourceFlags flags = ResourceFlags.None);
|
||||
public IResource CreateCopyDestinationBuffer(uint sizeInBytes, bool tempResource = false, ResourceFlags flags = ResourceFlags.None);
|
||||
|
||||
public IResource CreateUploadBuffer(uint sizeInBytes, ResourceFlags flags = ResourceFlags.None);
|
||||
public IResource CreateCopyDestinationBuffer(uint sizeInBytes, ResourceFlags flags = ResourceFlags.None);
|
||||
public void ReleaseTempResource();
|
||||
}
|
||||
@@ -2,23 +2,23 @@
|
||||
|
||||
namespace Ghost.Graphics.Contracts;
|
||||
|
||||
[ComImport]
|
||||
[Guid("63aad0b8-7c24-40ff-85a8-640d944cc325")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface ISwapChainPanelNativeRaw
|
||||
{
|
||||
// IUnknown: QueryInterface, AddRef, Release
|
||||
void QueryInterface(in Guid riid, out IntPtr ppvObject);
|
||||
uint AddRef();
|
||||
uint Release();
|
||||
|
||||
// SetSwapChain is the 4th slot in the vtable (0-based index 3)
|
||||
int SetSwapChain(IntPtr swapChainPtr);
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
|
||||
public unsafe readonly struct ISwapChainPanelNative
|
||||
{
|
||||
[ComImport]
|
||||
[Guid("63aad0b8-7c24-40ff-85a8-640d944cc325")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface Interface
|
||||
{
|
||||
// IUnknown: QueryInterface, AddRef, Release
|
||||
void QueryInterface(in Guid riid, out IntPtr ppvObject);
|
||||
uint AddRef();
|
||||
uint Release();
|
||||
|
||||
// SetSwapChain is the 4th slot in the vtable (0-based index 3)
|
||||
int SetSwapChain(IntPtr swapChainPtr);
|
||||
}
|
||||
|
||||
private readonly IntPtr _nativePtr;
|
||||
public readonly IntPtr NativePointer => _nativePtr;
|
||||
|
||||
@@ -34,7 +34,7 @@ public unsafe readonly struct ISwapChainPanelNative
|
||||
try
|
||||
{
|
||||
// Query for ISwapChainPanelNative
|
||||
var iid = typeof(ISwapChainPanelNativeRaw).GUID;
|
||||
var iid = typeof(Interface).GUID;
|
||||
var result = Marshal.QueryInterface(unknown, in iid, out var nativePtr);
|
||||
if (result < 0)
|
||||
{
|
||||
@@ -51,10 +51,9 @@ public unsafe readonly struct ISwapChainPanelNative
|
||||
|
||||
public int SetSwapChain(IntPtr swapChainPtr)
|
||||
{
|
||||
var raw = (ISwapChainPanelNativeRaw)Marshal.GetObjectForIUnknown(_nativePtr);
|
||||
var hr = raw.SetSwapChain(swapChainPtr);
|
||||
Marshal.ReleaseComObject(raw);
|
||||
return hr;
|
||||
var vtbl = *(void***)_nativePtr;
|
||||
var setSwapChainFn = (delegate* unmanaged<IntPtr, IntPtr, int>)vtbl[3];
|
||||
return setSwapChainFn(_nativePtr, swapChainPtr);
|
||||
}
|
||||
|
||||
public void Dispose() => Marshal.Release(_nativePtr);
|
||||
|
||||
Reference in New Issue
Block a user