Skip to content

Commit 677f0cc

Browse files
committed
metal: fix Simulator and Catalyst GPU capability detection
Simulator and Catalyst run on Mac GPU but Metal reports iOS-level capabilities. This causes wrong buffer alignment and missing feature flags like indirect execution. Tested with Vello on iPhone Simulator (iOS 18.2, Apple Silicon). Fixes #7057
1 parent be1a711 commit 677f0cc

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

wgpu-hal/src/metal/adapter.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ impl super::CapabilitiesQuery {
592592
//
593593
// Along with the different OSes, there is also two other modes that
594594
// applications can run in: the Simulator, and Mac Catalyst. This can
595-
// be detected using `cfg!(target_env = "sim")` or
596-
// `cfg!(target_env = "macabi")`.
595+
// be detected using `cfg!(target_abi = "sim")` or
596+
// `cfg!(target_abi = "macabi")`.
597597
//
598598
// Finally, iOS applications can be run on macOS and visionOS directly
599599
// using the "Designed for iPad" mode. This cannot be detected at
@@ -610,6 +610,13 @@ impl super::CapabilitiesQuery {
610610
let version = NSProcessInfo::processInfo().operatingSystemVersion();
611611
let os_type = super::OsType::new(version, device);
612612

613+
// Whether the actual GPU is Mac hardware (Simulator / Catalyst).
614+
let runs_on_mac: bool = cfg!(any(
615+
target_os = "macos",
616+
target_abi = "macabi",
617+
target_abi = "sim"
618+
));
619+
613620
let family_check = available!(macos = 10.15, ios = 13.0, tvos = 13.0, visionos = 1.0);
614621
let metal3 = family_check && device.supportsFamily(MTLGPUFamily::Metal3);
615622
let metal4 = family_check && device.supportsFamily(MTLGPUFamily::Metal4);
@@ -708,11 +715,12 @@ impl super::CapabilitiesQuery {
708715
MUTABLE_COMPARISON_SAMPLER_SUPPORT,
709716
),
710717
sampler_clamp_to_border: Self::supports_any(device, SAMPLER_CLAMP_TO_BORDER_SUPPORT),
711-
indirect_draw_dispatch: Self::supports_any(device, INDIRECT_DRAW_DISPATCH_SUPPORT),
718+
indirect_draw_dispatch: Self::supports_any(device, INDIRECT_DRAW_DISPATCH_SUPPORT)
719+
|| runs_on_mac,
712720
base_vertex_first_instance_drawing: Self::supports_any(
713721
device,
714722
BASE_VERTEX_FIRST_INSTANCE_SUPPORT,
715-
),
723+
) || runs_on_mac,
716724
dual_source_blending: Self::supports_any(device, DUAL_SOURCE_BLEND_SUPPORT),
717725
low_power: os_type != super::OsType::Macos || device.isLowPower(),
718726
headless: os_type == super::OsType::Macos && device.isHeadless(),
@@ -835,7 +843,9 @@ impl super::CapabilitiesQuery {
835843
16
836844
},
837845
// "Buffer alignment for copying an existing texture to a buffer"
838-
buffer_alignment: if matches!(os_type, super::OsType::Macos | super::OsType::VisionOs) {
846+
buffer_alignment: if matches!(os_type, super::OsType::Macos | super::OsType::VisionOs)
847+
|| runs_on_mac
848+
{
839849
256
840850
} else if family_check && device.supportsFamily(MTLGPUFamily::Apple3) {
841851
16
@@ -846,7 +856,8 @@ impl super::CapabilitiesQuery {
846856
constant_buffer_offset_alignment: if matches!(
847857
os_type,
848858
super::OsType::Macos | super::OsType::VisionOs
849-
) {
859+
) || runs_on_mac
860+
{
850861
256
851862
} else if device.supportsFeatureSet(MTLFeatureSet::macOS_GPUFamily2_v1) {
852863
32

0 commit comments

Comments
 (0)