Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DeviceError::Lost to represent device loss. #4238

Merged
merged 2 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ By @teoxoy in [#4185](https://github.com/gfx-rs/wgpu/pull/4185)
- Add `Rgb10a2Uint` format. By @teoxoy in [4199](https://github.com/gfx-rs/wgpu/pull/4199)
- Validate that resources are used on the right device. By @nical in [4207](https://github.com/gfx-rs/wgpu/pull/4207)
- Expose instance flags. By @nical in [4230](https://github.com/gfx-rs/wgpu/pull/4230)
- Add support for the bgra8unorm-storage feature. By @jinleili and @nical in [https://github.com/gfx-rs/wgpu/pull/4228](4228)
- Add support for the bgra8unorm-storage feature. By @jinleili and @nical in [#4228](https://github.com/gfx-rs/wgpu/pull/4228)
- Calls to lost devices now return `DeviceError::Lost` instead of `DeviceError::Invalid`. By @bradwerth in [#4238]([https://github.com/gfx-rs/wgpu/pull/4238])

#### Vulkan

Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let device = &device_guard[device_id];
if !device.is_valid() {
return Err(DeviceError::Invalid).map_pass_err(init_scope);
return Err(DeviceError::Lost).map_pass_err(init_scope);
}
cmd_buf.encoder.open_pass(base.label);

Expand Down
38 changes: 19 additions & 19 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

if desc.usage.is_empty() {
Expand Down Expand Up @@ -380,7 +380,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.get(device_id)
.map_err(|_| DeviceError::Invalid)?;
if !device.valid {
return Err(DeviceError::Invalid.into());
return Err(DeviceError::Lost.into());
}
let buffer = buffer_guard
.get_mut(buffer_id)
Expand Down Expand Up @@ -440,7 +440,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.get(device_id)
.map_err(|_| DeviceError::Invalid)?;
if !device.valid {
return Err(DeviceError::Invalid.into());
return Err(DeviceError::Lost.into());
}
let buffer = buffer_guard
.get_mut(buffer_id)
Expand Down Expand Up @@ -606,7 +606,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}
#[cfg(feature = "trace")]
if let Some(ref trace) = device.trace {
Expand Down Expand Up @@ -664,7 +664,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

// NB: Any change done through the raw texture handle will not be
Expand Down Expand Up @@ -743,7 +743,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

// NB: Any change done through the raw buffer handle will not be
Expand Down Expand Up @@ -1012,7 +1012,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -1096,7 +1096,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -1231,7 +1231,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -1317,7 +1317,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -1428,7 +1428,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -1500,7 +1500,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -1574,7 +1574,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid,
};
if !device.valid {
break DeviceError::Invalid;
break DeviceError::Lost;
}

let dev_stored = Stored {
Expand Down Expand Up @@ -1764,7 +1764,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -1860,7 +1860,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

let adapter = &adapter_guard[device.adapter_id.value];
Expand Down Expand Up @@ -2024,7 +2024,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -2280,7 +2280,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break DeviceError::Invalid.into(),
};
if !device.valid {
break DeviceError::Invalid.into();
break DeviceError::Lost.into();
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -2734,7 +2734,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let device = &device_guard[buffer.device_id.value];
if !device.valid {
return Err((op, DeviceError::Invalid.into()));
return Err((op, DeviceError::Lost.into()));
}

if let Err(e) = check_buffer_usage(buffer.usage, pub_usage) {
Expand Down Expand Up @@ -2980,7 +2980,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.map_err(|_| BufferAccessError::Invalid)?;
let device = &mut device_guard[buffer.device_id.value];
if !device.valid {
return Err(DeviceError::Invalid.into());
return Err(DeviceError::Lost.into());
}

closure = self.buffer_unmap_inner(buffer_id, buffer, device)
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub enum DeviceError {
impl From<hal::DeviceError> for DeviceError {
fn from(error: hal::DeviceError) -> Self {
match error {
hal::DeviceError::Lost => DeviceError::Invalid,
hal::DeviceError::Lost => DeviceError::Lost,
hal::DeviceError::OutOfMemory => DeviceError::OutOfMemory,
hal::DeviceError::ResourceCreationFailed => DeviceError::ResourceCreationFailed,
}
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Some(ref present) => {
let device = &device_guard[present.device_id.value];
if !device.is_valid() {
return Err(DeviceError::Invalid.into());
return Err(DeviceError::Lost.into());
}
(device, present.config.clone())
}
Expand Down Expand Up @@ -294,7 +294,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let device = &mut device_guard[present.device_id.value];
if !device.is_valid() {
return Err(DeviceError::Invalid.into());
return Err(DeviceError::Lost.into());
}

#[cfg(feature = "trace")]
Expand Down Expand Up @@ -383,7 +383,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let device = &mut device_guard[present.device_id.value];
if !device.is_valid() {
return Err(DeviceError::Invalid.into());
return Err(DeviceError::Lost.into());
}

#[cfg(feature = "trace")]
Expand Down