diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 232a9e24..888989d5 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -2590,6 +2590,20 @@ void MVKDevice::destroyImageView(MVKImageView* mvkImgView, MVKSwapchain* MVKDevice::createSwapchain(const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator) { +#if MVK_MACOS + // If we have selected a high-power GPU and want to force the window system + // to use it, force the window system to use a high-power GPU by calling the + // MTLCreateSystemDefaultDevice function, and if that GPU is the same as the + // selected GPU, update the MTLDevice instance used by the MVKPhysicalDevice. + id mtlDevice = _physicalDevice->getMTLDevice(); + if (_pMVKConfig->switchSystemGPU && !(mtlDevice.isLowPower || mtlDevice.isHeadless) ) { + id sysMTLDevice = MTLCreateSystemDefaultDevice(); + if (mvkGetRegistryID(sysMTLDevice) == mvkGetRegistryID(mtlDevice)) { + _physicalDevice->replaceMTLDevice(sysMTLDevice); + } + } +#endif + return new MVKSwapchain(this, pCreateInfo); } @@ -3186,20 +3200,6 @@ void MVKDevice::initPhysicalDevice(MVKPhysicalDevice* physicalDevice, const VkDe # define MVK_CONFIG_USE_COMMAND_POOLING 1 # endif MVK_SET_FROM_ENV_OR_BUILD_BOOL(_useCommandPooling, MVK_CONFIG_USE_COMMAND_POOLING); - -#if MVK_MACOS - // If we have selected a high-power GPU and want to force the window system - // to use it, force the window system to use a high-power GPU by calling the - // MTLCreateSystemDefaultDevice function, and if that GPU is the same as the - // selected GPU, update the MTLDevice instance used by the MVKPhysicalDevice. - id mtlDevice = _physicalDevice->getMTLDevice(); - if (_pMVKConfig->switchSystemGPU && !(mtlDevice.isLowPower || mtlDevice.isHeadless) ) { - id sysMTLDevice = MTLCreateSystemDefaultDevice(); - if (mvkGetRegistryID(sysMTLDevice) == mvkGetRegistryID(mtlDevice)) { - _physicalDevice->replaceMTLDevice(sysMTLDevice); - } - } -#endif } void MVKDevice::enableFeatures(const VkDeviceCreateInfo* pCreateInfo) { diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm index d937e7b2..0a2a438c 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm @@ -1246,7 +1246,14 @@ void MVKPixelFormats::modifyMTLFormatCapabilities() { if (_physicalDevice) { modifyMTLFormatCapabilities(_physicalDevice->getMTLDevice()); } else { +#if MVK_IOS_OR_TVOS id mtlDevice = MTLCreateSystemDefaultDevice(); // temp retained +#endif +#if MVK_MACOS + NSArray>* mtlDevices = MTLCopyAllDevices(); // temp retained + id mtlDevice = [mtlDevices[0] retain]; // temp retained + [mtlDevices release]; // temp release +#endif modifyMTLFormatCapabilities(mtlDevice); [mtlDevice release]; // release temp instance }