mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Desktop: Fix crash caused by submitting work mid surface-reconfigure (#4317)
Implement wgpu-sync
This commit is contained in:
@@ -7,7 +7,7 @@ use web_sys::js_sys::{Object, Reflect};
|
||||
use web_sys::wasm_bindgen::{JsCast, JsValue};
|
||||
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement, window};
|
||||
#[cfg(feature = "wgpu")]
|
||||
use wgpu_executor::WgpuExecutor;
|
||||
use wgpu_executor::{WgpuCurrentSurfaceTexture, WgpuExecutor, WgpuSurface};
|
||||
|
||||
const CANVASES_OBJECT_KEY: &str = "imageCanvases";
|
||||
|
||||
@@ -52,13 +52,13 @@ impl Canvas for CanvasHandle {
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgpu")]
|
||||
pub struct CanvasSurfaceHandle(CanvasHandle, Option<Arc<wgpu::Surface<'static>>>);
|
||||
pub struct CanvasSurfaceHandle(CanvasHandle, Option<Arc<WgpuSurface>>);
|
||||
#[cfg(feature = "wgpu")]
|
||||
impl CanvasSurfaceHandle {
|
||||
pub fn new() -> Self {
|
||||
Self(CanvasHandle::new(), None)
|
||||
}
|
||||
fn surface(&mut self, executor: &WgpuExecutor) -> &wgpu::Surface<'_> {
|
||||
fn surface(&mut self, executor: &WgpuExecutor) -> &WgpuSurface {
|
||||
if self.1.is_none() {
|
||||
let canvas = self.0.get().canvas.clone();
|
||||
let surface = executor
|
||||
@@ -115,9 +115,9 @@ impl CanvasSurface for CanvasSurfaceHandle {
|
||||
},
|
||||
);
|
||||
|
||||
let surface_texture = match surface.get_current_texture() {
|
||||
wgpu::CurrentSurfaceTexture::Success(t) | wgpu::CurrentSurfaceTexture::Suboptimal(t) => t,
|
||||
other => panic!("Failed to get surface texture: {other:?}"),
|
||||
let surface_texture = match surface.get_current_texture(&context.queue) {
|
||||
WgpuCurrentSurfaceTexture::Success(t) | WgpuCurrentSurfaceTexture::Suboptimal(t) => t,
|
||||
_ => panic!("Failed to get surface texture"),
|
||||
};
|
||||
|
||||
encoder.copy_texture_to_texture(
|
||||
@@ -136,7 +136,7 @@ impl CanvasSurface for CanvasSurfaceHandle {
|
||||
source_texture.size(),
|
||||
);
|
||||
|
||||
context.queue.submit([encoder.finish()]);
|
||||
surface_texture.queue.submit([encoder.finish()]);
|
||||
surface_texture.present();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user