bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Fix motion blur on wasm

Open rparrett opened this issue 9 months ago • 3 comments

Objective

Fixes #13097 and other issues preventing the motion blur example from working on wasm

Solution

  • Use a vec2 for padding
  • Fix error initializing the MotionBlur struct on wasm+webgl2
  • Disable MSAA on wasm+webgl2
  • Fix GlobalsUniform padding getting added on the shader side for webgpu builds

Notes

The motion blur example now runs, but with artifacts. In addition to the obvious black artifacts, the motion blur or dithering seem to just look worse in a way I can't really describe. That may be expected.

AdapterInfo { name: "ANGLE (Apple, ANGLE Metal Renderer: Apple M1 Max, Unspecified Version)", vendor: 4203, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Gl }
Screenshot 2024-04-25 at 6 51 21 AM

rparrett avatar Apr 25 '24 13:04 rparrett

It seems that there are other issues when building with webgpu that need to be addressed:

The shader uses more bytes of the buffer (16) than the layout's minBindingSize (12).
 - While validating that the entry-point's declaration for @group(0) @binding(5) matches [BindGroupLayout "motion_blur_layout"]
 - While validating the entry-point's compatibility for group 0 with [BindGroupLayout "motion_blur_layout"]
 - While validating fragment stage ([ShaderModule (unlabeled)], entryPoint: fragment).
 - While validating fragment state.
 - While calling [Device].CreateRenderPipeline([RenderPipelineDescriptor "motion_blur_pipeline"]).

edit: binding 5 is Globals, so this seems unrelated to padding in MotionBlur.

rparrett avatar Apr 29 '24 17:04 rparrett

Tested motion_blur with webgpu, webgl2, and on native (m1 mac). Now working everywhere, but the black artifacts are present in all web builds.

I had to modify the cfg gating for SIXTEEN_BYTE_ALIGNMENT to account for the webgl and webgpu features no longer being mutually exclusive. I'm not totally confident this was the correct thing to do or if that might have other side effects.

rparrett avatar Apr 29 '24 17:04 rparrett

Bummer, this was working at one point, but I forgot to re-test closer to final merge. Thanks!

aevyrie avatar May 02 '24 05:05 aevyrie