Skip to content

Commit 490b7e2

Browse files
committed
detect gpu model for MacOS
1 parent def7929 commit 490b7e2

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ elseif(APPLE)
190190
"-framework Foundation"
191191
"-framework CoreServices"
192192
"-framework SystemConfiguration"
193+
"-framework Metal"
194+
"-framework MetalKit"
193195
)
194196

195197
create_source_groups(MACOS_SOURCES)

source/gameanalytics/Platform/GADeviceOSX.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const char* getOSXVersion();
99
const char* getConnectionType();
1010
int getNumCpuCores();
1111
int64_t getTotalDeviceMemory();
12+
const char* getGPUName();
1213

1314
#endif
1415

source/gameanalytics/Platform/GADeviceOSX.mm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#import <SystemConfiguration/SystemConfiguration.h>
1717
#import <netinet/in.h>
1818

19+
#import <IOKit/IOKitLib.h>
20+
21+
#include <Metal/Metal.h>
22+
1923
typedef struct {
2024
NSInteger majorVersion;
2125
NSInteger minorVersion;
@@ -103,4 +107,17 @@ int64_t getTotalDeviceMemory()
103107
return (uint64_t)info.physicalMemory;
104108
}
105109

110+
const char* getGPUName()
111+
{
112+
NSArray* devices = MTLCopyAllDevices();
113+
if(devices && [devices count])
114+
{
115+
id device = devices[0];
116+
NSString* name = [device name];
117+
return [name UTF8String];
118+
}
119+
120+
return "";
121+
}
122+
106123
#endif // IS_MAC

source/gameanalytics/Platform/GAMacOS.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ std::string gameanalytics::GAPlatformMacOS::getCpuModel() const
193193

194194
std::string gameanalytics::GAPlatformMacOS::getGpuModel() const
195195
{
196-
return "Apple";
196+
if(_gpuModel.empty())
197+
{
198+
_gpuModel = ::getGPUName();
199+
}
200+
201+
return _gpuModel;
197202
}
198203

199204
int gameanalytics::GAPlatformMacOS::getNumCpuCores() const

source/gameanalytics/Platform/GAMacOS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace gameanalytics
3838

3939
private:
4040

41+
mutable std::string _gpuModel;
4142
static void signalHandler(int sig, siginfo_t* info, void* context);
4243
};
4344
}

0 commit comments

Comments
 (0)