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

Refactoring the ShaderLab Compiler Module using the LALR Algorithm for Enhanced GLSL Compatibility and Reduced Build Size #2113

Merged
merged 111 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
a669c92
refactor: [wip]pp & lexer
Sway007 May 27, 2024
6d1d2dc
refactor: [wip]pp & lexer
Sway007 May 27, 2024
a8b9c59
feat: semantic analyzer
Sway007 May 29, 2024
3d35749
feat: semantic analyzer
Sway007 May 29, 2024
7d688e5
feat: semantic analyzer
Sway007 May 31, 2024
4c827cb
feat: code opt
Sway007 Jun 11, 2024
d899eba
feat: varying arguments
Sway007 Jun 11, 2024
b63c7df
refactor: shader-lab
Sway007 Jun 11, 2024
066df5a
feat: unit-test
Sway007 Jun 12, 2024
c7a0b0c
feat: unit-test
Sway007 Jun 12, 2024
d7ed025
feat: logger opt
Sway007 Jun 12, 2024
3700668
feat: unitest
Sway007 Jun 13, 2024
00322c8
feat: unitest
Sway007 Jun 13, 2024
7cf3d4a
feat: unitest
Sway007 Jun 13, 2024
b0c5c92
Merge branch 'dev/1.3' of https://github.com/galacean/engine into ref…
Sway007 Jun 13, 2024
098297f
feat: merge
Sway007 Jun 13, 2024
23d82a9
fix: unitest
Sway007 Jun 13, 2024
7865886
feat: code opt
Sway007 Jun 18, 2024
9a3df18
feat(wip): conditional compile
Sway007 Jun 18, 2024
9e09d3e
feat: conditional compilation
Sway007 Jun 19, 2024
4d536bb
feat: conditional compilation
Sway007 Jun 19, 2024
126158b
feat: conditional compilation
Sway007 Jun 19, 2024
47470da
feat: conditional compilation
Sway007 Jun 20, 2024
0d4a522
fix: ci
Sway007 Jun 25, 2024
6f0b7ee
fix: ci
Sway007 Jun 25, 2024
dd1f4cc
fix: ci
Sway007 Jun 25, 2024
1ee04bf
fix: ci
Sway007 Jun 25, 2024
1ac3f27
fix: cr
Sway007 Jun 25, 2024
8070bcf
fix: cr
Sway007 Jun 25, 2024
f8759ea
fix: cr
Sway007 Jun 25, 2024
505b8b5
fix: cr
Sway007 Jun 25, 2024
ab5a9f3
fix: cr
Sway007 Jun 25, 2024
be18fae
fix: cr
Sway007 Jun 25, 2024
7eb3512
fix: cr
Sway007 Jun 25, 2024
761ba68
fix: cr
Sway007 Jun 25, 2024
94c7b99
Merge branch 'dev/1.3' of https://github.com/galacean/engine into ref…
Sway007 Jun 25, 2024
62d77ed
fix: cr
Sway007 Jun 26, 2024
ee5f73f
feat: add struct parser
Sway007 Jun 26, 2024
4992243
refactor: compilation time
Sway007 Jun 27, 2024
66d775a
refactor: compilation time
Sway007 Jun 27, 2024
bb47f52
refactor: compilation time
Sway007 Jun 27, 2024
1a96678
fix: pp scanner
Sway007 Jun 27, 2024
f22ebcf
fix: macro init
Sway007 Jun 27, 2024
dcff32e
fix: pp
Sway007 Jun 27, 2024
7dcf586
feat(wip): add shader struct parser
Sway007 Jul 1, 2024
3998c55
feat(wip): add shader struct parser
Sway007 Jul 1, 2024
39d65ef
feat(wip): add shader struct parser
Sway007 Jul 1, 2024
0ee4617
feat(wip): add shader struct parser
Sway007 Jul 1, 2024
03e3a94
feat(wip): add shader struct parser
Sway007 Jul 2, 2024
2572fa3
feat: add shader struct parser
Sway007 Jul 2, 2024
7b1c931
Merge branch 'dev/1.3' of https://github.com/galacean/engine into ref…
Sway007 Jul 2, 2024
cc1c0fd
feat: add shader struct parser
Sway007 Jul 2, 2024
ad9059e
fix: shader pass compilation cache
Sway007 Jul 3, 2024
c5d2087
refactor: symbol table
Sway007 Jul 3, 2024
897ada9
feat: opt code
Sway007 Jul 4, 2024
3386f50
fix: overloaded function codegen
Sway007 Jul 4, 2024
7c49f4e
feat: code opt
Sway007 Jul 5, 2024
a3fba34
fix: ci
Sway007 Jul 8, 2024
1ac0b3f
fix: ci
Sway007 Jul 8, 2024
757b2a8
fix: ci
Sway007 Jul 8, 2024
1ff5a8a
feat: update readme
Sway007 Jul 8, 2024
2ab8011
feat: code opt
Sway007 Jul 8, 2024
cd10bc4
feat: rm unused code
Sway007 Jul 8, 2024
39810cc
feat: code opt
Sway007 Jul 8, 2024
37c824c
feat: code opt
Sway007 Jul 8, 2024
6e7625c
feat: code opt
Sway007 Jul 9, 2024
785c205
feat: code opt
Sway007 Jul 9, 2024
9544354
feat: code opt
Sway007 Jul 9, 2024
23ea18d
feat: code opt
Sway007 Jul 9, 2024
4b091a5
feat: code opt
Sway007 Jul 9, 2024
54f9e87
feat: code opt
Sway007 Jul 9, 2024
ccb3d4b
feat: code opt
Sway007 Jul 9, 2024
96e5e6f
feat: code opt
Sway007 Jul 9, 2024
c69d453
feat: code opt
Sway007 Jul 9, 2024
cb0133e
feat: code opt
Sway007 Jul 9, 2024
8d27998
feat: code opt
Sway007 Jul 9, 2024
9445b79
feat: code opt
Sway007 Jul 9, 2024
157f03e
feat: code opt
Sway007 Jul 9, 2024
51b75c6
feat: code opt
Sway007 Jul 9, 2024
28a2481
feat: code opt
Sway007 Jul 9, 2024
49e588d
feat: code opt
Sway007 Jul 9, 2024
7905831
feat: code opt
Sway007 Jul 9, 2024
8efeb9c
feat: code opt
Sway007 Jul 9, 2024
b8dbc7c
feat: code opt
Sway007 Jul 9, 2024
efdcbea
refactor: opt get macros
GuoLei1990 Jul 9, 2024
a58c562
feat: code opt
Sway007 Jul 9, 2024
6a543fd
feat: code opt
Sway007 Jul 9, 2024
0318a33
feat: code opt
Sway007 Jul 9, 2024
6df9aff
feat: opt code
Sway007 Jul 9, 2024
0ee545f
feat: opt code
Sway007 Jul 9, 2024
6dd1a94
feat: rm logger
Sway007 Jul 9, 2024
091d828
feat: rm logger
Sway007 Jul 9, 2024
8d42c14
feat: opt code
Sway007 Jul 9, 2024
1705002
fix: e2e
Sway007 Jul 10, 2024
c2e596d
feat: opt code
Sway007 Jul 10, 2024
e1618c0
fix: typo
Sway007 Jul 10, 2024
0c2c008
feat: add time log
Sway007 Jul 10, 2024
2181572
feat: opt code
Sway007 Jul 10, 2024
0b000fd
refactor: opt code
GuoLei1990 Jul 10, 2024
9932195
fix: skip space
Sway007 Jul 11, 2024
3425662
fix: lint
Sway007 Jul 11, 2024
7d29c68
fix: lint
Sway007 Jul 11, 2024
94d91f1
feat: opt gc
Sway007 Jul 11, 2024
4a8dcc7
fix: returnable pool
Sway007 Jul 11, 2024
a730793
feat: opt gc cost
Sway007 Jul 12, 2024
1d13f40
feat: opt gc cost
Sway007 Jul 12, 2024
685a3ec
feat: opt gc cost
Sway007 Jul 15, 2024
9ac9051
feat: opt gc cost
Sway007 Jul 15, 2024
b6332df
feat: code opt
Sway007 Jul 15, 2024
b7f0fe5
feat: code opt
Sway007 Jul 15, 2024
342ff77
feat: code opt
Sway007 Jul 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
74 changes: 37 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

