Skip to content

Commit 814b919

Browse files
committed
Change core to only read lock fence
1 parent 865af59 commit 814b919

6 files changed

Lines changed: 18 additions & 43 deletions

File tree

wgpu-core/src/device/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub mod ray_tracing;
2828
pub mod resource;
2929
#[cfg(any(feature = "trace", feature = "replay"))]
3030
pub mod trace;
31-
pub(crate) use resource::{FenceReadGuard, FenceWriteGuard};
31+
pub(crate) use resource::FenceReadGuard;
3232
pub use {life::WaitIdleError, resource::Device};
3333

3434
pub const SHADER_STAGE_COUNT: usize = hal::MAX_CONCURRENT_SHADER_STAGES;

wgpu-core/src/device/queue.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
CommandAllocator, CommandBuffer, CommandEncoder, CommandEncoderError, CopySide,
2525
TransferError,
2626
},
27-
device::{DeviceError, FenceReadGuard, FenceWriteGuard, WaitIdleError},
27+
device::{DeviceError, FenceReadGuard, WaitIdleError},
2828
get_lowest_common_denom,
2929
global::Global,
3030
hal_label,
@@ -566,7 +566,7 @@ impl WebGpuError for QueueSubmitError {
566566
pub(crate) struct PendingSubmission<'a> {
567567
queue: &'a Queue,
568568
snatch_guard: SnatchGuard<'a>,
569-
fence: FenceWriteGuard<'a>,
569+
fence: FenceReadGuard<'a>,
570570
command_index_guard: RwLockWriteGuard<'a, CommandIndices>,
571571
// Command buffers to be executed, along with trackers for the resources they use.
572572
pub executions: Vec<EncoderInFlight>,
@@ -1557,7 +1557,7 @@ impl Queue {
15571557
) -> (PendingSubmission<'a>, SubmissionIndex) {
15581558
// Lock ordering requires that the fence lock be acquired after the snatch lock and
15591559
// before the command index lock.
1560-
let fence = self.device.fence.write();
1560+
let fence = self.device.fence.read();
15611561

15621562
let mut command_index_guard = self.device.command_indices.write();
15631563
command_index_guard.active_submission_index += 1;
@@ -1600,7 +1600,7 @@ impl Queue {
16001600
let PendingSubmission {
16011601
queue: _,
16021602
snatch_guard,
1603-
mut fence,
1603+
fence,
16041604
command_index_guard,
16051605
mut executions,
16061606
mut surface_textures,
@@ -1671,7 +1671,7 @@ impl Queue {
16711671
self.raw().submit(
16721672
&hal_command_buffers,
16731673
&submit_surface_textures,
1674-
(fence.as_mut(), submit_index),
1674+
(fence.as_ref(), submit_index),
16751675
)
16761676
}
16771677
.map_err(|e| self.device.handle_hal_error(e))?;
@@ -1692,7 +1692,7 @@ impl Queue {
16921692
self.lock_life().track_submission(submit_index, executions);
16931693

16941694
Ok(SubmissionResult {
1695-
fence: RwLockWriteGuard::downgrade(fence),
1695+
fence,
16961696
snatch_guard,
16971697
})
16981698
}

wgpu-core/src/device/resource.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::{
4141
TextureInitTrackerAction,
4242
},
4343
instance::{Adapter, RequestDeviceError},
44-
lock::{rank, Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard},
44+
lock::{rank, Mutex, RwLock, RwLockReadGuard},
4545
pipeline::{self, ColorStateError},
4646
pool::ResourcePool,
4747
present,
@@ -289,7 +289,6 @@ pub struct Device {
289289
}
290290

291291
pub(crate) type FenceReadGuard<'a> = RwLockReadGuard<'a, ManuallyDrop<Box<dyn hal::DynFence>>>;
292-
pub(crate) type FenceWriteGuard<'a> = RwLockWriteGuard<'a, ManuallyDrop<Box<dyn hal::DynFence>>>;
293292

294293
pub(crate) enum DeferredDestroy {
295294
TextureViews(WeakVec<TextureView>),

wgpu-core/src/lock/observing.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,6 @@ impl<'a, T> RwLockReadGuard<'a, T> {
185185
}
186186
}
187187

188-
impl<'a, T> RwLockWriteGuard<'a, T> {
189-
pub fn downgrade(this: Self) -> RwLockReadGuard<'a, T> {
190-
RwLockReadGuard {
191-
inner: parking_lot::RwLockWriteGuard::downgrade(this.inner),
192-
_state: this._state,
193-
}
194-
}
195-
}
196-
197188
impl<T: core::fmt::Debug> core::fmt::Debug for RwLock<T> {
198189
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
199190
self.inner.fmt(f)
@@ -226,11 +217,11 @@ impl<'a, T> core::ops::DerefMut for RwLockWriteGuard<'a, T> {
226217
///
227218
/// This type serves two purposes:
228219
///
229-
/// - Operations like `RwLockWriteGuard::downgrade` would like to be able to
230-
/// destructure lock guards and reassemble their pieces into new guards, but
231-
/// if the guard type itself implements `Drop`, we can't destructure it
232-
/// without unsafe code or pointless `Option`s whose state is almost always
233-
/// statically known.
220+
/// - Operations would like to be able to destructure lock guards and
221+
/// reassemble their pieces into new guards, but if the guard type
222+
/// itself implements `Drop`, we can't destructure it without unsafe
223+
/// code or pointless `Option`s whose state is almost always statically
224+
/// known.
234225
///
235226
/// - We can just implement `Drop` for this type once, and then use it in lock
236227
/// guards, rather than implementing `Drop` separately for each guard type.

wgpu-core/src/lock/ranked.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ impl LockState {
110110
///
111111
/// This type serves two purposes:
112112
///
113-
/// - Operations like `RwLockWriteGuard::downgrade` would like to be able to
114-
/// destructure lock guards and reassemble their pieces into new guards, but
115-
/// if the guard type itself implements `Drop`, we can't destructure it
116-
/// without unsafe code or pointless `Option`s whose state is almost always
117-
/// statically known.
113+
/// - Operations would like to be able to destructure lock guards and
114+
/// reassemble their pieces into new guards, but if the guard type
115+
/// itself implements `Drop`, we can't destructure it without unsafe
116+
/// code or pointless `Option`s whose state is almost always statically
117+
/// known.
118118
///
119119
/// - We can just implement `Drop` for this type once, and then use it in lock
120120
/// guards, rather than implementing `Drop` separately for each guard type.
@@ -299,15 +299,6 @@ impl<'a, T> RwLockReadGuard<'a, T> {
299299
}
300300
}
301301

302-
impl<'a, T> RwLockWriteGuard<'a, T> {
303-
pub fn downgrade(this: Self) -> RwLockReadGuard<'a, T> {
304-
RwLockReadGuard {
305-
inner: parking_lot::RwLockWriteGuard::downgrade(this.inner),
306-
saved: this.saved,
307-
}
308-
}
309-
}
310-
311302
impl<T: fmt::Debug> fmt::Debug for RwLock<T> {
312303
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
313304
self.inner.fmt(f)

wgpu-core/src/lock/vanilla.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ impl<'a, T> RwLockReadGuard<'a, T> {
116116
}
117117
}
118118

119-
impl<'a, T> RwLockWriteGuard<'a, T> {
120-
pub fn downgrade(this: Self) -> RwLockReadGuard<'a, T> {
121-
RwLockReadGuard(parking_lot::RwLockWriteGuard::downgrade(this.0))
122-
}
123-
}
124-
125119
impl<T: fmt::Debug> fmt::Debug for RwLock<T> {
126120
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127121
self.0.fmt(f)

0 commit comments

Comments
 (0)