-
Notifications
You must be signed in to change notification settings - Fork 160
vello_hybrid: add native WebGL backend #1011
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
Conversation
feb47e7
to
dbcd9cd
Compare
59e824d
to
eb2c76a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial comments on other parts of code. I ran the demos (native webgl, webgl, and winit). They look great 🥳
71c9a45
to
a3f6cf3
Compare
987f7de
to
ef903a9
Compare
Note, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Amazing work 🚀
This makes the webgl renderer backend compile safe.
27f98bf
to
25ea383
Compare
- Add warning if both webgl features are active. - Add todos - Add new example to CI.
All clear to merge from Raph: #vello > vello_hybrid: WebGL2 renderer backend that skips wgpu #947 @ 💬 |
…1016) # Context Addresses comment #1011 (comment) from @DJMcNab . Replaces `include_str!` with a direct import from `vello_sparse_shaders` to get access to the wgsl source code. ### Changes - Adds a `wgsl` module to the build-time module generated by `vello_sparse_shaders`. This allows `render_strips.wgsl` to be accessed via: `vello_sparse_shaders::wgsl::RENDER_STRIPS` instead of a cross-package `include_str!`. - Adds a `glsl` feature flag to `vello_sparse_shaders` so the default compiled module does not include `glsl` unless the `glsl` feature is used. This makes builds much leaner for wgsl without glsl. ### Test plan Reviewed generated code, and tested both examples manually: - `cargo run_wasm -p wgpu_webgl --release --port 8001` - `cargo run_wasm -p native_webgl --release --port 8000` Finally, CI is very thorough.
Context
This PR follows the conversation had about #947 . I made this PR separately as it also incorporates the clipping changes #957 .
In short, this PR adds a native WebGL backend when targeting
wasm32
and if using the"webgl"
feature onvello_hybrid
.The primary motivation of using a custom webgl renderer is binary size, allowing 3mb to be removed when targeting WebGL2 natively. This is achieved by omitting
wgpu
from the binary when the architecture iswasm32
and the"webgl"
feature flag is set onvello_hybrid
.Changes
vello_hybrid examples
webgl
example has been renamed towgpu_webgl
. Now it's more clear that it leverageswgpu
's WebGL backend.native_webgl
example has been added which uses the new WebGL renderer backend.ci.yml
tests both thewgpu_webgl
example and thenative_webgl
example - smoke testing both webgl techniques.ClipScene
has been added for manually viewing and testing deeply nested clipping. (file)The PR can be manually tested by locally pulling the branch and running the two examples:
cargo run_wasm -p wgpu_webgl --release
: Test original examplecargo run_wasm -p native_webgl --release
: Test new backendNew
vello_sparse_shaders
package addedThis new package contains the WGSL shaders as a source of truth.
vello_hybrid
optionally depends on this library which triggers a build step generating a compiled module. The module contains GLSL shader source code, as well as mappings from the WGSL identifiers to the naga-mangled identifiers in the GLSL.The generated code:
The generated code can then be imported with:
use vello_sparse_shaders::{clear_slots, render_strips};
vello_hybrid
changesA new
render
subdirectory has been added that contains:common.rs
: All the shared render logic.wgpu.rs
: The original renderer leveragingwgpu
.webgl.rs
: The new WebGL native backend renderer.The
Scheduler
has been made backend-agnostic by operating on a newRendererBackend
trait. Both thewgpu
andwebgl
renderer backends implementRendererBackend
.Feature flag changes
Feature flags in
vello_hybrid
are additive. By default thewgpu
feature is enabled. If the compile target iswasm32
and thewebgl
feature is enabled onvello_hybrid
, then the native WebGL renderer will be enabled.Warnings
A runtime warning has been added that will trigger once on either renderer being instantiated, if both:
wgpu
with its WebGL backend is active.WebGlRenderer
is also active.The warning is:
Screen recording
Note
The screen recording below is slightly stale – I've since changed the background to be dark so the white text scene can be read.
Left side is
native_webgl
example (using native WebGL2)Right side is the existing
webgl
example which useswgpu
with thewebgl
feature flag.Test plan
To scope down this PR, there are no automated tests for the renderer except for the single browser test introduced in the example. The shader compilation has some unit tests.
This PR was manually tested via the new native webgl example:
cargo run_wasm -p native_webgl
. This example can be tested against the originalcargo run_wasm -p wgpu_webgl
.Risks
The only risk I'm uncertain about is the addition of the
wgpu
feature flag, that is used as a default feature. Could this be a breaking change for users that specify "no default features". They'd have to add thewgpu
feature explicitly. This seems minor.Followup work
This PR is huge, because it implements all the existing vello_hybrid features in the WebGL backend. Similarly it also includes build-time shader compilation. Instead of making this change completely impenetrable, I'm splitting test infrastructure into a separate change. This PR must be manually tested in the interim.
The example has been added to CI so that it must compile and run.