Make wasm port work again

This cheats somewhat, using the non-robust version of the pipeline for
wasm, and blocking on native.
This commit is contained in:
Raph Levien 2023-01-26 17:41:30 -08:00
parent 264fd3ec12
commit db018da537
3 changed files with 31 additions and 16 deletions

View file

@ -188,24 +188,35 @@ async fn run(event_loop: EventLoop<UserEvent>, window: Window, args: Args) {
.surface .surface
.get_current_texture() .get_current_texture()
.expect("failed to get surface texture"); .expect("failed to get surface texture");
let fut = async { #[cfg(not(target_arch = "wasm32"))]
renderer {
.render_to_surface_async( block_on_wgpu(
&device_handle.device,
renderer.render_to_surface_async(
&device_handle.device, &device_handle.device,
&device_handle.queue, &device_handle.queue,
&scene, &scene,
&surface_texture, &surface_texture,
width, width,
height, height,
) ),
.await )
.expect("failed to render to surface"); .expect("failed to render to surface");
surface_texture.present(); }
}; // Note: in the wasm case, we're currently not running the robust
#[cfg(not(target_arch = "wasm32"))] // pipeline, as it requires more async wiring for the readback.
block_on_wgpu(&device_handle.device, fut);
#[cfg(target_arch = "wasm32")] #[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); device_handle.device.poll(wgpu::Maintain::Poll);
} }
Event::UserEvent(event) => match event { Event::UserEvent(event) => match event {

View file

@ -182,7 +182,7 @@ impl Renderer {
) -> Result<()> { ) -> Result<()> {
let mut render = Render::new(); let mut render = Render::new();
let encoding = scene.data(); 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 target = render.out_image();
let bump_buf = render.bump_buf(); let bump_buf = render.bump_buf();
self.engine.run_recording(device, queue, &recording, &[])?; self.engine.run_recording(device, queue, &recording, &[])?;

View file

@ -196,9 +196,7 @@ pub fn render_encoding_full(
height: u32, height: u32,
) -> (Recording, ResourceProxy) { ) -> (Recording, ResourceProxy) {
let mut render = Render::new(); let mut render = Render::new();
// TODO: leaks the download of the bump buf; a good way to fix would be to conditionalize let mut recording = render.render_encoding_coarse(encoding, shaders, width, height, false);
// that download.
let mut recording = render.render_encoding_coarse(encoding, shaders, width, height);
let out_image = render.out_image(); let out_image = render.out_image();
render.record_fine(shaders, &mut recording); render.record_fine(shaders, &mut recording);
(recording, out_image.into()) (recording, out_image.into())
@ -223,12 +221,16 @@ impl Render {
} }
/// Prepare a recording for the coarse rasterization phase. /// 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( pub fn render_encoding_coarse(
&mut self, &mut self,
encoding: &Encoding, encoding: &Encoding,
shaders: &FullShaders, shaders: &FullShaders,
width: u32, width: u32,
height: u32, height: u32,
robust: bool,
) -> Recording { ) -> Recording {
use crate::encoding::{resource::ResourceCache, PackedEncoding}; use crate::encoding::{resource::ResourceCache, PackedEncoding};
let mut recording = Recording::default(); let mut recording = Recording::default();
@ -526,7 +528,9 @@ impl Render {
info_bin_data_buf, info_bin_data_buf,
out_image, out_image,
}); });
recording.download(*bump_buf.as_buf().unwrap()); if robust {
recording.download(*bump_buf.as_buf().unwrap());
}
recording.free_resource(bump_buf); recording.free_resource(bump_buf);
recording recording
} }