From e83297ad27ccf2a496e4f041e9ae90c713f4b5e9 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Fri, 22 Jul 2022 08:34:01 +0200 Subject: [PATCH 01/12] use custom serde impl for TextureFormat --- wgpu-types/src/lib.rs | 539 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 464 insertions(+), 75 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index dcdc02b2fb..f96075cd3e 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1752,175 +1752,127 @@ pub enum AstcChannel { /// https://gpuweb.github.io/gpuweb/#enumdef-gputextureformat). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] pub enum TextureFormat { // Normal 8 bit formats /// Red channel only. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "r8unorm"))] R8Unorm, /// Red channel only. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "r8snorm"))] R8Snorm, /// Red channel only. 8 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "r8uint"))] R8Uint, /// Red channel only. 8 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "r8sint"))] R8Sint, // Normal 16 bit formats /// Red channel only. 16 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "r16uint"))] R16Uint, /// Red channel only. 16 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "r16sint"))] R16Sint, /// Red channel only. 16 bit integer per channel. [0, 65535] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "r16unorm"))] R16Unorm, /// Red channel only. 16 bit integer per channel. [0, 65535] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "r16snorm"))] R16Snorm, /// Red channel only. 16 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "r16float"))] R16Float, /// Red and green channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg8unorm"))] Rg8Unorm, /// Red and green channels. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg8snorm"))] Rg8Snorm, /// Red and green channels. 8 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg8uint"))] Rg8Uint, /// Red and green channels. 8 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg8sint"))] Rg8Sint, // Normal 32 bit formats /// Red channel only. 32 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "r32uint"))] R32Uint, /// Red channel only. 32 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "r32sint"))] R32Sint, /// Red channel only. 32 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "r32float"))] R32Float, /// Red and green channels. 16 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg16uint"))] Rg16Uint, /// Red and green channels. 16 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg16sint"))] Rg16Sint, /// Red and green channels. 16 bit integer per channel. [0, 65535] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "rg16unorm"))] Rg16Unorm, /// Red and green channels. 16 bit integer per channel. [0, 65535] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "rg16snorm"))] Rg16Snorm, /// Red and green channels. 16 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg16float"))] Rg16Float, /// Red, green, blue, and alpha channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8unorm"))] Rgba8Unorm, /// Red, green, blue, and alpha channels. 8 bit integer per channel. Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8unorm-srgb"))] Rgba8UnormSrgb, /// Red, green, blue, and alpha channels. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8snorm"))] Rgba8Snorm, /// Red, green, blue, and alpha channels. 8 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8uint"))] Rgba8Uint, /// Red, green, blue, and alpha channels. 8 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8sint"))] Rgba8Sint, /// Blue, green, red, and alpha channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "bgra8unorm"))] Bgra8Unorm, /// Blue, green, red, and alpha channels. 8 bit integer per channel. Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "bgra8unorm-srgb"))] Bgra8UnormSrgb, // Packed 32 bit formats /// Red, green, blue, and alpha channels. 10 bit integer for RGB channels, 2 bit integer for alpha channel. [0, 1023] ([0, 3] for alpha) converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgb10a2unorm"))] Rgb10a2Unorm, /// Red, green, and blue channels. 11 bit float with no sign bit for RG channels. 10 bit float with no sign bit for blue channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg11b10ufloat"))] Rg11b10Float, // Normal 64 bit formats /// Red and green channels. 32 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg32uint"))] Rg32Uint, /// Red and green channels. 32 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg32sint"))] Rg32Sint, /// Red and green channels. 32 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg32float"))] Rg32Float, /// Red, green, blue, and alpha channels. 16 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba16uint"))] Rgba16Uint, /// Red, green, blue, and alpha channels. 16 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba16sint"))] Rgba16Sint, /// Red, green, blue, and alpha channels. 16 bit integer per channel. [0, 65535] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "rgba16unorm"))] Rgba16Unorm, /// Red, green, blue, and alpha. 16 bit integer per channel. [0, 65535] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "rgba16snorm"))] Rgba16Snorm, /// Red, green, blue, and alpha channels. 16 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba16float"))] Rgba16Float, // Normal 128 bit formats /// Red, green, blue, and alpha channels. 32 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba32uint"))] Rgba32Uint, /// Red, green, blue, and alpha channels. 32 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba32sint"))] Rgba32Sint, /// Red, green, blue, and alpha channels. 32 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba32float"))] Rgba32Float, // Depth and stencil formats /// Special depth format with 32 bit floating point depth. - #[cfg_attr(feature = "serde", serde(rename = "depth32float"))] Depth32Float, /// Special depth/stencil format with 32 bit floating point depth and 8 bits integer stencil. - #[cfg_attr(feature = "serde", serde(rename = "depth32float-stencil8"))] Depth32FloatStencil8, /// Special depth format with at least 24 bit integer depth. - #[cfg_attr(feature = "serde", serde(rename = "depth24plus"))] Depth24Plus, /// Special depth/stencil format with at least 24 bit integer depth and 8 bits integer stencil. - #[cfg_attr(feature = "serde", serde(rename = "depth24plus-stencil8"))] Depth24PlusStencil8, /// Special depth/stencil format with 24 bit integer depth and 8 bits integer stencil. - #[cfg_attr(feature = "serde", serde(rename = "depth24unorm-stencil8"))] Depth24UnormStencil8, // Packed uncompressed texture formats /// Packed unsigned float with 9 bits mantisa for each RGB component, then a common 5 bits exponent - #[cfg_attr(feature = "serde", serde(rename = "rgb9e5ufloat"))] Rgb9e5Ufloat, // Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature. @@ -1930,7 +1882,6 @@ pub enum TextureFormat { /// Also known as DXT1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc1-rgba-unorm"))] Bc1RgbaUnorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 4 color + alpha pallet. 5 bit R + 6 bit G + 5 bit B + 1 bit alpha. /// Srgb-color [0, 63] ([0, 1] for alpha) converted to/from linear-color float [0, 1] in shader. @@ -1938,7 +1889,6 @@ pub enum TextureFormat { /// Also known as DXT1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc1-rgba-unorm-srgb"))] Bc1RgbaUnormSrgb, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet. 5 bit R + 6 bit G + 5 bit B + 4 bit alpha. /// [0, 63] ([0, 15] for alpha) converted to/from float [0, 1] in shader. @@ -1946,7 +1896,6 @@ pub enum TextureFormat { /// Also known as DXT3. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc2-rgba-unorm"))] Bc2RgbaUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet. 5 bit R + 6 bit G + 5 bit B + 4 bit alpha. /// Srgb-color [0, 63] ([0, 255] for alpha) converted to/from linear-color float [0, 1] in shader. @@ -1954,7 +1903,6 @@ pub enum TextureFormat { /// Also known as DXT3. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc2-rgba-unorm-srgb"))] Bc2RgbaUnormSrgb, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet + 8 alpha pallet. 5 bit R + 6 bit G + 5 bit B + 8 bit alpha. /// [0, 63] ([0, 255] for alpha) converted to/from float [0, 1] in shader. @@ -1962,7 +1910,6 @@ pub enum TextureFormat { /// Also known as DXT5. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc3-rgba-unorm"))] Bc3RgbaUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet + 8 alpha pallet. 5 bit R + 6 bit G + 5 bit B + 8 bit alpha. /// Srgb-color [0, 63] ([0, 255] for alpha) converted to/from linear-color float [0, 1] in shader. @@ -1970,7 +1917,6 @@ pub enum TextureFormat { /// Also known as DXT5. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc3-rgba-unorm-srgb"))] Bc3RgbaUnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 8 color pallet. 8 bit R. /// [0, 255] converted to/from float [0, 1] in shader. @@ -1978,7 +1924,6 @@ pub enum TextureFormat { /// Also known as RGTC1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc4-r-unorm"))] Bc4RUnorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 8 color pallet. 8 bit R. /// [-127, 127] converted to/from float [-1, 1] in shader. @@ -1986,7 +1931,6 @@ pub enum TextureFormat { /// Also known as RGTC1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc4-r-snorm"))] Bc4RSnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 8 color red pallet + 8 color green pallet. 8 bit RG. /// [0, 255] converted to/from float [0, 1] in shader. @@ -1994,7 +1938,6 @@ pub enum TextureFormat { /// Also known as RGTC2. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc5-rg-unorm"))] Bc5RgUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 8 color red pallet + 8 color green pallet. 8 bit RG. /// [-127, 127] converted to/from float [-1, 1] in shader. @@ -2002,21 +1945,18 @@ pub enum TextureFormat { /// Also known as RGTC2. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc5-rg-snorm"))] Bc5RgSnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 16 bit unsigned float RGB. Float in shader. /// /// Also known as BPTC (float). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc6h-rgb-ufloat"))] Bc6hRgbUfloat, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 16 bit signed float RGB. Float in shader. /// /// Also known as BPTC (float). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc6h-rgb-float"))] Bc6hRgbSfloat, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 8 bit integer RGBA. /// [0, 255] converted to/from float [0, 1] in shader. @@ -2024,7 +1964,6 @@ pub enum TextureFormat { /// Also known as BPTC (unorm). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc7-rgba-unorm"))] Bc7RgbaUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 8 bit integer RGBA. /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. @@ -2032,67 +1971,56 @@ pub enum TextureFormat { /// Also known as BPTC (unorm). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc7-rgba-unorm-srgb"))] Bc7RgbaUnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB. /// [0, 255] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgb8unorm"))] Etc2Rgb8Unorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB. /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgb8unorm-srgb"))] Etc2Rgb8UnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB + 1 bit alpha. /// [0, 255] ([0, 1] for alpha) converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgb8a1unorm"))] Etc2Rgb8A1Unorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB + 1 bit alpha. /// Srgb-color [0, 255] ([0, 1] for alpha) converted to/from linear-color float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgb8a1unorm-srgb"))] Etc2Rgb8A1UnormSrgb, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer RGB + 8 bit alpha. /// [0, 255] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgba8unorm"))] Etc2Rgba8Unorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer RGB + 8 bit alpha. /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgba8unorm-srgb"))] Etc2Rgba8UnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 11 bit integer R. /// [0, 255] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "eac-r11unorm"))] EacR11Unorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 11 bit integer R. /// [-127, 127] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "eac-r11snorm"))] EacR11Snorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 11 bit integer R + 11 bit integer G. /// [0, 255] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "eac-rg11unorm"))] EacRg11Unorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 11 bit integer R + 11 bit integer G. /// [-127, 127] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "eac-rg11snorm"))] EacRg11Snorm, /// block compressed texture. 16 bytes per block. /// @@ -2109,6 +2037,467 @@ pub enum TextureFormat { }, } +#[cfg(feature = "serde")] +impl<'de> Deserialize<'de> for TextureFormat { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + use serde::de::{self, Error, Unexpected}; + + struct TextureFormatVisitor; + + impl<'de> de::Visitor<'de> for TextureFormatVisitor { + type Value = TextureFormat; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("Invalid TextureFormat") + } + + fn visit_str(self, s: &str) -> Result { + let format = match s { + "r8unorm" => TextureFormat::R8Unorm, + "r8snorm" => TextureFormat::R8Snorm, + "r8uint" => TextureFormat::R8Uint, + "r8sint" => TextureFormat::R8Sint, + "r16uint" => TextureFormat::R16Uint, + "r16sint" => TextureFormat::R16Sint, + "r16unorm" => TextureFormat::R16Unorm, + "r16snorm" => TextureFormat::R16Snorm, + "r16float" => TextureFormat::R16Float, + "rg8unorm" => TextureFormat::Rg8Unorm, + "rg8snorm" => TextureFormat::Rg8Snorm, + "rg8uint" => TextureFormat::Rg8Uint, + "rg8sint" => TextureFormat::Rg8Sint, + "r32uint" => TextureFormat::R32Uint, + "r32sint" => TextureFormat::R32Sint, + "r32float" => TextureFormat::R32Float, + "rg16uint" => TextureFormat::Rg16Uint, + "rg16sint" => TextureFormat::Rg16Sint, + "rg16unorm" => TextureFormat::Rg16Unorm, + "rg16snorm" => TextureFormat::Rg16Snorm, + "rg16float" => TextureFormat::Rg16Float, + "rgba8unorm" => TextureFormat::Rgba8Unorm, + "rgba8unorm-srgb" => TextureFormat::Rgba8UnormSrgb, + "rgba8snorm" => TextureFormat::Rgba8Snorm, + "rgba8uint" => TextureFormat::Rgba8Uint, + "rgba8sint" => TextureFormat::Rgba8Sint, + "bgra8unorm" => TextureFormat::Bgra8Unorm, + "bgra8unorm-srgb" => TextureFormat::Bgra8UnormSrgb, + "rgb10a2unorm" => TextureFormat::Rgb10a2Unorm, + "rg11b10ufloat" => TextureFormat::Rg11b10Float, + "rg32uint" => TextureFormat::Rg32Uint, + "rg32sint" => TextureFormat::Rg32Sint, + "rg32float" => TextureFormat::Rg32Float, + "rgba16uint" => TextureFormat::Rgba16Uint, + "rgba16sint" => TextureFormat::Rgba16Sint, + "rgba16unorm" => TextureFormat::Rgba16Unorm, + "rgba16snorm" => TextureFormat::Rgba16Snorm, + "rgba16float" => TextureFormat::Rgba16Float, + "rgba32uint" => TextureFormat::Rgba32Uint, + "rgba32sint" => TextureFormat::Rgba32Sint, + "rgba32float" => TextureFormat::Rgba32Float, + "depth32float" => TextureFormat::Depth32Float, + "depth32float-stencil8" => TextureFormat::Depth32FloatStencil8, + "depth24plus" => TextureFormat::Depth24Plus, + "depth24plus-stencil8" => TextureFormat::Depth24PlusStencil8, + "depth24unorm-stencil8" => TextureFormat::Depth24UnormStencil8, + "rgb9e5ufloat" => TextureFormat::Rgb9e5Ufloat, + "bc1-rgba-unorm" => TextureFormat::Bc1RgbaUnorm, + "bc1-rgba-unorm-srgb" => TextureFormat::Bc1RgbaUnormSrgb, + "bc2-rgba-unorm" => TextureFormat::Bc2RgbaUnorm, + "bc2-rgba-unorm-srgb" => TextureFormat::Bc2RgbaUnormSrgb, + "bc3-rgba-unorm" => TextureFormat::Bc3RgbaUnorm, + "bc3-rgba-unorm-srgb" => TextureFormat::Bc3RgbaUnormSrgb, + "bc4-r-unorm" => TextureFormat::Bc4RUnorm, + "bc4-r-snorm" => TextureFormat::Bc4RSnorm, + "bc5-rg-unorm" => TextureFormat::Bc5RgUnorm, + "bc5-rg-snorm" => TextureFormat::Bc5RgSnorm, + "bc6h-rgb-ufloat" => TextureFormat::Bc6hRgbUfloat, + "bc6h-rgb-float" => TextureFormat::Bc6hRgbSfloat, + "bc7-rgba-unorm" => TextureFormat::Bc7RgbaUnorm, + "bc7-rgba-unorm-srgb" => TextureFormat::Bc7RgbaUnormSrgb, + "etc2-rgb8unorm" => TextureFormat::Etc2Rgb8Unorm, + "etc2-rgb8unorm-srgb" => TextureFormat::Etc2Rgb8UnormSrgb, + "etc2-rgb8a1unorm" => TextureFormat::Etc2Rgb8A1Unorm, + "etc2-rgb8a1unorm-srgb" => TextureFormat::Etc2Rgb8A1UnormSrgb, + "etc2-rgba8unorm" => TextureFormat::Etc2Rgba8Unorm, + "etc2-rgba8unorm-srgb" => TextureFormat::Etc2Rgba8UnormSrgb, + "eac-r11unorm" => TextureFormat::EacR11Unorm, + "eac-r11snorm" => TextureFormat::EacR11Snorm, + "eac-rg11unorm" => TextureFormat::EacRg11Unorm, + "eac-rg11snorm" => TextureFormat::EacRg11Snorm, + other => { + if other.starts_with("astc") { + let mut parts = other.split('-'); + parts.next(); // discard "astc" + let block = parts + .next() + .ok_or(E::invalid_value(Unexpected::Str(s), &self))?; + let channel = parts.collect::>().join("-"); + + let block = match block { + "4x4" => AstcBlock::B4x4, + "5x4" => AstcBlock::B5x4, + "5x5" => AstcBlock::B5x5, + "6x5" => AstcBlock::B6x5, + "6x6" => AstcBlock::B6x6, + "8x5" => AstcBlock::B8x5, + "8x6" => AstcBlock::B8x6, + "8x8" => AstcBlock::B8x8, + "10x5" => AstcBlock::B10x5, + "10x6" => AstcBlock::B10x6, + "10x8" => AstcBlock::B10x8, + "10x10" => AstcBlock::B10x10, + "12x10" => AstcBlock::B12x10, + "12x12" => AstcBlock::B12x12, + _ => return Err(E::invalid_value(Unexpected::Str(s), &self)), + }; + + let channel = match channel.as_ref() { + "unorm" => AstcChannel::Unorm, + "unorm-srgb" => AstcChannel::UnormSrgb, + "hdr" => AstcChannel::Hdr, + _ => return Err(E::invalid_value(Unexpected::Str(s), &self)), + }; + + TextureFormat::Astc { block, channel } + } else { + return Err(E::invalid_value(Unexpected::Str(s), &self)); + } + } + }; + + Ok(format) + } + } + + deserializer.deserialize_any(TextureFormatVisitor) + } +} + +#[cfg(feature = "serde")] +impl Serialize for TextureFormat { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + match *self { + TextureFormat::R8Unorm => { + let name = "r8unorm"; + serializer.serialize_unit_variant(name, 0, name) + } + TextureFormat::R8Snorm => { + let name = "r8snorm"; + serializer.serialize_unit_variant(name, 1, name) + } + TextureFormat::R8Uint => { + let name = "r8uint"; + serializer.serialize_unit_variant(name, 2, name) + } + TextureFormat::R8Sint => { + let name = "r8sint"; + serializer.serialize_unit_variant(name, 3, name) + } + TextureFormat::R16Uint => { + let name = "r16uint"; + serializer.serialize_unit_variant(name, 4, name) + } + TextureFormat::R16Sint => { + let name = "r16sint"; + serializer.serialize_unit_variant(name, 5, name) + } + TextureFormat::R16Unorm => { + let name = "r16unorm"; + serializer.serialize_unit_variant(name, 6, name) + } + TextureFormat::R16Snorm => { + let name = "r16snorm"; + serializer.serialize_unit_variant(name, 7, name) + } + TextureFormat::R16Float => { + let name = "r16float"; + serializer.serialize_unit_variant(name, 8, name) + } + TextureFormat::Rg8Unorm => { + let name = "rg8unorm"; + serializer.serialize_unit_variant(name, 9, name) + } + TextureFormat::Rg8Snorm => { + let name = "rg8snorm"; + serializer.serialize_unit_variant(name, 10, name) + } + TextureFormat::Rg8Uint => { + let name = "rg8uint"; + serializer.serialize_unit_variant(name, 11, name) + } + TextureFormat::Rg8Sint => { + let name = "rg8sint"; + serializer.serialize_unit_variant(name, 12, name) + } + TextureFormat::R32Uint => { + let name = "r32uint"; + serializer.serialize_unit_variant(name, 13, name) + } + TextureFormat::R32Sint => { + let name = "r32sint"; + serializer.serialize_unit_variant(name, 14, name) + } + TextureFormat::R32Float => { + let name = "r32float"; + serializer.serialize_unit_variant(name, 15, name) + } + TextureFormat::Rg16Uint => { + let name = "rg16uint"; + serializer.serialize_unit_variant(name, 16, name) + } + TextureFormat::Rg16Sint => { + let name = "rg16sint"; + serializer.serialize_unit_variant(name, 17, name) + } + TextureFormat::Rg16Unorm => { + let name = "rg16unorm"; + serializer.serialize_unit_variant(name, 18, name) + } + TextureFormat::Rg16Snorm => { + let name = "rg16snorm"; + serializer.serialize_unit_variant(name, 19, name) + } + TextureFormat::Rg16Float => { + let name = "rg16float"; + serializer.serialize_unit_variant(name, 20, name) + } + TextureFormat::Rgba8Unorm => { + let name = "rgba8unorm"; + serializer.serialize_unit_variant(name, 21, name) + } + TextureFormat::Rgba8UnormSrgb => { + let name = "rgba8unorm-srgb"; + serializer.serialize_unit_variant(name, 22, name) + } + TextureFormat::Rgba8Snorm => { + let name = "rgba8snorm"; + serializer.serialize_unit_variant(name, 23, name) + } + TextureFormat::Rgba8Uint => { + let name = "rgba8uint"; + serializer.serialize_unit_variant(name, 24, name) + } + TextureFormat::Rgba8Sint => { + let name = "rgba8sint"; + serializer.serialize_unit_variant(name, 25, name) + } + TextureFormat::Bgra8Unorm => { + let name = "bgra8unorm"; + serializer.serialize_unit_variant(name, 26, name) + } + TextureFormat::Bgra8UnormSrgb => { + let name = "bgra8unorm-srgb"; + serializer.serialize_unit_variant(name, 27, name) + } + TextureFormat::Rgb10a2Unorm => { + let name = "rgb10a2unorm"; + serializer.serialize_unit_variant(name, 28, name) + } + TextureFormat::Rg11b10Float => { + let name = "rg11b10ufloat"; + serializer.serialize_unit_variant(name, 29, name) + } + TextureFormat::Rg32Uint => { + let name = "rg32uint"; + serializer.serialize_unit_variant(name, 30, name) + } + TextureFormat::Rg32Sint => { + let name = "rg32sint"; + serializer.serialize_unit_variant(name, 31, name) + } + TextureFormat::Rg32Float => { + let name = "rg32float"; + serializer.serialize_unit_variant(name, 32, name) + } + TextureFormat::Rgba16Uint => { + let name = "rgba16uint"; + serializer.serialize_unit_variant(name, 33, name) + } + TextureFormat::Rgba16Sint => { + let name = "rgba16sint"; + serializer.serialize_unit_variant(name, 34, name) + } + TextureFormat::Rgba16Unorm => { + let name = "rgba16unorm"; + serializer.serialize_unit_variant(name, 35, name) + } + TextureFormat::Rgba16Snorm => { + let name = "rgba16snorm"; + serializer.serialize_unit_variant(name, 36, name) + } + TextureFormat::Rgba16Float => { + let name = "rgba16float"; + serializer.serialize_unit_variant(name, 37, name) + } + TextureFormat::Rgba32Uint => { + let name = "rgba32uint"; + serializer.serialize_unit_variant(name, 38, name) + } + TextureFormat::Rgba32Sint => { + let name = "rgba32sint"; + serializer.serialize_unit_variant(name, 39, name) + } + TextureFormat::Rgba32Float => { + let name = "rgba32float"; + serializer.serialize_unit_variant(name, 40, name) + } + TextureFormat::Depth32Float => { + let name = "depth32float"; + serializer.serialize_unit_variant(name, 41, name) + } + TextureFormat::Depth32FloatStencil8 => { + let name = "depth32float-stencil8"; + serializer.serialize_unit_variant(name, 42, name) + } + TextureFormat::Depth24Plus => { + let name = "depth24plus"; + serializer.serialize_unit_variant(name, 43, name) + } + TextureFormat::Depth24PlusStencil8 => { + let name = "depth24plus-stencil8"; + serializer.serialize_unit_variant(name, 44, name) + } + TextureFormat::Depth24UnormStencil8 => { + let name = "depth24unorm-stencil8"; + serializer.serialize_unit_variant(name, 45, name) + } + TextureFormat::Rgb9e5Ufloat => { + let name = "rgb9e5ufloat"; + serializer.serialize_unit_variant(name, 46, name) + } + TextureFormat::Bc1RgbaUnorm => { + let name = "bc1-rgba-unorm"; + serializer.serialize_unit_variant(name, 47, name) + } + TextureFormat::Bc1RgbaUnormSrgb => { + let name = "bc1-rgba-unorm-srgb"; + serializer.serialize_unit_variant(name, 48, name) + } + TextureFormat::Bc2RgbaUnorm => { + let name = "bc2-rgba-unorm"; + serializer.serialize_unit_variant(name, 49, name) + } + TextureFormat::Bc2RgbaUnormSrgb => { + let name = "bc2-rgba-unorm-srgb"; + serializer.serialize_unit_variant(name, 50, name) + } + TextureFormat::Bc3RgbaUnorm => { + let name = "bc3-rgba-unorm"; + serializer.serialize_unit_variant(name, 51, name) + } + TextureFormat::Bc3RgbaUnormSrgb => { + let name = "bc3-rgba-unorm-srgb"; + serializer.serialize_unit_variant(name, 52, name) + } + TextureFormat::Bc4RUnorm => { + let name = "bc4-r-unorm"; + serializer.serialize_unit_variant(name, 53, name) + } + TextureFormat::Bc4RSnorm => { + let name = "bc4-r-snorm"; + serializer.serialize_unit_variant(name, 54, name) + } + TextureFormat::Bc5RgUnorm => { + let name = "bc5-rg-unorm"; + serializer.serialize_unit_variant(name, 55, name) + } + TextureFormat::Bc5RgSnorm => { + let name = "bc5-rg-snorm"; + serializer.serialize_unit_variant(name, 56, name) + } + TextureFormat::Bc6hRgbUfloat => { + let name = "bc6h-rgb-ufloat"; + serializer.serialize_unit_variant(name, 57, name) + } + TextureFormat::Bc6hRgbSfloat => { + let name = "bc6h-rgb-float"; + serializer.serialize_unit_variant(name, 58, name) + } + TextureFormat::Bc7RgbaUnorm => { + let name = "bc7-rgba-unorm"; + serializer.serialize_unit_variant(name, 59, name) + } + TextureFormat::Bc7RgbaUnormSrgb => { + let name = "bc7-rgba-unorm-srgb"; + serializer.serialize_unit_variant(name, 60, name) + } + TextureFormat::Etc2Rgb8Unorm => { + let name = "etc2-rgb8unorm"; + serializer.serialize_unit_variant(name, 61, name) + } + TextureFormat::Etc2Rgb8UnormSrgb => { + let name = "etc2-rgb8unorm-srgb"; + serializer.serialize_unit_variant(name, 62, name) + } + TextureFormat::Etc2Rgb8A1Unorm => { + let name = "etc2-rgb8a1unorm"; + serializer.serialize_unit_variant(name, 63, name) + } + TextureFormat::Etc2Rgb8A1UnormSrgb => { + let name = "etc2-rgb8a1unorm-srgb"; + serializer.serialize_unit_variant(name, 64, name) + } + TextureFormat::Etc2Rgba8Unorm => { + let name = "etc2-rgba8unorm"; + serializer.serialize_unit_variant(name, 65, name) + } + TextureFormat::Etc2Rgba8UnormSrgb => { + let name = "etc2-rgba8unorm-srgb"; + serializer.serialize_unit_variant(name, 66, name) + } + TextureFormat::EacR11Unorm => { + let name = "eac-r11unorm"; + serializer.serialize_unit_variant(name, 67, name) + } + TextureFormat::EacR11Snorm => { + let name = "eac-r11snorm"; + serializer.serialize_unit_variant(name, 68, name) + } + TextureFormat::EacRg11Unorm => { + let name = "eac-rg11unorm"; + serializer.serialize_unit_variant(name, 69, name) + } + TextureFormat::EacRg11Snorm => { + let name = "eac-rg11snorm"; + serializer.serialize_unit_variant(name, 70, name) + } + TextureFormat::Astc { block, channel } => { + let block = match block { + AstcBlock::B4x4 => "4x4", + AstcBlock::B5x4 => "5x4", + AstcBlock::B5x5 => "5x5", + AstcBlock::B6x5 => "6x5", + AstcBlock::B6x6 => "6x6", + AstcBlock::B8x5 => "8x5", + AstcBlock::B8x6 => "8x6", + AstcBlock::B8x8 => "8x8", + AstcBlock::B10x5 => "10x5", + AstcBlock::B10x6 => "10x6", + AstcBlock::B10x8 => "10x8", + AstcBlock::B10x10 => "10x10", + AstcBlock::B12x10 => "12x10", + AstcBlock::B12x12 => "12x12", + }; + + let channel = match channel { + AstcChannel::Unorm => "unorm", + AstcChannel::UnormSrgb => "unorm-srgb", + AstcChannel::Hdr => "hdr", + }; + + let name = format!("astc-{block}-{channel}"); + serializer.serialize_str(&name) + } + } + } +} + impl TextureFormat { /// Get useful information about the texture format. pub fn describe(&self) -> TextureFormatInfo { @@ -2195,7 +2584,7 @@ impl TextureFormat { Self::Rgb10a2Unorm => ( native, float, linear, msaa_resolve, (1, 1), 4, attachment, 4), Self::Rg11b10Float => ( native, float, linear, msaa, (1, 1), 4, basic, 3), - // Packed 32 bit textures + // Packed 32 bit textures Self::Rg32Uint => ( native, uint, linear, noaa, (1, 1), 8, all_flags, 2), Self::Rg32Sint => ( native, sint, linear, noaa, (1, 1), 8, all_flags, 2), Self::Rg32Float => ( native, nearest, linear, noaa, (1, 1), 8, all_flags, 2), @@ -2203,7 +2592,7 @@ impl TextureFormat { Self::Rgba16Sint => ( native, sint, linear, msaa, (1, 1), 8, all_flags, 4), Self::Rgba16Float => ( native, float, linear, msaa_resolve, (1, 1), 8, all_flags, 4), - // Packed 32 bit textures + // Packed 32 bit textures Self::Rgba32Uint => ( native, uint, linear, noaa, (1, 1), 16, all_flags, 4), Self::Rgba32Sint => ( native, sint, linear, noaa, (1, 1), 16, all_flags, 4), Self::Rgba32Float => ( native, nearest, linear, noaa, (1, 1), 16, all_flags, 4), @@ -2215,7 +2604,7 @@ impl TextureFormat { Self::Depth24PlusStencil8 => ( native, depth, linear, msaa, (1, 1), 4, attachment, 2), Self::Depth24UnormStencil8 => ( d24_s8, depth, linear, msaa, (1, 1), 4, attachment, 2), - // Packed uncompressed + // Packed uncompressed Self::Rgb9e5Ufloat => ( native, float, linear, noaa, (1, 1), 4, basic, 3), // Optional normalized 16-bit-per-channel formats From 16c9188cfc6147171d65236d8807ee5e15923556 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Fri, 22 Jul 2022 08:37:49 +0200 Subject: [PATCH 02/12] clippy --- wgpu-types/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index f96075cd3e..76f99cd71c 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2133,7 +2133,7 @@ impl<'de> Deserialize<'de> for TextureFormat { parts.next(); // discard "astc" let block = parts .next() - .ok_or(E::invalid_value(Unexpected::Str(s), &self))?; + .ok_or_else(|| E::invalid_value(Unexpected::Str(s), &self))?; let channel = parts.collect::>().join("-"); let block = match block { From 485dc639e9bfcdf3eaf682f63dbcc6d6ce92405e Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Sat, 24 Sep 2022 06:20:00 +0200 Subject: [PATCH 03/12] Update wgpu-types/src/lib.rs Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com> --- wgpu-types/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 8472db4db1..6c94b05823 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2191,7 +2191,7 @@ impl<'de> Deserialize<'de> for TextureFormat { } } - deserializer.deserialize_any(TextureFormatVisitor) + deserializer.deserialize_str(TextureFormatVisitor) } } From 78c9c7b785a7d6a006be50f45d94dc71e7456769 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Sat, 24 Sep 2022 06:20:09 +0200 Subject: [PATCH 04/12] Update wgpu-types/src/lib.rs Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com> --- wgpu-types/src/lib.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 6c94b05823..a8ec3ef37f 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2147,13 +2147,10 @@ impl<'de> Deserialize<'de> for TextureFormat { "eac-rg11unorm" => TextureFormat::EacRg11Unorm, "eac-rg11snorm" => TextureFormat::EacRg11Snorm, other => { - if other.starts_with("astc") { - let mut parts = other.split('-'); - parts.next(); // discard "astc" - let block = parts - .next() + if let Some(parts) = other.strip_prefix("astc-") { + let (block, channel) = parts + .split_once('-') .ok_or_else(|| E::invalid_value(Unexpected::Str(s), &self))?; - let channel = parts.collect::>().join("-"); let block = match block { "4x4" => AstcBlock::B4x4, From 085dab953edda98868a985ffbbfcddc102deb0ac Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Sat, 24 Sep 2022 06:20:25 +0200 Subject: [PATCH 05/12] Update wgpu-types/src/lib.rs Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com> --- wgpu-types/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index a8ec3ef37f..daf2e4e8f6 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2070,7 +2070,7 @@ impl<'de> Deserialize<'de> for TextureFormat { type Value = TextureFormat; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("Invalid TextureFormat") + formatter.write_str("a valid texture format") } fn visit_str(self, s: &str) -> Result { From 687ee267f430a7904387d6050056781892bc58fb Mon Sep 17 00:00:00 2001 From: crowlkats Date: Sat, 24 Sep 2022 06:30:09 +0200 Subject: [PATCH 06/12] cleanup & use string serializer --- wgpu-types/src/lib.rs | 366 +++++++++--------------------------------- 1 file changed, 76 insertions(+), 290 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index daf2e4e8f6..e74d331440 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1843,7 +1843,6 @@ pub enum TextureFormat { // Packed 32 bit formats /// Packed unsigned float with 9 bits mantisa for each RGB component, then a common 5 bits exponent - #[cfg_attr(feature = "serde", serde(rename = "rgb9e5ufloat"))] Rgb9e5Ufloat, /// Red, green, blue, and alpha channels. 10 bit integer for RGB channels, 2 bit integer for alpha channel. [0, 1023] ([0, 3] for alpha) converted to/from float [0, 1] in shader. Rgb10a2Unorm, @@ -2118,9 +2117,9 @@ impl<'de> Deserialize<'de> for TextureFormat { "rgba32float" => TextureFormat::Rgba32Float, "depth32float" => TextureFormat::Depth32Float, "depth32float-stencil8" => TextureFormat::Depth32FloatStencil8, + "Depth16unorm" => TextureFormat::Depth16Unorm, "depth24plus" => TextureFormat::Depth24Plus, "depth24plus-stencil8" => TextureFormat::Depth24PlusStencil8, - "depth24unorm-stencil8" => TextureFormat::Depth24UnormStencil8, "rgb9e5ufloat" => TextureFormat::Rgb9e5Ufloat, "bc1-rgba-unorm" => TextureFormat::Bc1RgbaUnorm, "bc1-rgba-unorm-srgb" => TextureFormat::Bc1RgbaUnormSrgb, @@ -2198,291 +2197,78 @@ impl Serialize for TextureFormat { where S: serde::Serializer, { - match *self { - TextureFormat::R8Unorm => { - let name = "r8unorm"; - serializer.serialize_unit_variant(name, 0, name) - } - TextureFormat::R8Snorm => { - let name = "r8snorm"; - serializer.serialize_unit_variant(name, 1, name) - } - TextureFormat::R8Uint => { - let name = "r8uint"; - serializer.serialize_unit_variant(name, 2, name) - } - TextureFormat::R8Sint => { - let name = "r8sint"; - serializer.serialize_unit_variant(name, 3, name) - } - TextureFormat::R16Uint => { - let name = "r16uint"; - serializer.serialize_unit_variant(name, 4, name) - } - TextureFormat::R16Sint => { - let name = "r16sint"; - serializer.serialize_unit_variant(name, 5, name) - } - TextureFormat::R16Unorm => { - let name = "r16unorm"; - serializer.serialize_unit_variant(name, 6, name) - } - TextureFormat::R16Snorm => { - let name = "r16snorm"; - serializer.serialize_unit_variant(name, 7, name) - } - TextureFormat::R16Float => { - let name = "r16float"; - serializer.serialize_unit_variant(name, 8, name) - } - TextureFormat::Rg8Unorm => { - let name = "rg8unorm"; - serializer.serialize_unit_variant(name, 9, name) - } - TextureFormat::Rg8Snorm => { - let name = "rg8snorm"; - serializer.serialize_unit_variant(name, 10, name) - } - TextureFormat::Rg8Uint => { - let name = "rg8uint"; - serializer.serialize_unit_variant(name, 11, name) - } - TextureFormat::Rg8Sint => { - let name = "rg8sint"; - serializer.serialize_unit_variant(name, 12, name) - } - TextureFormat::R32Uint => { - let name = "r32uint"; - serializer.serialize_unit_variant(name, 13, name) - } - TextureFormat::R32Sint => { - let name = "r32sint"; - serializer.serialize_unit_variant(name, 14, name) - } - TextureFormat::R32Float => { - let name = "r32float"; - serializer.serialize_unit_variant(name, 15, name) - } - TextureFormat::Rg16Uint => { - let name = "rg16uint"; - serializer.serialize_unit_variant(name, 16, name) - } - TextureFormat::Rg16Sint => { - let name = "rg16sint"; - serializer.serialize_unit_variant(name, 17, name) - } - TextureFormat::Rg16Unorm => { - let name = "rg16unorm"; - serializer.serialize_unit_variant(name, 18, name) - } - TextureFormat::Rg16Snorm => { - let name = "rg16snorm"; - serializer.serialize_unit_variant(name, 19, name) - } - TextureFormat::Rg16Float => { - let name = "rg16float"; - serializer.serialize_unit_variant(name, 20, name) - } - TextureFormat::Rgba8Unorm => { - let name = "rgba8unorm"; - serializer.serialize_unit_variant(name, 21, name) - } - TextureFormat::Rgba8UnormSrgb => { - let name = "rgba8unorm-srgb"; - serializer.serialize_unit_variant(name, 22, name) - } - TextureFormat::Rgba8Snorm => { - let name = "rgba8snorm"; - serializer.serialize_unit_variant(name, 23, name) - } - TextureFormat::Rgba8Uint => { - let name = "rgba8uint"; - serializer.serialize_unit_variant(name, 24, name) - } - TextureFormat::Rgba8Sint => { - let name = "rgba8sint"; - serializer.serialize_unit_variant(name, 25, name) - } - TextureFormat::Bgra8Unorm => { - let name = "bgra8unorm"; - serializer.serialize_unit_variant(name, 26, name) - } - TextureFormat::Bgra8UnormSrgb => { - let name = "bgra8unorm-srgb"; - serializer.serialize_unit_variant(name, 27, name) - } - TextureFormat::Rgb10a2Unorm => { - let name = "rgb10a2unorm"; - serializer.serialize_unit_variant(name, 28, name) - } - TextureFormat::Rg11b10Float => { - let name = "rg11b10ufloat"; - serializer.serialize_unit_variant(name, 29, name) - } - TextureFormat::Rg32Uint => { - let name = "rg32uint"; - serializer.serialize_unit_variant(name, 30, name) - } - TextureFormat::Rg32Sint => { - let name = "rg32sint"; - serializer.serialize_unit_variant(name, 31, name) - } - TextureFormat::Rg32Float => { - let name = "rg32float"; - serializer.serialize_unit_variant(name, 32, name) - } - TextureFormat::Rgba16Uint => { - let name = "rgba16uint"; - serializer.serialize_unit_variant(name, 33, name) - } - TextureFormat::Rgba16Sint => { - let name = "rgba16sint"; - serializer.serialize_unit_variant(name, 34, name) - } - TextureFormat::Rgba16Unorm => { - let name = "rgba16unorm"; - serializer.serialize_unit_variant(name, 35, name) - } - TextureFormat::Rgba16Snorm => { - let name = "rgba16snorm"; - serializer.serialize_unit_variant(name, 36, name) - } - TextureFormat::Rgba16Float => { - let name = "rgba16float"; - serializer.serialize_unit_variant(name, 37, name) - } - TextureFormat::Rgba32Uint => { - let name = "rgba32uint"; - serializer.serialize_unit_variant(name, 38, name) - } - TextureFormat::Rgba32Sint => { - let name = "rgba32sint"; - serializer.serialize_unit_variant(name, 39, name) - } - TextureFormat::Rgba32Float => { - let name = "rgba32float"; - serializer.serialize_unit_variant(name, 40, name) - } - TextureFormat::Depth32Float => { - let name = "depth32float"; - serializer.serialize_unit_variant(name, 41, name) - } - TextureFormat::Depth32FloatStencil8 => { - let name = "depth32float-stencil8"; - serializer.serialize_unit_variant(name, 42, name) - } - TextureFormat::Depth24Plus => { - let name = "depth24plus"; - serializer.serialize_unit_variant(name, 43, name) - } - TextureFormat::Depth24PlusStencil8 => { - let name = "depth24plus-stencil8"; - serializer.serialize_unit_variant(name, 44, name) - } - TextureFormat::Depth24UnormStencil8 => { - let name = "depth24unorm-stencil8"; - serializer.serialize_unit_variant(name, 45, name) - } - TextureFormat::Rgb9e5Ufloat => { - let name = "rgb9e5ufloat"; - serializer.serialize_unit_variant(name, 46, name) - } - TextureFormat::Bc1RgbaUnorm => { - let name = "bc1-rgba-unorm"; - serializer.serialize_unit_variant(name, 47, name) - } - TextureFormat::Bc1RgbaUnormSrgb => { - let name = "bc1-rgba-unorm-srgb"; - serializer.serialize_unit_variant(name, 48, name) - } - TextureFormat::Bc2RgbaUnorm => { - let name = "bc2-rgba-unorm"; - serializer.serialize_unit_variant(name, 49, name) - } - TextureFormat::Bc2RgbaUnormSrgb => { - let name = "bc2-rgba-unorm-srgb"; - serializer.serialize_unit_variant(name, 50, name) - } - TextureFormat::Bc3RgbaUnorm => { - let name = "bc3-rgba-unorm"; - serializer.serialize_unit_variant(name, 51, name) - } - TextureFormat::Bc3RgbaUnormSrgb => { - let name = "bc3-rgba-unorm-srgb"; - serializer.serialize_unit_variant(name, 52, name) - } - TextureFormat::Bc4RUnorm => { - let name = "bc4-r-unorm"; - serializer.serialize_unit_variant(name, 53, name) - } - TextureFormat::Bc4RSnorm => { - let name = "bc4-r-snorm"; - serializer.serialize_unit_variant(name, 54, name) - } - TextureFormat::Bc5RgUnorm => { - let name = "bc5-rg-unorm"; - serializer.serialize_unit_variant(name, 55, name) - } - TextureFormat::Bc5RgSnorm => { - let name = "bc5-rg-snorm"; - serializer.serialize_unit_variant(name, 56, name) - } - TextureFormat::Bc6hRgbUfloat => { - let name = "bc6h-rgb-ufloat"; - serializer.serialize_unit_variant(name, 57, name) - } - TextureFormat::Bc6hRgbSfloat => { - let name = "bc6h-rgb-float"; - serializer.serialize_unit_variant(name, 58, name) - } - TextureFormat::Bc7RgbaUnorm => { - let name = "bc7-rgba-unorm"; - serializer.serialize_unit_variant(name, 59, name) - } - TextureFormat::Bc7RgbaUnormSrgb => { - let name = "bc7-rgba-unorm-srgb"; - serializer.serialize_unit_variant(name, 60, name) - } - TextureFormat::Etc2Rgb8Unorm => { - let name = "etc2-rgb8unorm"; - serializer.serialize_unit_variant(name, 61, name) - } - TextureFormat::Etc2Rgb8UnormSrgb => { - let name = "etc2-rgb8unorm-srgb"; - serializer.serialize_unit_variant(name, 62, name) - } - TextureFormat::Etc2Rgb8A1Unorm => { - let name = "etc2-rgb8a1unorm"; - serializer.serialize_unit_variant(name, 63, name) - } - TextureFormat::Etc2Rgb8A1UnormSrgb => { - let name = "etc2-rgb8a1unorm-srgb"; - serializer.serialize_unit_variant(name, 64, name) - } - TextureFormat::Etc2Rgba8Unorm => { - let name = "etc2-rgba8unorm"; - serializer.serialize_unit_variant(name, 65, name) - } - TextureFormat::Etc2Rgba8UnormSrgb => { - let name = "etc2-rgba8unorm-srgb"; - serializer.serialize_unit_variant(name, 66, name) - } - TextureFormat::EacR11Unorm => { - let name = "eac-r11unorm"; - serializer.serialize_unit_variant(name, 67, name) - } - TextureFormat::EacR11Snorm => { - let name = "eac-r11snorm"; - serializer.serialize_unit_variant(name, 68, name) - } - TextureFormat::EacRg11Unorm => { - let name = "eac-rg11unorm"; - serializer.serialize_unit_variant(name, 69, name) - } - TextureFormat::EacRg11Snorm => { - let name = "eac-rg11snorm"; - serializer.serialize_unit_variant(name, 70, name) - } + let name = match *self { + TextureFormat::R8Unorm => "r8unorm", + TextureFormat::R8Snorm => "r8snorm", + TextureFormat::R8Uint => "r8uint", + TextureFormat::R8Sint => "r8sint", + TextureFormat::R16Uint => "r16uint", + TextureFormat::R16Sint => "r16sint", + TextureFormat::R16Unorm => "r16unorm", + TextureFormat::R16Snorm => "r16snorm", + TextureFormat::R16Float => "r16float", + TextureFormat::Rg8Unorm => "rg8unorm", + TextureFormat::Rg8Snorm => "rg8snorm", + TextureFormat::Rg8Uint => "rg8uint", + TextureFormat::Rg8Sint => "rg8sint", + TextureFormat::R32Uint => "r32uint", + TextureFormat::R32Sint => "r32sint", + TextureFormat::R32Float => "r32float", + TextureFormat::Rg16Uint => "rg16uint", + TextureFormat::Rg16Sint => "rg16sint", + TextureFormat::Rg16Unorm => "rg16unorm", + TextureFormat::Rg16Snorm => "rg16snorm", + TextureFormat::Rg16Float => "rg16float", + TextureFormat::Rgba8Unorm => "rgba8unorm", + TextureFormat::Rgba8UnormSrgb => "rgba8unorm-srgb", + TextureFormat::Rgba8Snorm => "rgba8snorm", + TextureFormat::Rgba8Uint => "rgba8uint", + TextureFormat::Rgba8Sint => "rgba8sint", + TextureFormat::Bgra8Unorm => "bgra8unorm", + TextureFormat::Bgra8UnormSrgb => "bgra8unorm-srgb", + TextureFormat::Rgb10a2Unorm => "rgb10a2unorm", + TextureFormat::Rg11b10Float => "rg11b10ufloat", + TextureFormat::Rg32Uint => "rg32uint", + TextureFormat::Rg32Sint => "rg32sint", + TextureFormat::Rg32Float => "rg32float", + TextureFormat::Rgba16Uint => "rgba16uint", + TextureFormat::Rgba16Sint => "rgba16sint", + TextureFormat::Rgba16Unorm => "rgba16unorm", + TextureFormat::Rgba16Snorm => "rgba16snorm", + TextureFormat::Rgba16Float => "rgba16float", + TextureFormat::Rgba32Uint => "rgba32uint", + TextureFormat::Rgba32Sint => "rgba32sint", + TextureFormat::Rgba32Float => "rgba32float", + TextureFormat::Depth32Float => "depth32float", + TextureFormat::Depth16Unorm => "depth16unorm", + TextureFormat::Depth32FloatStencil8 => "depth32float-stencil8", + TextureFormat::Depth24Plus => "depth24plus", + TextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8", + TextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat", + TextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm", + TextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb", + TextureFormat::Bc2RgbaUnorm => "bc2-rgba-unorm", + TextureFormat::Bc2RgbaUnormSrgb => "bc2-rgba-unorm-srgb", + TextureFormat::Bc3RgbaUnorm => "bc3-rgba-unorm", + TextureFormat::Bc3RgbaUnormSrgb => "bc3-rgba-unorm-srgb", + TextureFormat::Bc4RUnorm => "bc4-r-unorm", + TextureFormat::Bc4RSnorm => "bc4-r-snorm", + TextureFormat::Bc5RgUnorm => "bc5-rg-unorm", + TextureFormat::Bc5RgSnorm => "bc5-rg-snorm", + TextureFormat::Bc6hRgbUfloat => "bc6h-rgb-ufloat", + TextureFormat::Bc6hRgbSfloat => "bc6h-rgb-float", + TextureFormat::Bc7RgbaUnorm => "bc7-rgba-unorm", + TextureFormat::Bc7RgbaUnormSrgb => "bc7-rgba-unorm-srgb", + TextureFormat::Etc2Rgb8Unorm => "etc2-rgb8unorm", + TextureFormat::Etc2Rgb8UnormSrgb => "etc2-rgb8unorm-srgb", + TextureFormat::Etc2Rgb8A1Unorm => "etc2-rgb8a1unorm", + TextureFormat::Etc2Rgb8A1UnormSrgb => "etc2-rgb8a1unorm-srgb", + TextureFormat::Etc2Rgba8Unorm => "etc2-rgba8unorm", + TextureFormat::Etc2Rgba8UnormSrgb => "etc2-rgba8unorm-srgb", + TextureFormat::EacR11Unorm => "eac-r11unorm", + TextureFormat::EacR11Snorm => "eac-r11snorm", + TextureFormat::EacRg11Unorm => "eac-rg11unorm", + TextureFormat::EacRg11Snorm => "eac-rg11snorm", TextureFormat::Astc { block, channel } => { let block = match block { AstcBlock::B4x4 => "4x4", @@ -2507,10 +2293,10 @@ impl Serialize for TextureFormat { AstcChannel::Hdr => "hdr", }; - let name = format!("astc-{block}-{channel}"); - serializer.serialize_str(&name) + &format!("astc-{block}-{channel}") } - } + }; + serializer.serialize_str(name) } } From 653531137d92a3d14167e906d5f8eef77d135305 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Sat, 24 Sep 2022 06:30:53 +0200 Subject: [PATCH 07/12] fix --- wgpu-types/src/lib.rs | 146 +++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index e74d331440..8e1f411256 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2198,77 +2198,77 @@ impl Serialize for TextureFormat { S: serde::Serializer, { let name = match *self { - TextureFormat::R8Unorm => "r8unorm", - TextureFormat::R8Snorm => "r8snorm", - TextureFormat::R8Uint => "r8uint", - TextureFormat::R8Sint => "r8sint", - TextureFormat::R16Uint => "r16uint", - TextureFormat::R16Sint => "r16sint", - TextureFormat::R16Unorm => "r16unorm", - TextureFormat::R16Snorm => "r16snorm", - TextureFormat::R16Float => "r16float", - TextureFormat::Rg8Unorm => "rg8unorm", - TextureFormat::Rg8Snorm => "rg8snorm", - TextureFormat::Rg8Uint => "rg8uint", - TextureFormat::Rg8Sint => "rg8sint", - TextureFormat::R32Uint => "r32uint", - TextureFormat::R32Sint => "r32sint", - TextureFormat::R32Float => "r32float", - TextureFormat::Rg16Uint => "rg16uint", - TextureFormat::Rg16Sint => "rg16sint", - TextureFormat::Rg16Unorm => "rg16unorm", - TextureFormat::Rg16Snorm => "rg16snorm", - TextureFormat::Rg16Float => "rg16float", - TextureFormat::Rgba8Unorm => "rgba8unorm", - TextureFormat::Rgba8UnormSrgb => "rgba8unorm-srgb", - TextureFormat::Rgba8Snorm => "rgba8snorm", - TextureFormat::Rgba8Uint => "rgba8uint", - TextureFormat::Rgba8Sint => "rgba8sint", - TextureFormat::Bgra8Unorm => "bgra8unorm", - TextureFormat::Bgra8UnormSrgb => "bgra8unorm-srgb", - TextureFormat::Rgb10a2Unorm => "rgb10a2unorm", - TextureFormat::Rg11b10Float => "rg11b10ufloat", - TextureFormat::Rg32Uint => "rg32uint", - TextureFormat::Rg32Sint => "rg32sint", - TextureFormat::Rg32Float => "rg32float", - TextureFormat::Rgba16Uint => "rgba16uint", - TextureFormat::Rgba16Sint => "rgba16sint", - TextureFormat::Rgba16Unorm => "rgba16unorm", - TextureFormat::Rgba16Snorm => "rgba16snorm", - TextureFormat::Rgba16Float => "rgba16float", - TextureFormat::Rgba32Uint => "rgba32uint", - TextureFormat::Rgba32Sint => "rgba32sint", - TextureFormat::Rgba32Float => "rgba32float", - TextureFormat::Depth32Float => "depth32float", - TextureFormat::Depth16Unorm => "depth16unorm", - TextureFormat::Depth32FloatStencil8 => "depth32float-stencil8", - TextureFormat::Depth24Plus => "depth24plus", - TextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8", - TextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat", - TextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm", - TextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb", - TextureFormat::Bc2RgbaUnorm => "bc2-rgba-unorm", - TextureFormat::Bc2RgbaUnormSrgb => "bc2-rgba-unorm-srgb", - TextureFormat::Bc3RgbaUnorm => "bc3-rgba-unorm", - TextureFormat::Bc3RgbaUnormSrgb => "bc3-rgba-unorm-srgb", - TextureFormat::Bc4RUnorm => "bc4-r-unorm", - TextureFormat::Bc4RSnorm => "bc4-r-snorm", - TextureFormat::Bc5RgUnorm => "bc5-rg-unorm", - TextureFormat::Bc5RgSnorm => "bc5-rg-snorm", - TextureFormat::Bc6hRgbUfloat => "bc6h-rgb-ufloat", - TextureFormat::Bc6hRgbSfloat => "bc6h-rgb-float", - TextureFormat::Bc7RgbaUnorm => "bc7-rgba-unorm", - TextureFormat::Bc7RgbaUnormSrgb => "bc7-rgba-unorm-srgb", - TextureFormat::Etc2Rgb8Unorm => "etc2-rgb8unorm", - TextureFormat::Etc2Rgb8UnormSrgb => "etc2-rgb8unorm-srgb", - TextureFormat::Etc2Rgb8A1Unorm => "etc2-rgb8a1unorm", - TextureFormat::Etc2Rgb8A1UnormSrgb => "etc2-rgb8a1unorm-srgb", - TextureFormat::Etc2Rgba8Unorm => "etc2-rgba8unorm", - TextureFormat::Etc2Rgba8UnormSrgb => "etc2-rgba8unorm-srgb", - TextureFormat::EacR11Unorm => "eac-r11unorm", - TextureFormat::EacR11Snorm => "eac-r11snorm", - TextureFormat::EacRg11Unorm => "eac-rg11unorm", - TextureFormat::EacRg11Snorm => "eac-rg11snorm", + TextureFormat::R8Unorm => "r8unorm".to_string(), + TextureFormat::R8Snorm => "r8snorm".to_string(), + TextureFormat::R8Uint => "r8uint".to_string(), + TextureFormat::R8Sint => "r8sint".to_string(), + TextureFormat::R16Uint => "r16uint".to_string(), + TextureFormat::R16Sint => "r16sint".to_string(), + TextureFormat::R16Unorm => "r16unorm".to_string(), + TextureFormat::R16Snorm => "r16snorm".to_string(), + TextureFormat::R16Float => "r16float".to_string(), + TextureFormat::Rg8Unorm => "rg8unorm".to_string(), + TextureFormat::Rg8Snorm => "rg8snorm".to_string(), + TextureFormat::Rg8Uint => "rg8uint".to_string(), + TextureFormat::Rg8Sint => "rg8sint".to_string(), + TextureFormat::R32Uint => "r32uint".to_string(), + TextureFormat::R32Sint => "r32sint".to_string(), + TextureFormat::R32Float => "r32float".to_string(), + TextureFormat::Rg16Uint => "rg16uint".to_string(), + TextureFormat::Rg16Sint => "rg16sint".to_string(), + TextureFormat::Rg16Unorm => "rg16unorm".to_string(), + TextureFormat::Rg16Snorm => "rg16snorm".to_string(), + TextureFormat::Rg16Float => "rg16float".to_string(), + TextureFormat::Rgba8Unorm => "rgba8unorm".to_string(), + TextureFormat::Rgba8UnormSrgb => "rgba8unorm-srgb".to_string(), + TextureFormat::Rgba8Snorm => "rgba8snorm".to_string(), + TextureFormat::Rgba8Uint => "rgba8uint".to_string(), + TextureFormat::Rgba8Sint => "rgba8sint".to_string(), + TextureFormat::Bgra8Unorm => "bgra8unorm".to_string(), + TextureFormat::Bgra8UnormSrgb => "bgra8unorm-srgb".to_string(), + TextureFormat::Rgb10a2Unorm => "rgb10a2unorm".to_string(), + TextureFormat::Rg11b10Float => "rg11b10ufloat".to_string(), + TextureFormat::Rg32Uint => "rg32uint".to_string(), + TextureFormat::Rg32Sint => "rg32sint".to_string(), + TextureFormat::Rg32Float => "rg32float".to_string(), + TextureFormat::Rgba16Uint => "rgba16uint".to_string(), + TextureFormat::Rgba16Sint => "rgba16sint".to_string(), + TextureFormat::Rgba16Unorm => "rgba16unorm".to_string(), + TextureFormat::Rgba16Snorm => "rgba16snorm".to_string(), + TextureFormat::Rgba16Float => "rgba16float".to_string(), + TextureFormat::Rgba32Uint => "rgba32uint".to_string(), + TextureFormat::Rgba32Sint => "rgba32sint".to_string(), + TextureFormat::Rgba32Float => "rgba32float".to_string(), + TextureFormat::Depth32Float => "depth32float".to_string(), + TextureFormat::Depth16Unorm => "depth16unorm".to_string(), + TextureFormat::Depth32FloatStencil8 => "depth32float-stencil8".to_string(), + TextureFormat::Depth24Plus => "depth24plus".to_string(), + TextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8".to_string(), + TextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat".to_string(), + TextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm".to_string(), + TextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb".to_string(), + TextureFormat::Bc2RgbaUnorm => "bc2-rgba-unorm".to_string(), + TextureFormat::Bc2RgbaUnormSrgb => "bc2-rgba-unorm-srgb".to_string(), + TextureFormat::Bc3RgbaUnorm => "bc3-rgba-unorm".to_string(), + TextureFormat::Bc3RgbaUnormSrgb => "bc3-rgba-unorm-srgb".to_string(), + TextureFormat::Bc4RUnorm => "bc4-r-unorm".to_string(), + TextureFormat::Bc4RSnorm => "bc4-r-snorm".to_string(), + TextureFormat::Bc5RgUnorm => "bc5-rg-unorm".to_string(), + TextureFormat::Bc5RgSnorm => "bc5-rg-snorm".to_string(), + TextureFormat::Bc6hRgbUfloat => "bc6h-rgb-ufloat".to_string(), + TextureFormat::Bc6hRgbSfloat => "bc6h-rgb-float".to_string(), + TextureFormat::Bc7RgbaUnorm => "bc7-rgba-unorm".to_string(), + TextureFormat::Bc7RgbaUnormSrgb => "bc7-rgba-unorm-srgb".to_string(), + TextureFormat::Etc2Rgb8Unorm => "etc2-rgb8unorm".to_string(), + TextureFormat::Etc2Rgb8UnormSrgb => "etc2-rgb8unorm-srgb".to_string(), + TextureFormat::Etc2Rgb8A1Unorm => "etc2-rgb8a1unorm".to_string(), + TextureFormat::Etc2Rgb8A1UnormSrgb => "etc2-rgb8a1unorm-srgb".to_string(), + TextureFormat::Etc2Rgba8Unorm => "etc2-rgba8unorm".to_string(), + TextureFormat::Etc2Rgba8UnormSrgb => "etc2-rgba8unorm-srgb".to_string(), + TextureFormat::EacR11Unorm => "eac-r11unorm".to_string(), + TextureFormat::EacR11Snorm => "eac-r11snorm".to_string(), + TextureFormat::EacRg11Unorm => "eac-rg11unorm".to_string(), + TextureFormat::EacRg11Snorm => "eac-rg11snorm".to_string(), TextureFormat::Astc { block, channel } => { let block = match block { AstcBlock::B4x4 => "4x4", @@ -2293,10 +2293,10 @@ impl Serialize for TextureFormat { AstcChannel::Hdr => "hdr", }; - &format!("astc-{block}-{channel}") + format!("astc-{block}-{channel}") } }; - serializer.serialize_str(name) + serializer.serialize_str(*name) } } From 003773965dbdda3dc03dab8f3f05a26035e699cc Mon Sep 17 00:00:00 2001 From: crowlkats Date: Sat, 24 Sep 2022 06:31:09 +0200 Subject: [PATCH 08/12] actually fix... --- wgpu-types/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 8e1f411256..e43000096c 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2296,7 +2296,7 @@ impl Serialize for TextureFormat { format!("astc-{block}-{channel}") } }; - serializer.serialize_str(*name) + serializer.serialize_str(&name) } } From ba22886e341d5f669c45f4659e57fb65a969210c Mon Sep 17 00:00:00 2001 From: crowlkats Date: Sun, 25 Sep 2022 03:33:36 +0200 Subject: [PATCH 09/12] first pass at test --- Cargo.lock | 5 +- wgpu-types/Cargo.toml | 3 + wgpu-types/src/lib.rs | 578 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 583 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e2ac814c2..1032d6ddfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1688,9 +1688,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -2320,6 +2320,7 @@ dependencies = [ "bitflags", "bitflags_serde_shim", "serde", + "serde_json", ] [[package]] diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index 2712a884ec..eed39e7c1d 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -19,3 +19,6 @@ replay = ["serde", "bitflags_serde_shim"] bitflags = "1.0" serde = { version = "1.0", features = ["serde_derive"], optional = true } bitflags_serde_shim = { version = "0.2", optional = true } + +[dev-dependencies] +serde_json = "1.0.85" diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index e43000096c..90204b9e88 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2117,7 +2117,7 @@ impl<'de> Deserialize<'de> for TextureFormat { "rgba32float" => TextureFormat::Rgba32Float, "depth32float" => TextureFormat::Depth32Float, "depth32float-stencil8" => TextureFormat::Depth32FloatStencil8, - "Depth16unorm" => TextureFormat::Depth16Unorm, + "depth16unorm" => TextureFormat::Depth16Unorm, "depth24plus" => TextureFormat::Depth24Plus, "depth24plus-stencil8" => TextureFormat::Depth24PlusStencil8, "rgb9e5ufloat" => TextureFormat::Rgb9e5Ufloat, @@ -2487,6 +2487,582 @@ impl TextureFormat { } } +#[test] +fn texture_format_serialize() { + assert_eq!( + serde_json::to_string(&TextureFormat::R8Unorm).unwrap(), + "\"r8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R8Snorm).unwrap(), + "\"r8snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R8Uint).unwrap(), + "\"r8uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R8Sint).unwrap(), + "\"r8sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Uint).unwrap(), + "\"r16uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Sint).unwrap(), + "\"r16sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Unorm).unwrap(), + "\"r16unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Snorm).unwrap(), + "\"r16snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Float).unwrap(), + "\"r16float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg8Unorm).unwrap(), + "\"rg8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg8Snorm).unwrap(), + "\"rg8snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg8Uint).unwrap(), + "\"rg8uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg8Sint).unwrap(), + "\"rg8sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R32Uint).unwrap(), + "\"r32uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R32Sint).unwrap(), + "\"r32sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R32Float).unwrap(), + "\"r32float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Uint).unwrap(), + "\"rg16uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Sint).unwrap(), + "\"rg16sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Unorm).unwrap(), + "\"rg16unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Snorm).unwrap(), + "\"rg16snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Float).unwrap(), + "\"rg16float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8Unorm).unwrap(), + "\"rgba8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8UnormSrgb).unwrap(), + "\"rgba8unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8Snorm).unwrap(), + "\"rgba8snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8Uint).unwrap(), + "\"rgba8uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8Sint).unwrap(), + "\"rgba8sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bgra8Unorm).unwrap(), + "\"bgra8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bgra8UnormSrgb).unwrap(), + "\"bgra8unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgb10a2Unorm).unwrap(), + "\"rgb10a2unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg11b10Float).unwrap(), + "\"rg11b10ufloat\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg32Uint).unwrap(), + "\"rg32uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg32Sint).unwrap(), + "\"rg32sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg32Float).unwrap(), + "\"rg32float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Uint).unwrap(), + "\"rgba16uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Sint).unwrap(), + "\"rgba16sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Unorm).unwrap(), + "\"rgba16unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Snorm).unwrap(), + "\"rgba16snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Float).unwrap(), + "\"rgba16float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba32Uint).unwrap(), + "\"rgba32uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba32Sint).unwrap(), + "\"rgba32sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba32Float).unwrap(), + "\"rgba32float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth32Float).unwrap(), + "\"depth32float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth16Unorm).unwrap(), + "\"depth16unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth32FloatStencil8).unwrap(), + "\"depth32float-stencil8\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth24Plus).unwrap(), + "\"depth24plus\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth24PlusStencil8).unwrap(), + "\"depth24plus-stencil8\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgb9e5Ufloat).unwrap(), + "\"rgb9e5ufloat\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc1RgbaUnorm).unwrap(), + "\"bc1-rgba-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc1RgbaUnormSrgb).unwrap(), + "\"bc1-rgba-unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc2RgbaUnorm).unwrap(), + "\"bc2-rgba-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc2RgbaUnormSrgb).unwrap(), + "\"bc2-rgba-unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc3RgbaUnorm).unwrap(), + "\"bc3-rgba-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc3RgbaUnormSrgb).unwrap(), + "\"bc3-rgba-unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc4RUnorm).unwrap(), + "\"bc4-r-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc4RSnorm).unwrap(), + "\"bc4-r-snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc5RgUnorm).unwrap(), + "\"bc5-rg-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc5RgSnorm).unwrap(), + "\"bc5-rg-snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc6hRgbUfloat).unwrap(), + "\"bc6h-rgb-ufloat\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc6hRgbSfloat).unwrap(), + "\"bc6h-rgb-float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc7RgbaUnorm).unwrap(), + "\"bc7-rgba-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc7RgbaUnormSrgb).unwrap(), + "\"bc7-rgba-unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgb8Unorm).unwrap(), + "\"etc2-rgb8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgb8UnormSrgb).unwrap(), + "\"etc2-rgb8unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgb8A1Unorm).unwrap(), + "\"etc2-rgb8a1unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgb8A1UnormSrgb).unwrap(), + "\"etc2-rgb8a1unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgba8Unorm).unwrap(), + "\"etc2-rgba8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgba8UnormSrgb).unwrap(), + "\"etc2-rgba8unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::EacR11Unorm).unwrap(), + "\"eac-r11unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::EacR11Snorm).unwrap(), + "\"eac-r11snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::EacRg11Unorm).unwrap(), + "\"eac-rg11unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::EacRg11Snorm).unwrap(), + "\"eac-rg11snorm\"".to_string() + ); +} + +#[test] +fn texture_format_deserialize() { + assert_eq!( + serde_json::from_str::("\"r8unorm\"").unwrap(), + TextureFormat::R8Unorm + ); + assert_eq!( + serde_json::from_str::("\"r8snorm\"").unwrap(), + TextureFormat::R8Snorm + ); + assert_eq!( + serde_json::from_str::("\"r8uint\"").unwrap(), + TextureFormat::R8Uint + ); + assert_eq!( + serde_json::from_str::("\"r8sint\"").unwrap(), + TextureFormat::R8Sint + ); + assert_eq!( + serde_json::from_str::("\"r16uint\"").unwrap(), + TextureFormat::R16Uint + ); + assert_eq!( + serde_json::from_str::("\"r16sint\"").unwrap(), + TextureFormat::R16Sint + ); + assert_eq!( + serde_json::from_str::("\"r16unorm\"").unwrap(), + TextureFormat::R16Unorm + ); + assert_eq!( + serde_json::from_str::("\"r16snorm\"").unwrap(), + TextureFormat::R16Snorm + ); + assert_eq!( + serde_json::from_str::("\"r16float\"").unwrap(), + TextureFormat::R16Float + ); + assert_eq!( + serde_json::from_str::("\"rg8unorm\"").unwrap(), + TextureFormat::Rg8Unorm + ); + assert_eq!( + serde_json::from_str::("\"rg8snorm\"").unwrap(), + TextureFormat::Rg8Snorm + ); + assert_eq!( + serde_json::from_str::("\"rg8uint\"").unwrap(), + TextureFormat::Rg8Uint + ); + assert_eq!( + serde_json::from_str::("\"rg8sint\"").unwrap(), + TextureFormat::Rg8Sint + ); + assert_eq!( + serde_json::from_str::("\"r32uint\"").unwrap(), + TextureFormat::R32Uint + ); + assert_eq!( + serde_json::from_str::("\"r32sint\"").unwrap(), + TextureFormat::R32Sint + ); + assert_eq!( + serde_json::from_str::("\"r32float\"").unwrap(), + TextureFormat::R32Float + ); + assert_eq!( + serde_json::from_str::("\"rg16uint\"").unwrap(), + TextureFormat::Rg16Uint + ); + assert_eq!( + serde_json::from_str::("\"rg16sint\"").unwrap(), + TextureFormat::Rg16Sint + ); + assert_eq!( + serde_json::from_str::("\"rg16unorm\"").unwrap(), + TextureFormat::Rg16Unorm + ); + assert_eq!( + serde_json::from_str::("\"rg16snorm\"").unwrap(), + TextureFormat::Rg16Snorm + ); + assert_eq!( + serde_json::from_str::("\"rg16float\"").unwrap(), + TextureFormat::Rg16Float + ); + assert_eq!( + serde_json::from_str::("\"rgba8unorm\"").unwrap(), + TextureFormat::Rgba8Unorm + ); + assert_eq!( + serde_json::from_str::("\"rgba8unorm-srgb\"").unwrap(), + TextureFormat::Rgba8UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"rgba8snorm\"").unwrap(), + TextureFormat::Rgba8Snorm + ); + assert_eq!( + serde_json::from_str::("\"rgba8uint\"").unwrap(), + TextureFormat::Rgba8Uint + ); + assert_eq!( + serde_json::from_str::("\"rgba8sint\"").unwrap(), + TextureFormat::Rgba8Sint + ); + assert_eq!( + serde_json::from_str::("\"bgra8unorm\"").unwrap(), + TextureFormat::Bgra8Unorm + ); + assert_eq!( + serde_json::from_str::("\"bgra8unorm-srgb\"").unwrap(), + TextureFormat::Bgra8UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"rgb10a2unorm\"").unwrap(), + TextureFormat::Rgb10a2Unorm + ); + assert_eq!( + serde_json::from_str::("\"rg11b10ufloat\"").unwrap(), + TextureFormat::Rg11b10Float + ); + assert_eq!( + serde_json::from_str::("\"rg32uint\"").unwrap(), + TextureFormat::Rg32Uint + ); + assert_eq!( + serde_json::from_str::("\"rg32sint\"").unwrap(), + TextureFormat::Rg32Sint + ); + assert_eq!( + serde_json::from_str::("\"rg32float\"").unwrap(), + TextureFormat::Rg32Float + ); + assert_eq!( + serde_json::from_str::("\"rgba16uint\"").unwrap(), + TextureFormat::Rgba16Uint + ); + assert_eq!( + serde_json::from_str::("\"rgba16sint\"").unwrap(), + TextureFormat::Rgba16Sint + ); + assert_eq!( + serde_json::from_str::("\"rgba16unorm\"").unwrap(), + TextureFormat::Rgba16Unorm + ); + assert_eq!( + serde_json::from_str::("\"rgba16snorm\"").unwrap(), + TextureFormat::Rgba16Snorm + ); + assert_eq!( + serde_json::from_str::("\"rgba16float\"").unwrap(), + TextureFormat::Rgba16Float + ); + assert_eq!( + serde_json::from_str::("\"rgba32uint\"").unwrap(), + TextureFormat::Rgba32Uint + ); + assert_eq!( + serde_json::from_str::("\"rgba32sint\"").unwrap(), + TextureFormat::Rgba32Sint + ); + assert_eq!( + serde_json::from_str::("\"rgba32float\"").unwrap(), + TextureFormat::Rgba32Float + ); + assert_eq!( + serde_json::from_str::("\"depth32float\"").unwrap(), + TextureFormat::Depth32Float + ); + assert_eq!( + serde_json::from_str::("\"depth16unorm\"").unwrap(), + TextureFormat::Depth16Unorm + ); + assert_eq!( + serde_json::from_str::("\"depth32float-stencil8\"").unwrap(), + TextureFormat::Depth32FloatStencil8 + ); + assert_eq!( + serde_json::from_str::("\"depth24plus\"").unwrap(), + TextureFormat::Depth24Plus + ); + assert_eq!( + serde_json::from_str::("\"depth24plus-stencil8\"").unwrap(), + TextureFormat::Depth24PlusStencil8 + ); + assert_eq!( + serde_json::from_str::("\"rgb9e5ufloat\"").unwrap(), + TextureFormat::Rgb9e5Ufloat + ); + assert_eq!( + serde_json::from_str::("\"bc1-rgba-unorm\"").unwrap(), + TextureFormat::Bc1RgbaUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc1-rgba-unorm-srgb\"").unwrap(), + TextureFormat::Bc1RgbaUnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"bc2-rgba-unorm\"").unwrap(), + TextureFormat::Bc2RgbaUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc2-rgba-unorm-srgb\"").unwrap(), + TextureFormat::Bc2RgbaUnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"bc3-rgba-unorm\"").unwrap(), + TextureFormat::Bc3RgbaUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc3-rgba-unorm-srgb\"").unwrap(), + TextureFormat::Bc3RgbaUnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"bc4-r-unorm\"").unwrap(), + TextureFormat::Bc4RUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc4-r-snorm\"").unwrap(), + TextureFormat::Bc4RSnorm + ); + assert_eq!( + serde_json::from_str::("\"bc5-rg-unorm\"").unwrap(), + TextureFormat::Bc5RgUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc5-rg-snorm\"").unwrap(), + TextureFormat::Bc5RgSnorm + ); + assert_eq!( + serde_json::from_str::("\"bc6h-rgb-ufloat\"").unwrap(), + TextureFormat::Bc6hRgbUfloat + ); + assert_eq!( + serde_json::from_str::("\"bc6h-rgb-float\"").unwrap(), + TextureFormat::Bc6hRgbSfloat + ); + assert_eq!( + serde_json::from_str::("\"bc7-rgba-unorm\"").unwrap(), + TextureFormat::Bc7RgbaUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc7-rgba-unorm-srgb\"").unwrap(), + TextureFormat::Bc7RgbaUnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgb8unorm\"").unwrap(), + TextureFormat::Etc2Rgb8Unorm + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgb8unorm-srgb\"").unwrap(), + TextureFormat::Etc2Rgb8UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgb8a1unorm\"").unwrap(), + TextureFormat::Etc2Rgb8A1Unorm + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgb8a1unorm-srgb\"").unwrap(), + TextureFormat::Etc2Rgb8A1UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgba8unorm\"").unwrap(), + TextureFormat::Etc2Rgba8Unorm + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgba8unorm-srgb\"").unwrap(), + TextureFormat::Etc2Rgba8UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"eac-r11unorm\"").unwrap(), + TextureFormat::EacR11Unorm + ); + assert_eq!( + serde_json::from_str::("\"eac-r11snorm\"").unwrap(), + TextureFormat::EacR11Snorm + ); + assert_eq!( + serde_json::from_str::("\"eac-rg11unorm\"").unwrap(), + TextureFormat::EacRg11Unorm + ); + assert_eq!( + serde_json::from_str::("\"eac-rg11snorm\"").unwrap(), + TextureFormat::EacRg11Snorm + ); +} + bitflags::bitflags! { /// Color write mask. Disabled color channels will not be written to. /// From fdeeeaf8a3e782f45d39bf7710480c7dd6d67895 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 26 Sep 2022 04:05:54 +0200 Subject: [PATCH 10/12] fix clippy --- wgpu-types/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 90204b9e88..df1bdf8f58 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2169,7 +2169,7 @@ impl<'de> Deserialize<'de> for TextureFormat { _ => return Err(E::invalid_value(Unexpected::Str(s), &self)), }; - let channel = match channel.as_ref() { + let channel = match channel { "unorm" => AstcChannel::Unorm, "unorm-srgb" => AstcChannel::UnormSrgb, "hdr" => AstcChannel::Hdr, From eef432c011aa0adb65632c45de8addf760370d5f Mon Sep 17 00:00:00 2001 From: crowlkats Date: Thu, 29 Sep 2022 05:12:01 +0200 Subject: [PATCH 11/12] fix rons --- player/tests/data/clear-buffer-texture.ron | 2 +- player/tests/data/quad.ron | 6 +++--- player/tests/data/zero-init-texture-binding.ron | 8 ++++---- player/tests/data/zero-init-texture-copytobuffer.ron | 4 ++-- player/tests/data/zero-init-texture-rendertarget.ron | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/player/tests/data/clear-buffer-texture.ron b/player/tests/data/clear-buffer-texture.ron index 023164282f..7d32a688e7 100644 --- a/player/tests/data/clear-buffer-texture.ron +++ b/player/tests/data/clear-buffer-texture.ron @@ -29,7 +29,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 27, )), // First fill the texture to ensure it wasn't just zero initialized or "happened" to be zero. diff --git a/player/tests/data/quad.ron b/player/tests/data/quad.ron index 11b6378300..1f7cb266f4 100644 --- a/player/tests/data/quad.ron +++ b/player/tests/data/quad.ron @@ -26,7 +26,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 27, )), CreateTextureView( @@ -67,7 +67,7 @@ ), targets: [ Some(( - format: rgba8unorm, + format: "rgba8unorm", )), ], )), @@ -129,4 +129,4 @@ ), ]), ], -) \ No newline at end of file +) diff --git a/player/tests/data/zero-init-texture-binding.ron b/player/tests/data/zero-init-texture-binding.ron index f1e51396f4..c6f8c40a53 100644 --- a/player/tests/data/zero-init-texture-binding.ron +++ b/player/tests/data/zero-init-texture-binding.ron @@ -26,7 +26,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 5, // SAMPLED + COPY_SRC )), CreateTextureView( @@ -52,7 +52,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 9, // STORAGE + COPY_SRC )), CreateTextureView( @@ -89,7 +89,7 @@ visibility: 4, // COMPUTE ty: StorageTexture ( access: r#write-only, - format: rgba8unorm, + format: "rgba8unorm", view_dimension: r#2d, ), count: None, @@ -194,4 +194,4 @@ ), ]), ], -) \ No newline at end of file +) diff --git a/player/tests/data/zero-init-texture-copytobuffer.ron b/player/tests/data/zero-init-texture-copytobuffer.ron index 684272140f..e3f72f1a08 100644 --- a/player/tests/data/zero-init-texture-copytobuffer.ron +++ b/player/tests/data/zero-init-texture-copytobuffer.ron @@ -19,7 +19,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 1, // COPY_SRC )), CreateBuffer( @@ -53,4 +53,4 @@ ), ]), ], -) \ No newline at end of file +) diff --git a/player/tests/data/zero-init-texture-rendertarget.ron b/player/tests/data/zero-init-texture-rendertarget.ron index 4239acc6aa..5741c7c33c 100644 --- a/player/tests/data/zero-init-texture-rendertarget.ron +++ b/player/tests/data/zero-init-texture-rendertarget.ron @@ -19,7 +19,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 17, // RENDER_ATTACHMENT + COPY_SRC )), CreateTextureView( @@ -82,4 +82,4 @@ ), ]), ], -) \ No newline at end of file +) From 04294a0487230c9aaa5f15953aa7d00b67976747 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Thu, 29 Sep 2022 05:45:53 +0200 Subject: [PATCH 12/12] address comment --- wgpu-types/src/lib.rs | 148 +++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 73 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index df1bdf8f58..46fe905fa2 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2197,78 +2197,79 @@ impl Serialize for TextureFormat { where S: serde::Serializer, { + let s: String; let name = match *self { - TextureFormat::R8Unorm => "r8unorm".to_string(), - TextureFormat::R8Snorm => "r8snorm".to_string(), - TextureFormat::R8Uint => "r8uint".to_string(), - TextureFormat::R8Sint => "r8sint".to_string(), - TextureFormat::R16Uint => "r16uint".to_string(), - TextureFormat::R16Sint => "r16sint".to_string(), - TextureFormat::R16Unorm => "r16unorm".to_string(), - TextureFormat::R16Snorm => "r16snorm".to_string(), - TextureFormat::R16Float => "r16float".to_string(), - TextureFormat::Rg8Unorm => "rg8unorm".to_string(), - TextureFormat::Rg8Snorm => "rg8snorm".to_string(), - TextureFormat::Rg8Uint => "rg8uint".to_string(), - TextureFormat::Rg8Sint => "rg8sint".to_string(), - TextureFormat::R32Uint => "r32uint".to_string(), - TextureFormat::R32Sint => "r32sint".to_string(), - TextureFormat::R32Float => "r32float".to_string(), - TextureFormat::Rg16Uint => "rg16uint".to_string(), - TextureFormat::Rg16Sint => "rg16sint".to_string(), - TextureFormat::Rg16Unorm => "rg16unorm".to_string(), - TextureFormat::Rg16Snorm => "rg16snorm".to_string(), - TextureFormat::Rg16Float => "rg16float".to_string(), - TextureFormat::Rgba8Unorm => "rgba8unorm".to_string(), - TextureFormat::Rgba8UnormSrgb => "rgba8unorm-srgb".to_string(), - TextureFormat::Rgba8Snorm => "rgba8snorm".to_string(), - TextureFormat::Rgba8Uint => "rgba8uint".to_string(), - TextureFormat::Rgba8Sint => "rgba8sint".to_string(), - TextureFormat::Bgra8Unorm => "bgra8unorm".to_string(), - TextureFormat::Bgra8UnormSrgb => "bgra8unorm-srgb".to_string(), - TextureFormat::Rgb10a2Unorm => "rgb10a2unorm".to_string(), - TextureFormat::Rg11b10Float => "rg11b10ufloat".to_string(), - TextureFormat::Rg32Uint => "rg32uint".to_string(), - TextureFormat::Rg32Sint => "rg32sint".to_string(), - TextureFormat::Rg32Float => "rg32float".to_string(), - TextureFormat::Rgba16Uint => "rgba16uint".to_string(), - TextureFormat::Rgba16Sint => "rgba16sint".to_string(), - TextureFormat::Rgba16Unorm => "rgba16unorm".to_string(), - TextureFormat::Rgba16Snorm => "rgba16snorm".to_string(), - TextureFormat::Rgba16Float => "rgba16float".to_string(), - TextureFormat::Rgba32Uint => "rgba32uint".to_string(), - TextureFormat::Rgba32Sint => "rgba32sint".to_string(), - TextureFormat::Rgba32Float => "rgba32float".to_string(), - TextureFormat::Depth32Float => "depth32float".to_string(), - TextureFormat::Depth16Unorm => "depth16unorm".to_string(), - TextureFormat::Depth32FloatStencil8 => "depth32float-stencil8".to_string(), - TextureFormat::Depth24Plus => "depth24plus".to_string(), - TextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8".to_string(), - TextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat".to_string(), - TextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm".to_string(), - TextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb".to_string(), - TextureFormat::Bc2RgbaUnorm => "bc2-rgba-unorm".to_string(), - TextureFormat::Bc2RgbaUnormSrgb => "bc2-rgba-unorm-srgb".to_string(), - TextureFormat::Bc3RgbaUnorm => "bc3-rgba-unorm".to_string(), - TextureFormat::Bc3RgbaUnormSrgb => "bc3-rgba-unorm-srgb".to_string(), - TextureFormat::Bc4RUnorm => "bc4-r-unorm".to_string(), - TextureFormat::Bc4RSnorm => "bc4-r-snorm".to_string(), - TextureFormat::Bc5RgUnorm => "bc5-rg-unorm".to_string(), - TextureFormat::Bc5RgSnorm => "bc5-rg-snorm".to_string(), - TextureFormat::Bc6hRgbUfloat => "bc6h-rgb-ufloat".to_string(), - TextureFormat::Bc6hRgbSfloat => "bc6h-rgb-float".to_string(), - TextureFormat::Bc7RgbaUnorm => "bc7-rgba-unorm".to_string(), - TextureFormat::Bc7RgbaUnormSrgb => "bc7-rgba-unorm-srgb".to_string(), - TextureFormat::Etc2Rgb8Unorm => "etc2-rgb8unorm".to_string(), - TextureFormat::Etc2Rgb8UnormSrgb => "etc2-rgb8unorm-srgb".to_string(), - TextureFormat::Etc2Rgb8A1Unorm => "etc2-rgb8a1unorm".to_string(), - TextureFormat::Etc2Rgb8A1UnormSrgb => "etc2-rgb8a1unorm-srgb".to_string(), - TextureFormat::Etc2Rgba8Unorm => "etc2-rgba8unorm".to_string(), - TextureFormat::Etc2Rgba8UnormSrgb => "etc2-rgba8unorm-srgb".to_string(), - TextureFormat::EacR11Unorm => "eac-r11unorm".to_string(), - TextureFormat::EacR11Snorm => "eac-r11snorm".to_string(), - TextureFormat::EacRg11Unorm => "eac-rg11unorm".to_string(), - TextureFormat::EacRg11Snorm => "eac-rg11snorm".to_string(), + TextureFormat::R8Unorm => "r8unorm", + TextureFormat::R8Snorm => "r8snorm", + TextureFormat::R8Uint => "r8uint", + TextureFormat::R8Sint => "r8sint", + TextureFormat::R16Uint => "r16uint", + TextureFormat::R16Sint => "r16sint", + TextureFormat::R16Unorm => "r16unorm", + TextureFormat::R16Snorm => "r16snorm", + TextureFormat::R16Float => "r16float", + TextureFormat::Rg8Unorm => "rg8unorm", + TextureFormat::Rg8Snorm => "rg8snorm", + TextureFormat::Rg8Uint => "rg8uint", + TextureFormat::Rg8Sint => "rg8sint", + TextureFormat::R32Uint => "r32uint", + TextureFormat::R32Sint => "r32sint", + TextureFormat::R32Float => "r32float", + TextureFormat::Rg16Uint => "rg16uint", + TextureFormat::Rg16Sint => "rg16sint", + TextureFormat::Rg16Unorm => "rg16unorm", + TextureFormat::Rg16Snorm => "rg16snorm", + TextureFormat::Rg16Float => "rg16float", + TextureFormat::Rgba8Unorm => "rgba8unorm", + TextureFormat::Rgba8UnormSrgb => "rgba8unorm-srgb", + TextureFormat::Rgba8Snorm => "rgba8snorm", + TextureFormat::Rgba8Uint => "rgba8uint", + TextureFormat::Rgba8Sint => "rgba8sint", + TextureFormat::Bgra8Unorm => "bgra8unorm", + TextureFormat::Bgra8UnormSrgb => "bgra8unorm-srgb", + TextureFormat::Rgb10a2Unorm => "rgb10a2unorm", + TextureFormat::Rg11b10Float => "rg11b10ufloat", + TextureFormat::Rg32Uint => "rg32uint", + TextureFormat::Rg32Sint => "rg32sint", + TextureFormat::Rg32Float => "rg32float", + TextureFormat::Rgba16Uint => "rgba16uint", + TextureFormat::Rgba16Sint => "rgba16sint", + TextureFormat::Rgba16Unorm => "rgba16unorm", + TextureFormat::Rgba16Snorm => "rgba16snorm", + TextureFormat::Rgba16Float => "rgba16float", + TextureFormat::Rgba32Uint => "rgba32uint", + TextureFormat::Rgba32Sint => "rgba32sint", + TextureFormat::Rgba32Float => "rgba32float", + TextureFormat::Depth32Float => "depth32float", + TextureFormat::Depth16Unorm => "depth16unorm", + TextureFormat::Depth32FloatStencil8 => "depth32float-stencil8", + TextureFormat::Depth24Plus => "depth24plus", + TextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8", + TextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat", + TextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm", + TextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb", + TextureFormat::Bc2RgbaUnorm => "bc2-rgba-unorm", + TextureFormat::Bc2RgbaUnormSrgb => "bc2-rgba-unorm-srgb", + TextureFormat::Bc3RgbaUnorm => "bc3-rgba-unorm", + TextureFormat::Bc3RgbaUnormSrgb => "bc3-rgba-unorm-srgb", + TextureFormat::Bc4RUnorm => "bc4-r-unorm", + TextureFormat::Bc4RSnorm => "bc4-r-snorm", + TextureFormat::Bc5RgUnorm => "bc5-rg-unorm", + TextureFormat::Bc5RgSnorm => "bc5-rg-snorm", + TextureFormat::Bc6hRgbUfloat => "bc6h-rgb-ufloat", + TextureFormat::Bc6hRgbSfloat => "bc6h-rgb-float", + TextureFormat::Bc7RgbaUnorm => "bc7-rgba-unorm", + TextureFormat::Bc7RgbaUnormSrgb => "bc7-rgba-unorm-srgb", + TextureFormat::Etc2Rgb8Unorm => "etc2-rgb8unorm", + TextureFormat::Etc2Rgb8UnormSrgb => "etc2-rgb8unorm-srgb", + TextureFormat::Etc2Rgb8A1Unorm => "etc2-rgb8a1unorm", + TextureFormat::Etc2Rgb8A1UnormSrgb => "etc2-rgb8a1unorm-srgb", + TextureFormat::Etc2Rgba8Unorm => "etc2-rgba8unorm", + TextureFormat::Etc2Rgba8UnormSrgb => "etc2-rgba8unorm-srgb", + TextureFormat::EacR11Unorm => "eac-r11unorm", + TextureFormat::EacR11Snorm => "eac-r11snorm", + TextureFormat::EacRg11Unorm => "eac-rg11unorm", + TextureFormat::EacRg11Snorm => "eac-rg11snorm", TextureFormat::Astc { block, channel } => { let block = match block { AstcBlock::B4x4 => "4x4", @@ -2293,10 +2294,11 @@ impl Serialize for TextureFormat { AstcChannel::Hdr => "hdr", }; - format!("astc-{block}-{channel}") + s = format!("astc-{block}-{channel}"); + &s } }; - serializer.serialize_str(&name) + serializer.serialize_str(name) } }