@@ -570,15 +570,122 @@ impl RenderContext {
570570 & mut color_attachments,
571571 depth_texture_ref,
572572 |rp_encoder| {
573- Self :: encode_pass_commands (
574- rp_encoder,
575- render_pipelines,
576- bind_groups,
577- buffers,
578- min_uniform_buffer_offset_alignment,
579- viewport,
580- & mut command_iter,
581- )
573+ rp_encoder. set_viewport ( & viewport) ;
574+
575+ while let Some ( cmd) = command_iter. next ( ) {
576+ match cmd {
577+ RenderCommand :: EndRenderPass => return Ok ( ( ) ) ,
578+ RenderCommand :: SetStencilReference { reference } => {
579+ rp_encoder. set_stencil_reference ( reference) ;
580+ }
581+ RenderCommand :: SetPipeline { pipeline } => {
582+ let pipeline_ref =
583+ render_pipelines. get ( pipeline) . ok_or_else ( || {
584+ RenderPassError :: Validation ( format ! (
585+ "Unknown pipeline {pipeline}"
586+ ) )
587+ } ) ?;
588+ rp_encoder. set_pipeline ( pipeline_ref) ?;
589+ }
590+ RenderCommand :: SetViewports { viewports, .. } => {
591+ for vp in viewports {
592+ rp_encoder. set_viewport ( & vp) ;
593+ }
594+ }
595+ RenderCommand :: SetScissors { viewports, .. } => {
596+ for vp in viewports {
597+ rp_encoder. set_scissor ( & vp) ;
598+ }
599+ }
600+ RenderCommand :: SetBindGroup {
601+ set,
602+ group,
603+ dynamic_offsets,
604+ } => {
605+ let group_ref =
606+ bind_groups. get ( group) . ok_or_else ( || {
607+ RenderPassError :: Validation ( format ! (
608+ "Unknown bind group {group}"
609+ ) )
610+ } ) ?;
611+ rp_encoder. set_bind_group (
612+ set,
613+ group_ref,
614+ & dynamic_offsets,
615+ min_uniform_buffer_offset_alignment,
616+ ) ?;
617+ }
618+ RenderCommand :: BindVertexBuffer { pipeline, buffer } => {
619+ let pipeline_ref =
620+ render_pipelines. get ( pipeline) . ok_or_else ( || {
621+ RenderPassError :: Validation ( format ! (
622+ "Unknown pipeline {pipeline}"
623+ ) )
624+ } ) ?;
625+ let buffer_ref = pipeline_ref
626+ . buffers ( )
627+ . get ( buffer as usize )
628+ . ok_or_else ( || {
629+ RenderPassError :: Validation ( format ! (
630+ "Vertex buffer index {buffer} not found for \
631+ pipeline {pipeline}"
632+ ) )
633+ } ) ?;
634+ rp_encoder. set_vertex_buffer ( buffer as u32 , buffer_ref) ;
635+ }
636+ RenderCommand :: BindIndexBuffer { buffer, format } => {
637+ let buffer_ref = buffers. get ( buffer) . ok_or_else ( || {
638+ RenderPassError :: Validation ( format ! (
639+ "Index buffer id {} not found" ,
640+ buffer
641+ ) )
642+ } ) ?;
643+ rp_encoder. set_index_buffer ( buffer_ref, format) ?;
644+ }
645+ RenderCommand :: PushConstants {
646+ pipeline,
647+ stage,
648+ offset,
649+ bytes,
650+ } => {
651+ let _ =
652+ render_pipelines. get ( pipeline) . ok_or_else ( || {
653+ RenderPassError :: Validation ( format ! (
654+ "Unknown pipeline {pipeline}"
655+ ) )
656+ } ) ?;
657+ let slice = unsafe {
658+ std:: slice:: from_raw_parts (
659+ bytes. as_ptr ( ) as * const u8 ,
660+ bytes. len ( ) * std:: mem:: size_of :: < u32 > ( ) ,
661+ )
662+ } ;
663+ rp_encoder. set_push_constants ( stage, offset, slice) ;
664+ }
665+ RenderCommand :: Draw {
666+ vertices,
667+ instances,
668+ } => {
669+ rp_encoder. draw ( vertices, instances) ?;
670+ }
671+ RenderCommand :: DrawIndexed {
672+ indices,
673+ base_vertex,
674+ instances,
675+ } => {
676+ rp_encoder. draw_indexed ( indices, base_vertex, instances) ?;
677+ }
678+ RenderCommand :: BeginRenderPass { .. } => {
679+ return Err ( RenderPassError :: Validation (
680+ "Nested render passes are not supported." . to_string ( ) ,
681+ ) ) ;
682+ }
683+ }
684+ }
685+
686+ return Err ( RenderPassError :: Validation (
687+ "Render pass did not terminate with EndRenderPass" . to_string ( ) ,
688+ ) ) ;
582689 } ,
583690 ) ?;
584691 }
@@ -596,133 +703,6 @@ impl RenderContext {
596703 return Ok ( ( ) ) ;
597704 }
598705
599- /// Encode commands to a render pass encoder using the high-level API.
600- ///
601- /// This method processes `RenderCommand` items from the iterator until
602- /// `EndRenderPass` is encountered. Commands are translated to calls on the
603- /// `RenderPassEncoder`, which performs validation and issues GPU commands.
604- fn encode_pass_commands < Commands > (
605- encoder : & mut RenderPassEncoder < ' _ > ,
606- render_pipelines : & [ RenderPipeline ] ,
607- bind_groups : & [ bind:: BindGroup ] ,
608- buffers : & [ Rc < buffer:: Buffer > ] ,
609- min_uniform_buffer_offset_alignment : u32 ,
610- initial_viewport : viewport:: Viewport ,
611- commands : & mut Commands ,
612- ) -> Result < ( ) , RenderPassError >
613- where
614- Commands : Iterator < Item = RenderCommand > ,
615- {
616- encoder. set_viewport ( & initial_viewport) ;
617-
618- while let Some ( command) = commands. next ( ) {
619- match command {
620- RenderCommand :: EndRenderPass => return Ok ( ( ) ) ,
621- RenderCommand :: SetStencilReference { reference } => {
622- encoder. set_stencil_reference ( reference) ;
623- }
624- RenderCommand :: SetPipeline { pipeline } => {
625- let pipeline_ref =
626- render_pipelines. get ( pipeline) . ok_or_else ( || {
627- RenderPassError :: Validation ( format ! (
628- "Unknown pipeline {pipeline}"
629- ) )
630- } ) ?;
631- encoder. set_pipeline ( pipeline_ref) ?;
632- }
633- RenderCommand :: SetViewports { viewports, .. } => {
634- for viewport in viewports {
635- encoder. set_viewport ( & viewport) ;
636- }
637- }
638- RenderCommand :: SetScissors { viewports, .. } => {
639- for viewport in viewports {
640- encoder. set_scissor ( & viewport) ;
641- }
642- }
643- RenderCommand :: SetBindGroup {
644- set,
645- group,
646- dynamic_offsets,
647- } => {
648- let group_ref = bind_groups. get ( group) . ok_or_else ( || {
649- RenderPassError :: Validation ( format ! ( "Unknown bind group {group}" ) )
650- } ) ?;
651- encoder. set_bind_group (
652- set,
653- group_ref,
654- & dynamic_offsets,
655- min_uniform_buffer_offset_alignment,
656- ) ?;
657- }
658- RenderCommand :: BindVertexBuffer { pipeline, buffer } => {
659- let pipeline_ref =
660- render_pipelines. get ( pipeline) . ok_or_else ( || {
661- RenderPassError :: Validation ( format ! (
662- "Unknown pipeline {pipeline}"
663- ) )
664- } ) ?;
665- let buffer_ref =
666- pipeline_ref. buffers ( ) . get ( buffer as usize ) . ok_or_else ( || {
667- RenderPassError :: Validation ( format ! (
668- "Vertex buffer index {buffer} not found for pipeline \
669- {pipeline}"
670- ) )
671- } ) ?;
672- encoder. set_vertex_buffer ( buffer as u32 , buffer_ref) ;
673- }
674- RenderCommand :: BindIndexBuffer { buffer, format } => {
675- let buffer_ref = buffers. get ( buffer) . ok_or_else ( || {
676- RenderPassError :: Validation ( format ! (
677- "Index buffer id {} not found" ,
678- buffer
679- ) )
680- } ) ?;
681- encoder. set_index_buffer ( buffer_ref, format) ?;
682- }
683- RenderCommand :: PushConstants {
684- pipeline,
685- stage,
686- offset,
687- bytes,
688- } => {
689- let _ = render_pipelines. get ( pipeline) . ok_or_else ( || {
690- RenderPassError :: Validation ( format ! ( "Unknown pipeline {pipeline}" ) )
691- } ) ?;
692- let slice = unsafe {
693- std:: slice:: from_raw_parts (
694- bytes. as_ptr ( ) as * const u8 ,
695- bytes. len ( ) * std:: mem:: size_of :: < u32 > ( ) ,
696- )
697- } ;
698- encoder. set_push_constants ( stage, offset, slice) ;
699- }
700- RenderCommand :: Draw {
701- vertices,
702- instances,
703- } => {
704- encoder. draw ( vertices, instances) ?;
705- }
706- RenderCommand :: DrawIndexed {
707- indices,
708- base_vertex,
709- instances,
710- } => {
711- encoder. draw_indexed ( indices, base_vertex, instances) ?;
712- }
713- RenderCommand :: BeginRenderPass { .. } => {
714- return Err ( RenderPassError :: Validation (
715- "Nested render passes are not supported." . to_string ( ) ,
716- ) ) ;
717- }
718- }
719- }
720-
721- return Err ( RenderPassError :: Validation (
722- "Render pass did not terminate with EndRenderPass" . to_string ( ) ,
723- ) ) ;
724- }
725-
726706 /// Reconfigure the presentation surface using current present mode/usage.
727707 fn reconfigure_surface (
728708 & mut self ,
0 commit comments