Accessing Vulkan memory for interop (Unreal Engine)

Hi, everybody,

I have a special problem and I’m not finding a solution. I want to access the memory of a Vulkan image from the Unreal Engine.
At the moment I can access PFN_vkGetMemoryFdKHR or PFN_vkGetMemoryWin32HandleKHR using VkInstance. But when I try to access this method with the VkDevice my application crashes.
Do I use the wrong VkDevice? - Unreal seems to offer several. Is there a method which checks if I use the correct one?
Is it possible to find out all devices of an instance? I didn’t find anything in the docs.

Is it possible that a certain extension is disabled? - Which exactly do I need for accessing the memory? Or how can I activate it?

Here is some code:

PFN_vkGetMemoryWin32HandleKHR func = (PFN_vkGetMemoryWin32HandleKHR)VulkanRHI::vkGetDeviceProcAddr(TextureDevice /* Got it from Unreal*/, "vkGetMemoryWin32HandleKHR");

						handleInfo.memory = vkMemory; //Got it from Unreal
int handle = -1;
func(TextureDevice, &handleInfo, &handle); // Error

I have only little experience with Vulkan, but I would like to solve this problem with the help of the Vulkan Sandbox (
In this project (without the Unreal Engine) the memory of the GPU is also accessed.
I would be grateful for any help. If you have any questions, feel free to ask them. I try to answer them.


Are you using Validation Layers in Vulkan?

Yes, by comparing the UUID or LUID from VkPhysicalDeviceIDProperties.

You mean in Vulkan? Well, um, simply vkEnumeratePhysicalDevices.

Only the extensions that you explicitly enabled are enabled.

VK_KHR_external_memory_capabilities and VK_KHR_get_physical_device_properties2 on instance. On device VK_KHR_external_memory, VK_KHR_external_memory_win32 (or another OS equivalent), also VK_KHR_dedicated_allocation+ VK_KHR_get_memory_requirements2 comes in handy.

For convenience all of that except VK_KHR_external_memory_win32 is also a core part of Vulkan 1.1.

Plus possibly external sync extensions too if\when you use thi

vkCreateInstance and vkCreateDevice.

How did you “got” a VkDeviceMemory from unreal??
Anyway, vkGetMemoryWin32HandleKHR is an export of Vulkan memory to outside. It converts a VkDeviceMemory to a Windows HANDLE. That really what you intended to do by that code snippet?

sorry for the late replay and thanks for your answer!

Currently I’m not using validation Layers. I think the engine should work properly.
If I’m still facing these issues I will try to implement these.

Okay. So I need to compile the engine code by myself.

Now I’m able to access PFN_vkGetMemoryWin32HandleKHR method. Now there is no exception thrown. Next issue is that I’m receiving a nullpointer handle. Why does this happen? Maybe I need to look more deeply into the Texture/Memory alloc process.

correct. The Unreal Engine offers a method, where I get the VkDeviceMemory.


Obviously I am not worried about the UE, but about your code.

The layers can simply be employed by installing the SDK, and setting VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation env. The errors appear in command-line by default.

I don’t know the internals of UE. But if it offers a VkDeviceMemory (which is itself weird), then I would bet it has a way to control instance and device creation.

You need to satisfy the VU checklist in Vulkan spec. For one, the memory has to be created as shareable. And you should check VkExternalMemoryProperties, if the driver supports this in the first place.


thanks for your answers!

I was not able to find some control options for this task. So I need to hack it into the source code.

It seems like the VkExportMemoryAllocateInfoKHR was missing. After implementing it into the source code I was able to call cuImportExternalMemory with CUDA_SUCCESS!


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.