@@ -1480,20 +1480,46 @@ impl crate::Device for super::Device {
1480
1480
& self ,
1481
1481
desc : & crate :: BindGroupLayoutDescriptor ,
1482
1482
) -> Result < super :: BindGroupLayout , crate :: DeviceError > {
1483
+ // Iterate through the entries and accumulate our Vulkan
1484
+ // DescriptorSetLayoutBindings and DescriptorBindingFlags, as well as
1485
+ // the list of which bindings are binding arrays, and our descriptor
1486
+ // counts.
1487
+ // Note: not bothering with on stack arrays here as it's low frequency
1488
+ let mut vk_bindings = Vec :: new ( ) ;
1489
+ let mut binding_flags = Vec :: new ( ) ;
1490
+ let mut binding_arrays = Vec :: new ( ) ;
1483
1491
let mut desc_count = gpu_descriptor:: DescriptorTotalCount :: default ( ) ;
1484
- let mut types = Vec :: new ( ) ;
1485
- for entry in desc. entries {
1492
+ for ( i, entry) in desc. entries . iter ( ) . enumerate ( ) {
1493
+ if let Some ( count) = entry. count {
1494
+ binding_arrays. push ( ( i as u32 , count) )
1495
+ }
1496
+
1497
+ let partially_bound = desc
1498
+ . flags
1499
+ . contains ( crate :: BindGroupLayoutFlags :: PARTIALLY_BOUND ) ;
1500
+ let mut flags = vk:: DescriptorBindingFlags :: empty ( ) ;
1501
+ if partially_bound && entry. count . is_some ( ) {
1502
+ flags |= vk:: DescriptorBindingFlags :: PARTIALLY_BOUND ;
1503
+ }
1504
+ if entry. count . is_some ( ) {
1505
+ flags |= vk:: DescriptorBindingFlags :: UPDATE_AFTER_BIND ;
1506
+ }
1507
+
1486
1508
let count = entry. count . map_or ( 1 , |c| c. get ( ) ) ;
1487
- if entry. binding as usize >= types. len ( ) {
1488
- types. resize (
1489
- entry. binding as usize + 1 ,
1490
- ( vk:: DescriptorType :: INPUT_ATTACHMENT , 0 ) ,
1491
- ) ;
1509
+ match entry. ty {
1510
+ wgt:: BindingType :: ExternalTexture => unimplemented ! ( ) ,
1511
+ _ => {
1512
+ vk_bindings. push ( vk:: DescriptorSetLayoutBinding {
1513
+ binding : entry. binding ,
1514
+ descriptor_type : conv:: map_binding_type ( entry. ty ) ,
1515
+ descriptor_count : count,
1516
+ stage_flags : conv:: map_shader_stage ( entry. visibility ) ,
1517
+ p_immutable_samplers : ptr:: null ( ) ,
1518
+ _marker : Default :: default ( ) ,
1519
+ } ) ;
1520
+ binding_flags. push ( flags) ;
1521
+ }
1492
1522
}
1493
- types[ entry. binding as usize ] = (
1494
- conv:: map_binding_type ( entry. ty ) ,
1495
- entry. count . map_or ( 1 , |c| c. get ( ) ) ,
1496
- ) ;
1497
1523
1498
1524
match entry. ty {
1499
1525
wgt:: BindingType :: Buffer {
@@ -1532,27 +1558,6 @@ impl crate::Device for super::Device {
1532
1558
}
1533
1559
}
1534
1560
1535
- //Note: not bothering with on stack array here as it's low frequency
1536
- let vk_bindings = desc
1537
- . entries
1538
- . iter ( )
1539
- . map ( |entry| vk:: DescriptorSetLayoutBinding {
1540
- binding : entry. binding ,
1541
- descriptor_type : types[ entry. binding as usize ] . 0 ,
1542
- descriptor_count : types[ entry. binding as usize ] . 1 ,
1543
- stage_flags : conv:: map_shader_stage ( entry. visibility ) ,
1544
- p_immutable_samplers : ptr:: null ( ) ,
1545
- _marker : Default :: default ( ) ,
1546
- } )
1547
- . collect :: < Vec < _ > > ( ) ;
1548
-
1549
- let binding_arrays: Vec < _ > = desc
1550
- . entries
1551
- . iter ( )
1552
- . enumerate ( )
1553
- . filter_map ( |( idx, entry) | entry. count . map ( |count| ( idx as u32 , count) ) )
1554
- . collect ( ) ;
1555
-
1556
1561
let vk_info = vk:: DescriptorSetLayoutCreateInfo :: default ( )
1557
1562
. bindings ( & vk_bindings)
1558
1563
. flags ( if !binding_arrays. is_empty ( ) {
@@ -1561,30 +1566,8 @@ impl crate::Device for super::Device {
1561
1566
vk:: DescriptorSetLayoutCreateFlags :: empty ( )
1562
1567
} ) ;
1563
1568
1564
- let partially_bound = desc
1565
- . flags
1566
- . contains ( crate :: BindGroupLayoutFlags :: PARTIALLY_BOUND ) ;
1567
-
1568
- let binding_flag_vec = desc
1569
- . entries
1570
- . iter ( )
1571
- . map ( |entry| {
1572
- let mut flags = vk:: DescriptorBindingFlags :: empty ( ) ;
1573
-
1574
- if partially_bound && entry. count . is_some ( ) {
1575
- flags |= vk:: DescriptorBindingFlags :: PARTIALLY_BOUND ;
1576
- }
1577
-
1578
- if entry. count . is_some ( ) {
1579
- flags |= vk:: DescriptorBindingFlags :: UPDATE_AFTER_BIND ;
1580
- }
1581
-
1582
- flags
1583
- } )
1584
- . collect :: < Vec < _ > > ( ) ;
1585
-
1586
- let mut binding_flag_info = vk:: DescriptorSetLayoutBindingFlagsCreateInfo :: default ( )
1587
- . binding_flags ( & binding_flag_vec) ;
1569
+ let mut binding_flag_info =
1570
+ vk:: DescriptorSetLayoutBindingFlagsCreateInfo :: default ( ) . binding_flags ( & binding_flags) ;
1588
1571
1589
1572
let vk_info = vk_info. push_next ( & mut binding_flag_info) ;
1590
1573
@@ -1604,7 +1587,7 @@ impl crate::Device for super::Device {
1604
1587
Ok ( super :: BindGroupLayout {
1605
1588
raw,
1606
1589
desc_count,
1607
- types : types . into_boxed_slice ( ) ,
1590
+ entries : desc . entries . into ( ) ,
1608
1591
binding_arrays,
1609
1592
} )
1610
1593
}
@@ -1787,28 +1770,36 @@ impl crate::Device for super::Device {
1787
1770
Vec :: with_capacity ( desc. acceleration_structures . len ( ) ) ;
1788
1771
let mut raw_acceleration_structures =
1789
1772
ExtendStack :: from_vec_capacity ( & mut raw_acceleration_structures) ;
1790
- for entry in desc. entries {
1791
- let ( ty, size) = desc. layout . types [ entry. binding as usize ] ;
1792
- if size == 0 {
1793
- continue ; // empty slot
1794
- }
1795
- let mut write = vk:: WriteDescriptorSet :: default ( )
1796
- . dst_set ( * set. raw ( ) )
1797
- . dst_binding ( entry. binding )
1798
- . descriptor_type ( ty) ;
1799
-
1800
- write = match ty {
1801
- vk:: DescriptorType :: SAMPLER => {
1773
+
1774
+ let layout_and_entry_iter = desc. entries . iter ( ) . map ( |entry| {
1775
+ let layout = desc
1776
+ . layout
1777
+ . entries
1778
+ . iter ( )
1779
+ . find ( |layout_entry| layout_entry. binding == entry. binding )
1780
+ . expect ( "internal error: no layout entry found with binding slot" ) ;
1781
+ ( layout, entry)
1782
+ } ) ;
1783
+ for ( layout, entry) in layout_and_entry_iter {
1784
+ let write = vk:: WriteDescriptorSet :: default ( ) . dst_set ( * set. raw ( ) ) ;
1785
+
1786
+ match layout. ty {
1787
+ wgt:: BindingType :: Sampler ( _) => {
1802
1788
let start = entry. resource_index ;
1803
1789
let end = start + entry. count ;
1804
1790
let local_image_infos;
1805
1791
( image_infos, local_image_infos) =
1806
1792
image_infos. extend ( desc. samplers [ start as usize ..end as usize ] . iter ( ) . map (
1807
1793
|sampler| vk:: DescriptorImageInfo :: default ( ) . sampler ( sampler. raw ) ,
1808
1794
) ) ;
1809
- write. image_info ( local_image_infos)
1795
+ writes. push (
1796
+ write
1797
+ . dst_binding ( entry. binding )
1798
+ . descriptor_type ( conv:: map_binding_type ( layout. ty ) )
1799
+ . image_info ( local_image_infos) ,
1800
+ ) ;
1810
1801
}
1811
- vk :: DescriptorType :: SAMPLED_IMAGE | vk :: DescriptorType :: STORAGE_IMAGE => {
1802
+ wgt :: BindingType :: Texture { .. } | wgt :: BindingType :: StorageTexture { .. } => {
1812
1803
let start = entry. resource_index ;
1813
1804
let end = start + entry. count ;
1814
1805
let local_image_infos;
@@ -1822,12 +1813,14 @@ impl crate::Device for super::Device {
1822
1813
. image_layout ( layout)
1823
1814
} ,
1824
1815
) ) ;
1825
- write. image_info ( local_image_infos)
1816
+ writes. push (
1817
+ write
1818
+ . dst_binding ( entry. binding )
1819
+ . descriptor_type ( conv:: map_binding_type ( layout. ty ) )
1820
+ . image_info ( local_image_infos) ,
1821
+ ) ;
1826
1822
}
1827
- vk:: DescriptorType :: UNIFORM_BUFFER
1828
- | vk:: DescriptorType :: UNIFORM_BUFFER_DYNAMIC
1829
- | vk:: DescriptorType :: STORAGE_BUFFER
1830
- | vk:: DescriptorType :: STORAGE_BUFFER_DYNAMIC => {
1823
+ wgt:: BindingType :: Buffer { .. } => {
1831
1824
let start = entry. resource_index ;
1832
1825
let end = start + entry. count ;
1833
1826
let local_buffer_infos;
@@ -1842,9 +1835,14 @@ impl crate::Device for super::Device {
1842
1835
)
1843
1836
} ,
1844
1837
) ) ;
1845
- write. buffer_info ( local_buffer_infos)
1838
+ writes. push (
1839
+ write
1840
+ . dst_binding ( entry. binding )
1841
+ . descriptor_type ( conv:: map_binding_type ( layout. ty ) )
1842
+ . buffer_info ( local_buffer_infos) ,
1843
+ ) ;
1846
1844
}
1847
- vk :: DescriptorType :: ACCELERATION_STRUCTURE_KHR => {
1845
+ wgt :: BindingType :: AccelerationStructure { .. } => {
1848
1846
let start = entry. resource_index ;
1849
1847
let end = start + entry. count ;
1850
1848
@@ -1867,14 +1865,16 @@ impl crate::Device for super::Device {
1867
1865
. acceleration_structures ( local_raw_acceleration_structures) ,
1868
1866
) ;
1869
1867
1870
- write
1871
- . descriptor_count ( entry. count )
1872
- . push_next ( local_acceleration_structure_infos)
1868
+ writes. push (
1869
+ write
1870
+ . dst_binding ( entry. binding )
1871
+ . descriptor_type ( conv:: map_binding_type ( layout. ty ) )
1872
+ . descriptor_count ( entry. count )
1873
+ . push_next ( local_acceleration_structure_infos) ,
1874
+ ) ;
1873
1875
}
1874
- _ => unreachable ! ( ) ,
1875
- } ;
1876
-
1877
- writes. push ( write) ;
1876
+ wgt:: BindingType :: ExternalTexture => unimplemented ! ( ) ,
1877
+ }
1878
1878
}
1879
1879
1880
1880
unsafe { self . shared . raw . update_descriptor_sets ( & writes, & [ ] ) } ;
0 commit comments