VirtualBox

Ignore:
Timestamp:
Aug 24, 2012 11:19:31 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
80301
Message:

wddm/3d: fix app crashes on shut down

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp

    r42683 r42971  
    449449}
    450450
     451static void vboxResourceInit(PVBOXWDDMDISP_RESOURCE pRc, UINT cAllocs)
     452{
     453    memset(pRc, 0, RT_OFFSETOF(VBOXWDDMDISP_RESOURCE, aAllocations[cAllocs]));
     454    pRc->cAllocations = cAllocs;
     455    for (UINT i = 0; i < cAllocs; ++i)
     456    {
     457        pRc->aAllocations[i].iAlloc = i;
     458        pRc->aAllocations[i].pRc = pRc;
     459    }
     460}
     461
    451462static PVBOXWDDMDISP_RESOURCE vboxResourceAlloc(UINT cAllocs)
    452463{
    453     PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)RTMemAllocZ(RT_OFFSETOF(VBOXWDDMDISP_RESOURCE, aAllocations[cAllocs]));
     464    PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)RTMemAlloc(RT_OFFSETOF(VBOXWDDMDISP_RESOURCE, aAllocations[cAllocs]));
    454465    Assert(pRc);
    455466    if (pRc)
    456467    {
    457         pRc->cAllocations = cAllocs;
    458         for (UINT i = 0; i < cAllocs; ++i)
    459         {
    460             pRc->aAllocations[i].iAlloc = i;
    461             pRc->aAllocations[i].pRc = pRc;
    462         }
     468        vboxResourceInit(pRc, cAllocs);
    463469        return pRc;
    464470    }
     
    12431249                            && pBbAlloc->SurfDesc.format == pRt->pAlloc->SurfDesc.format
    12441250                            && pBbAlloc->SurfDesc.VidPnSourceId == pRt->pAlloc->SurfDesc.VidPnSourceId
    1245 #if 0
    1246                             && (pBbRc == pRtRc
    1247                                     || (pBbRc->fFlags == pRtRc->fFlags
    1248                                             && pBbRc->RcDesc.enmPool == pRtRc->RcDesc.enmPool
    1249 //                                            && pBbRc->RcDesc.fFlags.Value == pRtRc->RcDesc.fFlags.Value
    1250                                         )
    1251 
    1252                                 )
    1253 #endif
    12541251                            )
    12551252                {
     
    14601457}
    14611458
    1462 static VOID vboxWddmSwapchainFillParams(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, D3DPRESENT_PARAMETERS *pParams)
     1459static VOID vboxWddmFillPresentParams(D3DPRESENT_PARAMETERS *pParams, PVBOXWDDMDISP_RESOURCE pRc, UINT cRTs)
     1460{
     1461    Assert(cRTs);
     1462    memset(pParams, 0, sizeof (D3DPRESENT_PARAMETERS));
     1463    pParams->BackBufferWidth = pRc->aAllocations[0].SurfDesc.width;
     1464    pParams->BackBufferHeight = pRc->aAllocations[0].SurfDesc.height;
     1465    pParams->BackBufferFormat = vboxDDI2D3DFormat(pRc->aAllocations[0].SurfDesc.format);
     1466    pParams->BackBufferCount = cRTs - 1;
     1467    pParams->MultiSampleType = vboxDDI2D3DMultiSampleType(pRc->RcDesc.enmMultisampleType);
     1468    pParams->MultiSampleQuality = pRc->RcDesc.MultisampleQuality;
     1469#if 0 //def VBOXDISP_WITH_WINE_BB_WORKAROUND /* this does not work so far any way :( */
     1470    if (cRTs == 1)
     1471        pParams->SwapEffect = D3DSWAPEFFECT_COPY;
     1472    else
     1473#endif
     1474    if (pRc->RcDesc.fFlags.DiscardRenderTarget)
     1475        pParams->SwapEffect = D3DSWAPEFFECT_DISCARD;
     1476    pParams->Windowed = TRUE;
     1477}
     1478
     1479static VOID vboxWddmSwapchainFillPresentParams(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, D3DPRESENT_PARAMETERS *pParams)
    14631480{
    14641481    Assert(pSwapchain->cRTs);
     
    14671484    Assert(pSwapchain->cRTs <= 2);
    14681485#endif
    1469     memset(pParams, 0, sizeof (D3DPRESENT_PARAMETERS));
    14701486    PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainGetBb(pSwapchain);
    14711487    PVBOXWDDMDISP_RESOURCE pRc = pRt->pAlloc->pRc;
    1472     pParams->BackBufferWidth = pRt->pAlloc->SurfDesc.width;
    1473     pParams->BackBufferHeight = pRt->pAlloc->SurfDesc.height;
    1474     pParams->BackBufferFormat = vboxDDI2D3DFormat(pRt->pAlloc->SurfDesc.format);
    1475     pParams->BackBufferCount = pSwapchain->cRTs - 1;
    1476     pParams->MultiSampleType = vboxDDI2D3DMultiSampleType(pRc->RcDesc.enmMultisampleType);
    1477     pParams->MultiSampleQuality = pRc->RcDesc.MultisampleQuality;
    1478 #if 0 //def VBOXDISP_WITH_WINE_BB_WORKAROUND /* this does not work so far any way :( */
    1479     if (pSwapchain->cRTs == 1)
    1480         pParams->SwapEffect = D3DSWAPEFFECT_COPY;
    1481     else
    1482 #endif
    1483     if (pRc->RcDesc.fFlags.DiscardRenderTarget)
    1484         pParams->SwapEffect = D3DSWAPEFFECT_DISCARD;
     1488    vboxWddmFillPresentParams(pParams, pRc, pSwapchain->cRTs);
    14851489}
    14861490
     
    14891493{
    14901494    D3DPRESENT_PARAMETERS Params;
    1491     vboxWddmSwapchainFillParams(pSwapchain, &Params);
     1495    vboxWddmSwapchainFillPresentParams(pSwapchain, &Params);
    14921496    IDirect3DSurface9* pD3D9OldFb = NULL;
    14931497    IDirect3DSwapChain9 * pOldIf = pSwapchain->pSwapChainIf;
     
    17011705    {
    17021706        VBOXWINEEX_D3DPRESENT_PARAMETERS Params;
    1703         vboxWddmSwapchainFillParams(pSwapchain, &Params.Base);
     1707        vboxWddmSwapchainFillPresentParams(pSwapchain, &Params.Base);
    17041708        Params.pHgsmi = NULL;
    17051709
     
    18101814            {
    18111815                D3DPRESENT_PARAMETERS Params;
    1812                 vboxWddmSwapchainFillParams(pSwapchain, &Params);
     1816                vboxWddmSwapchainFillPresentParams(pSwapchain, &Params);
    18131817                IDirect3DSurface9* pD3D9Surf;
    18141818                hr = pDevice9If->CreateRenderTarget(
     
    21302134static HRESULT vboxWddmD3DDeviceCreateDummy(PVBOXWDDMDISP_DEVICE pDevice)
    21312135{
    2132     HRESULT hr;
    2133     PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(2);
    2134     Assert(pRc);
    2135     if (pRc)
    2136     {
    2137         pRc->RcDesc.enmFormat = D3DDDIFMT_A8R8G8B8;
    2138         pRc->RcDesc.enmPool = D3DDDIPOOL_LOCALVIDMEM;
    2139         pRc->RcDesc.enmMultisampleType = D3DDDIMULTISAMPLE_NONE;
    2140         pRc->RcDesc.MultisampleQuality = 0;
    2141         for (UINT i = 0 ; i < pRc->cAllocations; ++i)
    2142         {
    2143             PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];
    2144             pAlloc->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
    2145             pAlloc->SurfDesc.width = 0x4;
    2146             pAlloc->SurfDesc.height = 0x4;
    2147             pAlloc->SurfDesc.format = D3DDDIFMT_A8R8G8B8;
    2148         }
    2149 
    2150         PVBOXWDDMDISP_SWAPCHAIN pSwapchain;
    2151         hr = vboxWddmSwapchainCreateIfForRc(pDevice, pRc, &pSwapchain);
    2152         Assert(hr == S_OK);
    2153         if (hr != S_OK)
    2154             vboxResourceFree(pRc);
    2155     }
    2156     else
    2157     {
    2158         hr = E_OUTOFMEMORY;
    2159     }
    2160 
    2161     return hr;
     2136    VBOXWDDMDISP_RESOURCE Rc;
     2137    vboxResourceInit(&Rc, 1);
     2138
     2139    Rc.RcDesc.enmFormat = D3DDDIFMT_A8R8G8B8;
     2140    Rc.RcDesc.enmPool = D3DDDIPOOL_LOCALVIDMEM;
     2141    Rc.RcDesc.enmMultisampleType = D3DDDIMULTISAMPLE_NONE;
     2142    Rc.RcDesc.MultisampleQuality = 0;
     2143    PVBOXWDDMDISP_ALLOCATION pAlloc = &Rc.aAllocations[0];
     2144    pAlloc->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
     2145    pAlloc->SurfDesc.width = 0x4;
     2146    pAlloc->SurfDesc.height = 0x4;
     2147    pAlloc->SurfDesc.format = D3DDDIFMT_A8R8G8B8;
     2148    Assert(!pDevice->pDevice9If);
     2149    VBOXWINEEX_D3DPRESENT_PARAMETERS Params;
     2150    vboxWddmFillPresentParams(&Params.Base, &Rc, 2);
     2151    Params.pHgsmi = &pDevice->Uhgsmi.BasePrivate.Base;
     2152    DWORD fFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
     2153    PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
     2154    IDirect3DDevice9 * pDevice9If = NULL;
     2155
     2156    HRESULT hr = pAdapter->D3D.pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, fFlags, &Params.Base, &pDevice9If);
     2157    if (!SUCCEEDED(hr))
     2158    {
     2159        WARN(("CreateDevice failed hr 0x%x", hr));
     2160        return hr;
     2161    }
     2162
     2163    pDevice->pDevice9If = pDevice9If;
     2164    return S_OK;
    21622165}
    21632166
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette