Skip to content

Commit

Permalink
Fix WASM
Browse files Browse the repository at this point in the history
16-byte alignment issue with DitherFade
  • Loading branch information
Waridley committed Jun 18, 2024
1 parent 14f8da6 commit 5443376
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions rs/assets/shaders/dither_fade.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

struct DitherFade {
fade: f32,
#ifdef SIXTEEN_BYTE_ALIGNMENT
_wasm_padding_8b: u32,
_wasm_padding_12b: u32,
_wasm_padding_16b: u32,
#endif
}

@group(2) @binding(200)
Expand Down
29 changes: 27 additions & 2 deletions rs/engine/src/mats/fade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,42 @@ use serde::{Deserialize, Serialize};
pub struct DitherFade {
#[uniform(200)]
pub fade: f32,
#[cfg(target_arch = "wasm32")]
#[uniform(200)]
pub _wasm_padding_8b: u32,
#[cfg(target_arch = "wasm32")]
#[uniform(200)]
pub _wasm_padding_12b: u32,
#[cfg(target_arch = "wasm32")]
#[uniform(200)]
pub _wasm_padding_16b: u32,
}

impl Default for DitherFade {
fn default() -> Self {
Self { fade: 1.0 }
Self {
fade: 1.0,
#[cfg(target_arch = "wasm32")]
_wasm_padding_8b: 0,
#[cfg(target_arch = "wasm32")]
_wasm_padding_12b: 0,
#[cfg(target_arch = "wasm32")]
_wasm_padding_16b: 0,
}
}
}

impl DitherFade {
pub fn new(fade: f32) -> Self {
Self { fade }
Self {
fade,
#[cfg(target_arch = "wasm32")]
_wasm_padding_8b: 0,
#[cfg(target_arch = "wasm32")]
_wasm_padding_12b: 0,
#[cfg(target_arch = "wasm32")]
_wasm_padding_16b: 0,
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion rs/engine/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ impl UiMatBuilder {
..default()
},
},
extension: DitherFade { fade: self.fade },
extension: DitherFade::new(self.fade),
}
}
}
Expand Down

0 comments on commit 5443376

Please sign in to comment.