Skip to content

Commit

Permalink
Metal backend ASTC HDR formats support (#2477)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili authored Feb 15, 2022
1 parent 8b66507 commit 1c17d15
Show file tree
Hide file tree
Showing 14 changed files with 405 additions and 463 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.

34 changes: 5 additions & 29 deletions wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,35 +717,7 @@ impl NumericType {
| Tf::Etc2Rgb8A1Unorm
| Tf::Etc2Rgb8A1UnormSrgb
| Tf::Etc2Rgba8Unorm
| Tf::Etc2Rgba8UnormSrgb
| Tf::Astc4x4RgbaUnorm
| Tf::Astc4x4RgbaUnormSrgb
| Tf::Astc5x4RgbaUnorm
| Tf::Astc5x4RgbaUnormSrgb
| Tf::Astc5x5RgbaUnorm
| Tf::Astc5x5RgbaUnormSrgb
| Tf::Astc6x5RgbaUnorm
| Tf::Astc6x5RgbaUnormSrgb
| Tf::Astc6x6RgbaUnorm
| Tf::Astc6x6RgbaUnormSrgb
| Tf::Astc8x5RgbaUnorm
| Tf::Astc8x5RgbaUnormSrgb
| Tf::Astc8x6RgbaUnorm
| Tf::Astc8x6RgbaUnormSrgb
| Tf::Astc10x5RgbaUnorm
| Tf::Astc10x5RgbaUnormSrgb
| Tf::Astc10x6RgbaUnorm
| Tf::Astc10x6RgbaUnormSrgb
| Tf::Astc8x8RgbaUnorm
| Tf::Astc8x8RgbaUnormSrgb
| Tf::Astc10x8RgbaUnorm
| Tf::Astc10x8RgbaUnormSrgb
| Tf::Astc10x10RgbaUnorm
| Tf::Astc10x10RgbaUnormSrgb
| Tf::Astc12x10RgbaUnorm
| Tf::Astc12x10RgbaUnormSrgb
| Tf::Astc12x12RgbaUnorm
| Tf::Astc12x12RgbaUnormSrgb => (NumericDimension::Vector(Vs::Quad), Sk::Float),
| Tf::Etc2Rgba8UnormSrgb => (NumericDimension::Vector(Vs::Quad), Sk::Float),
Tf::Bc4RUnorm | Tf::Bc4RSnorm | Tf::EacR11Unorm | Tf::EacR11Snorm => {
(NumericDimension::Scalar, Sk::Float)
}
Expand All @@ -755,6 +727,10 @@ impl NumericType {
Tf::Bc6hRgbUfloat | Tf::Bc6hRgbSfloat | Tf::Etc2Rgb8Unorm | Tf::Etc2Rgb8UnormSrgb => {
(NumericDimension::Vector(Vs::Tri), Sk::Float)
}
Tf::Astc {
block: _,
channel: _,
} => (NumericDimension::Vector(Vs::Quad), Sk::Float),
};

NumericType {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ winapi = { version = "0.3", features = ["libloaderapi", "windef", "winuser", "dc
native = { package = "d3d12", version = "0.4.1", features = ["libloading"], optional = true }

[target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies]
mtl = { package = "metal", git = "https://github.com/gfx-rs/metal-rs", rev = "140c8f4" }
mtl = { package = "metal", git = "https://github.com/gfx-rs/metal-rs", rev = "44af5cc" }
objc = "0.2.5"
core-graphics-types = "0.1"

Expand Down
34 changes: 5 additions & 29 deletions wgpu-hal/src/dx12/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,11 @@ pub(super) fn map_texture_format(format: wgt::TextureFormat) -> dxgiformat::DXGI
| Tf::EacR11Unorm
| Tf::EacR11Snorm
| Tf::EacRg11Unorm
| Tf::EacRg11Snorm
| Tf::Astc4x4RgbaUnorm
| Tf::Astc4x4RgbaUnormSrgb
| Tf::Astc5x4RgbaUnorm
| Tf::Astc5x4RgbaUnormSrgb
| Tf::Astc5x5RgbaUnorm
| Tf::Astc5x5RgbaUnormSrgb
| Tf::Astc6x5RgbaUnorm
| Tf::Astc6x5RgbaUnormSrgb
| Tf::Astc6x6RgbaUnorm
| Tf::Astc6x6RgbaUnormSrgb
| Tf::Astc8x5RgbaUnorm
| Tf::Astc8x5RgbaUnormSrgb
| Tf::Astc8x6RgbaUnorm
| Tf::Astc8x6RgbaUnormSrgb
| Tf::Astc10x5RgbaUnorm
| Tf::Astc10x5RgbaUnormSrgb
| Tf::Astc10x6RgbaUnorm
| Tf::Astc10x6RgbaUnormSrgb
| Tf::Astc8x8RgbaUnorm
| Tf::Astc8x8RgbaUnormSrgb
| Tf::Astc10x8RgbaUnorm
| Tf::Astc10x8RgbaUnormSrgb
| Tf::Astc10x10RgbaUnorm
| Tf::Astc10x10RgbaUnormSrgb
| Tf::Astc12x10RgbaUnorm
| Tf::Astc12x10RgbaUnormSrgb
| Tf::Astc12x12RgbaUnorm
| Tf::Astc12x12RgbaUnormSrgb => unreachable!(),
| Tf::EacRg11Snorm => unreachable!(),
Tf::Astc {
block: _,
channel: _,
} => unreachable!(),
}
}

Expand Down
41 changes: 13 additions & 28 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use glow::HasContext;
use std::sync::Arc;
use wgt::AstcChannel;

// https://webgl2fundamentals.org/webgl/lessons/webgl-data-textures.html

Expand Down Expand Up @@ -633,34 +634,18 @@ impl crate::Adapter<super::Api> for super::Adapter {
| Tf::EacR11Snorm
| Tf::EacRg11Unorm
| Tf::EacRg11Snorm
| Tf::Astc4x4RgbaUnorm
| Tf::Astc4x4RgbaUnormSrgb
| Tf::Astc5x4RgbaUnorm
| Tf::Astc5x4RgbaUnormSrgb
| Tf::Astc5x5RgbaUnorm
| Tf::Astc5x5RgbaUnormSrgb
| Tf::Astc6x5RgbaUnorm
| Tf::Astc6x5RgbaUnormSrgb
| Tf::Astc6x6RgbaUnorm
| Tf::Astc6x6RgbaUnormSrgb
| Tf::Astc8x5RgbaUnorm
| Tf::Astc8x5RgbaUnormSrgb
| Tf::Astc8x6RgbaUnorm
| Tf::Astc8x6RgbaUnormSrgb
| Tf::Astc10x5RgbaUnorm
| Tf::Astc10x5RgbaUnormSrgb
| Tf::Astc10x6RgbaUnorm
| Tf::Astc10x6RgbaUnormSrgb
| Tf::Astc8x8RgbaUnorm
| Tf::Astc8x8RgbaUnormSrgb
| Tf::Astc10x8RgbaUnorm
| Tf::Astc10x8RgbaUnormSrgb
| Tf::Astc10x10RgbaUnorm
| Tf::Astc10x10RgbaUnormSrgb
| Tf::Astc12x10RgbaUnorm
| Tf::Astc12x10RgbaUnormSrgb
| Tf::Astc12x12RgbaUnorm
| Tf::Astc12x12RgbaUnormSrgb => Tfc::SAMPLED | Tfc::SAMPLED_LINEAR,
| Tf::Astc {
block: _,
channel: AstcChannel::Unorm,
}
| Tf::Astc {
block: _,
channel: AstcChannel::UnormSrgb,
} => Tfc::SAMPLED | Tfc::SAMPLED_LINEAR,
Tf::Astc {
block: _,
channel: AstcChannel::Hdr,
} => unimplemented!(),
}
}

Expand Down
88 changes: 48 additions & 40 deletions wgpu-hal/src/gles/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ impl super::AdapterShared {
texture_format: wgt::TextureFormat,
) -> super::TextureFormatDesc {
use wgt::TextureFormat as Tf;
use wgt::{AstcBlock, AstcChannel};

let (internal, external, data_type) = match texture_format {
Tf::R8Unorm => (glow::R8, glow::RED, glow::UNSIGNED_BYTE),
Expand Down Expand Up @@ -104,46 +105,53 @@ impl super::AdapterShared {
Tf::EacR11Snorm => (glow::COMPRESSED_SIGNED_R11_EAC, glow::RED, 0),
Tf::EacRg11Unorm => (glow::COMPRESSED_RG11_EAC, glow::RG, 0),
Tf::EacRg11Snorm => (glow::COMPRESSED_SIGNED_RG11_EAC, glow::RG, 0),
Tf::Astc4x4RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_4x4_KHR, glow::RGBA, 0),
Tf::Astc4x4RgbaUnormSrgb => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, glow::RGBA, 0),
Tf::Astc5x4RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_5x4_KHR, glow::RGBA, 0),
Tf::Astc5x4RgbaUnormSrgb => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, glow::RGBA, 0),
Tf::Astc5x5RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_5x5_KHR, glow::RGBA, 0),
Tf::Astc5x5RgbaUnormSrgb => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, glow::RGBA, 0),
Tf::Astc6x5RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_6x5_KHR, glow::RGBA, 0),
Tf::Astc6x5RgbaUnormSrgb => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, glow::RGBA, 0),
Tf::Astc6x6RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_6x6_KHR, glow::RGBA, 0),
Tf::Astc6x6RgbaUnormSrgb => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, glow::RGBA, 0),
Tf::Astc8x5RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_8x5_KHR, glow::RGBA, 0),
Tf::Astc8x5RgbaUnormSrgb => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, glow::RGBA, 0),
Tf::Astc8x6RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_8x6_KHR, glow::RGBA, 0),
Tf::Astc8x6RgbaUnormSrgb => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, glow::RGBA, 0),
Tf::Astc8x8RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_8x8_KHR, glow::RGBA, 0),
Tf::Astc8x8RgbaUnormSrgb => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, glow::RGBA, 0),
Tf::Astc10x5RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_10x5_KHR, glow::RGBA, 0),
Tf::Astc10x5RgbaUnormSrgb => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, glow::RGBA, 0)
}
Tf::Astc10x6RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_10x6_KHR, glow::RGBA, 0),
Tf::Astc10x6RgbaUnormSrgb => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, glow::RGBA, 0)
}
Tf::Astc10x8RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_10x8_KHR, glow::RGBA, 0),
Tf::Astc10x8RgbaUnormSrgb => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, glow::RGBA, 0)
}
Tf::Astc10x10RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_10x10_KHR, glow::RGBA, 0),
Tf::Astc10x10RgbaUnormSrgb => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, glow::RGBA, 0)
}
Tf::Astc12x10RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_12x10_KHR, glow::RGBA, 0),
Tf::Astc12x10RgbaUnormSrgb => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, glow::RGBA, 0)
}
Tf::Astc12x12RgbaUnorm => (glow::COMPRESSED_RGBA_ASTC_12x12_KHR, glow::RGBA, 0),
Tf::Astc12x12RgbaUnormSrgb => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, glow::RGBA, 0)
}
Tf::Astc { block, channel } => match channel {
AstcChannel::Unorm => match block {
AstcBlock::B4x4 => (glow::COMPRESSED_RGBA_ASTC_4x4_KHR, glow::RGBA, 0),
AstcBlock::B5x4 => (glow::COMPRESSED_RGBA_ASTC_5x4_KHR, glow::RGBA, 0),
AstcBlock::B5x5 => (glow::COMPRESSED_RGBA_ASTC_5x5_KHR, glow::RGBA, 0),
AstcBlock::B6x5 => (glow::COMPRESSED_RGBA_ASTC_6x5_KHR, glow::RGBA, 0),
AstcBlock::B6x6 => (glow::COMPRESSED_RGBA_ASTC_6x6_KHR, glow::RGBA, 0),
AstcBlock::B8x5 => (glow::COMPRESSED_RGBA_ASTC_8x5_KHR, glow::RGBA, 0),
AstcBlock::B8x6 => (glow::COMPRESSED_RGBA_ASTC_8x6_KHR, glow::RGBA, 0),
AstcBlock::B8x8 => (glow::COMPRESSED_RGBA_ASTC_8x8_KHR, glow::RGBA, 0),
AstcBlock::B10x5 => (glow::COMPRESSED_RGBA_ASTC_10x5_KHR, glow::RGBA, 0),
AstcBlock::B10x6 => (glow::COMPRESSED_RGBA_ASTC_10x6_KHR, glow::RGBA, 0),
AstcBlock::B10x8 => (glow::COMPRESSED_RGBA_ASTC_10x8_KHR, glow::RGBA, 0),
AstcBlock::B10x10 => (glow::COMPRESSED_RGBA_ASTC_10x10_KHR, glow::RGBA, 0),
AstcBlock::B12x10 => (glow::COMPRESSED_RGBA_ASTC_12x10_KHR, glow::RGBA, 0),
AstcBlock::B12x12 => (glow::COMPRESSED_RGBA_ASTC_12x12_KHR, glow::RGBA, 0),
},
AstcChannel::UnormSrgb => match block {
AstcBlock::B4x4 => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, glow::RGBA, 0),
AstcBlock::B5x4 => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, glow::RGBA, 0),
AstcBlock::B5x5 => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, glow::RGBA, 0),
AstcBlock::B6x5 => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, glow::RGBA, 0),
AstcBlock::B6x6 => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, glow::RGBA, 0),
AstcBlock::B8x5 => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, glow::RGBA, 0),
AstcBlock::B8x6 => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, glow::RGBA, 0),
AstcBlock::B8x8 => (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, glow::RGBA, 0),
AstcBlock::B10x5 => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, glow::RGBA, 0)
}
AstcBlock::B10x6 => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, glow::RGBA, 0)
}
AstcBlock::B10x8 => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, glow::RGBA, 0)
}
AstcBlock::B10x10 => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, glow::RGBA, 0)
}
AstcBlock::B12x10 => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, glow::RGBA, 0)
}
AstcBlock::B12x12 => {
(glow::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, glow::RGBA, 0)
}
},
AstcChannel::Hdr => unimplemented!(),
},
};

super::TextureFormatDesc {
Expand Down
Loading

0 comments on commit 1c17d15

Please sign in to comment.