Skip to content

Commit

Permalink
Allow users to clear code cache (#15706)
Browse files Browse the repository at this point in the history
  • Loading branch information
deltakosh authored Oct 15, 2024
1 parent 96d8f17 commit b54e5d5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/dev/core/src/Materials/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ export class Effect implements IDisposable {
* Enable logging of the shader code when a compilation error occurs
*/
public static LogShaderCodeOnCompilationError = true;

/**
* Use this with caution
* See ClearCodeCache function comments
*/
public static AutomaticallyClearCodeCache = false;

/**
* Name of the effect.
*/
Expand Down Expand Up @@ -747,6 +754,10 @@ export class Effect implements IDisposable {
if (this._fallbacks) {
this._fallbacks.unBindMesh();
}

if (Effect.AutomaticallyClearCodeCache) {
this.clearCodeCache();
}
}

/**
Expand Down Expand Up @@ -1448,6 +1459,18 @@ export class Effect implements IDisposable {
return this;
}

/**
* Use this wisely: It will remove the cached code from this effect
* It is probably ok to call it if you are not using ShadowDepthWrapper or if everything is already up and running
* DO NOT CALL IT if you want to have support for context lost recovery
*/
public clearCodeCache() {
this._vertexSourceCode = "";
this._fragmentSourceCode = "";
this._fragmentSourceCodeBeforeMigration = "";
this._vertexSourceCodeBeforeMigration = "";
}

/**
* Release all associated resources.
**/
Expand All @@ -1464,6 +1487,8 @@ export class Effect implements IDisposable {
}
this._engine._releaseEffect(this);

this.clearCodeCache();

this._isDisposed = true;
}

Expand Down

0 comments on commit b54e5d5

Please sign in to comment.