Skip to content

Instantly share code, notes, and snippets.

@kylehowells
Created July 9, 2020 03:03
Show Gist options
  • Save kylehowells/63d0723abc9588eb734cade4b7df660d to your computer and use it in GitHub Desktop.
Save kylehowells/63d0723abc9588eb734cade4b7df660d to your computer and use it in GitHub Desktop.
Get the maximum supported Metal texture size for the current device on iOS or macOS.
import SceneKit
import CoreGraphics
static func getMaxImageWidth() -> Int {
let device = MTLCreateSystemDefaultDevice()!
// According to the Metal Feature Set Tables there are only two supported maximum resolutions
// 16384px for macs and the latest iOS devices
// 8192px for the older iOS devices
// Older Apple devices used to be limited to 4,096, 2,048 or even 1,024, but are no longer supported
// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
if device.supportsFamily(MTLGPUFamily.macCatalyst1) ||
device.supportsFamily(MTLGPUFamily.mac1) ||
device.supportsFamily(MTLGPUFamily.apple3) {
return 16384
}
return 8192
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment