From 51350b7af188667e1337917405470d067021636b Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 31 Jan 2024 09:52:20 +0100 Subject: [PATCH] Update docs for `Backend` and implement `std::fmt::Display` --- CHANGELOG.md | 2 +- tests/src/image.rs | 2 +- wgpu-types/src/lib.rs | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99bbcbc48b6..43d1250fa54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tests/src/image.rs b/tests/src/image.rs index 4c1f6b8b740..c80edb955d2 100644 --- a/tests/src/image.rs +++ b/tests/src/image.rs @@ -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) ); diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 34a7f130ff4..4ac30205db2 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -98,13 +98,13 @@ 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, @@ -112,7 +112,7 @@ pub enum Backend { 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", @@ -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`](