ruffle icon indicating copy to clipboard operation
ruffle copied to clipboard

webgl: Support basic BitmapData.draw on webgl backend

Open adrian17 opened this issue 3 years ago • 8 comments

Not a lot of code, is it :) The non-renderer side is based on @torokati44 's wgpu BitmapData.draw branch, and that could be restarted on top of this. TBH I'd love for someone else to take this over, I feel more comfortable in AVM2 land :)

Missing stuff that needs to be fixed, in order from "necessary for MVP" to "maybe later", with no clear border:

  • ~~bug: blending of transparent stuff is broken, I couldn't figure it out.~~ Fixed by Mike's premultiplied alpha PRs

  • ~~bug: current implementation of attachBitmap means that drawing on attached bitmap will reflect on the screen 1 frame late~~

  • no antialiasing, especially visible on text

  • it's slow, halfway because readPixels needs to wait till GPU finishes work, halfway because the implementation of copy_pixels_to_bitmapdata is really slow , especially the manual blending logic.

    • need to figure out the long-term solution for this ~~and the attachBitmap bug~~, especially permanently storing on GPU side and not loading to CPU unless AS actually needs it. This might help blending too.

Example profile (I dropped some samples to make it smaller, so readPixels should have more like 45%). You can see the readPixels just waiting, and manual copy+blend loop being damn slow. image

  • clip rect argument
  • ~~supporting BitmapData as argument~~
  • ~~- smoothing flag~~
  • blending parameter (needed for collision detection in Learn 2 Fly)
  • ~~what about other backends?~~

I'll post some more screenshots in a comment.

adrian17 avatar Apr 05 '22 20:04 adrian17

Fancy pants 2 (https://github.com/ruffle-rs/ruffle/issues/4646): backgrounds show up :) 2022-04-05_22-20-39

adrian17 avatar Apr 05 '22 20:04 adrian17

Mind Bender (https://github.com/ruffle-rs/ruffle/issues/2296): backgrounds show up, but 170 synchronous draw calls in a row are slooow - the game lags for ~10s until this shows up: 2022-04-05_22-23-11

(note: it is my belief that not calling readPixels would make draw() calls slightly more gpu-asynchronous and lag the VM less, but I don't have a guarantee here. If it turns out that it's slow no matter what... we have a problem.)

adrian17 avatar Apr 05 '22 20:04 adrian17

From the other reports we have:

-- #6336 and #5139 seem to be displayed perfectly now.

-- #4122 is playable as collisions are fixed.

-- #6584 is improved.

Toad06 avatar Apr 05 '22 21:04 Toad06

https://github.com/ruffle-rs/ruffle/issues/2013 slightly improved, now displays wind and rainbow unknown

SN902 avatar May 04 '22 12:05 SN902

I'm working on a related feature locally - BitmapData.draw for the webgpu backend.

Aaron1011 avatar Jun 03 '22 18:06 Aaron1011

My earlier work here may be relevant @Aaron1011: https://github.com/ruffle-rs/ruffle/discussions/4288

torokati44 avatar Jun 03 '22 18:06 torokati44

I've incorporated the AVM1-specific logic from this PR into https://github.com/ruffle-rs/ruffle/pull/7254, which adds support for the wgpu backend.

Aaron1011 avatar Jun 18 '22 23:06 Aaron1011

#6629 is this PR. Did you mean to refer to, or comment under, https://github.com/ruffle-rs/ruffle/pull/7254 perhaps?

torokati44 avatar Jun 19 '22 08:06 torokati44