@@ -15,9 +15,11 @@ use crate::{
15
15
} ;
16
16
17
17
use back;
18
+ use hal:: backend:: FastHashMap ;
18
19
use hal:: command:: RawCommandBuffer ;
19
20
use hal:: queue:: RawCommandQueue ;
20
- use hal:: { self ,
21
+ use hal:: {
22
+ self ,
21
23
DescriptorPool as _DescriptorPool,
22
24
Device as _Device,
23
25
Surface as _Surface,
@@ -27,7 +29,7 @@ use log::{info, trace};
27
29
use parking_lot:: { Mutex } ;
28
30
29
31
use std:: { ffi, iter, slice} ;
30
- use std:: collections:: hash_map:: { Entry , HashMap } ;
32
+ use std:: collections:: hash_map:: Entry ;
31
33
use std:: sync:: atomic:: Ordering ;
32
34
33
35
@@ -64,7 +66,7 @@ pub(crate) struct FramebufferKey {
64
66
}
65
67
impl Eq for FramebufferKey { }
66
68
67
- #[ derive( Debug ) ]
69
+ #[ derive( Debug , PartialEq ) ]
68
70
enum ResourceId {
69
71
Buffer ( BufferId ) ,
70
72
Texture ( TextureId ) ,
@@ -100,6 +102,7 @@ unsafe impl<B: hal::Backend> Sync for DestroyedResources<B> {}
100
102
101
103
impl < B : hal:: Backend > DestroyedResources < B > {
102
104
fn add ( & mut self , resource_id : ResourceId , ref_count : RefCount ) {
105
+ debug_assert ! ( !self . referenced. iter( ) . any( |r| r. 0 == resource_id) ) ;
103
106
self . referenced . push ( ( resource_id, ref_count) ) ;
104
107
}
105
108
@@ -195,8 +198,8 @@ pub struct Device<B: hal::Backend> {
195
198
life_guard : LifeGuard ,
196
199
pub ( crate ) trackers : Mutex < TrackerSet > ,
197
200
mem_props : hal:: MemoryProperties ,
198
- pub ( crate ) render_passes : Mutex < HashMap < RenderPassKey , B :: RenderPass > > ,
199
- pub ( crate ) framebuffers : Mutex < HashMap < FramebufferKey , B :: Framebuffer > > ,
201
+ pub ( crate ) render_passes : Mutex < FastHashMap < RenderPassKey , B :: RenderPass > > ,
202
+ pub ( crate ) framebuffers : Mutex < FastHashMap < FramebufferKey , B :: Framebuffer > > ,
200
203
desc_pool : Mutex < B :: DescriptorPool > ,
201
204
destroyed : Mutex < DestroyedResources < B > > ,
202
205
}
@@ -269,8 +272,8 @@ impl<B: hal::Backend> Device<B> {
269
272
life_guard,
270
273
trackers : Mutex :: new ( TrackerSet :: new ( ) ) ,
271
274
mem_props,
272
- render_passes : Mutex :: new ( HashMap :: new ( ) ) ,
273
- framebuffers : Mutex :: new ( HashMap :: new ( ) ) ,
275
+ render_passes : Mutex :: new ( FastHashMap :: default ( ) ) ,
276
+ framebuffers : Mutex :: new ( FastHashMap :: default ( ) ) ,
274
277
desc_pool,
275
278
destroyed : Mutex :: new ( DestroyedResources {
276
279
referenced : Vec :: new ( ) ,
@@ -1380,7 +1383,12 @@ pub fn device_create_swap_chain(
1380
1383
1381
1384
let ( old_raw, sem_available, command_pool) = match surface. swap_chain . take ( ) {
1382
1385
Some ( mut old) => {
1386
+ let mut destroyed = device. destroyed . lock ( ) ;
1383
1387
assert_eq ! ( old. device_id. value, device_id) ;
1388
+ for frame in old. frames {
1389
+ destroyed. add ( ResourceId :: Texture ( frame. texture_id . value ) , frame. texture_id . ref_count ) ;
1390
+ destroyed. add ( ResourceId :: TextureView ( frame. view_id . value ) , frame. view_id . ref_count ) ;
1391
+ }
1384
1392
unsafe {
1385
1393
old. command_pool . reset ( )
1386
1394
} ;
0 commit comments