Skip to content

Commit f918ac1

Browse files
authored
vk: fix astc_hdr formats support (#2971)
* vk: fix `astc_hdr` formats support * Update CHANGELOG
1 parent a08ea2a commit f918ac1

File tree

3 files changed

+57
-60
lines changed

3 files changed

+57
-60
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ the same every time it is rendered, we now warn if it is missing.
7171
#### Metal
7272
- Add the missing `msg_send![view, retain]` call within `from_view` by @jinleili in [#2976](https://github.com/gfx-rs/wgpu/pull/2976)
7373

74+
#### Vulkan
75+
76+
- Fix `astc_hdr` formats support by @jinleili in [#2971]](https://github.com/gfx-rs/wgpu/pull/2971)
77+
7478
### Changes
7579

7680
#### General

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,12 @@ impl PhysicalDeviceFeatures {
342342
}
343343
}
344344

345-
fn to_wgpu(&self, caps: &PhysicalDeviceCapabilities) -> (wgt::Features, wgt::DownlevelFlags) {
345+
fn to_wgpu(
346+
&self,
347+
instance: &ash::Instance,
348+
phd: vk::PhysicalDevice,
349+
caps: &PhysicalDeviceCapabilities,
350+
) -> (wgt::Features, wgt::DownlevelFlags) {
346351
use crate::auxil::db;
347352
use wgt::{DownlevelFlags as Df, Features as F};
348353
let mut features = F::empty()
@@ -532,7 +537,7 @@ impl PhysicalDeviceFeatures {
532537

533538
features.set(
534539
F::TEXTURE_FORMAT_16BIT_NORM,
535-
is_format_16bit_norm_supported(caps),
540+
is_format_16bit_norm_supported(instance, phd),
536541
);
537542

538543
if let Some(ref astc_hdr) = self.astc_hdr {
@@ -553,7 +558,9 @@ impl PhysicalDeviceFeatures {
553558

554559
features.set(
555560
F::DEPTH32FLOAT_STENCIL8,
556-
caps.supports_format(
561+
supports_format(
562+
instance,
563+
phd,
557564
vk::Format::D32_SFLOAT_S8_UINT,
558565
vk::ImageTiling::OPTIMAL,
559566
vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT,
@@ -562,7 +569,9 @@ impl PhysicalDeviceFeatures {
562569

563570
features.set(
564571
F::DEPTH24UNORM_STENCIL8,
565-
caps.supports_format(
572+
supports_format(
573+
instance,
574+
phd,
566575
vk::Format::D24_UNORM_S8_UINT,
567576
vk::ImageTiling::OPTIMAL,
568577
vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT,
@@ -589,7 +598,6 @@ pub struct PhysicalDeviceCapabilities {
589598
properties: vk::PhysicalDeviceProperties,
590599
vulkan_1_2: Option<vk::PhysicalDeviceVulkan12Properties>,
591600
descriptor_indexing: Option<vk::PhysicalDeviceDescriptorIndexingPropertiesEXT>,
592-
formats: Vec<vk::FormatProperties>,
593601
}
594602

595603
// This is safe because the structs have `p_next: *mut c_void`, which we null out/never read.
@@ -607,22 +615,6 @@ impl PhysicalDeviceCapabilities {
607615
.any(|ep| unsafe { CStr::from_ptr(ep.extension_name.as_ptr()) } == extension)
608616
}
609617

610-
fn supports_format(
611-
&self,
612-
format: vk::Format,
613-
tiling: vk::ImageTiling,
614-
features: vk::FormatFeatureFlags,
615-
) -> bool {
616-
self.formats
617-
.get(format.as_raw() as usize)
618-
.map(|properties| match tiling {
619-
vk::ImageTiling::LINEAR => properties.linear_tiling_features.contains(features),
620-
vk::ImageTiling::OPTIMAL => properties.optimal_tiling_features.contains(features),
621-
_ => false,
622-
})
623-
.unwrap()
624-
}
625-
626618
/// Map `requested_features` to the list of Vulkan extension strings required to create the logical device.
627619
fn get_required_extensions(&self, requested_features: wgt::Features) -> Vec<&'static CStr> {
628620
let mut extensions = Vec::new();
@@ -868,7 +860,6 @@ impl super::InstanceShared {
868860
} else {
869861
unsafe { self.raw.get_physical_device_properties(phd) }
870862
};
871-
capabilities.formats = query_format_properties(&self.raw, phd);
872863

873864
capabilities
874865
};
@@ -996,7 +987,8 @@ impl super::Instance {
996987
backend: wgt::Backend::Vulkan,
997988
};
998989

999-
let (available_features, downlevel_flags) = phd_features.to_wgpu(&phd_capabilities);
990+
let (available_features, downlevel_flags) =
991+
phd_features.to_wgpu(&self.shared.raw, phd, &phd_capabilities);
1000992
let mut workarounds = super::Workarounds::empty();
1001993
{
1002994
// see https://github.com/gfx-rs/gfx/issues/1930
@@ -1299,7 +1291,6 @@ impl super::Adapter {
12991291
}
13001292
};
13011293

1302-
log::info!("Private capabilities: {:?}", self.private_caps);
13031294
let raw_queue = {
13041295
profiling::scope!("vkGetDeviceQueue");
13051296
raw_device.get_device_queue(family_index, queue_index)
@@ -1449,13 +1440,9 @@ impl crate::Adapter<super::Api> for super::Adapter {
14491440

14501441
let vk_format = self.private_caps.map_texture_format(format);
14511442
let properties = self
1452-
.phd_capabilities
1453-
.formats
1454-
.get(vk_format.as_raw() as usize);
1455-
let properties = match properties {
1456-
Some(p) => p,
1457-
None => return Tfc::empty(),
1458-
};
1443+
.instance
1444+
.raw
1445+
.get_physical_device_format_properties(self.raw, vk_format);
14591446
let features = properties.optimal_tiling_features;
14601447

14611448
let mut flags = Tfc::empty();
@@ -1627,40 +1614,45 @@ impl crate::Adapter<super::Api> for super::Adapter {
16271614
}
16281615
}
16291616

1630-
/// Querys properties of all known image formats. The raw value of `vk::Format` corresponds
1631-
/// to the index of the returned Vec.
1632-
fn query_format_properties(
1633-
instance: &ash::Instance,
1634-
physical_device: vk::PhysicalDevice,
1635-
) -> Vec<vk::FormatProperties> {
1636-
// vk::Format::UNDEFINED
1637-
const FORMAT_MIN: i32 = 0;
1638-
1639-
// vk::Format::ASTC_12X12_SRGB_BLOCK
1640-
const FORMAT_MAX: i32 = 184;
1641-
1642-
debug_assert_eq!(FORMAT_MAX, vk::Format::ASTC_12X12_SRGB_BLOCK.as_raw());
1643-
1644-
(FORMAT_MIN..(FORMAT_MAX + 1))
1645-
.map(|raw| {
1646-
let image_format = vk::Format::from_raw(raw);
1647-
unsafe { instance.get_physical_device_format_properties(physical_device, image_format) }
1648-
})
1649-
.collect::<Vec<_>>()
1650-
}
1651-
1652-
fn is_format_16bit_norm_supported(caps: &PhysicalDeviceCapabilities) -> bool {
1617+
fn is_format_16bit_norm_supported(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool {
16531618
let tiling = vk::ImageTiling::OPTIMAL;
16541619
let features = vk::FormatFeatureFlags::SAMPLED_IMAGE
16551620
| vk::FormatFeatureFlags::STORAGE_IMAGE
16561621
| vk::FormatFeatureFlags::TRANSFER_SRC
16571622
| vk::FormatFeatureFlags::TRANSFER_DST;
1658-
let r16unorm = caps.supports_format(vk::Format::R16_UNORM, tiling, features);
1659-
let r16snorm = caps.supports_format(vk::Format::R16_SNORM, tiling, features);
1660-
let rg16unorm = caps.supports_format(vk::Format::R16G16_UNORM, tiling, features);
1661-
let rg16snorm = caps.supports_format(vk::Format::R16G16_SNORM, tiling, features);
1662-
let rgba16unorm = caps.supports_format(vk::Format::R16G16B16A16_UNORM, tiling, features);
1663-
let rgba16snorm = caps.supports_format(vk::Format::R16G16B16A16_SNORM, tiling, features);
1623+
let r16unorm = supports_format(instance, phd, vk::Format::R16_UNORM, tiling, features);
1624+
let r16snorm = supports_format(instance, phd, vk::Format::R16_SNORM, tiling, features);
1625+
let rg16unorm = supports_format(instance, phd, vk::Format::R16G16_UNORM, tiling, features);
1626+
let rg16snorm = supports_format(instance, phd, vk::Format::R16G16_SNORM, tiling, features);
1627+
let rgba16unorm = supports_format(
1628+
instance,
1629+
phd,
1630+
vk::Format::R16G16B16A16_UNORM,
1631+
tiling,
1632+
features,
1633+
);
1634+
let rgba16snorm = supports_format(
1635+
instance,
1636+
phd,
1637+
vk::Format::R16G16B16A16_SNORM,
1638+
tiling,
1639+
features,
1640+
);
16641641

16651642
r16unorm && r16snorm && rg16unorm && rg16snorm && rgba16unorm && rgba16snorm
16661643
}
1644+
1645+
fn supports_format(
1646+
instance: &ash::Instance,
1647+
phd: vk::PhysicalDevice,
1648+
format: vk::Format,
1649+
tiling: vk::ImageTiling,
1650+
features: vk::FormatFeatureFlags,
1651+
) -> bool {
1652+
let properties = unsafe { instance.get_physical_device_format_properties(phd, format) };
1653+
match tiling {
1654+
vk::ImageTiling::LINEAR => properties.linear_tiling_features.contains(features),
1655+
vk::ImageTiling::OPTIMAL => properties.optimal_tiling_features.contains(features),
1656+
_ => false,
1657+
}
1658+
}

wgpu-types/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ bitflags::bitflags! {
624624
///
625625
/// Supported Platforms:
626626
/// - Metal
627+
/// - Vulkan
627628
///
628629
/// This is a native-only feature.
629630
const TEXTURE_COMPRESSION_ASTC_HDR = 1 << 40;

0 commit comments

Comments
 (0)