From 305eadb19b58272674363fbb3c0924e15d30212a Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Sun, 20 Feb 2022 12:05:26 +0800 Subject: [PATCH] vulkan: HDR ASTC formats support --- wgpu-core/src/instance.rs | 1 + wgpu-hal/src/vulkan/adapter.rs | 32 ++++++++++++++++++++++++++++++-- wgpu-hal/src/vulkan/conv.rs | 17 ++++++++++++++++- wgpu-hal/src/vulkan/device.rs | 9 ++++++++- wgpu-hal/src/vulkan/instance.rs | 3 +++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 2542a6b761..f525d2eed0 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -197,6 +197,7 @@ impl Surface { wgt::TextureFormat::Rgba8UnormSrgb, wgt::TextureFormat::Bgra8Unorm, wgt::TextureFormat::Rgba8Unorm, + wgt::TextureFormat::Rgba16Float, ]; let suf = A::get_surface(self); diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 73736ee464..4334510842 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -25,6 +25,7 @@ pub struct PhysicalDeviceFeatures { robustness2: Option, depth_clip_enable: Option, multiview: Option, + astc_hdr: Option, } // This is safe because the structs have `p_next: *mut c_void`, which we null out/never read. @@ -59,6 +60,9 @@ impl PhysicalDeviceFeatures { if let Some(ref mut feature) = self.depth_clip_enable { info = info.push_next(feature); } + if let Some(ref mut feature) = self.astc_hdr { + info = info.push_next(feature); + } info } @@ -320,6 +324,15 @@ impl PhysicalDeviceFeatures { } else { None }, + astc_hdr: if enabled_extensions.contains(&vk::ExtTextureCompressionAstcHdrFn::name()) { + Some( + vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT::builder() + .texture_compression_astc_hdr(true) + .build(), + ) + } else { + None + }, } } @@ -523,6 +536,13 @@ impl PhysicalDeviceFeatures { is_format_16bit_norm_supported(caps), ); + if let Some(ref astc_hdr) = self.astc_hdr { + features.set( + F::TEXTURE_COMPRESSION_ASTC_HDR, + astc_hdr.texture_compression_astc_hdr != 0, + ); + } + (features, dl_flags) } @@ -633,6 +653,10 @@ impl PhysicalDeviceCapabilities { #[cfg(any(target_os = "macos", target_os = "ios"))] extensions.push(vk::KhrPortabilitySubsetFn::name()); + if requested_features.contains(wgt::Features::TEXTURE_COMPRESSION_ASTC_HDR) { + extensions.push(vk::ExtTextureCompressionAstcHdrFn::name()) + } + extensions } @@ -865,6 +889,12 @@ impl super::InstanceShared { .insert(vk::PhysicalDeviceDepthClipEnableFeaturesEXT::default()); builder = builder.push_next(next); } + if capabilities.supports_extension(vk::ExtTextureCompressionAstcHdrFn::name()) { + let next = features + .astc_hdr + .insert(vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT::default()); + builder = builder.push_next(next); + } let mut features2 = builder.build(); unsafe { @@ -1401,7 +1431,6 @@ impl crate::Adapter for super::Adapter { if !self.private_caps.can_present { return None; } - let queue_family_index = 0; //TODO { profiling::scope!("vkGetPhysicalDeviceSurfaceSupportKHR"); @@ -1509,7 +1538,6 @@ impl crate::Adapter for super::Adapter { .any(|sf| sf.format == vk_format || sf.format == vk::Format::UNDEFINED) }) .collect(); - Some(crate::SurfaceCapabilities { formats, swap_chain_sizes: caps.min_image_count..=max_image_count, diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index 81e0435607..727502aed8 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -121,7 +121,22 @@ impl super::PrivateCapabilities { AstcBlock::B12x10 => F::ASTC_12X10_SRGB_BLOCK, AstcBlock::B12x12 => F::ASTC_12X12_SRGB_BLOCK, }, - AstcChannel::Hdr => unimplemented!(), + AstcChannel::Hdr => match block { + AstcBlock::B4x4 => F::ASTC_4X4_SFLOAT_BLOCK_EXT, + AstcBlock::B5x4 => F::ASTC_5X4_SFLOAT_BLOCK_EXT, + AstcBlock::B5x5 => F::ASTC_5X5_SFLOAT_BLOCK_EXT, + AstcBlock::B6x5 => F::ASTC_6X5_SFLOAT_BLOCK_EXT, + AstcBlock::B6x6 => F::ASTC_6X6_SFLOAT_BLOCK_EXT, + AstcBlock::B8x5 => F::ASTC_8X5_SFLOAT_BLOCK_EXT, + AstcBlock::B8x6 => F::ASTC_8X6_SFLOAT_BLOCK_EXT, + AstcBlock::B8x8 => F::ASTC_8X8_SFLOAT_BLOCK_EXT, + AstcBlock::B10x5 => F::ASTC_10X5_SFLOAT_BLOCK_EXT, + AstcBlock::B10x6 => F::ASTC_10X6_SFLOAT_BLOCK_EXT, + AstcBlock::B10x8 => F::ASTC_10X8_SFLOAT_BLOCK_EXT, + AstcBlock::B10x10 => F::ASTC_10X10_SFLOAT_BLOCK_EXT, + AstcBlock::B12x10 => F::ASTC_12X10_SFLOAT_BLOCK_EXT, + AstcBlock::B12x12 => F::ASTC_12X12_SFLOAT_BLOCK_EXT, + }, }, } } diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 132393f4c9..55dcd82f9d 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -517,12 +517,19 @@ impl super::Device { None => vk::SwapchainKHR::null(), }; + let color_space = if config.format == wgt::TextureFormat::Rgba16Float { + // Enable wide color gamut mode + // Vulkan swapchain for Android only supports DISPLAY_P3_NONLINEAR_EXT and EXTENDED_SRGB_LINEAR_EXT + vk::ColorSpaceKHR::EXTENDED_SRGB_LINEAR_EXT + } else { + vk::ColorSpaceKHR::SRGB_NONLINEAR + }; let info = vk::SwapchainCreateInfoKHR::builder() .flags(vk::SwapchainCreateFlagsKHR::empty()) .surface(surface.raw) .min_image_count(config.swap_chain_size) .image_format(self.shared.private_caps.map_texture_format(config.format)) - .image_color_space(vk::ColorSpaceKHR::SRGB_NONLINEAR) + .image_color_space(color_space) .image_extent(vk::Extent2D { width: config.extent.width, height: config.extent.height, diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index a035b4fa1c..3cc304307a 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -162,6 +162,9 @@ impl super::Instance { extensions.push(vk::KhrGetPhysicalDeviceProperties2Fn::name()); + // Provid wide color gamut + extensions.push(vk::ExtSwapchainColorspaceFn::name()); + // Only keep available extensions. extensions.retain(|&ext| { if instance_extensions