From 4992de59385e9b26b4fc148ec0395ad9377bd390 Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Thu, 6 Oct 2022 05:08:45 +0800 Subject: [PATCH] gl: `ASTC_HDR` feature detection (#3042) --- CHANGELOG.md | 3 +++ wgpu-hal/src/gles/adapter.rs | 24 ++++++++++++++++++------ wgpu-hal/src/gles/conv.rs | 3 +-- wgpu-types/src/lib.rs | 1 + 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcf84b957a..5a15b564b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -130,6 +130,9 @@ SurfaceConfiguration { - Use the use effective api version for determining device features instead of wrongly assuming `VkPhysicalDeviceProperties.apiVersion` is the actual version of the device. By @i509VCB in [#3011](https://github.com/gfx-rs/wgpu/pull/3011) +#### GLES +- `TEXTURE_COMPRESSION_ASTC_HDR` feature detection by @jinleili in [#3042](https://github.com/gfx-rs/wgpu/pull/3042) + ### Performance - Made `StagingBelt::write_buffer()` check more thoroughly for reusable memory; by @kpreid in [#2906](https://github.com/gfx-rs/wgpu/pull/2906) diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 92aaf1bb13..0a513e96ee 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -355,11 +355,22 @@ impl super::Adapter { // This is a part of GLES-3 but not WebGL2 core !cfg!(target_arch = "wasm32") || extensions.contains("WEBGL_compressed_texture_etc"), ); - features.set( - wgt::Features::TEXTURE_COMPRESSION_ASTC_LDR, - extensions.contains("GL_KHR_texture_compression_astc_ldr") - || extensions.contains("WEBGL_compressed_texture_astc"), - ); + // `OES_texture_compression_astc` provides 2D + 3D, LDR + HDR support + if extensions.contains("WEBGL_compressed_texture_astc") + || extensions.contains("GL_OES_texture_compression_astc") + { + features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC_LDR); + features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC_HDR); + } else { + features.set( + wgt::Features::TEXTURE_COMPRESSION_ASTC_LDR, + extensions.contains("GL_KHR_texture_compression_astc_ldr"), + ); + features.set( + wgt::Features::TEXTURE_COMPRESSION_ASTC_HDR, + extensions.contains("GL_KHR_texture_compression_astc_hdr"), + ); + } let mut private_caps = super::PrivateCapabilities::empty(); private_caps.set( @@ -668,6 +679,7 @@ impl crate::Adapter for super::Adapter { let bcn_features = feature_fn(wgt::Features::TEXTURE_COMPRESSION_BC, filterable); let etc2_features = feature_fn(wgt::Features::TEXTURE_COMPRESSION_ETC2, filterable); let astc_features = feature_fn(wgt::Features::TEXTURE_COMPRESSION_ASTC_LDR, filterable); + let astc_hdr_features = feature_fn(wgt::Features::TEXTURE_COMPRESSION_ASTC_HDR, filterable); let private_caps_fn = |f, caps| { if self.shared.private_caps.contains(f) { @@ -765,7 +777,7 @@ impl crate::Adapter for super::Adapter { Tf::Astc { block: _, channel: AstcChannel::Hdr, - } => Tfc::empty(), + } => astc_hdr_features, } } diff --git a/wgpu-hal/src/gles/conv.rs b/wgpu-hal/src/gles/conv.rs index 78fa6fbcc0..d0d065f10e 100644 --- a/wgpu-hal/src/gles/conv.rs +++ b/wgpu-hal/src/gles/conv.rs @@ -115,7 +115,7 @@ impl super::AdapterShared { Tf::EacRg11Unorm => (glow::COMPRESSED_RG11_EAC, glow::RG, 0), Tf::EacRg11Snorm => (glow::COMPRESSED_SIGNED_RG11_EAC, glow::RG, 0), Tf::Astc { block, channel } => match channel { - AstcChannel::Unorm => match block { + AstcChannel::Unorm | AstcChannel::Hdr => 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), @@ -159,7 +159,6 @@ impl super::AdapterShared { (glow::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, glow::RGBA, 0) } }, - AstcChannel::Hdr => unimplemented!(), }, }; diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 46fe905fa2..a424389077 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -625,6 +625,7 @@ bitflags::bitflags! { /// Supported Platforms: /// - Metal /// - Vulkan + /// - OpenGL /// /// This is a native-only feature. const TEXTURE_COMPRESSION_ASTC_HDR = 1 << 40;