Refactored shader system to support both graphics and compute shaders. - Updated ANTLR grammars and parser logic for explicit shader model and compute shader entry points. - Split shader models and descriptors for graphics and compute. - Refactored pipeline key generation and D3D12 pipeline library for compute support. - Updated push constant layouts and HLSL includes for both shader types. - Improved error handling and test coverage with new example files. BREAKING CHANGE: Shader model, descriptor, and pipeline APIs have changed. Existing shader and pipeline code must be updated to use the new types and conventions.
91 lines
1.6 KiB
ANTLR
91 lines
1.6 KiB
ANTLR
parser grammar GhostShaderParser;
|
|
|
|
options {
|
|
tokenVocab = GhostShaderLexer;
|
|
}
|
|
|
|
// Top-level rule
|
|
shaderFile: shader+ EOF;
|
|
|
|
shader:
|
|
SHADER STRING_LITERAL LBRACE
|
|
shaderBody
|
|
RBRACE;
|
|
|
|
shaderBody:
|
|
shaderModel | (pipelineBlock | passBlock | functionCall)*;
|
|
|
|
shaderModel:
|
|
SM IDENTIFIER SEMICOLON;
|
|
|
|
scope:
|
|
GLOBAL | LOCAL;
|
|
|
|
// Pipeline block
|
|
pipelineBlock:
|
|
PIPELINE LBRACE
|
|
pipelineStatement*
|
|
RBRACE;
|
|
|
|
pipelineStatement:
|
|
IDENTIFIER EQUALS IDENTIFIER SEMICOLON;
|
|
|
|
// Pass block
|
|
passBlock:
|
|
PASS STRING_LITERAL LBRACE
|
|
passBody
|
|
RBRACE;
|
|
|
|
// Template
|
|
passBody:
|
|
(definesBlock | includesBlock | keywordsBlock | pipelineBlock | hlslBlock | shaderEntry)*;
|
|
|
|
definesBlock:
|
|
DEFINES LBRACE
|
|
defineStatement*
|
|
RBRACE;
|
|
|
|
defineStatement:
|
|
IDENTIFIER SEMICOLON;
|
|
|
|
includesBlock:
|
|
INCLUDES LBRACE
|
|
includeStatement*
|
|
RBRACE;
|
|
|
|
includeStatement:
|
|
STRING_LITERAL SEMICOLON;
|
|
|
|
keywordsBlock:
|
|
KEYWORDS LBRACE
|
|
keywordStatement*
|
|
RBRACE;
|
|
|
|
keywordStatement:
|
|
scope? IDENTIFIER (COMMA IDENTIFIER)* SEMICOLON;
|
|
|
|
hlslBlock:
|
|
HLSL LBRACE
|
|
hlslBody
|
|
RBRACE;
|
|
|
|
// Recursively matches content, ensuring braces are balanced.
|
|
hlslBody:
|
|
(
|
|
~(LBRACE | RBRACE) // Match ANY token except open/close braces
|
|
|
|
|
LBRACE hlslBody RBRACE // Or match a nested block recursively
|
|
)*;
|
|
|
|
shaderEntry:
|
|
IDENTIFIER STRING_LITERAL COLON STRING_LITERAL SEMICOLON;
|
|
|
|
functionCall:
|
|
IDENTIFIER LPAREN functionArguments? RPAREN SEMICOLON;
|
|
|
|
functionArguments:
|
|
functionArgument (COMMA functionArgument)*;
|
|
|
|
functionArgument:
|
|
STRING_LITERAL | NUMBER | IDENTIFIER;
|