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

Web Assembly port #155

Closed
pcwalton opened this issue May 22, 2019 · 29 comments
Closed

Web Assembly port #155

pcwalton opened this issue May 22, 2019 · 29 comments

Comments

@pcwalton
Copy link
Collaborator

@pcwalton pcwalton commented May 22, 2019

It would be nice to have a Web Assembly port, like Google's CanvasKit for Skia.

@asajeffrey
Copy link
Member

@asajeffrey asajeffrey commented May 22, 2019

Yes please!

@asajeffrey
Copy link
Member

@asajeffrey asajeffrey commented May 22, 2019

There might be a bit of work getting the multithreaded story sorted out, it would be nice if we could use post message rather than SharedArrayBuffer for communication.

@pcwalton
Copy link
Collaborator Author

@pcwalton pcwalton commented May 22, 2019

Web Assembly is one of the reasons behind the Executor and RenderCommandListener abstractions. (The other one is WebRender, which is hesitant to add any more threads, at least in Gecko.) Core Pathfinder no longer spawns any threads. For a single-threaded workload you would buffer RenderCommands into a vector, then send them to a Renderer all at once instead of using a SceneProxy. This is likely what a Web Assembly port will want to do.

@est31
Copy link
Contributor

@est31 est31 commented Jun 1, 2019

I'd love to help with this. I need some project to find out how ready the wasm ecosystem is and this seems like it could be that project. @pcwalton do you have a list of items to work on?

@pcwalton
Copy link
Collaborator Author

@pcwalton pcwalton commented Jun 1, 2019

@est31 Here are the remaining blockers:

  • HarfBuzz needs to compile with wasm
  • FreeType needs to compile with wasm
  • Check skribo to make sure it compiles
  • Check Pathfinder to make sure it compiles
  • The pathfinder_gl crate needs a WebGL implementation
  • Canvas C API needs to be finished
  • JavaScript bindings need to be written
@est31
Copy link
Contributor

@est31 est31 commented Jun 1, 2019

@pcwalton thanks for the list.

I'm not sure I want to do the HarfBuzz/Freetype parts because I don't want to attempt installing emscripten again. It's very tedious to install and set up. The js embedding for wasi right now seems to build on emscripten itself :/. So maybe I should work on #164 first?

Canvas C API needs to be finished

Instead of the C API, I'd have used wasm-bindgen instead. It allows you to expose rust-y APIs to javascript.

@pcwalton
Copy link
Collaborator Author

@pcwalton pcwalton commented Jun 1, 2019

Any and all help is appreciated! I'll probably get to FreeType and HB if someone else doesn't do it first.

As for the C API, we need it for other reasons, for example @toolness' Unity plugin, so I figured we might as well use it for the wasm port as well. But I don't feel strongly about it either way.

@est31
Copy link
Contributor

@est31 est31 commented Jun 1, 2019

Hmm yeah I just realized that #164 is larger than I thought. It requires changes in font-kit as well as skribo or requires replacing skribo use entirely both of which is probably involved and it's probably easier for you given you know both much better than me.

I'd love to help though after #164 is resolved! Of course, only if you haven't done WASM support by then already :).

@jrowny
Copy link

@jrowny jrowny commented Jul 10, 2019

FreeType and Harfbuzz compile without any modification via emscripten. We'd have to compile the whole thing via wasm32-unknown-emscripten then right? I'm a bit new to Rust, but I'd love to help with this as well if I can.

@jrowny
Copy link

@jrowny jrowny commented Jul 10, 2019

Also, won't SIMD be a problem?

@est31
Copy link
Contributor

@est31 est31 commented Jul 10, 2019

@jrowny feel free to take this issue :)

@jnetterf
Copy link

@jnetterf jnetterf commented Nov 30, 2019

I have a PR which adds a glow implementation of the device abstraction: #243

This allows parts of pathfinder to target WebGL 2 on wasm32-unknown-unknown. I'd appreciate feedback.

If this works, I think this leaves getting FreeType and Harfbuzz to compile without emscripten as the main challenge.

@s3bk
Copy link
Contributor

@s3bk s3bk commented Jan 27, 2020

I would like to report success!
DEMO

Modified pathfinder repo: https://github.com/s3bk/pathfinder
Grafeia repo: https://github.com/grafeia/grafeia

I am using vector to draw things and font to parse fonts and draw text.

@pcwalton
Copy link
Collaborator Author

@pcwalton pcwalton commented Jan 28, 2020

Wow!

@boulabiar
Copy link

@boulabiar boulabiar commented Jan 28, 2020

Excellent !
Does it work with complex languages like Arabic?

@s3bk
Copy link
Contributor

@s3bk s3bk commented Jan 28, 2020

@boulabiar I plan to support right to left scripts eventually. The pdf viewer using the font crate renders Arabic text correct.
What I may not implement for a while is embeddings, and instead require a new paragraph when the direction is switched.

@s3bk
Copy link
Contributor

