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

@@ -23,12 +23,12 @@ public readonly struct Handle<T> : IEquatable<Handle<T>>
public readonly bool IsValid => this != Invalid;
public readonly bool IsInvalid => this == Invalid;
public readonly override int GetHashCode()
public override readonly int GetHashCode()
{
return ID + (Generation << 16);
}
public readonly override bool Equals(object? obj)
public override readonly bool Equals(object? obj)
{
return obj is Handle<T> id && Equals(id);
}
@@ -76,12 +76,12 @@ public readonly struct Identifier<T> : IEquatable<Identifier<T>>
public readonly bool IsValid => this != Invalid;
public readonly bool IsInvalid => this == Invalid;
public readonly override int GetHashCode()
public override readonly int GetHashCode()
{
return Value;
}
public readonly override bool Equals(object? obj)
public override readonly bool Equals(object? obj)
{
return obj is Identifier<T> id && Equals(id);
}
@@ -152,7 +152,7 @@ public readonly struct Key64<T> : IEquatable<Key64<T>>
public bool IsValid => this != Invalid;
public bool IsInvalid => this == Invalid;
public readonly override int GetHashCode()
public override readonly int GetHashCode()
{
return Value.GetHashCode();
}
@@ -167,7 +167,7 @@ public readonly struct Key64<T> : IEquatable<Key64<T>>
return Value.CompareTo(other.Value);
}
public readonly override bool Equals(object? obj)
public override readonly bool Equals(object? obj)
{
return obj is Key64<T> id && Equals(id);
}
@@ -205,7 +205,7 @@ public readonly struct Key128<T> : IEquatable<Key128<T>>
public bool IsValid => this != Invalid;
public bool IsInvalid => this == Invalid;
public readonly override int GetHashCode()
public override readonly int GetHashCode()
{
return Value.GetHashCode();
}
@@ -220,7 +220,7 @@ public readonly struct Key128<T> : IEquatable<Key128<T>>
return Value.CompareTo(other.Value);
}
public readonly override bool Equals(object? obj)
public override readonly bool Equals(object? obj)
{
return obj is Key128<T> id && Equals(id);
}

View File

@@ -66,7 +66,7 @@ public readonly struct Result<T>
private readonly bool _isSuccess;
/// <summary>
/// Gets the value. Undefined if the result is a failure.
/// Gets the value. Undefined behavior if the result is a failure.
/// </summary>
public T Value
{
@@ -141,7 +141,7 @@ public readonly struct Result<T, E>
private readonly E _error;
/// <summary>
/// Gets the value. Undefined if the result is a failure.
/// Gets the value. Undefined behavior if the result is a failure.
/// </summary>
public T Value
{
@@ -194,10 +194,10 @@ public readonly ref struct RefResult<T, E>
where E : struct, Enum
{
private readonly ref T _value;
private readonly E _error;
private readonly E _error;
/// <summary>
/// Gets a reference to the value. Undefined if the result is a failure.
/// Gets a reference to the value. Undefined behavior if the result is a failure.
/// </summary>
public ref T Value
{
@@ -249,6 +249,12 @@ public readonly ref struct RefResult<T, E>
public static class ResultExtensions
{
extension(Error error)
{
public bool IsSuccess => error == Error.None;
public bool IsFailure => error != Error.None;
}
public static void ThrowIfFailed(this Error result, [CallerArgumentExpression(nameof(result))] string? op = null)
{
if (result != Error.None)

View File

@@ -1,41 +0,0 @@
using System.Runtime.CompilerServices;
namespace Ghost.Core.Utilities;
public ref struct BinaryWriter
{
private readonly Span<byte> _buffer;
private int _position;
public int Position
{
readonly get => _position;
set => _position = value;
}
public BinaryWriter(Span<byte> buffer)
{
_buffer = buffer;
_position = 0;
}
public unsafe void Write<T>(scoped ref readonly T value)
where T : unmanaged
{
Unsafe.WriteUnaligned(ref _buffer[_position], value);
_position += sizeof(T);
}
public void WriteBytes(ReadOnlySpan<byte> data)
{
data.CopyTo(_buffer.Slice(_position, data.Length));
_position += data.Length;
}
public Span<byte> GetSpan(int length)
{
var span = _buffer.Slice(_position, length);
_position += length;
return span;
}
}

View File

@@ -0,0 +1,53 @@
using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Collections;
using System.Runtime.CompilerServices;
namespace Ghost.Core.Utilities;
public struct BufferWriter : IDisposable
{
private UnsafeList<byte> _buffer;
private int _position;
public int Position
{
readonly get => _position;
set => _position = value;
}
public BufferWriter(int initialCapacity, AllocationHandle allocationHandle)
{
_buffer = new UnsafeList<byte>(initialCapacity, allocationHandle);
_position = 0;
}
public unsafe void Write<T>(T value)
where T : unmanaged
{
Unsafe.WriteUnaligned(ref _buffer[_position], value);
_position += sizeof(T);
}
public void WriteBytes(ReadOnlySpan<byte> data)
{
data.CopyTo(_buffer.AsSpan().Slice(_position, data.Length));
_position += data.Length;
}
public Span<byte> ReserveSpan(int length)
{
var span = _buffer.AsSpan().Slice(_position, length);
_position += length;
return span;
}
public readonly Span<byte> AsSpan()
{
return _buffer.AsSpan();
}
public void Dispose()
{
_buffer.Dispose();
}
}

View File

@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Ghost.Core.Utilities;
internal class EnumUtility

View File

@@ -18,11 +18,11 @@ public static class Hash
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong Hash64(ulong a, ulong b, ulong c)
{
ulong h1 = a * _PRIME1;
ulong h2 = b * _PRIME2;
ulong h3 = c * _PRIME3;
var h1 = a * _PRIME1;
var h2 = b * _PRIME2;
var h3 = c * _PRIME3;
ulong h = h1 ^ h2 ^ h3;
var h = h1 ^ h2 ^ h3;
h = (h ^ (h >> 33)) * _PRIME4;
return h ^ (h >> 29);
@@ -31,12 +31,12 @@ public static class Hash
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong Hash64(ulong a, ulong b, ulong c, ulong d)
{
ulong h1 = a * _PRIME1;
ulong h2 = b * _PRIME2;
ulong h3 = c * _PRIME3;
ulong h4 = d * _PRIME4;
var h1 = a * _PRIME1;
var h2 = b * _PRIME2;
var h3 = c * _PRIME3;
var h4 = d * _PRIME4;
ulong h = h1 ^ h2 ^ h3 ^ h4;
var h = h1 ^ h2 ^ h3 ^ h4;
h = (h ^ (h >> 33)) * _PRIME1;
return h ^ (h >> 29);

View File

@@ -1,6 +1,4 @@
using Misaki.HighPerformance.LowLevel;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using TerraFX.Interop.Windows;