@galacean/engine-shader-compiler 2.0.0-alpha.51 → 2.0.0-alpha.53

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.
Files changed (91) hide show
  1. package/README.md +40 -4
  2. package/bundler/cli.js +199 -104
  3. package/bundler/precompile.cjs.js +117 -47
  4. package/bundler/precompile.js +117 -47
  5. package/bundler/rollup.cjs.js +115 -45
  6. package/bundler/rollup.js +115 -45
  7. package/dist/browser.js +13421 -6555
  8. package/dist/browser.js.map +1 -1
  9. package/dist/browser.min.js +1 -1
  10. package/dist/browser.min.js.map +1 -1
  11. package/dist/main.js +1758 -8450
  12. package/dist/main.js.map +1 -1
  13. package/dist/module.js +1730 -8427
  14. package/dist/module.js.map +1 -1
  15. package/dist/precompile.main.js +2280 -0
  16. package/dist/precompile.main.js.map +1 -0
  17. package/dist/precompile.module.js +2276 -0
  18. package/dist/precompile.module.js.map +1 -0
  19. package/package.json +24 -13
  20. package/types/GLESBackend.d.ts +22 -0
  21. package/types/ShaderBackend.d.ts +15 -0
  22. package/types/ShaderCompilation.d.ts +40 -0
  23. package/types/ShaderCompiler.d.ts +42 -14
  24. package/types/ShaderInstructionEncoder.d.ts +46 -14
  25. package/types/ShaderPrecompiler.d.ts +31 -0
  26. package/types/bundler/precompile.d.ts +26 -3
  27. package/types/bundler/rollup.d.ts +23 -2
  28. package/types/codeGen/CodeGenVisitor.d.ts +11 -6
  29. package/types/codeGen/GLES100.d.ts +3 -5
  30. package/types/codeGen/GLES300.d.ts +14 -7
  31. package/types/codeGen/GLESVisitor.d.ts +55 -9
  32. package/types/codeGen/VisitorContext.d.ts +88 -29
  33. package/types/codeGen/types.d.ts +1 -1
  34. package/types/index.d.ts +4 -1
  35. package/types/precompile.d.ts +1 -0
  36. package/dist/browser.verbose.js +0 -9601
  37. package/dist/browser.verbose.js.map +0 -1
  38. package/dist/browser.verbose.min.js +0 -2
  39. package/dist/browser.verbose.min.js.map +0 -1
  40. package/dist/main.verbose.js +0 -9598
  41. package/dist/main.verbose.js.map +0 -1
  42. package/dist/module.verbose.js +0 -9591
  43. package/dist/module.verbose.js.map +0 -1
  44. package/types/GSError.d.ts +0 -16
  45. package/types/ParserUtils.d.ts +0 -43
  46. package/types/Preprocessor.d.ts +0 -30
  47. package/types/ShaderCompilerUtils.d.ts +0 -10
  48. package/types/common/BaseLexer.d.ts +0 -51
  49. package/types/common/BaseToken.d.ts +0 -35
  50. package/types/common/IBaseSymbol.d.ts +0 -5
  51. package/types/common/ShaderPosition.d.ts +0 -8
  52. package/types/common/ShaderRange.d.ts +0 -8
  53. package/types/common/SymbolTable.d.ts +0 -13
  54. package/types/common/SymbolTableStack.d.ts +0 -17
  55. package/types/common/enums/Keyword.d.ts +0 -124
  56. package/types/common/enums/ShaderStage.d.ts +0 -5
  57. package/types/common/index.d.ts +0 -5
  58. package/types/common/types.d.ts +0 -101
  59. package/types/lalr/CFG.d.ts +0 -5
  60. package/types/lalr/LALR1.d.ts +0 -27
  61. package/types/lalr/Production.d.ts +0 -9
  62. package/types/lalr/State.d.ts +0 -20
  63. package/types/lalr/StateItem.d.ts +0 -20
  64. package/types/lalr/Utils.d.ts +0 -22
  65. package/types/lalr/index.d.ts +0 -2
  66. package/types/lalr/types.d.ts +0 -14
  67. package/types/lexer/Lexer.d.ts +0 -143
  68. package/types/lexer/index.d.ts +0 -1
  69. package/types/parser/AST.d.ts +0 -502
  70. package/types/parser/Grammar.d.ts +0 -11
  71. package/types/parser/GrammarSymbol.d.ts +0 -128
  72. package/types/parser/SemanticAnalyzer.d.ts +0 -42
  73. package/types/parser/ShaderInfo.d.ts +0 -10
  74. package/types/parser/ShaderTargetParser.d.ts +0 -26
  75. package/types/parser/builtin/functions.d.ts +0 -34
  76. package/types/parser/builtin/index.d.ts +0 -2
  77. package/types/parser/builtin/variables.d.ts +0 -11
  78. package/types/parser/index.d.ts +0 -2
  79. package/types/parser/symbolTable/FnSymbol.d.ts +0 -6
  80. package/types/parser/symbolTable/StructSymbol.d.ts +0 -6
  81. package/types/parser/symbolTable/SymbolDataType.d.ts +0 -8
  82. package/types/parser/symbolTable/SymbolInfo.d.ts +0 -22
  83. package/types/parser/symbolTable/VarSymbol.d.ts +0 -8
  84. package/types/parser/symbolTable/index.d.ts +0 -6
  85. package/types/parser/types.d.ts +0 -24
  86. package/types/sourceParser/ShaderSourceFactory.d.ts +0 -8
  87. package/types/sourceParser/ShaderSourceParser.d.ts +0 -30
  88. package/types/sourceParser/ShaderSourceSymbol.d.ts +0 -10
  89. package/types/sourceParser/SourceLexer.d.ts +0 -19
  90. package/types/sourceParser/index.d.ts +0 -1
  91. package/verbose/package.json +0 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/engine-shader-compiler",
