跳到主要内容

启用特性

特性分类

Vulkan 中的所有功能特性可分为 3 种

  1. 1.0 核心功能
  2. 补充核心功能
  3. 扩展功能
    • 有一些扩展的功能,可以通过开关来启用其中的一部分,这些扩展特性被标记为VkPhysicalDevice[ExtensionName]Features

如何启用这些特性

所有特性功能必须在创建VkDevice时在 VkDeviceCreateInfo 结构中指定。

提示

不要忘记先使用vkGetPhysicalDeviceFeaturesvkGetPhysicalDeviceFeatures2查询支持的功能。

对于 Core 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;

所有特性功能可以使用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;