Skip to content

Guard macOS-only MTLDevice selectors for iOS - #115

Closed
yorgunkral31 wants to merge 1 commit into
renderbag:mainfrom
yorgunkral31:ios-metal-guards
Closed

yorgunkral31 wants to merge 1 commit into
renderbag:mainfrom
yorgunkral31:ios-metal-guards

Conversation

@yorgunkral31

Copy link
Copy Markdown

MTLDevice.location and MTLDevice.recommendedMaxWorkingSetSize are macOS-only selectors. The Metal backend calls both unconditionally during device initialization, which crashes on iOS hardware with -[AGXG17PDevice location]: unrecognized selector sent to instance (verified on an iPhone 16 Pro / A18 Pro while testing hedge-dev/UnleashedRecomp#1767 with the native Metal backend on device).

This guards the call sites for TARGET_OS_IPHONE:

  • the device type reports INTEGRATED (iOS devices are always integrated), and
  • dedicated video memory and the HDR heuristic use NSProcessInfo.physicalMemory instead (unified memory shares system RAM).

No behavior change on macOS. Related to the pending iOS support work in #102 — these guards are needed by any iOS target that builds the Metal backend, independent of that PR.

MTLDevice location and recommendedMaxWorkingSetSize are unavailable on
iOS and crash with unrecognized selector (verified on iPhone 16 Pro /
A18 Pro). iOS devices are always integrated and share system memory, so
report INTEGRATED and use ProcessInfo physicalMemory instead.
Comment thread plume_metal.cpp
Comment on lines +3836 to +3840
#if TARGET_OS_IPHONE
capabilities.preferHDR = NS::ProcessInfo::processInfo()->physicalMemory() > (512 * 1024 * 1024);
#else
capabilities.preferHDR = mtl->recommendedMaxWorkingSetSize() > (512 * 1024 * 1024);
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might as well update this to just check description.dedicatedVideoMemory since it's the same values.

Comment thread plume_metal.cpp
#if TARGET_OS_IPHONE
description.dedicatedVideoMemory = NS::ProcessInfo::processInfo()->physicalMemory();
#else
description.dedicatedVideoMemory = mtl->recommendedMaxWorkingSetSize();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does exist on iOS 16+ by the way, if we could use this on those versions instead.

@squidbus

Copy link
Copy Markdown
Contributor

I did this in a bit more proper way in #116 along with some macOS 27 fixes.

@squidbus squidbus closed this Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants