-
I made https://github.com/lobis/fractal-explorer in order to learn rust / gpu, which is based on this great tutorial. The latest commit at the time of writing is da6d8e1113ce8dc6b1dc6731562639d8d9f3f585. My goal was to have the project compile as a native application (works!) and also as a web app using WASM (this doesn't work). I think the problem is due to uniforms, I am not sure if I am using them correctly since it seems very user unfriendly (but I am not familiar with graphics programming so...). For example in order for my program to work I have to define additional members in the uniform struct to act as padding (maybe there is a cleaner solution?)
(file) This solution seems to work for the desktop application. However the web version doesn't seem to work. (I build it via I get the following error on my browser console:
Honestly I am not sure how to debug this error, maybe it doesn't even have to do with uniforms and my WASM configuration is just wrong (first time I build for this target). I would greatly appreciate any help as I would love to showcase my little project as a web app 🙏🏻 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I haven't been able to think of exactly what the problem might be here, but one thing I would suggest is reordering your struct members so that you need as little manual padding as possible. This not only saves memory but protects against implementation bugs. ( The simplest way to do this (in the absence of
pub struct Uniform {
pub domain: [[f32; 2]; 2],
pub mouse: [f32; 2],
pub c: [f32; 2],
pub time: f32,
pub mandelbrot: i32,
pub _padding: [f32; 2],
} The padding at the end of the Rust struct is necessary because WebGL (but not other targets; this is a “downlevel” restriction) requires the uniform buffer's overall size to be a multiple of 16 bytes. |
Beta Was this translation helpful? Give feedback.
I haven't been able to think of exactly what the problem might be here, but one thing I would suggest is reordering your struct members so that you need as little manual padding as possible. This not only saves memory but protects against implementation bugs. (
wgpu
has to work across many different graphics APIs which have different ideas about alignment requirements, and I've personally encountered one bug. It's stillwgpu
's responsibility to deal with them, but that doesn't mean there aren't unfixed ones.)The simplest way to do this (in the absence of
vec3
s) is to order the members from largest alignment to smallest.