Make wasm port work again This cheats somewhat, using the non-robust version of the pipeline for wasm, and blocking on native.
diff --git a/examples/with_winit/src/main.rs b/examples/with_winit/src/main.rs index 706c3de..d3daf97 100644 --- a/examples/with_winit/src/main.rs +++ b/examples/with_winit/src/main.rs
@@ -188,24 +188,35 @@ .surface .get_current_texture() .expect("failed to get surface texture"); - let fut = async { - renderer - .render_to_surface_async( + #[cfg(not(target_arch = "wasm32"))] + { + block_on_wgpu( + &device_handle.device, + renderer.render_to_surface_async( &device_handle.device, &device_handle.queue, &scene, &surface_texture, width, height, - ) - .await - .expect("failed to render to surface"); - surface_texture.present(); - }; - #[cfg(not(target_arch = "wasm32"))] - block_on_wgpu(&device_handle.device, fut); + ), + ) + .expect("failed to render to surface"); + } + // Note: in the wasm case, we're currently not running the robust + // pipeline, as it requires more async wiring for the readback. #[cfg(target_arch = "wasm32")] - wasm_bindgen_futures::spawn_local(fut); + renderer + .render_to_surface( + &device_handle.device, + &device_handle.queue, + &scene, + &surface_texture, + width, + height, + ) + .expect("failed to render to surface"); + surface_texture.present(); device_handle.device.poll(wgpu::Maintain::Poll); } Event::UserEvent(event) => match event {
diff --git a/src/lib.rs b/src/lib.rs index db2968f..7217311 100644 --- a/src/lib.rs +++ b/src/lib.rs
@@ -182,7 +182,7 @@ ) -> Result<()> { let mut render = Render::new(); let encoding = scene.data(); - let recording = render.render_encoding_coarse(encoding, &self.shaders, width, height); + let recording = render.render_encoding_coarse(encoding, &self.shaders, width, height, true); let target = render.out_image(); let bump_buf = render.bump_buf(); self.engine.run_recording(device, queue, &recording, &[])?;
diff --git a/src/render.rs b/src/render.rs index 710c77b..5874dbc 100644 --- a/src/render.rs +++ b/src/render.rs
@@ -196,9 +196,7 @@ height: u32, ) -> (Recording, ResourceProxy) { let mut render = Render::new(); - // TODO: leaks the download of the bump buf; a good way to fix would be to conditionalize - // that download. - let mut recording = render.render_encoding_coarse(encoding, shaders, width, height); + let mut recording = render.render_encoding_coarse(encoding, shaders, width, height, false); let out_image = render.out_image(); render.record_fine(shaders, &mut recording); (recording, out_image.into()) @@ -223,12 +221,16 @@ } /// Prepare a recording for the coarse rasterization phase. + /// + /// The `robust` parameter controls whether we're preparing for readback + /// of the atomic bump buffer, for robust dynamic memory. pub fn render_encoding_coarse( &mut self, encoding: &Encoding, shaders: &FullShaders, width: u32, height: u32, + robust: bool, ) -> Recording { use crate::encoding::{resource::ResourceCache, PackedEncoding}; let mut recording = Recording::default(); @@ -526,7 +528,9 @@ info_bin_data_buf, out_image, }); - recording.download(*bump_buf.as_buf().unwrap()); + if robust { + recording.download(*bump_buf.as_buf().unwrap()); + } recording.free_resource(bump_buf); recording }