mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Merge #119
119: Fix waiting on frame semaphores, plus check the epochs r=grovesNL a=kvark Fixes #88 Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
This commit is contained in:
commit
20841859d1
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -326,7 +326,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wgpu 0.2.2",
|
||||
"wgpu-native 0.2.5",
|
||||
"wgpu-native 0.2.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1392,7 +1392,7 @@ name = "wgpu"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wgpu-native 0.2.5",
|
||||
"wgpu-native 0.2.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1404,7 +1404,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wgpu-native"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
dependencies = [
|
||||
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1431,7 +1431,7 @@ dependencies = [
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wgpu-native 0.2.5",
|
||||
"wgpu-native 0.2.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#define WGPUMAX_BIND_GROUPS 4
|
||||
|
||||
#define WGPUMAX_COLOR_TARGETS 4
|
||||
|
||||
typedef enum {
|
||||
WGPUAddressMode_ClampToEdge = 0,
|
||||
WGPUAddressMode_Repeat = 1,
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "wgpu-native"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
authors = [
|
||||
"Dzmitry Malyshau <kvark@mozilla.com>",
|
||||
"Joshua Groves <josh@joshgroves.com>",
|
||||
|
@ -1120,6 +1120,7 @@ pub extern "C" fn wgpu_queue_submit(
|
||||
for &cmb_id in command_buffer_ids {
|
||||
let comb = &mut command_buffer_guard[cmb_id];
|
||||
swap_chain_links.extend(comb.swap_chain_links.drain(..));
|
||||
|
||||
// update submission IDs
|
||||
for id in comb.trackers.buffers.used() {
|
||||
buffer_guard[id]
|
||||
@ -1172,18 +1173,21 @@ pub extern "C" fn wgpu_queue_submit(
|
||||
let command_buffer_guard = HUB.command_buffers.read();
|
||||
let surface_guard = HUB.surfaces.read();
|
||||
|
||||
let wait_semaphores = swap_chain_links.into_iter().flat_map(|link| {
|
||||
//TODO: check the epoch
|
||||
surface_guard[link.swap_chain_id]
|
||||
.swap_chain
|
||||
.as_ref()
|
||||
.map(|swap_chain| {
|
||||
(
|
||||
&swap_chain.frames[link.image_index as usize].sem_available,
|
||||
hal::pso::PipelineStage::COLOR_ATTACHMENT_OUTPUT,
|
||||
)
|
||||
})
|
||||
});
|
||||
let wait_semaphores = swap_chain_links
|
||||
.into_iter()
|
||||
.flat_map(|link| {
|
||||
let swap_chain = surface_guard[link.swap_chain_id].swap_chain.as_ref()?;
|
||||
let frame = &swap_chain.frames[link.image_index as usize];
|
||||
let mut wait_for_epoch = frame.wait_for_epoch.lock();
|
||||
let current_epoch = *wait_for_epoch.as_ref()?;
|
||||
if link.epoch < current_epoch {
|
||||
None
|
||||
} else {
|
||||
debug_assert_eq!(link.epoch, current_epoch);
|
||||
*wait_for_epoch = None;
|
||||
Some((&frame.sem_available, hal::pso::PipelineStage::COLOR_ATTACHMENT_OUTPUT))
|
||||
}
|
||||
});
|
||||
|
||||
let submission =
|
||||
hal::queue::Submission::<_, _, &[<back::Backend as hal::Backend>::Semaphore]> {
|
||||
@ -1704,6 +1708,7 @@ pub fn swap_chain_populate_textures(
|
||||
fence: device.raw.create_fence(true).unwrap(),
|
||||
sem_available: device.raw.create_semaphore().unwrap(),
|
||||
sem_present: device.raw.create_semaphore().unwrap(),
|
||||
wait_for_epoch: Mutex::new(None),
|
||||
comb: swap_chain.command_pool.acquire_command_buffer(),
|
||||
});
|
||||
}
|
||||
|
@ -22,8 +22,10 @@ pub(crate) struct SwapChainLink<E> {
|
||||
}
|
||||
|
||||
impl SwapChainLink<Mutex<SwapImageEpoch>> {
|
||||
pub fn bump_epoch(&self) {
|
||||
*self.epoch.lock() += 1;
|
||||
pub fn bump_epoch(&self) -> SwapImageEpoch {
|
||||
let mut epoch = self.epoch.lock();
|
||||
*epoch += 1;
|
||||
*epoch
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +49,7 @@ pub(crate) struct Frame<B: hal::Backend> {
|
||||
pub fence: B::Fence,
|
||||
pub sem_available: B::Semaphore,
|
||||
pub sem_present: B::Semaphore,
|
||||
pub wait_for_epoch: Mutex<Option<SwapImageEpoch>>,
|
||||
pub comb: hal::command::CommandBuffer<B, hal::General, hal::command::MultiShot>,
|
||||
}
|
||||
|
||||
@ -146,11 +149,13 @@ pub extern "C" fn wgpu_swap_chain_get_next_texture(swap_chain_id: SwapChainId) -
|
||||
}
|
||||
mem::swap(&mut frame.sem_available, &mut swap_chain.sem_available);
|
||||
|
||||
HUB.textures.read()[frame.texture_id.value]
|
||||
let frame_epoch = HUB.textures.read()[frame.texture_id.value]
|
||||
.placement
|
||||
.as_swap_chain()
|
||||
.bump_epoch();
|
||||
|
||||
*frame.wait_for_epoch.lock() = Some(frame_epoch);
|
||||
|
||||
SwapChainOutput {
|
||||
texture_id: frame.texture_id.value,
|
||||
view_id: frame.view_id.value,
|
||||
|
Loading…
Reference in New Issue
Block a user