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

wgpu: WIP precompiled shaders #6501

Closed
wants to merge 1 commit into from
Closed

Conversation

relrelb
Copy link
Contributor

@relrelb relrelb commented Mar 20, 2022

Introduce a build_shaders feature in Ruffle's wgpu backend and
enable it on desktop. When enabled, the WGSL shaders are precompiled
using naga in a build script to the SPIR-V format. Then, those
SPIR-V modules are used directly instead of the WGSL sources.

This approach has 2 major advantages:

  1. It should reduce Ruffle's executable size by a decent amount of KBs
    (I expect 100KB-200KB), because the binary SPIR-V modules are much smaller
    than the WGSL textual source code, plus hopefully the Rust compiler
    will be smart enough to eliminate naga's WGSL parsing code, which
    is pretty high on the cargo bloat list.
  2. It should improve the startup time, as less logic is involved when
    loading precompiled SPIR-V modules.

However, I'm almost sure this feature won't work for WebGPU as it only supports WGSL. But maybe we can still minify the WGSL source code to reduce the WebAssembly binary size.

Introduce a `build_shaders` feature in Ruffle's `wgpu` backend and
enable it on desktop. When enabled, the WGSL shaders are precompiled
using `naga` in a build script to the SPIR-V format. Then, those
SPIR-V modules are used directly instead of the WGSL sources.

This approach has 2 major advantages:
1. It should reduce Ruffle's executable size by a decent amount of KBs
(I expect 100KB-200KB), because the binary SPIR-V modules are much smaller
than the WGSL textual source code, plus hopefully the Rust compiler
will be smart enough to eliminate `naga`'s WGSL parsing code, which
is pretty high on the `cargo bloat` list.
2. It should improve the startup time, as less logic is involved when
loading precompiled SPIR-V modules.
@relrelb relrelb marked this pull request as draft March 20, 2022 22:22
@adrian17
Copy link
Collaborator

It should reduce Ruffle's executable size

Wait... isn't this PR basically an opposite of e10d0fc ? Requiring naga was absolutely huge.

@relrelb
Copy link
Contributor Author

relrelb commented Mar 20, 2022

It should reduce Ruffle's executable size

Wait... isn't this PR basically an opposite of e10d0fc ? Requiring naga was absolutely huge.

This PR adds naga only as a build dependency, but it doesn't matter a lot because naga is already a dependency of wgpu. However, loading SPIR-V modules directly should significantly reduce the amount of needed functions in naga, because the WGSL parsing logic will not be used. I hope the Rust compiler is smart enough to detect those functions as dead and eliminate them.

@adrian17
Copy link
Collaborator

adrian17 commented Mar 20, 2022

This PR adds naga only as a build dependency

no, there's a

[features]
build_shaders = ["naga", "wgpu/spirv"]

the wgpu/spirv feature itself also adds naga as dependency at wgpu's cargo.toml level.

It's okay on desktop (hopefully it passes through the spir-v module as-is?), but on web we definitely don't want to drag extra wgpu features along.

@relrelb
Copy link
Contributor Author

relrelb commented Mar 21, 2022

Closing for now as the WGSL frontend code still appears in the binary. I've opened gfx-rs/wgpu#2549 to see if disabling WGSL using a Cargo feature could be possible.

@relrelb relrelb closed this Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants