I have archlinux OS, nvidia gtx1650, nvidia-465 drivers, vulkan 1.2.
There is a code that I want to export image from Xorg to GPU via VK_EXT_external_memory_host extension. This extension is supported in the specified drivers. But I get the ErrorOutOfDeviceMemory error.
There is an assumption that this behavior happens because of incorrectly aligned memory by the passed pointer - I haven’t checked this theory yet, but then why exactly this error is printed instead of, say, VK_ERROR_INVALID_EXTERNAL_HANDLE…
And another thing - my graphics card driver doesn’t provide available memory with needed memoryTypeIndex and flag { DeviceLocal }, i.e. there is only memory with { HostVisible | HostCoherent }, or with { HostCached } added.
Did not fully check your code, but I got the same error upon importing an fd on a different process. I fixed the problem by transferring the fd to the unrelated process via unix domain sockets [0]. The spec mentions that opaque fds should be transferable using unix domain sockets but nowhere states you must do that… so you must read between the lines in the spec:
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT specifies a POSIX file descriptor handle that has only limited valid usage outside of Vulkan and other compatible APIs. It must be compatible with the POSIX system calls dup , dup2 , close , and the non-standard system call dup3 . Additionally, it must be transportable over a socket using an SCM_RIGHTS control message. It owns a reference to the underlying memory resource represented by its Vulkan memory object.
I think I figured out what the problem is - it seems to be in allocated memory - vkImportMemoryHostPointerInfoEXT structure requires that pointer passed to it should point to memory area of exactly as many bytes as specified after vkAllocateMemory() allocation - and for this case it should be multiple of alignment value.
In other words, when importing it tries to copy all memory starting from the pointer address to the size specified in the allocation. But I allocate memory which is not a multiple of the alignment value, and it usually ends up with a bit less, which makes vulkan api start using memory outside of the chunk of memory that was allocated for the image.
I should try to allocate memory as a multiple of the alignment value.
Yes – everything works now – I made the memory allocation a multiple of the alignment, specify this size in the vulkan memory allocation structure and everything is fine now – the images are imported into the vulkan api