From 15488dfa1e133b14ad90c3cf69f4ef911283e735 Mon Sep 17 00:00:00 2001 From: Rukai Date: Tue, 11 Jun 2019 23:58:55 +1000 Subject: [PATCH] Fix descriptor sets free validation error --- wgpu-native/src/binding_model.rs | 9 +++++++++ wgpu-native/src/command/mod.rs | 1 + wgpu-native/src/command/render.rs | 7 ++++++- wgpu-native/src/device.rs | 11 +++++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/wgpu-native/src/binding_model.rs b/wgpu-native/src/binding_model.rs index 8867451330..74946809a6 100644 --- a/wgpu-native/src/binding_model.rs +++ b/wgpu-native/src/binding_model.rs @@ -5,6 +5,7 @@ use crate::{ BufferId, DeviceId, LifeGuard, + RefCount, SamplerId, Stored, TextureViewId, @@ -14,6 +15,8 @@ use arrayvec::ArrayVec; use bitflags::bitflags; use rendy_descriptor::{DescriptorRanges, DescriptorSet}; +use std::borrow::Borrow; + pub const MAX_BIND_GROUPS: usize = 4; bitflags! { @@ -113,3 +116,9 @@ pub struct BindGroup { pub(crate) used: TrackerSet, pub(crate) dynamic_count: usize, } + +impl Borrow for BindGroup { + fn borrow(&self) -> &RefCount { + &self.life_guard.ref_count + } +} diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index f7027dcf7f..85747797a4 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -132,6 +132,7 @@ impl CommandBufferHandle { } }); base.views.merge_extend(&head.views).unwrap(); + base.bind_groups.merge_extend(&head.bind_groups).unwrap(); let stages = all_buffer_stages() | all_image_stages(); unsafe { diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index 820c5cb532..94fafabdfd 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -211,7 +211,12 @@ pub extern "C" fn wgpu_render_pass_set_bind_group( let mut pass_guard = HUB.render_passes.write(); let pass = &mut pass_guard[pass_id]; let bind_group_guard = HUB.bind_groups.read(); - let bind_group = &bind_group_guard[bind_group_id]; + + let bind_group = pass + .trackers + .bind_groups + .use_extend(&*bind_group_guard, bind_group_id, (), ()) + .unwrap(); assert_eq!(bind_group.dynamic_count, offsets_length); let offsets = if offsets_length != 0 { diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 1edb8fff5c..c54ac48d3d 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -236,7 +236,7 @@ impl PendingResources { device.destroy_framebuffer(raw); }, NativeResource::DescriptorSet(raw) => unsafe { - descriptor_allocator.free(Some(raw).into_iter()); + descriptor_allocator.free(iter::once(raw)); }, } } @@ -1264,6 +1264,7 @@ pub extern "C" fn wgpu_queue_submit( let buffer_guard = HUB.buffers.read(); let texture_guard = HUB.textures.read(); let texture_view_guard = HUB.texture_views.read(); + let bind_group_guard = HUB.bind_groups.read(); // finish all the command buffers first for &cmb_id in command_buffer_ids { @@ -1274,7 +1275,7 @@ pub extern "C" fn wgpu_queue_submit( if frame.need_waiting.swap(false, Ordering::AcqRel) { assert_eq!(frame.acquired_epoch, Some(link.epoch), "{}. Image index {} with epoch {} != current epoch {:?}", - "Attempting to rendering to a swapchain output that has already been presented", + "Attempting to render to a swapchain output that has already been presented", link.image_index, link.epoch, frame.acquired_epoch); wait_semaphores.push(( &frame.sem_available, @@ -1307,6 +1308,12 @@ pub extern "C" fn wgpu_queue_submit( .submission_index .store(submit_index, Ordering::Release); } + for id in comb.trackers.bind_groups.used() { + bind_group_guard[id] + .life_guard + .submission_index + .store(submit_index, Ordering::Release); + } // execute resource transitions let mut transit = device.com_allocator.extend(comb);