Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vulkan: HDR ASTC formats support #2496

Merged
merged 1 commit into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ impl Surface {
wgt::TextureFormat::Rgba8UnormSrgb,
wgt::TextureFormat::Bgra8Unorm,
wgt::TextureFormat::Rgba8Unorm,
wgt::TextureFormat::Rgba16Float,
kvark marked this conversation as resolved.
Show resolved Hide resolved
];

let suf = A::get_surface(self);
Expand Down
32 changes: 30 additions & 2 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct PhysicalDeviceFeatures {
robustness2: Option<vk::PhysicalDeviceRobustness2FeaturesEXT>,
depth_clip_enable: Option<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>,
multiview: Option<vk::PhysicalDeviceMultiviewFeaturesKHR>,
astc_hdr: Option<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT>,
}

// This is safe because the structs have `p_next: *mut c_void`, which we null out/never read.
Expand Down Expand Up @@ -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
}

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

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

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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1401,7 +1431,6 @@ impl crate::Adapter<super::Api> for super::Adapter {
if !self.private_caps.can_present {
return None;
}

let queue_family_index = 0; //TODO
{
profiling::scope!("vkGetPhysicalDeviceSurfaceSupportKHR");
Expand Down Expand Up @@ -1509,7 +1538,6 @@ impl crate::Adapter<super::Api> 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,
Expand Down
17 changes: 16 additions & 1 deletion wgpu-hal/src/vulkan/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
}
Expand Down
9 changes: 8 additions & 1 deletion wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions wgpu-hal/src/vulkan/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down