@@ -70,24 +70,38 @@ mod tests {
7070/// Bind group layout used when creating pipelines and bind groups.
7171pub struct BindGroupLayout {
7272 layout : Rc < lambda_platform:: wgpu:: bind:: BindGroupLayout > ,
73+ /// Total number of dynamic bindings declared in this layout.
74+ dynamic_binding_count : u32 ,
7375}
7476
7577impl BindGroupLayout {
7678 pub ( crate ) fn raw ( & self ) -> & wgpu:: BindGroupLayout {
7779 self . layout . raw ( )
7880 }
81+
82+ /// Number of dynamic bindings declared in this layout.
83+ pub fn dynamic_binding_count ( & self ) -> u32 {
84+ self . dynamic_binding_count
85+ }
7986}
8087
8188#[ derive( Debug , Clone ) ]
8289/// Bind group that binds one or more resources to a pipeline set index.
8390pub struct BindGroup {
8491 group : Rc < lambda_platform:: wgpu:: bind:: BindGroup > ,
92+ /// Cached number of dynamic bindings expected when binding this group.
93+ dynamic_binding_count : u32 ,
8594}
8695
8796impl BindGroup {
8897 pub ( crate ) fn raw ( & self ) -> & wgpu:: BindGroup {
8998 self . group . raw ( )
9099 }
100+
101+ /// Number of dynamic bindings expected when calling set_bind_group.
102+ pub fn dynamic_binding_count ( & self ) -> u32 {
103+ self . dynamic_binding_count
104+ }
91105}
92106
93107/// Builder for creating a bind group layout with uniform buffer bindings.
@@ -135,6 +149,8 @@ impl BindGroupLayoutBuilder {
135149 pub fn build ( self , render_context : & RenderContext ) -> BindGroupLayout {
136150 let mut platform =
137151 lambda_platform:: wgpu:: bind:: BindGroupLayoutBuilder :: new ( ) ;
152+ let dynamic_binding_count =
153+ self . entries . iter ( ) . filter ( |( _, _, d) | * d) . count ( ) as u32 ;
138154 if let Some ( label) = & self . label {
139155 platform = platform. with_label ( label) ;
140156 }
@@ -148,6 +164,7 @@ impl BindGroupLayoutBuilder {
148164 let layout = platform. build ( render_context. device ( ) ) ;
149165 BindGroupLayout {
150166 layout : Rc :: new ( layout) ,
167+ dynamic_binding_count,
151168 }
152169 }
153170}
@@ -203,12 +220,23 @@ impl<'a> BindGroupBuilder<'a> {
203220 if let Some ( label) = & self . label {
204221 platform = platform. with_label ( label) ;
205222 }
223+ let max_binding = render_context. limit_max_uniform_buffer_binding_size ( ) ;
206224 for ( binding, buffer, offset, size) in self . entries . into_iter ( ) {
225+ if let Some ( sz) = size {
226+ assert ! (
227+ sz. get( ) <= max_binding,
228+ "Uniform binding at binding={} requests size={} > device limit {}" ,
229+ binding,
230+ sz. get( ) ,
231+ max_binding
232+ ) ;
233+ }
207234 platform = platform. with_uniform ( binding, buffer. raw ( ) , offset, size) ;
208235 }
209236 let group = platform. build ( render_context. device ( ) ) ;
210237 BindGroup {
211238 group : Rc :: new ( group) ,
239+ dynamic_binding_count : layout. dynamic_binding_count ( ) ,
212240 }
213241 }
214242}
0 commit comments