forked from Misaki/GhostEngine
Introduces a new Ghost.Shader.Concept project implementing a modern, data-oriented material and shader system with: - Global/local keyword bitsets (fast O(1) ops, 64 bytes) - Multi-pass shader program and per-pass render state overrides - Thread-safe, 16-byte aligned material property blocks - Material pooling to reduce GC pressure - Batch renderer for efficient PSO grouping and async variant warmup - Full demo (Program.cs) and extensive documentation (ARCHITECTURE.md, README.md, PROJECT_SUMMARY.md) - Minor integration: new enums, doc updates, and keyword handling in existing code No breaking changes to the existing engine; all new code is isolated. This serves as a reference implementation for high-performance, extensible material/shader architectures.
85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
using Ghost.Core.Graphics;
|
|
|
|
namespace Ghost.SDL.Compiler.Parser;
|
|
|
|
internal class KeywordsBlock : IBlockParser<List<FunctionCallDeclaration>, List<KeywordsGroup>>
|
|
{
|
|
public static bool ShouldEnter(Token token)
|
|
{
|
|
return token.Match(TokenType.Keyword, TokenLexicon.KnownKeywords.KEYWORDS);
|
|
}
|
|
|
|
public static List<FunctionCallDeclaration> Parse(TokenStreamSlice stream)
|
|
{
|
|
stream.Expect(TokenType.Keyword);
|
|
stream.Expect(TokenType.LBrace);
|
|
|
|
var keywords = new List<FunctionCallDeclaration>();
|
|
|
|
var bodyStream = stream.Slice(stream.Remaining - 1);
|
|
while (bodyStream.HasMore)
|
|
{
|
|
var keywordToken = bodyStream.Expect(TokenType.Identifier);
|
|
var args = ParseUtility.ParseFunctionArguments(ref bodyStream, TokenType.Identifier);
|
|
keywords.Add(new FunctionCallDeclaration { name = keywordToken, arguments = args });
|
|
bodyStream.Expect(TokenType.Semicolon);
|
|
}
|
|
|
|
stream.Expect(TokenType.RBrace);
|
|
|
|
return keywords;
|
|
}
|
|
|
|
public static List<KeywordsGroup>? SemanticAnalysis(List<FunctionCallDeclaration>? syntax, List<SDLError> errors)
|
|
{
|
|
if (syntax == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var keywords = new List<KeywordsGroup>(syntax.Count);
|
|
foreach (var keyword in syntax)
|
|
{
|
|
if (keyword.arguments == null || keyword.arguments.Count == 0)
|
|
{
|
|
errors.Add(new SDLError
|
|
{
|
|
message = $"Function '{keyword.name.lexeme}' must have at least one argument.",
|
|
line = keyword.name.line,
|
|
column = keyword.name.column
|
|
});
|
|
continue;
|
|
}
|
|
|
|
var group = new KeywordsGroup();
|
|
switch (keyword.name.lexeme)
|
|
{
|
|
case TokenLexicon.KnownFunctions.LOCAL:
|
|
group.space = KeywordSpace.Local;
|
|
break;
|
|
case TokenLexicon.KnownFunctions.GLOBAL:
|
|
group.space = KeywordSpace.Global;
|
|
break;
|
|
default:
|
|
errors.Add(new SDLError
|
|
{
|
|
message = $"Unknown function name '{keyword.name.lexeme}'.",
|
|
line = keyword.name.line,
|
|
column = keyword.name.column
|
|
});
|
|
continue;
|
|
}
|
|
|
|
foreach (var arg in keyword.arguments)
|
|
{
|
|
group.keywords ??= new List<string>(keyword.arguments.Count);
|
|
group.keywords.Add(arg.lexeme);
|
|
}
|
|
|
|
keywords.Add(group);
|
|
}
|
|
|
|
return keywords;
|
|
}
|
|
}
|