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:
114
Ghost.DSL/ShaderCompiler/Parser/ShaderBlock.cs
Normal file
114
Ghost.DSL/ShaderCompiler/Parser/ShaderBlock.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
namespace Ghost.DSL.ShaderCompiler.Parser;
|
||||
|
||||
internal class ShaderBlock : IBlockParser<DSLShaderSyntax, DSLShaderSemantics>
|
||||
{
|
||||
public static bool ShouldEnter(Token token)
|
||||
{
|
||||
return token.Match(TokenType.Keyword, TokenLexicon.KnownKeywords.SHADER);
|
||||
}
|
||||
|
||||
public static DSLShaderSyntax Parse(TokenStreamSlice stream)
|
||||
{
|
||||
var shader = new DSLShaderSyntax();
|
||||
|
||||
stream.Expect(TokenType.Keyword);
|
||||
shader.name = stream.Expect(TokenType.StringLiteral);
|
||||
stream.Expect(TokenType.LBrace);
|
||||
|
||||
var bodyStream = stream.Slice(stream.Remaining - 1);
|
||||
while (bodyStream.TryPeek(out var nextToken))
|
||||
{
|
||||
if (PropertiesBlock.ShouldEnter(nextToken))
|
||||
{
|
||||
shader.properties = PropertiesBlock.Parse(bodyStream.SliceNextBlock());
|
||||
}
|
||||
else if (PipelineBlock.ShouldEnter(nextToken))
|
||||
{
|
||||
shader.pipeline = PipelineBlock.Parse(bodyStream.SliceNextBlock());
|
||||
}
|
||||
else if (PassBlock.ShouldEnter(nextToken))
|
||||
{
|
||||
shader.passes ??= new();
|
||||
shader.passes.Add(PassBlock.Parse(bodyStream.SliceNextBlock()));
|
||||
}
|
||||
else if (nextToken.Match(TokenType.Identifier))
|
||||
{
|
||||
var func = ParseUtility.ParseFunction(ref bodyStream, TokenType.StringLiteral | TokenType.Number | TokenType.Identifier);
|
||||
|
||||
shader.functionCalls ??= new();
|
||||
shader.functionCalls.Add(func);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Unexpected token '{nextToken}' in shader body.");
|
||||
}
|
||||
}
|
||||
|
||||
stream.Expect(TokenType.RBrace);
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
public static DSLShaderSemantics? SemanticAnalysis(DSLShaderSyntax? syntax, List<DSLShaderError> errors)
|
||||
{
|
||||
if (syntax == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var shaderModel = new DSLShaderSemantics
|
||||
{
|
||||
name = syntax.name.lexeme,
|
||||
properties = PropertiesBlock.SemanticAnalysis(syntax.properties, errors),
|
||||
pipeline = PipelineBlock.SemanticAnalysis(syntax.pipeline, errors)
|
||||
};
|
||||
|
||||
if (syntax.passes != null)
|
||||
{
|
||||
foreach (var passSyntax in syntax.passes)
|
||||
{
|
||||
var passModel = PassBlock.SemanticAnalysis(passSyntax, errors);
|
||||
if (passModel != null)
|
||||
{
|
||||
shaderModel.passes ??= new();
|
||||
shaderModel.passes.Add(passModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (syntax.functionCalls != null)
|
||||
{
|
||||
foreach (var func in syntax.functionCalls)
|
||||
{
|
||||
switch (func.name.lexeme)
|
||||
{
|
||||
case TokenLexicon.KnownFunctions.FALLBACK:
|
||||
if (func.arguments == null || func.arguments.Count != 1)
|
||||
{
|
||||
errors.Add(new DSLShaderError
|
||||
{
|
||||
message = "Fallback declaration requires exactly one arguments: (fallback shader name).",
|
||||
line = func.name.line,
|
||||
column = func.name.column
|
||||
});
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
shaderModel.fallback = func.arguments[0].lexeme;
|
||||
break;
|
||||
default:
|
||||
errors.Add(new DSLShaderError
|
||||
{
|
||||
message = $"Unknown function '{func.name.lexeme}' in shader.",
|
||||
line = func.name.line,
|
||||
column = func.name.column
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return shaderModel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user