Mak*_*gan 2 c++ header wrapper vulkan
我正在尝试转换现有的代码库以使用在lunar SDK 中的vulkan.hpp 中定义的包装器。
\n\n特别是,我有以下代码行:
\n\nvkEnumerateInstanceLayerProperties(&layerCount, nullptr);
这是使用 vulkan 进行操作的原生 C 方式。
\n\n我尝试将其更改为:
\n\nvk::enumerateInstanceLayerProperties(&layerCount, nullptr);\n这是 vulkan.hpp 的命名约定。然而,这无法编译,并出现多个错误,第一个是error: \xe2\x80\x98unsigned int*\xe2\x80\x99 is not a class, struct, or union type
vulkan.hpp中定义的签名是:
\n\ntemplate <typename Allocator, typename Dispatch>\n VULKAN_HPP_INLINE typename ResultValueType<std::vector<LayerProperties,Allocator>>::type enumerateInstanceLayerProperties(Allocator const& vectorAllocator, Dispatch const &d )\nRun Code Online (Sandbox Code Playgroud)\n\n我的假设是第一个参数需要是一个向量:\nstd::vector<vk::LayerProperties> availableLayers;\n vk::enumerateInstanceLayerProperties(availableLayers, nullptr);
然而,这也无法编译,警告我:\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
d是函数的第二个参数。
成功编译这段代码需要什么调度?
\n使用 C++ 标头,该函数根本不接受任何参数,而是直接返回一个向量vk::LayerProperties,因此您只需分配结果:
std::vector<vk::LayerProperties> instanceLayerProps = vk::enumerateInstanceLayerProperties();
Run Code Online (Sandbox Code Playgroud)
这也使您不必调用该函数两次,就像使用 C 标头一样,您首先需要获取分配向量的计数。这一切都是在这里隐式完成的。