Merge pull request #30 from billhollings/master

GPU management.
This commit is contained in:
Bill Hollings 2018-01-29 12:01:22 -05:00 committed by GitHub
commit 91f3c61046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 26 deletions

@ -1 +1 @@
Subproject commit ba1e415a9ce9ade81d7a94ad67d902a8979a5767
Subproject commit ab3907e4b59b243e7391a71f5e962c1bb5ab8451

View File

@ -1056,6 +1056,8 @@ MVKQueryPool* MVKDevice::createQueryPool(const VkQueryPoolCreateInfo* pCreateInf
return new MVKOcclusionQueryPool(this, pCreateInfo);
case VK_QUERY_TYPE_TIMESTAMP:
return new MVKTimestampQueryPool(this, pCreateInfo);
case VK_QUERY_TYPE_PIPELINE_STATISTICS:
return new MVKPipelineStatisticsQueryPool(this, pCreateInfo);
default:
return new MVKUnsupportedQueryPool(this, pCreateInfo);
}
@ -1390,6 +1392,8 @@ MVKDevice::MVKDevice(MVKPhysicalDevice* physicalDevice, const VkDeviceCreateInfo
}
initPerformanceTracking();
MVKLogInfo("Created VkDevice to run on GPU %s", _pProperties->deviceName);
}
void MVKDevice::initPerformanceTracking() {

View File

@ -275,10 +275,33 @@ void MVKInstance::logVersions() {
MVKLogInfo("MoltenVK version %s. Vulkan version %s.", mvkVer, vkVer);
}
/** Returns an autorelease array containing the MTLDevices available on this system. */
/**
* Returns an autoreleased array containing the MTLDevices available on this system,
* sorted according to power, with higher power GPU's at the front of the array.
* This ensures that a lazy app that simply grabs the first GPU will get a high-power one by default.
* If the MVK_FORCE_LOW_POWER_GPU is defined, the returned array will only include low-power devices.
*/
static NSArray<id<MTLDevice>>* getAvailableMTLDevices() {
#if MVK_MACOS
return [MTLCopyAllDevices() autorelease];
NSArray* mtlDevs = [MTLCopyAllDevices() autorelease];
#ifdef MVK_FORCE_LOW_POWER_GPU
NSMutableArray* lpDevs = [[NSMutableArray new] autorelease];
for (id<MTLDevice> md in mtlDevs) {
if (md.isLowPower) { [lpDevs addObject: md]; }
}
return lpDevs;
#else
return [mtlDevs sortedArrayUsingComparator: ^(id<MTLDevice> md1, id<MTLDevice> md2) {
BOOL md1IsLP = md1.isLowPower;
BOOL md2IsLP = md2.isLowPower;
if (md1IsLP == md2IsLP) { return NSOrderedSame; }
return md2IsLP ? NSOrderedAscending : NSOrderedDescending;
}];
#endif // MVK_MACOS
#endif
#if MVK_IOS
return [NSArray arrayWithObject: MTLCreateSystemDefaultDevice()];
@ -297,11 +320,7 @@ MVKInstance::MVKInstance(const VkInstanceCreateInfo* pCreateInfo) {
NSArray<id<MTLDevice>>* mtlDevices = getAvailableMTLDevices();
_physicalDevices.reserve(mtlDevices.count);
for (id<MTLDevice> mtlDev in mtlDevices) {
#if (MVK_MACOS && defined(MVK_FORCE_LOW_POWER_GPU))
if (mtlDev.isLowPower) { _physicalDevices.push_back(new MVKPhysicalDevice(this, mtlDev)); }
#else
_physicalDevices.push_back(new MVKPhysicalDevice(this, mtlDev));
#endif
_physicalDevices.push_back(new MVKPhysicalDevice(this, mtlDev));
}
if (MVK_VULKAN_API_VERSION_CONFORM(MVK_VULKAN_API_VERSION) <

View File

@ -150,6 +150,18 @@ protected:
};
#pragma mark -
#pragma mark MVKPipelineStatisticsQueryPool
/** A Vulkan query pool for a query pool type that tracks pipeline statistics. */
class MVKPipelineStatisticsQueryPool : public MVKQueryPool {
public:
MVKPipelineStatisticsQueryPool(MVKDevice* device, const VkQueryPoolCreateInfo* pCreateInfo);
};
#pragma mark -
#pragma mark MVKUnsupportedQueryPool
@ -157,7 +169,7 @@ protected:
class MVKUnsupportedQueryPool : public MVKQueryPool {
public:
MVKUnsupportedQueryPool(MVKDevice* device, const VkQueryPoolCreateInfo* pCreateInfo);
MVKUnsupportedQueryPool(MVKDevice* device, const VkQueryPoolCreateInfo* pCreateInfo);
};

View File

@ -136,8 +136,8 @@ void MVKTimestampQueryPool::getResult(uint32_t query, void* pQryData, bool shoul
#pragma mark Construction
MVKTimestampQueryPool::MVKTimestampQueryPool(MVKDevice* device, const VkQueryPoolCreateInfo* pCreateInfo)
: MVKQueryPool(device, pCreateInfo, 1), _timestamps(pCreateInfo->queryCount) {
MVKTimestampQueryPool::MVKTimestampQueryPool(MVKDevice* device,
const VkQueryPoolCreateInfo* pCreateInfo) : MVKQueryPool(device, pCreateInfo, 1), _timestamps(pCreateInfo->queryCount) {
}
@ -233,16 +233,20 @@ MVKOcclusionQueryPool::~MVKOcclusionQueryPool() {
#pragma mark -
#pragma mark MVKUnsupportedQueryPool
#pragma mark MVKPipelineStatisticsQueryPool
MVKUnsupportedQueryPool::MVKUnsupportedQueryPool(MVKDevice* device, const VkQueryPoolCreateInfo* pCreateInfo)
: MVKQueryPool(device, pCreateInfo, 1) {
switch (pCreateInfo->queryType) {
case VK_QUERY_TYPE_PIPELINE_STATISTICS:
setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_FEATURE_NOT_PRESENT, "vkCreateQueryPool: VK_QUERY_TYPE_PIPELINE_STATISTICS is not supported."));
default:
setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_INITIALIZATION_FAILED, "vkCreateQueryPool: Unsupported query pool type: %d.", pCreateInfo->queryType));
}
MVKPipelineStatisticsQueryPool::MVKPipelineStatisticsQueryPool(MVKDevice* device,
const VkQueryPoolCreateInfo* pCreateInfo) : MVKQueryPool(device, pCreateInfo, 1) {
if ( !_device->_pFeatures->pipelineStatisticsQuery ) {
setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_FEATURE_NOT_PRESENT, "vkCreateQueryPool: VK_QUERY_TYPE_PIPELINE_STATISTICS is not supported."));
}
}
#pragma mark -
#pragma mark MVKUnsupportedQueryPool
MVKUnsupportedQueryPool::MVKUnsupportedQueryPool(MVKDevice* device,
const VkQueryPoolCreateInfo* pCreateInfo) : MVKQueryPool(device, pCreateInfo, 1) {
setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_INITIALIZATION_FAILED, "vkCreateQueryPool: Unsupported query pool type: %d.", pCreateInfo->queryType));
}

View File

@ -74,19 +74,19 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-gi"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "/Users/bill/Documents/Dev/iOSProjects/Molten/MoltenVK-bh/External/SPIRV-Cross/shaders/flatten/rowmajor.flatten.vert"
isEnabled = "NO">
argument = "/Users/bill/Documents/Dev/iOSProjects/Molten/MoltenVK-bh/External/SPIRV-Cross/shaders-msl/comp/functions.comp"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-si"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "/Users/bill/Documents/Dev/iOSProjects/Molten/Support/Valve/Dota2/shader-issues/spv_cross_bug/spv_cross_bug.spv"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-mo"