File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,18 @@ dxc_shader_compiler = ["hassle-rs"]
63
63
renderdoc = [" libloading" , " renderdoc-sys" ]
64
64
fragile-send-sync-non-atomic-wasm = [" wgt/fragile-send-sync-non-atomic-wasm" ]
65
65
link = [" metal/link" ]
66
+ # Panic when running into an out-of-memory error (for debugging purposes).
67
+ #
68
+ # Only affects the d3d12 and vulkan backends.
69
+ oom_panic = []
70
+ # Panic when running into a device lost error (for debugging purposes).
71
+ # Only affects the d3d12 and vulkan backends.
72
+ device_lost_panic = []
73
+ # Panic when running into an internal error other than out-of-memory and device lost
74
+ # (for debugging purposes).
75
+ #
76
+ # Only affects the d3d12 and vulkan backends.
77
+ internal_error_panic = []
66
78
67
79
[[example ]]
68
80
name = " halmark"
Original file line number Diff line number Diff line change @@ -21,8 +21,26 @@ impl HResult<()> for i32 {
21
21
Err ( Cow :: Borrowed ( description) )
22
22
}
23
23
fn into_device_result ( self , description : & str ) -> Result < ( ) , crate :: DeviceError > {
24
+ #![ allow( unreachable_code) ]
25
+
24
26
self . into_result ( ) . map_err ( |err| {
25
27
log:: error!( "{} failed: {}" , description, err) ;
28
+
29
+ match self {
30
+ winerror:: E_OUTOFMEMORY => {
31
+ #[ cfg( feature = "oom_panic" ) ]
32
+ panic ! ( "{description} failed: Out of memory" ) ;
33
+ }
34
+ winerror:: DXGI_ERROR_DEVICE_RESET | winerror:: DXGI_ERROR_DEVICE_REMOVED => {
35
+ #[ cfg( feature = "device_lost_panic" ) ]
36
+ panic ! ( "{description} failed: Device lost ({err})" ) ;
37
+ }
38
+ _ => {
39
+ #[ cfg( feature = "internal_error_panic" ) ]
40
+ panic ! ( "{description} failed: {err}" ) ;
41
+ }
42
+ }
43
+
26
44
if self == winerror:: E_OUTOFMEMORY {
27
45
crate :: DeviceError :: OutOfMemory
28
46
} else {
Original file line number Diff line number Diff line change @@ -724,13 +724,25 @@ impl crate::Queue<Api> for Queue {
724
724
725
725
impl From < vk:: Result > for crate :: DeviceError {
726
726
fn from ( result : vk:: Result ) -> Self {
727
+ #![ allow( unreachable_code) ]
727
728
match result {
728
729
vk:: Result :: ERROR_OUT_OF_HOST_MEMORY | vk:: Result :: ERROR_OUT_OF_DEVICE_MEMORY => {
730
+ #[ cfg( feature = "oom_panic" ) ]
731
+ panic ! ( "Out of memory ({result:?})" ) ;
732
+
729
733
Self :: OutOfMemory
730
734
}
731
- vk:: Result :: ERROR_DEVICE_LOST => Self :: Lost ,
735
+ vk:: Result :: ERROR_DEVICE_LOST => {
736
+ #[ cfg( feature = "device_lost_panic" ) ]
737
+ panic ! ( "Device lost" ) ;
738
+
739
+ Self :: Lost
740
+ }
732
741
_ => {
733
- log:: warn!( "Unrecognized device error {:?}" , result) ;
742
+ #[ cfg( feature = "internal_error_panic" ) ]
743
+ panic ! ( "Internal error: {result:?}" ) ;
744
+
745
+ log:: warn!( "Unrecognized device error {result:?}" ) ;
734
746
Self :: Lost
735
747
}
736
748
}
You can’t perform that action at this time.
0 commit comments