diff --git a/packages/shader-lab/src/ShaderLab.ts b/packages/shader-lab/src/ShaderLab.ts index 37df11060b..95a804d95f 100644 --- a/packages/shader-lab/src/ShaderLab.ts +++ b/packages/shader-lab/src/ShaderLab.ts @@ -91,11 +91,13 @@ export class ShaderLab implements IShaderLab { for (const err of parser.errors) { this.errors.push(err); } + // #endif if (!program) { + // #if _VERBOSE this._logErrors(); + // #endif return undefined; } - // #endif const codeGen = backend === ShaderPlatformTarget.GLES100 ? GLES100Visitor.getVisitor() : GLES300Visitor.getVisitor(); diff --git a/packages/shader-lab/src/ShaderLabUtils.ts b/packages/shader-lab/src/ShaderLabUtils.ts index b2847b67e8..f4d411ef13 100644 --- a/packages/shader-lab/src/ShaderLabUtils.ts +++ b/packages/shader-lab/src/ShaderLabUtils.ts @@ -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 } } diff --git a/packages/shader-lab/src/codeGen/CodeGenVisitor.ts b/packages/shader-lab/src/codeGen/CodeGenVisitor.ts index a42b3abe33..ec817461f4 100644 --- a/packages/shader-lab/src/codeGen/CodeGenVisitor.ts +++ b/packages/shader-lab/src/codeGen/CodeGenVisitor.ts @@ -46,7 +46,7 @@ export class CodeGenVisitor { const error = context.referenceAttribute(prop); // #if _VERBOSE if (error) { - this.errors.push(error); + this.errors.push(error); } // #endif return prop.lexeme; @@ -54,7 +54,7 @@ export class CodeGenVisitor { const error = context.referenceVarying(prop); // #if _VERBOSE if (error) { - this.errors.push(error); + this.errors.push(error); } // #endif return prop.lexeme; diff --git a/packages/shader-lab/src/codeGen/VisitorContext.ts b/packages/shader-lab/src/codeGen/VisitorContext.ts index 3d6308f78e..6a177d12b7 100644 --- a/packages/shader-lab/src/codeGen/VisitorContext.ts +++ b/packages/shader-lab/src/codeGen/VisitorContext.ts @@ -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); @@ -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); diff --git a/packages/shader-lab/src/common/Keywords.ts b/packages/shader-lab/src/common/Keywords.ts index 9085d0d6f5..0ab7b47fa5 100644 --- a/packages/shader-lab/src/common/Keywords.ts +++ b/packages/shader-lab/src/common/Keywords.ts @@ -77,6 +77,7 @@ export enum EKeyword { GS_RasterState, GS_EditorProperties, GS_EditorMacros, + GS_Editor, GS_Tags, GS_ReplacementTag, GS_LightMode, diff --git a/packages/shader-lab/src/contentParser/KeywordMap.ts b/packages/shader-lab/src/contentParser/KeywordMap.ts index f6b20188da..bb43d824fa 100644 --- a/packages/shader-lab/src/contentParser/KeywordMap.ts +++ b/packages/shader-lab/src/contentParser/KeywordMap.ts @@ -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], ["Tags", EKeyword.GS_Tags], ["VertexShader", EKeyword.GS_VertexShader], ["FragmentShader", EKeyword.GS_FragmentShader], diff --git a/packages/shader-lab/src/contentParser/ShaderContentParser.ts b/packages/shader-lab/src/contentParser/ShaderContentParser.ts index 72bd7bcd2b..eba5e1c058 100644 --- a/packages/shader-lab/src/contentParser/ShaderContentParser.ts +++ b/packages/shader-lab/src/contentParser/ShaderContentParser.ts @@ -26,8 +26,8 @@ import { import { GSErrorName } from "../GSError"; // #if _VERBOSE import { GSError } from "../GSError"; -import { ShaderLabUtils } from "../ShaderLabUtils"; // #endif +import { ShaderLabUtils } from "../ShaderLabUtils"; const EngineType = [ EKeyword.GS_RenderQueueType, @@ -129,6 +129,7 @@ export class ShaderContentParser { 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(); @@ -191,7 +192,7 @@ export class ShaderContentParser { variable.location ); // #if _VERBOSE - this._errors.push(error); + this._errors.push(error); return; // #endif } @@ -248,7 +249,7 @@ export class ShaderContentParser { scanner.getCurPosition() ); // #if _VERBOSE - this._errors.push(error); + this._errors.push(error); scanner.scanToCharacter(";"); return; // #endif @@ -266,7 +267,7 @@ export class ShaderContentParser { scanner.getCurPosition() ); // #if _VERBOSE - this._errors.push(error); + this._errors.push(error); scanner.scanToCharacter(";"); return; // #endif @@ -306,7 +307,7 @@ export class ShaderContentParser { engineTypeProp.location ); // #if _VERBOSE - this._errors.push(error); + this._errors.push(error); scanner.scanToCharacter(";"); return; // #endif @@ -328,20 +329,12 @@ export class ShaderContentParser { 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( diff --git a/packages/shader-lab/src/parser/ShaderTargetParser.ts b/packages/shader-lab/src/parser/ShaderTargetParser.ts index e0b70f8b66..2bbb3da72c 100644 --- a/packages/shader-lab/src/parser/ShaderTargetParser.ts +++ b/packages/shader-lab/src/parser/ShaderTargetParser.ts @@ -10,7 +10,7 @@ import { addTranslationRule, createGrammar } from "../lalr/CFG"; 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"; @@ -120,9 +120,9 @@ export class ShaderTargetParser { token.location ); // #if _VERBOSE - this.sematicAnalyzer.errors.push(error); - return null; + this.sematicAnalyzer.errors.push(error); // #endif + return null; } } } diff --git a/packages/shader-lab/src/preprocessor/PpParser.ts b/packages/shader-lab/src/preprocessor/PpParser.ts index afe5e8dd4b..df8e76982a 100644 --- a/packages/shader-lab/src/preprocessor/PpParser.ts +++ b/packages/shader-lab/src/preprocessor/PpParser.ts @@ -105,7 +105,9 @@ export class PpParser { private static reportError(loc: ShaderRange | ShaderPosition, message: string, source: string, file: string) { const error = ShaderLabUtils.createGSError(message, GSErrorName.PreprocessorError, source, loc, file); + // #if _VERBOSE this._errors.push(error); + // #endif } private static _parseInclude(scanner: PpScanner) { @@ -642,23 +644,6 @@ export class PpParser { } 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; diff --git a/tests/src/shader-lab/ShaderLab.test.ts b/tests/src/shader-lab/ShaderLab.test.ts index 71aae9b691..08b367ba52 100644 --- a/tests/src/shader-lab/ShaderLab.test.ts +++ b/tests/src/shader-lab/ShaderLab.test.ts @@ -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)"); @@ -253,7 +255,5 @@ describe("ShaderLab", () => { for (const err of shaderLabVerbose.errors) { console.log(err.toString()); } - - expect(shaderParse.bind(shaderLabRelease, errorShader)).to.throw(Error); }); }); diff --git a/tests/src/shader-lab/shaders/demo.shader b/tests/src/shader-lab/shaders/demo.shader index c6ca75e4f2..c0ff0dc8f7 100644 --- a/tests/src/shader-lab/shaders/demo.shader +++ b/tests/src/shader-lab/shaders/demo.shader @@ -38,6 +38,8 @@ Shader "Water" { Pass "default" { Tags { ReplacementTag = "Opaque", pipelineStage = "DepthOnly"} + RenderQueueType = customRenderQueue; + struct a2v { vec4 POSITION; vec2 TEXCOORD_0;