Refactor render graph error handling and resource APIs

- RenderGraph.Compile/Execute now return Error for better failure detection; error handling is propagated throughout compiler and executor.
- Renamed ScheduleReleaseResource to ReleaseResource for clarity; updated all usages.
- ResourceManager now calls ReleaseResource directly on Mesh, Material, and Shader types.
- Camera exposes Actual/Virtual size properties and Render returns Error.
- RenderingContext now uses IResourceManager for mesh/resource ops.
- Replaced custom BinaryWriter with BufferWriter in RenderGraphHasher.
- Improved variable naming, interface signatures, and code formatting.
- Added Error extension for IsSuccess/IsFailure.
- Minor FMOD/native interop and test code cleanups.
- No breaking API changes except for new Error return values on some methods.
This commit is contained in:
2026-02-25 19:08:54 +09:00
parent 30090f84ab
commit 162b71f309
93 changed files with 537 additions and 593 deletions

View File

@@ -1,4 +1,3 @@
using System;
using System.Diagnostics;
namespace Ghost.Nvtt.Native

View File

@@ -1,4 +1,3 @@
using System;
using System.Diagnostics;
namespace Ghost.Nvtt.Native

View File

@@ -32,15 +32,15 @@ public sealed unsafe class NvttOutputOptionsHandle : IDisposable
private delegate void ErrorDelegate(Ghost.Nvtt.Native.NvttError error);
// Pinned delegate instances must stay alive as long as native code may call them.
private BeginImageDelegate? _beginImageDelegate;
private OutputDataDelegate? _outputDataDelegate;
private ErrorDelegate? _errorDelegate;
private BeginImageDelegate? _beginImageDelegate;
private OutputDataDelegate? _outputDataDelegate;
private ErrorDelegate? _errorDelegate;
// Managed user-facing callbacks.
private Action<int, int, int, int, int, int>? _beginImage;
private Func<nint, int, bool>? _outputData;
private Action? _endImage;
private Action<NvttError>? _errorHandler;
private Func<nint, int, bool>? _outputData;
private Action? _endImage;
private Action<NvttError>? _errorHandler;
// -------------------------------------------------------------------------
// Construction / destruction
@@ -58,7 +58,7 @@ public sealed unsafe class NvttOutputOptionsHandle : IDisposable
// Release delegate references so GC can collect them.
_beginImageDelegate = null;
_outputDataDelegate = null;
_errorDelegate = null;
_errorDelegate = null;
}
// -------------------------------------------------------------------------
@@ -142,7 +142,7 @@ public sealed unsafe class NvttOutputOptionsHandle : IDisposable
ThrowIfDisposed();
_beginImage = beginImage;
_outputData = outputData;
_endImage = endImage;
_endImage = endImage;
RebindOutputHandler();
}
@@ -173,13 +173,13 @@ public sealed unsafe class NvttOutputOptionsHandle : IDisposable
_outputDataDelegate = (data, size, lastChunk) =>
{
bool ok = outputData?.Invoke((nint)data, size) ?? true;
var ok = outputData?.Invoke((nint)data, size) ?? true;
return ok ? Ghost.Nvtt.Native.NvttBoolean.NVTT_True
: Ghost.Nvtt.Native.NvttBoolean.NVTT_False;
};
nint beginPtr = Marshal.GetFunctionPointerForDelegate(_beginImageDelegate);
nint outputPtr = Marshal.GetFunctionPointerForDelegate(_outputDataDelegate);
var beginPtr = Marshal.GetFunctionPointerForDelegate(_beginImageDelegate);
var outputPtr = Marshal.GetFunctionPointerForDelegate(_outputDataDelegate);
Api.nvttSetOutputOptionsOutputHandler(
_ptr,
@@ -193,7 +193,7 @@ public sealed unsafe class NvttOutputOptionsHandle : IDisposable
var handler = _errorHandler;
_errorDelegate = error => handler?.Invoke(error);
nint errorPtr = Marshal.GetFunctionPointerForDelegate(_errorDelegate);
var errorPtr = Marshal.GetFunctionPointerForDelegate(_errorDelegate);
Api.nvttSetOutputOptionsErrorHandler(
_ptr,
(delegate* unmanaged[Cdecl]<Ghost.Nvtt.Native.NvttError, void>)errorPtr);

View File

@@ -1,6 +1,3 @@
using Ghost.Nvtt.Native;
using System.Runtime.InteropServices;
namespace Ghost.Nvtt;
/// <summary>
@@ -20,7 +17,7 @@ public sealed unsafe class NvttSurfaceHandle : IDisposable
// -------------------------------------------------------------------------
// Construction / destruction
// -------------------------------------------------------------------------
public NvttSurfaceHandle() => _ptr = Api.nvttCreateSurface();
/// <summary>Wraps an existing raw pointer (takes ownership; will destroy on dispose).</summary>
@@ -150,8 +147,8 @@ public sealed unsafe class NvttSurfaceHandle : IDisposable
get
{
ThrowIfDisposed();
float* p = Api.nvttSurfaceData(_ptr);
int count = Width * Height * Depth * 4;
var p = Api.nvttSurfaceData(_ptr);
var count = Width * Height * Depth * 4;
return p == null ? Span<float>.Empty : new Span<float>(p, count);
}
}
@@ -163,8 +160,8 @@ public sealed unsafe class NvttSurfaceHandle : IDisposable
public Span<float> Channel(int index)
{
ThrowIfDisposed();
float* p = Api.nvttSurfaceChannel(_ptr, index);
int count = Width * Height * Depth;
var p = Api.nvttSurfaceChannel(_ptr, index);
var count = Width * Height * Depth;
return p == null ? Span<float>.Empty : new Span<float>(p, count);
}
@@ -205,7 +202,7 @@ public sealed unsafe class NvttSurfaceHandle : IDisposable
fixed (byte* p = utf8)
{
Ghost.Nvtt.Native.NvttBoolean nvAlpha;
bool ok = NvttInterop.ToBool(
var ok = NvttInterop.ToBool(
Api.nvttSurfaceLoad(_ptr, (sbyte*)p, &nvAlpha,
NvttInterop.ToNvtt(expectSigned), tc));
hasAlpha = NvttInterop.ToBool(nvAlpha);
@@ -221,7 +218,7 @@ public sealed unsafe class NvttSurfaceHandle : IDisposable
fixed (byte* p = data)
{
Ghost.Nvtt.Native.NvttBoolean nvAlpha;
bool ok = NvttInterop.ToBool(
var ok = NvttInterop.ToBool(
Api.nvttSurfaceLoadFromMemory(_ptr, p, (ulong)data.Length,
&nvAlpha, NvttInterop.ToNvtt(expectSigned), tc));
hasAlpha = NvttInterop.ToBool(nvAlpha);
@@ -363,7 +360,7 @@ public sealed unsafe class NvttSurfaceHandle : IDisposable
NvttTimingContext* tc = null)
{
ThrowIfDisposed();
float* color = stackalloc float[4] { r, g, b, a };
var color = stackalloc float[4] { r, g, b, a };
return NvttInterop.ToBool(
Api.nvttSurfaceBuildNextMipmapSolidColor(_ptr, color, tc));
}

View File

@@ -75,7 +75,7 @@ public sealed unsafe class NvttTimingContextHandle : IDisposable
fixed (byte* p = buf)
{
Api.nvttTimingContextGetRecordSafe(_ptr, index, (sbyte*)p, (nuint)buf.Length, &seconds);
string desc = NvttInterop.FromUtf8((sbyte*)p) ?? string.Empty;
var desc = NvttInterop.FromUtf8((sbyte*)p) ?? string.Empty;
return (desc, seconds);
}
}