Skip to content

Commit

Permalink
Update docs for Backend and implement std::fmt::Display
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Jan 31, 2024
1 parent 0888a63 commit 51350b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Bottom level categories:
- As with other instance flags, this flag can be changed in calls to `InstanceFlags::with_env` with the new `WGPU_GPU_BASED_VALIDATION` environment variable.

By @ErichDonGubler in [#5046](https://github.com/gfx-rs/wgpu/pull/5046).

- `wgpu::Backend` now implements `std::fmt::Display` instead of providing a `to_str` method

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion tests/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub async fn compare_image_output(
let file_stem = reference_path.file_stem().unwrap().to_string_lossy();
let renderer = format!(
"{}-{}-{}",
adapter_info.backend.to_str(),
adapter_info.backend,
sanitize_for_path(&adapter_info.name),
sanitize_for_path(&adapter_info.driver)
);
Expand Down
12 changes: 9 additions & 3 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@ pub const QUERY_SIZE: u32 = 8;
pub enum Backend {
/// Dummy backend, used for testing.
Empty = 0,
/// Vulkan API
/// Vulkan API (Windows, Linux, Android, MacOS via `vulkan-portability`/MoltenVK)
Vulkan = 1,
/// Metal API (Apple platforms)
Metal = 2,
/// Direct3D-12 (Windows)
Dx12 = 3,
/// OpenGL ES-3 (Linux, Android)
/// OpenGL ES-3 (Linux, Android, WebGL, Windows, MacOS via Angle)
Gl = 4,
/// WebGPU in the browser
BrowserWebGpu = 5,
}

impl Backend {
/// Returns the string name of the backend.
pub fn to_str(self) -> &'static str {
pub const fn to_str(self) -> &'static str {
match self {
Backend::Empty => "empty",
Backend::Vulkan => "vulkan",
Expand All @@ -124,6 +124,12 @@ impl Backend {
}
}

impl std::fmt::Display for Backend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_str())
}
}

/// Power Preference when choosing a physical adapter.
///
/// Corresponds to [WebGPU `GPUPowerPreference`](
Expand Down

0 comments on commit 51350b7

Please sign in to comment.