@galacean/engine-shader-compiler 0.0.0-experimental-2.0-spine.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/bundler/cli.js +341 -0
- package/bundler/precompile.cjs.js +324 -0
- package/bundler/precompile.js +294 -0
- package/bundler/rollup.cjs.js +368 -0
- package/bundler/rollup.js +341 -0
- package/dist/browser.js +8938 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.min.js +2 -0
- package/dist/browser.min.js.map +1 -0
- package/dist/browser.verbose.js +9601 -0
- package/dist/browser.verbose.js.map +1 -0
- package/dist/browser.verbose.min.js +2 -0
- package/dist/browser.verbose.min.js.map +1 -0
- package/dist/main.js +8935 -0
- package/dist/main.js.map +1 -0
- package/dist/main.verbose.js +9598 -0
- package/dist/main.verbose.js.map +1 -0
- package/dist/module.js +8928 -0
- package/dist/module.js.map +1 -0
- package/dist/module.verbose.js +9591 -0
- package/dist/module.verbose.js.map +1 -0
- package/package.json +69 -0
- package/types/GSError.d.ts +16 -0
- package/types/ParserUtils.d.ts +39 -0
- package/types/Preprocessor.d.ts +30 -0
- package/types/ShaderCompiler.d.ts +21 -0
- package/types/ShaderCompilerUtils.d.ts +10 -0
- package/types/ShaderInstructionEncoder.d.ts +1 -0
- package/types/TempArray.d.ts +5 -0
- package/types/bundler/cli.d.ts +1 -0
- package/types/bundler/precompile.d.ts +25 -0
- package/types/bundler/rollup.d.ts +41 -0
- package/types/codeGen/CodeGenVisitor.d.ts +1 -0
- package/types/codeGen/GLES100.d.ts +12 -0
- package/types/codeGen/GLES300.d.ts +20 -0
- package/types/codeGen/GLESVisitor.d.ts +1 -0
- package/types/codeGen/VisitorContext.d.ts +2 -0
- package/types/codeGen/index.d.ts +3 -0
- package/types/codeGen/types.d.ts +12 -0
- package/types/common/BaseLexer.d.ts +2 -0
- package/types/common/BaseToken.d.ts +35 -0
- package/types/common/IBaseSymbol.d.ts +5 -0
- package/types/common/ShaderPosition.d.ts +8 -0
- package/types/common/ShaderRange.d.ts +8 -0
- package/types/common/SymbolTable.d.ts +9 -0
- package/types/common/SymbolTableStack.d.ts +13 -0
- package/types/common/enums/Keyword.d.ts +124 -0
- package/types/common/enums/ShaderStage.d.ts +5 -0
- package/types/common/index.d.ts +5 -0
- package/types/common/types.d.ts +101 -0
- package/types/index.d.ts +3 -0
- package/types/lalr/CFG.d.ts +5 -0
- package/types/lalr/LALR1.d.ts +27 -0
- package/types/lalr/Production.d.ts +9 -0
- package/types/lalr/State.d.ts +20 -0
- package/types/lalr/StateItem.d.ts +20 -0
- package/types/lalr/Utils.d.ts +22 -0
- package/types/lalr/index.d.ts +2 -0
- package/types/lalr/types.d.ts +14 -0
- package/types/lexer/Lexer.d.ts +143 -0
- package/types/lexer/index.d.ts +1 -0
- package/types/parser/AST.d.ts +502 -0
- package/types/parser/Grammar.d.ts +11 -0
- package/types/parser/GrammarSymbol.d.ts +128 -0
- package/types/parser/SemanticAnalyzer.d.ts +2 -0
- package/types/parser/ShaderInfo.d.ts +10 -0
- package/types/parser/ShaderTargetParser.d.ts +24 -0
- package/types/parser/builtin/functions.d.ts +34 -0
- package/types/parser/builtin/index.d.ts +2 -0
- package/types/parser/builtin/variables.d.ts +11 -0
- package/types/parser/index.d.ts +2 -0
- package/types/parser/symbolTable/FnSymbol.d.ts +6 -0
- package/types/parser/symbolTable/StructSymbol.d.ts +6 -0
- package/types/parser/symbolTable/SymbolDataType.d.ts +8 -0
- package/types/parser/symbolTable/SymbolInfo.d.ts +22 -0
- package/types/parser/symbolTable/VarSymbol.d.ts +8 -0
- package/types/parser/symbolTable/index.d.ts +6 -0
- package/types/parser/types.d.ts +24 -0
- package/types/sourceParser/ShaderSourceFactory.d.ts +8 -0
- package/types/sourceParser/ShaderSourceParser.d.ts +1 -0
- package/types/sourceParser/ShaderSourceSymbol.d.ts +10 -0
- package/types/sourceParser/SourceLexer.d.ts +19 -0
- package/types/sourceParser/index.d.ts +1 -0
- package/verbose/package.json +11 -0
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@galacean/engine-shader-compiler",
|
|
3
|
+
"version": "0.0.0-experimental-2.0-spine.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"registry": "https://registry.npmjs.org"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/galacean/engine.git"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "dist/main.js",
|
|
13
|
+
"module": "dist/module.js",
|
|
14
|
+
"browser": "dist/browser.min.js",
|
|
15
|
+
"debug": "src/index.ts",
|
|
16
|
+
"types": "types/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./dist/module.js",
|
|
20
|
+
"require": "./dist/main.js",
|
|
21
|
+
"types": "./types/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./bundler/rollup": {
|
|
24
|
+
"import": "./bundler/rollup.js",
|
|
25
|
+
"require": "./bundler/rollup.cjs.js",
|
|
26
|
+
"types": "./types/bundler/rollup.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./bundler/precompile": {
|
|
29
|
+
"import": "./bundler/precompile.js",
|
|
30
|
+
"require": "./bundler/precompile.cjs.js",
|
|
31
|
+
"types": "./types/bundler/precompile.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./verbose": {
|
|
34
|
+
"import": "./dist/module.verbose.js",
|
|
35
|
+
"require": "./dist/main.verbose.js",
|
|
36
|
+
"types": "./types/index.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./src/*": "./src/*.ts",
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"bin": {
|
|
42
|
+
"shader-compiler-precompile": "./bundler/cli.js"
|
|
43
|
+
},
|
|
44
|
+
"umd": {
|
|
45
|
+
"name": "Galacean.ShaderCompiler",
|
|
46
|
+
"globals": {
|
|
47
|
+
"@galacean/engine-math": "Galacean",
|
|
48
|
+
"@galacean/engine-core": "Galacean"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist/**/*",
|
|
53
|
+
"bundler/**/*",
|
|
54
|
+
"types/**/*",
|
|
55
|
+
"verbose/package.json"
|
|
56
|
+
],
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@rollup/pluginutils": "^5.0.0",
|
|
59
|
+
"@galacean/engine-math": "0.0.0-experimental-2.0-spine.0",
|
|
60
|
+
"@galacean/engine-core": "0.0.0-experimental-2.0-spine.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@galacean/engine-design": "0.0.0-experimental-2.0-spine.0"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "rollup -c rollup.config.js && node -e \"require('fs').chmodSync('bundler/cli.js', 0o755)\"",
|
|
67
|
+
"b:types": "tsc"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ShaderPosition } from "./common/ShaderPosition";
|
|
2
|
+
import { ShaderRange } from "./common/ShaderRange";
|
|
3
|
+
export declare class GSError extends Error {
|
|
4
|
+
readonly location: ShaderRange | ShaderPosition;
|
|
5
|
+
readonly source: string;
|
|
6
|
+
readonly file?: string;
|
|
7
|
+
static wrappingLineCount: number;
|
|
8
|
+
constructor(name: GSErrorName, message: string, location: ShaderRange | ShaderPosition, source: string, file?: string);
|
|
9
|
+
toString(): string;
|
|
10
|
+
}
|
|
11
|
+
export declare enum GSErrorName {
|
|
12
|
+
PreprocessorError = "PreprocessorError",
|
|
13
|
+
CompilationError = "CompilationError",
|
|
14
|
+
ScannerError = "ScannerError",
|
|
15
|
+
CompilationWarn = "CompilationWarning"
|
|
16
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { GalaceanDataType } from "./common";
|
|
2
|
+
import { ASTNode, TreeNode } from "./parser/AST";
|
|
3
|
+
import { GrammarSymbol, NoneTerminal } from "./parser/GrammarSymbol";
|
|
4
|
+
export declare class ParserUtils {
|
|
5
|
+
static unwrapNodeByType<T = TreeNode>(node: TreeNode, type: NoneTerminal): T | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Parse a function-macro parameter-list lexeme (`"(a, b, c)"`) into its parameter
|
|
8
|
+
* names. An empty list `"()"` yields `[]`. Leading/trailing whitespace around each
|
|
9
|
+
* name is trimmed. Empty entries from consecutive commas are filtered out.
|
|
10
|
+
*/
|
|
11
|
+
static parseMacroParamList(lexeme: string): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Walk single-child precedence-chain wrappers down to a `VariableIdentifier`,
|
|
14
|
+
* returning the leaf node (or `undefined` for any compound expression).
|
|
15
|
+
*
|
|
16
|
+
* `allowParens` chooses between two callers' needs:
|
|
17
|
+
* - `true` — descend through `( expression )` form, so `(v)` resolves to
|
|
18
|
+
* `v`. Use when the caller substitutes at the expression root
|
|
19
|
+
* (aliasing, renaming); user-written parens carry no extra meaning.
|
|
20
|
+
* - `false` — any 3-child `PrimaryExpression` aborts; `(v)` stays
|
|
21
|
+
* compound. Use when the caller treats the unwrapped node as a single
|
|
22
|
+
* token (IO-struct arg drop, alias detection); user-written parens
|
|
23
|
+
* must not collapse.
|
|
24
|
+
*/
|
|
25
|
+
static unwrapBareIdentifier(node: TreeNode, options: {
|
|
26
|
+
allowParens: boolean;
|
|
27
|
+
}): ASTNode.VariableIdentifier | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Lexeme variant of `unwrapBareIdentifier({ allowParens: true })` for callers
|
|
30
|
+
* that already work with strings. Returns `null` for compound expressions.
|
|
31
|
+
*/
|
|
32
|
+
static extractDirectIdentLexeme(expr: TreeNode): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Check if type `tb` is compatible with type `ta`.
|
|
35
|
+
*/
|
|
36
|
+
static typeCompatible(ta: GalaceanDataType, tb: GalaceanDataType | undefined): boolean;
|
|
37
|
+
static toString(sm: GrammarSymbol): string;
|
|
38
|
+
static isTerminal(sm: GrammarSymbol): boolean;
|
|
39
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ASTNode } from "./parser/AST";
|
|
2
|
+
import type { BranchSignature } from "./common/BaseToken";
|
|
3
|
+
export type IncludeMap = {
|
|
4
|
+
readonly [includeName: string]: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
export type ChunkOutputCache = Map<string, string>;
|
|
7
|
+
export interface MacroDefineInfo {
|
|
8
|
+
isFunction: boolean;
|
|
9
|
+
params: string[];
|
|
10
|
+
/** Value AST. Set when the replacement list parses as `expression` (which
|
|
11
|
+
* includes comma-separated lists per C99 §6.10.3); absent for the GLSL ES
|
|
12
|
+
* 3.00 §3.4 opaque cases the grammar can't reduce (empty, type-alias keyword,
|
|
13
|
+
* trailing punctuation, unbalanced bracket, trailing operator). Identifier
|
|
14
|
+
* references inside are collected by `MacroCallSymbol._collectIdentifierRefs`
|
|
15
|
+
* walking this subtree. */
|
|
16
|
+
valueAst?: ASTNode.Expression;
|
|
17
|
+
/** Whitespace-normalized directive text. Dedup key against re-includes in
|
|
18
|
+
* the same branch; differing values produce different keys. */
|
|
19
|
+
dedupKey: string;
|
|
20
|
+
/** `#ifdef` branch at registration time; call sites filter to visible entries. */
|
|
21
|
+
branch: BranchSignature;
|
|
22
|
+
}
|
|
23
|
+
export interface MacroDefineList {
|
|
24
|
+
[macroName: string]: MacroDefineInfo[];
|
|
25
|
+
}
|
|
26
|
+
export declare class Preprocessor {
|
|
27
|
+
private static readonly _includeReg;
|
|
28
|
+
static parse(source: string, basePathForIncludeKey: string, includeMap: IncludeMap, chunkOutputCache: ChunkOutputCache): string;
|
|
29
|
+
private static _replace;
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ShaderLanguage } from "@galacean/engine-core";
|
|
2
|
+
import type { IPrecompiledShader, IShaderSource } from "@galacean/engine-design";
|
|
3
|
+
import type { IShaderProgramSource } from "@galacean/engine-design/types/shader-compiler/IShaderProgramSource";
|
|
4
|
+
import { ShaderPosition, ShaderRange } from "./common";
|
|
5
|
+
import { IncludeMap } from "./Preprocessor";
|
|
6
|
+
export declare class ShaderCompiler {
|
|
7
|
+
private static _parser;
|
|
8
|
+
private static _shaderPositionPool;
|
|
9
|
+
private static _shaderRangePool;
|
|
10
|
+
static _processingPassText?: string;
|
|
11
|
+
private _includeMap;
|
|
12
|
+
private readonly _chunkOutputCache;
|
|
13
|
+
/** Replace the `#include` lookup table and clear the derived chunk cache. */
|
|
14
|
+
_setIncludeMap(includeMap: IncludeMap): void;
|
|
15
|
+
static createPosition(index: number, line?: number, column?: number): ShaderPosition;
|
|
16
|
+
static createRange(start: ShaderPosition, end: ShaderPosition): ShaderRange;
|
|
17
|
+
_parseShaderSource(sourceCode: string): IShaderSource;
|
|
18
|
+
_parseShaderPass(source: string, vertexEntry: string, fragmentEntry: string, backend: ShaderLanguage, basePathForIncludeKey: string): IShaderProgramSource | undefined;
|
|
19
|
+
_precompile(sourceCode: string, platformTarget: ShaderLanguage, basePathForIncludeKey: string): IPrecompiledShader;
|
|
20
|
+
private _serializeRenderStates;
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ClearableObjectPool, type IPoolElement } from "@galacean/engine-core";
|
|
2
|
+
import { GSErrorName } from "./GSError";
|
|
3
|
+
import { ShaderRange } from "./common/ShaderRange";
|
|
4
|
+
import { ShaderPosition } from "./common/ShaderPosition";
|
|
5
|
+
export declare class ShaderCompilerUtils {
|
|
6
|
+
private static _shaderCompilerObjectPoolSet;
|
|
7
|
+
static createObjectPool<T extends IPoolElement>(type: new () => T): ClearableObjectPool<T>;
|
|
8
|
+
static clearAllShaderCompilerObjectPool(): void;
|
|
9
|
+
static createGSError(message: string, errorName: GSErrorName, source: string, location: ShaderRange | ShaderPosition, file?: string): Error;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { ShaderInstruction } from "@galacean/engine-design";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Normalize to forward slashes (Windows uses `\`; downstream regex/keys assume `/`). */
|
|
2
|
+
export declare function normalizePath(p: string): string;
|
|
3
|
+
export interface PrecompileOptions {
|
|
4
|
+
/** Absolute or relative path to the directory containing `.shader` sources. */
|
|
5
|
+
input: string;
|
|
6
|
+
/** Absolute or relative path to the directory where `.shaderc` outputs are written. */
|
|
7
|
+
output: string;
|
|
8
|
+
/** Remove `.shaderc` files whose `.shader` source no longer exists, and prune empty dirs. */
|
|
9
|
+
clean?: boolean;
|
|
10
|
+
/** Watch the input dir and re-run incrementally on `.shader` / `.glsl` changes. */
|
|
11
|
+
watch?: boolean;
|
|
12
|
+
/** Compile only this file (path may be relative to cwd). Skips full scan + cleanup. */
|
|
13
|
+
only?: string;
|
|
14
|
+
/** Generate `<output>/index.ts` aggregating every `.shaderc` file. */
|
|
15
|
+
emitIndex?: boolean;
|
|
16
|
+
/** Generate raw-source indexes: `<input>/index.ts` (.shader) + sibling `ShaderLibrary/index.ts` (.glsl). */
|
|
17
|
+
emitSources?: boolean;
|
|
18
|
+
/** Optional shader platform target passed through to `_precompile`. Defaults to `0`. */
|
|
19
|
+
platformTarget?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function precompile(options: PrecompileOptions): Promise<void>;
|
|
22
|
+
export declare function runFull(options: Omit<PrecompileOptions, "watch">): Promise<{
|
|
23
|
+
failed: number;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function startWatcher(options: Omit<PrecompileOptions, "watch" | "only">): Promise<void>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Plugin } from "rollup";
|
|
2
|
+
export interface ShaderPrecompileOptions {
|
|
3
|
+
/** Directory containing `.shader` source files. */
|
|
4
|
+
input: string;
|
|
5
|
+
/** Directory where `.shaderc` outputs are written. */
|
|
6
|
+
output: string;
|
|
7
|
+
/** Remove `.shaderc` whose source no longer exists. Default `true`. */
|
|
8
|
+
clean?: boolean;
|
|
9
|
+
/** Emit an aggregated `<output>/index.ts`. Default `true`. */
|
|
10
|
+
emitIndex?: boolean;
|
|
11
|
+
/** Emit raw-source indexes (`.shader` + `.glsl`) into the input tree. */
|
|
12
|
+
emitSources?: boolean;
|
|
13
|
+
/** Shader platform target. Default `0`. */
|
|
14
|
+
platformTarget?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface ShaderPluginOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Override the default include pattern. The plugin always matches `.glsl`,
|
|
19
|
+
* `.shader`, and `.shaderc` extensions; this option exists for advanced
|
|
20
|
+
* cases where the host bundler needs to gate by additional path constraints.
|
|
21
|
+
* Returning `false` skips a file.
|
|
22
|
+
*/
|
|
23
|
+
filter?: (id: string) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* When set, the plugin runs an initial full precompile in `buildStart` and,
|
|
26
|
+
* in watch mode, starts a background file watcher that incrementally
|
|
27
|
+
* regenerates `.shaderc` outputs when `.shader` / `.glsl` files change.
|
|
28
|
+
* Without this option the plugin only does file-extension transforms —
|
|
29
|
+
* pre-compile must be triggered separately via the `shader-precompile` CLI.
|
|
30
|
+
*/
|
|
31
|
+
precompile?: ShaderPrecompileOptions;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Rollup plugin that transforms shader assets into JS modules.
|
|
35
|
+
*
|
|
36
|
+
* - Always: transforms `.glsl` / `.shader` / `.shaderc` files.
|
|
37
|
+
* - When `precompile` option is set: runs a full precompile in buildStart and,
|
|
38
|
+
* in watch mode, starts a background watcher that mirrors `.shader` source
|
|
39
|
+
* changes into `.shaderc` outputs and refreshes the aggregated index.
|
|
40
|
+
*/
|
|
41
|
+
export declare function shaderCompiler(options?: ShaderPluginOptions): Plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ASTNode } from "../parser/AST";
|
|
2
|
+
import { StructProp } from "../parser/types";
|
|
3
|
+
import { GLESVisitor } from "./GLESVisitor";
|
|
4
|
+
export declare class GLES100Visitor extends GLESVisitor {
|
|
5
|
+
private static _singleton;
|
|
6
|
+
static getVisitor(): GLES100Visitor;
|
|
7
|
+
getAttributeProp(prop: StructProp): string;
|
|
8
|
+
getVaryingProp(prop: StructProp): string;
|
|
9
|
+
getMRTProp(): string;
|
|
10
|
+
visitPostfixExpression(node: ASTNode.PostfixExpression): string;
|
|
11
|
+
visitJumpStatement(node: ASTNode.JumpStatement): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ASTNode } from "../parser/AST";
|
|
2
|
+
import { ShaderData } from "../parser/ShaderInfo";
|
|
3
|
+
import { StructProp } from "../parser/types";
|
|
4
|
+
import { GLESVisitor } from "./GLESVisitor";
|
|
5
|
+
import { ICodeSegment } from "./types";
|
|
6
|
+
export declare class GLES300Visitor extends GLESVisitor {
|
|
7
|
+
private static _singleton;
|
|
8
|
+
static getVisitor(): GLES300Visitor;
|
|
9
|
+
private _otherCodeArray;
|
|
10
|
+
private _fragColorVariableRegistered;
|
|
11
|
+
reset(): void;
|
|
12
|
+
getOtherGlobal(data: ShaderData, out: ICodeSegment[]): void;
|
|
13
|
+
getAttributeProp(prop: StructProp): string;
|
|
14
|
+
getVaryingProp(prop: StructProp): string;
|
|
15
|
+
getMRTProp(prop: StructProp): string;
|
|
16
|
+
visitFunctionIdentifier(node: ASTNode.FunctionIdentifier): string;
|
|
17
|
+
visitVariableIdentifier(node: ASTNode.VariableIdentifier): string;
|
|
18
|
+
visitJumpStatement(node: ASTNode.JumpStatement): string;
|
|
19
|
+
private _registerFragColorVariable;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IShaderSource } from "@galacean/engine-design";
|
|
2
|
+
export type IRenderState = [
|
|
3
|
+
/** Constant RenderState. */
|
|
4
|
+
Record<number, boolean | string | number | any>,
|
|
5
|
+
/** Variable RenderState. */
|
|
6
|
+
Record<number, string>
|
|
7
|
+
];
|
|
8
|
+
export type ITag = IShaderSource["subShaders"][number]["tags"];
|
|
9
|
+
export type ICodeSegment = {
|
|
10
|
+
text: string;
|
|
11
|
+
index: number;
|
|
12
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ShaderRange, ShaderPosition } from ".";
|
|
2
|
+
import type { IPoolElement } from "@galacean/engine-core";
|
|
3
|
+
/**
|
|
4
|
+
* One condition in a branch signature: `defined: true` for `#ifdef X` (the
|
|
5
|
+
* branch is active when `X` is defined), `defined: false` for `#ifndef X` /
|
|
6
|
+
* after `#else` (active when `X` is undefined).
|
|
7
|
+
*/
|
|
8
|
+
export interface BranchConstraint {
|
|
9
|
+
name: string;
|
|
10
|
+
defined: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Snapshot of the `#ifdef`/`#ifndef`/`#else` stack at a source position. An
|
|
14
|
+
* empty signature means unconditional (top-level). Constraints are conjunctive:
|
|
15
|
+
* the position is active iff every constraint holds. Produced by the Lexer
|
|
16
|
+
* (the sole branch-stack maintainer) and stamped onto every emitted token +
|
|
17
|
+
* every registered `MacroDefineInfo`.
|
|
18
|
+
*/
|
|
19
|
+
export type BranchSignature = readonly BranchConstraint[];
|
|
20
|
+
export declare const EMPTY_BRANCH: BranchSignature;
|
|
21
|
+
export declare class BaseToken<T extends number = number> implements IPoolElement {
|
|
22
|
+
static pool: import("@galacean/engine-core").ClearableObjectPool<BaseToken<number>>;
|
|
23
|
+
type: T;
|
|
24
|
+
lexeme: string;
|
|
25
|
+
location: ShaderRange;
|
|
26
|
+
/** Branch signature snapshot at the point this token was emitted. Empty
|
|
27
|
+
* signature (default) means top-level / unconditional. The Lexer tags
|
|
28
|
+
* every token; downstream code (AST nodes built from tokens) can read
|
|
29
|
+
* the field directly to know which `#ifdef` branch they're inside. */
|
|
30
|
+
branch: BranchSignature;
|
|
31
|
+
set(type: T, lexeme: string, start?: ShaderPosition): any;
|
|
32
|
+
set(type: T, lexeme: string, location?: ShaderRange): any;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|
|
35
|
+
export declare const EOF: BaseToken<number>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IPoolElement } from "@galacean/engine-core";
|
|
2
|
+
import { ShaderPosition } from "./ShaderPosition";
|
|
3
|
+
export declare class ShaderRange implements IPoolElement {
|
|
4
|
+
start: ShaderPosition;
|
|
5
|
+
end: ShaderPosition;
|
|
6
|
+
set(start: ShaderPosition, end: ShaderPosition): void;
|
|
7
|
+
dispose(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IBaseSymbol } from "./IBaseSymbol";
|
|
2
|
+
export declare class SymbolTable<T extends IBaseSymbol> {
|
|
3
|
+
private _table;
|
|
4
|
+
insert(symbol: T, isInMacroBranch?: boolean): void;
|
|
5
|
+
getSymbol(symbol: T, includeMacro?: boolean): T | undefined;
|
|
6
|
+
getSymbols(symbol: T, includeMacro: boolean, out: T[]): T[];
|
|
7
|
+
/** Iterate every registered symbol. Order within a name bucket is insertion order. */
|
|
8
|
+
forEach(callback: (symbol: T) => void): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IBaseSymbol } from "./IBaseSymbol";
|
|
2
|
+
import { SymbolTable } from "./SymbolTable";
|
|
3
|
+
export declare class SymbolTableStack<S extends IBaseSymbol, T extends SymbolTable<S>> {
|
|
4
|
+
stack: T[];
|
|
5
|
+
get scope(): T;
|
|
6
|
+
get isInMacroBranch(): boolean;
|
|
7
|
+
pushScope(scope: T): void;
|
|
8
|
+
clear(): void;
|
|
9
|
+
popScope(): T | undefined;
|
|
10
|
+
insert(symbol: S): void;
|
|
11
|
+
lookup(symbol: S, includeMacro?: boolean): S | undefined;
|
|
12
|
+
lookupAll(symbol: S, includeMacro: boolean, out: S[]): S[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export declare enum Keyword {
|
|
2
|
+
CONST = 0,
|
|
3
|
+
BOOL = 1,
|
|
4
|
+
FLOAT = 2,
|
|
5
|
+
DOUBLE = 3,
|
|
6
|
+
INT = 4,
|
|
7
|
+
UINT = 5,
|
|
8
|
+
BREAK = 6,
|
|
9
|
+
CONTINUE = 7,
|
|
10
|
+
DO = 8,
|
|
11
|
+
ELSE = 9,
|
|
12
|
+
FOR = 10,
|
|
13
|
+
IF = 11,
|
|
14
|
+
WHILE = 12,
|
|
15
|
+
DISCARD = 13,
|
|
16
|
+
RETURN = 14,
|
|
17
|
+
BVEC2 = 15,
|
|
18
|
+
BVEC3 = 16,
|
|
19
|
+
BVEC4 = 17,
|
|
20
|
+
IVEC2 = 18,
|
|
21
|
+
IVEC3 = 19,
|
|
22
|
+
IVEC4 = 20,
|
|
23
|
+
UVEC2 = 21,
|
|
24
|
+
UVEC3 = 22,
|
|
25
|
+
UVEC4 = 23,
|
|
26
|
+
VEC2 = 24,
|
|
27
|
+
VEC3 = 25,
|
|
28
|
+
VEC4 = 26,
|
|
29
|
+
VEC4_ARRAY = 27,
|
|
30
|
+
MAT2 = 28,
|
|
31
|
+
MAT3 = 29,
|
|
32
|
+
MAT4 = 30,
|
|
33
|
+
MAT2X3 = 31,
|
|
34
|
+
MAT2X4 = 32,
|
|
35
|
+
MAT3X2 = 33,
|
|
36
|
+
MAT3X4 = 34,
|
|
37
|
+
MAT4X2 = 35,
|
|
38
|
+
MAT4X3 = 36,
|
|
39
|
+
IN = 37,
|
|
40
|
+
OUT = 38,
|
|
41
|
+
INOUT = 39,
|
|
42
|
+
CENTROID = 40,
|
|
43
|
+
SAMPLER2D = 41,
|
|
44
|
+
SAMPLER3D = 42,
|
|
45
|
+
SAMPLER_CUBE = 43,
|
|
46
|
+
SAMPLER2D_SHADOW = 44,
|
|
47
|
+
SAMPLER_CUBE_SHADOW = 45,
|
|
48
|
+
SAMPLER2D_ARRAY = 46,
|
|
49
|
+
SAMPLER2D_ARRAY_SHADOW = 47,
|
|
50
|
+
I_SAMPLER2D = 48,
|
|
51
|
+
I_SAMPLER3D = 49,
|
|
52
|
+
I_SAMPLER_CUBE = 50,
|
|
53
|
+
I_SAMPLER2D_ARRAY = 51,
|
|
54
|
+
U_SAMPLER2D = 52,
|
|
55
|
+
U_SAMPLER3D = 53,
|
|
56
|
+
U_SAMPLER_CUBE = 54,
|
|
57
|
+
U_SAMPLER2D_ARRAY = 55,
|
|
58
|
+
STRUCT = 56,
|
|
59
|
+
LAYOUT = 57,
|
|
60
|
+
LOCATION = 58,
|
|
61
|
+
VOID = 59,
|
|
62
|
+
PRECISION = 60,
|
|
63
|
+
PRECISE = 61,
|
|
64
|
+
HIGHP = 62,
|
|
65
|
+
MEDIUMP = 63,
|
|
66
|
+
LOWP = 64,
|
|
67
|
+
INVARIANT = 65,
|
|
68
|
+
SMOOTH = 66,
|
|
69
|
+
FLAT = 67,
|
|
70
|
+
NOPERSPECTIVE = 68,
|
|
71
|
+
True = 69,
|
|
72
|
+
False = 70,
|
|
73
|
+
LeftBrace = 71,
|
|
74
|
+
RightBrace = 72,
|
|
75
|
+
Equal = 73,
|
|
76
|
+
BitwiseOr = 74,
|
|
77
|
+
GSRenderQueueType = 75,
|
|
78
|
+
GSBlendState = 76,
|
|
79
|
+
GSDepthState = 77,
|
|
80
|
+
GSStencilState = 78,
|
|
81
|
+
GSRasterState = 79,
|
|
82
|
+
GSEditorProperties = 80,
|
|
83
|
+
GSEditorMacros = 81,
|
|
84
|
+
GSEditor = 82,
|
|
85
|
+
GSTags = 83,
|
|
86
|
+
GSVertexShader = 84,
|
|
87
|
+
GSFragmentShader = 85,
|
|
88
|
+
GSSubShader = 86,
|
|
89
|
+
GSPass = 87,
|
|
90
|
+
GSBlendFactor = 88,
|
|
91
|
+
GSBlendOperation = 89,
|
|
92
|
+
GSBool = 90,
|
|
93
|
+
GSNumber = 91,
|
|
94
|
+
GSColor = 92,
|
|
95
|
+
GSCompareFunction = 93,
|
|
96
|
+
GSStencilOperation = 94,
|
|
97
|
+
GSCullMode = 95,
|
|
98
|
+
GSColorWriteMask = 96,
|
|
99
|
+
GSUsePass = 97,
|
|
100
|
+
MACRO_IF = 98,
|
|
101
|
+
MACRO_IFDEF = 99,
|
|
102
|
+
MACRO_IFNDEF = 100,
|
|
103
|
+
MACRO_ELSE = 101,
|
|
104
|
+
MACRO_ELIF = 102,
|
|
105
|
+
MACRO_ENDIF = 103,
|
|
106
|
+
MACRO_UNDEF = 104,
|
|
107
|
+
/** Legacy opaque `#define` token — whole directive packed into one lexeme. Retained
|
|
108
|
+
* for macros whose value can't be parsed as a GLSL expression (type aliases,
|
|
109
|
+
* qualifier aliases, partial-syntax macros). Expression-style macros instead emit
|
|
110
|
+
* `MACRO_DEFINE` + ID + value tokens + `MACRO_DEFINE_END`. */
|
|
111
|
+
MACRO_DEFINE_EXPRESSION = 105,
|
|
112
|
+
MACRO_CONDITIONAL_EXPRESSION = 106,
|
|
113
|
+
MACRO_CALL = 107,
|
|
114
|
+
/** `#define` directive head for expression-style macros. */
|
|
115
|
+
MACRO_DEFINE = 108,
|
|
116
|
+
/** Terminates a `MACRO_DEFINE` directive at end-of-line. */
|
|
117
|
+
MACRO_DEFINE_END = 109,
|
|
118
|
+
/** `(params)` block for a function-like `#define`. The lexer captures the entire
|
|
119
|
+
* parenthesized parameter list as one opaque token so the macro-define CFG rule
|
|
120
|
+
* doesn't need its own parameter-list production (which would conflict with
|
|
121
|
+
* function_call_parameter_list under LALR(1)). The AST consumer parses the
|
|
122
|
+
* lexeme to recover the individual parameter names. */
|
|
123
|
+
MACRO_DEFINE_PARAMS = 110
|
|
124
|
+
}
|