Merge pull request #420 from mlfarrell/bugfix/default-device-graphics-switching-macos

If user requests system default device curing vkCreateDevice, call …
This commit is contained in:
Bill Hollings 2018-12-20 17:01:59 -05:00 committed by GitHub
commit a01b99514e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -243,7 +243,9 @@ public:
/** Returns the underlying Metal device. */
inline id<MTLDevice> getMTLDevice() { return _mtlDevice; }
/*** Replaces the underlying Metal device .*/
inline void replaceMTLDevice(id<MTLDevice> mtlDevice) { [_mtlDevice autorelease]; _mtlDevice = [mtlDevice retain]; }
#pragma mark Construction

View File

@ -1761,6 +1761,20 @@ uint32_t MVKDevice::expandVisibilityResultMTLBuffer(uint32_t queryCount) {
MVKDevice::MVKDevice(MVKPhysicalDevice* physicalDevice, const VkDeviceCreateInfo* pCreateInfo) {
initPerformanceTracking();
#if MVK_MACOS
//on mac OS, the wrong GPU will drive the screen (graphics switching will not occur)
//unless we call this specific MTLCreateSystemDefaultDevice method to create the metal device
id<MTLDevice> device = physicalDevice->getMTLDevice();
if (!device.headless && !device.lowPower) {
id<MTLDevice> sysDefaultDevice = MTLCreateSystemDefaultDevice();
//lets be 100% sure this is the device the user asked for
if (sysDefaultDevice.registryID == device.registryID) {
physicalDevice->replaceMTLDevice(sysDefaultDevice);
}
}
#endif
_physicalDevice = physicalDevice;
_pMVKConfig = _physicalDevice->_mvkInstance->getMoltenVKConfiguration();