Initializing D3D9 forces a third-party library to stop working

First, the general situation ... a third-party library loaded via a DLL does rendering in HWND. This is a simple 2D rendering and does not directly use D3D in the way that I see - depending on the DLL, a lot of D3DKMT functions are displayed, such as D3DKMTCreateDevice, but not ordinary D3D calls, such as IDirect3D9::CreateDevice. When I call IDirect3D9::CreateDevice, third-party rendering becomes sluggish. He does not complain, but simply displays everything as black rectangles. My own rendering works fine.

Specificity ... a third-party DLL is Mozilla XULRunner 1.9.x, which is the core of FireFox (not 2.0, which is equipped with hardware acceleration), wrapped in the wxWidgets wxWebConnect library. wxWC loads the XUL DLL and provides a web browser GUI component.

I have a working application using wx and wxWebConnect here, compiled exe and code: http://www.kirix.com/forums/viewtopic.php?f=25&t=911#p2605

Here is my real code, it is slightly related to wxWidgets, but not enough to make it hard to read - I get HWND from a random window just to initialize D3D, but I never render it:

void MyFrame::OnD3DButton( wxCommandEvent &event )
{
    static bool initialized = false;
    static LPDIRECT3D9 mpD3D = NULL;
    static LPDIRECT3DDEVICE9 mpD3DDevice=NULL;
    if(!initialized)
    {
        wxButton *button=wxDynamicCast(event.GetEventObject(), wxButton);
        HWND mHWnd = (HWND)button->GetHandle();
        mpD3D = Direct3DCreate9(D3D_SDK_VERSION);

        D3DPRESENT_PARAMETERS md3dpp;
        ZeroMemory( &md3dpp, sizeof(D3DPRESENT_PARAMETERS) );
        md3dpp.Windowed                 = true;
        md3dpp.SwapEffect               = D3DSWAPEFFECT_DISCARD;
        // triple buffer if VSync is on
        md3dpp.BackBufferCount          = 1;
        md3dpp.EnableAutoDepthStencil   = 0;
        md3dpp.hDeviceWindow            = mHWnd;
        md3dpp.BackBufferWidth          = 0;
        md3dpp.BackBufferHeight         = 0;
        md3dpp.FullScreen_RefreshRateInHz = 0;
        md3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
        md3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
        md3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
        md3dpp.MultiSampleQuality = 0;

        HRESULT hr = mpD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,mHWnd,
            D3DCREATE_MULTITHREADED|D3DCREATE_MIXED_VERTEXPROCESSING,&md3dpp,&mpD3DDevice);
        if(FAILED(hr))
            wxMessageBox(wxString("mpD3D->CreateDevice() FAILED"));
        else
        {
            wxMessageBox(wxString("mpD3D->CreateDevice() SUCCEEDED"));
            initialized = true;
        }
    }

}
+3
source share
2 answers

The problem may be that CreateDevice will change the state of the FPU if you do not pass the flag D3DCREATE_FPU_PRESERVE. It took me a lot of time to find this when I was bitten.

+5
source

Are you creating a D3D device with the same hwnd as a third-party dll?

, , - , direct3d , d3d.

+1

Source: https://habr.com/ru/post/1791970/


All Articles