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

[wsi] Refactor platform system to support multiple WSI implementations #3738

Merged
merged 6 commits into from
May 13, 2024

Conversation

flibitijibibo
Copy link
Contributor

@flibitijibibo flibitijibibo commented Dec 8, 2023

This reorganizes the WSI backend system to support multiple backends in a single binary - this is important for dxvk-native which can support either SDL2 or GLFW. We achieve this by doing the following:

  • Add a refcounted init/quit system to WSI, which is used by DxvkInstance
  • Move the WSI-specific code from dxvk_platform_exts to WSI
  • SDL2 and GLFW are now dynamically loaded, rather than dynamically linked, to avoid hard dependencies that could otherwise be optional
  • The WSI backends are now implementations of a common interface, which effectively implements the same API that was exposed to the rest of DXVK. WSI init will iterate through each compiled-in backend and continue until one of them successfully initializes. This can be overridden with the DXVK_WSIDRIVER environment variable.

Supercedes #3736

Part of #3451

Fixes #3321

Obsoletes #3324

@flibitijibibo
Copy link
Contributor Author

Latest push is another rebase - I've got some spare cycles this week so if there's anything that needs to be addressed in this (or the other two) PRs let me know and I'll get it done ASAP!

This is preparation for loading/unloading WSI backends at runtime, which will be in an upcoming commit.
This ensures that all of the WSI backend logic is in one place rather than two.
…interface.

Rather than directly calling functions, the API now calls shared functions that call into a WsiDriver instance, which is allocated and implemented by the backend. Functionally this should be the same, it just has the extra allocation for the function table.

This prepares the WSI library for supporting multiple implementations in a single binary.
Removing these link-time dependencies is important for making a single binary that is compatible with either backend, regardless of whether or not each one is currently available to the program.
Copy link
Owner

@doitsujin doitsujin left a comment

Choose a reason for hiding this comment

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

Looking into (finally) getting this merged for the 2.4 release among other stuff, looks good overall, just one concern.

src/wsi/wsi_platform.cpp Outdated Show resolved Hide resolved
…ction.

Since we're not linking to the libraries anymore, it doesn't make much sense to
use find_library, and in fact we need to use dependency() in order to get the
right CFLAGS for includes, defines, etc, so use that instead.

As a result, we can remove the 'SDL2/' folders from the includes, making the SDL
includes more correct.
@flibitijibibo
Copy link
Contributor Author

Latest push adjusts the behavior of DXVK_WSIDRIVER, particularly when the variable is unset: When Win32 is available we assume that is the default, when it is not available we throw an explicit error requesting that the variable be set.

@misyltoad misyltoad merged commit 6259e86 into doitsujin:master May 13, 2024
3 checks passed
@flibitijibibo flibitijibibo deleted the wsi-final branch May 13, 2024 13:26
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.

Native builds with SDL and GLFW are incompatible, so should have different SONAMEs
3 participants