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

Panic in web builds #16

Closed
rparrett opened this issue Mar 14, 2023 · 0 comments · Fixed by #19
Closed

Panic in web builds #16

rparrett opened this issue Mar 14, 2023 · 0 comments · Fixed by #19

Comments

@rparrett
Copy link
Contributor

rparrett commented Mar 14, 2023

Problem

wasm.js:374 panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_render_pipeline
      note: label = `transparent_mesh2d_pipeline`
    In the provided shader, the type given for group 1 binding 0 has a size of 4. As the device does not support `DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED`, the type must have a size that is a multiple of 16 bytes.

', /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.15.1/src/backend/direct.rs:3024:5

Reproduction

To reproduce, it may be simplest to use wasm-server-runner.

  1. Follow the directions in the link above to install wasm-server-runner
  2. cargo run --target wasm32-unknown-unknown --example tiling
  3. Open your browser to the address given
  4. Open javascript console to observe error

Additional Info

This is a minimal sort of fix that solves the issue. Obviously not ideal as BackgroundMaterial is pub.

For more background, here's a PR that fixed a similar issue in Bevy itself: bevyengine/bevy#6460

diff --git a/src/lib.rs b/src/lib.rs
index 996500e..8cdb948 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -149,6 +149,8 @@ pub trait ScrollingBackground {
 pub struct BackgroundMaterial {
     #[uniform(0)]
     pub movement_scale: f32,
+    #[uniform(0)]
+    pub _wasm_padding: Vec3,
     /// This image must have its [`SamplerDescriptor`] address_mode_* fields set to
     /// [`AddressMode::Repeat`].
     #[texture(1)]
@@ -302,6 +304,7 @@ impl BackgroundImageBundle {
             material: background_materials.add(BackgroundMaterial {
                 texture: image,
                 movement_scale: 1.0,
+                _wasm_padding: Vec3::ZERO,
             }),
             mesh: BG_MESH_HANDLE.typed().into(),
             transform: Default::default(),
diff --git a/src/shaders/background.wgsl b/src/shaders/background.wgsl
index 10942d5..bc0fff6 100644
--- a/src/shaders/background.wgsl
+++ b/src/shaders/background.wgsl
@@ -5,6 +5,7 @@
 #import braymatter::bglib
 struct Uniforms {
     scale: f32,
+    _wasm_padding: vec3<f32>
 };
 
 @group(1) @binding(0)
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 a pull request may close this issue.

1 participant