From 30565ef681204ace6f4026da3c09d287dc50d744 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Wed, 22 Nov 2023 16:43:08 +0100 Subject: [PATCH 1/3] GetBindGroupLayout 'raises error' instead of panicing on invalid index --- src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 747ed76b..b877184a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -245,6 +245,7 @@ pub struct WGPURenderPassEncoderImpl { pub struct WGPURenderPipelineImpl { context: Arc, id: id::RenderPipelineId, + error_sink: ErrorSink, } impl Drop for WGPURenderPipelineImpl { fn drop(&mut self) { @@ -2227,6 +2228,7 @@ pub unsafe extern "C" fn wgpuDeviceCreateRenderPipeline( Arc::into_raw(Arc::new(WGPURenderPipelineImpl { context: context.clone(), id: render_pipeline_id, + error_sink: error_sink.clone(), })) } @@ -3500,17 +3502,13 @@ pub unsafe extern "C" fn wgpuRenderPipelineGetBindGroupLayout( render_pipeline: native::WGPURenderPipeline, group_index: u32, ) -> native::WGPUBindGroupLayout { - let (render_pipeline_id, context) = { + let (render_pipeline_id, context, error_sink) = { let render_pipeline = render_pipeline.as_ref().expect("invalid render pipeline"); - (render_pipeline.id, &render_pipeline.context) + (render_pipeline.id, &render_pipeline.context, &render_pipeline.error_sink) }; - let (bind_group_layout_id, error) = gfx_select!(render_pipeline_id => context.render_pipeline_get_bind_group_layout(render_pipeline_id, group_index, ())); if let Some(cause) = error { - panic!( - "Error in wgpuRenderPipelineGetBindGroupLayout: Error reflecting bind group {group_index}: {f}", - f = format_error(context, &cause) - ); + handle_error(context, error_sink, cause, "", None, "wgpuRenderPipelineGetBindGroupLayout") } Arc::into_raw(Arc::new(WGPUBindGroupLayoutImpl { From 44b870cdbb71342da989bf5f833df67c5a87f6f0 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Wed, 22 Nov 2023 16:49:04 +0100 Subject: [PATCH 2/3] fmt --- src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b877184a..8736166d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3504,11 +3504,22 @@ pub unsafe extern "C" fn wgpuRenderPipelineGetBindGroupLayout( ) -> native::WGPUBindGroupLayout { let (render_pipeline_id, context, error_sink) = { let render_pipeline = render_pipeline.as_ref().expect("invalid render pipeline"); - (render_pipeline.id, &render_pipeline.context, &render_pipeline.error_sink) + ( + render_pipeline.id, + &render_pipeline.context, + &render_pipeline.error_sink, + ) }; let (bind_group_layout_id, error) = gfx_select!(render_pipeline_id => context.render_pipeline_get_bind_group_layout(render_pipeline_id, group_index, ())); if let Some(cause) = error { - handle_error(context, error_sink, cause, "", None, "wgpuRenderPipelineGetBindGroupLayout") + handle_error( + context, + error_sink, + cause, + "", + None, + "wgpuRenderPipelineGetBindGroupLayout", + ) } Arc::into_raw(Arc::new(WGPUBindGroupLayoutImpl { From c7ad9da7974fd7e26506f41cf8b60f54177a6e22 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Wed, 22 Nov 2023 17:01:07 +0100 Subject: [PATCH 3/3] Also for compute pipeline --- src/lib.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8736166d..7a369c10 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -147,6 +147,7 @@ pub struct WGPUComputePassEncoderImpl { pub struct WGPUComputePipelineImpl { context: Arc, id: id::ComputePipelineId, + error_sink: ErrorSink, } impl Drop for WGPUComputePipelineImpl { fn drop(&mut self) { @@ -1681,17 +1682,21 @@ pub unsafe extern "C" fn wgpuComputePipelineGetBindGroupLayout( pipeline: native::WGPUComputePipeline, group_index: u32, ) -> native::WGPUBindGroupLayout { - let (pipeline_id, context) = { + let (pipeline_id, context, error_sink) = { let pipeline = pipeline.as_ref().expect("invalid pipeline"); - (pipeline.id, &pipeline.context) + (pipeline.id, &pipeline.context, &pipeline.error_sink) }; let (bind_group_layout_id, error) = gfx_select!(pipeline_id => context.compute_pipeline_get_bind_group_layout(pipeline_id, group_index, ())); if let Some(cause) = error { - panic!( - "Error in wgpuComputePipelineGetBindGroupLayout: Error reflecting bind group {group_index}: {f}", - f = format_error(context, &cause) - ); + handle_error( + context, + error_sink, + cause, + "", + None, + "wgpuComputePipelineGetBindGroupLayout", + ) } Arc::into_raw(Arc::new(WGPUBindGroupLayoutImpl { @@ -1946,6 +1951,7 @@ pub unsafe extern "C" fn wgpuDeviceCreateComputePipeline( Arc::into_raw(Arc::new(WGPUComputePipelineImpl { context: context.clone(), id: compute_pipeline_id, + error_sink: error_sink.clone(), })) }