Best technique for iPad 1 vs iPad 2 GPU determination? - ios

The performance of the iPad 2 GPU is way better than the iPad 1. I'd like to switch in my app and add some extra nice graphical subtlety when I know the GPU can handle it.
So I'd like to be able to detect essentially the distinction between the iPad 1 and 2 (and later), ideally using as close to a capability detection as I can. There are plenty of unrelated things I could switch on (presence of camera, etc), but ideally I'd like to find something, maybe an OpenGL capability, that distinguishes the GPU more directly.
This Apple page doesn't list anything useful for iPad 1 vs 2, and this article talks about benchmarking and GPU arch differences but doesn't pinpoint anything that looks like I can query directly (e.g. number of texture units or whatever).
Anyone have any thoughts on how to do this, or am I missing something obvious? Thanks.

One distinction you can query for is maximum texture size. On iPad 2 and iPhone 4S, the maximum texture size is 4096 x 4096, where on all other iOS devices it's 2048 x 2048. It would seem to me to be a safe assumption that future, more powerful iOS devices would also have a maximum texture size at least this large.
To query for the maximum texture size, first create your OpenGL ES context, then set it as the current context and run the following query:
GLint maxTextureSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
On my iPhone 4, this returns 2048 in maxTextureSize, but on my iPad 2 and iPhone 4S this gives back the value of 4096.
You can also test for the presence of some new extensions that the iPad 2 supports, such as EXT_shadow_samplers (more are documented in "What's New in iOS: iOS 5.0"), but those tests will only work on iOS 5.0. Stragglers still on iOS 4.x won't have those capabilities register.

