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:
@@ -331,8 +331,8 @@ namespace Ghost.FMOD.Core
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PLUGINLIST
|
||||
{
|
||||
PLUGINTYPE type;
|
||||
IntPtr description;
|
||||
private PLUGINTYPE type;
|
||||
private IntPtr description;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
@@ -1396,8 +1396,7 @@ namespace Ghost.FMOD.Core
|
||||
// System information functions.
|
||||
public RESULT getVersion(out uint version)
|
||||
{
|
||||
uint buildnumber;
|
||||
return getVersion(out version, out buildnumber);
|
||||
return getVersion(out version, out var buildnumber);
|
||||
}
|
||||
public RESULT getVersion(out uint version, out uint buildnumber)
|
||||
{
|
||||
@@ -2189,7 +2188,7 @@ namespace Ghost.FMOD.Core
|
||||
/*
|
||||
'ChannelControl' API
|
||||
*/
|
||||
interface IChannelControl
|
||||
internal interface IChannelControl
|
||||
{
|
||||
RESULT getSystemObject(out System system);
|
||||
|
||||
@@ -3539,8 +3538,7 @@ namespace Ghost.FMOD.Core
|
||||
}
|
||||
public RESULT getParameterInfo(int index, out DSP_PARAMETER_DESC desc)
|
||||
{
|
||||
IntPtr descPtr;
|
||||
var result = FMOD5_DSP_GetParameterInfo(this.handle, index, out descPtr);
|
||||
var result = FMOD5_DSP_GetParameterInfo(this.handle, index, out var descPtr);
|
||||
desc = (DSP_PARAMETER_DESC)Marshal.PtrToStructure<DSP_PARAMETER_DESC>(descPtr);
|
||||
return result;
|
||||
}
|
||||
@@ -4060,7 +4058,7 @@ namespace Ghost.FMOD.Core
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct StringWrapper
|
||||
{
|
||||
IntPtr nativeUtf8Ptr;
|
||||
private IntPtr nativeUtf8Ptr;
|
||||
|
||||
public StringWrapper(IntPtr ptr)
|
||||
{
|
||||
@@ -4117,15 +4115,15 @@ namespace Ghost.FMOD.Core
|
||||
}
|
||||
}
|
||||
|
||||
static class StringHelper
|
||||
internal static class StringHelper
|
||||
{
|
||||
public class ThreadSafeEncoding : IDisposable
|
||||
{
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
byte[] encodedBuffer = new byte[128];
|
||||
char[] decodedBuffer = new char[128];
|
||||
bool inUse;
|
||||
GCHandle gcHandle;
|
||||
private UTF8Encoding encoding = new UTF8Encoding();
|
||||
private byte[] encodedBuffer = new byte[128];
|
||||
private char[] decodedBuffer = new char[128];
|
||||
private bool inUse;
|
||||
private GCHandle gcHandle;
|
||||
|
||||
public bool InUse()
|
||||
{
|
||||
@@ -4234,7 +4232,7 @@ namespace Ghost.FMOD.Core
|
||||
}
|
||||
}
|
||||
|
||||
static List<ThreadSafeEncoding> encoders = new List<ThreadSafeEncoding>(1);
|
||||
private static List<ThreadSafeEncoding> encoders = new List<ThreadSafeEncoding>(1);
|
||||
|
||||
public static ThreadSafeEncoding GetFreeHelper()
|
||||
{
|
||||
|
||||
@@ -170,13 +170,13 @@ namespace Ghost.FMOD.Studio
|
||||
}
|
||||
|
||||
// This is only need for loading memory and given our C# wrapper LOAD_MEMORY_POINT isn't feasible anyway
|
||||
enum LOAD_MEMORY_MODE : int
|
||||
internal enum LOAD_MEMORY_MODE : int
|
||||
{
|
||||
LOAD_MEMORY,
|
||||
LOAD_MEMORY_POINT,
|
||||
}
|
||||
|
||||
enum LOAD_MEMORY_ALIGNMENT : int
|
||||
internal enum LOAD_MEMORY_ALIGNMENT : int
|
||||
{
|
||||
VALUE = 32
|
||||
}
|
||||
@@ -235,7 +235,7 @@ namespace Ghost.FMOD.Studio
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
struct Union_IntBoolFloatString
|
||||
internal struct Union_IntBoolFloatString
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public int intvalue;
|
||||
@@ -529,8 +529,7 @@ namespace Ghost.FMOD.Studio
|
||||
using (var encoder = StringHelper.GetFreeHelper())
|
||||
{
|
||||
var stringMem = Marshal.AllocHGlobal(256);
|
||||
var retrieved = 0;
|
||||
var result = FMOD_Studio_System_GetParameterLabelByID(this.handle, id, labelindex, stringMem, 256, out retrieved);
|
||||
var result = FMOD_Studio_System_GetParameterLabelByID(this.handle, id, labelindex, stringMem, 256, out var retrieved);
|
||||
|
||||
if (result == RESULT.ERR_TRUNCATED)
|
||||
{
|
||||
@@ -550,8 +549,7 @@ namespace Ghost.FMOD.Studio
|
||||
}
|
||||
public RESULT getParameterByID(PARAMETER_ID id, out float value)
|
||||
{
|
||||
float finalValue;
|
||||
return getParameterByID(id, out value, out finalValue);
|
||||
return getParameterByID(id, out value, out var finalValue);
|
||||
}
|
||||
public RESULT getParameterByID(PARAMETER_ID id, out float value, out float finalvalue)
|
||||
{
|
||||
@@ -574,8 +572,7 @@ namespace Ghost.FMOD.Studio
|
||||
}
|
||||
public RESULT getParameterByName(string name, out float value)
|
||||
{
|
||||
float finalValue;
|
||||
return getParameterByName(name, out value, out finalValue);
|
||||
return getParameterByName(name, out value, out var finalValue);
|
||||
}
|
||||
public RESULT getParameterByName(string name, out float value, out float finalvalue)
|
||||
{
|
||||
@@ -612,8 +609,7 @@ namespace Ghost.FMOD.Studio
|
||||
|
||||
using var encoder = StringHelper.GetFreeHelper();
|
||||
var stringMem = Marshal.AllocHGlobal(256);
|
||||
var retrieved = 0;
|
||||
var result = FMOD_Studio_System_LookupPath(this.handle, ref id, stringMem, 256, out retrieved);
|
||||
var result = FMOD_Studio_System_LookupPath(this.handle, ref id, stringMem, 256, out var retrieved);
|
||||
|
||||
if (result == RESULT.ERR_TRUNCATED)
|
||||
{
|
||||
@@ -1014,8 +1010,7 @@ namespace Ghost.FMOD.Studio
|
||||
|
||||
using var encoder = StringHelper.GetFreeHelper();
|
||||
var stringMem = Marshal.AllocHGlobal(256);
|
||||
var retrieved = 0;
|
||||
var result = FMOD_Studio_EventDescription_GetParameterLabelByIndex(this.handle, index, labelindex, stringMem, 256, out retrieved);
|
||||
var result = FMOD_Studio_EventDescription_GetParameterLabelByIndex(this.handle, index, labelindex, stringMem, 256, out var retrieved);
|
||||
|
||||
if (result == RESULT.ERR_TRUNCATED)
|
||||
{
|
||||
@@ -1038,9 +1033,8 @@ namespace Ghost.FMOD.Studio
|
||||
|
||||
using var encoder = StringHelper.GetFreeHelper();
|
||||
var stringMem = Marshal.AllocHGlobal(256);
|
||||
var retrieved = 0;
|
||||
var nameBytes = encoder.byteFromStringUTF8(name);
|
||||
var result = FMOD_Studio_EventDescription_GetParameterLabelByName(this.handle, nameBytes, labelindex, stringMem, 256, out retrieved);
|
||||
var result = FMOD_Studio_EventDescription_GetParameterLabelByName(this.handle, nameBytes, labelindex, stringMem, 256, out var retrieved);
|
||||
|
||||
if (result == RESULT.ERR_TRUNCATED)
|
||||
{
|
||||
@@ -1063,8 +1057,7 @@ namespace Ghost.FMOD.Studio
|
||||
|
||||
using var encoder = StringHelper.GetFreeHelper();
|
||||
var stringMem = Marshal.AllocHGlobal(256);
|
||||
var retrieved = 0;
|
||||
var result = FMOD_Studio_EventDescription_GetParameterLabelByID(this.handle, id, labelindex, stringMem, 256, out retrieved);
|
||||
var result = FMOD_Studio_EventDescription_GetParameterLabelByID(this.handle, id, labelindex, stringMem, 256, out var retrieved);
|
||||
|
||||
if (result == RESULT.ERR_TRUNCATED)
|
||||
{
|
||||
@@ -1413,8 +1406,7 @@ namespace Ghost.FMOD.Studio
|
||||
}
|
||||
public RESULT getParameterByID(PARAMETER_ID id, out float value)
|
||||
{
|
||||
float finalvalue;
|
||||
return getParameterByID(id, out value, out finalvalue);
|
||||
return getParameterByID(id, out value, out var finalvalue);
|
||||
}
|
||||
public RESULT getParameterByID(PARAMETER_ID id, out float value, out float finalvalue)
|
||||
{
|
||||
@@ -1437,8 +1429,7 @@ namespace Ghost.FMOD.Studio
|
||||
}
|
||||
public RESULT getParameterByName(string name, out float value)
|
||||
{
|
||||
float finalValue;
|
||||
return getParameterByName(name, out value, out finalValue);
|
||||
return getParameterByName(name, out value, out var finalValue);
|
||||
}
|
||||
public RESULT getParameterByName(string name, out float value, out float finalvalue)
|
||||
{
|
||||
@@ -1608,8 +1599,7 @@ namespace Ghost.FMOD.Studio
|
||||
|
||||
using var encoder = StringHelper.GetFreeHelper();
|
||||
var stringMem = Marshal.AllocHGlobal(256);
|
||||
var retrieved = 0;
|
||||
var result = FMOD_Studio_Bus_GetPath(this.handle, stringMem, 256, out retrieved);
|
||||
var result = FMOD_Studio_Bus_GetPath(this.handle, stringMem, 256, out var retrieved);
|
||||
|
||||
if (result == RESULT.ERR_TRUNCATED)
|
||||
{
|
||||
@@ -1628,8 +1618,7 @@ namespace Ghost.FMOD.Studio
|
||||
}
|
||||
public RESULT getVolume(out float volume)
|
||||
{
|
||||
float finalVolume;
|
||||
return getVolume(out volume, out finalVolume);
|
||||
return getVolume(out volume, out var finalVolume);
|
||||
}
|
||||
public RESULT getVolume(out float volume, out float finalvolume)
|
||||
{
|
||||
@@ -1762,8 +1751,7 @@ namespace Ghost.FMOD.Studio
|
||||
|
||||
using var encoder = StringHelper.GetFreeHelper();
|
||||
var stringMem = Marshal.AllocHGlobal(256);
|
||||
var retrieved = 0;
|
||||
var result = FMOD_Studio_VCA_GetPath(this.handle, stringMem, 256, out retrieved);
|
||||
var result = FMOD_Studio_VCA_GetPath(this.handle, stringMem, 256, out var retrieved);
|
||||
|
||||
if (result == RESULT.ERR_TRUNCATED)
|
||||
{
|
||||
@@ -1781,8 +1769,7 @@ namespace Ghost.FMOD.Studio
|
||||
}
|
||||
public RESULT getVolume(out float volume)
|
||||
{
|
||||
float finalVolume;
|
||||
return getVolume(out volume, out finalVolume);
|
||||
return getVolume(out volume, out var finalVolume);
|
||||
}
|
||||
public RESULT getVolume(out float volume, out float finalvolume)
|
||||
{
|
||||
@@ -1845,8 +1832,7 @@ namespace Ghost.FMOD.Studio
|
||||
|
||||
using var encoder = StringHelper.GetFreeHelper();
|
||||
var stringMem = Marshal.AllocHGlobal(256);
|
||||
var retrieved = 0;
|
||||
var result = FMOD_Studio_Bank_GetPath(this.handle, stringMem, 256, out retrieved);
|
||||
var result = FMOD_Studio_Bank_GetPath(this.handle, stringMem, 256, out var retrieved);
|
||||
|
||||
if (result == RESULT.ERR_TRUNCATED)
|
||||
{
|
||||
@@ -1895,8 +1881,7 @@ namespace Ghost.FMOD.Studio
|
||||
|
||||
using var encoder = StringHelper.GetFreeHelper();
|
||||
var stringMem = Marshal.AllocHGlobal(256);
|
||||
var retrieved = 0;
|
||||
var result = FMOD_Studio_Bank_GetStringInfo(this.handle, index, out id, stringMem, 256, out retrieved);
|
||||
var result = FMOD_Studio_Bank_GetStringInfo(this.handle, index, out id, stringMem, 256, out var retrieved);
|
||||
|
||||
if (result == RESULT.ERR_TRUNCATED)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Ghost.Zeux.MeshOptimizer;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Ghost.Zeux.MeshOptimizer;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ghost.MeshOptimizer
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Ghost.Zeux.MeshOptimizer;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ghost.MeshOptimizer
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using Ghost.Zeux.MeshOptimizer;
|
||||
|
||||
namespace Ghost.MeshOptimizer
|
||||
{
|
||||
public partial struct meshopt_Meshlet
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using Ghost.Zeux.MeshOptimizer;
|
||||
|
||||
namespace Ghost.MeshOptimizer
|
||||
{
|
||||
public partial struct meshopt_OverdrawStatistics
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using Ghost.Zeux.MeshOptimizer;
|
||||
|
||||
namespace Ghost.MeshOptimizer
|
||||
{
|
||||
public unsafe partial struct meshopt_Stream
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using Ghost.Zeux.MeshOptimizer;
|
||||
|
||||
namespace Ghost.MeshOptimizer
|
||||
{
|
||||
public partial struct meshopt_VertexCacheStatistics
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using Ghost.Zeux.MeshOptimizer;
|
||||
|
||||
namespace Ghost.MeshOptimizer
|
||||
{
|
||||
public partial struct meshopt_VertexFetchStatistics
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Ghost.Nvtt.Native
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Ghost.Nvtt.Native
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user