可以在进程之间共享纹理而无需复制纹理数据吗?

huangapple go评论80阅读模式
英文:

Is it possible to share textures between processes without texture's data copy?

问题

我认为可以尝试使用Vulkan的外部内存扩展,在进程A中分配内存,创建一个HANDLE指向该内存,并通过共享内存将该HANDLE传递给进程B。

但是这似乎不可能,因为HANDLE实际上只是一个void*,不同进程存在不同的内存映射,因此指针/HANDLE实际上不能在进程之间传递

是否有一种方法可以在不复制所有图像像素数据的情况下,在不同的进程中获取句柄并重新创建GL纹理/VK图像(类似于使用PBO时的情况)?

英文:

I tought that it might work using the Vulkan's external memory extension by allocating the memory in process A, create a HANDLE to that memory and pass that HANDLE via shared memory to process B.

But this seems is not possible as HANDLE is actually just a void* and for different processes exist different memory mapping, so the pointer/HANDLE is actually not transferable between processes.

Is there some way how to get the handle somehow and recreate the GL texture/ VK image in different process without copying all images's pixel data (like when PBO is used)?

答案1

得分: 6

要将HANDLE传递给不同的进程,请使用函数DuplicateHandle,它将创建一个引用同一对象的重复句柄,但在另一个进程中。然后,您需要通过某种IPC方式将新的HANDLE的值(在原始进程中无法使用)传递给其他进程。您可以使用共享内存,发送消息,或者...总之,任何允许您向其他进程发送sizeof(void*)大小的整数的方式,即在C中的uintptr_t。然后,您只需将HANDLE强制转换为uintptr_t,将该数值发送到其他进程,然后在那里将其转换回HANDLE

您必须手动执行此操作,因为没有机制告诉进程,突然之间,一个全新的HANDLE已经神奇地出现在它们的任务上下文中。

英文:

To transfer a HANDLE to a different process use the function DuplicateHandle, which will create a duplicate handle referencing the same object, but in the other process. Then you'll have to pass the value of that new HANDLE (which isn't usable in the original process) to the other process by some means of IPC. You could use shared memory, or send a message, or… well whatever that allows you to send the other process an integer of sizeof(void*), i.e. in terms of C a uintptr_t. You then just cast the HANDLE to a uintptr_t send that numeric value to the other process, where you cast it back to a HANDLE.

You have to do this manually, since there's no mechanism in place, that tells a process that suddenly and out of the blue an entirely new HANDLE was magicked into their task context.

huangapple
  • 本文由 发表于 2023年7月24日 19:21:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753964.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定