Refactor shader system: arrays, keywords, property syntax

Major refactor of shader compiler and related systems:
- Switch ShaderDescriptor/PassDescriptor to arrays; remove IPassDescriptor
- Rewrite keywords block parser/semantic analysis for flexible syntax
- Change property initializers to brace syntax `{ ... }`
- Simplify TokenStream API (remove ref index params)
- Make GetBindlessIndex return uint (~0u for not found)
- Update shader compilation and variant logic for new descriptors
- Update test shader syntax to match new property/keyword formats
- Add AGENTS.md agent development guide
- Add Antlr4 dependency to Ghost.DSL
- Miscellaneous code style and error handling improvements
This commit is contained in:
2026-01-10 18:36:18 +09:00
parent 6a041f75ba
commit d71bdb3fc9
18 changed files with 548 additions and 246 deletions

View File

@@ -2,26 +2,42 @@ using Ghost.Core.Graphics;
namespace Ghost.DSL.ShaderCompiler.Parser;
internal class KeywordsBlock : IBlockParser<List<FunctionCallDeclaration>, List<KeywordsGroup>>
internal class KeywordsBlock : IBlockParser<List<List<Token>>, List<KeywordsGroup>>
{
public static bool ShouldEnter(Token token)
{
return token.Match(TokenType.Keyword, TokenLexicon.KnownKeywords.KEYWORDS);
}
public static List<FunctionCallDeclaration> Parse(TokenStreamSlice stream)
public static List<List<Token>> Parse(TokenStreamSlice stream)
{
stream.Expect(TokenType.Keyword);
stream.Expect(TokenType.LBrace);
var keywords = new List<FunctionCallDeclaration>();
var keywords = new List<List<Token>>();
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 });
var keys = new List<Token>();
while (!bodyStream.Match(TokenType.Semicolon))
{
var expectType = TokenType.Identifier;
if (keys.Count == 0)
{
expectType |= TokenType.Keyword;
}
var argument = bodyStream.Expect(expectType);
keys.Add(argument);
if (bodyStream.Match(TokenType.Comma))
{
bodyStream.Consume();
}
}
keywords.Add(keys);
bodyStream.Expect(TokenType.Semicolon);
}
@@ -30,7 +46,7 @@ internal class KeywordsBlock : IBlockParser<List<FunctionCallDeclaration>, List<
return keywords;
}
public static List<KeywordsGroup>? SemanticAnalysis(List<FunctionCallDeclaration>? syntax, List<DSLShaderError> errors)
public static List<KeywordsGroup>? SemanticAnalysis(List<List<Token>>? syntax, List<DSLShaderError> errors)
{
if (syntax == null)
{
@@ -38,42 +54,42 @@ internal class KeywordsBlock : IBlockParser<List<FunctionCallDeclaration>, List<
}
var keywords = new List<KeywordsGroup>(syntax.Count);
foreach (var keyword in syntax)
foreach (var keys in syntax)
{
if (keyword.arguments == null || keyword.arguments.Count == 0)
if (keys.Count == 0)
{
errors.Add(new DSLShaderError
{
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)
group.space = keys[0].lexeme switch
{
case TokenLexicon.KnownFunctions.LOCAL:
group.space = KeywordSpace.Local;
break;
case TokenLexicon.KnownFunctions.GLOBAL:
group.space = KeywordSpace.Global;
break;
default:
TokenLexicon.KnownFunctions.LOCAL => KeywordSpace.Local,
TokenLexicon.KnownFunctions.GLOBAL => KeywordSpace.Global,
_ => KeywordSpace.Local
};
for (var i = 0; i < keys.Count; i++)
{
var token = keys[i];
if (i == 0 && token.type == TokenType.Keyword)
{
continue;
}
if (token.type != TokenType.Identifier)
{
errors.Add(new DSLShaderError
{
message = $"Unknown function name '{keyword.name.lexeme}'.",
line = keyword.name.line,
column = keyword.name.column
message = $"Invalid keyword '{token.lexeme}' in keywords block.",
line = token.line,
column = token.column
});
continue;
}
}
foreach (var arg in keyword.arguments)
{
group.keywords ??= new List<string>(keyword.arguments.Count);
group.keywords.Add(arg.lexeme);
group.keywords ??= new List<string>(keys.Count);
group.keywords.Add(token.lexeme);
}
keywords.Add(group);