The d3d4linux project allows to compile HLSL shaders on Linux using the Microsoft DirectX compiler DLL. It works by launching a Windows program in the background using Wine and diverting calls to that server on the fly.
Note: this is not for porting games to Linux. The goal of this project is to use Linux machines to build and package Windows games (because Linux build machines are cheaper and more reliable). You could see it as “shader cross-compilation”. In the end you still get HLSL bytecode which is of little use on Linux.
Only four functions are implemented for now. They are the ones required by the Unreal Engine shader compiler:
D3DCompileD3DReflectD3DStripShaderD3DDisassemble
d3d4linux is work in progress and not ready for production but is being successfully used at Dontnod Entertainment to package Windows versions of Unreal Engine 4 games.
Prerequisites:
apt install g++-mingw-w64
Build d3d4linux:
make
Prerequisites:
apt install wine64
Launch the test:
make check
Patch and build:
- copy
d3d4linux.Build.csand theincludedirectory toEngine/Sources/ThirdParty/d3d4linux. - copy
d3d4linux.exeand thed3dcompilerDLLs toEngine/Binaries/ThirdParty/d3d4linux. - apply one of the patches found in the
extrasdirectory to the Unreal source tree. - verify and optionally tweak the
D3D4LINUX_macros inEngine/Source/Developer/Windows/ShaderFormatD3D/Private/D3D11ShaderCompiler.cppso that they match your desired setup (note that these can also be overridden at runtime using the similarly named environment variables) - make sure to rebuild
UE4EditorandShaderCompileWorker.
Cook:
- with AutomationTool: run
BuildCookRunas usual with the-targetplatform=Win64argument. - with UE4Editor: run with the
-run=Cook -TargetPlatform=WindowsNoEditorarguments.
Debug:
- set the
D3D4LINUX_VERBOSEenvironment variable to1for some debugging information.