Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShaderLab ignore Editor module #2395

Merged
merged 162 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
5a26f3d
fix(shader-lab): compatible with empty macro
Sway007 Sep 20, 2023
5ecc318
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Sep 20, 2023
cafc24f
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Sep 20, 2023
dc69489
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Sep 21, 2023
221b7b6
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Sep 21, 2023
0d45d9c
fix(shader-lab): add break and continue syntax
Sway007 Sep 21, 2023
0f14c3f
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Sep 27, 2023
8871d9b
fix: typo
Sway007 Oct 11, 2023
3b4ffd7
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Nov 1, 2023
f649a58
fix(shader-lab): Make usepass compatible with buitin shader
Sway007 Nov 1, 2023
598fc56
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Nov 2, 2023
e33a66f
fix(shader-lab): compatible with no varying variable
Sway007 Nov 2, 2023
41ef06f
feat(shader-lab): detect mismatch return type
Sway007 Nov 6, 2023
b5214fc
fix(shader-lab): renderState assignment
Sway007 Nov 7, 2023
f36ce02
feat: extend material loader data type
Sway007 Nov 13, 2023
ff8b7c2
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Nov 13, 2023
634236f
fix(shader-lab): glsl type pattern
Sway007 Nov 13, 2023
91e6fa4
fix(shader-lab): glsl type pattern
Sway007 Nov 13, 2023
3932448
fix: switch case break
Sway007 Nov 15, 2023
b5fa1e6
feat: add loader for shader asset
Sway007 Mar 11, 2024
d8d9a87
feat: compatible with 1.2-pre version
Sway007 Mar 12, 2024
4f575fc
Merge branch 'main' of https://github.com/galacean/engine into feat/s…
Sway007 Mar 18, 2024
a5f76dc
feat: opt code
Sway007 Mar 18, 2024
d2d14d1
Merge branch 'main' of https://github.com/galacean/engine into feat/s…
Sway007 Apr 16, 2024
326afea
fix: keep macro declaration
Sway007 Apr 26, 2024
a46c5dc
test: add unitest
Sway007 Apr 26, 2024
bfd4b1d
fix: macro function & line change
Sway007 May 6, 2024
5fe627d
fix: test case
Sway007 May 6, 2024
cfdc44d
Merge branch 'fix/shaderlab/macro' into feat/shaderloader
Sway007 May 7, 2024
d65e88a
"v0.0.0-experimental-shaderlab.0"
Sway007 May 7, 2024
81ba305
"v0.0.0-experimental-shaderlab.1"
Sway007 May 7, 2024
470dc62
fix: recursive chunck load
Sway007 May 7, 2024
6c7436a
"v0.0.0-experimental-shaderlab.2"
zhuxudong May 7, 2024
671cace
fix: array index loss
Sway007 Jun 11, 2024
92b972e
feat: merge
Sway007 Jun 11, 2024
9226d38
fix: test-case
Sway007 Jun 11, 2024
ff6a69a
fix: test-case
Sway007 Jun 12, 2024
83b9ca2
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Jun 13, 2024
f510c2a
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Jul 15, 2024
94e30f5
fix: conditional compilation
Sway007 Jul 16, 2024
e3c7aa5
fix: expand token
Sway007 Jul 16, 2024
36b77e0
fix: expand token
Sway007 Jul 16, 2024
b2e07fc
feat: code opt
Sway007 Jul 16, 2024
93df92e
fix: ci
Sway007 Jul 16, 2024
8e0cc28
feat: cache error shader
Sway007 Jul 17, 2024
7652250
Merge branch 'dev/1.3' of https://github.com/galacean/engine into fea…
Sway007 Jul 17, 2024
c92e674
fix: preprocessor parse expression
Sway007 Jul 17, 2024
3fefbe9
Merge branch 'dev/1.3' of https://github.com/galacean/engine into fea…
Sway007 Jul 17, 2024
9eb7398
fix: gles 100 code gen
Sway007 Jul 17, 2024
9f5b5bc
feat: support relative path include
Sway007 Jul 18, 2024
82f73b2
Merge branch 'dev/1.3' of https://github.com/galacean/engine into fea…
Sway007 Jul 18, 2024
964b846
feat: test case
Sway007 Jul 18, 2024
f6fed8b
feat: compatible with builtin shader chunk import
Sway007 Jul 18, 2024
519ab40
feat: code opt
Sway007 Jul 18, 2024
ee6a813
feat: code opt
Sway007 Jul 18, 2024
d7e0ac8
feat: code opt
Sway007 Jul 18, 2024
8f75c28
feat: code opt
Sway007 Jul 18, 2024
00447fb
feat: code opt
Sway007 Jul 18, 2024
d5a3c0c
feat: add log
Sway007 Jul 19, 2024
c176226
feat: add log
Sway007 Jul 19, 2024
b8ca43f
feat: add log
Sway007 Jul 22, 2024
a6d21d6
Merge branch 'dev/1.3' of https://github.com/galacean/engine into fea…
Sway007 Jul 30, 2024
ce23026
fix: multi dist
Sway007 Aug 1, 2024
3bcaeb0
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Aug 5, 2024
79a7a0c
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Aug 5, 2024
fa7131c
Merge branch 'main' of https://github.com/galacean/engine
Sway007 Aug 6, 2024
3093bd2
Merge branch 'main' into feat/shaderlab-error-report
Sway007 Aug 20, 2024
6eba20a
Merge branch 'main' of https://github.com/galacean/engine into feat/s…
Sway007 Aug 20, 2024
8c90796
feat(shaderlab): [wip] optmize error log
Sway007 Aug 23, 2024
dab8003
Merge branch 'main' of https://github.com/galacean/engine into feat/s…
Sway007 Aug 26, 2024
f12b8f7
feat(shaderlab): multi package
Sway007 Aug 27, 2024
c32969b
feat(shaderlab): opt code
Sway007 Aug 27, 2024
9d4d808
feat(shaderlab): opt code
Sway007 Aug 27, 2024
f5edeb3
feat(shaderlab): opt code
Sway007 Aug 27, 2024
68e1556
feat(shaderlab): opt code
Sway007 Aug 27, 2024
dd4777c
feat(shaderlab): test case
Sway007 Aug 27, 2024
1a918da
feat: opt code
Sway007 Aug 27, 2024
4c9e16c
Merge branch 'main' of https://github.com/galacean/engine into feat/s…
Sway007 Aug 27, 2024
e4d267c
feat: opt code
Sway007 Aug 27, 2024
077e009
feat: opt code
Sway007 Aug 27, 2024
462af90
feat: opt code
Sway007 Aug 27, 2024
54f9c79
feat: opt code
Sway007 Aug 27, 2024
d01b060
feat: opt code
Sway007 Aug 27, 2024
df84ce0
feat: opt code
Sway007 Aug 27, 2024
1426499
feat: opt code
Sway007 Aug 27, 2024
48eb236
feat: opt code
Sway007 Aug 27, 2024
3b06a3f
feat: opt code
Sway007 Aug 27, 2024
ab356b6
feat: opt code
Sway007 Aug 27, 2024
ab6de2c
feat: opt code
Sway007 Aug 27, 2024
5092aab
feat: opt code
Sway007 Aug 27, 2024
8a5f838
feat: opt code
Sway007 Aug 27, 2024
ff3f5ae
feat: opt code
Sway007 Aug 27, 2024
c679a9e
feat: opt code
Sway007 Aug 27, 2024
44b7e84
feat: opt code
Sway007 Sep 2, 2024
eb0bcde
feat: code opt
Sway007 Sep 11, 2024
2f56705
feat: code opt
Sway007 Sep 26, 2024
b102ac8
Merge branch 'dev/1.4' of https://github.com/galacean/engine into fea…
Sway007 Sep 26, 2024
e1f749a
feat: add shaderlab verbose package
Sway007 Sep 26, 2024
6e36dd0
feat: add shaderlab verbose package
Sway007 Sep 26, 2024
032a631
feat: update readme
Sway007 Sep 26, 2024
adb871f
feat: rollup.config.js opt
Sway007 Sep 26, 2024
cc8e0a1
feat: code opt & compatible with multiple log
Sway007 Oct 8, 2024
b7da54e
feat: code opt
Sway007 Oct 8, 2024
59776c4
feat: _EDITOR to _VERBOSE
Sway007 Oct 8, 2024
11ebcbc
feat: opt shaderlabobjectpool
Sway007 Oct 8, 2024
67f9c8d
feat: rm redundant code
Sway007 Oct 8, 2024
c76c81f
feat: code opt
Sway007 Oct 9, 2024
2236ac3
feat: code opt
Sway007 Oct 9, 2024
9f8cbe7
feat: code opt
Sway007 Oct 9, 2024
0df3db6
fix: new scope when parse pass
Sway007 Oct 10, 2024
a72aade
feat: code opt
Sway007 Oct 10, 2024
a19e9ba
feat: code opt
Sway007 Oct 11, 2024
4c47c15
feat: code opt
Sway007 Oct 11, 2024
d83cb29
feat: code opt
Sway007 Oct 11, 2024
a180d29
feat: code opt
Sway007 Oct 12, 2024
7c57e15
feat: add testcase for BaseScanner
Sway007 Oct 12, 2024
4c63401
feat: code opt
Sway007 Oct 12, 2024
87c719d
feat: code opt
Sway007 Oct 12, 2024
2661cae
feat: code opt
Sway007 Oct 12, 2024
a85ee45
feat: code opt
Sway007 Oct 12, 2024
4c50206
feat: code opt
Sway007 Oct 12, 2024
cae81c2
feat: code opt
Sway007 Oct 12, 2024
eb515be
feat: code opt
Sway007 Oct 12, 2024
fb3974e
feat: code opt
Sway007 Oct 12, 2024
f0742cf
feat: code opt
Sway007 Oct 12, 2024
ef6496b
feat: code opt
Sway007 Oct 14, 2024
8086b86
feat(shaderlab): ignore editor module
Sway007 Oct 17, 2024
cb6188f
Merge branch 'dev/1.4' of https://github.com/galacean/engine into fea…
Sway007 Oct 17, 2024
c80f141
feat: code opt
Sway007 Oct 31, 2024
0d57693
feat: code opt
Sway007 Oct 31, 2024
b173007
feat: hide ShaderChunk type
Sway007 Oct 31, 2024
006a08c
Merge branch 'main' of https://github.com/galacean/engine into feat/s…
Sway007 Oct 31, 2024
0addd19
feat: add types
Sway007 Oct 31, 2024
f9434bb
feat: code opt
Sway007 Oct 31, 2024
d12640e
feat: code opt
Sway007 Oct 31, 2024
4b64817
feat: opt regex
Sway007 Oct 31, 2024
d351bae
feat: support relative include in shader loader
Sway007 Oct 31, 2024
2df9acb
refactor: loader api
Sway007 Nov 4, 2024
e037baa
fix: return null shader source when compile error
Sway007 Nov 5, 2024
2e3c530
feat: code opt
Sway007 Nov 5, 2024
882229f
feat: code opt
Sway007 Nov 5, 2024
e747bae
feat: code opt
Sway007 Nov 5, 2024
d15921c
Merge branch 'dev/1.4' of https://github.com/galacean/engine into fea…
Sway007 Nov 5, 2024
0927b2d
feat: code opt
Sway007 Nov 5, 2024
c0e2a60
feat: code opt
Sway007 Nov 5, 2024
f755ebb
Merge branch 'feat/shaderloader' into feat/editor_module
Sway007 Nov 5, 2024
2b911ee
fix: renderqueue assignment support variable
Sway007 Nov 5, 2024
5badefe
Merge branch 'dev/1.4' of https://github.com/galacean/engine into fea…
Sway007 Nov 12, 2024
cc64947
feat: code clean
Sway007 Nov 12, 2024
fa6b2de
fix: verbose version
Sway007 Nov 13, 2024
671df03
fix: resouce manager load local resource
Sway007 Nov 14, 2024
257dffe
fix: unitest
Sway007 Nov 14, 2024
caa9c01
fix: unitest
Sway007 Nov 14, 2024
fb008e3
fix: e2e
Sway007 Nov 14, 2024
1027705
feat: code opt
Sway007 Nov 15, 2024
e57f2aa
feat: code opt
Sway007 Nov 15, 2024
0c8d1d6
feat: code opt
Sway007 Nov 15, 2024
c05c7ef
feat: code opt
Sway007 Nov 15, 2024
9de0104
feat: code opt
Sway007 Nov 15, 2024
eeb1188
feat: remove redundant
Sway007 Nov 15, 2024
28b9a95
feat: remove redundant code
Sway007 Nov 15, 2024
2749c76
feat: add unitest
Sway007 Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/shader-lab/src/ShaderLab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@
for (const err of parser.errors) {
this.errors.push(err);
}
// #endif
if (!program) {
// #if _VERBOSE

Check warning on line 96 in packages/shader-lab/src/ShaderLab.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/ShaderLab.ts#L96

Added line #L96 was not covered by tests
this._logErrors();
// #endif

Check warning on line 98 in packages/shader-lab/src/ShaderLab.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/ShaderLab.ts#L98

Added line #L98 was not covered by tests
return undefined;
}
// #endif

