In this effort to try to figure out the most reliable way to know when the GPU is ready to render, I was studying this thread.
And I quote @aardgoose from it:
The shader compile/link operations are carried out asynchronously to your Javascript in a separate GPU thread./process (even without parallel compile implemented), so those calls appear to complete quickly. (for Chrome at least).
However when you make any WebGL call that needs to see the result of the compile/link operations, that call waits for them to complete.
I guess that applies to any async operation in the GPU involving CPU/GPU communication, like also texture upload.
So if that’s true, which seems logic, manually calling one of those ‘cheap’ WebGL operations would provide us with a way to have some kind of ‘onReady’ utility in the Three.js lib, to hopefully do something like the following without having to rely on RAFs, and perform everything synchronously:
scene.add(mySuperHeavyTextureMaterialMesh);
renderer.render(scene, camera); // That will make the GPU very busy
// This onReady method could execute internally one of those WebGL operations
// that rely on the GPU to have finished its job and be ready,
// and then fire a callback
renderer.onReady( () => {
// Now the GPU is idle and ready to render, do your stuff
})
My WebGL knowledge is basic at best, so I don’t know if this is genius or just plain stupid.
If it could work I would gladly make a PR to try to add it to the lib, any feedback is super welcome
.