@s3bk s3bk commented Jan 28, 2020

Upon request from #rust-offtopic, here is the PDF viewer running in wasm:

https://pdf-rs.github.io/view-wasm/

(use ◁ and ▷ keys to navigate)

I moved the code to display a scene here: https://github.com/s3bk/pathfinder_view

@CoreyDotCom
Copy link

@CoreyDotCom CoreyDotCom commented Feb 5, 2020

Nice job @s3bk! Any chance you can hoist a sample up so that it's straight forward to infer performance of the tiger sample? e.g. Hard to tell if it's redrawing in full as you pan or if things are cached at that point. Looking to check out what the perf/cost is for dynamically changing path data / animation in the wasm port.

@s3bk
Copy link
Contributor

@s3bk s3bk commented Feb 5, 2020

@CoreyDotCom the scene of the tiger is cached, but everything is redrawn every frame (that something changed).

@s3bk
Copy link
Contributor

@s3bk s3bk commented Feb 5, 2020

@CoreyDotCom https://github.com/s3bk/webgl_demo/
https://s3bk.github.io/webgl_demo/

In the grafeia demo, a lot of time is spend copying memory… 30% on chromium and 11.5% in Firefox.

@leoyanggit
Copy link

@leoyanggit leoyanggit commented Jun 4, 2020

https://github.com/s3bk/pathfinder

I would like to report success!
DEMO

Modified pathfinder repo: https://github.com/s3bk/pathfinder
Grafeia repo: https://github.com/grafeia/grafeia

I am using vector to draw things and font to parse fonts and draw text.

@s3bk WoW looks promising. I wanted to try it out. Is there instruction about how to build pathfinder with your change to wasm?

@s3bk
Copy link
Contributor

@s3bk s3bk commented Jun 4, 2020

@leoyanggit
look at the Makefile in https://github.com/s3bk/webgl_demo/
You can add a [patch] section to use servo/pathfinder

@leoyanggit
Copy link

@leoyanggit leoyanggit commented Jun 11, 2020

@s3bk Thanks! I successfully compiled and ran webgl_demo. I'm currently looking into text rendering. You mentioned you are using https://github.com/pdf-rs/font to render text. I'm wondering you have a demo that uses it along with pathfinder.

@s3bk
Copy link
Contributor

@s3bk s3bk commented Jun 11, 2020

@leoyanggit you are lucky. I just implemented some for pathfinder_canvas
s3bk@5b003f4

pathfinder_canvas = { git = "https://github.com/s3bk/pathfinder", features = ["pf-simple-text"] }

Demo using the canvas api from python:

https://github.com/s3bk/pathfinder_python

@s3bk
Copy link
Contributor

@s3bk s3bk commented Jun 11, 2020

woops. WebAssembly … the canvas text stuff should still work.

@leoyanggit
Copy link

@leoyanggit leoyanggit commented Jun 11, 2020

If I use pf-text feature pathfinder_canvas = { git = "https://github.com/servo/pathfinder/", features = ["pf-text"] } in my project, wasm-pack build -t no-modules --release will try to compile servo-freetype-sys with wasm32-unknown-unknown target. But it failed with the following error. It looks like wasm-pack calling my clang directly with wasm32-unknown-unknown target. I'm new to Rust and WebAssembly. I'm wondering if I should expect wasm-pack call emscripten to compile servo-freetype-sys for this case.

Run Build Command(s):/usr/bin/make cmTC_118b1/fast && /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_118b1.dir/build.make CMakeFiles/cmTC_118b1.dir/build Building C object CMakeFiles/cmTC_118b1.dir/testCCompiler.c.o /usr/bin/clang -ffunction-sections -fdata-sections -fPIC --target=wasm32-unknown-unknown -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -o CMakeFiles/cmTC_118b1.dir/testCCompiler.c.o -c /Users/lyang/test/target/wasm32-unknown-unknown/release/build/servo-freetype-sys-8979fe94f5a2c82d/out/build/CMakeFiles/CMakeTmp/testCCompiler.c error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"' 1 error generated. make[1]: *** [CMakeFiles/cmTC_118b1.dir/testCCompiler.c.o] Error 1 make: *** [cmTC_118b1/fast] Error 2

@s3bk
Copy link
Contributor

@s3bk s3bk commented Jun 11, 2020

pf-text is the old freetype and harfbuzz based impl.
pf-simple-text is new and uses my font parser.

pf-text will also override pf-simple-text so if anything enables that, you get the above problem

@s3bk
Copy link
Contributor

@s3bk s3bk commented Jun 11, 2020

If posslble, could we move this to #pathfinder:matrix.org?
I expect a few more problems… and this issue isn't really a good place.

@pcwalton
Copy link
Collaborator Author

@pcwalton pcwalton commented Jul 28, 2020

We have a wasm port now. Let's close this in favor of more specific items.

@pcwalton pcwalton closed this Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants
You can’t perform that action at this time.