Better lifetime control of cached shader programs
- Dominant language
- JavaScript
- Stars
- 15.7k
- Forks
- 3.9k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 32
Description
Once the reference count for a shader program goes to zero, it is deleted every 120 frames in an attempt to avoid trashing the cache:
```
if (this._shaderFrameCount++ === 120) {
this._shaderFrameCount = 0;
this._context.shaderCache.destroyReleasedShaderPrograms();
}
```
However, this can still trash the cache when shader programs are re-requested a bit later. Some ideas to address this:
- Perhaps the cache has to exceed a certain number of shader programs with a zero reference count before deleting them all.
- Pass in the optional number of frames when requesting a shader program from the cache. Also allow forever and explicit destruction later.
- Pass in an optional function that evaluates to `true` when the function should be deleted, e.g., `n` number of frames passed, a parent object was destroyed, etc. We may need to build a higher-order function to logically and functions from different cache requests together.
The most low-tech solution is good with me. A typical game will know all of its shader for a level up front and will compile them all while the user plays pong on the loading screen. We, of course, don't know our shaders in many cases until runtime and don't know how many of them we will generate.
CC #640
Contributor guide
Assessment
This issue has not been assessed yet.