3
- "version": "2.0.0-alpha.51",
3
+ "version": "2.0.0-alpha.53",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -21,6 +21,11 @@
21
21
  "require": "./dist/main.js",
22
22
  "types": "./types/index.d.ts"
23
23
  },
24
+ "./precompile": {
25
+ "import": "./dist/precompile.module.js",
26
+ "require": "./dist/precompile.main.js",
27
+ "types": "./types/precompile.d.ts"
28
+ },
24
29
  "./bundler/rollup": {
25
30
  "import": "./bundler/rollup.js",
26
31
  "require": "./bundler/rollup.cjs.js",
@@ -31,11 +36,6 @@
31
36
  "require": "./bundler/precompile.cjs.js",
32
37
  "types": "./types/bundler/precompile.d.ts"
33
38
  },
34
- "./verbose": {
35
- "import": "./dist/module.verbose.js",
36
- "require": "./dist/main.verbose.js",
37
- "types": "./types/index.d.ts"
38
- },
39
39
  "./src/*": "./src/*.ts",
40
40
  "./package.json": "./package.json"
41
41
  },
@@ -52,19 +52,30 @@
52
52
  "files": [
53
53
  "dist/**/*",
54
54
  "bundler/**/*",
55
- "types/**/*",
56
- "verbose/package.json"
55
+ "types/**/*"
57
56
  ],
58
57
  "dependencies": {
59
58
  "@rollup/pluginutils": "^5.0.0",
60
- "@galacean/engine-math": "2.0.0-alpha.51",
61
- "@galacean/engine-core": "2.0.0-alpha.51"
59
+ "@galacean/engine-core": "2.0.0-alpha.53",
60
+ "@galacean/engine-design": "2.0.0-alpha.53",
61
+ "@galacean/engine-shader-parser": "2.0.0-alpha.53",
62
+ "@galacean/engine-math": "2.0.0-alpha.53"
62
63
  },
63
- "devDependencies": {
64
- "@galacean/engine-design": "2.0.0-alpha.51"
64
+ "typesVersions": {
65
+ "*": {
66
+ "precompile": [
67
+ "types/precompile.d.ts"
68
+ ],
69
+ "bundler/rollup": [
70
+ "types/bundler/rollup.d.ts"
71
+ ],
72
+ "bundler/precompile": [
73
+ "types/bundler/precompile.d.ts"
74
+ ]
75
+ }
65
76
  },
66
77
  "scripts": {
67
- "build": "rollup -c rollup.config.js && node -e \"require('fs').chmodSync('bundler/cli.js', 0o755)\"",
78
+ "build": "rollup -c rollup.config.js",
68
79
  "b:types": "tsc"
69
80
  }
70
81
  }
