QVulkanFunctions Class

QVulkanFunctions 类提供了对实例级核心 Vulkan 1.3 API 的跨平台访问。更多

Header: #include <QVulkanFunctions>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui

详细说明

Qt 和 Qt 应用程序默认不链接任何 Vulkan 库。相反,所有函数都是在运行时动态解析的。每个QVulkanInstance 都提供了一个 QVulkanFunctions 对象,可通过QVulkanInstance::functions() 检索。该对象不包含设备级函数,以避免内部调度的潜在开销。相反,依赖于设备或设备可调度子对象的函数通过QVulkanDeviceFunctionsQVulkanInstance::deviceFunctions() 公开。QVulkanFunctions 和QVulkanDeviceFunctions 一起提供了对完整核心 Vulkan API(不包括任何扩展)的访问。

注意: QVulkanFunctions 实例不能直接构建。

典型用法如下:

void Window::init()
{
    QVulkanInstance *inst = vulkanInstance();
    QVulkanFunctions *f = inst->functions();
    // ...
    uint32_t count = 0;
    VkResult err = f->vkEnumeratePhysicalDevices(inst->vkInstance(), &count, nullptr);
    // ...
}

注: 不包括窗口系统接口(WSI)的具体内容和扩展。该类仅涵盖核心 Vulkan 命令,实例创建、销毁和函数解析除外,因为QVulkanInstance 本身已涵盖此类功能。

要访问其他功能,应用程序可以使用QVulkanInstance::getInstanceProcAddr() 和 vkGetDeviceProcAddr()。应用程序还可以决定直接链接到 Vulkan 库,因为带有适当加载器的平台通常会导出核心命令的函数符号。更多信息,请参阅vkGetInstanceProcAddr 的手册

注意: Vulkan 1.1、1.2 和 1.3 命令的成员函数原型是ifdefed ,使用 Vulkan 头文件定义的相应VK_VERSION_1_x 。因此,只有当系统(应用程序在其上构建)的 Vulkan 头文件足够新且包含 1.1、1.2 或 1.3 Vulkan API 定义时,应用程序才能调用这些函数。从源代码构建 Qt 时,这还会产生一个额外的结果:构建环境中的 Vulkan 头文件也必须与 1.1、1.2 和 1.3 兼容,这样才能获得支持解析 1.1、1.2 和 1.3 API 命令的 Qt 构建。如果这两个条件都不满足,应用程序将只能通过 QVulkanFunctions 和QVulkanDeviceFunctions 调用 Vulkan 1.0 命令。

另请参阅 QVulkanInstance,QVulkanDeviceFunctions,QWindow::setVulkanInstance() 和QWindow::setSurfaceType() 。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.