-
Notifications
You must be signed in to change notification settings - Fork 123
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
Library Forwarding: Add support for 32-bit Vulkan #3487
Draft
neobrain
wants to merge
14
commits into
FEX-Emu:main
Choose a base branch
from
neobrain:feature_libfwd_vulkan32
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…acking_exit const
…yout_wrappers is used
…ayout This allows automatic repacking of structs with array members.
…m_repack This is useful in particular for union members. A guest_layout specialization must be provided manually for the type of the annotated member.
…when needed This only needs to be done for functions that have a custom host-side implementation and that don't take a VkDevice argument.
…hat use custom repacking
Sonicadvance1
added a commit
to Sonicadvance1/FEX
that referenced
this pull request
Mar 20, 2024
This will be necessary before FEX-Emu#3487 is merged. Once FEX-Emu#3487 is merged then 32-bit Vulkan thunk libraries is built which results in crashing in every 32-bit vulkan/dxvk game. Explicitly disable the thunking until this config option is set. Once X11 is as stable on 32-bit as 64-bit then this option can get removed. For testing purposes it's easy to set the environment variable `FEX_THUNKS32BITENABLED=1`
Sonicadvance1
added a commit
to Sonicadvance1/FEX
that referenced
this pull request
Mar 20, 2024
This will be necessary before FEX-Emu#3487 is merged. Once FEX-Emu#3487 is merged then 32-bit Vulkan thunk libraries is built which results in crashing in every 32-bit vulkan/dxvk game. Explicitly disable the thunking until this config option is set. Once X11 is as stable on 32-bit as 64-bit then this option can get removed. For testing purposes it's easy to set the environment variable `FEX_THUNKS32BITENABLED=1`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me even with the bit of debug logging and fetching of symbols each time an entrypoint is called.
Needs #3500 merged first to ensure we don't regress user's behaviour.
5 tasks
This was referenced May 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This brings together virtually every feature added to
thunkgen
over the past year to add preliminary support for running 32-bit applications with Vulkan calls forwarded to the 64-bit host driver. This moves us to Phase 4 of the Library Forwarding Roadmap:The incomplete but large subset of the Vulkan API covered here is sufficient to run
zink
:Since X11 cannot be forwarded in 32-bit applications yet, this support is limited to Wayland only.
Implementation
Object handles
Vulkan structs that only contain object handles usually have compatible layout between 32-bit and 64-bit, but sometimes they need special treatment. This is because Vulkan distinguishes between "dispatchable" handles and "non-dispatchable" handles.
Most handles are non-dispatchable (e.g.
VkPipeline
,VkFramebuffer
): They're represented asuint64_t
and hence don't need any special handling. Dispatchable handles (e.g.VkDevice
,VkQueue
) are pointer-sized and hence need to be zero-extended. For structs containing dispatchable handles, this is done via custom repacking.Furthermore, each dispatchable handle type is annotated as
fexgen::opaque_type
, which allows functions that take handle parameters directly to be forwarded automatically.Vulkan's extension mechanism: pNext
The vast majority of struct types in Vulkan are extensible, since they contain a
pNext
pointer to other Vulkan structs (which in turn may also contain such apNext
pointer). This poses a major challenge for 32-bit support, since this pointer immediately breaks data layout compatibility even in otherwise trivially compatible member arrangements. FEX's forwarding code for Vulkan hence makes extensive use of custom repacking, and it's combined with a simple macro to automate it to some extent.Arrays of structs
The Vulkan API uses pointers-to-arrays in some places:
If the 32-bit data layout of the element type matches the one on 64-bit, there's nothing we need to do. However if it does differ, we have to manually repack each element individually.
thunkgen
won't directly help here, since it cannot distinguish a pointer-to-array from a simple pointer-to-object.For function parameters, this is done using
fexgen::ptr_passthrough
:For structs, custom repacking is used instead:
In both cases, the helper function
RepackStructArray
does the actual legwork of repacking (also considering recursing into any potentialpNext
pointers).Testing
Two programs have been verified to work with the lavapipe Vulkan driver:
vkcube
Super Meat Boy
running via zink:SDL_VIDEODRIVER=wayland EGL_PLATFORM=wayland MESA_LOADER_DRIVER_OVERRIDE=zink FEXInterpreter ./SuperMeatBoy
TODO
[ ] Verify forwarding works on hardware drivers, too