启用特性

本节介绍启用特性的物流。

特性类别

Vulkan 中的所有特性可以分为/找到在 3 个部分

  1. 核心 1.0 特性

  2. 未来核心版本特性

  3. 扩展特性

    • 有时,扩展包含特性,以便启用扩展的某些方面。 这些很容易找到,因为它们都被标记为 VkPhysicalDevice[ExtensionName]Features

如何启用特性

所有特性都必须在 VkDevice 创建时在 VkDeviceCreateInfo 结构内启用。

不要忘记先使用 vkGetPhysicalDeviceFeaturesvkGetPhysicalDeviceFeatures2 查询

对于核心 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;