mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 12:21:31 +11:00
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:
parent
264fd3ec12
commit
db018da537
|
@ -188,24 +188,35 @@ async fn run(event_loop: EventLoop<UserEvent>, window: Window, args: Args) {
|
|||
.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 {
|
||||
|
|
|
@ -182,7 +182,7 @@ impl Renderer {
|
|||
) -> 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, &[])?;
|
||||
|
|
|
@ -196,9 +196,7 @@ pub fn render_encoding_full(
|
|||
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 @@ impl Render {
|
|||
}
|
||||
|
||||
/// 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 @@ impl Render {
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue