Refactor: variant-aware shader/material pipeline overhaul
Major architectural update to graphics/material/shader system: - Introduced strongly-typed key structs (Key64/Key128) for passes, variants, and pipelines; removed legacy key types. - Implemented robust hashing and key generation utilities for efficient variant and pipeline lookup/caching. - Shader compiler now compiles/caches all keyword variants using new key system; includes handled as lists. - Switched to push constant root signature for per-draw data; updated HLSL and C# codegen accordingly. - Refactored Material, Shader, and Pass data structures for cache efficiency and variant support. - Pipeline library and PSO management now use 128-bit keys and variant-specific caching. - Replaced WorldNode with SceneNode in editor/scene graph; introduced ComponentManager for archetype/query management. - Migrated math utilities to Misaki.HighPerformance.Mathematics; updated editor controls. - Updated all HLSL and codegen for new buffer/push constant layouts and macros. - Misc: project reference cleanup, D3D12 Work Graph support, doc updates, and code modernization.
This commit is contained in:
@@ -81,4 +81,30 @@ public struct PipelineState
|
||||
Blend = Blend.Opaque,
|
||||
ColorMask = ColorWriteMask.All
|
||||
};
|
||||
|
||||
public readonly ulong GetHashCode64()
|
||||
{
|
||||
// 32-bit packed key for states controlled by material / overrides.
|
||||
// layout:
|
||||
// 0..3 Blend (4 bits)
|
||||
// 4..6 Cull (3 bits)
|
||||
// 7..10 DeafaultState (4 bits)
|
||||
// 11 ZWrite (1 bit)
|
||||
// 12..15 ColorMask (4 bits)
|
||||
|
||||
var key = 0u;
|
||||
key |= ((uint)Blend & 0xFu) << 0;
|
||||
key |= ((uint)Cull & 0x7u) << 4;
|
||||
key |= ((uint)ZTest & 0xFu) << 7;
|
||||
key |= ((uint)ZWrite & 0x1u) << 11;
|
||||
key |= ((uint)ColorMask & 0xFu) << 12;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
public override readonly int GetHashCode()
|
||||
{
|
||||
var code64 = GetHashCode64();
|
||||
return ((int)code64) ^ (int)(code64 >> 32);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public struct ShaderEntryPoint
|
||||
public struct KeywordsGroup
|
||||
{
|
||||
public KeywordSpace space;
|
||||
public List<string>? keywords;
|
||||
public List<string> keywords;
|
||||
}
|
||||
|
||||
public interface IPassDescriptor
|
||||
@@ -53,7 +53,7 @@ public struct PropertyDescriptor
|
||||
public object? defaultValue;
|
||||
}
|
||||
|
||||
public class FullPassDescriptor : IPassDescriptor
|
||||
public class PassDescriptor : IPassDescriptor
|
||||
{
|
||||
public string uniqueIdentifier = string.Empty;
|
||||
public string name = string.Empty;
|
||||
@@ -70,19 +70,9 @@ public class FullPassDescriptor : IPassDescriptor
|
||||
public string Name => name;
|
||||
}
|
||||
|
||||
public class FallbackPassDescriptor : IPassDescriptor
|
||||
{
|
||||
public string fallbackPassIdentifier = string.Empty;
|
||||
public string name = string.Empty;
|
||||
|
||||
public string Identifier => fallbackPassIdentifier;
|
||||
public string Name => name;
|
||||
}
|
||||
|
||||
public class ShaderDescriptor
|
||||
{
|
||||
public string name = string.Empty;
|
||||
public string? generatedCodePath;
|
||||
public uint cbufferSize;
|
||||
public List<PropertyDescriptor> globalProperties = new();
|
||||
public List<PropertyDescriptor> properties = new();
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
namespace Ghost.Core;
|
||||
|
||||
public interface IHandleType;
|
||||
public interface IIdentifierType;
|
||||
public interface IKeyType;
|
||||
|
||||
public readonly struct Handle<T> : IEquatable<Handle<T>>
|
||||
{
|
||||
public int ID
|
||||
@@ -139,19 +135,19 @@ public readonly struct Identifier<T> : IEquatable<Identifier<T>>
|
||||
public static implicit operator Identifier<T>(int value) => new Identifier<T>(value);
|
||||
}
|
||||
|
||||
public readonly struct Key<T>
|
||||
public readonly struct Key64<T> : IEquatable<Key64<T>>
|
||||
{
|
||||
public ulong Value
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public Key(ulong value)
|
||||
public Key64(ulong value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Key<T> Invalid => new(0);
|
||||
public static Key64<T> Invalid => new(0);
|
||||
|
||||
public bool IsValid => this != Invalid;
|
||||
public bool IsInvalid => this == Invalid;
|
||||
@@ -161,28 +157,86 @@ public readonly struct Key<T>
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public readonly override bool Equals(object? obj)
|
||||
{
|
||||
return obj is Key<T> id && Equals(id);
|
||||
}
|
||||
|
||||
public readonly bool Equals(Key<T> other)
|
||||
public readonly bool Equals(Key64<T> other)
|
||||
{
|
||||
return Value == other.Value;
|
||||
}
|
||||
|
||||
public readonly int CompareTo(Key<T> other)
|
||||
public readonly int CompareTo(Key64<T> other)
|
||||
{
|
||||
return Value.CompareTo(other.Value);
|
||||
}
|
||||
|
||||
public static bool operator ==(Key<T> a, Key<T> b)
|
||||
public readonly override bool Equals(object? obj)
|
||||
{
|
||||
return obj is Key64<T> id && Equals(id);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString("X16");
|
||||
}
|
||||
|
||||
public static bool operator ==(Key64<T> a, Key64<T> b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator !=(Key<T> a, Key<T> b)
|
||||
public static bool operator !=(Key64<T> a, Key64<T> b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct Key128<T> : IEquatable<Key128<T>>
|
||||
{
|
||||
public UInt128 Value
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public Key128(UInt128 value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Key128<T> Invalid => new(0);
|
||||
|
||||
public bool IsValid => this != Invalid;
|
||||
public bool IsInvalid => this == Invalid;
|
||||
|
||||
public readonly override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public readonly bool Equals(Key128<T> other)
|
||||
{
|
||||
return Value == other.Value;
|
||||
}
|
||||
|
||||
public readonly int CompareTo(Key128<T> other)
|
||||
{
|
||||
return Value.CompareTo(other.Value);
|
||||
}
|
||||
|
||||
public readonly override bool Equals(object? obj)
|
||||
{
|
||||
return obj is Key128<T> id && Equals(id);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString("X16");
|
||||
}
|
||||
|
||||
public static bool operator ==(Key128<T> a, Key128<T> b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator !=(Key128<T> a, Key128<T> b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
}
|
||||
44
Ghost.Core/Utilities/Hash.cs
Normal file
44
Ghost.Core/Utilities/Hash.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ghost.Core.Utilities;
|
||||
|
||||
public static class Hash
|
||||
{
|
||||
private const ulong _PRIME1 = 0xfa517d6985796b7bul;
|
||||
private const ulong _PRIME2 = 0x589578278297b985ul;
|
||||
private const ulong _PRIME3 = 0x221147a447814b73ul;
|
||||
private const ulong _PRIME4 = 0x9e3779b97f4a7c15ul; // Golden Ratio
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong Hash64(ulong a, ulong b)
|
||||
{
|
||||
return a ^ (b * _PRIME4 + (a << 6) + (a >> 2));
|
||||
}
|
||||
|
||||
[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;
|
||||
|
||||
ulong h = h1 ^ h2 ^ h3;
|
||||
|
||||
h = (h ^ (h >> 33)) * _PRIME4;
|
||||
return h ^ (h >> 29);
|
||||
}
|
||||
|
||||
[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;
|
||||
|
||||
ulong h = h1 ^ h2 ^ h3 ^ h4;
|
||||
|
||||
h = (h ^ (h >> 33)) * _PRIME1;
|
||||
return h ^ (h >> 29);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user