const codeGen =
backend === ShaderPlatformTarget.GLES100 ? GLES100Visitor.getVisitor() : GLES300Visitor.getVisitor();
Expand Down
4 changes: 2 additions & 2 deletions packages/shader-lab/src/ShaderLabUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export class ShaderLabUtils {
source: string,
location: ShaderRange | ShaderPosition,
file?: string
) {
): Error {
// #if _VERBOSE
return new GSError(errorName, message, location, source, file);
// #else
throw new Error(`[${errorName}]: ${message}`);
return new Error(`[${errorName}]: ${message}`);
// #endif
}
}
4 changes: 2 additions & 2 deletions packages/shader-lab/src/codeGen/CodeGenVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export class CodeGenVisitor {
const error = context.referenceAttribute(prop);
// #if _VERBOSE
if (error) {
this.errors.push(error);
this.errors.push(<GSError>error);
}
// #endif
return prop.lexeme;
} else if (context.isVaryingStruct(<string>postExpr.type)) {
const error = context.referenceVarying(prop);
// #if _VERBOSE
if (error) {
this.errors.push(error);
this.errors.push(<GSError>error);
}
// #endif
return prop.lexeme;
Expand Down
4 changes: 2 additions & 2 deletions packages/shader-lab/src/codeGen/VisitorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class VisitorContext {
return this.varyingStruct?.ident?.lexeme === type;
}

referenceAttribute(ident: BaseToken): GSError {
referenceAttribute(ident: BaseToken): Error {
if (this._referencedAttributeList[ident.lexeme]) return;

const prop = this.attributeList.find((item) => item.ident.lexeme === ident.lexeme);
Expand All @@ -75,7 +75,7 @@ export class VisitorContext {
this._referencedAttributeList[ident.lexeme] = prop;
}

referenceVarying(ident: BaseToken): GSError | undefined {
referenceVarying(ident: BaseToken): Error | undefined {
if (this._referencedVaryingList[ident.lexeme]) return;

const prop = this.varyingStruct?.propList.find((item) => item.ident.lexeme === ident.lexeme);
Expand Down
1 change: 1 addition & 0 deletions packages/shader-lab/src/common/Keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export enum EKeyword {
GS_RasterState,
GS_EditorProperties,
GS_EditorMacros,
GS_Editor,
GS_Tags,
GS_ReplacementTag,
GS_LightMode,
Expand Down
1 change: 1 addition & 0 deletions packages/shader-lab/src/contentParser/KeywordMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const KeywordMap = new Map([
["RasterState", EKeyword.GS_RasterState],
["EditorProperties", EKeyword.GS_EditorProperties],
["EditorMacros", EKeyword.GS_EditorMacros],
["Editor", EKeyword.GS_Editor],
GuoLei1990 marked this conversation as resolved.
Show resolved Hide resolved
["Tags", EKeyword.GS_Tags],
["VertexShader", EKeyword.GS_VertexShader],
["FragmentShader", EKeyword.GS_FragmentShader],
Expand Down
27 changes: 10 additions & 17 deletions packages/shader-lab/src/contentParser/ShaderContentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import { GSErrorName } from "../GSError";
// #if _VERBOSE
import { GSError } from "../GSError";
import { ShaderLabUtils } from "../ShaderLabUtils";
// #endif
import { ShaderLabUtils } from "../ShaderLabUtils";

const EngineType = [
EKeyword.GS_RenderQueueType,
Expand Down Expand Up @@ -129,6 +129,7 @@

case EKeyword.GS_EditorProperties:
case EKeyword.GS_EditorMacros:
case EKeyword.GS_Editor:
this._addGlobalStatement(ret, scanner, start, word.lexeme.length);
scanner.scanPairedText("{", "}", true);
start = scanner.getCurPosition();
Expand Down Expand Up @@ -191,7 +192,7 @@
variable.location
);
// #if _VERBOSE
this._errors.push(error);
this._errors.push(<GSError>error);

Check warning on line 195 in packages/shader-lab/src/contentParser/ShaderContentParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/contentParser/ShaderContentParser.ts#L195

Added line #L195 was not covered by tests
return;
// #endif
}
Expand Down Expand Up @@ -248,7 +249,7 @@
scanner.getCurPosition()
);
// #if _VERBOSE
this._errors.push(error);
this._errors.push(<GSError>error);

Check warning on line 252 in packages/shader-lab/src/contentParser/ShaderContentParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/contentParser/ShaderContentParser.ts#L252

Added line #L252 was not covered by tests
scanner.scanToCharacter(";");
return;
// #endif
Expand All @@ -266,7 +267,7 @@
scanner.getCurPosition()
);
// #if _VERBOSE
this._errors.push(error);
this._errors.push(<GSError>error);

Check warning on line 270 in packages/shader-lab/src/contentParser/ShaderContentParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/contentParser/ShaderContentParser.ts#L270

Added line #L270 was not covered by tests
scanner.scanToCharacter(";");
return;
// #endif
Expand Down Expand Up @@ -306,7 +307,7 @@
engineTypeProp.location
);
// #if _VERBOSE
this._errors.push(error);
this._errors.push(<GSError>error);

Check warning on line 310 in packages/shader-lab/src/contentParser/ShaderContentParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/contentParser/ShaderContentParser.ts#L310

Added line #L310 was not covered by tests
scanner.scanToCharacter(";");
return;
// #endif
Expand All @@ -328,20 +329,12 @@
const word = scanner.scanToken();
scanner.scanText(";");
const value = ShaderContentParser._engineType.RenderQueueType[word.lexeme];
const key = RenderStateDataKey.RenderQueueType;
if (value == undefined) {
const error = ShaderLabUtils.createGSError(
`Invalid render queue ${word.lexeme}`,
GSErrorName.CompilationError,
scanner.source,
word.location
);
// #if _VERBOSE
this._errors.push(error);
return;
// #endif
ret.renderStates.variableMap[key] = word.lexeme;
} else {
ret.renderStates.constantMap[key] = value;
}
const key = RenderStateDataKey.RenderQueueType;
ret.renderStates.constantMap[key] = value;
}

private static _addGlobalStatement(
Expand Down
6 changes: 3 additions & 3 deletions packages/shader-lab/src/parser/ShaderTargetParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { LALR1 } from "../lalr";
import { ParserUtils } from "../ParserUtils";
import { Logger } from "@galacean/engine";
import { GSErrorName } from "../GSError";
import { GSError, GSErrorName } from "../GSError";
import { ShaderLab } from "../ShaderLab";
import { ShaderLabUtils } from "../ShaderLabUtils";

Expand Down Expand Up @@ -120,9 +120,9 @@
token.location
);
// #if _VERBOSE
this.sematicAnalyzer.errors.push(error);
return null;
this.sematicAnalyzer.errors.push(<GSError>error);

Check warning on line 123 in packages/shader-lab/src/parser/ShaderTargetParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/parser/ShaderTargetParser.ts#L123

Added line #L123 was not covered by tests
// #endif
return null;

Check warning on line 125 in packages/shader-lab/src/parser/ShaderTargetParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/parser/ShaderTargetParser.ts#L125

Added line #L125 was not covered by tests
Comment on lines +123 to +125
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add test coverage for error handling

The error handling code path is not covered by tests. Consider adding test cases for:

  • Invalid token scenarios
  • Error propagation in both verbose and non-verbose modes

Would you like me to help generate test cases for these scenarios?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 123-123: packages/shader-lab/src/parser/ShaderTargetParser.ts#L123
Added line #L123 was not covered by tests


[warning] 125-125: packages/shader-lab/src/parser/ShaderTargetParser.ts#L125
Added line #L125 was not covered by tests

}
}
}
Expand Down
19 changes: 2 additions & 17 deletions packages/shader-lab/src/preprocessor/PpParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@

