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:
Code:
gcc -o d3dtest d3dtest.c -ld3d9 -lX11
./d3dtest
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:
Code:
#include <d3d9xlib.h>
#include <stdio.h>

Display *g_dpy;
IDirect3D9 *g_d3d9;

const D3DFORMAT fb_formats[] = {
    D3DFMT_A2R10G10B10,
    D3DFMT_X8R8G8B8,
    D3DFMT_X1R5G5B5,
    D3DFMT_R5G6B5
};

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";
        default:
            return "Unknown";
    }
}

void
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);
        return;
    }

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

void
print_adapter_info( UINT adapter )
{
    D3DADAPTER_IDENTIFIER9 ident;
    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);
        return;
    }

    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;
        default:
            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;
        default:
            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"
           "|\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.Data3,
           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],
           ident.WHQLLevel);

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

        modecount = IDirect3D9_GetAdapterModeCount(g_d3d9, adapter,
                                                   fb_formats[i]);
        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,
                   d3dformat_to_string(cmode.Format));
        }
    }
}

int
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");
        XCloseDisplay(g_dpy);
        return 1;
    }

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

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

    IDirect3D9_Release(g_d3d9);
    XCloseDisplay(g_dpy);

    return 0;
}