A drop-in ddraw.dll that runs DirectDraw and Direct3D 3–7 games on Direct3D 9, on modern Windows and on Linux.
dd2d9 is a reimplementation of Windows XP SP3's ddraw.dll: DirectDraw 1–7 and Direct3D 3–7, drawn through Direct3D 9. It aims to behave call for call like the original (its checks, return codes and their order follow XP's own code), with XP's bugs fixed and modern options added: scaling filters, antialiasing, anisotropic filtering, a frame limiter, and the answers old games expect about memory, the processor and the desktop's colour depth. It's a single file, ddraw.dll, with no runtime to install.
- Requirements
- Installing
- Uninstalling
- What it does
- Settings
- Files dd2d9 uses
- Troubleshooting
- Building from source
- For developers
- License
- A 32-bit game that uses DirectDraw (DirectX 1–7), with or without Direct3D 3–7.
- Windows Vista or later with Direct3D 9, or Linux with Wine or Proton. (Not Windows XP: dd2d9 uses Vista's locks and timers.) Under Wine, dd2d9 presents through the prefix's Direct3D 9: Wine's own (wined3d), or DXVK if it's installed in the prefix.
- For games that also use 3dfx Glide (Need for Speed III, High Stakes, NFS4 and others of the Voodoo era): gl2d9 for the Glide part. Its README's Using gl2d9 with dd2d9 has the recommended settings for running both.
Copy ddraw.dll next to the game's exe. Don't replace the one in System32 or SysWOW64.
Either unzip the release and run install.sh for the prefix the game uses:
WINEPREFIX=~/Games/foo ./install.sh # every program in the prefix
WINEPREFIX=~/Games/foo ./install.sh --app game.exe # only game.exe; the rest keep Wine's ddrawThat copies the ddraw.dll beside the script (or build/ddraw.dll, in a source tree) into the prefix's 32-bit system folder (syswow64 in a 64-bit prefix, system32 in a 32-bit one), keeping Wine's own beside it as ddraw.dll.wine, sets the ddraw=native,builtin override (for the prefix, or with --app for the named programs only), and creates C:\windows\dd2d9.ini from dd2d9.ini.example if there's none. After a Wine or Proton update, run it again: the update may put Wine's ddraw.dll back, and where it doesn't, the copy kept of Wine's own is the old Wine's until you do.
Or, for one game: put ddraw.dll next to the game's exe and run the game with WINEDLLOVERRIDES="ddraw=n".
Set log=1 in dd2d9.ini and start the game. dd2d9.log appears next to the game's exe, with the version, the config files read and the settings in effect.
- Windows: delete
ddraw.dllfrom the game's folder. - Wine / Proton:
WINEPREFIX=~/Games/foo ./install.sh --uninstallputs Wine'sddraw.dllback and removes the prefix's override. It keepsdd2d9.ini; overrides made with--appstay, but fall back to Wine'sddraw. - You can also delete
dd2d9.inianddd2d9.log.
- Every interface version: IDirectDraw 1, 2, 4 and 7, IDirectDrawSurface 1, 2, 3, 4 and 7, palettes, clippers, gamma and colour controls, and the video port container. Their method tables are writable, as
ddraw.dll's, for overlays and patches that hook them. - Calls behave as in XP's
ddraw.dll: the checks, their order and the return codes follow its decompiled code, fromBlt's rectangle and flag rules to attachments, palettes and clippers. - Surfaces in system memory, laid out as
ddraw.dlllays them out.Lockgives a direct pointer, andGetDCputs a GDI device context right on that memory, so games that draw text with GDI work; aDDSCAPS_OWNDCsurface keeps its DC, as on XP. - A software blitter for all 2D: colour fills, raster ops, stretching, mirroring, source and destination colour keys (ranges too, compared colour by colour, as XP's driver compared them in video memory), overlapping copies, and conversion between 8, 16, 24 and 32-bit formats (to 8 bits, the nearest palette entry). Colour-keyed copies (sprites) use SSE2.
- Flip chains swap memory between surfaces, as the hardware did, including chains games put together themselves.
- Presenting: a thread of its own owns the Direct3D 9 device. It converts only the changed part of the image (applying the palette and the gamma ramp), scales it into the game's window and presents it, without holding up the game. Frames go out through the device's own
Present, so overlay and capture tools (RivaTuner, Afterburner) show and record them, 2D games included; through a swap chain of its own (IDirect3DSwapChain9::Present) only for a window larger than the device's image, and under Wine or without the desktop compositor for a Direct3D game flipping without vsync. - Gamma and colour controls: the primary's gamma ramp, calibrated by a gamma calibrator registered as for
ddraw.dll(DDSGR_CALIBRATE), andIDirectDrawColorControl's brightness, contrast, hue and saturation on the primary and on overlays, as the DirectX 7 SDK has them, applied to the picture (by pixel shaders, or by the CPU where there are none). - V-sync as the game asks:
Flipwaits for its frame unless the game passesDDFLIP_NOVSYNC; a Direct3D game that keeps flipping without vsync is also presented without waiting, so its frames aren't held to the refresh rate.WaitForVerticalBlank,GetScanLineandGetVerticalBlankStatusfollow the desktop compositor's vblank wherever there is one (vsync=offtoo), and a virtual vblank timer elsewhere (Wine, no compositor).
- Real display mode switches for exclusive-mode games, as the original did. The colour depth stays virtual: an 8-bit game runs on a 32-bit desktop. If the monitor lacks the mode, dd2d9 falls back to a borderless window with the image scaled.
display=windowanddisplay=borderlessavoid mode switches altogether. - Alt+Tab as in
ddraw.dll: losing focus restores the desktop and minimizes the game (not under i3 and sway, which don't minimize windows:minimize=), and coming back sets it up again. The game is told of it asddraw.dlltells it (not while its window is minimized: one left minimized in front, as Wine does under window managers that don't minimize, is restored a moment later; Alt+Tab's Tab let go sets it aside at once), and while it is in front the system's error boxes, the cursor shadow, hot tracking and the IME status window are off. A window that would be minimized with no taskbar button (owned, a tool window, or one the taskbar missed) stays reachable: its owner is minimized instead, or it gets a button while in the background. The screensaver and monitor power-off are blocked while the game is in front. - Lost surfaces as in
ddraw.dll: mode changes and focus loss make surfaces lost until the game restores them, as games expect; a mode change loses every DirectDraw object's surfaces, as on XP, not only those of the object that made it. Unlike on real hardware, their contents survive. - Several DirectDraw objects: a second one taking exclusive mode takes it over from the first, for games that recreate their DirectDraw object without releasing the old one. In normal mode, a window shows the object that last drew into it (a video renderer's movie over the game, as with DirectShow's Video Mixing Renderer 7).
- The game sees its own display mode as the screen when it's shown scaled or in a window, as after a real mode switch. Its cursor functions, every way of asking for the screen's size (
GetSystemMetrics, the desktop window's rectangle,GetMonitorInfo,EnumDisplaySettings' current mode), its window's rectangles and coordinate conversions, and its window's mouse messages are translated, so it sees its mode's coordinates with its window as the screen, and the cursor never leaves that screen. AChangeDisplaySettingsto that mode does nothing. The window's size messages and GDI's screen size are the mode's too. Graphics and input DLLs in the game folder (DXVK...) keep the real values. - Movies played by Windows' video player (MCI) into the game's window are scaled and placed with the game's image: the position the game gives in its mode's coordinates is translated, as the mouse's is, and so are the player's window control (MCIWnd), the picture placed in it and the command interface (
mciSendCommand, the player's own child window included, also opened by command string and moved by the game). The area a game is asked to repaint (WM_PAINT) is in its mode's coordinates too. - Fullscreen goes to the primary monitor, as with
ddraw.dll:display=switchanddisplay=borderlessalike, wherever Windows put the game's window.display=windowstays where the window is. - Windowed games get a desktop-sized primary surface, and the part under their window is shown; what a game draws into that window itself with GDI blits (
StretchDIBits,BitBltand the like) goes into the primary, so it shows with dd2d9's frames instead of flickering with them. - Overlays: overlay surfaces (RGB, YUY2, UYVY or YV12) are laid over the primary as it's presented, as the hardware showed them without touching its pixels: stretched or shrunk, mirrored, behind a destination colour key, with a source key (ranges too), bobbing a field at a time (
DDOVER_BOB,DDFLIP_ODD,DDFLIP_EVEN), with alpha and colour controls as the DirectX 7 SDK has them (the overlay's own alpha, alpha surfaces for it and for the destination, constants, edge blending around its source key), in their z-order.UpdateOverlay, the position and z-order methods and overlay flip chains followddraw.dll's checks. A windowed program paints the destination key into its window with GDI, so dd2d9 also looks for the key in what that window draws; in a window, only the part of an overlay over the program's own window shows. The video port container answers as with the Voodoo3: one port, which can't be made.videooverlay=offreports no overlay hardware. DDSCL_CREATEDEVICEWINDOW'sDirectDrawDeviceWndwindow covers the screen in exclusive mode and shows the picture, its mouse messages its own, asddraw.dll's.- PrintScreen copies the primary to the clipboard in exclusive mode where
EnablePrintScreenis set underHKLM\Software\Microsoft\DirectDraw, asddraw.dlldoes. - An 8-bit mode's screen is a palette device to GDI, as on XP:
GetDeviceCapssays so, andGetSystemPaletteEntriesandGetSystemPaletteUsegive the primary's palette as XP's GDI had it (the static colours at its ends while the primary has none).
- Direct3D 7 (
IDirect3D7,IDirect3DDevice7, vertex buffers), matched to XP'sd3dim700.dll, drawn through the same Direct3D 9 device dd2d9 presents with. It works on Windows' Direct3D 9 and on DXVK alike. - Direct3D 3–6 (devices, viewports, lights, materials, textures, execute buffers and vertex buffers), matched to XP's
d3dim.dll. As on XP, every vertex goes through a CPU front end (transformed, lit with the DirectX 5 or 6 light model, fogged and clipped), then Direct3D 9 draws it. The old render states are mapped onto texture stages as Microsoft's own rasterizer mapped them. - 2D over 3D works: textures, render targets and Z buffers get a GPU copy, and what Direct3D drew is read back before DirectDraw touches the pixels, so HUDs and menus drawn over a 3D frame show.
- Z buffers can be locked and blitted by DirectDraw like any surface, where the GPU samples depth textures (
INTZ: nearly all do, DXVK too; for Z buffers without stencil also AMD'sDF24andDF16) andzaccessisn'toff. Each lock waits for the GPU and copies the buffer back; a lock of at most 64×64 pixels (a lens flare's occlusion test) copies only its rectangle. With antialiasing on, a multisampled Z buffer is resolved for it (RESZ); a GPU without that turns antialiasing off the first time DirectDraw reads or writes a Z buffer. - Cube maps become Direct3D 9 cube textures, their faces drawn into read back as other render targets are.
- Bump maps (
DDPF_BUMPDUDV: U8V8, U5V5L6, U8V8L8) are listed and drawn where the GPU has environment-mapped bump mapping. - Luminance and alpha-only textures (8-bit luminance, luminance with alpha, 8-bit alpha) are drawn as Direct3D 9's own formats; Direct3D 7 hardware devices list them.
- Any number of lights on a Direct3D 7 device: with more enabled than the GPU lights at once (8 as a rule), dd2d9 lights those draws itself, as XP lit a hardware device's vertices, and Direct3D 9 draws them.
- Textures Direct3D drew into are copied on the GPU when used, mipmapped, colour-keyed (the key made transparent by a pixel shader) and palettized ones too (each colour made the palette entry the CPU's copy would give it).
- Clip status and picking: Direct3D 7's
GetClipStatusfollows what's drawn (the clip codes of untransformed vertices, with vertex blending and the user clip planes, and their extents withD3DRENDERSTATE_EXTENTS). Direct3D 3–6'sPickfinds the triangles under the point with their depth (the visible part of one the clip volume cuts),D3DOP_SPANis drawn (as points, as XP's driver path did), and Ramp devices light in shades of the material's colour, as the monochromatic Ramp model did. - What Direct3D 9 lacks is emulated: palettized textures (8-bit, and the 1-, 2- and 4-bit ones a game may create), and the software devices rendering to 8-bit surfaces as XP's RGB and Ramp rasterizers did (an 8-bit primary drawn into shown through its palette on the GPU).
- The gamma ramp applies to 3D frames too.
- Scaling: keep the aspect ratio, fill the screen or scale by whole numbers, with sharp-bilinear (the default), point or linear filtering.
- 3D quality: antialiasing, anisotropic filtering, mipmaps for textures that have none, linear filtering of point-filtered textures, 32-bit rendering of 16-bit targets (no banding) and 24-bit Z buffers.
- Old-hardware fixes: emulated W buffering (no z-fighting of light maps on roads in NFS III), and light maps and decals pulled forward as 16-bit depth buffers rounded them.
- A frame limiter for games that run too fast or use a whole processor core.
- What the game is told about the machine, as a PC of its era would answer:
- 1 GB of memory by default (
ram): Windows reports 2 GB and a 4 GB page file, and old games overflow adding them up and claim there isn't enough; - one processor for its threads (
cpus), and a 2 GHz clock in the registry (cpu); - a 256-colour, 16 or 24-bit desktop (
desktopbpp) for games that refuse a 32-bit one, through DirectDraw, GDI and the display settings alike.
- 1 GB of memory by default (
- Windows 9x and XP behaviour games relied on, on by default:
- memory from the process heap comes zeroed (
heapzero), for games that read it before writing, such as Daytona USA Deluxe; - a critical section a thread releases goes to the thread waiting for it (
fairlocks), where Windows since Vista lets the releasing thread take it straight back (KOF 99 Evolution's intro movie); - a multimedia timer's callback gets back the registers it should have kept (
safetimers), as Windows up to XP gave them back; Windows 10 and 11 crash after a callback that doesn't keep them (Mega Man X's sound library). Sound callbacks (waveOutOpen,midiOutOpen) get them back too, withselfsuspend=off; - the game's joystick reads are answered from a thread of dd2d9's (
joypoll), so a sound library that suspends the game's main thread, as Miles Sound System 3 does, can't leave it holding a joystick lock its own handler then waits for; - a sound callback that suspends its own thread carries on (
selfsuspend=off): Miles Sound System 3's sound callback suspends the main thread, and since Vista it runs on that very thread (Mega Man X stood still on a black screen). Anywhere else, a thread suspending itself is suspended; - a file the game opens with
FILE_FLAG_NO_BUFFERINGis opened without it (nobuffering=off), as Windows 95 and 98 ignored the flag; since NT every read of such a file must be whole, aligned sectors, and Biko crashed reading a 60-byte header that way; - a thread the game terminates isn't killed while it holds the loader's lock (
safeterminate): it gets 20 ms to end by itself and is then terminated with that lock held by the caller. Need for Speed III ends its movies by terminating the stream thread the moment the thread says it is done; on more than one processor that catches the thread in the middle of its ending, with the lock no thread can start without, and the game froze on a black screen; - while Direct3D Retained Mode (
d3drm.dll) is loaded, the back buffer gets a copy of the frame just shown after eachFlip(flipcopy=auto), where a flip leaves it the frame before: Retained Mode clears and draws again only the squares that changed, and the rest of its next frame showed the older one (Biko: a mosaic of two frames).
- memory from the process heap comes zeroed (
- Fullscreen windows: dd2d9 keeps the window's style, as
ddraw.dlldoes, but presents into the client area, so it makes the window slightly larger than the screen with its frame just off it. - 8-bit to RGB blits use the palette (
ddraw.dllcopies the index as grey). display=windowdoesn't lose surfaces on focus loss: the game keeps running.display=borderless(andwindow) don't lose surfaces across Alt+Tab: they report lost in the background, but back in front nothing is lost, as the display never left the game's mode (display=switchstill loses them, asddraw.dlldid). Need for Speed: High Stakes never restores its flip chain and quit at the first failed Flip.- Surface memory has slack around it: games that clip sprites loosely write a few rows past the bottom or above the top of their buffers, which XP's video memory and heap took without a crash.
- Back from Alt+Tab, surfaces outside the primary's flip chain can still be drawn with. They report lost as in
ddraw.dll, but keep their pixels, so games that don't restore all of theirs keep working (Captain Claw). In the background, lost surfaces can still be locked, for the same game. - Surfaces of a complex surface that outlive it stay usable (Jazz Jackrabbit 2 keeps drawing to its old back buffer).
- No reference leak when a DirectDraw 1 flip chain shrinks (
ddraw.dllleaks one). - A second DirectDraw object takes exclusive mode over from a first one that has lost activation, or whose window is gone or hidden.
- Each DirectDraw object in normal mode keeps its own display mode. In
ddraw.dllthe display mode is one for all: a mode one object sets shows in the others'GetDisplayModeand makes theirTestCooperativeLevelreturnDDERR_WRONGMODE. In dd2d9 only an exclusive object's mode is shown to the others. - Alt+Tab's and Alt+Esc's key-up and a suspend request set the game aside only where a focus loss minimizes its window: left as it is (
minimize=off, i3 and sway,DDSCL_NOWINDOWCHANGES), it would stay set aside in front, with nothing to restore it from. - Direct3D 3–6 checks what
d3dim.dllused blindly: unknown handles, a draw with no viewport, bad vertex types, execute-buffer offsets past the buffer and NULL pointers give errors instead of crashes.
BltBatchchecks its arguments and fails withDDERR_UNSUPPORTED, as inddraw.dll.- FourCC surfaces are limited to DXT1–5, YUY2, UYVY and YV12, what
GetFourCCCodeslists, made where XP made them. They blit to and from any surface through a decoding to 32-bit colour, encoded again when written (YUV as BT.601 video levels); their colour keys are compared as the colour they decode to. - Overlays take no alpha from their destination's own (
DDOVER_ALPHADEST): the primary has no alpha in its format, and no alpha channel can be attached to it (DDSCAPS_ALPHAsurfaces, whichCreateSurfacerefuses asddraw.dlldoes); no video port can be made (there is nothing to capture from). - Direct3D: where the GPU samples no depth textures (for a Z buffer with stencil: no
INTZ), or withzaccess=off, DirectDraw doesn't see what Direct3D drew into a Z buffer: it can clear one (DDBLT_DEPTHFILL), and a lock shows Direct3D's clears, not its triangles.
dd2d9 reads these files in order, later ones winning:
C:\windows\dd2d9.ini(in a Wine prefix,drive_c/windows/dd2d9.ini;install.shcreates it);dd2d9.ininext toddraw.dll;dd2d9.ininext to the game's exe;- the file named by the
DD2D9_INIenvironment variable.
Keys outside any section, in [dd2d9] or in [default] apply to every game. A [game.exe] section applies to that exe only. dd2d9.ini.example explains every key.
| Setting | Values (default first) |
|---|---|
display |
switch (real mode switches), window, borderless |
minimize |
auto (a fullscreen game's window is minimized when the game loses the focus, as with ddraw.dll, except under i3 and sway), on, off (left as it is). Tiling window managers don't minimize windows: under Wine a game's window minimized there didn't get the keyboard focus back from another workspace, and the game's mouse stood still. auto finds i3 and sway by the I3SOCK and SWAYSOCK they give the programs they start, or by the session's desktop (XDG_CURRENT_DESKTOP, XDG_SESSION_DESKTOP, DESKTOP_SESSION), or under Wine by their IPC socket, and stops minimizing once a window manager leaves the window minimized in front; under another tiling window manager, set off, but not under one that minimizes: under Openbox the window, left as it is, came back in front as soon as another desktop was switched to |
stretch |
aspect, fill, integer |
filter |
sharp (sharp bilinear: flat pixels, blended only over one screen pixel at their edges), point, linear |
vsync |
auto (the game decides), on, off (never waits, at most two presents a refresh). Under Windows' desktop compositor dd2d9 paces the frames to the screen's refresh itself; elsewhere (Wine, no compositor) Direct3D 9's vsync does |
d3d |
auto: dd2d9's own Direct3D 3–7; off: no Direct3D (2D only) |
d3d9 |
system (Windows' or the prefix's d3d9.dll, even when the game folder has DXVK's), game (the one the game loads) |
fpslimit |
0 (off); frames per second at most |
antialiasing |
0 (off); 2, 4 or 8 samples |
antialias2d |
off: with antialiasing, 2D drawn through Direct3D (HUDs, menus: screen-aligned, the depth test off or always passing, no depth written) stays pixel-sharp; on: antialiased like the 3D |
anisotropy |
0 (off); 2, 4, 8 or 16, on textures the game filters smoothly |
mipmaps |
off; on: the GPU makes smaller levels for textures the game gave none |
texfilter |
game; linear: point-filtered textures drawn bilinear (cut-outs keep the game's filtering) |
render32 |
off; on: 16-bit render targets drawn in 32 bits (no banding in blending and fog) |
depth24 |
off; on: 16-bit Z buffers made 24-bit (less z-fighting in the distance) |
wbuffer |
on: W buffering offered and emulated; force: also for transformed vertices; off |
overlaybias |
on: light maps and decals pulled forward one 16-bit depth step; off; a number for more steps |
alternatepixelcenter |
off; on: Direct3D drawn half a pixel up and left, as some old drivers offered |
ram |
1024: MB of memory games are told about, at most 2047; 0: the real values |
vram |
512: MB of video memory DirectDraw reports, 1–2047 |
cpu |
2000: MHz in the registry; 0: the real clock |
cpus |
1: processors the game's threads run on and the game is told about, numbered from 0 (GetSystemInfo and the affinity calls). The sound mixer's, Direct3D 9's, the display driver's and dd2d9's own threads are left on any processor, as the sound and the card were outside the game's processor on a machine of the time; 0: all, for everything |
heapzero |
on: the game's heap memory comes zeroed, as fresh memory often was on Windows 9x (Daytona USA Deluxe needs it); off: as Windows gives it |
fairlocks |
on: a critical section the game releases goes to the thread waiting for it, as up to Windows XP (KOF 99 Evolution's intro needs it); off: as Windows has it now |
safetimers |
on: a multimedia timer's callback (timeSetEvent) gets back the registers, stack and direction flag it should have kept, as up to Windows XP (Mega Man X needs it on Windows 10 and 11); off: as Windows has it now |
joypoll |
on: the game's joystick reads (joyGetPosEx, joyGetPos) are answered from what a thread of dd2d9's read a few milliseconds before (the first read of a joystick, and one after 2 s without any, goes to winmm when it isn't made inside a timer or sound callback); off: straight from winmm |
nobuffering |
off: FILE_FLAG_NO_BUFFERING is dropped from the game's CreateFileA/CreateFileW, as Windows 9x ignored it (Biko); on: kept, as Windows has it |
safeterminate |
on: TerminateThread waits up to 20 ms for the thread to end by itself and never kills it while it holds the loader's lock (Need for Speed III's movies on more than one processor); off: as Windows has it |
flipcopy |
auto: after each Flip the back buffer gets a copy of the frame just shown while Direct3D Retained Mode (d3drm.dll) is loaded (Biko needs it); on: always; off: never, as ddraw.dll has it |
selfsuspend |
off: a sound callback (waveOutOpen, midiOutOpen) that suspends its own thread carries on, and gets back the registers it should have kept (Mega Man X needs it since Vista); on: as Windows has it |
desktopbpp |
32; 8, 16 or 24: the desktop's colour depth the game is told about; while the game has a mode of its own, that mode's depth. With 8 a windowed game draws through a palette, as on a 256-colour desktop |
lockwhole |
off; on: a Lock of part of a surface counts as a change to all of it, for a game that writes outside what it locked |
zaccess |
on: Z buffers can be locked and blitted by DirectDraw where the GPU allows it; off: on the GPU only, for a driver that misbehaves with it |
palettizedtextures |
on: 8-bit palettized textures offered to Direct3D 3–7, as most cards of the time; off: not offered, as Matrox's G200/G400 (N.I.C.E. 2 then loads its 16-bit textures instead of its 256-colour ones) |
videooverlay |
on: overlay surfaces offered and laid over the primary when shown; off: no overlay hardware, so games blit instead |
log |
0; 1 (info); 2 (every blit, lock, flip, palette change, Direct3D 3 execute buffer, window message and failed call) |
drawtrace |
off; on: one frame's Direct3D draws logged every 600 scenes (about 10 s) |
logfile |
a path; by default dd2d9.log next to the game's exe |
Environment variables: DD2D9_INI names an extra config file. DD2D9_LOG=0, 1 or 2 overrides log; any other value is taken as a log file path (for example DD2D9_LOG='Z:\tmp\dd2d9.log' under Wine).
| File | |
|---|---|
ddraw.dll |
dd2d9 itself. |
dd2d9.ini |
Settings (see Settings). |
dd2d9.log |
Next to the game's exe, with log=1 or more. If that folder can't be written to, the current folder or %TEMP%. Send it with any bug report. |
- Nothing changes, and
log=1writes nodd2d9.log: dd2d9 isn't being loaded. Under Wine, check theddraw=noverride, or runinstall.shagain after a Wine update. On load, dd2d9 also sends a debug message saying where it was loaded from: under Wine 9,WINEDEBUG=warn+sehprints it; on Windows, use DebugView. - A game refuses to start on a 32-bit desktop ("16 bit screen mode required"): set
desktopbpp=16in a[game.exe]section;desktopbpp=8for one that asks for 256 colours. - A game says there isn't enough memory: keep
ramat its default, or lower it. - A game runs too fast: set
fpslimit. If it times itself from the registry's processor clock, trycpu=0. - The mouse is off in a scaled or windowed mode: please report it with
dd2d9.log(log=2); the translation can't be turned off since 1.3.0. - Z-fighting (hatched light maps or decals): try
wbuffer=forceor a higheroverlaybias, anddepth24=on. - Display mode switches are a problem:
display=borderlessordisplay=windowavoid them. - Under a tiling window manager, the game's mouse stops after switching workspaces: set
minimize=off(i3 and sway have it by default). - Under Wine with DXVK in the game's folder:
d3d9=system, the default, presents through the prefix's own Direct3D 9;d3d9=gameuses the game folder's. - The mouse freezes, or a game's own cursor sticks in a corner, in a game that reads the mouse through DirectInput 1–7 (N.I.C.E. 2): DirectInput's older versions get the mouse through a low-level hook that today's Windows can drop, and some games then use whatever their failed read left behind. Put dinputto8 (its
dinput.dll) next to the game, which passes DirectInput 1–7 on to DirectInput 8. - Something else: set
log=2and look for failed calls indd2d9.log. Please report problems with the log.
Requires mingw-w64 (i686) and Meson. On Arch: pacman -S mingw-w64-gcc meson.
meson setup build --cross-file build-win32.txt
ninja -C buildThe output is build/ddraw.dll, statically linked, with no MinGW runtime to install.
| Path | What |
|---|---|
src/ |
The DLL. ddraw.cpp and the dd*.cpp files beside it (the DirectDraw object: display modes, focus, the window, timing, caps, surface creation, the video port container), surface.cpp, attach.cpp, lock.cpp, buffer.cpp, palette.cpp, clipper.cpp (surfaces, palettes, clippers), blit*.cpp and fourcc.cpp (the software blitter, DXT and YUV), presenter.cpp, present*.cpp and quadpass.cpp (presenting through Direct3D 9, the full-screen passes), overlay.cpp, video.cpp, gpu.cpp and gpu*.cpp (the shared Direct3D 9 device, GPU copies of surfaces and textures, drawing), d3d7*.cpp (Direct3D 7), d3d6*.cpp (Direct3D 3–6: objects, devices, viewports, the CPU vertex pipeline and execute buffers), d3dxlate.cpp (state translation both share), compat*.cpp and hooks.cpp (import patching for the compatibility options), input*.cpp (mouse translation), convert.cpp (SSE2 pixel conversion), config.cpp, log.cpp, format.cpp, util.cpp (config, logging, pixel formats, locks). |
tests/ |
The test programs below. |
tests/wine/ |
Runs Wine's own ddraw test suite against a build and compares it with a baseline (see its README). |
re/ |
Reverse-engineering notes (below). |
tools/ |
ddtrace/: a separate ddraw.dll that logs a game's DirectDraw and Direct3D calls in front of any ddraw.dll (Windows' own, dd2d9 or another wrapper), for comparing them call for call (see its README). |
build/ddtest.exe writes its results to ddtest.txt:
- with no argument, pixel-exact checks of blits, keys and their ranges, conversion, GDI (
DDSCAPS_OWNDCtoo), YUV surfaces, interface versions, palettes, object lifetimes, cooperative levels and activation, gamma ramps (and the gamma calibrator, withfmtcal.dllbeside it and the registry writable), the modules the hooks reach (withhooktool.dllbeside it), and an 8-bit texture Direct3D draws into; ddtest overlaychecks overlays (keys and their ranges, alpha, bob and field flips, colour controls on them and on the primary, the video port container) andDDSCL_CREATEDEVICEWINDOW's window;ddtest fs8runs a 640×480×8 exclusive-mode flip-chain animation and checks the pacing;ddtest winruns a windowed primary with a clipper (and checks that the program's own GDI drawing into the window stays);ddtest mousechecks the mouse translation (run it withdisplay=borderless; withwincaller.dllnext to it and the Windows folder writable, it also checks that a Windows module's call reaching dd2d9's hook isn't translated);ddtest audit borderlessandddtest audit window(run with thatdisplayindd2d9.ini) take fullscreen the ways games do and check where the picture lands on the real screen, and that every way of asking for the screen's size gives the game's mode;ddtest fuzzruns thousands of random blits (8, 16 and 32-bit, colour keys (ranges in video memory, compared colour by colour; in system memory, asddraw.dll's software blitter, single colours), mirroring, stretching, overlapping copies, surfaces 65535 pixels wide and tall) against a reference implementation.
build/focustest.exe [paintfg] runs a 640×480×16 exclusive-mode flip chain for a minute, to be switched away from and back to (Alt+Tab); each second it writes the frames flipped and whether the window is minimized to focustest.txt. paintfg takes the foreground back in the window's WM_PAINT, as Need for Speed III does: switched away, it must stay away.
build/d3d7test.exe [w h [bpp]] [3d] [gamma] renders a Direct3D 7 triangle with DirectDraw fills and GDI text on top (3d: without), then flips; gamma sets an inverting gamma ramp. It writes d3d7test.txt.
All checks pass under Wine 11 (wined3d, Xvfb).
build/dfshim.dll, copied beside a test as d3d9.dll (with d3d9=game, and under Wine WINEDLLOVERRIDES=d3d9=n,b), is a Direct3D 9 without INTZ but with DF24 and DF16, as older Radeons and Intel's GPUs have them: the system's, its INTZ hidden and those two made as INTZ. It adds the depth textures it made to dfshim.txt. d3d7test and ddtest pass through it (d3d7test at 16 and 32 bits, with antialiasing and depth24=on too).
tests/wine/ runs Wine's own ddraw tests (expectations confirmed on Windows) against a build and compares the result with a baseline; see tests/wine/README.md.
tests/sdk/ runs the DirectX 7 SDK's samples with dd2d9 and with Wine's own ddraw and compares screenshots of the two (run.sh, then compare.py; the samples' locations are set in run.sh).
build/ddbench.exe measures performance and writes ddbench.txt: ddbench blit (blitter throughput), ddbench flip <w> <h> <bpp> (a sprite game loop), ddbench window (small updates to a windowed primary), ddbench zlock [w h] (Direct3D frames with small and whole locks of the Z buffer). With log=1, the presenter logs every 10 seconds how much of the frame it converted and how long the game waited for it.
build/d3dimbench.exe [seconds] checks and times Direct3D 3-6's CPU vertex pipeline: ProcessVertices with lights, fog and clipping (and odd vertices: NaN, infinities, zero normals), a lit sphere drawn with DrawIndexedPrimitive (whole, and a row at a time through IDirect3DDevice2, which transforms only the vertices each draw uses), 2048 small DrawPrimitive calls of transformed vertices a frame (the cost of a draw), one texture drawn with colour keying on and off in turn (and the key checked transparent only with it), and execute buffers (a TRIANGLE instruction per row, per triangle, and cut by the near plane), and checks that consecutive TRIANGLE instructions draw the same pixels as drawn one by one. It writes d3dimbench.txt with a hash of each part's output, the time spent in the drawing calls, the transformed vertices (d3dimbench-tl-*.bin) and images (d3dimbench-*.raw, 256x256 32-bit): two builds meant to give the same output are compared by those.
build/fmtprobe.exe asks whatever ddraw.dll it loads and writes the answers to fmtprobe.txt: run beside dd2d9's it shows dd2d9's, and without it Windows' own (on XP with a card of the time, or on today's Windows). The first part:
- the texture formats each Direct3D 7 device and Direct3D 3's and 2's hardware and software devices list;
- whether luminance, alpha-only, bump-map and 1- and 4-bit palettized surfaces can be made as textures, as plain surfaces and as render targets (a new device on them,
SetRenderTargetto them); - what plain 1-, 2-, 4- and 8-bit surfaces do (pitch, fills, a DC with and without a palette, palettes of other sizes, blits);
SetRenderTargetand the target the device then has, and what each target format holds after a clear;- which 8-bit layouts are made with the display in 256 colours (it sets that mode for a moment).
With DirectX 7 present a second part follows:
- the registry keys and files Direct3D's device lists depend on, every device list and Z-buffer format, and the caps as hex words;
- reference counts,
EnumSurfaces, texture-management calls and palettes; - stretched, clipped and overlapping blits (which source pixel each destination pixel takes);
- clears through Direct3D 1-3's viewports, and each device's default states;
- exclusive mode step by step (
TestCooperativeLevel, lost surfaces, the window's messages, gamma ramps; it changes the display mode several times); - Z buffers with stencil in layouts no device lists: where they are made, and what each device does with one of 15 bits and 1 of stencil;
- surfaces of very many pixels (up to 65535x65535: slow where memory is short);
- the words clears and draws leave in Z buffers of 16, 24 and 32 bits;
- colour-key ranges in blits and overlays; overlays' bob, field flips, alpha flags and effects, and the colour controls; the video port container; Z buffers whose depth and stencil share bits; the device window's mouse messages;
DDSCAPS_OWNDC; exclusive mode's activation and focus loss (the system's settings, the flip chain, Alt+Tab's key-up, a suspend request,CheckFullscreen); YUV surfaces and their fills; the gamma calibrator (fmtcal.dllbeside the probe, registered underHKLMwhile its section runs, which takes an administrator's rights); the primary copied to the clipboard on PrintScreen (EnablePrintScreen, set underHKLMwhile its section runs, and put back); GDI's palette of an 8-bit screen beside DirectDraw's palettes; - some 300 calls with missing or invalid arguments.
Each section of the second part, and each of those calls, runs in a process of its own (fmtprobe section N, fmtprobe try N), so a ddraw.dll that crashes or hangs in one loses only that one, and the file says so. The probe runs on Windows 98 with DirectX 6 too (a Pentium Pro or later), where it leaves Direct3D 7 out; fmtprobe dx6 (or a copy named fmtprobe-dx6.exe) does so anywhere, and writes fmtprobe-dx6.txt.
build/reloadtest.exe [dll] frees and reloads dd2d9 (by default ddraw_.dll) while the game window stays subclassed, as a wrapper loading dd2d9 under another name may do.
build/shimtest.exe [call], with build/fakeshim.dll beside it, runs dd2d9 under a stand-in for Windows' compatibility shims: fakeshim.dll hooks ddraw.dll's GetProcAddress import as it loads and, when called, patches the program's import again and passes calls on to what it found there, as the shim engine did to N.I.C.E. 2's setup (with a jump, or with a call given call). It writes shimtest.txt (shimtest-call.txt), which ends in ALL PASSED when GetProcAddress calls return with the shim's answers; a file that stops before its last line means the process died in a loop between the two hooks.
re/ has the vtable map of XP SP3's ddraw.dll (5.3.2600.5512), with naming scripts for Ghidra and IDA. re/spec/ describes, from its decompiled code, what each method checks and in which order, with the differences from dd2d9 that remain. CHANGELOG.md explains every change and which game or test showed the need for it.
Thanks to KyoriAsh for testing dd2d9 with many lesser-known games, for running tests on
older versions of Windows in virtual machines to show how the original ddraw.dll behaves,
and for his help throughout.
MIT, see LICENSE. dd2d9 contains no Microsoft code or binaries.