MVKInstance instantiate MVKPhysicalDevices in-place instead of using new.

This commit is contained in:
Bill Hollings 2020-03-30 13:13:54 -04:00
parent fee050372b
commit 8ec5f93802
2 changed files with 6 additions and 12 deletions

View File

@ -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 <string>
#include <mutex>
class MVKPhysicalDevice;
class MVKDevice;
class MVKSurface;
class MVKDebugReportCallback;
class MVKDebugUtilsMessenger;
@ -190,7 +189,7 @@ protected:
MVKConfiguration _mvkConfig;
VkApplicationInfo _appInfo;
MVKVectorInline<MVKPhysicalDevice*, 1> _physicalDevices;
MVKVectorInline<MVKPhysicalDevice, 2> _physicalDevices;
MVKVectorDefault<MVKDebugReportCallback*> _debugReportCallbacks;
MVKVectorDefault<MVKDebugUtilsMessenger*> _debugUtilMessengers;
std::unordered_map<std::string, MVKEntryPoint> _entryPoints;

View File

@ -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<id<MTLDevice>>* mtlDevices = availableMTLDevicesArray();
_physicalDevices.reserve(mtlDevices.count);
for (id<MTLDevice> 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<mutex> lock(_dcbLock);
_useCreationCallbacks = true;
mvkDestroyContainerContents(_debugReportCallbacks);
}