@galacean/engine-shader-compiler 2.0.0-alpha.43 → 2.0.0-alpha.45

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/dist/main.js CHANGED
@@ -8924,7 +8924,7 @@ ShaderCompiler._shaderPositionPool = ShaderCompilerUtils.createObjectPool(Shader
8924
8924
  ShaderCompiler._shaderRangePool = ShaderCompilerUtils.createObjectPool(ShaderRange);
8925
8925
 
8926
8926
  //@ts-ignore
8927
- var version = "2.0.0-alpha.43";
8927
+ var version = "2.0.0-alpha.45";
8928
8928
  var mode = "Release";
8929
8929
  console.log("Galacean Engine Shader Compiler Version: " + version + " | Mode: " + mode);
8930
8930
 
@@ -9586,7 +9586,7 @@ ShaderCompiler._shaderPositionPool = ShaderCompilerUtils.createObjectPool(Shader
9586
9586
  ShaderCompiler._shaderRangePool = ShaderCompilerUtils.createObjectPool(ShaderRange);
9587
9587
 
9588
9588
  //@ts-ignore
9589
- var version = "2.0.0-alpha.43";
9589
+ var version = "2.0.0-alpha.45";
9590
9590
  var mode = "Release";
9591
9591
  mode = "Verbose";
9592
9592
  console.log("Galacean Engine Shader Compiler Version: " + version + " | Mode: " + mode);
package/dist/module.js CHANGED
@@ -8920,7 +8920,7 @@ ShaderCompiler._shaderPositionPool = ShaderCompilerUtils.createObjectPool(Shader
8920
8920
  ShaderCompiler._shaderRangePool = ShaderCompilerUtils.createObjectPool(ShaderRange);
8921
8921
 
8922
8922
  //@ts-ignore
8923
- var version = "2.0.0-alpha.43";
8923
+ var version = "2.0.0-alpha.45";
8924
8924
  var mode = "Release";
8925
8925
  console.log("Galacean Engine Shader Compiler Version: " + version + " | Mode: " + mode);
8926
8926
 
@@ -9582,7 +9582,7 @@ ShaderCompiler._shaderPositionPool = ShaderCompilerUtils.createObjectPool(Shader
9582
9582
  ShaderCompiler._shaderRangePool = ShaderCompilerUtils.createObjectPool(ShaderRange);
9583
9583
 
9584
9584
  //@ts-ignore
9585
- var version = "2.0.0-alpha.43";
9585
+ var version = "2.0.0-alpha.45";
9586
9586
  var mode = "Release";
9587
9587
  mode = "Verbose";
9588
9588
  console.log("Galacean Engine Shader Compiler Version: " + version + " | Mode: " + mode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/engine-shader-compiler",
3
- "version": "2.0.0-alpha.43",
3
+ "version": "2.0.0-alpha.45",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -57,11 +57,11 @@
57
57
  ],
58
58
  "dependencies": {
59
59
  "@rollup/pluginutils": "^5.0.0",
60
- "@galacean/engine-math": "2.0.0-alpha.43",
61
- "@galacean/engine-core": "2.0.0-alpha.43"
60
+ "@galacean/engine-math": "2.0.0-alpha.45",
61
+ "@galacean/engine-core": "2.0.0-alpha.45"
62
62
  },
63
63
  "devDependencies": {
64
- "@galacean/engine-design": "2.0.0-alpha.43"
64
+ "@galacean/engine-design": "2.0.0-alpha.45"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "rollup -c rollup.config.js && node -e \"require('fs').chmodSync('bundler/cli.js', 0o755)\"",
@@ -36,4 +36,8 @@ export declare class ParserUtils {
36
36
  static typeCompatible(ta: GalaceanDataType, tb: GalaceanDataType | undefined): boolean;
37
37
  static toString(sm: GrammarSymbol): string;
38
38
  static isTerminal(sm: GrammarSymbol): boolean;
39
+ /**
40
+ * @internal
41
+ */
42
+ static printStatePool(logPath: string): void;
39
43
  }
@@ -18,4 +18,8 @@ export declare class ShaderCompiler {
18
18
  _parseShaderPass(source: string, vertexEntry: string, fragmentEntry: string, backend: ShaderLanguage, basePathForIncludeKey: string): IShaderProgramSource | undefined;
19
19
  _precompile(sourceCode: string, platformTarget: ShaderLanguage, basePathForIncludeKey: string): IPrecompiledShader;
20
20
  private _serializeRenderStates;
21
+ /**
22
+ * @internal
23
+ */
24
+ _logErrors(errors: Error[]): void;
21
25
  }
@@ -1 +1,31 @@
1
+ import type { ShaderInstruction } from "@galacean/engine-design";
1
2
  export type { ShaderInstruction } from "@galacean/engine-design";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare class ShaderInstructionEncoder {
7
+ private static _DIRECTIVE_RE;
8
+ private static _FUNC_MACRO_RE;
9
+ static parse(glsl: string): ShaderInstruction[];
10
+ private static _pushConditionInstruction;
11
+ private static _findDirectiveStart;
12
+ private static _pushText;
13
+ /**
14
+ * Backfill jump offset of an IF/ELIF instruction.
15
+ * When onlyPlaceholder is true, only backfill if the current value is still -1
16
+ */
17
+ private static _backfillJump;
18
+ private static _stripLineComment;
19
+ private static _parseCondition;
20
+ private static _skipWs;
21
+ private static _parseOr;
22
+ private static _parseAnd;
23
+ private static _parseUnary;
24
+ private static _parsePrimary;
25
+ private static _isDigit;
26
+ private static _isAlnum;
27
+ private static _scanIdentifier;
28
+ private static _scanNumber;
29
+ private static _scanOp;
30
+ private static _evalNumOp;
31
+ }
@@ -1 +1,38 @@
1
- export {};
1
+ import { ShaderPosition, ShaderRange } from "../common";
2
+ import { ASTNode } from "../parser/AST";
3
+ import { NodeChild, StructProp } from "../parser/types";
4
+ import { ReturnableObjectPool } from "@galacean/engine-core";
5
+ import { TempArray } from "../TempArray";
6
+ /**
7
+ * @internal
8
+ * The code generator
9
+ */
10
+ export declare abstract class CodeGenVisitor {
11
+ readonly errors: Error[];
12
+ abstract getAttributeProp(prop: StructProp): string;
13
+ abstract getVaryingProp(prop: StructProp): string;
14
+ abstract getMRTProp(prop: StructProp): string;
15
+ protected static _tmpArrayPool: ReturnableObjectPool<TempArray<string>>;
16
+ defaultCodeGen(children: NodeChild[]): string;
17
+ visitPostfixExpression(node: ASTNode.PostfixExpression): string;
18
+ visitVariableIdentifier(node: ASTNode.VariableIdentifier): string;
19
+ visitFunctionCall(node: ASTNode.FunctionCall): string;
20
+ visitMacroCallFunction(node: ASTNode.MacroCallFunction): string;
21
+ visitStatementList(node: ASTNode.StatementList): string;
22
+ /**
23
+ * Code-generate a `#define` macro parsed as expression AST. Produces a `#define`
24
+ * directive whose value is the AST-rewritten string — so varying flattening
25
+ * happens naturally via `visitPostfixExpression` inside the AST walk.
26
+ */
27
+ visitMacroDefine(node: ASTNode.MacroDefine): string;
28
+ visitSingleDeclaration(node: ASTNode.SingleDeclaration): string;
29
+ visitGlobalVariableDeclaration(node: ASTNode.VariableDeclaration): string;
30
+ visitDeclaration(node: ASTNode.Declaration): string;
31
+ visitFunctionParameterList(node: ASTNode.FunctionParameterList): string;
32
+ visitFunctionHeader(node: ASTNode.FunctionHeader): string;
33
+ visitJumpStatement(node: ASTNode.JumpStatement): string;
34
+ visitFunctionIdentifier(node: ASTNode.FunctionIdentifier): string;
35
+ visitStructSpecifier(node: ASTNode.StructSpecifier): string;
36
+ visitFunctionDefinition(fnNode: ASTNode.FunctionDefinition): string;
37
+ protected _reportError(loc: ShaderRange | ShaderPosition, message: string): void;
38
+ }
@@ -1 +1,33 @@
1
- export {};
1
+ import type { IShaderInfo } from "@galacean/engine-design";
2
+ import { ASTNode } from "../parser/AST";
3
+ import { ShaderData } from "../parser/ShaderInfo";
4
+ import { CodeGenVisitor } from "./CodeGenVisitor";
5
+ import { ICodeSegment } from "./types";
6
+ /**
7
+ * @internal
8
+ */
9
+ export declare abstract class GLESVisitor extends CodeGenVisitor {
10
+ private _globalCodeArray;
11
+ private static _lookupSymbol;
12
+ private static _serializedGlobalKey;
13
+ reset(): void;
14
+ getOtherGlobal(data: ShaderData, out: ICodeSegment[]): void;
15
+ visitShaderProgram(node: ASTNode.GLShaderProgram, vertexEntry: string, fragmentEntry: string): IShaderInfo;
16
+ /** Populate `_structVarMap` for varying/attribute/mrt-typed variables across both stages before codegen. */
17
+ private _collectAllStructVars;
18
+ private _vertexMain;
19
+ private _fragmentMain;
20
+ private _extractLocalVarNames;
21
+ /**
22
+ * Pre-walk `#define` values in global macro declarations and register any
23
+ * `structVar.prop` member accesses as referenced struct props. This must run before
24
+ * struct codegen emits the declaration lists (`attribute …`, `varying …`, `MRT …`),
25
+ * otherwise properties used only from macros would be missing from the output.
26
+ */
27
+ private _preRegisterGlobalMacroRefs;
28
+ private _walkMacroDefineTokens;
29
+ private _getGlobalSymbol;
30
+ private _getCustomStruct;
31
+ private _getGlobalMacroDeclarations;
32
+ private _visitGlobalMacroIfStatement;
33
+ }
@@ -1,2 +1,49 @@
1
+ import { BaseToken } from "../common/BaseToken";
2
+ import { EShaderStage } from "../common/enums/ShaderStage";
3
+ import { SymbolTable } from "../common/SymbolTable";
4
+ import { ASTNode, TreeNode } from "../parser/AST";
5
+ import { ESymbolType, SymbolInfo } from "../parser/symbolTable";
6
+ import { StructProp } from "../parser/types";
1
7
  /** Role of a struct type in the shader compiler's IO flattening. */
2
8
  export type StructRole = "varying" | "attribute" | "mrt";
9
+ /** @internal */
10
+ export declare class VisitorContext {
11
+ private static _lookupSymbol;
12
+ private static _singleton;
13
+ static get context(): VisitorContext;
14
+ static reset(): void;
15
+ attributeStructs: ASTNode.StructSpecifier[];
16
+ attributeList: StructProp[];
17
+ varyingStructs: ASTNode.StructSpecifier[];
18
+ varyingList: StructProp[];
19
+ mrtStructs: ASTNode.StructSpecifier[];
20
+ mrtList: StructProp[];
21
+ stage: EShaderStage;
22
+ stageEntry: string;
23
+ _referencedAttributeList: Record<string, StructProp[]>;
24
+ _referencedVaryingList: Record<string, StructProp[]>;
25
+ _referencedMRTList: Record<string, StructProp[]>;
26
+ _referencedGlobals: Record<string, SymbolInfo[]>;
27
+ _referencedGlobalMacroASTs: TreeNode[];
28
+ /**
29
+ * Maps variable names (function params, locals, and globals whose type is a
30
+ * varying/attribute/mrt struct) to their role. Populated during stage setup and
31
+ * used by macro-value rewriting to recognize `varName.prop` patterns that should
32
+ * be flattened against the IO lists.
33
+ */
34
+ _structVarMap: Record<string, StructRole>;
35
+ _passSymbolTable: SymbolTable<SymbolInfo>;
36
+ reset(resetAll?: boolean): void;
37
+ isAttributeStruct(type: string): boolean;
38
+ isVaryingStruct(type: string): boolean;
39
+ isMRTStruct(type: string): boolean;
40
+ /** Return the role of a struct type, or undefined if it isn't one of the IO roles. */
41
+ getStructRole(typeLexeme: string): StructRole | undefined;
42
+ /** Register a variable as holding a value of a varying/attribute/mrt struct type. */
43
+ registerStructVar(varName: string, role: StructRole): void;
44
+ referenceAttribute(ident: BaseToken): Error | void;
45
+ referenceVarying(ident: BaseToken): Error | void;
46
+ referenceMRTProp(ident: BaseToken): Error | void;
47
+ referenceGlobal(ident: string, type: ESymbolType): void;
48
+ private _referenceProp;
49
+ }
@@ -1,2 +1,51 @@
1
+ import { ShaderPosition, ShaderRange } from ".";
1
2
  import { BaseToken } from "./BaseToken";
2
3
  export type OnToken = (token: BaseToken, scanner: BaseLexer) => void;
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare abstract class BaseLexer {
8
+ static isDigit(charCode: number): boolean;
9
+ static isHexDigit(charCode: number): boolean;
10
+ static isAlpha(charCode: number): boolean;
11
+ static isAlnum(charCode: number): boolean;
12
+ static isPreprocessorStartChar(charCode: number): boolean;
13
+ /**
14
+ * If `i` points at the start of a `/* … *\/` block comment, return the index
15
+ * just past the closing `*\/`. Otherwise return `i` unchanged. If the
16
+ * comment is unterminated, returns `len` (clamped, never overshoots).
17
+ * Single source of truth for block-comment scanning across the lexer.
18
+ */
19
+ protected static _skipBlockComment(src: string, i: number, len: number): number;
20
+ /**
21
+ * If `i` points at the start of a `//` line comment, return the index of the
22
+ * terminating newline (or `len` at EOF). The newline itself is NOT consumed
23
+ * — callers decide whether `\n` is whitespace or a logical separator.
24
+ * Otherwise return `i` unchanged.
25
+ */
26
+ protected static _skipLineComment(src: string, i: number, len: number): number;
27
+ static isWhiteSpaceChar(charCode: number, includeBreak: boolean): boolean;
28
+ protected _currentIndex: number;
29
+ protected _source: string;
30
+ protected _column: number;
31
+ protected _line: number;
32
+ get currentIndex(): number;
33
+ get source(): string;
34
+ get line(): number;
35
+ get column(): number;
36
+ constructor(source?: string);
37
+ setSource(source: string): void;
38
+ getShaderPosition(backOffset?: number): ShaderPosition;
39
+ isEnd(): boolean;
40
+ getCurChar(): string;
41
+ getCurCharCode(): number;
42
+ advance(count: number): void;
43
+ skipSpace(includeLineBreak: boolean): void;
44
+ skipCommentsAndSpace(): void;
45
+ peek(to: number): string;
46
+ scanLexeme(lexeme: string): void;
47
+ scanTwoExpectedLexemes(lexeme1: string, lexeme2: string): string | null;
48
+ throwError(pos: ShaderPosition | ShaderRange, ...msgs: any[]): void;
49
+ scanPairedChar(left: string, right: string, balanced: boolean, skipLeading: boolean): string;
50
+ abstract scanToken(onToken?: OnToken): void;
51
+ }
@@ -4,6 +4,10 @@ export declare class SymbolTable<T extends IBaseSymbol> {
4
4
  insert(symbol: T, isInMacroBranch?: boolean): void;
5
5
  getSymbol(symbol: T, includeMacro?: boolean): T | undefined;
6
6
  getSymbols(symbol: T, includeMacro: boolean, out: T[]): T[];
7
+ /**
8
+ * @internal
9
+ */
10
+ _getSymbols(symbol: T, includeMacro: boolean, out: T[]): T[];
7
11
  /** Iterate every registered symbol. Order within a name bucket is insertion order. */
8
12
  forEach(callback: (symbol: T) => void): void;
9
13
  }
@@ -2,6 +2,10 @@ import { IBaseSymbol } from "./IBaseSymbol";
2
2
  import { SymbolTable } from "./SymbolTable";
3
3
  export declare class SymbolTableStack<S extends IBaseSymbol, T extends SymbolTable<S>> {
4
4
  stack: T[];
5
+ /**
6
+ * @internal
7
+ */
8
+ _macroLevel: number;
5
9
  get scope(): T;
6
10
  get isInMacroBranch(): boolean;
7
11
  pushScope(scope: T): void;
@@ -1,2 +1,42 @@
1
+ import { ShaderRange } from "../common";
2
+ import { SymbolTable } from "../common/SymbolTable";
3
+ import { SymbolTableStack } from "../common/SymbolTableStack";
4
+ import { SymbolInfo } from "../parser/symbolTable";
5
+ import { ASTNode, TreeNode } from "./AST";
6
+ import { ShaderData } from "./ShaderInfo";
1
7
  import { NodeChild } from "./types";
8
+ import { MacroDefineList } from "../Preprocessor";
2
9
  export type TranslationRule<T = any> = (sa: SemanticAnalyzer, ...tokens: NodeChild[]) => T;
10
+ /**
11
+ * @internal
12
+ * The semantic analyzer of `ShaderCompiler` compiler.
13
+ * - Build symbol table
14
+ * - Static analysis
15
+ */
16
+ export default class SemanticAnalyzer {
17
+ /**
18
+ * @internal
19
+ */
20
+ static _lookupSymbol: SymbolInfo;
21
+ semanticStack: TreeNode[];
22
+ acceptRule?: TranslationRule;
23
+ symbolTableStack: SymbolTableStack<SymbolInfo, SymbolTable<SymbolInfo>>;
24
+ curFunctionInfo: {
25
+ header?: ASTNode.FunctionDeclarator;
26
+ returnStatement?: ASTNode.JumpStatement;
27
+ };
28
+ private _shaderData;
29
+ private _translationRuleTable;
30
+ private _macroDefineList;
31
+ readonly errors: Error[];
32
+ get shaderData(): ShaderData;
33
+ get macroDefineList(): MacroDefineList;
34
+ constructor();
35
+ reset(macroDefineList: MacroDefineList): void;
36
+ pushScope(): void;
37
+ popScope(): SymbolTable<SymbolInfo>;
38
+ addTranslationRule(pid: number, rule: TranslationRule): void;
39
+ getTranslationRule(pid: number): TranslationRule<any>;
40
+ reportError(loc: ShaderRange, message: string): void;
41
+ reportWarning(loc: ShaderRange, message: string): void;
42
+ }
@@ -16,6 +16,8 @@ export declare class ShaderTargetParser {
16
16
  private get curState();
17
17
  private get stateActionTable();
18
18
  private get stateGotoTable();
19
+ /** @internal */
20
+ get errors(): Error[];
19
21
  static _singleton: ShaderTargetParser;
20
22
  static create(): ShaderTargetParser;
21
23
  private constructor();
@@ -1 +1,30 @@
1
- export {};
1
+ import type { IShaderSource } from "@galacean/engine-design";
2
+ import { GSError } from "../GSError";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare class ShaderSourceParser {
7
+ static readonly errors: GSError[];
8
+ private static _renderStateConstMap;
9
+ private static _symbolTableStack;
10
+ private static _lexer;
11
+ private static _lookupSymbol;
12
+ static parse(sourceCode: string): IShaderSource;
13
+ private static _parseShader;
14
+ private static _parseRenderStateDeclarationOrAssignment;
15
+ private static _mergeRenderStates;
16
+ private static _parseVariableDeclaration;
17
+ private static _pushScope;
18
+ private static _popScope;
19
+ private static _parseRenderStateProperties;
20
+ private static _createCompileError;
21
+ private static _scanEnumConstValue;
22
+ private static _parseRenderStateProperty;
23
+ private static _parseRenderQueueDeclarationOrAssignment;
24
+ private static _addPendingContents;
25
+ private static _parseSubShader;
26
+ private static _parseTags;
27
+ private static _parsePass;
28
+ private static _parseRenderStateAndTags;
29
+ private static _parseRenderState;
30
+ }