Why Can't DirectX be Ported to Linux?

DirectX is just an API so why can't it be ported to Linux? I know the Proprietary DirectX User Runtime and User Mode Drivers would both have to be reimplemented to conform to the Linux DRM driver model in MESA or similar, and I'm not necessarily saying it would be a good use of developer time, but is there any reason that a native Linux port of DirectX couldn't theoretically happen by someone other than Microsoft? I would think that a project like MESA could basically take DX calls and turn it into the same sorts of operations that would need to happen to support OpenGL / Vulkan. I am aware that this would require re-writing a bunch of code i.e DirectX is not a state-machine like OpenGL is, but ultimately I guess the question is would such a pursuit be possible or is there something that makes it entirely infeasible?

Edited by Bronxolon on
Valve worked on something like this a few years ago, while porting their engine to Linux: https://github.com/ValveSoftware/ToGL. There was also this effort to translate DirectX11 to Vulkan.

In a technical sense, it's totally possible to port DirectX to Linux, by either translating calls to a Linux supported API like OpenGL or Vulkan, or by implementing a driver. I can't speak about the legal aspects, however this is probably why there's no official DirectX driver on Linux.
While porting D3D api itself would be possible either by translation to GL, Vulkan or driver commands directly, there is other part of D3D api that would make such porting harder - DXGI. That is part that provides swap chains and integrates with windowing system. It allows to pass HWND to create swap chain. Where will you get HWND on Linux? And HMONITOR? Will it be X11 window? Wayland window? Will it be DRM buffer? It will require a whole new level of abstraction that does not exist in mesa or on Linux. At that point it sounds almost easier just to use Wine to run .exe compiler for Windows which uses D3D - Wine knows how to display window and translate D3D to GL.

Edited by Mārtiņš Možeiko on