-
Notifications
You must be signed in to change notification settings - Fork 345
Description
Not all resources are used all the time by a 3D application. In particular, applications often have caches of resources which are rarely used and low priority. Many times, the contents of these resources can be recreated on-demand.
This represents a classic space-time tradeoff. If there is plenty of memory, it makes sense for an application to keep these resources around so they can be used without having to recreate them (spending memory for time's benefit). However, if available memory gets low, these resources are good candidates to destroy because their contents can be recreated, and they are unlikely to be needed immediately (spending time for memory's benefit).
Because the web author doesn't know the exact machine their code is running on, they often are unable to make the right space-time tradeoff. Instead, the OS or browser has a much better knowledge of the system resources than the website. It would be valuable of the OS or browser could help the application make this tradeoff.
This problem is particularly important on memory-constrained devices.
Purgeable resources are one way of doing this. Each resource could have something like:
enum GPUPurgeabilityState {
"ContentsPreserved",
"ContentsDiscarded"
};
interface GPUResourceBase {
void setPurgeable();
GPUPurgeabilityState setNonPurgeable();
}If a resource is marked as purgeable, the OS / browser might discard its contents. When a resource is marked as non-purgeable, the function returns state which determines whether or not the contents are still valid. This is better than the application unconditionally deleting the resource, because its contents are preserved if memory permits, thereby improving performance and battery life.
This way, the OS / browser can help the application make a good space-time tradeoff without any application code having to run when memory gets low.