@@ -0,0 +1,22 @@
1
+ import type { IShaderInfo } from "@galacean/engine-design";
2
+ import { ShaderLanguage } from "@galacean/engine-core";
3
+ import { type ShaderClueIR, type ShaderCoreInfo } from "@galacean/engine-shader-parser/internal";
4
+ /**
5
+ * Static internal facade for GLES source generation.
6
+ * @internal
7
+ */
8
+ export declare class GLESBackend {
9
+ private static readonly _gles100VisitorPool;
10
+ private static readonly _gles300VisitorPool;
11
+ private constructor();
12
+ /**
13
+ * Generates one GLES program with request-owned visitor state.
14
+ * @param ir - Request-owned neutral parser IR consumed read-only.
15
+ * @param coreInfo - Entry and stage-interface facts derived from the same IR.
16
+ * @param target - GLES language version to emit.
17
+ * @returns Generated vertex and fragment source.
18
+ * @internal
19
+ */
20
+ static generate(ir: ShaderClueIR, coreInfo: ShaderCoreInfo, target: ShaderLanguage): IShaderInfo | undefined;
21
+ private static _generateWithPool;
22
+ }
@@ -0,0 +1,15 @@
1
+ import type { IShaderInfo } from "@galacean/engine-design";
2
+ import type { ShaderClueIR, ShaderCoreInfo } from "@galacean/engine-shader-parser/internal";
3
+ /**
4
+ * Internal boundary implemented by shader source backends.
5
+ * @internal
6
+ */
7
+ export interface ShaderBackend {
8
+ /**
9
+ * Generates target source from neutral shader facts.
10
+ * @param ir - Neutral shader IR backed by the parsed program.
11
+ * @param coreInfo - Entry and IO facts required by code generation.
12
+ * @returns Generated stage source.
13
+ */
14
+ generate(ir: ShaderClueIR, coreInfo: ShaderCoreInfo): IShaderInfo;
15
+ }
@@ -0,0 +1,40 @@
1
+ import { ShaderLanguage } from "@galacean/engine-core";
2
+ import type { IRenderStates, IShaderSource } from "@galacean/engine-design";
3
+ import type { IShaderProgramSource } from "@galacean/engine-design/types/shader-compiler/IShaderProgramSource";
4
+ import { ShaderCoreInfo, type ParsedShaderPassData, type ShaderSourceParseResult } from "@galacean/engine-shader-parser/internal";
5
+ /**
6
+ * Rejects a partial ShaderLab structure when source parsing produced errors.
7
+ * @param result - ShaderLab source-parser result.
8
+ * @returns Complete parsed ShaderLab structure.
9
+ * @throws ShaderSourceParseError when structural source diagnostics exist.
10
+ * @internal
11
+ */
12
+ export declare function requireValidShaderSource(result: ShaderSourceParseResult): IShaderSource;
13
+ /**
14
+ * Generates one backend program from a parser-owned pass without reparsing it.
15
+ * @param parsed - Neutral parser output.
16
+ * @param vertexEntry - Vertex entry name.
17
+ * @param fragmentEntry - Fragment entry name.
18
+ * @param backend - Target GLES language.
19
+ * @param coreInfo - Optional stage facts already derived from this exact parser result.
20
+ * @returns Generated program, or `undefined` when parser or entry admission fails.
21
+ * @internal
22
+ */
23
+ export declare function generateParsedShaderPassData(parsed: ParsedShaderPassData, vertexEntry: string, fragmentEntry: string, backend: ShaderLanguage, coreInfo?: ShaderCoreInfo): IShaderProgramSource | undefined;
24
+ /**
25
+ * Converts parser-owned render states into JSON-safe precompile data.
26
+ * @param renderStates - Parsed render-state maps.
27
+ * @returns Serializable constant and variable maps.
28
+ * @internal
29
+ */
30
+ export declare function serializeRenderStates(renderStates: IRenderStates): {
31
+ constantMap: Record<string, number | string | boolean | number[]>;
32
+ variableMap: Record<string, string>;
33
+ };
34
+ /**
35
+ * Formats a parser failure with include-source attribution.
36
+ * @param error - Parser failure.
37
+ * @returns User-facing error text.
38
+ * @internal
39
+ */
40
+ export declare function formatShaderError(error: Error): string;
@@ -1,25 +1,53 @@
1
1
  import { ShaderLanguage } from "@galacean/engine-core";
2
- import type { IPrecompiledShader, IShaderSource } from "@galacean/engine-design";
2
+ import type { IShaderSource } from "@galacean/engine-design";
3
3
  import type { IShaderProgramSource } from "@galacean/engine-design/types/shader-compiler/IShaderProgramSource";
