Enable VkDevice Features Selectively

We selectively enable GPU features that we require as enabling all of them might result in extra driver overhead in certain circumstances. Setting them is handled by `QuirkManager` with the new `FEAT_SET` function that ties a quirk with a feature.
This commit is contained in:
PixelyIon 2021-11-14 21:00:34 +05:30
parent ec378814aa
commit 51659e1329
3 changed files with 18 additions and 6 deletions

View File

@ -119,7 +119,7 @@ namespace skyline::gpu {
return std::move(vk::raii::PhysicalDevices(instance).front()); // We just select the first device as we aren't expecting multiple GPUs
}
vk::raii::Device GPU::CreateDevice(const vk::raii::PhysicalDevice &physicalDevice, typeof(vk::DeviceQueueCreateInfo::queueCount) &vkQueueFamilyIndex, QuirkManager& quirks) {
vk::raii::Device GPU::CreateDevice(const vk::raii::PhysicalDevice &physicalDevice, typeof(vk::DeviceQueueCreateInfo::queueCount) &vkQueueFamilyIndex, QuirkManager &quirks) {
auto properties{physicalDevice.getProperties()};
auto features{physicalDevice.getFeatures2()};
auto extensions{physicalDevice.enumerateDeviceExtensionProperties()};
@ -164,14 +164,15 @@ namespace skyline::gpu {
for (const auto &queueFamily : queueFamilies)
queueString += util::Format("\n* {}x{}{}{}{}{}: TSB{} MIG({}x{}x{}){}", queueFamily.queueCount, queueFamily.queueFlags & vk::QueueFlagBits::eGraphics ? 'G' : '-', queueFamily.queueFlags & vk::QueueFlagBits::eCompute ? 'C' : '-', queueFamily.queueFlags & vk::QueueFlagBits::eTransfer ? 'T' : '-', queueFamily.queueFlags & vk::QueueFlagBits::eSparseBinding ? 'S' : '-', queueFamily.queueFlags & vk::QueueFlagBits::eProtected ? 'P' : '-', queueFamily.timestampValidBits, queueFamily.minImageTransferGranularity.width, queueFamily.minImageTransferGranularity.height, queueFamily.minImageTransferGranularity.depth, familyIndex++ == vkQueueFamilyIndex ? " <--" : "");
Logger::Info("Vulkan Device:\nName: {}\nType: {}\nVulkan Version: {}.{}.{}\nDriver Version: {}.{}.{}\nQueues:{}\nExtensions:{}\nQuirks:{}", properties.deviceName,
vk::to_string(properties.deviceType),
Logger::Info("Vulkan Device:\nName: {}\nType: {}\nVulkan Version: {}.{}.{}\nDriver Version: {}.{}.{}\nQueues:{}\nExtensions:{}\nQuirks:{}",
properties.deviceName, vk::to_string(properties.deviceType),
VK_VERSION_MAJOR(properties.apiVersion), VK_VERSION_MINOR(properties.apiVersion), VK_VERSION_PATCH(properties.apiVersion),
VK_VERSION_MAJOR(properties.driverVersion), VK_VERSION_MINOR(properties.driverVersion), VK_VERSION_PATCH(properties.driverVersion),
queueString, extensionString, quirks.Summary());
}
return vk::raii::Device(physicalDevice, vk::DeviceCreateInfo{
.pNext = &features,
.queueCreateInfoCount = 1,
.pQueueCreateInfos = &queue,
.enabledExtensionCount = requiredDeviceExtensions.size(),

View File

@ -4,7 +4,7 @@
#include "quirk_manager.h"
namespace skyline {
QuirkManager::QuirkManager(vk::PhysicalDeviceProperties properties, vk::PhysicalDeviceFeatures2 features2, const std::vector<vk::ExtensionProperties> &extensions) {
QuirkManager::QuirkManager(const vk::PhysicalDeviceProperties &properties, vk::PhysicalDeviceFeatures2 &features2, const std::vector<vk::ExtensionProperties> &extensions) {
for (auto &extension : extensions) {
#define EXT_SET(name, property) \
case util::Hash(name): \
@ -28,7 +28,18 @@ namespace skyline {
#undef EXT_SET_V
}
supportsLogicOp = features2.features.logicOp;
auto deviceFeatures2{features2};
features2 = vk::PhysicalDeviceFeatures2{}; // We only want to enable features we required due to potential overhead from unused features
#define FEAT_SET(feature, property) \
if (deviceFeatures2.features.feature) { \
property = true; \
features2.features.feature = true; \
}
FEAT_SET(logicOp, supportsLogicOp)
#undef FEAT_SET
}
std::string QuirkManager::Summary() {

View File

@ -17,7 +17,7 @@ namespace skyline {
QuirkManager() = default;
QuirkManager(vk::PhysicalDeviceProperties properties, vk::PhysicalDeviceFeatures2 features, const std::vector<vk::ExtensionProperties>& extensions);
QuirkManager(const vk::PhysicalDeviceProperties &properties, vk::PhysicalDeviceFeatures2 &features, const std::vector<vk::ExtensionProperties> &extensions);
/**
* @return A summary of all the GPU quirks as a human-readable string