@@ -820,6 +820,18 @@ impl RenderContext {
820820 return Ok ( ( ) ) ;
821821 }
822822
823+ fn validate_pipeline_exists (
824+ render_pipelines : & [ RenderPipeline ] ,
825+ pipeline : usize ,
826+ ) -> Result < ( ) , RenderPassError > {
827+ if render_pipelines. get ( pipeline) . is_none ( ) {
828+ return Err ( RenderPassError :: Validation ( format ! (
829+ "Unknown pipeline {pipeline}"
830+ ) ) ) ;
831+ }
832+ return Ok ( ( ) ) ;
833+ }
834+
823835 fn encode_active_render_pass_commands (
824836 command_iter : & mut std:: vec:: IntoIter < RenderCommand > ,
825837 rp_encoder : & mut encoder:: RenderPassEncoder < ' _ > ,
@@ -896,11 +908,13 @@ impl RenderContext {
896908 rp_encoder. set_index_buffer ( buffer_ref, format) ?;
897909 }
898910 RenderCommand :: Immediates {
899- pipeline : _ ,
911+ pipeline,
900912 stage : _,
901913 offset,
902914 bytes,
903915 } => {
916+ Self :: validate_pipeline_exists ( render_pipelines, pipeline) ?;
917+
904918 // Convert the u32 words to a byte slice for set_immediates.
905919 let byte_slice = unsafe {
906920 std:: slice:: from_raw_parts (
@@ -1039,4 +1053,13 @@ mod tests {
10391053 let has_attachment = RenderContext :: has_depth_attachment ( None , stencil_ops) ;
10401054 assert ! ( has_attachment) ;
10411055 }
1056+
1057+ #[ test]
1058+ fn immediates_validate_pipeline_exists_rejects_unknown_pipeline ( ) {
1059+ let pipelines: Vec < RenderPipeline > = vec ! [ ] ;
1060+ let err = RenderContext :: validate_pipeline_exists ( & pipelines, 7 )
1061+ . err ( )
1062+ . expect ( "must error" ) ;
1063+ assert ! ( err. to_string( ) . contains( "Unknown pipeline 7" ) ) ;
1064+ }
10421065}
0 commit comments