WineD3D on Windows

Compiling WineD3D for use on Windows

WineD3D is the core of Wine's Direct3D implementation. In WineD3D we translate Direct3D functions to Windows OpenGL. The use of Windows OpenGL allows WineD3D and several Direct3D dlls to function on Windows.

At the moment Direct3D8 (d3d8.dll) , Direct3D9 (d3d9.dll) and Direct3D 10 can be used on Windows. DirectDraw and Direct3D<7 can't be used at this point due to a conflict with opengl32.dll. [In short ddraw.dll loads wined3d somewhere at startup (e.g. when a surface is created). Wined3d dynamicly loads opengl32.dll when it is loaded. During initialization of wined3d we query the opengl capabilities and for this purpose use opengl functions like wglCreateContext and wglMakeCurrent. It appears that when wglMakeCurrent is called, this triggers opengl32.dll to create a directdraw surface (so native opengl32.dll calls our ddraw.dll!) and since wined3d wasn't initialized we again have to initialize opengl and this causes some infinite loop. There are hacks to get it to run but it is very unstable and 3d won't work. The proper solution is likely to avoid opengl32.dll and directly load the ICD.]

The Wine 3D dlls can be cross-compiled like any other Wine dll or test. Care should be taken that '-DUSE_WIN32_OPENGL' is used when compiling WineD3D. This flag is needed because on Windows we load gl functions from opengl32.dll but on Linux we have a hack around to use libGL.so.

The script below can be used to cross-compile d3d8/d3d9/wined3d from a Linux machine. The script has been tested on Debian and Ubuntu. On Debian/Ubuntu the mingw binaries are all prefixed with 'i586-mingw32msvc' hence '--host=i586-mingw32msvc' on Gentoo for instance a different prefix is used and there you need '--host=i686-mingw32'. The script assumes mingw is around and that the Wine source code is in a directory 'wine-git'.

#!/bin/sh
set -ex
unset CC
rm -rf wine-tools wine-win32
mkdir -p wine-tools
cd wine-tools
$HOME/wine-git/configure --without-x
make __tooldeps__
cd ..
mkdir -p wine-win32
cd wine-win32
$HOME/wine-git/configure --without-x --without-freetype --host=i586-mingw32msvc CFLAGS="-O2 -DWINE_NOWINSOCK -DUSE_WIN32_OPENGL" --with-wine-tools=$HOME/wine-tools/
make dlls/d3d10 dlls/d3d10core dlls/d3d8 dlls/d3d9 dlls/dxgi dlls/wined3d
mkdir -p crossdlls
cp dlls/d3d10/d3d10.dll dlls/d3d10core/d3d10core.dll dlls/d3d8/d3d8.dll dlls/d3d9/d3d9.dll dlls/dxgi/dxgi.dll dlls/wined3d/wined3d.dll libs/wine/libwine.dll crossdlls/

Installation

Note: precompiled versions of WineD3D from official Wine releases are available at http://www.nongnu.org/wined3d/

After compilation you need to copy all the dlls you've built. You can place the dlls in the directory of the program you want to run.

Alternatively, you can install them system-wide by copying them to c:\windows\system32\ (overwriting Microsoft versions) and removing d3d8.dll and d3d9.dll in c:\windows\system32\dllcache\. Note that if you do that, Windows will detect this, and will prompt you to insert the installation CD to revert to MS versions of the DLLs.

You might also be interested in wiki page Parallels to follow code changes being made.

Software emulation and pseudo-dedicated server

Sometimes it's useful to run an emulated D3D backend with null 3D display, allowing for running games as dedicated servers, which weren't designed to in the first place!

Please clone my wined3d-null branch if interested.

If one needs a headless server, it's recommended to run tightvnc (Debian sid binary will suffice if libgl1-mesa-swx11 is installed) due to its GLX support.

It's even possible to cross-compile Wine and Mesa for i686-w64-mingw32 for Windows support of aforementioned functionality.

For Mesa:

scons build=release machine=generic platform=windows toolchain=crossmingw llvm=no debug=yes verbose=yes texture_float=no libgl-gdi

For Wine:

$HOME/dev/wine/configure --without-x --without-freetype --host=i686-w64-mingw32 --target=i686-w64-mingw32 CFLAGS='-O2 -g -DWINE_NOWINSOCK -DUSE_WIN32_OPENGL' --with-wine-tools=$HOME/dev/wine-build-mingw/win32/.. ac_cv_prog_DLLWRAP='i686-w64-mingw32-gcc -shared -shared-libgcc'

You may need to force-enable -shared-libgcc and -lstdc++ for Mesa. There were nasty libgcc crashes seen with static linking.


WineD3DOnWindows (last edited 2014-01-08 09:07:39 by WangMingye)