Skip to content

Commit

Permalink
Make Surface::present() errors non-fatal.
Browse files Browse the repository at this point in the history
  • Loading branch information
vorporeal committed Feb 20, 2025
1 parent d11b074 commit 691c538
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use std::{
borrow::Cow::Borrowed, error::Error, fmt, future::ready, ops::Range, pin::Pin, ptr::NonNull,
slice, sync::Arc,
};
use wgc::{command::bundle_ffi::*, error::ContextErrorSource, pipeline::CreateShaderModuleError};
use wgc::{
command::bundle_ffi::*, error::ContextErrorSource, pipeline::CreateShaderModuleError,
present::SurfaceError,
};
use wgt::WasmNotSendSync;

#[derive(Clone)]
Expand Down Expand Up @@ -589,6 +592,7 @@ pub struct CoreTlas {
pub struct CoreSurfaceOutputDetail {
context: ContextWgpuCore,
surface_id: wgc::id::SurfaceId,
error_sink: ErrorSink,
}

type ErrorSink = Arc<Mutex<ErrorSinkRaw>>;
Expand Down Expand Up @@ -3443,9 +3447,16 @@ impl dispatch::SurfaceInterface for CoreSurface {
crate::SurfaceStatus,
dispatch::DispatchSurfaceOutputDetail,
) {
let error_sink = if let Some(error_sink) = self.error_sink.lock().as_ref() {
error_sink.clone()
} else {
Arc::new(Mutex::new(ErrorSinkRaw::new()))
};

let output_detail = CoreSurfaceOutputDetail {
context: self.context.clone(),
surface_id: self.id,
error_sink: error_sink.clone(),
}
.into();

Expand All @@ -3455,7 +3466,7 @@ impl dispatch::SurfaceInterface for CoreSurface {
.map(|id| CoreTexture {
context: self.context.clone(),
id,
error_sink: Arc::new(Mutex::new(ErrorSinkRaw::new())),
error_sink,
})
.map(Into::into);

Expand Down Expand Up @@ -3489,9 +3500,16 @@ impl Drop for CoreSurface {

impl dispatch::SurfaceOutputDetailInterface for CoreSurfaceOutputDetail {
fn present(&self) {
let error = SurfaceError::Device(wgc::device::DeviceError::Lost);
self.context
.handle_error_nolabel(&self.error_sink, error, "Surface::present");

match self.context.0.surface_present(self.surface_id) {
Ok(_status) => (),
Err(err) => self.context.handle_error_fatal(err, "Surface::present"),
Err(err) => {
self.context
.handle_error_nolabel(&self.error_sink, err, "Surface::present");
}
}
}

Expand Down

0 comments on commit 691c538

Please sign in to comment.