@@ -1482,16 +1482,17 @@ impl crate::Device for super::Device {
1482
1482
) -> Result < super :: BindGroupLayout , crate :: DeviceError > {
1483
1483
// Iterate through the entries and accumulate our Vulkan
1484
1484
// DescriptorSetLayoutBindings and DescriptorBindingFlags, as well as
1485
- // the list of which bindings are binding arrays, and our descriptor
1486
- // counts.
1485
+ // our binding map and our descriptor counts.
1487
1486
// Note: not bothering with on stack arrays here as it's low frequency
1488
1487
let mut vk_bindings = Vec :: new ( ) ;
1489
1488
let mut binding_flags = Vec :: new ( ) ;
1490
- let mut binding_arrays = Vec :: new ( ) ;
1489
+ let mut binding_map = Vec :: new ( ) ;
1490
+ let mut next_binding = 0 ;
1491
+ let mut contains_binding_arrays = false ;
1491
1492
let mut desc_count = gpu_descriptor:: DescriptorTotalCount :: default ( ) ;
1492
- for ( i , entry) in desc. entries . iter ( ) . enumerate ( ) {
1493
- if let Some ( count ) = entry. count {
1494
- binding_arrays . push ( ( i as u32 , count ) )
1493
+ for entry in desc. entries {
1494
+ if entry. count . is_some ( ) {
1495
+ contains_binding_arrays = true ;
1495
1496
}
1496
1497
1497
1498
let partially_bound = desc
@@ -1510,14 +1511,22 @@ impl crate::Device for super::Device {
1510
1511
wgt:: BindingType :: ExternalTexture => unimplemented ! ( ) ,
1511
1512
_ => {
1512
1513
vk_bindings. push ( vk:: DescriptorSetLayoutBinding {
1513
- binding : entry . binding ,
1514
+ binding : next_binding ,
1514
1515
descriptor_type : conv:: map_binding_type ( entry. ty ) ,
1515
1516
descriptor_count : count,
1516
1517
stage_flags : conv:: map_shader_stage ( entry. visibility ) ,
1517
1518
p_immutable_samplers : ptr:: null ( ) ,
1518
1519
_marker : Default :: default ( ) ,
1519
1520
} ) ;
1520
1521
binding_flags. push ( flags) ;
1522
+ binding_map. push ( (
1523
+ entry. binding ,
1524
+ super :: BindingInfo {
1525
+ binding : next_binding,
1526
+ binding_array_size : entry. count ,
1527
+ } ,
1528
+ ) ) ;
1529
+ next_binding += 1 ;
1521
1530
}
1522
1531
}
1523
1532
@@ -1560,7 +1569,7 @@ impl crate::Device for super::Device {
1560
1569
1561
1570
let vk_info = vk:: DescriptorSetLayoutCreateInfo :: default ( )
1562
1571
. bindings ( & vk_bindings)
1563
- . flags ( if !binding_arrays . is_empty ( ) {
1572
+ . flags ( if contains_binding_arrays {
1564
1573
vk:: DescriptorSetLayoutCreateFlags :: UPDATE_AFTER_BIND_POOL
1565
1574
} else {
1566
1575
vk:: DescriptorSetLayoutCreateFlags :: empty ( )
@@ -1588,7 +1597,8 @@ impl crate::Device for super::Device {
1588
1597
raw,
1589
1598
desc_count,
1590
1599
entries : desc. entries . into ( ) ,
1591
- binding_arrays,
1600
+ binding_map,
1601
+ contains_binding_arrays,
1592
1602
} )
1593
1603
}
1594
1604
unsafe fn destroy_bind_group_layout ( & self , bg_layout : super :: BindGroupLayout ) {
@@ -1640,27 +1650,25 @@ impl crate::Device for super::Device {
1640
1650
unsafe { self . shared . set_object_name ( raw, label) } ;
1641
1651
}
1642
1652
1643
- let mut binding_arrays = BTreeMap :: new ( ) ;
1653
+ let mut binding_map = BTreeMap :: new ( ) ;
1644
1654
for ( group, & layout) in desc. bind_group_layouts . iter ( ) . enumerate ( ) {
1645
- for & ( binding, binding_array_size ) in & layout. binding_arrays {
1646
- binding_arrays . insert (
1655
+ for & ( binding, binding_info ) in & layout. binding_map {
1656
+ binding_map . insert (
1647
1657
naga:: ResourceBinding {
1648
1658
group : group as u32 ,
1649
1659
binding,
1650
1660
} ,
1651
1661
naga:: back:: spv:: BindingInfo {
1652
- binding_array_size : Some ( binding_array_size. get ( ) ) ,
1662
+ descriptor_set : group as u32 ,
1663
+ binding : binding_info. binding ,
1664
+ binding_array_size : binding_info. binding_array_size . map ( NonZeroU32 :: get) ,
1653
1665
} ,
1654
1666
) ;
1655
1667
}
1656
1668
}
1657
1669
1658
1670
self . counters . pipeline_layouts . add ( 1 ) ;
1659
-
1660
- Ok ( super :: PipelineLayout {
1661
- raw,
1662
- binding_arrays,
1663
- } )
1671
+ Ok ( super :: PipelineLayout { raw, binding_map } )
1664
1672
}
1665
1673
unsafe fn destroy_pipeline_layout ( & self , pipeline_layout : super :: PipelineLayout ) {
1666
1674
unsafe {
@@ -1682,9 +1690,7 @@ impl crate::Device for super::Device {
1682
1690
super :: AccelerationStructure ,
1683
1691
> ,
1684
1692
) -> Result < super :: BindGroup , crate :: DeviceError > {
1685
- let contains_binding_arrays = !desc. layout . binding_arrays . is_empty ( ) ;
1686
-
1687
- let desc_set_layout_flags = if contains_binding_arrays {
1693
+ let desc_set_layout_flags = if desc. layout . contains_binding_arrays {
1688
1694
gpu_descriptor:: DescriptorSetLayoutCreateFlags :: UPDATE_AFTER_BIND
1689
1695
} else {
1690
1696
gpu_descriptor:: DescriptorSetLayoutCreateFlags :: empty ( )
@@ -1780,6 +1786,7 @@ impl crate::Device for super::Device {
1780
1786
. expect ( "internal error: no layout entry found with binding slot" ) ;
1781
1787
( layout, entry)
1782
1788
} ) ;
1789
+ let mut next_binding = 0 ;
1783
1790
for ( layout, entry) in layout_and_entry_iter {
1784
1791
let write = vk:: WriteDescriptorSet :: default ( ) . dst_set ( * set. raw ( ) ) ;
1785
1792
@@ -1794,10 +1801,11 @@ impl crate::Device for super::Device {
1794
1801
) ) ;
1795
1802
writes. push (
1796
1803
write
1797
- . dst_binding ( entry . binding )
1804
+ . dst_binding ( next_binding )
1798
1805
. descriptor_type ( conv:: map_binding_type ( layout. ty ) )
1799
1806
. image_info ( local_image_infos) ,
1800
1807
) ;
1808
+ next_binding += 1 ;
1801
1809
}
1802
1810
wgt:: BindingType :: Texture { .. } | wgt:: BindingType :: StorageTexture { .. } => {
1803
1811
let start = entry. resource_index ;
@@ -1815,10 +1823,11 @@ impl crate::Device for super::Device {
1815
1823
) ) ;
1816
1824
writes. push (
1817
1825
write
1818
- . dst_binding ( entry . binding )
1826
+ . dst_binding ( next_binding )
1819
1827
. descriptor_type ( conv:: map_binding_type ( layout. ty ) )
1820
1828
. image_info ( local_image_infos) ,
1821
1829
) ;
1830
+ next_binding += 1 ;
1822
1831
}
1823
1832
wgt:: BindingType :: Buffer { .. } => {
1824
1833
let start = entry. resource_index ;
@@ -1837,10 +1846,11 @@ impl crate::Device for super::Device {
1837
1846
) ) ;
1838
1847
writes. push (
1839
1848
write
1840
- . dst_binding ( entry . binding )
1849
+ . dst_binding ( next_binding )
1841
1850
. descriptor_type ( conv:: map_binding_type ( layout. ty ) )
1842
1851
. buffer_info ( local_buffer_infos) ,
1843
1852
) ;
1853
+ next_binding += 1 ;
1844
1854
}
1845
1855
wgt:: BindingType :: AccelerationStructure { .. } => {
1846
1856
let start = entry. resource_index ;
@@ -1867,11 +1877,12 @@ impl crate::Device for super::Device {
1867
1877
1868
1878
writes. push (
1869
1879
write
1870
- . dst_binding ( entry . binding )
1880
+ . dst_binding ( next_binding )
1871
1881
. descriptor_type ( conv:: map_binding_type ( layout. ty ) )
1872
1882
. descriptor_count ( entry. count )
1873
1883
. push_next ( local_acceleration_structure_infos) ,
1874
1884
) ;
1885
+ next_binding += 1 ;
1875
1886
}
1876
1887
wgt:: BindingType :: ExternalTexture => unimplemented ! ( ) ,
1877
1888
}
@@ -2033,7 +2044,7 @@ impl crate::Device for super::Device {
2033
2044
compiled_vs = Some ( self . compile_stage (
2034
2045
vertex_stage,
2035
2046
naga:: ShaderStage :: Vertex ,
2036
- & desc. layout . binding_arrays ,
2047
+ & desc. layout . binding_map ,
2037
2048
) ?) ;
2038
2049
stages. push ( compiled_vs. as_ref ( ) . unwrap ( ) . create_info ) ;
2039
2050
}
@@ -2045,14 +2056,14 @@ impl crate::Device for super::Device {
2045
2056
compiled_ts = Some ( self . compile_stage (
2046
2057
t,
2047
2058
naga:: ShaderStage :: Task ,
2048
- & desc. layout . binding_arrays ,
2059
+ & desc. layout . binding_map ,
2049
2060
) ?) ;
2050
2061
stages. push ( compiled_ts. as_ref ( ) . unwrap ( ) . create_info ) ;
2051
2062
}
2052
2063
compiled_ms = Some ( self . compile_stage (
2053
2064
mesh_stage,
2054
2065
naga:: ShaderStage :: Mesh ,
2055
- & desc. layout . binding_arrays ,
2066
+ & desc. layout . binding_map ,
2056
2067
) ?) ;
2057
2068
stages. push ( compiled_ms. as_ref ( ) . unwrap ( ) . create_info ) ;
2058
2069
}
@@ -2062,7 +2073,7 @@ impl crate::Device for super::Device {
2062
2073
let compiled = self . compile_stage (
2063
2074
stage,
2064
2075
naga:: ShaderStage :: Fragment ,
2065
- & desc. layout . binding_arrays ,
2076
+ & desc. layout . binding_map ,
2066
2077
) ?;
2067
2078
stages. push ( compiled. create_info ) ;
2068
2079
Some ( compiled)
@@ -2270,7 +2281,7 @@ impl crate::Device for super::Device {
2270
2281
let compiled = self . compile_stage (
2271
2282
& desc. stage ,
2272
2283
naga:: ShaderStage :: Compute ,
2273
- & desc. layout . binding_arrays ,
2284
+ & desc. layout . binding_map ,
2274
2285
) ?;
2275
2286
2276
2287
let vk_infos = [ {
0 commit comments