private static reportError(loc: ShaderRange | ShaderPosition, message: string, source: string, file: string) {
const error = ShaderLabUtils.createGSError(message, GSErrorName.PreprocessorError, source, loc, file);
// #if _VERBOSE

Check warning on line 108 in packages/shader-lab/src/preprocessor/PpParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/preprocessor/PpParser.ts#L108

Added line #L108 was not covered by tests
this._errors.push(error);
// #endif

Check warning on line 110 in packages/shader-lab/src/preprocessor/PpParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/preprocessor/PpParser.ts#L110

Added line #L110 was not covered by tests
Comment on lines +108 to +110
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix static context reference and add test coverage.

  1. Replace this with the class name to improve clarity in static context.
  2. Add test coverage for error reporting in verbose mode.
- this._errors.push(error);
+ PpParser._errors.push(error);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// #if _VERBOSE
this._errors.push(error);
// #endif
// #if _VERBOSE
PpParser._errors.push(error);
// #endif
🧰 Tools
🪛 Biome

[error] 109-109: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

🪛 GitHub Check: codecov/patch

[warning] 108-108: packages/shader-lab/src/preprocessor/PpParser.ts#L108
Added line #L108 was not covered by tests


[warning] 110-110: packages/shader-lab/src/preprocessor/PpParser.ts#L110
Added line #L110 was not covered by tests

}

