Skip to content

Commit ebdd958

Browse files
alokedesaiWumpf
andauthored
Make Surface#configure and Surface#get_current_texture non-fatal (gfx-rs#6253)
* Make Surface#configure non-fatal * Make Surface#get_current_texture non-fatal --------- Co-authored-by: Andreas Reich <[email protected]>
1 parent f8b67a7 commit ebdd958

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ By @cwfitzgerald in [#6619](https://github.com/gfx-rs/wgpu/pull/6619).
5050

5151
### Render and Compute Passes Now Properly Enforce Their Lifetime
5252

53-
A regression intoduced in 23.0.0 caused lifetimes of render and compute passes to be incorrectly enforced. While this is not
53+
A regression introduced in 23.0.0 caused lifetimes of render and compute passes to be incorrectly enforced. While this is not
5454
a soundness issue, the intent is to move an error from runtime to compile time. This issue has been fixed and restored to the 22.0.0 behavior.
5555

5656
### The `diagnostic(…);` directive is now supported in WGSL
@@ -134,6 +134,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148]
134134
- Make `Surface::as_hal` take an immutable reference to the surface. By @jerzywilczek in [#9999](https://github.com/gfx-rs/wgpu/pull/9999)
135135
- Add actual sample type to `CreateBindGroupError::InvalidTextureSampleType` error message. By @ErichDonGubler in [#6530](https://github.com/gfx-rs/wgpu/pull/6530).
136136
- Improve binding error to give a clearer message when there is a mismatch between resource binding as it is in the shader and as it is in the binding layout. By @eliemichel in [#6553](https://github.com/gfx-rs/wgpu/pull/6553).
137+
- `Surface::configure` and `Surface::get_current_texture` are no longer fatal. By @alokedesai in [#6253](https://github.com/gfx-rs/wgpu/pull/6253)
137138

138139
#### D3D12
139140

examples/src/framework.rs

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ impl SurfaceWrapper {
226226
// If the surface is outdated, or was lost, reconfigure it.
227227
wgpu::SurfaceError::Outdated
228228
| wgpu::SurfaceError::Lost
229+
| wgpu::SurfaceError::Other
229230
// If OutOfMemory happens, reconfiguring may not help, but we might as well try
230231
| wgpu::SurfaceError::OutOfMemory,
231232
) => {

wgpu-types/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5642,6 +5642,8 @@ pub enum SurfaceStatus {
56425642
Outdated,
56435643
/// The surface under the swap chain is lost.
56445644
Lost,
5645+
/// The surface status is not known since `get_current_texture` previously failed.
5646+
Unknown,
56455647
}
56465648

56475649
/// Nanosecond timestamp used by the presentation engine.

wgpu/src/api/surface.rs

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl Surface<'_> {
102102
SurfaceStatus::Timeout => return Err(SurfaceError::Timeout),
103103
SurfaceStatus::Outdated => return Err(SurfaceError::Outdated),
104104
SurfaceStatus::Lost => return Err(SurfaceError::Lost),
105+
SurfaceStatus::Unknown => return Err(SurfaceError::Other),
105106
};
106107

107108
let guard = self.config.lock();

wgpu/src/api/surface_texture.rs

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub enum SurfaceError {
5858
Lost,
5959
/// There is no more memory left to allocate a new frame.
6060
OutOfMemory,
61+
/// Acquiring a texture failed with a generic error. Check error callbacks for more information.
62+
Other,
6163
}
6264
static_assertions::assert_impl_all!(SurfaceError: Send, Sync);
6365

@@ -68,6 +70,7 @@ impl fmt::Display for SurfaceError {
6870
Self::Outdated => "The underlying surface has changed, and therefore the swap chain must be updated",
6971
Self::Lost => "The swap chain has been lost and needs to be recreated",
7072
Self::OutOfMemory => "There is no more memory left to allocate a new frame",
73+
Self::Other => "Acquiring a texture failed with a generic error. Check error callbacks for more information",
7174
})
7275
}
7376
}

wgpu/src/backend/wgpu_core.rs

+29-12
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ pub struct CoreSurface {
442442
/// Configured device is needed to know which backend
443443
/// code to execute when acquiring a new frame.
444444
configured_device: Mutex<Option<wgc::id::DeviceId>>,
445+
/// The error sink with which to report errors.
446+
/// `None` if the surface has not been configured.
447+
error_sink: Mutex<Option<ErrorSink>>,
445448
}
446449

447450
#[derive(Debug)]
@@ -827,6 +830,7 @@ impl dispatch::InstanceInterface for ContextWgpuCore {
827830
context: self.clone(),
828831
id,
829832
configured_device: Mutex::default(),
833+
error_sink: Mutex::default(),
830834
}))
831835
}
832836

@@ -3435,9 +3439,11 @@ impl dispatch::SurfaceInterface for CoreSurface {
34353439

34363440
let error = self.context.0.surface_configure(self.id, device.id, config);
34373441
if let Some(e) = error {
3438-
self.context.handle_error_fatal(e, "Surface::configure");
3442+
self.context
3443+
.handle_error_nolabel(&device.error_sink, e, "Surface::configure");
34393444
} else {
34403445
*self.configured_device.lock() = Some(device.id);
3446+
*self.error_sink.lock() = Some(device.error_sink.clone());
34413447
}
34423448
}
34433449

@@ -3448,6 +3454,12 @@ impl dispatch::SurfaceInterface for CoreSurface {
34483454
crate::SurfaceStatus,
34493455
dispatch::DispatchSurfaceOutputDetail,
34503456
) {
3457+
let output_detail = CoreSurfaceOutputDetail {
3458+
context: self.context.clone(),
3459+
surface_id: self.id,
3460+
}
3461+
.into();
3462+
34513463
match self.context.0.surface_get_current_texture(self.id, None) {
34523464
Ok(wgc::present::SurfaceOutput { status, texture_id }) => {
34533465
let data = texture_id
@@ -3458,19 +3470,24 @@ impl dispatch::SurfaceInterface for CoreSurface {
34583470
})
34593471
.map(Into::into);
34603472

3461-
(
3462-
data,
3463-
status,
3464-
CoreSurfaceOutputDetail {
3465-
context: self.context.clone(),
3466-
surface_id: self.id,
3473+
(data, status, output_detail)
3474+
}
3475+
Err(err) => {
3476+
let error_sink = self.error_sink.lock();
3477+
match error_sink.as_ref() {
3478+
Some(error_sink) => {
3479+
self.context.handle_error_nolabel(
3480+
error_sink,
3481+
err,
3482+
"Surface::get_current_texture_view",
3483+
);
3484+
(None, crate::SurfaceStatus::Unknown, output_detail)
34673485
}
3468-
.into(),
3469-
)
3486+
None => self
3487+
.context
3488+
.handle_error_fatal(err, "Surface::get_current_texture_view"),
3489+
}
34703490
}
3471-
Err(err) => self
3472-
.context
3473-
.handle_error_fatal(err, "Surface::get_current_texture_view"),
34743491
}
34753492
}
34763493
}

0 commit comments

Comments
 (0)