Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metal: set max_buffer_size by the correct physical device restriction #2502

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use mtl::{MTLFeatureSet, MTLGPUFamily, MTLLanguageVersion};
use objc::{class, msg_send, sel, sel_impl};
use objc::{
class, msg_send,
runtime::{BOOL, YES},
sel, sel_impl,
};
use parking_lot::Mutex;
use wgt::{AstcBlock, AstcChannel};

Expand Down Expand Up @@ -819,10 +823,18 @@ impl super::PrivateCapabilities {
max_textures_per_stage: if os_is_mac { 128 } else { 31 },
max_samplers_per_stage: 16,
buffer_alignment: if os_is_mac { 256 } else { 64 },
max_buffer_size: if device.supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v2) {
1 << 30 // 1GB on macOS 1.2 and up
} else {
1 << 28 // 256MB otherwise
max_buffer_size: unsafe {
let sel = sel!(maxBufferLength);
let can_use: BOOL = msg_send![device.as_ref(), respondsToSelector: sel];
if can_use == YES {
// maxBufferLength available on macOS 10.14+ and iOS 12.0+
let buffer_size: mtl::NSInteger = msg_send![device.as_ref(), maxBufferLength];
buffer_size as _
} else if os_is_mac {
1 << 30 // 1GB on macOS 10.11 and up
} else {
1 << 28 // 256MB on iOS 8.0+
}
},
max_texture_size: if Self::supports_any(
device,
Expand Down
30 changes: 6 additions & 24 deletions wgpu-hal/src/metal/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,12 @@ impl super::Surface {
}

pub(super) fn dimensions(&self) -> wgt::Extent3d {
let (size, scale): (CGSize, CGFloat) = match self.view {
Some(view) if !cfg!(target_os = "macos") => unsafe {
let bounds: CGRect = msg_send![view.as_ptr(), bounds];
let window: Option<NonNull<Object>> = msg_send![view.as_ptr(), window];
let screen = window.and_then(|window| -> Option<NonNull<Object>> {
msg_send![window.as_ptr(), screen]
});
match screen {
Some(screen) => {
let screen_space: *mut Object = msg_send![screen.as_ptr(), coordinateSpace];
let rect: CGRect = msg_send![view.as_ptr(), convertRect:bounds toCoordinateSpace:screen_space];
let scale_factor: CGFloat = msg_send![screen.as_ptr(), nativeScale];
(rect.size, scale_factor)
}
None => (bounds.size, 1.0),
}
},
_ => unsafe {
let render_layer_borrow = self.render_layer.lock();
let render_layer = render_layer_borrow.as_ref();
let bounds: CGRect = msg_send![render_layer, bounds];
let contents_scale: CGFloat = msg_send![render_layer, contentsScale];
(bounds.size, contents_scale)
},
let (size, scale): (CGSize, CGFloat) = unsafe {
let render_layer_borrow = self.render_layer.lock();
let render_layer = render_layer_borrow.as_ref();
let bounds: CGRect = msg_send![render_layer, bounds];
let contents_scale: CGFloat = msg_send![render_layer, contentsScale];
(bounds.size, contents_scale)
};

wgt::Extent3d {
Expand Down