google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.76k stars 1.88k forks source link

Web: Missing fence API bindings for TypeScript/Javascript #7395

Open BStringhamVRSK opened 10 months ago

BStringhamVRSK commented 10 months ago

The TypeScript/JavaScript bindings appear to be missing the following fence functions:

We are experiencing synchronization issues on our web implementation that we don't see on Windows, iOS, or Android, and I believe the lack of fences is the cause.

Is there an underlying reason why these don't exist?

pixelflinger commented 10 months ago

I don't think emscripten even supports fences.

What do you mean by "We are experiencing synchronization issues".

BStringhamVRSK commented 10 months ago

@pixelflinger The synchronization artifacts we are seeing are these:

Is there a possibility that on Web, the mesh or vertex/index buffers are getting modified while a frame is still in flight? This bug has that kind of feel, so I'm wondering if that is the case here. We don't see this on other platforms. The only differences in code are primarily at the JS interface to Filament. It's possible the bug lies with us, but, given that the scene always draws correctly before any changes are made, makes me suspect that the CPU and GPU are getting out of sync, meaning that the CPU is fiddling with resources the GPU is still trying to use.

On other platforms, we are allowing the CPU to get 2 frames ahead of the GPU, and performing sync using fences. I'd like to do the same on web. On web, I assume Filament doesn't block the CPU and wait for the GPU to finish when a frame is submitted. So, if I start messing with the scene, I could be messing things up.

BStringhamVRSK commented 7 months ago

@pixelflinger We are still seeing this issue. Do you have any ideas on workarounds or other suggestions on possible causes?