@galacean/engine-shader-compiler 2.0.0-alpha.54 → 2.0.0-alpha.56

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/engine-shader-compiler",
3
- "version": "2.0.0-alpha.54",
3
+ "version": "2.0.0-alpha.56",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -56,10 +56,10 @@
56
56
  ],
57
57
  "dependencies": {
58
58
  "@rollup/pluginutils": "^5.0.0",
59
- "@galacean/engine-math": "2.0.0-alpha.54",
60
- "@galacean/engine-core": "2.0.0-alpha.54",
61
- "@galacean/engine-shader-parser": "2.0.0-alpha.54",
62
- "@galacean/engine-design": "2.0.0-alpha.54"
59
+ "@galacean/engine-core": "2.0.0-alpha.56",
60
+ "@galacean/engine-design": "2.0.0-alpha.56",
61
+ "@galacean/engine-shader-parser": "2.0.0-alpha.56",
62
+ "@galacean/engine-math": "2.0.0-alpha.56"
63
63
  },
64
64
  "typesVersions": {
65
65
  "*": {
@@ -1,3 +1,4 @@
1
+ import { BaseToken } from "@galacean/engine-shader-parser/internal";
1
2
  import { ASTNode, TreeNode } from "@galacean/engine-shader-parser/internal";
2
3
  import { FnSymbol } from "@galacean/engine-shader-parser/internal";
3
4
  import { NodeChild, StructProp } from "@galacean/engine-shader-parser/internal";
@@ -18,6 +19,13 @@ export declare abstract class CodeGenVisitor implements ICodeGenVisitor {
18
19
  cache(node: TreeNode, code: string): string;
19
20
  getCachedCode(node: TreeNode): string | undefined;
20
21
  defaultCodeGen(children: NodeChild[]): string;
22
+ /**
23
+ * Spells a source token in the generated code.
24
+ * @param token - Source token
25
+ * @returns Generated text for the token
26
+ */
27
+ protected tokenLexeme(token: BaseToken): string;
28
+ protected interfaceMemberName(name: string): string;
21
29
  visitPostfixExpression(node: ASTNode.PostfixExpression): string;
22
30
  visitVariableIdentifier(node: ASTNode.VariableIdentifier): string;
23
31
  protected referenceFunction(symbol: FnSymbol, referenceIndex: number, branch: BranchSignature): void;
@@ -26,8 +34,7 @@ export declare abstract class CodeGenVisitor implements ICodeGenVisitor {
26
34
  visitStatementList(node: ASTNode.StatementList): string;
27
35
  /**
28
36
  * Code-generate a `#define` macro parsed as expression AST. Produces a `#define`
29
- * directive whose value is the AST-rewritten string — so varying flattening
30
- * happens naturally via `visitPostfixExpression` inside the AST walk.
37
+ * directive whose value retains ordinary expression and member-access semantics.
31
38
  */
32
39
  visitMacroDefine(node: ASTNode.MacroDefine): string;
33
40
  visitSingleDeclaration(node: ASTNode.SingleDeclaration): string;
@@ -1,10 +1,10 @@
1
- import { ASTNode } from "@galacean/engine-shader-parser/internal";
2
1
  import { StructProp } from "@galacean/engine-shader-parser/internal";
3
2
  import { GLESVisitor } from "./GLESVisitor";
4
3
  export declare class GLES100Visitor extends GLESVisitor {
4
+ protected readonly supportsArrayStructReturn = false;
5
5
  getAttributeProp(prop: StructProp): string;
6
6
  getVaryingProp(prop: StructProp): string;
7
7
  getMRTProp(): string;
8
- visitPostfixExpression(node: ASTNode.PostfixExpression): string;
9
- visitJumpStatement(node: ASTNode.JumpStatement): string;
8
+ protected fragmentColorOutput(): string;
9
+ protected mrtOutput(prop: StructProp): string;
10
10
  }
@@ -17,7 +17,10 @@ export declare class GLES300Visitor extends GLESVisitor {
17
17
  visitFunctionIdentifier(node: ASTNode.FunctionIdentifier): string;
18
18
  visitVariableIdentifier(node: ASTNode.VariableIdentifier): string;
19
19
  visitPostfixExpression(node: ASTNode.PostfixExpression): string;
20
- visitJumpStatement(node: ASTNode.JumpStatement): string;
20
+ protected fragmentColorOutput(): string;
21
+ protected mrtOutput(prop: StructProp): string;
22
+ private _fragmentColorName;
23
+ private _fragmentDataName;
21
24
  private _registerFragColorVariable;
22
25
  private _registerOutput;
23
26
  protected prepareFragment(entryInfo: ShaderEntryPointInfo, outerGlobalMacroStatements: readonly ASTNode.GlobalDeclaration[]): void;
@@ -1,9 +1,12 @@
1
1
  import type { IShaderInfo } from "@galacean/engine-design";
2
2
  import type { IPoolElement } from "@galacean/engine-core";
3
+ import { BaseToken } from "@galacean/engine-shader-parser/internal";
3
4
  import { ASTNode } from "@galacean/engine-shader-parser/internal";
5
+ import { NodeChild } from "@galacean/engine-shader-parser/internal";
4
6
  import { ShaderData } from "@galacean/engine-shader-parser/internal";
5
7
  import { FnSymbol } from "@galacean/engine-shader-parser/internal";
6
- import type { BranchSignature, ShaderClueIR, ShaderCoreInfo, ShaderEntryPointInfo, DeferredDeclarationOwnership } from "@galacean/engine-shader-parser/internal";
8
+ import { ShaderStructRole } from "@galacean/engine-shader-parser/internal";
9
+ import type { BranchSignature, StructProp, ShaderClueIR, ShaderCoreInfo, ShaderEntryPointInfo, DeferredDeclarationOwnership } from "@galacean/engine-shader-parser/internal";
7
10
  import { CodeGenVisitor } from "./CodeGenVisitor";
8
11
  import { ICodeSegment } from "./types";
9
12
  import type { ShaderBackend } from "../ShaderBackend";
@@ -11,6 +14,16 @@ import type { ShaderBackend } from "../ShaderBackend";
11
14
  * @internal
12
15
  */
13
16
  export declare abstract class GLESVisitor extends CodeGenVisitor implements ShaderBackend, IPoolElement {
17
+ protected readonly supportsArrayStructReturn: boolean;
18
+ /** Names of pass-scope declarations, which stage-interface globals must not redeclare. */
19
+ private readonly _globalNames;
20
+ /** Interface type and variable tokens whose source names GLSL ES rejects. */
21
+ private readonly _escapedDeclarations;
22
+ private _vertexOutputNames?;
23
+ private readonly _fragmentVaryingProps;
24
+ private readonly _globalInputs;
25
+ private readonly _inputHelperBodies;
26
+ private readonly _inputHelperGroups;
14
27
  private _globalCodeArray;
15
28
  private readonly _forwardFunctionDeclarations;
16
29
  private readonly _forwardStructIndices;
@@ -47,6 +60,37 @@ export declare abstract class GLESVisitor extends CodeGenVisitor implements Shad
47
60
  generate(ir: ShaderClueIR, coreInfo: ShaderCoreInfo): IShaderInfo;
48
61
  private _vertexMain;
49
62
  private _fragmentMain;
63
+ private _referenceInterfaceDependencies;
64
+ /**
65
+ * Resolves an interface member's global name, shared by both stages for varyings.
66
+ * @param prop - Interface member
67
+ * @param role - Stage-interface role of the member's structure
68
+ * @returns Generated global identifier
69
+ */
70
+ protected interfaceName(prop: StructProp, role: ShaderStructRole): string;
71
+ protected interfaceMemberName(name: string): string;
72
+ private _interfaceTypeName;
73
+ /**
74
+ * Escapes interface-typed variables whose names GLSL ES reserves.
75
+ * @param name - Source name
76
+ * @param structs - Struct declarations of the variable type
77
+ * @returns The escaped name, or the source name when no escape is necessary
78
+ */
79
+ private _interfaceVariableName;
80
+ private _collectEscapedDeclarations;
81
+ protected tokenLexeme(token: BaseToken): string;
82
+ private _escapedReference;
83
+ protected abstract fragmentColorOutput(): string;
84
+ protected abstract mrtOutput(prop: StructProp): string;
85
+ private _transferName;
86
+ visitStructSpecifier(node: ASTNode.StructSpecifier): string;
87
+ private _containsArray;
88
+ defaultCodeGen(children: NodeChild[]): string;
89
+ private _observeWholeStruct;
90
+ visitFunctionHeader(node: ASTNode.FunctionHeader): string;
91
+ visitFunctionIdentifier(node: ASTNode.FunctionIdentifier): string;
92
+ visitFunctionDefinition(fnNode: ASTNode.FunctionDefinition): string;
93
+ private _initializeGlobalInputs;
50
94
  protected prepareFragment(entryInfo: ShaderEntryPointInfo, outerGlobalMacroStatements: readonly ASTNode.GlobalDeclaration[]): void;
51
95
  /**
52
96
  * Pre-walk `#define` values in global macro declarations and register any
@@ -56,7 +100,6 @@ export declare abstract class GLESVisitor extends CodeGenVisitor implements Shad
56
100
  */
57
101
  private _preRegisterGlobalMacroRefs;
58
102
  private _walkMacroDefineTokens;
59
- private _registerFragmentReturns;
60
103
  private _getGlobalSymbol;
61
104
  protected referenceFunction(symbol: FnSymbol, referenceIndex: number, branch: BranchSignature): void;
62
105
  private _getForwardSignature;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Tests whether GLSL ES rejects an identifier that ShaderLab accepts.
3
+ * @param name - Source identifier
4
+ * @returns Whether the identifier uses a reserved word or namespace
5
+ * @internal
6
+ */
7
+ export declare function isUnsafeGLSLIdentifier(name: string): boolean;
8
+ /**
9
+ * Allocates generated identifiers that avoid source identifiers and each other.
10
+ * @internal
11
+ */
12
+ export declare class NameAllocator {
13
+ private readonly _used;
14
+ private readonly _names;
15
+ /**
16
+ * Reserves a source identifier so that generated names never shadow it.
17
+ * @param name - Source identifier
18
+ */
19
+ reserve(name: string): void;
20
+ /**
21
+ * Keeps a source identifier when GLSL accepts it, otherwise assigns a legal name to its identity.
22
+ * @param key - Source declaration or namespace identity
23
+ * @param name - Source identifier
24
+ * @returns Identifier used by the declaration and its references
25
+ */
26
+ sourceName(key: unknown, name: string): string;
27
+ /**
28
+ * Returns the same identifier for every request with the same key.
29
+ * @param key - Identity of the generated declaration, independent of its spelling
30
+ * @param preferred - Readable base name. Repeated underscores collapse to one, because WebGL rejects `__`
31
+ * @returns An identifier that differs from every reserved and previously allocated name
32
+ */
33
+ allocate(key: unknown, preferred: string): string;
34
+ /** Releases all reservations and allocations between compilation requests. */
35
+ reset(): void;
36
+ }
@@ -4,8 +4,10 @@ import { SymbolTable } from "@galacean/engine-shader-parser/internal";
4
4
  import { ASTNode, TreeNode } from "@galacean/engine-shader-parser/internal";
5
5
  import { ESymbolType, SymbolInfo, VarSymbol } from "@galacean/engine-shader-parser/internal";
6
6
  import { ShaderStructRole, StructProp } from "@galacean/engine-shader-parser/internal";
7
+ import { NameAllocator } from "./NameAllocator";
7
8
  /** @internal */
8
9
  export declare class VisitorContext {
10
+ readonly names: NameAllocator;
9
11
  private readonly _lookupSymbol;
10
12
  private readonly _structRoles;
11
13
  private readonly _vertexUnresolvedVariableRoles;
@@ -34,8 +36,6 @@ export declare class VisitorContext {
34
36
  /** Receives interface uses so generated fields retain their declaration dependencies. */
35
37
  onReferenceStructProps?: (props: readonly StructProp[]) => void;
36
38
  readonly codeCache: Map<TreeNode, string>;
37
- private readonly fragmentReturnModes;
38
- private readonly terminalInterfaceReturns;
39
39
  constructor();
40
40
  reset(resetAll?: boolean): void;
41
41
  /**
@@ -78,31 +78,9 @@ export declare class VisitorContext {
78
78
  * @returns Interface role, or `undefined` when the reference is not an unambiguous interface value.
79
79
  */
80
80
  getStructVarRole(symbols: readonly SymbolInfo[]): ShaderStructRole | undefined;
81
- /**
82
- * Marks a value-return belonging to a fragment entry for backend lowering.
83
- * @param statement - Exact return statement identity.
84
- * @param mode - Fragment output contract of the containing entry declaration.
85
- */
86
- registerFragmentReturn(statement: ASTNode.JumpStatement, mode: FragmentReturnMode): void;
87
- /**
88
- * Finds the output contract for a fragment-entry return statement.
89
- * @param statement - Return statement identity.
90
- * @returns Output mode, or `undefined` for ordinary helper/vertex returns.
91
- */
92
- getFragmentReturnMode(statement: ASTNode.JumpStatement): FragmentReturnMode | undefined;
93
- /** Marks a syntactically final interface return whose control-flow exit can be omitted. */
94
- registerTerminalInterfaceReturn(statement: ASTNode.JumpStatement): void;
95
- /**
96
- * Tests whether an interface return is the final syntactic statement in its function.
97
- * @param statement - Return statement identity.
98
- * @returns Whether backend lowering may omit a trailing `return;`.
99
- */
100
- isTerminalInterfaceReturn(statement: ASTNode.JumpStatement): boolean;
101
81
  referenceAttribute(ident: BaseToken): void;
102
82
  referenceVarying(ident: BaseToken): void;
103
83
  referenceMRTProp(ident: BaseToken): void;
104
84
  referenceGlobal(ident: string, type: ESymbolType): void;
105
85
  private _referenceProp;
106
86
  }
107
- /** @internal */
108
- export type FragmentReturnMode = "color" | "mrt";