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.
115 lines
2.9 KiB
C#
115 lines
2.9 KiB
C#
namespace Ghost.Core.Graphics;
|
|
|
|
public enum KeywordSpace
|
|
{
|
|
Local,
|
|
Global,
|
|
}
|
|
|
|
public enum ShaderPropertyType
|
|
{
|
|
None,
|
|
Float, Float2, Float3, Float4,
|
|
Float4x4,
|
|
Int, Int2, Int3, Int4,
|
|
UInt, UInt2, UInt3, UInt4,
|
|
Bool, Bool2, Bool3, Bool4,
|
|
Texture2D, Texture3D, TextureCube,
|
|
Texture2DArray, TextureCubeArray,
|
|
Sampler
|
|
}
|
|
|
|
public struct ShaderEntryPoint
|
|
{
|
|
public string entry;
|
|
public string shader;
|
|
|
|
public readonly bool IsCreated => !string.IsNullOrEmpty(entry) && !string.IsNullOrEmpty(shader);
|
|
}
|
|
|
|
public struct KeywordsGroup
|
|
{
|
|
public KeywordSpace space;
|
|
public List<string> keywords;
|
|
}
|
|
|
|
public interface IPassDescriptor
|
|
{
|
|
public string Identifier
|
|
{
|
|
get;
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get;
|
|
}
|
|
}
|
|
|
|
public struct PropertyDescriptor
|
|
{
|
|
public ShaderPropertyType type;
|
|
public string name;
|
|
public object? defaultValue;
|
|
}
|
|
|
|
public class PassDescriptor : IPassDescriptor
|
|
{
|
|
public string uniqueIdentifier = string.Empty;
|
|
public string name = string.Empty;
|
|
|
|
public ShaderEntryPoint taskShader;
|
|
public ShaderEntryPoint meshShader;
|
|
public ShaderEntryPoint pixelShader;
|
|
public List<string>? defines;
|
|
public List<string>? includes;
|
|
public List<KeywordsGroup>? keywords;
|
|
public PipelineState localPipeline;
|
|
|
|
public string Identifier => uniqueIdentifier;
|
|
public string Name => name;
|
|
}
|
|
|
|
public class ShaderDescriptor
|
|
{
|
|
public string name = string.Empty;
|
|
public uint cbufferSize;
|
|
public List<PropertyDescriptor> globalProperties = new();
|
|
public List<PropertyDescriptor> properties = new();
|
|
public List<IPassDescriptor> passes = new();
|
|
}
|
|
|
|
public static class ShaderDescriptorExtensions
|
|
{
|
|
public static uint GetSize(this ShaderPropertyType type)
|
|
{
|
|
return type switch
|
|
{
|
|
ShaderPropertyType.Float => 4,
|
|
ShaderPropertyType.Float2 => 8,
|
|
ShaderPropertyType.Float3 => 12,
|
|
ShaderPropertyType.Float4 => 16,
|
|
ShaderPropertyType.Float4x4 => 64,
|
|
ShaderPropertyType.Int => 4,
|
|
ShaderPropertyType.Int2 => 8,
|
|
ShaderPropertyType.Int3 => 12,
|
|
ShaderPropertyType.Int4 => 16,
|
|
ShaderPropertyType.UInt => 4,
|
|
ShaderPropertyType.UInt2 => 8,
|
|
ShaderPropertyType.UInt3 => 12,
|
|
ShaderPropertyType.UInt4 => 16,
|
|
ShaderPropertyType.Bool => 4,
|
|
ShaderPropertyType.Bool2 => 8,
|
|
ShaderPropertyType.Bool3 => 12,
|
|
ShaderPropertyType.Bool4 => 16,
|
|
ShaderPropertyType.Texture2D => 4, // Bindless resource use uint32
|
|
ShaderPropertyType.Texture3D => 4,
|
|
ShaderPropertyType.TextureCube => 4,
|
|
ShaderPropertyType.Texture2DArray => 4,
|
|
ShaderPropertyType.TextureCubeArray => 4,
|
|
ShaderPropertyType.Sampler => 4,
|
|
_ => 0,
|
|
};
|
|
}
|
|
}
|