Skip to content

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Sep 16, 2025

Originally submitted as:


Had to work around some sRGB complications (and push constants) but it finally works!

  • rustup target add wasm32-unknown-unknown
      (should we add this to rust-toolchain.toml?)
  • cargo run-wasm -p example-runner-wgpu
      (defaults to serving the result of the build on http://localhost:8000)
  • google-chrome-stable --enable-features=Vulkan --enable-unsafe-webgpu http://localhost:8000
image

@eddyb eddyb force-pushed the run-wasm branch 2 times, most recently from 065edda to 1ea004b Compare September 16, 2025 05:04
@eddyb eddyb marked this pull request as ready for review September 16, 2025 05:14
@eddyb eddyb enabled auto-merge September 16, 2025 05:14
@eddyb eddyb changed the title [WIP] run-wasm helper (cargo-run-wasm) for testing the wgpu runner on the web. run-wasm helper (cargo-run-wasm) for testing the wgpu runner on the web. Sep 16, 2025
@eddyb
Copy link
Member Author

eddyb commented Sep 16, 2025

I just wanted to rebase and share this branch, but I spent a few minutes on it and I think I fixed all remaining issues (the screenshot in the description is from the current state of the branch).

Ironically(?), the sky shader doesn't work because of it demoing pipeline-overridable constants (Vulkan specialization constants), but I am happy to default to the mouse shader because of the interactivity.

compiled_shader_modules: CompiledShaderModules,
mut compiled_shader_modules: CompiledShaderModules,
) -> wgpu::RenderPipeline {
if options.emulate_push_constants_with_storage_buffer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it should be somewhere reusable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I whipped up that transformation, because WebGPU launched w/o push constants:

But given that I'm doing this on the SPIR-V module, before Naga sees it, it should maybe be:

  • part of wgpu/Naga, which would let other wgpu users reuse this emulation
    • or at least implemented here on Naga IR, then passing WGSL/naga::Module to wgpu
  • done as part of the build script, and potentially implemented in rustc_codegen_spirv/SPIR-T
    • @Firestar99's ideas around a WGSL-outputting target would also be relevant here
    • for wasm, it'd likely be best to disable runtime Naga, and embed the WGSL directly

Copy link
Collaborator

@LegNeato LegNeato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loved this demo when I saw it.

@eddyb eddyb added this pull request to the merge queue Sep 16, 2025
Merged via the queue into Rust-GPU:main with commit d9bb8aa Sep 16, 2025
13 checks passed
@eddyb eddyb deleted the run-wasm branch September 16, 2025 20:11
@eddyb
Copy link
Member Author

eddyb commented Sep 17, 2025

  • rustup target add wasm32-unknown-unknown
      (should we add this to rust-toolchain.toml?)

Oops, forgot about this.
I'm also thinking that if we build this in CI, and use a crate like we_clap (which wraps clap to let ?foo=bar work for web targets, like --foo=bar does for CLI), we could have this on the website, w/ all the examples.
(might even be more impactful for shadertoys, tho I'm not sure the current approach there is a good idea)

EDIT: oh and wgpu has a WebGL2 fallback we could enable, allowing simpler web demos to "always work".

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