4
- import { ShaderPosition, ShaderRange } from "./common";
5
- import { IncludeMap } from "./Preprocessor";
4
+ import { type IncludeMap } from "@galacean/engine-shader-parser/internal";
5
+ import type { ParsedShaderPass } from "@galacean/engine-shader-parser/shared";
6
+ /**
7
+ * Compiles ShaderLab sources into runtime GLES programs.
8
+ *
9
+ * Source parsing and backend generation remain independent of authoring diagnostics; structural
10
+ * source errors reject compilation before partial runtime programs can be created. Offline `.shaderc`
11
+ * validation lives in the bundler-only precompiler entry and is excluded from this runtime package surface.
12
+ */
6
13
  export declare class ShaderCompiler {
7
- private static _parser;
8
- private static _shaderPositionPool;
9
- private static _shaderRangePool;
10
- static _processingPassText?: string;
11
14
  private _includeMap;
12
15
  private readonly _chunkOutputCache;
13
- /** Replace the `#include` lookup table and clear the derived chunk cache. */
16
+ private readonly _sourceParserObjectPool;
17
+ private readonly _parserObjectPool;
18
+ private readonly _runtimeParser;
19
+ /**
20
+ * Replaces the `#include` lookup table and clears the derived chunk cache.
21
+ * @param includeMap - Canonical include paths mapped to shader chunks.
22
+ * @internal
23
+ */
14
24
  _setIncludeMap(includeMap: IncludeMap): void;
15
- static createPosition(index: number, line?: number, column?: number): ShaderPosition;
16
- static createRange(start: ShaderPosition, end: ShaderPosition): ShaderRange;
25
+ /**
26
+ * Parses one ShaderLab document into its source structure.
27
+ * @param sourceCode - Complete ShaderLab source.
28
+ * @returns Parsed subshaders, passes, entries, and render states.
29
+ * @throws ShaderSourceParseError when source-structure diagnostics were produced.
30
+ * @internal
31
+ */
17
32
  _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
33
  /**
34
+ * Parses and generates one runtime ShaderLab pass.
35
+ * @param source - GLSL source contained by the pass.
36
+ * @param vertexEntry - Vertex entry function name.
37
+ * @param fragmentEntry - Fragment entry function name.
38
+ * @param backend - Target GLES language version.
39
+ * @param sourceFile - Optional logical source location used for relative includes and attribution.
40
+ * @param sourceScopeStarts - Inherited ShaderLab content boundaries from source parsing.
41
+ * @returns Generated stage program, or `undefined` after a blocking parser or backend error.
22
42
  * @internal
23
43
  */
24
- _logErrors(errors: Error[]): void;
44
+ _parseShaderPass(source: string, vertexEntry: string, fragmentEntry: string, backend: ShaderLanguage, sourceFile?: string, sourceScopeStarts?: readonly number[]): IShaderProgramSource | undefined;
45
+ /**
46
+ * Generates backend source from a pass returned by `ShaderAnalyzer.analyze()` without parsing it again.
47
+ * @param pass - Opaque parsed-pass handle from the analyzer result.
48
+ * @param backend - Target GLES language version.
49
+ * @returns Variant-selectable instructions and unselected text for inspection, or `undefined` on validation failure.
50
+ * @throws TypeError when `pass` was not created by the compatible shader-parser package instance.
51
+ */
52
+ generate(pass: ParsedShaderPass, backend: ShaderLanguage): IShaderProgramSource | undefined;
25
53
  }
@@ -1,4 +1,5 @@
1
- import type { ShaderInstruction } from "@galacean/engine-design";
1
+ import type { PreprocessorExpressionParseResult, ShaderInstruction } from "@galacean/engine-design";
2
+ import type { DeferredDeclarationOwnership } from "@galacean/engine-shader-parser/internal";
2
3
  export type { ShaderInstruction } from "@galacean/engine-design";
3
4
  /**
4
5
  * @internal
@@ -6,9 +7,52 @@ export type { ShaderInstruction } from "@galacean/engine-design";
6
7
  export declare class ShaderInstructionEncoder {
7
8
  private static _DIRECTIVE_RE;
8
9
  private static _FUNC_MACRO_RE;
9
- static parse(glsl: string): ShaderInstruction[];
10
+ /**
11
+ * Marks compiler-owned text without placing parser objects in the instruction stream.
12
+ * @param text - Declaration or derived declaration text.
13
+ * @param owner - Neutral declaration identity, if runtime selection is required.
14
+ * @param activate - Whether this is the declaration's original source position.
15
+ * @returns Intermediate source consumed by the instruction encoder.
16
+ * @internal
17
+ */
18
+ static declaration(text: string, owner?: DeferredDeclarationOwnership, activate?: boolean): string;
19
+ /**
20
+ * Marks derived text shared by any selected, reachable declaration without activating an owner.
21
+ * @param text - Shared derived declaration text.
22
+ * @param owners - Declarations that require the text; an empty list never retains it.
23
+ * @returns Intermediate source consumed by the instruction encoder.
24
+ * @internal
25
+ */
26
+ static sharedDeclaration(text: string, owners: readonly DeferredDeclarationOwnership[]): string;
27
+ /**
28
+ * Records a declaration dependency for variant-time reachability after ownership selection.
29
+ * @param from - Referencing declaration identity, or zero for a stage root.
30
+ * @param to - Referenced declaration identity.
31
+ * @returns Intermediate source consumed by the instruction encoder.
32
+ * @internal
33
+ */
34
+ static reference(from: number, to: number): string;
35
+ /**
36
+ * Removes private emission markers from the public source view after instruction encoding.
37
+ * @param source - Encoded intermediate stage source.
38
+ * @returns GLSL source without compiler metadata.
39
+ * @internal
40
+ */
41
+ static source(source: string): string;
42
+ /**
43
+ * Encodes generated GLSL directives into runtime-selectable instructions.
44
+ * @param glsl - Generated stage source.
45
+ * @param preprocessorExpressions - Parser-owned expression trees keyed by logical directive text.
46
+ * @returns Runtime shader instruction stream.
47
+ * @throws Error when a conditional directive is malformed or has a deterministic evaluation failure.
48
+ * @internal
49
+ */
50
+ static parse(glsl: string, preprocessorExpressions?: ReadonlyMap<string, PreprocessorExpressionParseResult>): ShaderInstruction[];
10
51
  private static _pushConditionInstruction;
