From 7c588be937e2ad229b7ffa42c5a04476dd3f2e6a Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:07:04 +0200 Subject: [PATCH 1/2] add back components info of `TextureFormat`s --- wgpu-types/src/lib.rs | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index c30f7712fe..5025ac7ae1 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -3025,6 +3025,92 @@ impl TextureFormat { } } + /// Returns the number of components this format has. + pub fn components(&self) -> u8 { + self.components_with_aspect(TextureAspect::All) + } + + /// Returns the number of components this format has taking into account the `aspect`. + /// + /// The `aspect` is only relevant for combined depth-stencil formats. + pub fn components_with_aspect(&self, aspect: TextureAspect) -> u8 { + match *self { + Self::R8Unorm + | Self::R8Snorm + | Self::R8Uint + | Self::R8Sint + | Self::R16Unorm + | Self::R16Snorm + | Self::R16Uint + | Self::R16Sint + | Self::R16Float + | Self::R32Uint + | Self::R32Sint + | Self::R32Float => 1, + + Self::Rg8Unorm + | Self::Rg8Snorm + | Self::Rg8Uint + | Self::Rg8Sint + | Self::Rg16Unorm + | Self::Rg16Snorm + | Self::Rg16Uint + | Self::Rg16Sint + | Self::Rg16Float + | Self::Rg32Uint + | Self::Rg32Sint + | Self::Rg32Float => 2, + + Self::Rgba8Unorm + | Self::Rgba8UnormSrgb + | Self::Rgba8Snorm + | Self::Rgba8Uint + | Self::Rgba8Sint + | Self::Bgra8Unorm + | Self::Bgra8UnormSrgb + | Self::Rgba16Unorm + | Self::Rgba16Snorm + | Self::Rgba16Uint + | Self::Rgba16Sint + | Self::Rgba16Float + | Self::Rgba32Uint + | Self::Rgba32Sint + | Self::Rgba32Float => 4, + + Self::Rgb9e5Ufloat | Self::Rg11b10Float => 3, + Self::Rgb10a2Unorm => 4, + + Self::Stencil8 | Self::Depth16Unorm | Self::Depth24Plus | Self::Depth32Float => 1, + + Self::Depth24PlusStencil8 | Self::Depth32FloatStencil8 => match aspect { + TextureAspect::All => 2, + TextureAspect::DepthOnly | TextureAspect::StencilOnly => 1, + }, + + Self::Bc4RUnorm | Self::Bc4RSnorm => 1, + Self::Bc5RgUnorm | Self::Bc5RgSnorm => 2, + Self::Bc6hRgbUfloat | Self::Bc6hRgbFloat => 3, + Self::Bc1RgbaUnorm + | Self::Bc1RgbaUnormSrgb + | Self::Bc2RgbaUnorm + | Self::Bc2RgbaUnormSrgb + | Self::Bc3RgbaUnorm + | Self::Bc3RgbaUnormSrgb + | Self::Bc7RgbaUnorm + | Self::Bc7RgbaUnormSrgb => 4, + + Self::EacR11Unorm | Self::EacR11Snorm => 1, + Self::EacRg11Unorm | Self::EacRg11Snorm => 2, + Self::Etc2Rgb8Unorm | Self::Etc2Rgb8UnormSrgb => 3, + Self::Etc2Rgb8A1Unorm + | Self::Etc2Rgb8A1UnormSrgb + | Self::Etc2Rgba8Unorm + | Self::Etc2Rgba8UnormSrgb => 4, + + Self::Astc { .. } => 4, + } + } + /// Strips the `Srgb` suffix from the given texture format. pub fn remove_srgb_suffix(&self) -> TextureFormat { match *self { From a461c4008dd75102713242150c00e69a77856ff4 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:11:27 +0200 Subject: [PATCH 2/2] add changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9146ab30b..5985745817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,8 +59,8 @@ Bottom level categories: #### General - Document feature requirements for `DEPTH32FLOAT_STENCIL8` by @ErichDonGubler in [#3734](https://github.com/gfx-rs/wgpu/pull/3734). -- Flesh out docs. for `AdapterInfo::{device,vendor}` by @ErichDonGubler in [#3763](https://github.com/gfx-rs/wgpu/pull/3763). -- Spell out which sizes are in bytes. By @jimblandy in [#3773](https://github.com/gfx-rs/wgpu/pull/3773). +- Flesh out docs. for `AdapterInfo::{device,vendor}` by @ErichDonGubler in [#3763](https://github.com/gfx-rs/wgpu/pull/3763). +- Spell out which sizes are in bytes. By @jimblandy in [#3773](https://github.com/gfx-rs/wgpu/pull/3773). ### Bug Fixes @@ -73,6 +73,7 @@ Bottom level categories: #### General - Fix Multiview to disable validation of TextureViewDimension and ArrayLayerCount. By @MalekiRe in [#3779](https://github.com/gfx-rs/wgpu/pull/3779#issue-1713269437). +- Add back components info to `TextureFormat`s. By @teoxoy in [#3843](https://github.com/gfx-rs/wgpu/pull/3843). #### Vulkan - Fix incorrect aspect in barriers when using emulated Stencil8 textures. By @cwfitzgerald in [#3833](https://github.com/gfx-rs/wgpu/pull/3833).