Skip to content

Commit

Permalink
Fix definition of NSOperatingSystemVersion
Browse files Browse the repository at this point in the history
The `NSOperatingSystemVersion` struct doesn't contain an `is_mac` flag,
so the cast in `msg_send![process_info, operatingSystemVersion]` is
invalid.
  • Loading branch information
grovesNL committed Mar 4, 2023
1 parent 54e4c86 commit 187ff0b
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,11 @@ impl super::PrivateCapabilities {
major: usize,
minor: usize,
patch: usize,
is_mac: bool,
}

impl NSOperatingSystemVersion {
fn at_least(&self, mac_version: (usize, usize), ios_version: (usize, usize)) -> bool {
if self.is_mac {
fn at_least(&self, mac_version: (usize, usize), ios_version: (usize, usize), is_mac: bool) -> bool {
if is_mac {
self.major > mac_version.0
|| (self.major == mac_version.0 && self.minor >= mac_version.1)
} else {
Expand All @@ -474,8 +473,7 @@ impl super::PrivateCapabilities {
};

let os_is_mac = device.supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v1);
version.is_mac = os_is_mac;
let family_check = version.at_least((10, 15), (13, 0));
let family_check = version.at_least((10, 15), (13, 0), os_is_mac);

let mut sample_count_mask = crate::TextureFormatCapabilities::MULTISAMPLE_X4; // 1 and 4 samples are supported on all devices
if device.supports_texture_sample_count(2) {
Expand All @@ -488,9 +486,9 @@ impl super::PrivateCapabilities {
sample_count_mask |= crate::TextureFormatCapabilities::MULTISAMPLE_X16;
}

let rw_texture_tier = if version.at_least((10, 13), (11, 0)) {
let rw_texture_tier = if version.at_least((10, 13), (11, 0), os_is_mac) {
device.read_write_texture_support()
} else if version.at_least((10, 12), OS_NOT_SUPPORT) {
} else if version.at_least((10, 12), OS_NOT_SUPPORT, os_is_mac) {
if Self::supports_any(device, &[MTLFeatureSet::macOS_ReadWriteTextureTier2]) {
MTLReadWriteTextureTier::Tier2
} else {
Expand All @@ -502,25 +500,25 @@ impl super::PrivateCapabilities {

Self {
family_check,
msl_version: if version.at_least((12, 0), (15, 0)) {
msl_version: if version.at_least((12, 0), (15, 0), os_is_mac) {
MTLLanguageVersion::V2_4
} else if version.at_least((11, 0), (14, 0)) {
} else if version.at_least((11, 0), (14, 0), os_is_mac) {
MTLLanguageVersion::V2_3
} else if version.at_least((10, 15), (13, 0)) {
} else if version.at_least((10, 15), (13, 0), os_is_mac) {
MTLLanguageVersion::V2_2
} else if version.at_least((10, 14), (12, 0)) {
} else if version.at_least((10, 14), (12, 0), os_is_mac) {
MTLLanguageVersion::V2_1
} else if version.at_least((10, 13), (11, 0)) {
} else if version.at_least((10, 13), (11, 0), os_is_mac) {
MTLLanguageVersion::V2_0
} else if version.at_least((10, 12), (10, 0)) {
} else if version.at_least((10, 12), (10, 0), os_is_mac) {
MTLLanguageVersion::V1_2
} else if version.at_least((10, 11), (9, 0)) {
} else if version.at_least((10, 11), (9, 0), os_is_mac) {
MTLLanguageVersion::V1_1
} else {
MTLLanguageVersion::V1_0
},
// macOS 10.11 doesn't support read-write resources
fragment_rw_storage: version.at_least((10, 12), (8, 0)),
fragment_rw_storage: version.at_least((10, 12), (8, 0), os_is_mac),
read_write_texture_tier: rw_texture_tier,
msaa_desktop: os_is_mac,
msaa_apple3: if family_check {
Expand All @@ -537,7 +535,7 @@ impl super::PrivateCapabilities {
MUTABLE_COMPARISON_SAMPLER_SUPPORT,
),
sampler_clamp_to_border: Self::supports_any(device, SAMPLER_CLAMP_TO_BORDER_SUPPORT),
sampler_lod_average: { version.at_least((11, 0), (9, 0)) },
sampler_lod_average: { version.at_least((11, 0), (9, 0), os_is_mac) },
base_instance: Self::supports_any(device, BASE_INSTANCE_SUPPORT),
base_vertex_instance_drawing: Self::supports_any(device, BASE_VERTEX_INSTANCE_SUPPORT),
dual_source_blending: Self::supports_any(device, DUAL_SOURCE_BLEND_SUPPORT),
Expand Down Expand Up @@ -626,7 +624,7 @@ impl super::PrivateCapabilities {
},
max_samplers_per_stage: 16,
buffer_alignment: if os_is_mac { 256 } else { 64 },
max_buffer_size: if version.at_least((10, 14), (12, 0)) {
max_buffer_size: if version.at_least((10, 14), (12, 0), os_is_mac) {
// maxBufferLength available on macOS 10.14+ and iOS 12.0+
let buffer_size: metal::NSInteger =
unsafe { msg_send![device.as_ref(), maxBufferLength] };
Expand Down Expand Up @@ -710,10 +708,10 @@ impl super::PrivateCapabilities {
supports_binary_archives: family_check
&& (device.supports_family(MTLGPUFamily::Apple3)
|| device.supports_family(MTLGPUFamily::Mac1)),
supports_capture_manager: version.at_least((10, 13), (11, 0)),
can_set_maximum_drawables_count: version.at_least((10, 14), (11, 2)),
can_set_display_sync: version.at_least((10, 13), OS_NOT_SUPPORT),
can_set_next_drawable_timeout: version.at_least((10, 13), (11, 0)),
supports_capture_manager: version.at_least((10, 13), (11, 0), os_is_mac),
can_set_maximum_drawables_count: version.at_least((10, 14), (11, 2), os_is_mac),
can_set_display_sync: version.at_least((10, 13), OS_NOT_SUPPORT, os_is_mac),
can_set_next_drawable_timeout: version.at_least((10, 13), (11, 0), os_is_mac),
supports_arrays_of_textures: Self::supports_any(
device,
&[
Expand All @@ -726,14 +724,14 @@ impl super::PrivateCapabilities {
&& (device.supports_family(MTLGPUFamily::Apple6)
|| device.supports_family(MTLGPUFamily::Mac1)
|| device.supports_family(MTLGPUFamily::MacCatalyst1)),
supports_mutability: version.at_least((10, 13), (11, 0)),
supports_mutability: version.at_least((10, 13), (11, 0), os_is_mac),
//Depth clipping is supported on all macOS GPU families and iOS family 4 and later
supports_depth_clip_control: os_is_mac
|| device.supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v1),
supports_preserve_invariance: version.at_least((11, 0), (13, 0)),
supports_preserve_invariance: version.at_least((11, 0), (13, 0), os_is_mac),
// Metal 2.2 on mac, 2.3 on iOS.
supports_shader_primitive_index: version.at_least((10, 15), (14, 0)),
has_unified_memory: if version.at_least((10, 15), (13, 0)) {
supports_shader_primitive_index: version.at_least((10, 15), (14, 0), os_is_mac),
has_unified_memory: if version.at_least((10, 15), (13, 0), os_is_mac) {
Some(device.has_unified_memory())
} else {
None
Expand Down

0 comments on commit 187ff0b

Please sign in to comment.