@@ -523,7 +523,7 @@ pub(crate) struct VertexSlot {
523523/// derived from those buffers and the current pipeline, avoiding recomputation on each draw.
524524#[ derive( Debug , Default ) ]
525525pub ( crate ) struct VertexState {
526- pub ( crate ) slots : [ Option < VertexSlot > ; hal:: MAX_VERTEX_BUFFERS ] ,
526+ slots : [ Option < VertexSlot > ; hal:: MAX_VERTEX_BUFFERS ] ,
527527 pub ( crate ) limits : VertexLimits ,
528528}
529529
@@ -557,14 +557,51 @@ impl VertexState {
557557 ) ;
558558 }
559559
560- pub ( crate ) fn last_assigned_index ( & self ) -> Option < usize > {
560+ fn last_assigned_index ( & self ) -> Option < usize > {
561561 self . slots
562562 . iter ( )
563563 . enumerate ( )
564564 . filter_map ( |( i, s) | s. as_ref ( ) . map ( |_| i) )
565565 . next_back ( )
566566 }
567567
568+ pub ( super ) fn validate (
569+ & self ,
570+ pipeline : & RenderPipeline ,
571+ binder : & Binder ,
572+ ) -> Result < ( ) , DrawError > {
573+ // Check all needed vertex buffers have been bound
574+ for index in pipeline
575+ . vertex_steps
576+ . iter ( )
577+ . enumerate ( )
578+ . filter_map ( |( index, step) | step. map ( |_| index) )
579+ {
580+ if self . slots [ index] . is_none ( ) {
581+ return Err ( DrawError :: MissingVertexBuffer {
582+ pipeline : pipeline. error_ident ( ) ,
583+ index,
584+ } ) ;
585+ }
586+ }
587+
588+ let bind_group_space_used = binder. last_assigned_index ( ) . map_or ( 0 , |i| i + 1 ) ;
589+ let vertex_buffer_space_used = self . last_assigned_index ( ) . map_or ( 0 , |i| i + 1 ) ;
590+
591+ let bind_groups_plus_vertex_buffers =
592+ u32:: try_from ( bind_group_space_used + vertex_buffer_space_used) . unwrap ( ) ;
593+ if bind_groups_plus_vertex_buffers
594+ > pipeline. device . limits . max_bind_groups_plus_vertex_buffers
595+ {
596+ return Err ( DrawError :: TooManyBindGroupsPlusVertexBuffers {
597+ given : bind_groups_plus_vertex_buffers,
598+ limit : pipeline. device . limits . max_bind_groups_plus_vertex_buffers ,
599+ } ) ;
600+ }
601+
602+ Ok ( ( ) )
603+ }
604+
568605 /// Call `f` for each dirty slot with `(slot_index, buffer, offset, size)` and mark them clean.
569606 pub ( crate ) fn flush < F > ( & mut self , mut f : F )
570607 where
@@ -617,34 +654,7 @@ impl<'scope, 'snatch_guard, 'cmd_enc> State<'scope, 'snatch_guard, 'cmd_enc> {
617654 return Err ( DrawError :: MissingBlendConstant ) ;
618655 }
619656
620- // Check all needed vertex buffers have been bound
621- for index in pipeline
622- . vertex_steps
623- . iter ( )
624- . enumerate ( )
625- . filter_map ( |( index, step) | step. map ( |_| index) )
626- {
627- if self . vertex . slots [ index] . is_none ( ) {
628- return Err ( DrawError :: MissingVertexBuffer {
629- pipeline : pipeline. error_ident ( ) ,
630- index,
631- } ) ;
632- }
633- }
634-
635- let bind_group_space_used = self . pass . binder . last_assigned_index ( ) . map_or ( 0 , |i| i + 1 ) ;
636- let vertex_buffer_space_used = self . vertex . last_assigned_index ( ) . map_or ( 0 , |i| i + 1 ) ;
637-
638- let bind_groups_plus_vertex_buffers =
639- u32:: try_from ( bind_group_space_used + vertex_buffer_space_used) . unwrap ( ) ;
640- if bind_groups_plus_vertex_buffers
641- > pipeline. device . limits . max_bind_groups_plus_vertex_buffers
642- {
643- return Err ( DrawError :: TooManyBindGroupsPlusVertexBuffers {
644- given : bind_groups_plus_vertex_buffers,
645- limit : pipeline. device . limits . max_bind_groups_plus_vertex_buffers ,
646- } ) ;
647- }
657+ self . vertex . validate ( & * pipeline, & self . pass . binder ) ?;
648658
649659 if family == DrawCommandFamily :: DrawIndexed {
650660 // Pipeline expects an index buffer
0 commit comments