From 8ec5f938026ea4c545a9e94d32ebf21fe03d56d7 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Mon, 30 Mar 2020 13:13:54 -0400 Subject: [PATCH] MVKInstance instantiate MVKPhysicalDevices in-place instead of using new. --- MoltenVK/MoltenVK/GPUObjects/MVKInstance.h | 5 ++--- MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm | 13 ++++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.h b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.h index 575033de..aa10c2cb 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.h @@ -19,6 +19,7 @@ #pragma once #include "MVKEnvironment.h" +#include "MVKDevice.h" #include "MVKLayers.h" #include "MVKVulkanAPIObject.h" #include "MVKVector.h" @@ -27,8 +28,6 @@ #include #include -class MVKPhysicalDevice; -class MVKDevice; class MVKSurface; class MVKDebugReportCallback; class MVKDebugUtilsMessenger; @@ -190,7 +189,7 @@ protected: MVKConfiguration _mvkConfig; VkApplicationInfo _appInfo; - MVKVectorInline _physicalDevices; + MVKVectorInline _physicalDevices; MVKVectorDefault _debugReportCallbacks; MVKVectorDefault _debugUtilMessengers; std::unordered_map _entryPoints; diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm index 12787cc0..5706f581 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm @@ -18,9 +18,7 @@ #include "MVKInstance.h" -#include "MVKDevice.h" #include "MVKFoundation.h" -#include "MVKEnvironment.h" #include "MVKSurface.h" #include "MVKOSExtensions.h" #include "MVKLogging.h" @@ -64,7 +62,7 @@ VkResult MVKInstance::getPhysicalDevices(uint32_t* pCount, VkPhysicalDevice* pPh // Now populate the devices for (uint32_t pdIdx = 0; pdIdx < *pCount; pdIdx++) { - pPhysicalDevices[pdIdx] = _physicalDevices[pdIdx]->getVkPhysicalDevice(); + pPhysicalDevices[pdIdx] = _physicalDevices[pdIdx].getVkPhysicalDevice(); } return result; @@ -91,7 +89,7 @@ VkResult MVKInstance::getPhysicalDeviceGroups(uint32_t* pCount, VkPhysicalDevice // Now populate the device groups for (uint32_t pdIdx = 0; pdIdx < *pCount; pdIdx++) { pPhysicalDeviceGroupProps[pdIdx].physicalDeviceCount = 1; - pPhysicalDeviceGroupProps[pdIdx].physicalDevices[0] = _physicalDevices[pdIdx]->getVkPhysicalDevice(); + pPhysicalDeviceGroupProps[pdIdx].physicalDevices[0] = _physicalDevices[pdIdx].getVkPhysicalDevice(); pPhysicalDeviceGroupProps[pdIdx].subsetAllocation = VK_FALSE; } @@ -359,9 +357,8 @@ MVKInstance::MVKInstance(const VkInstanceCreateInfo* pCreateInfo) : _enabledExte // and other Obj-C classes, so wrap it all in an autorelease pool. @autoreleasepool { NSArray>* mtlDevices = availableMTLDevicesArray(); - _physicalDevices.reserve(mtlDevices.count); for (id mtlDev in mtlDevices) { - _physicalDevices.push_back(new MVKPhysicalDevice(this, mtlDev)); + _physicalDevices.emplace_back(this, mtlDev); } } @@ -679,10 +676,8 @@ VkResult MVKInstance::verifyLayers(uint32_t count, const char* const* names) { } MVKInstance::~MVKInstance() { - _useCreationCallbacks = true; - mvkDestroyContainerContents(_physicalDevices); - lock_guard lock(_dcbLock); + _useCreationCallbacks = true; mvkDestroyContainerContents(_debugReportCallbacks); }