52
+ private static _parseCondition;
11
53
  private static _findDirectiveStart;
54
+ private static _findLogicalLineEnd;
55
+ private static _findInlineWhitespace;
12
56
  private static _pushText;
13
57
  /**
14
58
  * Backfill jump offset of an IF/ELIF instruction.
@@ -16,16 +60,4 @@ export declare class ShaderInstructionEncoder {
16
60
  */
17
61
  private static _backfillJump;
18
62
  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
63
  }
@@ -0,0 +1,31 @@
1
+ import { ShaderLanguage } from "@galacean/engine-core";
2
+ import type { IPrecompiledShader } from "@galacean/engine-design";
3
+ import { type IncludeMap } from "@galacean/engine-shader-parser/internal/analyzer";
4
+ /**
5
+ * Offline-only ShaderLab to `.shaderc` compiler with deterministic validation.
6
+ *
7
+ * This class is intentionally excluded from the runtime compiler entry. CLI and bundler adapters import
8
+ * it from `@galacean/engine-shader-compiler/precompile`.
9
+ */
10
+ export declare class ShaderPrecompiler {
11
+ private _includeMap;
12
+ private readonly _chunkOutputCache;
13
+ private readonly _sourceParserObjectPool;
14
+ private readonly _parserObjectPool;
15
+ private readonly _validatedParser;
16
+ /**
17
+ * Replaces the logical include registry used by offline compilation.
18
+ * @param includeMap - Canonical or normalizable include keys mapped to chunk sources.
19
+ * @throws Error when multiple keys collide after normalization.
20
+ */
21
+ setIncludeMap(includeMap: IncludeMap): void;
22
+ /**
23
+ * Compiles complete ShaderLab source into a serializable `.shaderc` structure.
24
+ * @param sourceCode - Complete ShaderLab source.
25
+ * @param platformTarget - Target GLES language.
26
+ * @param sourceFile - Optional logical root location used for relative includes and attribution.
27
+ * @returns Serializable precompiled shader.
28
+ * @throws Error when structural parsing, pass validation, or backend generation fails.
29
+ */
30
+ precompile(sourceCode: string, platformTarget: ShaderLanguage, sourceFile?: string): IPrecompiledShader;
31
+ }
@@ -1,5 +1,10 @@
1
- /** Normalize to forward slashes (Windows uses `\`; downstream regex/keys assume `/`). */
1
+ /**
2
+ * Converts a filesystem path to the slash-separated form used by shader asset keys.
3
+ * @param p - Filesystem path.
4
+ * @returns Slash-separated path.
5
+ */
2
6
  export declare function normalizePath(p: string): string;