private static _parseInclude(scanner: PpScanner) {
Expand Down Expand Up @@ -642,23 +644,6 @@
}

private static _onToken(token: BaseToken, scanner: PpScanner) {
this._skipEditorBlock(token, scanner);
this._expandToken(token, scanner);
}

private static _skipEditorBlock(token: BaseToken, scanner: PpScanner) {
if (token.lexeme === "EditorProperties" || token.lexeme === "EditorMacros") {
const start = scanner.current - token.lexeme.length;
scanner.scanPairedBlock("{", "}");
const end = scanner.current;
const startPosition = ShaderLab.createPosition(start);
const endPosition = ShaderLab.createPosition(end);
const range = ShaderLab.createRange(startPosition, endPosition);
this.expandSegments.push({ rangeInBlock: range, replace: "" });
}
}

private static _expandToken(token: BaseToken, scanner: PpScanner) {
const macro = this._definedMacros.get(token.lexeme);
if (macro) {
let replace = macro.body.lexeme;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/shader-lab/ShaderLab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ describe("ShaderLab", () => {
expect(pass1.renderStates).not.be.null;

const { constantMap, variableMap } = pass1.renderStates;
expect(Object.values(variableMap).includes("customRenderQueue"));

expect(constantMap).not.be.null;

expect(toString(constantMap[RenderStateDataKey.BlendStateBlendColor] as Color)).eq("Color(1, 1, 1, 1)");
Expand Down Expand Up @@ -253,7 +255,5 @@ describe("ShaderLab", () => {
for (const err of shaderLabVerbose.errors) {
console.log(err.toString());
}

expect(shaderParse.bind(shaderLabRelease, errorShader)).to.throw(Error);
});
});
2 changes: 2 additions & 0 deletions tests/src/shader-lab/shaders/demo.shader
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Shader "Water" {
Pass "default" {
Tags { ReplacementTag = "Opaque", pipelineStage = "DepthOnly"}

RenderQueueType = customRenderQueue;

struct a2v {
vec4 POSITION;
vec2 TEXCOORD_0;
Expand Down
Loading