VirtualBox

Changeset 42971 in vbox for trunk/src


Ignore:
Timestamp:
Aug 24, 2012 11:19:31 AM (12 years ago)
Author:
vboxsync
Message:

wddm/3d: fix app crashes on shut down

Location:
trunk/src/VBox/Additions/WINNT/Graphics
Files:
3 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
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c

    r42516 r42971  
    19581958    }
    19591959
     1960    if (This->swapchains)
     1961    {
    19601962    HeapFree(GetProcessHeap(), 0, This->swapchains);
    19611963    This->swapchains = NULL;
    19621964    This->NumberOfSwapChains = 0;
     1965    }
     1966    else
     1967    {
     1968        Assert(!This->NumberOfSwapChains);
     1969    }
    19631970
    19641971    for (i = 0; i < This->NumberOfPalettes; i++) HeapFree(GetProcessHeap(), 0, This->palettes[i]);
     
    70057012    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
    70067013    int i;
     7014    IWineD3DSwapChain **pvOldBuf = This->swapchains;
     7015
    70077016    for (i = 0; i < This->NumberOfSwapChains; ++i)
    70087017    {
     
    70427051            context_destroy(This, This->contexts[0]);
    70437052        }
    7044     }
     7053        This->swapchains = NULL;
     7054    }
     7055
     7056    if (pvOldBuf)
     7057        HeapFree(GetProcessHeap(), 0, pvOldBuf);
     7058
    70457059    return WINED3D_OK;
    70467060}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c

    r42499 r42971  
    6262}
    6363
    64 VOID swapchain_invalidate(IWineD3DSwapChainImpl *pSwapchain)
     64static VOID swapchain_cleanup_rt_refs(IWineD3DSwapChainImpl *pSwapchain, IWineD3DSurface *rt, int iBb)
     65{
     66    IWineD3DDeviceImpl *device = pSwapchain->device;
     67    struct wined3d_context *context;
     68    UINT i;
     69    for (i = 0; i < device->numContexts; ++i)
     70    {
     71        context = device->contexts[i];
     72
     73        if (rt == context->current_rt)
     74        {
     75            context->current_rt = NULL;
     76        }
     77    }
     78
     79    if (device->NumberOfSwapChains)
     80    {
     81        IWineD3DSwapChainImpl *pDefaultSwapchain = (IWineD3DSwapChainImpl*)device->swapchains[0];
     82        for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
     83        {
     84            if (device->render_targets[i] == rt)
     85            {
     86                IWineD3DSurface *newRt;
     87                if (i)
     88                    newRt = NULL;
     89                else if (iBb == -1) /* front buffer */
     90                    newRt = pDefaultSwapchain->frontBuffer;
     91                else
     92                    newRt = pDefaultSwapchain->backBuffer ? pDefaultSwapchain->backBuffer[0] : pDefaultSwapchain->frontBuffer;
     93
     94                IWineD3DDevice_SetRenderTarget((IWineD3DDevice*)device, i, newRt, TRUE);
     95            }
     96        }
     97    }
     98}
     99
     100static VOID swapchain_cleanup_refs(IWineD3DSwapChainImpl *pSwapchain)
    65101{
    66102    /* first make sure the swapchain is not used by anyone */
     
    76112            context->currentSwapchain = NULL;
    77113        }
    78 
    79         if (pSwapchain->frontBuffer == context->current_rt)
    80         {
    81             context->current_rt = NULL;
    82         }
    83         else if (pSwapchain->backBuffer)
    84         {
    85             UINT j;
    86             for (j = 0; j < pSwapchain->presentParms.BackBufferCount; ++j)
    87             {
    88                 if (pSwapchain->backBuffer[j] == context->current_rt)
    89                 {
    90                     context->current_rt = NULL;
    91                     break;
    92                 }
    93             }
    94         }
    95     }
     114    }
     115
     116    if (pSwapchain->frontBuffer)
     117        swapchain_cleanup_rt_refs(pSwapchain, pSwapchain->frontBuffer, -1);
     118
     119    if (pSwapchain->backBuffer)
     120    {
     121        UINT j;
     122        for (j = 0; j < pSwapchain->presentParms.BackBufferCount; ++j)
     123        {
     124            swapchain_cleanup_rt_refs(pSwapchain, pSwapchain->backBuffer[j], j);
     125        }
     126    }
     127}
     128
     129static VOID swapchain_invalidate(IWineD3DSwapChainImpl *pSwapchain)
     130{
     131    swapchain_cleanup_refs(pSwapchain);
    96132
    97133    pSwapchain->win_handle = NULL;
     
    105141{
    106142    IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
    107     WINED3DDISPLAYMODE mode;
    108143    unsigned int i;
    109144
     
    111146
    112147    IWineD3DSwapChain_SetGammaRamp(iface, 0, &This->orig_gamma);
     148
     149#ifdef VBOX_WITH_WDDM
     150    /* first remove swapchain from a list to ensure context is properly acquired
     151     * & gl resources are properly cleared on last swapchain destruction */
     152    IWineD3DDevice_RemoveSwapChain((IWineD3DDevice*)This->device, (IWineD3DSwapChain*)This);
     153
     154    swapchain_cleanup_refs(This);
     155#endif
    113156
    114157    /* Release the swapchain's draw buffers. Make sure This->backBuffer[0] is
     
    154197        This->presentRt = NULL;
    155198    }
    156 #endif
    157 
     199
     200    if(This->win_handle) {
     201        VBoxExtWndDestroy(This->win_handle, This->hDC);
     202        swapchain_invalidate(This);
     203    }
     204    else
     205    {
     206        WARN("null win info");
     207    }
     208#else
    158209    IWineD3DDevice_RemoveSwapChain((IWineD3DDevice*)This->device, (IWineD3DSwapChain*)This);
    159210    if (!This->device->NumberOfSwapChains)
     
    165216         */
    166217        if(This->presentParms.Windowed == FALSE && This->presentParms.AutoRestoreDisplayMode) {
     218            WINED3DDISPLAYMODE mode;
    167219            mode.Width = This->orig_width;
    168220            mode.Height = This->orig_height;
     
    172224        }
    173225    }
    174 #ifdef VBOX_WITH_WDDM
    175     if(This->win_handle) {
    176         VBoxExtWndDestroy(This->win_handle, This->hDC);
    177         swapchain_invalidate(This);
    178     }
    179     else
    180     {
    181         WARN("null win info");
    182     }
    183 #else
     226
    184227    HeapFree(GetProcessHeap(), 0, This->context);
    185228#endif
     229
    186230    HeapFree(GetProcessHeap(), 0, This);
    187231}
Note: See TracChangeset for help on using the changeset viewer.

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