7
+ /** Controls CLI and programmatic `.shaderc` generation for one source tree. */
3
8
  export interface PrecompileOptions {
4
9
  /** Absolute or relative path to the directory containing `.shader` sources. */
5
10
  input: string;
@@ -9,17 +14,35 @@ export interface PrecompileOptions {
9
14
  clean?: boolean;
10
15
  /** Watch the input dir and re-run incrementally on `.shader` / `.glsl` changes. */
11
16
  watch?: boolean;
12
- /** Compile only this file (path may be relative to cwd). Skips full scan + cleanup. */
17
+ /** Compile only this `.shader` file inside `input` (path may be relative to cwd). Skips full scan + cleanup. */
13
18
  only?: string;
14
19
  /** Generate `<output>/index.ts` aggregating every `.shaderc` file. */
15
20
  emitIndex?: boolean;
16
21
  /** Generate raw-source indexes: `<input>/index.ts` (.shader) + sibling `ShaderLibrary/index.ts` (.glsl). */
17
22
  emitSources?: boolean;
18
- /** Optional shader platform target passed through to `_precompile`. Defaults to `0`. */
23
+ /** Optional shader platform target passed through to `precompile`. Defaults to `0`. */
19
24
  platformTarget?: number;
20
25
  }
26
+ /**
27
+ * Precompiles shaders once or starts incremental watch mode.
28
+ * @param options - Source, output, cleanup, watch, and artifact-generation options.
29
+ * @returns After a one-shot compile finishes or a watch has been installed.
30
+ * @throws Error when a one-shot compile has failures or the source tree is invalid.
31
+ */
21
32
  export declare function precompile(options: PrecompileOptions): Promise<void>;
33
+ /**
34
+ * Precompiles the current shader source tree once.
35
+ * @param options - Source, output, cleanup, and artifact-generation options.
36
+ * @returns An object containing the number of shader sources that failed to compile.
37
+ * @throws Error when the input tree or an explicitly selected source is invalid.
38
+ */
22
39
  export declare function runFull(options: Omit<PrecompileOptions, "watch">): Promise<{
23
40
  failed: number;
24
41
  }>;
42
+ /**
43
+ * Watches one shader source tree and serializes incremental rebuilds.
44
+ * @param options - Source, output, cleanup, and artifact-generation options.
45
+ * @returns Once the filesystem watcher has been installed.
46
+ * @throws Error when the initial include registry cannot be loaded.
47
+ */
25
48
  export declare function startWatcher(options: Omit<PrecompileOptions, "watch" | "only">): Promise<void>;
@@ -1,4 +1,4 @@
1
- import type { Plugin } from "rollup";
1
+ /** Controls the offline precompile step started by the Rollup plugin. */
2
2
  export interface ShaderPrecompileOptions {
3
3
  /** Directory containing `.shader` source files. */
4
4
  input: string;
@@ -13,6 +13,7 @@ export interface ShaderPrecompileOptions {
13
13
  /** Shader platform target. Default `0`. */
14
14
  platformTarget?: number;
15
15
  }
16
+ /** Configures shader asset transformation and optional offline precompilation. */
16
17
  export interface ShaderPluginOptions {
17
18
  /**
18
19
  * Override the default include pattern. The plugin always matches `.glsl`,
@@ -30,6 +31,22 @@ export interface ShaderPluginOptions {
30
31
  */
31
32
  precompile?: ShaderPrecompileOptions;
32
33
  }
34
+ /** Minimal host context shared by supported Rollup and Vite versions. */
35
+ interface ShaderPluginContext {
36
+ error(message: string): never;
37
+ warn(message: string): void;
38
+ meta: {
39
+ watchMode: boolean;
40
+ };
41
+ }
42
+ /** The implemented hooks, without unrelated hooks tied to the build's Rollup version. */
43
+ export interface ShaderCompilerPlugin {
44
+ name: string;
45
+ buildStart(this: ShaderPluginContext): Promise<void>;
46
+ transform(code: string, id: string): {
47
+ code: string;
48
+ } | null;
49
+ }
33
50
  /**
34
51
  * Rollup plugin that transforms shader assets into JS modules.
35
52
  *
@@ -37,5 +54,9 @@ export interface ShaderPluginOptions {
37
54
  * - When `precompile` option is set: runs a full precompile in buildStart and,
38
55
  * in watch mode, starts a background watcher that mirrors `.shader` source
39
56
  * changes into `.shaderc` outputs and refreshes the aggregated index.
57
+ * @param options - Transform filter and optional offline precompile configuration.
58
+ * @returns Rollup plugin for shader source and artifact modules.
59
+ * @throws Error during `buildStart` when offline precompilation reports failures.
40
60
  */
41
- export declare function shaderCompiler(options?: ShaderPluginOptions): Plugin;
61
+ export declare function shaderCompiler(options?: ShaderPluginOptions): ShaderCompilerPlugin;
62
+ export {};
@@ -1,21 +1,26 @@
1
- import { ShaderPosition, ShaderRange } from "../common";
2
- import { ASTNode } from "../parser/AST";
3
- import { NodeChild, StructProp } from "../parser/types";
1
+ import { ASTNode, TreeNode } from "@galacean/engine-shader-parser/internal";
2
+ import { FnSymbol } from "@galacean/engine-shader-parser/internal";
3
+ import { NodeChild, StructProp } from "@galacean/engine-shader-parser/internal";
4
+ import type { BranchSignature, ICodeGenVisitor } from "@galacean/engine-shader-parser/internal";
5
+ import { VisitorContext } from "./VisitorContext";
4
6
  import { ReturnableObjectPool } from "@galacean/engine-core";
5
7
  import { TempArray } from "../TempArray";
6
8
  /**
7
9
  * @internal
8
10
  * The code generator
9
11
  */
10
- export declare abstract class CodeGenVisitor {
11
- readonly errors: Error[];
12
+ export declare abstract class CodeGenVisitor implements ICodeGenVisitor {
12
13
  abstract getAttributeProp(prop: StructProp): string;
13
14
  abstract getVaryingProp(prop: StructProp): string;
14
15
  abstract getMRTProp(prop: StructProp): string | null;
15
16
  protected static _tmpArrayPool: ReturnableObjectPool<TempArray<string>>;
17
+ protected readonly context: VisitorContext;
18
+ cache(node: TreeNode, code: string): string;
19
+ getCachedCode(node: TreeNode): string | undefined;
16
20
  defaultCodeGen(children: NodeChild[]): string;
17
21
  visitPostfixExpression(node: ASTNode.PostfixExpression): string;
18
22
  visitVariableIdentifier(node: ASTNode.VariableIdentifier): string;
23
+ protected referenceFunction(symbol: FnSymbol, referenceIndex: number, branch: BranchSignature): void;
19
24
  visitFunctionCall(node: ASTNode.FunctionCall): string;
20
25
  visitMacroCallFunction(node: ASTNode.MacroCallFunction): string;
21
26
  visitStatementList(node: ASTNode.StatementList): string;
@@ -32,7 +37,7 @@ export declare abstract class CodeGenVisitor {
32
37
  visitFunctionHeader(node: ASTNode.FunctionHeader): string;
33
38
  visitJumpStatement(node: ASTNode.JumpStatement): string;
34
39
  visitFunctionIdentifier(node: ASTNode.FunctionIdentifier): string;
40
+ visitTypeSpecifier(node: ASTNode.TypeSpecifier): string;
35
41
  visitStructSpecifier(node: ASTNode.StructSpecifier): string;
36
42
  visitFunctionDefinition(fnNode: ASTNode.FunctionDefinition): string;
37
- protected _reportError(loc: ShaderRange | ShaderPosition, message: string): void;
38
43
  }
@@ -1,12 +1,10 @@
1
- import { ASTNode } from "../parser/AST";
2
- import { StructProp } from "../parser/types";
1
+ import { ASTNode } from "@galacean/engine-shader-parser/internal";
2
+ import { StructProp } from "@galacean/engine-shader-parser/internal";
3
3
  import { GLESVisitor } from "./GLESVisitor";
4
4
  export declare class GLES100Visitor extends GLESVisitor {
5
- private static _singleton;
6
- static getVisitor(): GLES100Visitor;
7
5
  getAttributeProp(prop: StructProp): string;
8
6
  getVaryingProp(prop: StructProp): string;
9
- getMRTProp(): string | null;
7
+ getMRTProp(): string;
10
8
  visitPostfixExpression(node: ASTNode.PostfixExpression): string;
11
9
  visitJumpStatement(node: ASTNode.JumpStatement): string;
12
10
  }
@@ -1,13 +1,14 @@
1
- import { ASTNode } from "../parser/AST";
2
- import { ShaderData } from "../parser/ShaderInfo";
3
- import { StructProp } from "../parser/types";
1
+ import { ASTNode } from "@galacean/engine-shader-parser/internal";
2
+ import { ShaderData } from "@galacean/engine-shader-parser/internal";
3
+ import { ShaderEntryPointInfo } from "@galacean/engine-shader-parser/internal";
4
+ import { StructProp } from "@galacean/engine-shader-parser/internal";
4
5
  import { GLESVisitor } from "./GLESVisitor";
5
6
  import { ICodeSegment } from "./types";
6
7
  export declare class GLES300Visitor extends GLESVisitor {
7
- private static _singleton;
8
- static getVisitor(): GLES300Visitor;
9
- private _otherCodeArray;
10
- private _fragColorVariableRegistered;
8
+ private readonly _outputDeclarations;
9
+ private _fragDataArrayRequired;
10
+ private readonly _fragDataIndices;
11
+ private readonly _scannedFragmentFunctions;
11
12
  reset(): void;
12
13
  getOtherGlobal(data: ShaderData, out: ICodeSegment[]): void;
13
14
  getAttributeProp(prop: StructProp): string;
@@ -15,6 +16,12 @@ export declare class GLES300Visitor extends GLESVisitor {
15
16
  getMRTProp(prop: StructProp): string;
16
17
  visitFunctionIdentifier(node: ASTNode.FunctionIdentifier): string;
17
18
  visitVariableIdentifier(node: ASTNode.VariableIdentifier): string;
19
+ visitPostfixExpression(node: ASTNode.PostfixExpression): string;
18
20
  visitJumpStatement(node: ASTNode.JumpStatement): string;
19
21
  private _registerFragColorVariable;
22
+ private _registerOutput;
23
+ protected prepareFragment(entryInfo: ShaderEntryPointInfo, outerGlobalMacroStatements: readonly ASTNode.GlobalDeclaration[]): void;
24
+ private _scanFragmentOutputs;
25
+ private _registerFragDataArray;
26
+ private _registerFragDataVariable;
20
27
  }
@@ -1,23 +1,53 @@
1
1
  import type { IShaderInfo } from "@galacean/engine-design";
2
- import { ASTNode } from "../parser/AST";
3
- import { ShaderData } from "../parser/ShaderInfo";
2
+ import type { IPoolElement } from "@galacean/engine-core";
3
+ import { ASTNode } from "@galacean/engine-shader-parser/internal";
4
+ import { ShaderData } from "@galacean/engine-shader-parser/internal";
5
+ import { FnSymbol } from "@galacean/engine-shader-parser/internal";
6
+ import type { BranchSignature, ShaderClueIR, ShaderCoreInfo, ShaderEntryPointInfo, DeferredDeclarationOwnership } from "@galacean/engine-shader-parser/internal";
4
7
  import { CodeGenVisitor } from "./CodeGenVisitor";
5
8
  import { ICodeSegment } from "./types";
9
+ import type { ShaderBackend } from "../ShaderBackend";
6
10
  /**
7
11
  * @internal
8
12
  */
9
- export declare abstract class GLESVisitor extends CodeGenVisitor {
13
+ export declare abstract class GLESVisitor extends CodeGenVisitor implements ShaderBackend, IPoolElement {
10
14
  private _globalCodeArray;
11
- private static _lookupSymbol;
12
- private static _serializedGlobalKey;
15
+ private readonly _forwardFunctionDeclarations;
16
+ private readonly _forwardStructIndices;
17
+ private readonly _structCodeSegments;
18
+ private readonly _forwardVariableIndices;
19
+ private readonly _variableCodeSegments;
20
+ private readonly _declarationOwners;
21
+ private readonly _deferredPrototypes;
22
+ private readonly _declarationReferences;
23
+ private _currentDeclaration?;
24
+ private _sourceIR?;
25
+ private _outerMacroDeclarations;
26
+ /**
27
+ * Clears pass-local output retained by the pooled visitor.
28
+ */
13
29
  reset(): void;
30
+ /**
31
+ * Releases references retained by an idle visitor when its pool is collected.
32
+ * @internal
33
+ */
34
+ dispose(): void;
35
+ /**
36
+ * Emits target-specific declarations that precede generated global code.
37
+ * @param data - Parser-owned shader facts.
38
+ * @param out - Destination code segments.
39
+ */
14
40
  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;
41
+ /**
42
+ * Generates vertex and fragment source from neutral parser facts.
43
+ * @param ir - Request-owned neutral shader IR.
44
+ * @param coreInfo - Entry and stage-interface facts derived from the same IR.
45
+ * @returns Generated vertex and fragment source.
46
+ */
47
+ generate(ir: ShaderClueIR, coreInfo: ShaderCoreInfo): IShaderInfo;
18
48
  private _vertexMain;
19
49
  private _fragmentMain;
20
- private _extractLocalVarNames;
50
+ protected prepareFragment(entryInfo: ShaderEntryPointInfo, outerGlobalMacroStatements: readonly ASTNode.GlobalDeclaration[]): void;
21
51
  /**
22
52
  * Pre-walk `#define` values in global macro declarations and register any
23
53
  * `structVar.prop` member accesses as referenced struct props. This must run before
@@ -26,8 +56,24 @@ export declare abstract class GLESVisitor extends CodeGenVisitor {
26
56
  */
27
57
  private _preRegisterGlobalMacroRefs;
28
58
  private _walkMacroDefineTokens;
59
+ private _registerFragmentReturns;
29
60
  private _getGlobalSymbol;
61
+ protected referenceFunction(symbol: FnSymbol, referenceIndex: number, branch: BranchSignature): void;
62
+ private _getForwardSignature;
63
+ private _canBranchesOverlap;
64
+ visitVariableIdentifier(node: ASTNode.VariableIdentifier): string;
65
+ private _getForwardDeclarations;
66
+ visitTypeSpecifier(node: ASTNode.TypeSpecifier): string;
67
+ private _prepareForwardTypes;
68
+ private _isContextIndependent;
69
+ private _hasDeclarationContextBarrier;
70
+ private _unsupportedForwardDeclaration;
30
71
  private _getCustomStruct;
31
72
  private _getGlobalMacroDeclarations;
32
73
  private _visitGlobalMacroIfStatement;
74
+ /** Ownership of the declaration currently generating dependencies. @internal */
75
+ protected get currentDeclarationOwner(): DeferredDeclarationOwnership | undefined;
76
+ private _referenceDeclaration;
77
+ private _emitDeclarationReferences;
78
+ private _declaration;
33
79
  }