@@ -143,12 +143,56 @@ crate::impl_storage_item!(Queue);
143
143
impl Drop for Queue {
144
144
fn drop ( & mut self ) {
145
145
resource_log ! ( "Drop {}" , self . error_ident( ) ) ;
146
+
147
+ let last_successful_submission_index = self
148
+ . device
149
+ . last_successful_submission_index
150
+ . load ( Ordering :: Acquire ) ;
151
+
152
+ let fence = self . device . fence . read ( ) ;
153
+ let wait_res = unsafe {
154
+ self . device . raw ( ) . wait (
155
+ fence. as_ref ( ) ,
156
+ last_successful_submission_index,
157
+ crate :: device:: CLEANUP_WAIT_MS ,
158
+ )
159
+ } ;
160
+ drop ( fence) ;
161
+
162
+ match wait_res {
163
+ Ok ( true ) => { }
164
+ // Note: If we don't panic here we are in UB land (destroying resources while they are still in use by the GPU).
165
+ Ok ( false ) => {
166
+ panic ! ( "We timed out while waiting on the last successful submission to complete!" ) ;
167
+ }
168
+ Err ( e) => {
169
+ panic ! (
170
+ "We ran into an error while waiting on the last successful submission to complete! - {e}"
171
+ ) ;
172
+ }
173
+ }
174
+
175
+ let snatch_guard = self . device . snatchable_lock . read ( ) ;
176
+ let ( submission_closures, mapping_closures, queue_empty) =
177
+ self . maintain ( last_successful_submission_index, & snatch_guard) ;
178
+ drop ( snatch_guard) ;
179
+
180
+ assert ! ( queue_empty) ;
181
+
182
+ let closures = crate :: device:: UserClosures {
183
+ mappings : mapping_closures,
184
+ submissions : submission_closures,
185
+ device_lost_invocations : SmallVec :: new ( ) ,
186
+ } ;
187
+
146
188
// SAFETY: We are in the Drop impl and we don't use self.pending_writes anymore after this point.
147
189
let pending_writes = unsafe { ManuallyDrop :: take ( & mut self . pending_writes . lock ( ) ) } ;
148
190
pending_writes. dispose ( self . device . raw ( ) ) ;
149
191
// SAFETY: we never access `self.raw` beyond this point.
150
192
let queue = unsafe { ManuallyDrop :: take ( & mut self . raw ) } ;
151
193
self . device . release_queue ( queue) ;
194
+
195
+ closures. fire ( ) ;
152
196
}
153
197
}
154
198
0 commit comments