Open smcv opened 5 days ago
At one point I thought about making it accessible via the DXGIFactory since we need to know which WSI to use the moment anything DXGI gets touched, but it's worth noting that a dxvk-native application must set the variable on startup, so if the application and its launcher both use it they're required to specify the WSI as if they were the base process (we treat "no value found" as a hard error to avoid apps depending on any kind of default value), so that would avoid the conflict in this particular example.
A real export wouldn't be so bad though, an example could be tried with this line in FNA3D: https://github.com/FNA-XNA/FNA3D/blob/master/src/FNA3D_Driver_D3D11.c#L5198
When a program uses DXVK-Native, currently it must set the environment variable
DXVK_WSI_DRIVER=SDL2
or similar, as documented in the README. This can be done by a wrapper script, or by callingsetenv()
orputenv()
at the beginning ofmain()
, for example something like this in a C++ executable that uses SDL2:However, setting environment variables like this inherits down through the process hierarchy: for example if a game launcher uses SDL2 and DXVK-Native, then every game launched by it would inherit
DXVK_WSI_DRIVER=SDL2
, even if the game has nothing to do with SDL2 and is actually using GLFW. This seems error-prone: the fact that the parent process (launcher) uses SDL2 for its HWND implementation is a fact about the parent process only, and generally not a true fact about its child processes.One solution that might be suggested is to unset the environment variable after initializing DXVK, but that usually isn't safe, because
environ
is shared state with no specific locking, therefore it is unsafe to edit the environment in one thread while another thread might be callinggetenv()
. Many libraries callgetenv()
in functions that might be called from a non-main thread, for example anything that usesgettext()
for localization, with the result that the only place that the environment can safely be altered is right at the beginning ofmain()
, before the first non-main thread has been created.Would it be possible to add a DXVK-specific way to set the WSI in use, as non-inheritable process-global state, analogous to
SDL_SetHint()
? Perhaps something like this?Or alternatively, a way to tell DXVK "my HWND is actually a SDL2 SDL_Window" via parameters to
CreateDeviceEx
orCreateSwapChainForHwnd()
or equivalent, or by calling a DXVK-specific method on the Device, or something of that sort (whatever layer is the most sensible one), so that you could do something like this?cc @flibitijibibo