Skip to content

Commit 921c6ab

Browse files
authored
[metal] remove extraneous main thread check (#7692)
1 parent 1268219 commit 921c6ab

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ Naga now infers the correct binding layout when a resource appears only in an as
8080

8181
- Get `vertex_index` & `instance_index` builtins working for indirect draws. By @teoxoy in [#7535](https://github.com/gfx-rs/wgpu/pull/7535)
8282

83+
#### Metal
84+
85+
- Remove extraneous main thread warning in `fn surface_capabilities()`. By @jamesordner in [#7692](https://github.com/gfx-rs/wgpu/pull/7692)
86+
8387
### Changes
8488

8589
- Loosen Viewport validation requirements to match the [new specs](https://github.com/gpuweb/gpuweb/pull/5025). By @ebbdrop in [#7564](https://github.com/gfx-rs/wgpu/pull/7564)

wgpu-hal/src/metal/adapter.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use parking_lot::Mutex;
77
use wgt::{AstcBlock, AstcChannel};
88

99
use alloc::sync::Arc;
10-
use std::thread;
1110

1211
use super::TimestampQuerySupport;
1312

@@ -342,13 +341,6 @@ impl crate::Adapter for super::Adapter {
342341
&self,
343342
surface: &super::Surface,
344343
) -> Option<crate::SurfaceCapabilities> {
345-
let current_extent = if surface.main_thread_id == thread::current().id() {
346-
Some(surface.dimensions())
347-
} else {
348-
log::warn!("Unable to get the current view dimensions on a non-main thread");
349-
None
350-
};
351-
352344
let mut formats = vec![
353345
wgt::TextureFormat::Bgra8Unorm,
354346
wgt::TextureFormat::Bgra8UnormSrgb,
@@ -380,7 +372,7 @@ impl crate::Adapter for super::Adapter {
380372
wgt::CompositeAlphaMode::PostMultiplied,
381373
],
382374

383-
current_extent,
375+
current_extent: Some(surface.dimensions()),
384376
usage: wgt::TextureUses::COLOR_TARGET
385377
| wgt::TextureUses::COPY_SRC
386378
| wgt::TextureUses::COPY_DST

wgpu-hal/src/metal/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ mod time;
2828

2929
use alloc::{borrow::ToOwned as _, string::String, sync::Arc, vec::Vec};
3030
use core::{fmt, iter, ops, ptr::NonNull, sync::atomic};
31-
use std::thread;
3231

3332
use arrayvec::ArrayVec;
3433
use bitflags::bitflags;
@@ -376,7 +375,6 @@ pub struct Surface {
376375
render_layer: Mutex<metal::MetalLayer>,
377376
swapchain_format: RwLock<Option<wgt::TextureFormat>>,
378377
extent: RwLock<wgt::Extent3d>,
379-
main_thread_id: thread::ThreadId,
380378
// Useful for UI-intensive applications that are sensitive to
381379
// window resizing.
382380
pub present_with_transaction: bool,

wgpu-hal/src/metal/surface.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use alloc::borrow::ToOwned as _;
44
use core::mem::ManuallyDrop;
55
use core::ptr::NonNull;
6-
use std::thread;
76

87
use core_graphics_types::{
98
base::CGFloat,
@@ -29,7 +28,6 @@ impl super::Surface {
2928
render_layer: Mutex::new(layer),
3029
swapchain_format: RwLock::new(None),
3130
extent: RwLock::new(wgt::Extent3d::default()),
32-
main_thread_id: thread::current().id(),
3331
present_with_transaction: false,
3432
}
3533
}
@@ -109,6 +107,13 @@ impl super::Surface {
109107
}
110108
}
111109

110+
/// Gets the current dimensions of the `Surface`.
111+
///
112+
/// This function is safe to call off of the main thread. However, note that
113+
/// `bounds` and `contentsScale` may be modified by the main thread while
114+
/// this function is running, possibly resulting in the two values being out
115+
/// of sync. This is sound, as these properties are accessed atomically.
116+
/// See: <https://github.com/gfx-rs/wgpu/pull/7692>
112117
pub(super) fn dimensions(&self) -> wgt::Extent3d {
113118
let (size, scale): (CGSize, CGFloat) = unsafe {
114119
let render_layer_borrow = self.render_layer.lock();

0 commit comments

Comments
 (0)