Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixi V8 Upgrade #1495

Merged
merged 87 commits into from
Oct 17, 2024
Merged

Pixi V8 Upgrade #1495

merged 87 commits into from
Oct 17, 2024

Conversation

tannerwuster
Copy link
Contributor

Upgrade to Pixi v7 to v8 highlights several key changes that are expected to lead to significant performance improvements. These include:

  • WebGPU Renderer: The new version of Pixi introduces a WebGPU-based renderer as a core rendering paradigm, which is expected to provide better performance and set the stage for future advancements as WebGL phases out.
  • Graphics and Texture Upgrades: The update includes numerous upgrades to graphics and texture handling, which should result in improved performance.

Additionally, the description mentions that there are many other changes included in the update, which can be found in the here. Overall, the upgrade to Pixi v8 is expected to bring significant performance gains and improvements to the library.

@bhousel
Copy link
Contributor

bhousel commented Oct 8, 2024

Noting here the few issues that I'd like to check before merging this to main. None of this is really blocking.

  • Background imagery seams
    (Texture frame dimensions were off by 1px) (4e8f16b)
  • Try to get max supported texture size and use that for the atlas textures (currently 2048x2048)
    (new idea, but would be good to minimize the texture swaps) (cdfc590)
  • Consider using textures for dash line drawing
    (new idea, this might give us a bit of perf boost if they dashes look same) (f3f689f)
  • Check text label textures used in scene and free the ones that aren't needed anymore
    (we've never cleaned these up before, and we really should) (02ade6a)
  • For testing, allow user to supply an optional url parameter to use a specific renderer:
    &renderer=val where val is one of webgl1, webgl2 (or just webgl), webgpu
    Pixi will console log the renderer in use at startup. (1c3779c)

Specifically, `deferredRedraw` is a thing the background tile layer will try to call.
We can use the max supported size to avoid the texture swaps.
This works in WebGL, but seems to raise a warning in WebGPU.
The WebGPU code is commented out for now.
This isn't a perfect solution, but it will prevent the Text Atlas from
continuing to grow forever
A few things going on here:
- We were calling `texSubImage2D` with the wrong rect (x,y,w,h) in some situations
- It was using `texture.frame` which is the frame with the half pixel correction applied to it,
  making it 1px too small - this was introducing 1px of seam
- In situations where we use padding (symbols and text), we need to remove the
  padding from the bin, so we can just use the bin as the rectangle for `texSubImage2D`
- Also improved the calculations for the atlas sizes.  Now we will prefer
  8196x8196, but smaller sizes are fine too.  Anything larger is just really unnecessary.
- Tested tiles with and without the half-pixel correction, and yes we should
  still keep this code there to avoid textures from sampling neighbor texels.
This is a small improvement on 8afe728

WebGPU has a `writeTexture` call that works directly on ArrayBuffers, so we don't
need to do an extra async copy with `createImageBitmap` to convert the pixels into
an image supported by `copyExternalImageToTexture`.
This switches the DashLine plugin over to using textures instead of drawing
every dash with geometry (moveTo/lineTo).  This causes a huge speedup
around places that have a lot of dashed lines, or very long dashed lines.

Also simplified the DashLine internals, and fixed some various mysterious
bugs in that code, and did the stuff needed to make it work on Pixi v8.
I also renamed `DashLine.polygon` -> `DashLine.poly` to make it like pixi v8.
`&renderer=val` where val is one of `webgl1`, `webgl2` (or just `webgl`), `webgpu`
Pixi will console log the renderer in use at startup.
@bhousel bhousel merged commit 4beea45 into main Oct 17, 2024
5 checks passed
@bhousel bhousel deleted the pixi_v8 branch October 17, 2024 20:01
@bhousel
Copy link
Contributor

bhousel commented Oct 17, 2024

Update on this...
I merged this pull request today, and it's now available for testing in our latest canary build ! 🎉
This was a big effort by the Rapid dev team, so hats off to @tannerwuster and @Bonkles for their work too!
Rapid canary builds will now report themselves as v2.5.0-pre0 - this will be in the next minor release of Rapid.

Pixi v8 offers a bunch of improvements - you can read more about them here.
Most scenes in Rapid now feel a little bit faster due to Pixi's improved geometry batching performance. We've also made a few specific improvements to make scenes with a lot of dashed lines render a lot faster.

This also marks the first time that we can try out the new WebGPU renderer in Pixi. WebGPU is intended as the successor technology to WebGL. It's still an experimental technology in most web browsers, but it should prove to be even more performant in the future as browsers and Pixi improve their support for it. For now, WebGL remains the default renderer, and Rapid should continue to run on any device that supports even old versions of WebGL.

👉 We'd appreciate some help testing, so I added a url parameter to force Rapid to use a particular renderer:
You can optionally add &renderer=val to the url, where val is one of: webgl1, webgl2 (or just webgl), or webgpu

If you have your browser developer console open, it will print the version of Pixi and which renderer is in use:
Screenshot 2024-10-17 at 4 50 08 PM

If you do notice any issues when running Rapid with one of these flags, please report them here on GitHub, and let us know what you find! 🙇

@bhousel bhousel added the feature-renderer Issue or request related to the renderer / WebGL label Oct 17, 2024
@bhousel bhousel mentioned this pull request Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed feature-renderer Issue or request related to the renderer / WebGL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants