eternagame / eterna-next

The Eterna citizen science platform for RNA design
https://eternagame.org
Other
0 stars 0 forks source link

Designer rendering research/prototyping #298

Open luxaritas opened 1 year ago

luxaritas commented 1 year ago

Due to the complexity of interoperation between canvas and DOM, we want to explore the viability of an SVG-based 2D RNA visualization. In particular, there are concerns around the performance of animations with large numbers of bases.

NB: We probably still have to deal with Canvas for RNA3D, which means we probably still need to think through how interop needs to work.

luxaritas commented 1 year ago

After doing some research, it looks like SVG starts to break down around 1000 elements, which is quite low in our case. I'll probably want to start looking at other options for WebGL/DOM integration as it seems like we may not have much of a choice

luxaritas commented 1 year ago

Ultimately this isn't an issue specific to RNA2D - it affects RNA3D as well, and really doesn't have much to do about the performance of RNA2D itself at this point (since we've determined SVG won't cut it) but more generally handling interlaced HTML/WebGL content.

I started looking into this, and found a few resources:

Eventually I stumbled across https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas#synchronous_display_of_frames_produced_by_an_offscreencanvas - this shows a pattern of using OffscreenCanvas.transferToImageBitmap and a canvas with a bitmaprenderer context, which is supposed to allow for transferring image data without a readback from the GPU to CPU. Now Safari doesn't support OffscreenCanvas, but createImageBitmap can create an ImageBitmap directly from a regular WebGL canvas, which should have the same benefits.

I used a modified version of the PixiJS Bunny Mark application to test this out, and with 10k bunnies, splitting the image across 16 canvas elements:

Turns out, Firefox incurs readbacks when generating ImageBitmaps. There's an open bug for createImageBitmap and one for OffscreenCanvas.transferToImageBitmap.

luxaritas commented 1 year ago

I'm throwing this under designer-hud since at this point I'm considering this largely in terms of its impact with the windowing system

luxaritas commented 1 year ago

Investigating virtual-webgl gave me the idea that maybe passing the webgl canvas to a Context2D's drawImage would work instead, but same problem exists there, with a related open bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1163426