From e97e54e4a33db14c4192f2e7d796ce34112143f2 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 30 Aug 2019 21:49:25 -0400 Subject: [PATCH] Stop rebinding descriptors on the first incompatible --- wgpu-native/src/command/compute.rs | 26 +++++++++++++++++--------- wgpu-native/src/command/render.rs | 26 +++++++++++++++++--------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/wgpu-native/src/command/compute.rs b/wgpu-native/src/command/compute.rs index bbc03f89a..3461cb213 100644 --- a/wgpu-native/src/command/compute.rs +++ b/wgpu-native/src/command/compute.rs @@ -255,6 +255,7 @@ pub fn compute_pass_set_pipeline( pass.binder.pipeline_layout_id = Some(pipeline.layout_id.clone()); pass.binder .reset_expectations(pipeline_layout.bind_group_layout_ids.len()); + let mut is_compatible = true; for (index, (entry, &bgl_id)) in pass .binder @@ -263,15 +264,22 @@ pub fn compute_pass_set_pipeline( .zip(&pipeline_layout.bind_group_layout_ids) .enumerate() { - if let LayoutChange::Match(bg_id, offsets) = entry.expect_layout(bgl_id) { - let desc_set = bind_group_guard[bg_id].raw.raw(); - unsafe { - pass.raw.bind_compute_descriptor_sets( - &pipeline_layout.raw, - index, - iter::once(desc_set), - offsets.iter().map(|offset| *offset as u32), - ); + match entry.expect_layout(bgl_id) { + LayoutChange::Match(bg_id, offsets) if is_compatible => { + let desc_set = bind_group_guard[bg_id].raw.raw(); + unsafe { + pass.raw.bind_compute_descriptor_sets( + &pipeline_layout.raw, + index, + iter::once(desc_set), + offsets.iter().map(|offset| *offset as u32), + ); + } + } + LayoutChange::Match(..) | + LayoutChange::Unchanged => {} + LayoutChange::Mismatch => { + is_compatible = false; } } } diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index 38cecd24d..9e9778238 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -593,6 +593,7 @@ pub fn render_pass_set_pipeline( pass.binder.pipeline_layout_id = Some(pipeline.layout_id.clone()); pass.binder .reset_expectations(pipeline_layout.bind_group_layout_ids.len()); + let mut is_compatible = true; for (index, (entry, &bgl_id)) in pass .binder @@ -601,15 +602,22 @@ pub fn render_pass_set_pipeline( .zip(&pipeline_layout.bind_group_layout_ids) .enumerate() { - if let LayoutChange::Match(bg_id, offsets) = entry.expect_layout(bgl_id) { - let desc_set = bind_group_guard[bg_id].raw.raw(); - unsafe { - pass.raw.bind_graphics_descriptor_sets( - &pipeline_layout.raw, - index, - iter::once(desc_set), - offsets.iter().map(|offset| *offset as u32), - ); + match entry.expect_layout(bgl_id) { + LayoutChange::Match(bg_id, offsets) if is_compatible => { + let desc_set = bind_group_guard[bg_id].raw.raw(); + unsafe { + pass.raw.bind_graphics_descriptor_sets( + &pipeline_layout.raw, + index, + iter::once(desc_set), + offsets.iter().map(|offset| *offset as u32), + ); + } + } + LayoutChange::Match(..) | + LayoutChange::Unchanged => {} + LayoutChange::Mismatch => { + is_compatible = false; } } }