Vulkan hpp 包装器,签名冲突

Mak*_*gan 2 c++ header wrapper vulkan

我正在尝试转换现有的代码库以使用在lunar SDK 中的vulkan.hpp 中定义的包装器。

\n\n

特别是,我有以下代码行:

\n\n

vkEnumerateInstanceLayerProperties(&layerCount, nullptr);

\n\n

这是使用 vulkan 进行操作的原生 C 方式。

\n\n

我尝试将其更改为:

\n\n

vk::enumerateInstanceLayerProperties(&layerCount, nullptr);\n这是 vulkan.hpp 的命名约定。然而,这无法编译,并出现多个错误,第一个是error: \xe2\x80\x98unsigned int*\xe2\x80\x99 is not a class, struct, or union type

\n\n

vulkan.hpp中定义的签名是:

\n\n
template <typename Allocator, typename Dispatch>\n  VULKAN_HPP_INLINE typename ResultValueType<std::vector<LayerProperties,Allocator>>::type enumerateInstanceLayerProperties(Allocator const& vectorAllocator, Dispatch const &d )\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的假设是第一个参数需要是一个向量:\nstd::vector<vk::LayerProperties> availableLayers;\n vk::enumerateInstanceLayerProperties(availableLayers, nullptr);

\n\n

然而,这也无法编译,警告我:\nerror: request for member \xe2\x80\x98vkEnumerateInstanceLayerProperties\xe2\x80\x99 in \xe2\x80\x98d\xe2\x80\x99, whichis of non-class type \xe2\x80\x98std::nullptr_t\xe2\x80\x99

\n\n

d是函数的第二个参数。

\n\n

成功编译这段代码需要什么调度?

\n

Sas*_*ems 5

使用 C++ 标头,该函数根本不接受任何参数,而是直接返回一个向量vk::LayerProperties,因此您只需分配结果:

std::vector<vk::LayerProperties> instanceLayerProps = vk::enumerateInstanceLayerProperties();
Run Code Online (Sandbox Code Playgroud)

这也使您不必调用该函数两次,就像使用 C 标头一样,您首先需要获取分配向量的计数。这一切都是在这里隐式完成的。