filament icon indicating copy to clipboard operation
filament copied to clipboard

Web: Missing fence API bindings for TypeScript/Javascript

Open BStringhamVRSK opened this issue 1 year ago • 3 comments

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

  • Engine::createFence()
  • Engine::destroy(fence)
  • Fence::Wait()
  • Fence::WaitAndDestroy()

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?

BStringhamVRSK avatar Nov 29 '23 20:11 BStringhamVRSK

I don't think emscripten even supports fences.

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

pixelflinger avatar Dec 01 '23 21:12 pixelflinger

@pixelflinger The synchronization artifacts we are seeing are these:

  • An object is added to the scene, it renders correctly
  • The object is modified: mesh removed from scene, old mesh and vertex/index buffers deleted; new mesh and vertex/index buffers created and added to the scene
  • New object sometimes does not appear, or may appear with corrupted geometry.

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 avatar Dec 04 '23 19:12 BStringhamVRSK

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

BStringhamVRSK avatar Mar 21 '24 17:03 BStringhamVRSK