Skip to content

Commit a4f727b

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 a4f727b

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

wgpu-hal/src/metal/adapter.rs

Lines changed: 14 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,10 @@ 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 =
615+
cfg!(any(target_os = "macos", target_abi = "macabi", target_abi = "sim"));
616+
613617
let family_check = available!(macos = 10.15, ios = 13.0, tvos = 13.0, visionos = 1.0);
614618
let metal3 = family_check && device.supportsFamily(MTLGPUFamily::Metal3);
615619
let metal4 = family_check && device.supportsFamily(MTLGPUFamily::Metal4);
@@ -708,11 +712,12 @@ impl super::CapabilitiesQuery {
708712
MUTABLE_COMPARISON_SAMPLER_SUPPORT,
709713
),
710714
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),
715+
indirect_draw_dispatch: Self::supports_any(device, INDIRECT_DRAW_DISPATCH_SUPPORT)
716+
|| runs_on_mac,
712717
base_vertex_first_instance_drawing: Self::supports_any(
713718
device,
714719
BASE_VERTEX_FIRST_INSTANCE_SUPPORT,
715-
),
720+
) || runs_on_mac,
716721
dual_source_blending: Self::supports_any(device, DUAL_SOURCE_BLEND_SUPPORT),
717722
low_power: os_type != super::OsType::Macos || device.isLowPower(),
718723
headless: os_type == super::OsType::Macos && device.isHeadless(),
@@ -835,7 +840,9 @@ impl super::CapabilitiesQuery {
835840
16
836841
},
837842
// "Buffer alignment for copying an existing texture to a buffer"
838-
buffer_alignment: if matches!(os_type, super::OsType::Macos | super::OsType::VisionOs) {
843+
buffer_alignment: if matches!(os_type, super::OsType::Macos | super::OsType::VisionOs)
844+
|| runs_on_mac
845+
{
839846
256
840847
} else if family_check && device.supportsFamily(MTLGPUFamily::Apple3) {
841848
16
@@ -846,7 +853,8 @@ impl super::CapabilitiesQuery {
846853
constant_buffer_offset_alignment: if matches!(
847854
os_type,
848855
super::OsType::Macos | super::OsType::VisionOs
849-
) {
856+
) || runs_on_mac
857+
{
850858
256
851859
} else if device.supportsFeatureSet(MTLFeatureSet::macOS_GPUFamily2_v1) {
852860
32

0 commit comments

Comments
 (0)