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.
150 lines
2.7 KiB
C#
150 lines
2.7 KiB
C#
using Ghost.Core;
|
|
using Ghost.Core.Graphics;
|
|
using Ghost.Graphics.RHI;
|
|
using Misaki.HighPerformance.LowLevel.Buffer;
|
|
using Misaki.HighPerformance.LowLevel.Collections;
|
|
|
|
namespace Ghost.Graphics.Contracts;
|
|
|
|
public struct ShaderCompileResult : IDisposable
|
|
{
|
|
public UnsafeArray<byte> bytecode;
|
|
public ShaderReflectionData reflectionData;
|
|
|
|
public readonly bool IsCreated => bytecode.IsCreated;
|
|
|
|
public void Dispose()
|
|
{
|
|
bytecode.Dispose();
|
|
}
|
|
}
|
|
|
|
public struct GraphicsCompiledResult : IDisposable
|
|
{
|
|
public ShaderCompileResult tsResult;
|
|
public ShaderCompileResult msResult;
|
|
public ShaderCompileResult psResult;
|
|
|
|
public void Dispose()
|
|
{
|
|
tsResult.Dispose();
|
|
msResult.Dispose();
|
|
psResult.Dispose();
|
|
}
|
|
}
|
|
|
|
public ref struct ShaderCompilationConfig
|
|
{
|
|
public ReadOnlySpan<string> defines;
|
|
public ReadOnlySpan<string> includes;
|
|
public string shaderPath;
|
|
public string entryPoint;
|
|
public ShaderStage stage;
|
|
public CompilerTier tier;
|
|
public CompilerOptimizeLevel optimizeLevel;
|
|
public CompilerOption options;
|
|
}
|
|
|
|
public enum CompilerTier
|
|
{
|
|
Tier0,
|
|
Tier1,
|
|
Tier2
|
|
}
|
|
|
|
public enum CompilerOptimizeLevel
|
|
{
|
|
O0,
|
|
O1,
|
|
O2,
|
|
O3
|
|
}
|
|
|
|
[Flags]
|
|
public enum CompilerOption
|
|
{
|
|
None = 0,
|
|
KeepDebugInfo = 1 << 0,
|
|
KeepReflections = 1 << 1,
|
|
WarnAsError = 1 << 2,
|
|
SpirvCrossCompile = 1 << 3
|
|
}
|
|
|
|
public enum ShaderStage
|
|
{
|
|
TaskShader,
|
|
MeshShader,
|
|
PixelShader,
|
|
ComputeShader
|
|
}
|
|
|
|
public enum ShaderInputType
|
|
{
|
|
ConstantBuffer,
|
|
Texture,
|
|
Sampler,
|
|
UAV,
|
|
StructuredBuffer,
|
|
ByteAddressBuffer,
|
|
RWStructuredBuffer,
|
|
RWByteAddressBuffer
|
|
}
|
|
|
|
public struct ResourceBindingInfo
|
|
{
|
|
public string Name
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public ShaderInputType Type
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public uint BindPoint
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public uint BindCount
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public uint Space
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public uint Size
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public IReadOnlyList<CBufferPropertyInfo>? Properties
|
|
{
|
|
get; set;
|
|
}
|
|
}
|
|
|
|
public readonly struct ShaderReflectionData
|
|
{
|
|
public List<ResourceBindingInfo> ResourcesBindings
|
|
{
|
|
get;
|
|
}
|
|
|
|
public ShaderReflectionData()
|
|
{
|
|
ResourcesBindings = new List<ResourceBindingInfo>();
|
|
}
|
|
}
|
|
|
|
public interface IShaderCompiler : IDisposable
|
|
{
|
|
Result<ShaderCompileResult> Compile(ref readonly ShaderCompilationConfig config, Allocator allocator);
|
|
Result<GraphicsCompiledResult> CompilePass(IPassDescriptor descriptor, ref readonly ShaderCompilationConfig additionalConfig, Key64<ShaderVariant> key);
|
|
Result<GraphicsCompiledResult, ErrorStatus> LoadCompiledCache(Key64<ShaderVariant> key);
|
|
}
|