Quote Originally Posted by smitty3268 View Post
Ouch. Ok, you're right, i didn't actually look at the code and was trying to go off what i thought. However, doesn't this go against what was earlier said that native apps couldn't run against it? Is there some other reason this is true? I confess to not really understanding the commit you linked to, because it's just a big deletion of the wine code, so it doesn't really show how you achieved the support without it and i'm not familiar enough with mesa/graphics code to find that on my own.
It's designed so that the state tracker doesn't know about the window system, only the subsystem (drm in this case). For this I came up with ID3DAdapter9 and its accompanying Present interfaces. Originally there were two libraries, both compiled from within the mesa tree; notably libd3d9-xlib. IDirect3D9[Ex] is a completely self contained interface and although it parrots many Windows-isms it's by no means dependent on Windows. As you can see from this ginormous, ugly function, mapping X11 to the functions in the IDirect3D9[Ex] interface is perfectly possible. This was in fact the way I originally tested the driver as it was significantly easier than getting it to work with wine's internals and pulling useful debug information.
The libd3d9-xlib implementation bitrotted and eventually it was nuked since everything was done through wine, but it could easily be revived and you'd have completely wine-less Direct3D 9 available. Literally this:
gcc -o d3dtest d3dtest.c -ld3d9 -lX11
The only difference was the entrance points (a technicality if you ask me) because it was easier and mirrored GLX in a lot of ways. Here's an example program:
#include <d3d9xlib.h>
#include <stdio.h>

Display *g_dpy;
IDirect3D9 *g_d3d9;

const D3DFORMAT fb_formats[] = {

const char *
d3dformat_to_string( D3DFORMAT fmt )
    switch (fmt) {
        case D3DFMT_A2R10G10B10: return "D3DFMT_A2R10G10B10";
        case D3DFMT_X8R8G8B8: return "D3DFMT_X8R8G8B8";
        case D3DFMT_X1R5G5B5: return "D3DFMT_X1R5G5B5";
        case D3DFMT_R5G6B5: return "D3DFMT_R5G6B5";
            return "Unknown";

print_mode_info( UINT adapter,
                 UINT mode,
                 D3DFORMAT format )
    D3DDISPLAYMODE modeinfo;
    HRESULT hr;

    hr = IDirect3D9_EnumAdapterModes(g_d3d9, adapter, format, mode, &modeinfo);
    if (FAILED(hr)) {
        printf("| | ERROR 0x%08x: Unable to query mode info %u on adapter %u\n",
               hr, mode, adapter);

    printf("| | %ux%u @ %uHz\n",
           modeinfo.Width, modeinfo.Height, modeinfo.RefreshRate);

print_adapter_info( UINT adapter )
    HRESULT hr;
    UINT modecount;
    unsigned i, j;
    const char *os, *runtime;

    hr = IDirect3D9_GetAdapterIdentifier(g_d3d9, adapter, 0, &ident);
    if (FAILED(hr)) {
        printf("ERROR 0x%08x: Unable to query adapter %u\n", hr, adapter);

    switch ((ident.DriverVersionHighPart >> 16) & 0xFFFF) {
        case 4: os = "Windows 95/98/NT4"; break;
        case 5: os = "Windows 2000"; break;
        case 6: os = "Windows 2000/XP"; break;
        case 7: os = "Windows Vista"; break;
        case 8: os = "Windows 7"; break;
            os = "Unknown";
    switch (ident.DriverVersionHighPart & 0xFFFF) {
        case 11: runtime = "Direct3D 6"; break;
        case 12: runtime = "Direct3D 7"; break;
        case 13: runtime = "Direct3D 8"; break;
        case 14: runtime = "Direct3D 9"; break;
        case 15: runtime = "Direct3D 10"; break;
        case 16: runtime = "Direct3D 10.1"; break;
        case 17: runtime = "Direct3D 11"; break;
            runtime = "Unknown";

    printf("Adapter %u:\n"
           "| Driver: %s\n"
           "| Description: %s\n"
           "| DeviceName: %s\n"
           "| DriverVersion:\n"
           "| | OS: %s\n"
           "| | Runtime: %s\n"
           "| | Version: %u\n"
           "| | Build: %u\n"
           "| VendorId: 0x%x\n"
           "| DeviceId: 0x%x\n"
           "| SubSysId: 0x%x\n"
           "| Revision: %u\n"
           "| GUID: {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n"
           "| WHQL: 0x%08x\n"
           adapter, ident.Driver, ident.Description, ident.DeviceName, os,
           runtime, (ident.DriverVersionLowPart >> 16) & 0xFFFF,
           ident.DriverVersionLowPart & 0xFFFF, ident.VendorId,
           ident.DeviceId, ident.SubSysId, ident.Revision,
           ident.DeviceIdentifier.Data1, ident.DeviceIdentifier.Data2,
           ident.DeviceIdentifier.Data4[0], ident.DeviceIdentifier.Data4[1],
           ident.DeviceIdentifier.Data4[2], ident.DeviceIdentifier.Data4[3],
           ident.DeviceIdentifier.Data4[4], ident.DeviceIdentifier.Data4[5],
           ident.DeviceIdentifier.Data4[6], ident.DeviceIdentifier.Data4[7],

    for (i = 0; i < sizeof(fb_formats)/sizeof(*fb_formats); ++i) {
        printf("| Modes (%s):\n",

        modecount = IDirect3D9_GetAdapterModeCount(g_d3d9, adapter,
        if (modecount > 0) {
            for (j = 0; j < modecount; ++j) {
                print_mode_info(adapter, j, fb_formats[i]);
        } else {
            printf("|   None\n");

        D3DDISPLAYMODE cmode;

        printf("| Current Mode:\n");
        hr = IDirect3D9_GetAdapterDisplayMode(g_d3d9, adapter, &cmode);
        if (FAILED(hr)) {
            printf("|   ERROR 0x%08x: Unable to query "
                   "current mode on adapter %u\n", hr, adapter);
        } else {
            printf("|   %ux%u @ %uHz (%s)\n",
                   cmode.Width, cmode.Height, cmode.RefreshRate,

main( int argc,
      char *argv[] )
    UINT i, adaptercount;

    g_dpy = XOpenDisplay(NULL);
    if (!g_dpy) { fprintf(stderr, "XOpenDisplay failed!\n"); return 1; }

    g_d3d9 = XDirect3DCreate9(D3D_SDK_VERSION, g_dpy);
    if (!g_d3d9) {
        fprintf(stderr, "XDirect3DCreate9 failed!\n");
        return 1;

    adaptercount = IDirect3D9_GetAdapterCount(g_d3d9);
    if (adaptercount == 0) {
        printf("No adapters present on this system.\n");

    for (i = 0; i < adaptercount; ++i) {
        if (i != adaptercount-1) { printf("\n"); }


    return 0;