Skip to content
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

Thunks: Implement support for 32-bit Vulkan thunking #2294

Closed

Conversation

neobrain
Copy link
Member

Simplified version of #1611, redesigned from the ground up around requirements for 32-bit Vulkan specifically. For the time being, this allows us to omit the full-blown analysis pass to check for ABI-compatibility between guest/host architectures.

Overview

This PR adds assisted automated repacking of structs with differing data layout between guest and host. Repacking is fully automatic for "simple" structures (i.e. no pointers, and all members are either built-in types with same size on guest and host or they are simple structs themselves).

For pointer members/parameters, repacking must be assisted by one of these generator annotations:

  • Type annotation opaque_type: Used for "handle"-like types that don't have any publicly visible member data. (This will skip any repacking.)
  • Type-member annotation custom_repack: Allows for a user-provided function to be called after size-extending the pointer to host-layout. All other architecture differences are assumed to be taken care of by that function.
  • Type-member/Function annotation param_is_sized_array: Used to specify that a function parameter is a dynamically-sized array, the size of which is specified by another function parameter. Repacking logic (if needed) is recursively applied to each element in the array. (NOT IMPLEMENTED)

Impact

All currently thunked libraries will likely need annotations for pointer-types throughout their respective APIs. The full scope of this is TBD.

TODO

(incomplete)

  • Implement param_is_sized_array annotation
  • Add full compatibility with the Vulkan API

This is useful information e.g. when map lookup from clang::Type pointers
fails during code generation.
Repacking is fully automatic for structures composed of simple types
with compatible ABI across guest/host architectures.

To repack structures with pointers, the custom_repack annotation can be
used. Repacking will still be automated then (with the pointer being
extended from guest-size to host-size), but a call to a user-provided
function is emitted to handle architecture differences.
Struct repacking logic is skipped for pointers to opaque types.

// Normally, we would implement fex_custom_repack individually for each customized struct.
// In this case, they all need the same repacking, so we just implement it once and alias all fex_custom_repack instances
extern "C" const_void_ptr default_fex_custom_repack(const const_void_ptr& source) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess these shouldn't be references since checking for nullptr on a reference is...icky?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oop wait, it's a reference to a pointer type, nevermind.

@neobrain
Copy link
Member Author

Superseded by #3487.

@neobrain neobrain closed this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants