@@ -19,7 +19,7 @@ use smallvec::SmallVec;
1919use thiserror:: Error ;
2020use wgt:: { BufferAddress , TextureFormat , TextureViewDimension } ;
2121
22- use std:: { borrow:: Cow , iter, marker:: PhantomData , mem, ops:: Range , ptr} ;
22+ use std:: { borrow:: Cow , iter, marker:: PhantomData , mem, num :: NonZeroU32 , ops:: Range , ptr} ;
2323
2424mod life;
2525pub mod queue;
@@ -1387,7 +1387,7 @@ impl<A: HalApi> Device<A> {
13871387 . entries
13881388 . get ( & binding)
13891389 . ok_or ( Error :: MissingBindingDeclaration ( binding) ) ?;
1390- let res_index = match entry. resource {
1390+ let ( res_index, count ) = match entry. resource {
13911391 Br :: Buffer ( ref bb) => {
13921392 let bb = Self :: create_buffer_binding (
13931393 bb,
@@ -1402,21 +1402,11 @@ impl<A: HalApi> Device<A> {
14021402
14031403 let res_index = hal_buffers. len ( ) ;
14041404 hal_buffers. push ( bb) ;
1405- res_index
1405+ ( res_index, 1 )
14061406 }
14071407 Br :: BufferArray ( ref bindings_array) => {
1408- if let Some ( count) = decl. count {
1409- let count = count. get ( ) as usize ;
1410- let num_bindings = bindings_array. len ( ) ;
1411- if count != num_bindings {
1412- return Err ( Error :: BindingArrayLengthMismatch {
1413- actual : num_bindings,
1414- expected : count,
1415- } ) ;
1416- }
1417- } else {
1418- return Err ( Error :: SingleBindingExpected ) ;
1419- }
1408+ let num_bindings = bindings_array. len ( ) ;
1409+ Self :: check_array_binding ( self . features , decl. count , num_bindings) ?;
14201410
14211411 let res_index = hal_buffers. len ( ) ;
14221412 for bb in bindings_array. iter ( ) {
@@ -1432,7 +1422,7 @@ impl<A: HalApi> Device<A> {
14321422 ) ?;
14331423 hal_buffers. push ( bb) ;
14341424 }
1435- res_index
1425+ ( res_index, num_bindings )
14361426 }
14371427 Br :: Sampler ( id) => {
14381428 match decl. ty {
@@ -1464,7 +1454,7 @@ impl<A: HalApi> Device<A> {
14641454
14651455 let res_index = hal_samplers. len ( ) ;
14661456 hal_samplers. push ( & sampler. raw ) ;
1467- res_index
1457+ ( res_index, 1 )
14681458 }
14691459 _ => {
14701460 return Err ( Error :: WrongBindingType {
@@ -1505,21 +1495,11 @@ impl<A: HalApi> Device<A> {
15051495 view : & view. raw ,
15061496 usage : internal_use,
15071497 } ) ;
1508- res_index
1498+ ( res_index, 1 )
15091499 }
15101500 Br :: TextureViewArray ( ref bindings_array) => {
1511- if let Some ( count) = decl. count {
1512- let count = count. get ( ) as usize ;
1513- let num_bindings = bindings_array. len ( ) ;
1514- if count != num_bindings {
1515- return Err ( Error :: BindingArrayLengthMismatch {
1516- actual : num_bindings,
1517- expected : count,
1518- } ) ;
1519- }
1520- } else {
1521- return Err ( Error :: SingleBindingExpected ) ;
1522- }
1501+ let num_bindings = bindings_array. len ( ) ;
1502+ Self :: check_array_binding ( self . features , decl. count , num_bindings) ?;
15231503
15241504 let res_index = hal_textures. len ( ) ;
15251505 for & id in bindings_array. iter ( ) {
@@ -1551,13 +1531,14 @@ impl<A: HalApi> Device<A> {
15511531 } ) ;
15521532 }
15531533
1554- res_index
1534+ ( res_index, num_bindings )
15551535 }
15561536 } ;
15571537
15581538 hal_entries. push ( hal:: BindGroupEntry {
15591539 binding,
15601540 resource_index : res_index as u32 ,
1541+ count : count as u32 ,
15611542 } ) ;
15621543 }
15631544
@@ -1596,6 +1577,39 @@ impl<A: HalApi> Device<A> {
15961577 } )
15971578 }
15981579
1580+ fn check_array_binding (
1581+ features : wgt:: Features ,
1582+ count : Option < NonZeroU32 > ,
1583+ num_bindings : usize ,
1584+ ) -> Result < ( ) , super :: binding_model:: CreateBindGroupError > {
1585+ use super :: binding_model:: CreateBindGroupError as Error ;
1586+
1587+ if let Some ( count) = count {
1588+ let count = count. get ( ) as usize ;
1589+ if count < num_bindings {
1590+ return Err ( Error :: BindingArrayPartialLengthMismatch {
1591+ actual : num_bindings,
1592+ expected : count,
1593+ } ) ;
1594+ }
1595+ if count != num_bindings
1596+ && !features. contains ( wgt:: Features :: PARTIALLY_BOUND_BINDING_ARRAY )
1597+ {
1598+ return Err ( Error :: BindingArrayLengthMismatch {
1599+ actual : num_bindings,
1600+ expected : count,
1601+ } ) ;
1602+ }
1603+ if num_bindings == 0 {
1604+ return Err ( Error :: BindingArrayZeroLength ) ;
1605+ }
1606+ } else {
1607+ return Err ( Error :: SingleBindingExpected ) ;
1608+ } ;
1609+
1610+ Ok ( ( ) )
1611+ }
1612+
15991613 fn texture_use_parameters (
16001614 binding : u32 ,
16011615 decl : & wgt:: BindGroupLayoutEntry ,
0 commit comments