Skip to content

Commit

Permalink
Add Rgb10a2Uint format
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Oct 3, 2023
1 parent 6df7e2d commit 7e4a115
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions tests/tests/clear_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
4 changes: 3 additions & 1 deletion wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ fn map_storage_format_to_naga(format: wgt::TextureFormat) -> Option<naga::Storag
Tf::Rgba8Uint => Sf::Rgba8Uint,
Tf::Rgba8Sint => Sf::Rgba8Sint,

Tf::Rgb10a2Uint => Sf::Rgb10a2Uint,
Tf::Rgb10a2Unorm => Sf::Rgb10a2Unorm,
Tf::Rg11b10Float => Sf::Rg11b10Float,

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/auxil/dxgi/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option<dxgifor
Tf::Rgba8Uint => 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,
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ impl crate::Adapter<super::Api> 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,
Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/gles/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ impl crate::Adapter<super::Api> 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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/vulkan/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion wgpu-info/src/texture.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 21 additions & 3 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -2724,6 +2728,7 @@ impl TextureFormat {
| Self::Bgra8Unorm
| Self::Bgra8UnormSrgb
| Self::Rgb9e5Ufloat
| Self::Rgb10a2Uint
| Self::Rgb10a2Unorm
| Self::Rg11b10Float
| Self::Rg32Uint
Expand Down Expand Up @@ -2822,6 +2827,7 @@ impl TextureFormat {
| Self::Bgra8Unorm
| Self::Bgra8UnormSrgb
| Self::Rgb9e5Ufloat
| Self::Rgb10a2Uint
| Self::Rgb10a2Unorm
| Self::Rg11b10Float
| Self::Rg32Uint
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -3723,6 +3737,10 @@ fn texture_format_deserialize() {
serde_json::from_str::<TextureFormat>("\"bgra8unorm-srgb\"").unwrap(),
TextureFormat::Bgra8UnormSrgb
);
assert_eq!(
serde_json::from_str::<TextureFormat>("\"rgb10a2uint\"").unwrap(),
TextureFormat::Rgb10a2Uint
);
assert_eq!(
serde_json::from_str::<TextureFormat>("\"rgb10a2unorm\"").unwrap(),
TextureFormat::Rgb10a2Unorm
Expand Down
3 changes: 3 additions & 0 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e4a115

Please sign in to comment.