Skip to content

Commit

Permalink
Merge branch 'dev/1.4' of https://github.com/galacean/engine into dev…
Browse files Browse the repository at this point in the history
…/1.4
  • Loading branch information
GuoLei1990 committed Nov 18, 2024
2 parents 3a1f97e + 736225b commit 40dae5b
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 46 deletions.
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 @@ 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();
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],
["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 {
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 @@ 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();
Expand Down Expand Up @@ -191,7 +192,7 @@ export class ShaderContentParser {
variable.location
);
// #if _VERBOSE
this._errors.push(error);
this._errors.push(<GSError>error);
return;
// #endif
}
Expand Down Expand Up @@ -248,7 +249,7 @@ export class ShaderContentParser {
scanner.getCurPosition()
);
// #if _VERBOSE
this._errors.push(error);
this._errors.push(<GSError>error);
scanner.scanToCharacter(";");
return;
// #endif
Expand All @@ -266,7 +267,7 @@ export class ShaderContentParser {
scanner.getCurPosition()
);
// #if _VERBOSE
this._errors.push(error);
this._errors.push(<GSError>error);
scanner.scanToCharacter(";");
return;
// #endif
Expand Down Expand Up @@ -306,7 +307,7 @@ export class ShaderContentParser {
engineTypeProp.location
);
// #if _VERBOSE
this._errors.push(error);
this._errors.push(<GSError>error);
scanner.scanToCharacter(";");
return;
// #endif
Expand All @@ -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(
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 { 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";

Expand Down Expand Up @@ -120,9 +120,9 @@ export class ShaderTargetParser {
token.location
);
// #if _VERBOSE
this.sematicAnalyzer.errors.push(error);
return null;
this.sematicAnalyzer.errors.push(<GSError>error);
// #endif
return null;
}
}
}
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 @@ 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) {
Expand Down Expand Up @@ -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;
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

0 comments on commit 40dae5b

Please sign in to comment.