- name: Install
run: pnpm install
- run: npm run build
- run: npm run build:editor

codecov:
runs-on: macos-latest
Expand All @@ -66,7 +66,7 @@ jobs:
- name: Install
run: pnpm install
- name: Build
run: npm run build
run: npm run build:editor
- name: Test
run: npm run test-cov
- run: pnpm install codecov -w
Expand All @@ -82,38 +82,38 @@ jobs:
node-version: [16.x]

steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Install pnpm
uses: pnpm/action-setup@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Run Cypress Tests
uses: cypress-io/github-action@v5
with:
build: npm run build
start: npm run e2e:case
wait-on: 'http://localhost:5175'
wait-on-timeout: 120
browser: chrome
- name: Upload Diff
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-diff
path: e2e/diff/
- name: Upload Origin
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-origin
path: e2e/fixtures/originImage
- name: Upload Screenshots
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-screenshots
path: e2e/downloads/
- uses: actions/checkout@v3
with:
lfs: true
- name: Install pnpm
uses: pnpm/action-setup@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Run Cypress Tests
uses: cypress-io/github-action@v5
with:
build: npm run build:editor
start: npm run e2e:case
wait-on: "http://localhost:5175"
wait-on-timeout: 120
browser: chrome
- name: Upload Diff
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-diff
path: e2e/diff/
- name: Upload Origin
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-origin
path: e2e/fixtures/originImage
- name: Upload Screenshots
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-screenshots
path: e2e/downloads/
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ e2e/.dev/mpa
.husky/post-commit
.husky/pre-push
.husky/post-merge

