feat(wrapper): span-based interop, resource API refactor
Refactored native wrappers to use ReadOnlySpan<T> for pointer parameters, improving .NET safety and interop. Enhanced wrapper generator with $TYPE and prefix/suffix-based parameter remapping. Added platform-specific native library loading for meshoptimizer, nvtt, and ufbx. Updated D3D12GraphicsEngineFactory for native DLL resolution and removed redundant logic from UnitTestApp. Changed RenderGraphBuilder's resource extraction API to use QueryTextureExtraction/QueryBufferExtraction with explicit handles and flags. Removed IRenderer and D3D12Renderer, moving RenderContext to RenderPipeline. Improved mesh loading, resource management, and updated test shader conventions. Updated project references, build settings, and added launchSettings.json for tooling. BREAKING CHANGE: Native wrapper APIs now use ReadOnlySpan<T> instead of pointers. RenderGraphBuilder resource extraction API has changed. IRenderer and D3D12Renderer have been removed.
This commit is contained in:
@@ -91,7 +91,6 @@ public partial class EntityQueryTest : ITest
|
||||
{
|
||||
_world.Dispose();
|
||||
_jobScheduler.Dispose();
|
||||
JobScheduler.ReleaseTempAllocator();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ public unsafe partial class TestRenderPipeline : IRenderPipeline
|
||||
{
|
||||
private class MeshletDebugPassData
|
||||
{
|
||||
public Identifier<RGTexture> depth;
|
||||
public Identifier<RGTexture> backbuffer;
|
||||
public RenderList renderList;
|
||||
public Handle<Material> material;
|
||||
@@ -202,7 +203,7 @@ public unsafe partial class TestRenderPipeline : IRenderPipeline
|
||||
|
||||
var m_11 = 1.0f / math.tan(vfovF * 0.5f);
|
||||
var m_00 = m_11 / aspectScreen;
|
||||
var m_22 = -request.view.farClipPlane / (request.view.farClipPlane - request.view.nearClipPlane);
|
||||
var m_22 = request.view.farClipPlane / (request.view.farClipPlane - request.view.nearClipPlane);
|
||||
var m_23 = -(request.view.farClipPlane * request.view.nearClipPlane) / (request.view.farClipPlane - request.view.nearClipPlane);
|
||||
|
||||
var projectionMatrix = new float4x4
|
||||
@@ -210,7 +211,7 @@ public unsafe partial class TestRenderPipeline : IRenderPipeline
|
||||
m_00, 0, 0, 0,
|
||||
0, m_11, 0, 0,
|
||||
0, 0, m_22, m_23,
|
||||
0, 0, -1, 0
|
||||
0, 0, 1, 0
|
||||
);
|
||||
|
||||
//var vp = math.mul(projectionMatrix, viewMatrix);
|
||||
@@ -341,12 +342,13 @@ public unsafe partial class TestRenderPipeline : IRenderPipeline
|
||||
}
|
||||
}
|
||||
|
||||
// FIX: We still not change our root signature layout yet.
|
||||
|
||||
private void MeshletDebugPass(Identifier<RGTexture> backbuffer, RenderList renderList, uint globalIndex, uint viewIndex, uint instanceBuffer)
|
||||
{
|
||||
using (var builder = _renderGraph.AddRasterRenderPass<MeshletDebugPassData>("Meshlet Debug Pass", out var passData))
|
||||
{
|
||||
var depth = builder.CreateTexture(RGTextureDesc.RelativeDepth(1.0f), "Depth Texture");
|
||||
|
||||
passData.depth = depth;
|
||||
passData.backbuffer = backbuffer;
|
||||
passData.renderList = renderList;
|
||||
passData.globalIndex = globalIndex;
|
||||
@@ -355,6 +357,8 @@ public unsafe partial class TestRenderPipeline : IRenderPipeline
|
||||
passData.material = _meshletMaterial;
|
||||
|
||||
builder.SetColorAttachment(backbuffer, 0);
|
||||
builder.SetDepthAttachment(depth);
|
||||
|
||||
builder.SetRenderFunc<MeshletDebugPassData>(static (data, ctx)=>
|
||||
{
|
||||
ctx.SetGlobalData(data.globalIndex, data.viewIndex);
|
||||
|
||||
@@ -25,40 +25,12 @@ public partial class UnitTestApp : Application
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private static void LoadDll()
|
||||
{
|
||||
var currentDir = AppContext.BaseDirectory;
|
||||
var platform = OperatingSystem.IsWindows() ? "win" :
|
||||
OperatingSystem.IsLinux() ? "linux" :
|
||||
OperatingSystem.IsMacOS() ? "osx" : "unknown";
|
||||
var arch = Environment.Is64BitProcess ? "x64" : "x86";
|
||||
var nativeDllDir = Path.Combine(currentDir, "runtimes", platform + "-" + arch, "native");
|
||||
if (Directory.Exists(nativeDllDir))
|
||||
{
|
||||
foreach (var dll in Directory.EnumerateFiles(nativeDllDir, "*.dll"))
|
||||
{
|
||||
NativeLibrary.Load(dll);
|
||||
}
|
||||
}
|
||||
//NativeLibrary.SetDllImportResolver(typeof(UnitTestApp).Assembly, (libraryName, assembly, searchPath) =>
|
||||
//{
|
||||
// if (libraryName == "dxcompiler")
|
||||
// {
|
||||
// NativeLibrary.Load(Path.Combine(nativeDllDir, "dxil.dll"));
|
||||
// }
|
||||
|
||||
// return IntPtr.Zero;
|
||||
//});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the application is launched.
|
||||
/// </summary>
|
||||
/// <param name="args">Details about the launch request and process.</param>
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
LoadDll();
|
||||
|
||||
_window = new GraphicsTestWindow();
|
||||
_window.Activate();
|
||||
|
||||
|
||||
@@ -80,15 +80,15 @@ internal static class MeshUtility
|
||||
continue;
|
||||
}
|
||||
|
||||
var maxScratchIndices = (uint)(pMesh->max_face_triangles * 3u);
|
||||
var maxScratchIndices = (int)(pMesh->max_face_triangles * 3u);
|
||||
|
||||
using var triIndicesArray = new UnsafeArray<uint>((int)maxScratchIndices, scope1.AllocationHandle);
|
||||
using var triIndicesArray = new UnsafeArray<uint>(maxScratchIndices, scope1.AllocationHandle);
|
||||
|
||||
for (var j = 0u; j < pMesh->num_faces; j++)
|
||||
{
|
||||
var face = pMesh->faces.data[j];
|
||||
|
||||
var numTris = UfbxApi.TriangulateFace((uint*)triIndicesArray.GetUnsafePtr(), maxScratchIndices, pMesh, face);
|
||||
var numTris = UfbxApi.TriangulateFace(triIndicesArray.AsSpan(0, maxScratchIndices), pMesh, face);
|
||||
|
||||
var totalIndices = numTris * 3;
|
||||
for (var k = 0; k < totalIndices; k++)
|
||||
@@ -147,13 +147,13 @@ internal static class MeshUtility
|
||||
vertex_size = (nuint)sizeof(Vertex)
|
||||
};
|
||||
|
||||
var numUniqueVertices = stream.GenerateIndices(1, (uint*)weldedIndices.GetUnsafePtr(), (nuint)weldedIndices.Count, null, &error);
|
||||
var numUniqueVertices = UfbxApi.GenerateIndices([stream], weldedIndices, null, &error);
|
||||
if (numUniqueVertices == 0 && error.type != ufbx_error_type.UFBX_ERROR_NONE)
|
||||
{
|
||||
return Result.Failure($"Welding failed: {error.description}");
|
||||
}
|
||||
|
||||
MeshOptApi.OptimizeVertexCache((uint*)cachedIndices.GetUnsafePtr(), (uint*)weldedIndices.GetUnsafePtr(), numIndices, numIndices);
|
||||
MeshOptApi.OptimizeVertexCache((uint*)cachedIndices.GetUnsafePtr(), (uint*)weldedIndices.GetUnsafePtr(), numIndices, numUniqueVertices);
|
||||
|
||||
vertices = new UnsafeList<Vertex>((int)numUniqueVertices, allocator);
|
||||
indices = new UnsafeList<uint>((int)numIndices, allocator);
|
||||
@@ -165,11 +165,11 @@ internal static class MeshUtility
|
||||
MemoryUtility.MemCpy(indices.GetUnsafePtr(), cachedIndices.GetUnsafePtr(), numIndices * sizeof(uint));
|
||||
indices.UnsafeSetCount((int)numIndices);
|
||||
|
||||
if (needComputeNormals)
|
||||
{
|
||||
MeshBuilder.ComputeNormal(vertices, indices);
|
||||
MeshBuilder.ComputeTangents(vertices, indices);
|
||||
}
|
||||
//if (needComputeNormals)
|
||||
//{
|
||||
// MeshBuilder.ComputeNormal(vertices, indices);
|
||||
// MeshBuilder.ComputeTangents(vertices, indices);
|
||||
//}
|
||||
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using Ghost.Graphics.Utilities;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Misaki.HighPerformance.Jobs;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.Mathematics;
|
||||
|
||||
@@ -19,6 +20,7 @@ public sealed partial class GraphicsTestWindow : Window
|
||||
{
|
||||
private RenderSystem? _renderSystem;
|
||||
private ISwapChain? _swapChain;
|
||||
private JobScheduler _jobScheduler;
|
||||
private World? _world;
|
||||
|
||||
private Handle<Mesh> _meshHandle;
|
||||
@@ -43,6 +45,8 @@ public sealed partial class GraphicsTestWindow : Window
|
||||
};
|
||||
|
||||
AllocationManager.Initialize(opts);
|
||||
|
||||
_jobScheduler = new JobScheduler(Environment.ProcessorCount - 1);
|
||||
}
|
||||
|
||||
private void GraphicsTestWindow_Activated(object sender, WindowActivatedEventArgs e)
|
||||
@@ -75,7 +79,7 @@ public sealed partial class GraphicsTestWindow : Window
|
||||
_renderSystem.Start();
|
||||
|
||||
// ECS Setup
|
||||
_world = World.Create();
|
||||
_world = World.Create(_jobScheduler);
|
||||
_world.AddService(_renderSystem);
|
||||
|
||||
// Add Systems
|
||||
@@ -105,7 +109,7 @@ public sealed partial class GraphicsTestWindow : Window
|
||||
|
||||
_world.EntityManager.SetComponent(cameraEntity, new LocalToWorld
|
||||
{
|
||||
matrix = float4x4.TRS(new float3(0.0f, 1.0f, 5.0f), quaternion.EulerXYZ(new float3(0, 0, 0)), new float3(1.0f, 1.0f, 1.0f))
|
||||
matrix = float4x4.TRS(new float3(0.0f, 1.0f, -5.0f), quaternion.EulerXYZ(new float3(0, 0, 0)), float3.one)
|
||||
});
|
||||
|
||||
// Create Mesh Entity
|
||||
@@ -158,6 +162,7 @@ public sealed partial class GraphicsTestWindow : Window
|
||||
_renderSystem?.ResourceManager.ReleaseMesh(_meshHandle);
|
||||
|
||||
_swapChain?.Dispose();
|
||||
_jobScheduler.Dispose();
|
||||
_renderSystem?.Dispose();
|
||||
|
||||
AllocationManager.Dispose();
|
||||
|
||||
Reference in New Issue
Block a user