With Vulkan released, I decided to write (as a hobby) a Vulkan based GUI. However, I'm currently stuck at the very first step - loading Vulkan functions. I'm using Nvidia's C++ Vulkan wrapper which requires, as far as I can see, Vulkan functions to be loaded globally.
I can load local functions successfully, however ::vkCreateInstance fails:
void loadInstanceFunctions() {
PFN_vkCreateInstance vkCreateInstance = (PFN_vkCreateInstance)vkGetInstanceProcAddr(nullptr, "vkCreateInstance"); //works
::vkCreateInstance = (PFN_vkCreateInstance)vkGetInstanceProcAddr(nullptr, "vkCreateInstance"); //does not work
}
Trying to assign new function pointer globally gives me 2 compile-time errors (compiled using VS2015):
- expression must be a modifiable lvalue.
- '=': function as left operand.
There are function prototypes declared in vulkan.h header, for example:
VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(
const VkInstanceCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkInstance* pInstance);
This is what might prevent me from loading functions globally. If I were to define VK_NO_PROTOTYPES, then these prototypes would be skipped and I believe that I could just re-declare them as PFN_vkCreateInstance vkCreateInstance = nullptr; and so on. But is this the correct way?
So, my question - what is the correct way to load Vulkan functions globally?
vkCreateInstance, then you use scope resolution to access what seems to be a global variable calledvkCreateInstance(or at least a global name namedvkCreateInstance-- who knows!). I have no idea what it is you are trying to do. Post a minimal reproducible example that generates your error. - Yakk - Adam Nevraumont