# For bison generated files used by ShaderLab
*.tab.c
*.output
GuoLei1990 marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 19 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
"test-debug": "cross-env TS_NODE_PROJECT=tsconfig.tests.json floss --path tests -r ts-node/register --debug",
"test-cov": "cross-env TS_NODE_PROJECT=tsconfig.tests.json IS_COV=1 nyc --reporter=lcov floss --path tests -r ts-node/register",
"build": "npm run b:module && npm run b:types",
"build:editor": "npm run b:module:editor && npm run b:types",
"lint": "eslint packages/*/src --ext .ts",
"watch": "cross-env NODE_ENV=development BUILD_TYPE=MODULE rollup -cw -m inline",
"watch:umd": "cross-env NODE_ENV=development BUILD_TYPE=UMD rollup -cw -m inline",
"watch": "cross-env NODE_ENV=release BUILD_TYPE=MODULE rollup -cw -m inline",
"watch:editor": "cross-env NODE_ENV=editor BUILD_TYPE=MODULE rollup -cw -m inline",
"watch:umd": "cross-env NODE_ENV=release BUILD_TYPE=UMD rollup -cw -m inline",
"watch:umd:editor": "cross-env NODE_ENV=editor BUILD_TYPE=UMD rollup -cw -m inline",
"b:types": "pnpm -r --filter=./packages/* run b:types",
"b:module": "cross-env BUILD_TYPE=MODULE rollup -c",
"b:umd": "cross-env BUILD_TYPE=UMD rollup -c",
"b:module": "cross-env BUILD_TYPE=MODULE NODE_ENV=release rollup -c",
"b:module:editor": "cross-env BUILD_TYPE=MODULE NODE_ENV=editor rollup -c",
"b:umd": "cross-env BUILD_TYPE=UMD NODE_ENV=release rollup -c",
"b:miniprogram": "cross-env BUILD_TYPE=MINI rollup -c",
"b:all": "npm run b:types && cross-env BUILD_TYPE=ALL rollup -c",
"b:all": "cross-env NODE_ENV=release npm run b:types && cross-env BUILD_TYPE=ALL NODE_ENV=release rollup -c",
"b:all:editor": "cross-env NODE_ENV=editor npm run b:types && cross-env BUILD_TYPE=ALL rollup -c",
"clean": "pnpm -r exec rm -rf dist && pnpm -r exec rm -rf types",
"e2e:case": "pnpm -C ./e2e run case",
"e2e": "cypress run --browser chrome --headless",
Expand All @@ -36,32 +41,33 @@
"@types/chai-spies": "^1.0.3",
"@types/mocha": "^8.0.0",
"@types/node": "^18.7.16",
"@types/webxr": "latest",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"chai": "^4.3.6",
"chai-spies": "^1.0.0",
"cross-env": "^5.2.0",
"cypress": "^12.17.1",
"cypress-recurse": "^1.23.0",
"electron": "^13",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^5.0.0",
"floss": "^5.0.1",
"fs-extra": "^10.1.0",
"husky": "^8.0.0",
"lint-staged": "^10.5.3",
"nyc": "^15.1.0",
"odiff-bin": "^2.5.0",
"prettier": "^3.0.0",
"rollup": "^2.36.1",
"rollup-plugin-glslify": "^1.2.0",
"rollup-plugin-jscc": "^2.0.0",
"rollup-plugin-modify": "^3.0.0",
"rollup-plugin-serve": "^1.1.0",
"rollup-plugin-swc3": "^0.10.1",
"ts-node": "^10",
"typescript": "^5.1.6",
"@types/webxr": "latest",
"husky": "^8.0.0",
"fs-extra": "^10.1.0",
"cypress": "^12.17.1",
"cypress-recurse": "^1.23.0",
"odiff-bin": "^2.5.0"
"typescript": "^5.1.6"
},
"lint-staged": {
"*.{ts}": [
Expand All @@ -70,4 +76,4 @@
]
},
"repository": "[email protected]:galacean/runtime.git"
}
}
2 changes: 1 addition & 1 deletion packages/core/src/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export class Engine extends EventDispatcher {
protected _initialize(configuration: EngineConfiguration): Promise<Engine> {
const { shaderLab, physics } = configuration;

if (shaderLab) {
if (shaderLab && !Shader._shaderLab) {
Shader._shaderLab = shaderLab;
}

Expand Down
47 changes: 25 additions & 22 deletions packages/core/src/shader/Shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,51 +89,54 @@ export class Shader implements IReferable {
throw "ShaderLab has not been set up yet.";
}

const shaderInfo = Shader._shaderLab.parseShader(nameOrShaderSource);
if (shaderMap[shaderInfo.name]) {
console.error(`Shader named "${shaderInfo.name}" already exists.`);
const shaderContent = Shader._shaderLab._parseShaderContent(nameOrShaderSource);
if (shaderMap[shaderContent.name]) {
console.error(`Shader named "${shaderContent.name}" already exists.`);
return;
}
const subShaderList = shaderInfo.subShaders.map((subShaderInfo) => {
const passList = subShaderInfo.passes.map((passInfo) => {
if (typeof passInfo === "string") {
const subShaderList = shaderContent.subShaders.map((subShaderContent) => {
const passList = subShaderContent.passes.map((passInfo) => {
if (passInfo.isUsePass) {
// Use pass reference
const paths = passInfo.split("/");
const paths = passInfo.name.split("/");
return Shader.find(paths[0])
?.subShaders.find((subShader) => subShader.name === paths[1])
?.passes.find((pass) => pass.name === paths[2]);
}

const shaderPass = new ShaderPass(
const shaderPassContent = new ShaderPass(
passInfo.name,
passInfo.vertexSource,
passInfo.fragmentSource,
passInfo.contents,
passInfo.vertexEntry,
passInfo.fragmentEntry,
passInfo.tags
);

const renderStates = passInfo.renderStates;
const renderState = new RenderState();
shaderPass._renderState = renderState;

shaderPassContent._renderState = renderState;
// Parse const render state
const constRenderStateInfo = renderStates[0];
for (let k in constRenderStateInfo) {
Shader._applyConstRenderStates(renderState, <RenderStateElementKey>parseInt(k), constRenderStateInfo[k]);
const { constantMap, variableMap } = renderStates;
for (let k in constantMap) {
Shader._applyConstRenderStates(renderState, <RenderStateElementKey>parseInt(k), constantMap[k]);
}

// Parse variable render state
const variableRenderStateInfo = renderStates[1];
const renderStateDataMap = {} as Record<number, ShaderProperty>;
for (let k in variableRenderStateInfo) {
renderStateDataMap[k] = ShaderProperty.getByName(variableRenderStateInfo[k]);
for (let k in variableMap) {
renderStateDataMap[k] = ShaderProperty.getByName(variableMap[k]);
}
shaderPass._renderStateDataMap = renderStateDataMap;
return shaderPass;
shaderPassContent._renderStateDataMap = renderStateDataMap;

return shaderPassContent;
});
return new SubShader(shaderInfo.name, passList, subShaderInfo.tags);

return new SubShader(subShaderContent.name, passList, subShaderContent.tags);
});

shader = new Shader(shaderInfo.name, subShaderList);
shaderMap[shaderInfo.name] = shader;
shader = new Shader(shaderContent.name, subShaderList);
shaderMap[shaderContent.name] = shader;
return shader;
} else {
if (shaderMap[nameOrShaderSource]) {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/shader/ShaderMacro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ShaderMacroCollection } from "./ShaderMacroCollection";
*/
export class ShaderMacro {
/** @internal */
static _macroMaskMap: string[][] = [];
static _macroMaskMap: ShaderMacro[][] = [];
/** @internal */
static _macroNameIdMap: Record<string, number> = Object.create(null);

Expand Down Expand Up @@ -41,9 +41,9 @@ export class ShaderMacro {
ShaderMacro._macroMap[key] = macro;
if (index == maskMap.length) {
maskMap.length++;
maskMap[index] = new Array<string>(32);
maskMap[index] = new Array<ShaderMacro>(32);
}
maskMap[index][bit] = key;
maskMap[index][bit] = macro;
ShaderMacro._macroCounter++;
}
return macro;
Expand All @@ -52,7 +52,7 @@ export class ShaderMacro {
/**
* @internal
*/
static _getNamesByMacros(macros: ShaderMacroCollection, out: string[]): void {
static _getMacrosElements(macros: ShaderMacroCollection, out: ShaderMacro[]): void {
const maskMap = ShaderMacro._macroMaskMap;
const mask = macros._mask;
out.length = 0;
Expand Down
Loading
Loading