mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #1593
1593: Fix VVL on halmark example r=kvark a=kvark **Connections** We have a bunch of VVL related to resource destruction on the halmark example. It also seems to leak memory quite a ton and eventually hang the system. **Description** This PR fixes the logic of changing the command pools in halmark, its initialization sequence, and its destruction. **Testing** Tested on halmark and others Co-authored-by: Dzmitry Malyshau <kvark@fastmail.com>
This commit is contained in:
@@ -10,6 +10,7 @@ const MAX_BUNNIES: usize = 1 << 20;
|
||||
const BUNNY_SIZE: f32 = 0.15 * 256.0;
|
||||
const GRAVITY: f32 = -9.8 * 100.0;
|
||||
const MAX_VELOCITY: f32 = 750.0;
|
||||
const COMMAND_BUFFER_PER_CONTEXT: usize = 100;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -34,17 +35,17 @@ struct ExecutionContext<A: hal::Api> {
|
||||
fence_value: hal::FenceValue,
|
||||
used_views: Vec<A::TextureView>,
|
||||
used_cmd_bufs: Vec<A::CommandBuffer>,
|
||||
bunnies_recorded: usize,
|
||||
frames_recorded: usize,
|
||||
}
|
||||
|
||||
impl<A: hal::Api> ExecutionContext<A> {
|
||||
unsafe fn wait_and_clear(&mut self, device: &A::Device) {
|
||||
device.wait(&self.fence, self.fence_value, !0).unwrap();
|
||||
self.encoder.reset_all(self.used_cmd_bufs.drain(..));
|
||||
for view in self.used_views.drain(..) {
|
||||
device.destroy_texture_view(view);
|
||||
}
|
||||
self.encoder.reset_all(self.used_cmd_bufs.drain(..));
|
||||
self.bunnies_recorded = 0;
|
||||
self.frames_recorded = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,11 +431,14 @@ impl<A: hal::Api> Example<A> {
|
||||
unsafe { device.create_bind_group(&local_group_desc).unwrap() }
|
||||
};
|
||||
|
||||
let init_fence_value = 1;
|
||||
let fence = unsafe {
|
||||
let mut fence = device.create_fence().unwrap();
|
||||
let init_cmd = cmd_encoder.end_encoding().unwrap();
|
||||
queue.submit(&[&init_cmd], Some((&mut fence, 1))).unwrap();
|
||||
device.wait(&fence, 1, !0).unwrap();
|
||||
queue
|
||||
.submit(&[&init_cmd], Some((&mut fence, init_fence_value)))
|
||||
.unwrap();
|
||||
device.wait(&fence, init_fence_value, !0).unwrap();
|
||||
device.destroy_buffer(staging_buffer);
|
||||
cmd_encoder.reset_all(iter::once(init_cmd));
|
||||
fence
|
||||
@@ -463,10 +467,10 @@ impl<A: hal::Api> Example<A> {
|
||||
contexts: vec![ExecutionContext {
|
||||
encoder: cmd_encoder,
|
||||
fence,
|
||||
fence_value: 1,
|
||||
fence_value: init_fence_value + 1,
|
||||
used_views: Vec::new(),
|
||||
used_cmd_bufs: Vec::new(),
|
||||
bunnies_recorded: 0,
|
||||
frames_recorded: 0,
|
||||
}],
|
||||
context_index: 0,
|
||||
extent: [window_size.0, window_size.1],
|
||||
@@ -511,6 +515,8 @@ impl<A: hal::Api> Example<A> {
|
||||
self.surface.unconfigure(&self.device);
|
||||
self.device.exit();
|
||||
self.instance.destroy_surface(self.surface);
|
||||
drop(self.adapter);
|
||||
drop(self.queue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -641,8 +647,8 @@ impl<A: hal::Api> Example<A> {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.bunnies_recorded += self.bunnies.len();
|
||||
let do_fence = ctx.bunnies_recorded > MAX_BUNNIES;
|
||||
ctx.frames_recorded += 1;
|
||||
let do_fence = ctx.frames_recorded > COMMAND_BUFFER_PER_CONTEXT;
|
||||
|
||||
unsafe {
|
||||
ctx.encoder.end_render_pass();
|
||||
@@ -673,7 +679,7 @@ impl<A: hal::Api> Example<A> {
|
||||
fence_value: 0,
|
||||
used_views: Vec::new(),
|
||||
used_cmd_bufs: Vec::new(),
|
||||
bunnies_recorded: 0,
|
||||
frames_recorded: 0,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ impl super::Adapter {
|
||||
"mali",
|
||||
"intel",
|
||||
];
|
||||
let strings_that_imply_cpu = ["mesa offscreen", "swiftshader", "lavapipe"];
|
||||
let strings_that_imply_cpu = ["mesa offscreen", "swiftshader", "llvmpipe"];
|
||||
|
||||
//TODO: handle Intel Iris XE as discreet
|
||||
let inferred_device_type = if vendor.contains("qualcomm")
|
||||
|
||||
@@ -287,14 +287,21 @@ impl super::Instance {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for super::InstanceShared {
|
||||
impl Drop for super::Instance {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
if let Some(du) = self.debug_utils.take() {
|
||||
du.extension
|
||||
.destroy_debug_utils_messenger(du.messenger, None);
|
||||
match Arc::get_mut(&mut self.shared) {
|
||||
Some(shared) => unsafe {
|
||||
if let Some(du) = shared.debug_utils.take() {
|
||||
du.extension
|
||||
.destroy_debug_utils_messenger(du.messenger, None);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
log::error!("Unable to drop Instance: something created from it is still alive");
|
||||
}
|
||||
self.raw.destroy_instance(None);
|
||||
}
|
||||
unsafe {
|
||||
self.shared.raw.destroy_instance(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user