aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHao Lu <hlu@fb.com>2017-10-23 15:16:50 -0700
committerMarat Dukhan <marat@fb.com>2017-10-23 15:16:50 -0700
commit3617d5b0f9c19facda2cb6750d9cadf856b0770d (patch)
tree38bed182b326679769c360857d2906595dcdd8cc
parentb1662f4f719fde65be2d4a072005e5e02b88d5fa (diff)
downloadcpuinfo-3617d5b0f9c19facda2cb6750d9cadf856b0770d.tar.gz
Detect GPU name on iOS
-rw-r--r--include/cpuinfo.h6
-rw-r--r--src/arm/mach/init.c8
-rw-r--r--src/gpu/api.h1
-rw-r--r--src/gpu/gles-ios.m43
4 files changed, 54 insertions, 4 deletions
diff --git a/include/cpuinfo.h b/include/cpuinfo.h
index ac12492..cae8af9 100644
--- a/include/cpuinfo.h
+++ b/include/cpuinfo.h
@@ -6,6 +6,10 @@
#include <stdbool.h>
#endif
+#ifdef __APPLE__
+ #include <TargetConditionals.h>
+#endif
+
#include <stdint.h>
/* Identify architecture and define corresponding macro */
@@ -466,7 +470,7 @@ struct cpuinfo_core {
struct cpuinfo_package {
/** SoC or processor chip model name */
char name[CPUINFO_PACKAGE_NAME_MAX];
-#ifdef __ANDROID__
+#if defined(__ANDROID__) || (defined(__APPLE__) && TARGET_OS_IPHONE)
/** Integrated GPU model name */
char gpu_name[CPUINFO_GPU_NAME_MAX];
#endif
diff --git a/src/arm/mach/init.c b/src/arm/mach/init.c
index 648952e..ee552e7 100644
--- a/src/arm/mach/init.c
+++ b/src/arm/mach/init.c
@@ -13,6 +13,7 @@
#include <cpuinfo.h>
#include <mach/api.h>
+#include <gpu/api.h>
#include <api.h>
#include <log.h>
@@ -270,6 +271,7 @@ void cpuinfo_arm_mach_init(void) {
.core_count = cores_per_package,
};
decode_package_name(packages[i].name);
+ cpuinfo_gpu_ios_query_gles2(packages[i].gpu_name);
}
@@ -344,7 +346,7 @@ void cpuinfo_arm_mach_init(void) {
uint32_t threads_per_l1 = 0, l1_count = 0;
if (l1i_cache_size != 0 || l1d_cache_size != 0) {
- /* Assume that L1 caches are private to each core */
+ /* Assume L1 caches are private to each core */
threads_per_l1 = 1;
l1_count = mach_topology.threads / threads_per_l1;
cpuinfo_log_debug("detected %"PRIu32" L1 caches", l1_count);
@@ -352,7 +354,7 @@ void cpuinfo_arm_mach_init(void) {
uint32_t threads_per_l2 = 0, l2_count = 0;
if (l2_cache_size != 0) {
- /* L2 cache is shared between all cores */
+ /* Assume L2 cache is shared between all cores */
threads_per_l2 = mach_topology.cores;
l2_count = 1;
cpuinfo_log_debug("detected %"PRIu32" L2 caches", l2_count);
@@ -360,7 +362,7 @@ void cpuinfo_arm_mach_init(void) {
uint32_t threads_per_l3 = 0, l3_count = 0;
if (l3_cache_size != 0) {
- /* L3 cache is shared between all cores */
+ /* Assume L3 cache is shared between all cores */
threads_per_l3 = mach_topology.cores;
l3_count = 1;
cpuinfo_log_debug("detected %"PRIu32" L3 caches", l3_count);
diff --git a/src/gpu/api.h b/src/gpu/api.h
index 7f60eb5..a64553b 100644
--- a/src/gpu/api.h
+++ b/src/gpu/api.h
@@ -5,3 +5,4 @@
#include <cpuinfo.h>
bool cpuinfo_gpu_query_gles2(char name[restrict static CPUINFO_GPU_NAME_MAX]);
+void cpuinfo_gpu_ios_query_gles2(char name[restrict static CPUINFO_GPU_NAME_MAX]);
diff --git a/src/gpu/gles-ios.m b/src/gpu/gles-ios.m
new file mode 100644
index 0000000..5de639f
--- /dev/null
+++ b/src/gpu/gles-ios.m
@@ -0,0 +1,43 @@
+#import <OpenGLES/EAGL.h>
+#import <OpenGLES/ES2/gl.h>
+
+#import <cpuinfo.h>
+#import <log.h>
+#import <gpu/api.h>
+
+
+void cpuinfo_gpu_ios_query_gles2(char gpu_name[restrict static CPUINFO_GPU_NAME_MAX]) {
+ EAGLContext* existing_context = [EAGLContext currentContext];
+ EAGLContext* current_context = nil;
+ if (existing_context == nil) {
+ /* No existing context: create new context */
+
+ /* OpenGL ES 2.0 is supported by iPhone 3GS and up */
+ current_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
+ if (!current_context) {
+ cpuinfo_log_warning("failed to initialize OpenGLES context");
+ }
+
+ /* Set context */
+ if (![EAGLContext setCurrentContext: current_context]) {
+ cpuinfo_log_warning("failed to set current OpenGLES context");
+ }
+ }
+
+ const char* renderer_str = (const char*) glGetString(GL_RENDERER);
+ if (renderer_str != NULL) {
+ strncpy(gpu_name, renderer_str, CPUINFO_GPU_NAME_MAX - 1);
+ gpu_name[CPUINFO_GPU_NAME_MAX - 1] = '\0';
+ cpuinfo_log_debug("GL_RENDERER: %s", renderer_str);
+ } else {
+ cpuinfo_log_warning("failed to get GL_RENDERER for OpenGL ES2 context");
+ }
+
+ if (current_context) {
+ /* Reset context */
+ if (![EAGLContext setCurrentContext: nil]) {
+ cpuinfo_log_warning("failed to reset OpenGLES context");
+ }
+ current_context = nil;
+ }
+}