Merge pull request #2410 from GuoLei1990/fix/shader-destroy

Fix shader destroy memory residual
This commit is contained in:
SwayYan
2024-10-30 18:08:12 +08:00
committed by GitHub
3 changed files with 8 additions and 2 deletions

View File

@@ -491,7 +491,7 @@ export class Engine extends EventDispatcher {
if (length > shaderProgramPools.length) {
shaderProgramPools.length = length;
}
shaderProgramPools[index] = pool = new ShaderProgramPool();
shaderProgramPools[index] = pool = new ShaderProgramPool(this);
shaderPass._shaderProgramPools.push(pool);
}
return pool;

View File

@@ -146,8 +146,11 @@ export class ShaderPass extends ShaderPart {
_destroy(): void {
const shaderProgramPools = this._shaderProgramPools;
for (let i = 0, n = shaderProgramPools.length; i < n; i++) {
shaderProgramPools[i]._destroy();
const shaderProgramPool = shaderProgramPools[i];
shaderProgramPool._destroy();
delete shaderProgramPool.engine._shaderProgramPools[this._shaderPassId];
}
// Clear array storing multiple engine shader program pools
shaderProgramPools.length = 0;
}

View File

@@ -1,3 +1,4 @@
import { Engine } from "../Engine";
import { ShaderMacroCollection } from "./ShaderMacroCollection";
import { ShaderProgram } from "./ShaderProgram";
@@ -11,6 +12,8 @@ export class ShaderProgramPool {
private _lastQueryMap: Record<number, ShaderProgram>;
private _lastQueryKey: number;
constructor(public engine: Engine) {}
/**
* Get shader program by macro collection.
* @param macros - macro collection