Today with more GPU's available, here is what I came up with for my own needs.
enum GpuClass {
kGpuA5 = 0,
kGpuA6,
kGpuA7,
kGpuA8,
kGpuUnknown,
} ;
- (enum GpuClass)reportGpuClass {
NSString *glVersion = [NSString stringWithUTF8String:(char *)glGetString(GL_VERSION)];
if ([glVersion containsString:#"Apple A5"] || [glVersion containsString:#"S5L8"]) {
NSLog(#"Running on a A5 GPU");
return kGpuA5;
}
if ([glVersion containsString:#"Apple A6"] || [glVersion containsString:#"IMGSGX5"]) {
NSLog(#"Running on a A6 GPU");
return kGpuA6;
}
if ([glVersion containsString:#"Apple A7"] || [glVersion containsString:#"G6430"]) {
NSLog(#"Running on a A7 GPU");
return kGpuA7;
}
if ([glVersion containsString:#"Apple A8"] || [glVersion containsString:#"GXA6850"]) {
NSLog(#"Running on a A8 GPU");
return kGpuA8;
}
return kGpuUnknown;
}
You may further differentiate between specific chips by specifying more full version numbers. e.g. specify IMGSGX543 instead of just IMGSGX5.

Related

Is there a way to know the color (white, black, rose gold, etc) of an iOS device in Swift? [duplicate]

Is there any way or hack to detect on what color (black / white) iPhone, iPad or iPod touch the iOS is installed?
I want to load corresponding UI skins in case of Black or White devices.
There's a private API to retrieve both the DeviceColor and the DeviceEnclosureColor.
UIDevice *device = [UIDevice currentDevice];
SEL selector = NSSelectorFromString(#"deviceInfoForKey:");
if (![device respondsToSelector:selector]) {
selector = NSSelectorFromString(#"_deviceInfoForKey:");
}
if ([device respondsToSelector:selector]) {
NSLog(#"DeviceColor: %# DeviceEnclosureColor: %#", [device performSelector:selector withObject:#"DeviceColor"], [device performSelector:selector withObject:#"DeviceEnclosureColor"]);
}
I've blogged about this and provide a sample app:
http://www.futuretap.com/blog/device-colors/
Warning: As mentioned, this is a private API. Don't use this in App Store builds.
The answer to the question is NO (as of now) and personally I don't think it's worth much, because what if the end-user uses a skin or an additional casing for his iPhone?
I'd suggest to initially ask the user "Hey, what's the color of your phone?" and then do accordingly.
Additionally, a research provided me with this information, I'm not sure if it's TRUE or if is going to help you.
The serial number is the key :)
If aabccdddeef is the serial number of the iPhone 4, ee represents the Color, (A4=black). I hope some of you here check this information with yours to see if this is true.
Just my 2 cents worth - if anyone is looking for the iPhone 5c colors, the colors below are picked from the apple website.
Hope it is of use to anyone:-)
iPhone 5c Colors:
Green
R 179
G 243
B 142
HEX #B3F38E
Blue
R 123
G 195
B 252
HEX #7BC3FC
Yellow
R 255
G 243
B 141
HEX #FFF38D
Red
R 252
G 132
B 142
HEX #FF848E
White
R 239
G 239
B 239
HEX #EFEFEF
According to information sprinkled around the web, the color of the device is encoded in the serial number. iFixit's blog indicates that the third- and second-to-last positions hold the information: xxxxxxxxCCx For an iPhone 4, A4 indicates black. No one seems to have the code for a white iPhone 4, which is strange. One forum posting indicates that it might be DZ. Everyone seems to be just parroting everyone else's information here.
Another site, mydigitallife.com, has an article listing the color codes for various older models. In some cases, the three positions have to be read together in order to determine the color. According to this site, all iPhone 3Gs models have 3N in the color code position; 3NP indicates "Black 16GB 3Gs", and 3NQ indicates "White 16GB 3Gs". The original (2G) iPhone also uses all three positions to indicate size (there were no color options).
There are already a number of questions here on SO that will help you to get the device's serial number.
For debugging purposes I compiled a more comprehensive list of of possible deviceInfoForKey: keys.
Interesting keys to note (for this question) are DeviceRGBColor DeviceEnclosureRGBColor. The values appear to be an integer that represent the RGB value in the form 0x00rrggbb.
Here, for reference, are all the keys I found:
ActiveWirelessTechnology
AirplaneMode
assistant
BasebandCertId
BasebandChipId
BasebandPostponementStatus
BasebandStatus
BatteryCurrentCapacity
BatteryIsCharging
BluetoothAddress
BoardId
BootNonce
BuildVersion
CertificateProductionStatus
CertificateSecurityMode
ChipID
CompassCalibrationDictionary
CPUArchitecture
DeviceClass
DeviceColor
DeviceEnclosureColor
DeviceEnclosureRGBColor
DeviceName
DeviceRGBColor
DeviceSupportsFaceTime
DeviceVariant
DeviceVariantGuess
DiagData
dictation
DiskUsage
EffectiveProductionStatus
EffectiveProductionStatusAp
EffectiveProductionStatusSEP
EffectiveSecurityMode
EffectiveSecurityModeAp
EffectiveSecurityModeSEP
FirmwarePreflightInfo
FirmwareVersion
FrontFacingCameraHFRCapability
HardwarePlatform
HasSEP
HWModelStr
Image4Supported
InternalBuild
InverseDeviceID
ipad
MixAndMatchPrevention
MLBSerialNumber
MobileSubscriberCountryCode
MobileSubscriberNetworkCode
ModelNumber
PartitionType
PasswordProtected
ProductName
ProductType
ProductVersion
ProximitySensorCalibrationDictionary
RearFacingCameraHFRCapability
RegionCode
RegionInfo
SDIOManufacturerTuple
SDIOProductInfo
SerialNumber
SIMTrayStatus
SoftwareBehavior
SoftwareBundleVersion
SupportedDeviceFamilies
SupportedKeyboards
telephony
UniqueChipID
UniqueDeviceID
UserAssignedDeviceName
wifi
WifiVendor
As others have noted, no, there is no official way of getting this information. Apple clearly knows (look in iTunes when you sync), so they could make it available. Might be worth raising a Radar.

Trouble with phone number in ipad mini

I am developing an app that shows a 10 digit number. When I run it in my iPhone 6 it shows ok. It displays 8183874201. But when I run it in my old iPad Mini it show the number in a format like this -467821389.
The code I am running is:
var telefonoCasaStaff = self.timelineData[0].objectForKey("TelCasa") as Int
self.telCasaTextLabel.text = String(telefonoCasaStaff)
Any ideas?
Int is a 64-bit integer on 64-bit devices, and a 32-bit integer
on 32-bit devices.
8183874201 = 0x1E7CC0299 exceeds the range of 32-bit integers, and
apparently is truncated to 32-bit.
You could use Int64, but generally, storing phone numbers
as integers makes not much sense, and you should use strings instead.

iPad missing OpenGL extension string GL_APPLE_texture_2D_limited_npot

In my iOS game, I want to use the GL_APPLE_texture_2D_limited_npot extension when available to save memory (the game have NPOT textures, and in my current implementation I add some padding to make those power of two).
I am testing in my iPad (first generation). Every thing I have read so far says that all iOS devices which supports OpenGLES2 (including iPad) also support GL_APPLE_texture_2D_limited_npot (which is very good, since my game use OpenGLES2). I have tested in my iPad, and it does support (I removed the padding and the images work if I set wrap to GL_CLAMP_TO_EDGE), but the extension does not show when I call glGetString(GL_EXTENSIONS). The code:
const char *extensions = (const char *)glGetString(GL_EXTENSIONS);
std::cout << extensions << "\n";
Results in:
GL_OES_depth_texture GL_OES_depth24 GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_half_float GL_OES_vertex_array_object GL_EXT_blend_minmax GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_read_format_bgra GL_EXT_separate_shader_objects GL_EXT_shader_texture_lod GL_EXT_texture_filter_anisotropic GL_APPLE_framebuffer_multisample GL_APPLE_rgb_422 GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_IMG_read_format GL_IMG_texture_compression_pvrtc
Why does this extension does not show with glGetString(GL_EXTENSIONS)? What is the proper way to check for it? Does all OpenGLES2 iOS devices really support it?
OpenGL ES 2.0 supports non power of 2 textures in specification. There is no need for extension. Here is the spec: http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf (Page 69):
If wt and ht are the specified image width and height, and if either wt or ht are
less than zero, then the error INVALID_VALUE is generated.
The maximum allowable width and height of a two-dimensional texture image
must be at least 2k-lod for image arrays of level zero through k, where k is the log
base 2 of MAX_TEXTURE_SIZE. and lod is the level-of-detail of the image array.
It may be zero for image arrays of any level-of-detail greater than k. The error
INVALID_VALUE is generated if the specified image is too large to be stored under
any conditions.
Not a word about power of two restriction (that is in OpenGL ES 1.x standard).
And if you read the specification of extension - http://www.khronos.org/registry/gles/extensions/APPLE/APPLE_texture_2D_limited_npot.txt, then you'll notice that it is written agains OpenGL ES 1.1 spec.

Detecting Color of iPhone/iPad/iPod touch?

Is there any way or hack to detect on what color (black / white) iPhone, iPad or iPod touch the iOS is installed?
I want to load corresponding UI skins in case of Black or White devices.
There's a private API to retrieve both the DeviceColor and the DeviceEnclosureColor.
UIDevice *device = [UIDevice currentDevice];
SEL selector = NSSelectorFromString(#"deviceInfoForKey:");
if (![device respondsToSelector:selector]) {
selector = NSSelectorFromString(#"_deviceInfoForKey:");
}
if ([device respondsToSelector:selector]) {
NSLog(#"DeviceColor: %# DeviceEnclosureColor: %#", [device performSelector:selector withObject:#"DeviceColor"], [device performSelector:selector withObject:#"DeviceEnclosureColor"]);
}
I've blogged about this and provide a sample app:
http://www.futuretap.com/blog/device-colors/
Warning: As mentioned, this is a private API. Don't use this in App Store builds.
The answer to the question is NO (as of now) and personally I don't think it's worth much, because what if the end-user uses a skin or an additional casing for his iPhone?
I'd suggest to initially ask the user "Hey, what's the color of your phone?" and then do accordingly.
Additionally, a research provided me with this information, I'm not sure if it's TRUE or if is going to help you.
The serial number is the key :)
If aabccdddeef is the serial number of the iPhone 4, ee represents the Color, (A4=black). I hope some of you here check this information with yours to see if this is true.
Just my 2 cents worth - if anyone is looking for the iPhone 5c colors, the colors below are picked from the apple website.
Hope it is of use to anyone:-)
iPhone 5c Colors:
Green
R 179
G 243
B 142
HEX #B3F38E
Blue
R 123
G 195
B 252
HEX #7BC3FC
Yellow
R 255
G 243
B 141
HEX #FFF38D
Red
R 252
G 132
B 142
HEX #FF848E
White
R 239
G 239
B 239
HEX #EFEFEF
According to information sprinkled around the web, the color of the device is encoded in the serial number. iFixit's blog indicates that the third- and second-to-last positions hold the information: xxxxxxxxCCx For an iPhone 4, A4 indicates black. No one seems to have the code for a white iPhone 4, which is strange. One forum posting indicates that it might be DZ. Everyone seems to be just parroting everyone else's information here.
Another site, mydigitallife.com, has an article listing the color codes for various older models. In some cases, the three positions have to be read together in order to determine the color. According to this site, all iPhone 3Gs models have 3N in the color code position; 3NP indicates "Black 16GB 3Gs", and 3NQ indicates "White 16GB 3Gs". The original (2G) iPhone also uses all three positions to indicate size (there were no color options).
There are already a number of questions here on SO that will help you to get the device's serial number.
For debugging purposes I compiled a more comprehensive list of of possible deviceInfoForKey: keys.
Interesting keys to note (for this question) are DeviceRGBColor DeviceEnclosureRGBColor. The values appear to be an integer that represent the RGB value in the form 0x00rrggbb.
Here, for reference, are all the keys I found:
ActiveWirelessTechnology
AirplaneMode
assistant
BasebandCertId
BasebandChipId
BasebandPostponementStatus
BasebandStatus
BatteryCurrentCapacity
BatteryIsCharging
BluetoothAddress
BoardId
BootNonce
BuildVersion
CertificateProductionStatus
CertificateSecurityMode
ChipID
CompassCalibrationDictionary
CPUArchitecture
DeviceClass
DeviceColor
DeviceEnclosureColor
DeviceEnclosureRGBColor
DeviceName
DeviceRGBColor
DeviceSupportsFaceTime
DeviceVariant
DeviceVariantGuess
DiagData
dictation
DiskUsage
EffectiveProductionStatus
EffectiveProductionStatusAp
EffectiveProductionStatusSEP
EffectiveSecurityMode
EffectiveSecurityModeAp
EffectiveSecurityModeSEP
FirmwarePreflightInfo
FirmwareVersion
FrontFacingCameraHFRCapability
HardwarePlatform
HasSEP
HWModelStr
Image4Supported
InternalBuild
InverseDeviceID
ipad
MixAndMatchPrevention
MLBSerialNumber
MobileSubscriberCountryCode
MobileSubscriberNetworkCode
ModelNumber
PartitionType
PasswordProtected
ProductName
ProductType
ProductVersion
ProximitySensorCalibrationDictionary
RearFacingCameraHFRCapability
RegionCode
RegionInfo
SDIOManufacturerTuple
SDIOProductInfo
SerialNumber
SIMTrayStatus
SoftwareBehavior
SoftwareBundleVersion
SupportedDeviceFamilies
SupportedKeyboards
telephony
UniqueChipID
UniqueDeviceID
UserAssignedDeviceName
wifi
WifiVendor
As others have noted, no, there is no official way of getting this information. Apple clearly knows (look in iTunes when you sync), so they could make it available. Might be worth raising a Radar.

How do I detect a dual core CPU on iOS?

My app uses an NSOperationQueue to cache thumbnail images in a background thread. On the iPad2 I can push the concurrent task count limit up to 5 or 6, but on single core devices like the iPad 1 this brings the UI to a grinding halt.
So, I'd like to detect a dual core device (currently only iPad 2) and adapt the concurrent limit appropriately. I know I'm not supposed to check model numbers, rather device features. So what device feature should I be looking for that would tell me whether the cpu is dual core?
Method 1
[[NSProcessInfo processInfo] activeProcessorCount];
NSProcessInfo also has a processorCount property. Learn the difference here.
Method 2
#include <mach/mach_host.h>
unsigned int countCores()
{
host_basic_info_data_t hostInfo;
mach_msg_type_number_t infoCount;
infoCount = HOST_BASIC_INFO_COUNT;
host_info( mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount ) ;
return (unsigned int)(hostInfo.max_cpus);
}
Method 3
#include <sys/sysctl.h>
unsigned int countCores()
{
size_t len;
unsigned int ncpu;
len = sizeof(ncpu);
sysctlbyname ("hw.ncpu",&ncpu,&len,NULL,0);
return ncpu;
}
Just use:
[[NSProcessInfo processInfo] processorCount]
I guess this needs a separate answer rather than a comment:
I wonder what does the number of cores means now that apple brought more asymmetric processing with A10 fusion? Do we have 2.2 cores or 4 cores? apple neglected to make activeProcessorCount float to account for it's fractal nature. note it was like so even before fusion cause they likely had thermal throttling back then. They need either fix overcomittal of nsoperationqueue or come up with a float equivalent for activeProcessorCount and deprecate the activeProcessorCount in its current form that is losing its utility in the face of recent hw advancements
So the faster the Moore's law falls into oblivion or receives a shiny new constant
the more meaningless core counting becomes. Unless you are writing some sort
of a Geek Bench 42, multicore score edition.
Living in the late 2016, to address the underlying issue you are facing rather than hacking through with max concurrent operation prop I assume
you have adjusted the QoS for the NSOperationQueue to .Background?
Me thinks this is a cleaner way to solve your problem with modern
ios sdk then counting 'em cores using miles of rope courtesy of albertamg
Also please take a look at
NSProcessInfoThermalStateDidChangeNotification (macos) and NSProcessInfo.lowPowerModeEnabled (ios)
(I guess an alternative to observing NSProcessInfoThermalStateDidChangeNotification
is to KVo on activeProcessorCount new value)
if you start to account for those new realities, the magic constants adjustments
for multiplying core count would get interesting very fast...
and rot as the new hardware rolls out of cupertino.
And it will be just about as easy to get it right on the current
zoo of Apple hw as to get socket-level networking working correctly:
doable, but by select few in Cupetino with iSteve shadow
looming over the shoulder checking quality ;-)
In Swift you can detect / print the number of active processors with the following code:
let processInfo = ProcessInfo()
print(processInfo.activeProcessorCount)
This code does not need any extra header files or frameworks and works completely natively.
Among other things, you can get that information through a system call...
NSDictionary dictionaryWithObjectsAndKeys:
[self machineType],#"MachineType",
[self humanMachineType],#"HumanMachineType",
[self powerPCTypeString],#"ProcessorType",
[NSNumber numberWithLong:
[self processorClockSpeed]],
#"ProcessorClockSpeed",
[NSNumber numberWithLong:
[self processorClockSpeedInMHz]],
#"ProcessorClockSpeedInMHz",
[NSNumber numberWithInt:[self countProcessors]],
#"CountProcessors",
[self computerName],#"ComputerName",
[self computerSerialNumber],#"ComputerSerialNumber",
[self operatingSystemString],#"OperatingSystem",
[self systemVersionString],#"SystemVersion",
nil];
Here's the reference...
http://cocoadev.com/HowToGetHardwareAndNetworkInfo
I guess:
sysctl(HW_NCPU)
or
sysctlbyname("hw.ncpu", NULL, &size, NULL, 0);
should work.
you can modify code from: Detect the specific iPhone/iPod touch model
Swift 5
To obtain logical cores count use this snippet:
let logicalCoresCount = ProcessInfo.processInfo.processorCount
To obtain physical cores count use below one:
func physicalCoresCount() -> UInt {
var size: size_t = MemoryLayout<UInt>.size
var coresCount: UInt = 0
sysctlbyname("hw.physicalcpu", &coresCount, &size, nil, 0)
return coresCount
}

Resources