启用特性
本节介绍启用特性的物流。
特性类别
Vulkan 中的所有特性可以分为/找到在 3 个部分
-
核心 1.0 特性
-
这些是 Vulkan 初始 1.0 版本提供的特性集。 特性列表可以在 VkPhysicalDeviceFeatures 中找到
-
-
未来核心版本特性
-
对于 Vulkan 1.1+,一些新特性被添加到 Vulkan 的核心版本中。为了保持
VkPhysicalDeviceFeatures
的大小向后兼容,创建了新的结构来保存特性的分组。
-
-
扩展特性
-
有时,扩展包含特性,以便启用扩展的某些方面。 这些很容易找到,因为它们都被标记为
VkPhysicalDevice[ExtensionName]Features
-
如何启用特性
所有特性都必须在 VkDevice
创建时在 VkDeviceCreateInfo 结构内启用。
不要忘记先使用 |
对于核心 1.0 特性,这就像使用要启用的特性设置 VkDeviceCreateInfo::pEnabledFeatures
一样简单。
VkPhysicalDeviceFeatures features = {};
vkGetPhysicalDeviceFeatures(physical_device, &features);
// Logic if feature is not supported
if (features.robustBufferAccess == VK_FALSE) {
}
VkDeviceCreateInfo info = {};
info.pEnabledFeatures = &features;
对于所有特性,包括核心 1.0 特性,使用 VkPhysicalDeviceFeatures2
传递到 VkDeviceCreateInfo.pNext
VkPhysicalDeviceShaderDrawParametersFeatures ext_feature = {};
VkPhysicalDeviceFeatures2 physical_features2 = {};
physical_features2.pNext = &ext_feature;
vkGetPhysicalDeviceFeatures2(physical_device, &physical_features2);
// Logic if feature is not supported
if (ext_feature.shaderDrawParameters == VK_FALSE) {
}
VkDeviceCreateInfo info = {};
info.pNext = &physical_features2;
对于“未来核心版本特性”也是如此。
VkPhysicalDeviceVulkan11Features features11 = {};
VkPhysicalDeviceFeatures2 physical_features2 = {};
physical_features2.pNext = &features11;
vkGetPhysicalDeviceFeatures2(physical_device, &physical_features2);
// Logic if feature is not supported
if (features11.shaderDrawParameters == VK_FALSE) {
}
VkDeviceCreateInfo info = {};
info.pNext = &physical_features2;