How to get programmatically the maximum texture size (width and height) with metal? with openGL i can do: glGetIntegerv(GL_MAX_TEXTURE_SIZE, ...)
but how to do it with Metal ?
Asked
Active
Viewed 2,835 times
5

zeus
- 12,173
- 9
- 63
- 184
-
@trojanfoe off course, why you say i never accept answers ? – zeus Oct 14 '19 at 10:58
-
1Because looking at your profile I saw your last 10 questions going unaccepted. – trojanfoe Oct 14 '19 at 11:24
-
You should really switch the accepted answer to @codeTiger, he was the one that told you programmatically how to do exactly what you asked. – David H Jan 03 '22 at 19:32
-
1@DavidH done :) i forget – zeus Jan 04 '22 at 11:00
3 Answers
6
There is currently no API for retrieving the maximum texture dimensions of a Metal device. You should consult the Metal Feature Set Tables for this information and include it in your app instead.
For A9 and newer GPUs running current versions of iOS/tvOS/iPadOS, the maximum size of a 2D texture is 16384×16384.

warrenm
- 31,094
- 6
- 92
- 116
3
As @warrenm has mentioned, it is programmatically not possible to get the maximum texture size supported by the device. However, the below code will give you the hardcoded size based on the device type.
int maxTexSize = 4096;
if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1] || [mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) {
maxTexSize = 16384;
else if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v2] || [mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v2]) {
maxTexSize = 8192;
} else {
maxTexSize = 4096;
}

codetiger
- 2,650
- 20
- 37
3
There is a new API in iOS13 that should make this process a bit more robust (for iOS devices):
// If you use this you must be on iOS 13, so the code is valid for any device running that
func maxTextureDimension2(mtlDevice: MTLDevice) -> Int {
// https://developer.apple.com/documentation/metal/mtldevice/3143473-supportsfamily
let maxTexSize = mtlDevice.supportsFamily(.apple3) ? 16384 : 8192
return maxTexSize
}
If deploying to older iOS then use @codeTiger's answer.
PS: the algorithm is directly from Warren Moore.

David H
- 40,852
- 12
- 92
- 138