From 7e4a115b6f8c197a38963f6a30482986f3ccb115 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:16:14 +0200 Subject: [PATCH] Add `Rgb10a2Uint` format --- Cargo.lock | 2 +- Cargo.toml | 2 +- tests/tests/clear_texture.rs | 1 + wgpu-core/Cargo.toml | 2 +- wgpu-core/src/validation.rs | 4 +++- wgpu-hal/Cargo.toml | 4 ++-- wgpu-hal/src/auxil/dxgi/conv.rs | 1 + wgpu-hal/src/gles/adapter.rs | 1 + wgpu-hal/src/gles/conv.rs | 5 +++++ wgpu-hal/src/metal/adapter.rs | 11 ++++++++--- wgpu-hal/src/metal/mod.rs | 3 +-- wgpu-hal/src/vulkan/conv.rs | 1 + wgpu-info/src/texture.rs | 3 ++- wgpu-types/src/lib.rs | 24 +++++++++++++++++++++--- wgpu/src/backend/web.rs | 3 +++ 15 files changed, 52 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f3b3489a5a..d6760b935e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1601,7 +1601,7 @@ dependencies = [ [[package]] name = "naga" version = "0.13.0" -source = "git+https://github.com/gfx-rs/naga?rev=df8107b7#df8107b78812cc2b1e3d5de35279cedc1f0da3fb" +source = "git+https://github.com/gfx-rs/naga?rev=6668d0694cc51ee66c71c2ca3a1ab1081956299b#6668d0694cc51ee66c71c2ca3a1ab1081956299b" dependencies = [ "bit-set", "bitflags 2.4.0", diff --git a/Cargo.toml b/Cargo.toml index 8794c68e11..e239248401 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,7 @@ version = "0.17" [workspace.dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "df8107b7" +rev = "6668d0694cc51ee66c71c2ca3a1ab1081956299b" version = "0.13.0" [workspace.dependencies] diff --git a/tests/tests/clear_texture.rs b/tests/tests/clear_texture.rs index 36f48af359..e3894f7820 100644 --- a/tests/tests/clear_texture.rs +++ b/tests/tests/clear_texture.rs @@ -24,6 +24,7 @@ static TEXTURE_FORMATS_UNCOMPRESSED_GLES_COMPAT: &[wgpu::TextureFormat] = &[ wgpu::TextureFormat::Rgba8Sint, wgpu::TextureFormat::Bgra8Unorm, wgpu::TextureFormat::Bgra8UnormSrgb, + wgpu::TextureFormat::Rgb10a2Uint, wgpu::TextureFormat::Rgb10a2Unorm, wgpu::TextureFormat::Rg11b10Float, wgpu::TextureFormat::Rg32Uint, diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 19bc3ad64d..7fdec68a2f 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -72,7 +72,7 @@ thiserror = "1" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "df8107b7" +rev = "6668d0694cc51ee66c71c2ca3a1ab1081956299b" version = "0.13.0" features = ["clone", "span", "validate"] diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index ef5c65ed00..59793743f7 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -296,6 +296,7 @@ fn map_storage_format_to_naga(format: wgt::TextureFormat) -> Option Sf::Rgba8Uint, Tf::Rgba8Sint => Sf::Rgba8Sint, + Tf::Rgb10a2Uint => Sf::Rgb10a2Uint, Tf::Rgb10a2Unorm => Sf::Rgb10a2Unorm, Tf::Rg11b10Float => Sf::Rg11b10Float, @@ -350,6 +351,7 @@ fn map_storage_format_from_naga(format: naga::StorageFormat) -> wgt::TextureForm Sf::Rgba8Uint => Tf::Rgba8Uint, Sf::Rgba8Sint => Tf::Rgba8Sint, + Sf::Rgb10a2Uint => Tf::Rgb10a2Uint, Sf::Rgb10a2Unorm => Tf::Rgb10a2Unorm, Sf::Rg11b10Float => Tf::Rg11b10Float, @@ -667,7 +669,7 @@ impl NumericType { | Tf::Rgb10a2Unorm | Tf::Rgba16Float | Tf::Rgba32Float => (NumericDimension::Vector(Vs::Quad), Sk::Float), - Tf::Rgba8Uint | Tf::Rgba16Uint | Tf::Rgba32Uint => { + Tf::Rgba8Uint | Tf::Rgba16Uint | Tf::Rgba32Uint | Tf::Rgb10a2Uint => { (NumericDimension::Vector(Vs::Quad), Sk::Uint) } Tf::Rgba8Sint | Tf::Rgba16Sint | Tf::Rgba32Sint => { diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 18e63b3d4e..ff8662c721 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -120,14 +120,14 @@ android_system_properties = "0.1.1" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "df8107b7" +rev = "6668d0694cc51ee66c71c2ca3a1ab1081956299b" version = "0.13.0" features = ["clone"] # DEV dependencies [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "df8107b7" +rev = "6668d0694cc51ee66c71c2ca3a1ab1081956299b" version = "0.13.0" features = ["wgsl-in"] diff --git a/wgpu-hal/src/auxil/dxgi/conv.rs b/wgpu-hal/src/auxil/dxgi/conv.rs index 0456cd719b..3798f7ea0a 100644 --- a/wgpu-hal/src/auxil/dxgi/conv.rs +++ b/wgpu-hal/src/auxil/dxgi/conv.rs @@ -34,6 +34,7 @@ pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option DXGI_FORMAT_R8G8B8A8_UINT, Tf::Rgba8Sint => DXGI_FORMAT_R8G8B8A8_SINT, Tf::Rgb9e5Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP, + Tf::Rgb10a2Uint => DXGI_FORMAT_R10G10B10A2_UINT, Tf::Rgb10a2Unorm => DXGI_FORMAT_R10G10B10A2_UNORM, Tf::Rg11b10Float => DXGI_FORMAT_R11G11B10_FLOAT, Tf::Rg32Uint => DXGI_FORMAT_R32G32_UINT, diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index cbbcf7399e..4c81fca65b 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -828,6 +828,7 @@ impl crate::Adapter for super::Adapter { Tf::Rgba8Snorm => filterable, Tf::Rgba8Uint => renderable | storage, Tf::Rgba8Sint => renderable | storage, + Tf::Rgb10a2Uint => renderable, Tf::Rgb10a2Unorm => filterable_renderable, Tf::Rg11b10Float => filterable | float_renderable, Tf::Rg32Uint => renderable, diff --git a/wgpu-hal/src/gles/conv.rs b/wgpu-hal/src/gles/conv.rs index 9bfac022a1..c09d573716 100644 --- a/wgpu-hal/src/gles/conv.rs +++ b/wgpu-hal/src/gles/conv.rs @@ -35,6 +35,11 @@ impl super::AdapterShared { Tf::Bgra8Unorm => (glow::RGBA8, glow::BGRA, glow::UNSIGNED_BYTE), //TODO? Tf::Rgba8Uint => (glow::RGBA8UI, glow::RGBA_INTEGER, glow::UNSIGNED_BYTE), Tf::Rgba8Sint => (glow::RGBA8I, glow::RGBA_INTEGER, glow::BYTE), + Tf::Rgb10a2Uint => ( + glow::RGB10_A2UI, + glow::RGBA_INTEGER, + glow::UNSIGNED_INT_2_10_10_10_REV, + ), Tf::Rgb10a2Unorm => ( glow::RGB10_A2, glow::RGBA, diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index c4617deaa0..538ccd64bf 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -166,6 +166,11 @@ impl crate::Adapter for super::Adapter { flags.set(Tfc::STORAGE, pc.format_rgba8_srgb_all); flags } + Tf::Rgb10a2Uint => { + let mut flags = Tfc::COLOR_ATTACHMENT | msaa_count; + flags.set(Tfc::STORAGE, pc.format_rgb10a2_uint_write); + flags + } Tf::Rgb10a2Unorm => { let mut flags = all_caps; flags.set(Tfc::STORAGE, pc.format_rgb10a2_unorm_all); @@ -399,7 +404,7 @@ const RGB10A2UNORM_ALL: &[MTLFeatureSet] = &[ MTLFeatureSet::macOS_GPUFamily1_v1, ]; -const RGB10A2UINT_COLOR_WRITE: &[MTLFeatureSet] = &[ +const RGB10A2UINT_WRITE: &[MTLFeatureSet] = &[ MTLFeatureSet::iOS_GPUFamily3_v1, MTLFeatureSet::tvOS_GPUFamily2_v1, MTLFeatureSet::macOS_GPUFamily1_v1, @@ -636,8 +641,7 @@ impl super::PrivateCapabilities { format_rgba8_srgb_no_write: !Self::supports_any(device, RGBA8_SRGB), format_rgb10a2_unorm_all: Self::supports_any(device, RGB10A2UNORM_ALL), format_rgb10a2_unorm_no_write: !Self::supports_any(device, RGB10A2UNORM_ALL), - format_rgb10a2_uint_color: !Self::supports_any(device, RGB10A2UINT_COLOR_WRITE), - format_rgb10a2_uint_color_write: Self::supports_any(device, RGB10A2UINT_COLOR_WRITE), + format_rgb10a2_uint_write: Self::supports_any(device, RGB10A2UINT_WRITE), format_rg11b10_all: Self::supports_any(device, RG11B10FLOAT_ALL), format_rg11b10_no_write: !Self::supports_any(device, RG11B10FLOAT_ALL), format_rgb9e5_all: Self::supports_any(device, RGB9E5FLOAT_ALL), @@ -971,6 +975,7 @@ impl super::PrivateCapabilities { Tf::Bgra8Unorm => BGRA8Unorm, Tf::Rgba8Uint => RGBA8Uint, Tf::Rgba8Sint => RGBA8Sint, + Tf::Rgb10a2Uint => RGB10A2Uint, Tf::Rgb10a2Unorm => RGB10A2Unorm, Tf::Rg11b10Float => RG11B10Float, Tf::Rg32Uint => RG32Uint, diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index c6b91a4f3c..d9da4f7476 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -208,8 +208,7 @@ struct PrivateCapabilities { format_rgba8_srgb_no_write: bool, format_rgb10a2_unorm_all: bool, format_rgb10a2_unorm_no_write: bool, - format_rgb10a2_uint_color: bool, - format_rgb10a2_uint_color_write: bool, + format_rgb10a2_uint_write: bool, format_rg11b10_all: bool, format_rg11b10_no_write: bool, format_rgb9e5_all: bool, diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index 459b7f858f..71b8a877c9 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -34,6 +34,7 @@ impl super::PrivateCapabilities { Tf::Bgra8Unorm => F::B8G8R8A8_UNORM, Tf::Rgba8Uint => F::R8G8B8A8_UINT, Tf::Rgba8Sint => F::R8G8B8A8_SINT, + Tf::Rgb10a2Uint => F::A2B10G10R10_UINT_PACK32, Tf::Rgb10a2Unorm => F::A2B10G10R10_UNORM_PACK32, Tf::Rg11b10Float => F::B10G11R11_UFLOAT_PACK32, Tf::Rg32Uint => F::R32G32_UINT, diff --git a/wgpu-info/src/texture.rs b/wgpu-info/src/texture.rs index 5bafa67a59..aecd3071bd 100644 --- a/wgpu-info/src/texture.rs +++ b/wgpu-info/src/texture.rs @@ -1,6 +1,6 @@ // Lets keep these on one line #[rustfmt::skip] -pub const TEXTURE_FORMAT_LIST: [wgpu::TextureFormat; 114] = [ +pub const TEXTURE_FORMAT_LIST: [wgpu::TextureFormat; 115] = [ wgpu::TextureFormat::R8Unorm, wgpu::TextureFormat::R8Snorm, wgpu::TextureFormat::R8Uint, @@ -29,6 +29,7 @@ pub const TEXTURE_FORMAT_LIST: [wgpu::TextureFormat; 114] = [ wgpu::TextureFormat::Rgba8Sint, wgpu::TextureFormat::Bgra8Unorm, wgpu::TextureFormat::Bgra8UnormSrgb, + wgpu::TextureFormat::Rgb10a2Uint, wgpu::TextureFormat::Rgb10a2Unorm, wgpu::TextureFormat::Rg11b10Float, wgpu::TextureFormat::Rg32Uint, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index a680d91296..26cf8ccbc0 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2148,6 +2148,8 @@ pub enum TextureFormat { // Packed 32 bit formats /// Packed unsigned float with 9 bits mantisa for each RGB component, then a common 5 bits exponent Rgb9e5Ufloat, + /// Red, green, blue, and alpha channels. 10 bit integer for RGB channels, 2 bit integer for alpha channel. Unsigned in shader. + Rgb10a2Uint, /// 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, /// 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. @@ -2408,6 +2410,7 @@ impl<'de> Deserialize<'de> for TextureFormat { "rgba8sint" => TextureFormat::Rgba8Sint, "bgra8unorm" => TextureFormat::Bgra8Unorm, "bgra8unorm-srgb" => TextureFormat::Bgra8UnormSrgb, + "rgb10a2uint" => TextureFormat::Rgb10a2Uint, "rgb10a2unorm" => TextureFormat::Rgb10a2Unorm, "rg11b10ufloat" => TextureFormat::Rg11b10Float, "rg32uint" => TextureFormat::Rg32Uint, @@ -2534,6 +2537,7 @@ impl Serialize for TextureFormat { TextureFormat::Rgba8Sint => "rgba8sint", TextureFormat::Bgra8Unorm => "bgra8unorm", TextureFormat::Bgra8UnormSrgb => "bgra8unorm-srgb", + TextureFormat::Rgb10a2Uint => "rgb10a2uint", TextureFormat::Rgb10a2Unorm => "rgb10a2unorm", TextureFormat::Rg11b10Float => "rg11b10ufloat", TextureFormat::Rg32Uint => "rg32uint", @@ -2724,6 +2728,7 @@ impl TextureFormat { | Self::Bgra8Unorm | Self::Bgra8UnormSrgb | Self::Rgb9e5Ufloat + | Self::Rgb10a2Uint | Self::Rgb10a2Unorm | Self::Rg11b10Float | Self::Rg32Uint @@ -2822,6 +2827,7 @@ impl TextureFormat { | Self::Bgra8Unorm | Self::Bgra8UnormSrgb | Self::Rgb9e5Ufloat + | Self::Rgb10a2Uint | Self::Rgb10a2Unorm | Self::Rg11b10Float | Self::Rg32Uint @@ -2931,6 +2937,7 @@ impl TextureFormat { Self::Rgba8Sint => ( msaa, all_flags), Self::Bgra8Unorm => (msaa_resolve, attachment), Self::Bgra8UnormSrgb => (msaa_resolve, attachment), + Self::Rgb10a2Uint => ( msaa, attachment), Self::Rgb10a2Unorm => (msaa_resolve, attachment), Self::Rg11b10Float => ( msaa, rg11b10f), Self::Rg32Uint => ( noaa, all_flags), @@ -3036,7 +3043,8 @@ impl TextureFormat { | Self::Rgba16Uint | Self::R32Uint | Self::Rg32Uint - | Self::Rgba32Uint => Some(uint), + | Self::Rgba32Uint + | Self::Rgb10a2Uint => Some(uint), Self::R8Sint | Self::Rg8Sint @@ -3124,7 +3132,9 @@ impl TextureFormat { | Self::Rg16Sint | Self::Rg16Float => Some(4), Self::R32Uint | Self::R32Sint | Self::R32Float => Some(4), - Self::Rgb9e5Ufloat | Self::Rgb10a2Unorm | Self::Rg11b10Float => Some(4), + Self::Rgb9e5Ufloat | Self::Rgb10a2Uint | Self::Rgb10a2Unorm | Self::Rg11b10Float => { + Some(4) + } Self::Rgba16Unorm | Self::Rgba16Snorm @@ -3232,7 +3242,7 @@ impl TextureFormat { | Self::Rgba32Float => 4, Self::Rgb9e5Ufloat | Self::Rg11b10Float => 3, - Self::Rgb10a2Unorm => 4, + Self::Rgb10a2Uint | Self::Rgb10a2Unorm => 4, Self::Stencil8 | Self::Depth16Unorm | Self::Depth24Plus | Self::Depth32Float => 1, @@ -3431,6 +3441,10 @@ fn texture_format_serialize() { serde_json::to_string(&TextureFormat::Bgra8UnormSrgb).unwrap(), "\"bgra8unorm-srgb\"".to_string() ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgb10a2Uint).unwrap(), + "\"rgb10a2uint\"".to_string() + ); assert_eq!( serde_json::to_string(&TextureFormat::Rgb10a2Unorm).unwrap(), "\"rgb10a2unorm\"".to_string() @@ -3723,6 +3737,10 @@ fn texture_format_deserialize() { serde_json::from_str::("\"bgra8unorm-srgb\"").unwrap(), TextureFormat::Bgra8UnormSrgb ); + assert_eq!( + serde_json::from_str::("\"rgb10a2uint\"").unwrap(), + TextureFormat::Rgb10a2Uint + ); assert_eq!( serde_json::from_str::("\"rgb10a2unorm\"").unwrap(), TextureFormat::Rgb10a2Unorm diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 3868a01fcd..131b18976b 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -197,6 +197,9 @@ fn map_texture_format(texture_format: wgt::TextureFormat) -> web_sys::GpuTexture TextureFormat::Bgra8UnormSrgb => tf::Bgra8unormSrgb, // Packed 32-bit formats TextureFormat::Rgb9e5Ufloat => tf::Rgb9e5ufloat, + TextureFormat::Rgb10a2Uint => { + unimplemented!("Current version of web_sys is missing {texture_format:?}") + } TextureFormat::Rgb10a2Unorm => tf::Rgb10a2unorm, TextureFormat::Rg11b10Float => tf::Rg11b10ufloat, // 64-bit formats