diff --git a/Cargo.lock b/Cargo.lock index 20637239f1..80bc29c0f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -991,7 +991,7 @@ dependencies = [ [[package]] name = "metal" version = "0.23.1" -source = "git+https://github.com/gfx-rs/metal-rs?rev=140c8f4#140c8f4e39001ae154f153ffc767da6c0c9d7f06" +source = "git+https://github.com/gfx-rs/metal-rs?rev=44af5cc#44af5cca340617d42d701264f9bf71d1f3e68096" dependencies = [ "bitflags", "block", diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index b5f464efe6..ad76f0523f 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -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) } @@ -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 { diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 7f21eef494..cd0dd8d453 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -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" diff --git a/wgpu-hal/src/dx12/conv.rs b/wgpu-hal/src/dx12/conv.rs index 45c648a6ab..8c1cdb9ab6 100644 --- a/wgpu-hal/src/dx12/conv.rs +++ b/wgpu-hal/src/dx12/conv.rs @@ -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!(), } } diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 87307ac27f..e6283f3502 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -1,5 +1,6 @@ use glow::HasContext; use std::sync::Arc; +use wgt::AstcChannel; // https://webgl2fundamentals.org/webgl/lessons/webgl-data-textures.html @@ -633,34 +634,18 @@ impl crate::Adapter 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!(), } } diff --git a/wgpu-hal/src/gles/conv.rs b/wgpu-hal/src/gles/conv.rs index daf637b5e4..45468c2452 100644 --- a/wgpu-hal/src/gles/conv.rs +++ b/wgpu-hal/src/gles/conv.rs @@ -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), @@ -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 { diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 7e4a0119b5..3a65589f53 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -1,6 +1,7 @@ use mtl::{MTLFeatureSet, MTLGPUFamily, MTLLanguageVersion}; use objc::{class, msg_send, sel, sel_impl}; use parking_lot::Mutex; +use wgt::{AstcBlock, AstcChannel}; use std::{sync::Arc, thread}; @@ -321,35 +322,11 @@ impl crate::Adapter for super::Adapter { Tfc::empty() } } - 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 => { - if pc.format_astc { + Tf::Astc { + block: _, + channel: _, + } => { + if pc.format_astc || pc.format_astc_hdr { Tfc::SAMPLED_LINEAR } else { Tfc::empty() @@ -722,8 +699,10 @@ impl super::PrivateCapabilities { // M1 in macOS supports EAC/ETC2 || (family_check && device.supports_family(MTLGPUFamily::Apple7)), format_astc: Self::supports_any(device, ASTC_PIXEL_FORMAT_FEATURES) - // A13/A14/M1 and later always support ASTC - || (family_check && device.supports_family(MTLGPUFamily::Apple6)), + // A8(Apple2) and later always support ASTC pixel formats + || (family_check && device.supports_family(MTLGPUFamily::Apple2)), + // A13(Apple6) M1(Apple7) and later always support HDR ASTC pixel formats + format_astc_hdr: family_check && device.supports_family(MTLGPUFamily::Apple6), format_any8_unorm_srgb_all: Self::supports_any(device, ANY8_UNORM_SRGB_ALL), format_any8_unorm_srgb_no_write: !Self::supports_any(device, ANY8_UNORM_SRGB_ALL) && !os_is_mac, @@ -1024,6 +1003,7 @@ impl super::PrivateCapabilities { | F::TEXTURE_FORMAT_16BIT_NORM; features.set(F::TEXTURE_COMPRESSION_ASTC_LDR, self.format_astc); + features.set(F::TEXTURE_COMPRESSION_ASTC_HDR, self.format_astc_hdr); features.set(F::TEXTURE_COMPRESSION_BC, self.format_bc); features.set(F::TEXTURE_COMPRESSION_ETC2, self.format_eac_etc); @@ -1118,7 +1098,6 @@ impl super::PrivateCapabilities { pub fn map_format(&self, format: wgt::TextureFormat) -> mtl::MTLPixelFormat { use mtl::MTLPixelFormat::*; use wgt::TextureFormat as Tf; - match format { Tf::R8Unorm => R8Unorm, Tf::R8Snorm => R8Snorm, @@ -1201,34 +1180,56 @@ impl super::PrivateCapabilities { Tf::EacR11Snorm => EAC_R11Snorm, Tf::EacRg11Unorm => EAC_RG11Unorm, Tf::EacRg11Snorm => EAC_RG11Snorm, - Tf::Astc4x4RgbaUnorm => ASTC_4x4_LDR, - Tf::Astc4x4RgbaUnormSrgb => ASTC_4x4_sRGB, - Tf::Astc5x4RgbaUnorm => ASTC_5x4_LDR, - Tf::Astc5x4RgbaUnormSrgb => ASTC_5x4_sRGB, - Tf::Astc5x5RgbaUnorm => ASTC_5x5_LDR, - Tf::Astc5x5RgbaUnormSrgb => ASTC_5x5_sRGB, - Tf::Astc6x5RgbaUnorm => ASTC_6x5_LDR, - Tf::Astc6x5RgbaUnormSrgb => ASTC_6x5_sRGB, - Tf::Astc6x6RgbaUnorm => ASTC_6x6_LDR, - Tf::Astc6x6RgbaUnormSrgb => ASTC_6x6_sRGB, - Tf::Astc8x5RgbaUnorm => ASTC_8x5_LDR, - Tf::Astc8x5RgbaUnormSrgb => ASTC_8x5_sRGB, - Tf::Astc8x6RgbaUnorm => ASTC_8x6_LDR, - Tf::Astc8x6RgbaUnormSrgb => ASTC_8x6_sRGB, - Tf::Astc10x5RgbaUnorm => ASTC_8x8_LDR, - Tf::Astc10x5RgbaUnormSrgb => ASTC_8x8_sRGB, - Tf::Astc10x6RgbaUnorm => ASTC_10x5_LDR, - Tf::Astc10x6RgbaUnormSrgb => ASTC_10x5_sRGB, - Tf::Astc8x8RgbaUnorm => ASTC_10x6_LDR, - Tf::Astc8x8RgbaUnormSrgb => ASTC_10x6_sRGB, - Tf::Astc10x8RgbaUnorm => ASTC_10x8_LDR, - Tf::Astc10x8RgbaUnormSrgb => ASTC_10x8_sRGB, - Tf::Astc10x10RgbaUnorm => ASTC_10x10_LDR, - Tf::Astc10x10RgbaUnormSrgb => ASTC_10x10_sRGB, - Tf::Astc12x10RgbaUnorm => ASTC_12x10_LDR, - Tf::Astc12x10RgbaUnormSrgb => ASTC_12x10_sRGB, - Tf::Astc12x12RgbaUnorm => ASTC_12x12_LDR, - Tf::Astc12x12RgbaUnormSrgb => ASTC_12x12_sRGB, + Tf::Astc { block, channel } => match channel { + AstcChannel::Unorm => match block { + AstcBlock::B4x4 => ASTC_4x4_LDR, + AstcBlock::B5x4 => ASTC_5x4_LDR, + AstcBlock::B5x5 => ASTC_5x5_LDR, + AstcBlock::B6x5 => ASTC_6x5_LDR, + AstcBlock::B6x6 => ASTC_6x6_LDR, + AstcBlock::B8x5 => ASTC_8x5_LDR, + AstcBlock::B8x6 => ASTC_8x6_LDR, + AstcBlock::B8x8 => ASTC_8x8_LDR, + AstcBlock::B10x5 => ASTC_10x5_LDR, + AstcBlock::B10x6 => ASTC_10x6_LDR, + AstcBlock::B10x8 => ASTC_10x8_LDR, + AstcBlock::B10x10 => ASTC_10x10_LDR, + AstcBlock::B12x10 => ASTC_12x10_LDR, + AstcBlock::B12x12 => ASTC_12x12_LDR, + }, + AstcChannel::UnormSrgb => match block { + AstcBlock::B4x4 => ASTC_4x4_sRGB, + AstcBlock::B5x4 => ASTC_5x4_sRGB, + AstcBlock::B5x5 => ASTC_5x5_sRGB, + AstcBlock::B6x5 => ASTC_6x5_sRGB, + AstcBlock::B6x6 => ASTC_6x6_sRGB, + AstcBlock::B8x5 => ASTC_8x5_sRGB, + AstcBlock::B8x6 => ASTC_8x6_sRGB, + AstcBlock::B8x8 => ASTC_8x8_sRGB, + AstcBlock::B10x5 => ASTC_10x5_sRGB, + AstcBlock::B10x6 => ASTC_10x6_sRGB, + AstcBlock::B10x8 => ASTC_10x8_sRGB, + AstcBlock::B10x10 => ASTC_10x10_sRGB, + AstcBlock::B12x10 => ASTC_12x10_sRGB, + AstcBlock::B12x12 => ASTC_12x12_sRGB, + }, + AstcChannel::Hdr => match block { + AstcBlock::B4x4 => ASTC_4x4_HDR, + AstcBlock::B5x4 => ASTC_5x4_HDR, + AstcBlock::B5x5 => ASTC_5x5_HDR, + AstcBlock::B6x5 => ASTC_6x5_HDR, + AstcBlock::B6x6 => ASTC_6x6_HDR, + AstcBlock::B8x5 => ASTC_8x5_HDR, + AstcBlock::B8x6 => ASTC_8x6_HDR, + AstcBlock::B8x8 => ASTC_8x8_HDR, + AstcBlock::B10x5 => ASTC_10x5_HDR, + AstcBlock::B10x6 => ASTC_10x6_HDR, + AstcBlock::B10x8 => ASTC_10x8_HDR, + AstcBlock::B10x10 => ASTC_10x10_HDR, + AstcBlock::B12x10 => ASTC_12x10_HDR, + AstcBlock::B12x12 => ASTC_12x12_HDR, + }, + }, } } } diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 7bf7977e3a..84c1e20929 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -166,6 +166,7 @@ struct PrivateCapabilities { format_bc: bool, format_eac_etc: bool, format_astc: bool, + format_astc_hdr: bool, format_any8_unorm_srgb_all: bool, format_any8_unorm_srgb_no_write: bool, format_any8_snorm_all: bool, diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index 67c0c58b3b..b4ba96b741 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -208,10 +208,18 @@ impl crate::Surface for super::Surface { render_layer.set_pixel_format(self.raw_swapchain_format); render_layer.set_framebuffer_only(framebuffer_only); render_layer.set_presents_with_transaction(self.present_with_transaction); + // opt-in to Metal EDR + // EDR potentially more power used in display and more bandwidth, memory footprint. + #[cfg(target_os = "macos")] + { + let wants_edr = self.raw_swapchain_format == mtl::MTLPixelFormat::RGBA16Float; + if wants_edr != render_layer.wants_extended_dynamic_range_content() { + render_layer.set_wants_extended_dynamic_range_content(wants_edr); + } + } // this gets ignored on iOS for certain OS/device combinations (iphone5s iOS 10.3) - let () = msg_send![*render_layer, setMaximumDrawableCount: config.swap_chain_size as u64]; - + render_layer.set_maximum_drawable_count(config.swap_chain_size as _); render_layer.set_drawable_size(drawable_size); if caps.can_set_next_drawable_timeout { let () = msg_send![*render_layer, setAllowsNextDrawableTimeout:false]; diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index 7ee0cd0e91..81e0435607 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -5,6 +5,7 @@ impl super::PrivateCapabilities { pub fn map_texture_format(&self, format: wgt::TextureFormat) -> vk::Format { use ash::vk::Format as F; use wgt::TextureFormat as Tf; + use wgt::{AstcBlock, AstcChannel}; match format { Tf::R8Unorm => F::R8_UNORM, Tf::R8Snorm => F::R8_SNORM, @@ -87,34 +88,41 @@ impl super::PrivateCapabilities { Tf::EacR11Snorm => F::EAC_R11_SNORM_BLOCK, Tf::EacRg11Unorm => F::EAC_R11G11_UNORM_BLOCK, Tf::EacRg11Snorm => F::EAC_R11G11_SNORM_BLOCK, - Tf::Astc4x4RgbaUnorm => F::ASTC_4X4_UNORM_BLOCK, - Tf::Astc4x4RgbaUnormSrgb => F::ASTC_4X4_SRGB_BLOCK, - Tf::Astc5x4RgbaUnorm => F::ASTC_5X4_UNORM_BLOCK, - Tf::Astc5x4RgbaUnormSrgb => F::ASTC_5X4_SRGB_BLOCK, - Tf::Astc5x5RgbaUnorm => F::ASTC_5X5_UNORM_BLOCK, - Tf::Astc5x5RgbaUnormSrgb => F::ASTC_5X5_SRGB_BLOCK, - Tf::Astc6x5RgbaUnorm => F::ASTC_6X5_UNORM_BLOCK, - Tf::Astc6x5RgbaUnormSrgb => F::ASTC_6X5_SRGB_BLOCK, - Tf::Astc6x6RgbaUnorm => F::ASTC_6X6_UNORM_BLOCK, - Tf::Astc6x6RgbaUnormSrgb => F::ASTC_6X6_SRGB_BLOCK, - Tf::Astc8x5RgbaUnorm => F::ASTC_8X5_UNORM_BLOCK, - Tf::Astc8x5RgbaUnormSrgb => F::ASTC_8X5_SRGB_BLOCK, - Tf::Astc8x6RgbaUnorm => F::ASTC_8X6_UNORM_BLOCK, - Tf::Astc8x6RgbaUnormSrgb => F::ASTC_8X6_SRGB_BLOCK, - Tf::Astc8x8RgbaUnorm => F::ASTC_8X8_UNORM_BLOCK, - Tf::Astc8x8RgbaUnormSrgb => F::ASTC_8X8_SRGB_BLOCK, - Tf::Astc10x5RgbaUnorm => F::ASTC_10X5_UNORM_BLOCK, - Tf::Astc10x5RgbaUnormSrgb => F::ASTC_10X5_SRGB_BLOCK, - Tf::Astc10x6RgbaUnorm => F::ASTC_10X6_UNORM_BLOCK, - Tf::Astc10x6RgbaUnormSrgb => F::ASTC_10X6_SRGB_BLOCK, - Tf::Astc10x8RgbaUnorm => F::ASTC_10X8_UNORM_BLOCK, - Tf::Astc10x8RgbaUnormSrgb => F::ASTC_10X8_SRGB_BLOCK, - Tf::Astc10x10RgbaUnorm => F::ASTC_10X10_UNORM_BLOCK, - Tf::Astc10x10RgbaUnormSrgb => F::ASTC_10X10_SRGB_BLOCK, - Tf::Astc12x10RgbaUnorm => F::ASTC_12X10_UNORM_BLOCK, - Tf::Astc12x10RgbaUnormSrgb => F::ASTC_12X10_SRGB_BLOCK, - Tf::Astc12x12RgbaUnorm => F::ASTC_12X12_UNORM_BLOCK, - Tf::Astc12x12RgbaUnormSrgb => F::ASTC_12X12_SRGB_BLOCK, + Tf::Astc { block, channel } => match channel { + AstcChannel::Unorm => match block { + AstcBlock::B4x4 => F::ASTC_4X4_UNORM_BLOCK, + AstcBlock::B5x4 => F::ASTC_5X4_UNORM_BLOCK, + AstcBlock::B5x5 => F::ASTC_5X5_UNORM_BLOCK, + AstcBlock::B6x5 => F::ASTC_6X5_UNORM_BLOCK, + AstcBlock::B6x6 => F::ASTC_6X6_UNORM_BLOCK, + AstcBlock::B8x5 => F::ASTC_8X5_UNORM_BLOCK, + AstcBlock::B8x6 => F::ASTC_8X6_UNORM_BLOCK, + AstcBlock::B8x8 => F::ASTC_8X8_UNORM_BLOCK, + AstcBlock::B10x5 => F::ASTC_10X5_UNORM_BLOCK, + AstcBlock::B10x6 => F::ASTC_10X6_UNORM_BLOCK, + AstcBlock::B10x8 => F::ASTC_10X8_UNORM_BLOCK, + AstcBlock::B10x10 => F::ASTC_10X10_UNORM_BLOCK, + AstcBlock::B12x10 => F::ASTC_12X10_UNORM_BLOCK, + AstcBlock::B12x12 => F::ASTC_12X12_UNORM_BLOCK, + }, + AstcChannel::UnormSrgb => match block { + AstcBlock::B4x4 => F::ASTC_4X4_SRGB_BLOCK, + AstcBlock::B5x4 => F::ASTC_5X4_SRGB_BLOCK, + AstcBlock::B5x5 => F::ASTC_5X5_SRGB_BLOCK, + AstcBlock::B6x5 => F::ASTC_6X5_SRGB_BLOCK, + AstcBlock::B6x6 => F::ASTC_6X6_SRGB_BLOCK, + AstcBlock::B8x5 => F::ASTC_8X5_SRGB_BLOCK, + AstcBlock::B8x6 => F::ASTC_8X6_SRGB_BLOCK, + AstcBlock::B8x8 => F::ASTC_8X8_SRGB_BLOCK, + AstcBlock::B10x5 => F::ASTC_10X5_SRGB_BLOCK, + AstcBlock::B10x6 => F::ASTC_10X6_SRGB_BLOCK, + AstcBlock::B10x8 => F::ASTC_10X8_SRGB_BLOCK, + AstcBlock::B10x10 => F::ASTC_10X10_SRGB_BLOCK, + AstcBlock::B12x10 => F::ASTC_12X10_SRGB_BLOCK, + AstcBlock::B12x12 => F::ASTC_12X12_SRGB_BLOCK, + }, + AstcChannel::Hdr => unimplemented!(), + }, } } } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 711309df4e..bf0f61cab4 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -564,6 +564,11 @@ bitflags::bitflags! { /// /// This is a native only feature. const ADDRESS_MODE_CLAMP_TO_ZERO = 1 << 42; + /// Supported Platforms: + /// - Metal + /// + /// This is a native-only feature. + const TEXTURE_COMPRESSION_ASTC_HDR = 1 << 43; } } @@ -1483,6 +1488,60 @@ impl TextureFormatInfo { } } +/// ASTC block dimensions +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +pub enum AstcBlock { + /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). + B4x4, + /// 5x4 block compressed texture. 16 bytes per block (6.4 bit/px). + B5x4, + /// 5x5 block compressed texture. 16 bytes per block (5.12 bit/px). + B5x5, + /// 6x5 block compressed texture. 16 bytes per block (4.27 bit/px). + B6x5, + /// 6x6 block compressed texture. 16 bytes per block (3.56 bit/px). + B6x6, + /// 8x5 block compressed texture. 16 bytes per block (3.2 bit/px). + B8x5, + /// 8x6 block compressed texture. 16 bytes per block (2.67 bit/px). + B8x6, + /// 8x8 block compressed texture. 16 bytes per block (2 bit/px). + B8x8, + /// 10x5 block compressed texture. 16 bytes per block (2.56 bit/px). + B10x5, + /// 10x6 block compressed texture. 16 bytes per block (2.13 bit/px). + B10x6, + /// 10x8 block compressed texture. 16 bytes per block (1.6 bit/px). + B10x8, + /// 10x10 block compressed texture. 16 bytes per block (1.28 bit/px). + B10x10, + /// 12x10 block compressed texture. 16 bytes per block (1.07 bit/px). + B12x10, + /// 12x12 block compressed texture. 16 bytes per block (0.89 bit/px). + B12x12, +} + +/// ASTC RGBA channel +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +pub enum AstcChannel { + /// 8 bit integer RGBA, [0, 255] converted to/from linear-color float [0, 1] in shader. + /// + /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this channel. + Unorm, + /// 8 bit integer RGBA, Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. + /// + /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this channel. + UnormSrgb, + /// floating-point RGBA, linear-color float can be outside of the [0, 1] range. + /// + /// [`Features::TEXTURE_COMPRESSION_ASTC_HDR`] must be enabled to use this channel. + Hdr, +} + /// Underlying texture data format. /// /// If there is a conversion in the format (such as srgb -> linear), The conversion listed is for @@ -1825,174 +1884,15 @@ pub enum TextureFormat { /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. #[cfg_attr(feature = "serde", serde(rename = "eac-rg11snorm"))] EacRg11Snorm, - /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-4x4-unorm"))] - Astc4x4RgbaUnorm, - /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-4x4-unorm-srgb"))] - Astc4x4RgbaUnormSrgb, - /// 5x4 block compressed texture. 16 bytes per block (6.4 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. + /// block compressed texture. 16 bytes per block. /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-5x4-unorm"))] - Astc5x4RgbaUnorm, - /// 5x4 block compressed texture. 16 bytes per block (6.4 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-5x4-unorm-srgb"))] - Astc5x4RgbaUnormSrgb, - /// 5x5 block compressed texture. 16 bytes per block (5.12 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-5x5-unorm"))] - Astc5x5RgbaUnorm, - /// 5x5 block compressed texture. 16 bytes per block (5.12 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-5x5-unorm-srgb"))] - Astc5x5RgbaUnormSrgb, - /// 6x5 block compressed texture. 16 bytes per block (4.27 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-6x5-unorm"))] - Astc6x5RgbaUnorm, - /// 6x5 block compressed texture. 16 bytes per block (4.27 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-6x5-unorm-srgb"))] - Astc6x5RgbaUnormSrgb, - /// 6x6 block compressed texture. 16 bytes per block (3.56 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-6x6-unorm"))] - Astc6x6RgbaUnorm, - /// 6x6 block compressed texture. 16 bytes per block (3.56 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-6x6-unorm-srgb"))] - Astc6x6RgbaUnormSrgb, - /// 8x5 block compressed texture. 16 bytes per block (3.2 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-8x5-unorm"))] - Astc8x5RgbaUnorm, - /// 8x5 block compressed texture. 16 bytes per block (3.2 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-8x5-unorm-srgb"))] - Astc8x5RgbaUnormSrgb, - /// 8x6 block compressed texture. 16 bytes per block (2.67 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-8x6-unorm"))] - Astc8x6RgbaUnorm, - /// 8x6 block compressed texture. 16 bytes per block (2.67 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-8x6-unorm-srgb"))] - Astc8x6RgbaUnormSrgb, - /// 8x8 block compressed texture. 16 bytes per block (2 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-8x8-unorm"))] - Astc8x8RgbaUnorm, - /// 8x8 block compressed texture. 16 bytes per block (2 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-8x8-unorm-srgb"))] - Astc8x8RgbaUnormSrgb, - /// 10x5 block compressed texture. 16 bytes per block (2.56 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-10x5-unorm"))] - Astc10x5RgbaUnorm, - /// 10x5 block compressed texture. 16 bytes per block (2.56 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-10x5-unorm-srgb"))] - Astc10x5RgbaUnormSrgb, - /// 10x6 block compressed texture. 16 bytes per block (2.13 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-10x6-unorm"))] - Astc10x6RgbaUnorm, - /// 10x6 block compressed texture. 16 bytes per block (2.13 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-10x6-unorm-srgb"))] - Astc10x6RgbaUnormSrgb, - /// 10x8 block compressed texture. 16 bytes per block (1.6 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-10x8-unorm"))] - Astc10x8RgbaUnorm, - /// 10x8 block compressed texture. 16 bytes per block (1.6 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-10x8-unorm-srgb"))] - Astc10x8RgbaUnormSrgb, - /// 10x10 block compressed texture. 16 bytes per block (1.28 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-10x10-unorm"))] - Astc10x10RgbaUnorm, - /// 10x10 block compressed texture. 16 bytes per block (1.28 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-10x10-unorm-srgb"))] - Astc10x10RgbaUnormSrgb, - /// 12x10 block compressed texture. 16 bytes per block (1.07 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-12x10-unorm"))] - Astc12x10RgbaUnorm, - /// 12x10 block compressed texture. 16 bytes per block (1.07 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-12x10-unorm-srgb"))] - Astc12x10RgbaUnormSrgb, - /// 12x12 block compressed texture. 16 bytes per block (0.89 bit/px). Complex pallet. 8 bit integer RGBA. - /// [0, 255] converted to/from float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-12x12-unorm"))] - Astc12x12RgbaUnorm, - /// 12x12 block compressed texture. 16 bytes per block (0.89 bit/px). Complex pallet. 8 bit integer RGBA. - /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - /// - /// [`Features::TEXTURE_COMPRESSION_ASTC_LDR`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "astc-12x12-unorm-srgb"))] - Astc12x12RgbaUnormSrgb, + /// Features [`TEXTURE_COMPRESSION_ASTC_LDR`] or [`TEXTURE_COMPRESSION_ASTC_HDR`] must be enabled to use this texture format. + Astc { + /// compressed block dimensions + block: AstcBlock, + /// + channel: AstcChannel, + }, } impl TextureFormat { @@ -2003,6 +1903,7 @@ impl TextureFormat { let bc = Features::TEXTURE_COMPRESSION_BC; let etc2 = Features::TEXTURE_COMPRESSION_ETC2; let astc_ldr = Features::TEXTURE_COMPRESSION_ASTC_LDR; + let astc_hdr = Features::TEXTURE_COMPRESSION_ASTC_HDR; let norm16bit = Features::TEXTURE_FORMAT_16BIT_NORM; // Sample Types @@ -2199,45 +2100,29 @@ impl TextureFormat { Self::EacRg11Snorm => (etc2, float, linear, noaa, (4, 4), 16, basic, 2), // ASTC compressed textures - Self::Astc4x4RgbaUnorm => (astc_ldr, float, linear, noaa, (4, 4), 16, basic, 4), - Self::Astc4x4RgbaUnormSrgb => (astc_ldr, float, corrected, noaa, (4, 4), 16, basic, 4), - Self::Astc5x4RgbaUnorm => (astc_ldr, float, linear, noaa, (5, 4), 16, basic, 4), - Self::Astc5x4RgbaUnormSrgb => (astc_ldr, float, corrected, noaa, (5, 4), 16, basic, 4), - Self::Astc5x5RgbaUnorm => (astc_ldr, float, linear, noaa, (5, 5), 16, basic, 4), - Self::Astc5x5RgbaUnormSrgb => (astc_ldr, float, corrected, noaa, (5, 5), 16, basic, 4), - Self::Astc6x5RgbaUnorm => (astc_ldr, float, linear, noaa, (6, 5), 16, basic, 4), - Self::Astc6x5RgbaUnormSrgb => (astc_ldr, float, corrected, noaa, (6, 5), 16, basic, 4), - Self::Astc6x6RgbaUnorm => (astc_ldr, float, linear, noaa, (6, 6), 16, basic, 4), - Self::Astc6x6RgbaUnormSrgb => (astc_ldr, float, corrected, noaa, (6, 6), 16, basic, 4), - Self::Astc8x5RgbaUnorm => (astc_ldr, float, linear, noaa, (8, 5), 16, basic, 4), - Self::Astc8x5RgbaUnormSrgb => (astc_ldr, float, corrected, noaa, (8, 5), 16, basic, 4), - Self::Astc8x6RgbaUnorm => (astc_ldr, float, linear, noaa, (8, 6), 16, basic, 4), - Self::Astc8x6RgbaUnormSrgb => (astc_ldr, float, corrected, noaa, (8, 6), 16, basic, 4), - Self::Astc10x5RgbaUnorm => (astc_ldr, float, linear, noaa, (10, 5), 16, basic, 4), - Self::Astc10x5RgbaUnormSrgb => { - (astc_ldr, float, corrected, noaa, (10, 5), 16, basic, 4) - } - Self::Astc10x6RgbaUnorm => (astc_ldr, float, linear, noaa, (10, 6), 16, basic, 4), - Self::Astc10x6RgbaUnormSrgb => { - (astc_ldr, float, corrected, noaa, (10, 6), 16, basic, 4) - } - Self::Astc8x8RgbaUnorm => (astc_ldr, float, linear, noaa, (8, 8), 16, basic, 4), - Self::Astc8x8RgbaUnormSrgb => (astc_ldr, float, corrected, noaa, (8, 8), 16, basic, 4), - Self::Astc10x8RgbaUnorm => (astc_ldr, float, linear, noaa, (10, 8), 16, basic, 4), - Self::Astc10x8RgbaUnormSrgb => { - (astc_ldr, float, corrected, noaa, (10, 8), 16, basic, 4) - } - Self::Astc10x10RgbaUnorm => (astc_ldr, float, linear, noaa, (10, 10), 16, basic, 4), - Self::Astc10x10RgbaUnormSrgb => { - (astc_ldr, float, corrected, noaa, (10, 10), 16, basic, 4) - } - Self::Astc12x10RgbaUnorm => (astc_ldr, float, linear, noaa, (12, 10), 16, basic, 4), - Self::Astc12x10RgbaUnormSrgb => { - (astc_ldr, float, corrected, noaa, (12, 10), 16, basic, 4) - } - Self::Astc12x12RgbaUnorm => (astc_ldr, float, linear, noaa, (12, 12), 16, basic, 4), - Self::Astc12x12RgbaUnormSrgb => { - (astc_ldr, float, corrected, noaa, (12, 12), 16, basic, 4) + Self::Astc { block, channel } => { + let (feature, color_space) = match channel { + AstcChannel::Hdr => (astc_hdr, linear), + AstcChannel::Unorm => (astc_ldr, linear), + AstcChannel::UnormSrgb => (astc_ldr, corrected), + }; + let dimensions = match block { + AstcBlock::B4x4 => (4, 4), + AstcBlock::B5x4 => (5, 4), + AstcBlock::B5x5 => (5, 5), + AstcBlock::B6x5 => (6, 5), + AstcBlock::B6x6 => (6, 6), + AstcBlock::B8x5 => (8, 5), + AstcBlock::B8x6 => (8, 6), + AstcBlock::B8x8 => (8, 8), + AstcBlock::B10x5 => (10, 5), + AstcBlock::B10x6 => (10, 6), + AstcBlock::B10x8 => (10, 8), + AstcBlock::B10x10 => (10, 10), + AstcBlock::B12x10 => (12, 10), + AstcBlock::B12x12 => (12, 12), + }; + (feature, float, color_space, noaa, dimensions, 16, basic, 4) } // Optional normalized 16-bit-per-channel formats @@ -3056,7 +2941,10 @@ fn test_physical_size() { depth_or_array_layers: 1 } ); - let format = TextureFormat::Astc8x5RgbaUnorm; // 8x5 blocks + let format = TextureFormat::Astc { + block: AstcBlock::B8x5, + channel: AstcChannel::Unorm, + }; // 8x5 blocks assert_eq!( Extent3d { width: 7, diff --git a/wgpu/examples/skybox/main.rs b/wgpu/examples/skybox/main.rs index d569d9d1ff..fa3c7d8653 100644 --- a/wgpu/examples/skybox/main.rs +++ b/wgpu/examples/skybox/main.rs @@ -4,7 +4,7 @@ mod framework; use bytemuck::{Pod, Zeroable}; use cgmath::SquareMatrix; use std::borrow::Cow; -use wgpu::util::DeviceExt; +use wgpu::{util::DeviceExt, AstcBlock, AstcChannel}; const IMAGE_SIZE: u32 = 128; @@ -273,7 +273,10 @@ impl framework::Example for Skybox { let skybox_format = if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC_LDR) { log::info!("Using ASTC_LDR"); - wgpu::TextureFormat::Astc4x4RgbaUnormSrgb + wgpu::TextureFormat::Astc { + block: AstcBlock::B4x4, + channel: AstcChannel::UnormSrgb, + } } else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2) { log::info!("Using ETC2"); wgpu::TextureFormat::Etc2Rgb8UnormSrgb @@ -306,7 +309,10 @@ impl framework::Example for Skybox { ); let bytes = match skybox_format { - wgpu::TextureFormat::Astc4x4RgbaUnormSrgb => &include_bytes!("images/astc.dds")[..], + wgpu::TextureFormat::Astc { + block: AstcBlock::B4x4, + channel: AstcChannel::UnormSrgb, + } => &include_bytes!("images/astc.dds")[..], wgpu::TextureFormat::Etc2Rgb8UnormSrgb => &include_bytes!("images/etc2.dds")[..], wgpu::TextureFormat::Bc1RgbaUnormSrgb => &include_bytes!("images/bc1.dds")[..], wgpu::TextureFormat::Bgra8UnormSrgb => &include_bytes!("images/bgra.dds")[..], diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index ff23b63024..3ea9c3271e 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -25,13 +25,13 @@ use std::{ use parking_lot::Mutex; pub use wgt::{ - AdapterInfo, AddressMode, Backend, Backends, BindGroupLayoutEntry, BindingType, BlendComponent, - BlendFactor, BlendOperation, BlendState, BufferAddress, BufferBindingType, BufferSize, - BufferUsages, Color, ColorTargetState, ColorWrites, CommandBufferDescriptor, CompareFunction, - DepthBiasState, DepthStencilState, DeviceType, DownlevelCapabilities, DownlevelFlags, - DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, ImageDataLayout, - ImageSubresourceRange, IndexFormat, Limits, MultisampleState, Origin3d, - PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, PrimitiveState, + AdapterInfo, AddressMode, AstcBlock, AstcChannel, Backend, Backends, BindGroupLayoutEntry, + BindingType, BlendComponent, BlendFactor, BlendOperation, BlendState, BufferAddress, + BufferBindingType, BufferSize, BufferUsages, Color, ColorTargetState, ColorWrites, + CommandBufferDescriptor, CompareFunction, DepthBiasState, DepthStencilState, DeviceType, + DownlevelCapabilities, DownlevelFlags, DynamicOffset, Extent3d, Face, Features, FilterMode, + FrontFace, ImageDataLayout, ImageSubresourceRange, IndexFormat, Limits, MultisampleState, + Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, PrimitiveState, PrimitiveTopology, PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType, SamplerBorderColor, ShaderLocation, ShaderModel, ShaderStages, StencilFaceState, StencilOperation, StencilState, StorageTextureAccess, SurfaceConfiguration, SurfaceStatus, diff --git a/wgpu/tests/clear_texture.rs b/wgpu/tests/clear_texture.rs index 8794c2d85d..0a2c9dd152 100644 --- a/wgpu/tests/clear_texture.rs +++ b/wgpu/tests/clear_texture.rs @@ -78,35 +78,120 @@ static TEXTURE_FORMATS_ETC2: &[wgpu::TextureFormat] = &[ ]; // needs TEXTURE_COMPRESSION_ASTC_LDR +use wgpu::{AstcBlock, AstcChannel}; static TEXTURE_FORMATS_ASTC: &[wgpu::TextureFormat] = &[ - wgpu::TextureFormat::Astc4x4RgbaUnorm, - wgpu::TextureFormat::Astc4x4RgbaUnormSrgb, - wgpu::TextureFormat::Astc5x4RgbaUnorm, - wgpu::TextureFormat::Astc5x4RgbaUnormSrgb, - wgpu::TextureFormat::Astc5x5RgbaUnorm, - wgpu::TextureFormat::Astc5x5RgbaUnormSrgb, - wgpu::TextureFormat::Astc6x5RgbaUnorm, - wgpu::TextureFormat::Astc6x5RgbaUnormSrgb, - wgpu::TextureFormat::Astc6x6RgbaUnorm, - wgpu::TextureFormat::Astc6x6RgbaUnormSrgb, - wgpu::TextureFormat::Astc8x5RgbaUnorm, - wgpu::TextureFormat::Astc8x5RgbaUnormSrgb, - wgpu::TextureFormat::Astc8x6RgbaUnorm, - wgpu::TextureFormat::Astc8x6RgbaUnormSrgb, - wgpu::TextureFormat::Astc10x5RgbaUnorm, - wgpu::TextureFormat::Astc10x5RgbaUnormSrgb, - wgpu::TextureFormat::Astc10x6RgbaUnorm, - wgpu::TextureFormat::Astc10x6RgbaUnormSrgb, - wgpu::TextureFormat::Astc8x8RgbaUnorm, - wgpu::TextureFormat::Astc8x8RgbaUnormSrgb, - wgpu::TextureFormat::Astc10x8RgbaUnorm, - wgpu::TextureFormat::Astc10x8RgbaUnormSrgb, - wgpu::TextureFormat::Astc10x10RgbaUnorm, - wgpu::TextureFormat::Astc10x10RgbaUnormSrgb, - wgpu::TextureFormat::Astc12x10RgbaUnorm, - wgpu::TextureFormat::Astc12x10RgbaUnormSrgb, - wgpu::TextureFormat::Astc12x12RgbaUnorm, - wgpu::TextureFormat::Astc12x12RgbaUnormSrgb, + wgpu::TextureFormat::Astc { + block: AstcBlock::B4x4, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B5x4, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B5x5, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B6x5, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B6x6, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B8x5, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B8x6, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B8x8, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B10x5, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B10x6, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B10x8, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B10x10, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B12x10, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B12x12, + channel: AstcChannel::Unorm, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B4x4, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B5x4, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B5x5, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B6x5, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B6x6, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B8x5, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B8x6, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B8x8, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B10x5, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B10x6, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B10x8, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B10x10, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B12x10, + channel: AstcChannel::UnormSrgb, + }, + wgpu::TextureFormat::Astc { + block: AstcBlock::B12x12, + channel: AstcChannel::UnormSrgb, + }, ]; fn single_texture_clear_test(