-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support thunking of multi-instance Vulkan applications #1774
Comments
After playing a bit at this with the copyable functions, and looking at the codegen, repacking the arguments can be /very/ expensive. I'm not sure yet of how it would look in practice, but i think intercepting after the arguments have been packed would make things much more efficient as then we can just pass around the pointer to them. Then things would look
The guest packer could add the host_ptr as a second argument to the guest handler, and we could amend the thunk op there to take two parameters, so we can pack a variable amount of data independently of the original argument list. Which would constrain us in other ways, but the host_ptr case would fit right in, instead of being an exception. |
Copyable functions PoC in our X11 thunks FEX/ThunkLibs/libX11/libX11_Host.cpp Line 61 in c5f1929
Boilerplate aside, DECL_COPYABLE_TRAMPLOLINE(XUnregisterIMInstantiateCallbackCBFN)
Bool fexfn_impl_libX11_XUnregisterIMInstantiateCallback_internal(
Display* a0, struct _XrmHashBucketRec* a1,
char* a2, char* a3, XUnregisterIMInstantiateCallbackCBFN* a4, XPointer a5) {
auto fn = binder::make_instance(a4, &CallbackMarshaler<XUnregisterIMInstantiateCallbackCBFN>::marshal<offsetof(CallbackUnpacks, libX11_XUnregisterIMInstantiateCallbackCB)>);
return fexldr_ptr_libX11_XUnregisterIMInstantiateCallback(a0, a1, a2, a3, fn, a5);
} |
FEX's libvulkan thunks don't work if multiple
VkInstances
are used that return different function pointers tovkGetDeviceProcAddr
. This is because to implementvkGetDeviceProcAddr
in the first place, FEX needs to pre-query aVkInstance
-specific function pointer during initialization. The function pointer itself is called without any direct reference to the originalVkInstance
, so FEX acts as if only the first VkInstance created by the application was used.In the broader picture, the problem is a restriction in the thunk generator: Functions that must be guest-callable through host function pointers can not use a custom guest entrypoint.
Suggested solution: Extending framework for guest-callable host function pointers
Currently, guest-callable host function pointers are implemented by linking the host function pointer to a generic template function that forwards the packed argument list plus the original host function pointer to a
hostcall_
thunk. In this case, the function pointer isvkGetDeviceProcAddr
as returned fromvkGetInstanceProcAddr
. What's needed is a way of customizing the target function: Instead of calling the thunk that initiates a Guest->Host transition, a custom function should be called.Implementation sketch of the guest-side thunk library:
The text was updated successfully, but these errors were encountered: