@@ -342,7 +342,12 @@ impl PhysicalDeviceFeatures {
342
342
}
343
343
}
344
344
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 ) {
346
351
use crate :: auxil:: db;
347
352
use wgt:: { DownlevelFlags as Df , Features as F } ;
348
353
let mut features = F :: empty ( )
@@ -532,7 +537,7 @@ impl PhysicalDeviceFeatures {
532
537
533
538
features. set (
534
539
F :: TEXTURE_FORMAT_16BIT_NORM ,
535
- is_format_16bit_norm_supported ( caps ) ,
540
+ is_format_16bit_norm_supported ( instance , phd ) ,
536
541
) ;
537
542
538
543
if let Some ( ref astc_hdr) = self . astc_hdr {
@@ -553,7 +558,9 @@ impl PhysicalDeviceFeatures {
553
558
554
559
features. set (
555
560
F :: DEPTH32FLOAT_STENCIL8 ,
556
- caps. supports_format (
561
+ supports_format (
562
+ instance,
563
+ phd,
557
564
vk:: Format :: D32_SFLOAT_S8_UINT ,
558
565
vk:: ImageTiling :: OPTIMAL ,
559
566
vk:: FormatFeatureFlags :: DEPTH_STENCIL_ATTACHMENT ,
@@ -562,7 +569,9 @@ impl PhysicalDeviceFeatures {
562
569
563
570
features. set (
564
571
F :: DEPTH24UNORM_STENCIL8 ,
565
- caps. supports_format (
572
+ supports_format (
573
+ instance,
574
+ phd,
566
575
vk:: Format :: D24_UNORM_S8_UINT ,
567
576
vk:: ImageTiling :: OPTIMAL ,
568
577
vk:: FormatFeatureFlags :: DEPTH_STENCIL_ATTACHMENT ,
@@ -589,7 +598,6 @@ pub struct PhysicalDeviceCapabilities {
589
598
properties : vk:: PhysicalDeviceProperties ,
590
599
vulkan_1_2 : Option < vk:: PhysicalDeviceVulkan12Properties > ,
591
600
descriptor_indexing : Option < vk:: PhysicalDeviceDescriptorIndexingPropertiesEXT > ,
592
- formats : Vec < vk:: FormatProperties > ,
593
601
}
594
602
595
603
// This is safe because the structs have `p_next: *mut c_void`, which we null out/never read.
@@ -607,22 +615,6 @@ impl PhysicalDeviceCapabilities {
607
615
. any ( |ep| unsafe { CStr :: from_ptr ( ep. extension_name . as_ptr ( ) ) } == extension)
608
616
}
609
617
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
-
626
618
/// Map `requested_features` to the list of Vulkan extension strings required to create the logical device.
627
619
fn get_required_extensions ( & self , requested_features : wgt:: Features ) -> Vec < & ' static CStr > {
628
620
let mut extensions = Vec :: new ( ) ;
@@ -868,7 +860,6 @@ impl super::InstanceShared {
868
860
} else {
869
861
unsafe { self . raw . get_physical_device_properties ( phd) }
870
862
} ;
871
- capabilities. formats = query_format_properties ( & self . raw , phd) ;
872
863
873
864
capabilities
874
865
} ;
@@ -996,7 +987,8 @@ impl super::Instance {
996
987
backend : wgt:: Backend :: Vulkan ,
997
988
} ;
998
989
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) ;
1000
992
let mut workarounds = super :: Workarounds :: empty ( ) ;
1001
993
{
1002
994
// see https://github.com/gfx-rs/gfx/issues/1930
@@ -1299,7 +1291,6 @@ impl super::Adapter {
1299
1291
}
1300
1292
} ;
1301
1293
1302
- log:: info!( "Private capabilities: {:?}" , self . private_caps) ;
1303
1294
let raw_queue = {
1304
1295
profiling:: scope!( "vkGetDeviceQueue" ) ;
1305
1296
raw_device. get_device_queue ( family_index, queue_index)
@@ -1449,13 +1440,9 @@ impl crate::Adapter<super::Api> for super::Adapter {
1449
1440
1450
1441
let vk_format = self . private_caps . map_texture_format ( format) ;
1451
1442
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) ;
1459
1446
let features = properties. optimal_tiling_features ;
1460
1447
1461
1448
let mut flags = Tfc :: empty ( ) ;
@@ -1627,40 +1614,45 @@ impl crate::Adapter<super::Api> for super::Adapter {
1627
1614
}
1628
1615
}
1629
1616
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 {
1653
1618
let tiling = vk:: ImageTiling :: OPTIMAL ;
1654
1619
let features = vk:: FormatFeatureFlags :: SAMPLED_IMAGE
1655
1620
| vk:: FormatFeatureFlags :: STORAGE_IMAGE
1656
1621
| vk:: FormatFeatureFlags :: TRANSFER_SRC
1657
1622
| 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
+ ) ;
1664
1641
1665
1642
r16unorm && r16snorm && rg16unorm && rg16snorm && rgba16unorm && rgba16snorm
1666
1643
}
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
+ }
0 commit comments