当前位置:网站首页>Vulkan开启特征(feature)的正确姿势
Vulkan开启特征(feature)的正确姿势
2022-07-30 18:50:00 【zenny_chen】
当我们在用Vulkan写一些应用时,无论是用其图形流水线还是计算流水线,或多或少需要用到一些当前设备的Vulkan核心版本所不具备的扩展特征,那么我们如何能既安全又方便地开启一些我们需要的特征呢?本文将给各位进行介绍。
我们要开启当前设备的某一扩展特征基本有两种手段。而且这两种手段并非是互斥的,而是需要一同使用。
一、指定特定的扩展名
这种是常见且常用的方式。我们先调用 vkEnumerateDeviceExtensionProperties
API枚举出当前指定使用的 物理设备 一共支持多少种扩展,最后在创建 逻辑设备 时将将所需要使用的扩展名指定在 VkDeviceCreateInfo
结构体对象的 ppEnabledExtensionNames
成员之中。
下面为枚举扩展名的大致示例代码:
enum MY_CONSTANT
{
MAX_VULKAN_GLOBAL_EXT_PROPS = 256
};
// Query Vulkan extensions the current selected physical device supports
uint32_t extPropCount = 0U;
res = vkEnumerateDeviceExtensionProperties(physicalDevices[deviceIndex], NULL, &extPropCount, NULL);
if (res != VK_SUCCESS)
{
printf("vkEnumerateDeviceExtensionProperties for count failed: %d\n", res);
return res;
}
printf("The current selected physical device supports %u Vulkan extensions!\n", extPropCount);
if (extPropCount > MAX_VULKAN_GLOBAL_EXT_PROPS) {
extPropCount = MAX_VULKAN_GLOBAL_EXT_PROPS;
}
VkExtensionProperties extProps[MAX_VULKAN_GLOBAL_EXT_PROPS];
res = vkEnumerateDeviceExtensionProperties(physicalDevices[deviceIndex], NULL, &extPropCount, extProps);
if (res != VK_SUCCESS)
{
printf("vkEnumerateDeviceExtensionProperties for content failed: %d\n", res);
return res;
}
这里各位需要注意的是,某些扩展可能在当前Vulkan版本中已经被融入到核心里去了,而有些GPU设计商可能就不会再把该扩展名列出来了,因此我们用 vkEnumerateDeviceExtensionProperties
这一API时压根就枚举不到,但这并不意味着我们就无法使用该扩展。
比如说我们当前设备可能枚举不到 VK_KHR_8BIT_STORAGE_EXTENSION_NAME
这一特征,但该特征早在Vulkan 1.2版本中就已经被加入到核心中去了。此时,我们可以通过下面将会介绍的,利用其相应的特征结构体去做进一步查询。而该特征名正好有个特征结构体,名字为:VkPhysicalDevice8BitStorageFeatures
。
另外,对于一些没有相应特征结构体的扩展,也可利用其对应的属性结构体进行查询。比如,如果我们当前设备没有枚举到 VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME
这一特征,那么我们可以跟subgroup相关的 VkPhysicalDeviceSubgroupProperties
这个属性中的 supportedOperations
做进一步查询。
下面我们将谈论一下Vulkan中如何通过特征结构体进行特征查询并进行开启。
边栏推荐
猜你喜欢
The use of @ symbol in MySql
好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%
OneFlow source code analysis: Op, Kernel and interpreter
Codeblocks + Widgets 创建窗口代码分析
cocos creater 热更重启导致崩溃
开心的聚餐
Spark学习:用spark实现ETL
Swiper rotates pictures and plays background music
使用postman调接口报Content type ‘text/plain;charset=UTF-8‘ not supported
SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
随机推荐
基于inquirer封装一个控制台文件选择器
OneFlow源码解析:Op、Kernel与解释器
mysql的多实例
[Use of Qt Designer tool]
ByteArrayInputStream class source code analysis
node封装一个控制台进度条插件
ESP8266-Arduino programming example-HC-SR04 ultrasonic sensor driver
《痞子衡嵌入式半月刊》 第 59 期
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.解决方法
还有三天忙完
The use of @ symbol in MySql
What is the value of biomedical papers? How to translate the papers into Chinese and English?
while,do while,for循环语句
natural language processing nltk
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
LeetCode Exercise - Two Questions About Finding Sum of Array Elements
The sixteenth issue of eight-part article Balabala said (MQ)
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
电脑死机的时候,发生了什么?
LeetCode 练习——关于查找数组元素之和的两道题