Vulkan app to use Nvidia GPU (Optimus)

I have tried
extern “C” {
_declspec(dllexport) uint32_t NvOptimusEnablement = 0x00000001;
which worked fine on OpenGL apps, but no success with Vulkan.
Also tried the context menu run with nvidia gpu, no success.
Also tried adding the executable to be run with nvidia gpu via nvidia control panel, no success.
The only thing that seems to work is to select nvidia gpu as the preferred one globally via nvidia control panel but this method is not acceptable for me as all the new processes get to use nvidia gpu.

Vulkan has explicit GPU select in the API. When you create a device you have to say which physical device(s) it should use. If you have 2 physical devices, one for onboard GPU and one for dedicated GPU, simply select the dedicated GPU (VkPhysicalDeviceProperties::deviceType is VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) when you create your device.


Thanks a lot @virtual_storm