VirtualBox

Changeset 37734 in vbox


Ignore:
Timestamp:
Jul 1, 2011 4:36:39 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
72600
Message:

wddm/3d: 1.fix ie9 under Aero (still some problems w/o Aero), 2.Fix the driver crash

Location:
trunk/src/VBox/Additions/WINNT/Graphics/Video
Files:
8 edited

Legend:

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

    r37640 r37734  
    15291529    return hr;
    15301530}
    1531 
    1532 #if 0
    1533 static HRESULT vboxWddmRenderTargetUpdateSurface(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pAlloc, uint32_t iBBuf)
    1534 {
    1535     if (pAlloc->SurfDesc.VidPnSourceId != pDevice->iPrimaryScreen)
    1536         return S_OK;
    1537 
    1538     IDirect3DSurface9 *pD3D9Surf;
    1539     IDirect3DDevice9 *pDevice9If = pDevice->aScreens[pDevice->iPrimaryScreen].pDevice9If;
    1540     HRESULT hr = pDevice9If->GetBackBuffer(0 /*UINT iSwapChain*/,
    1541             iBBuf, D3DBACKBUFFER_TYPE_MONO, &pD3D9Surf);
    1542     Assert(hr == S_OK);
    1543     if (hr == S_OK)
    1544     {
    1545         Assert(pD3D9Surf);
    1546         Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
    1547         if (pAlloc->pD3DIf)
    1548             pAlloc->pD3DIf->Release();
    1549         pAlloc->pD3DIf = pD3D9Surf;
    1550     }
    1551     return hr;
    1552 }
    1553 static HRESULT vboxWddmRenderTargetUpdate(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_RESOURCE pRc, uint32_t iNewRTFB)
    1554 {
    1555     if (pRc->RcDesc.VidPnSourceId != pDevice->iPrimaryScreen)
    1556         return S_OK;
    1557 
    1558     PVBOXWDDMDISP_ALLOCATION pAlloc;
    1559     UINT iBBuf = 0;
    1560     Assert(iNewRTFB < pRc->cAllocations);
    1561 
    1562     for (UINT i = 1; i < pRc->cAllocations; ++i, ++iBBuf)
    1563     {
    1564         UINT iAlloc = (iNewRTFB + i) % pRc->cAllocations;
    1565         Assert(iAlloc != iNewRTFB);
    1566         pAlloc = &pRc->aAllocations[iAlloc];
    1567         HRESULT tmpHr = vboxWddmRenderTargetUpdateSurface(pDevice, pAlloc, iBBuf);
    1568         Assert(tmpHr == S_OK);
    1569     }
    1570 
    1571     pAlloc = &pRc->aAllocations[iNewRTFB];
    1572     if (pRc->cAllocations > 1)
    1573     {
    1574 #ifdef VBOXWDDM_WITH_VISIBLE_FB
    1575         HRESULT tmpHr = vboxWddmRenderTargetUpdateSurface(pDevice, pAlloc, ~0UL /* <- for the frontbuffer */);
    1576         Assert(tmpHr == S_OK);
    1577 #else
    1578         if (pAlloc->pD3DIf)
    1579         {
    1580             pAlloc->pD3DIf->Release();
    1581             pAlloc->pD3DIf = NULL;
    1582         }
    1583 #endif
    1584     }
    1585     else
    1586     {
    1587 #ifndef VBOXDISP_WITH_WINE_BB_WORKAROUND
    1588 # error "port me!"
    1589 #endif
    1590         /* work-around wine backbuffer for devices w/o backbuffers */
    1591         HRESULT tmpHr = vboxWddmRenderTargetUpdateSurface(pDevice, pAlloc, 0);
    1592         Assert(tmpHr == S_OK);
    1593     }
    1594 
    1595 #ifdef DEBUG
    1596     for (UINT i = 0; i < pRc->cAllocations; ++i)
    1597     {
    1598         pAlloc = &pRc->aAllocations[i];
    1599         if (iNewRTFB == i)
    1600         {
    1601             Assert((!pAlloc->pD3DIf) == (pRc->cAllocations > 1));
    1602         }
    1603 
    1604         for (UINT j = i+1; j < pRc->cAllocations; ++j)
    1605         {
    1606             PVBOXWDDMDISP_ALLOCATION pAllocJ = &pRc->aAllocations[j];
    1607             Assert(pAlloc->pD3DIf != pAllocJ->pD3DIf);
    1608         }
    1609     }
    1610 #endif
    1611     return S_OK;
    1612 }
    1613 #endif
    16141531
    16151532static D3DFORMAT vboxDDI2D3DFormat(D3DDDIFORMAT format)
     
    18411758    {
    18421759#ifndef VBOXWDDM_WITH_VISIBLE_FB
    1843         pSwapchain->pRenderTargetFbCopy->Release();
    1844         pSwapchain->pRenderTargetFbCopy = NULL;
    1845         pSwapchain->bRTFbCopyUpToDate = FALSE;
     1760        if (pSwapchain->pRenderTargetFbCopy)
     1761        {
     1762            pSwapchain->pRenderTargetFbCopy->Release();
     1763            pSwapchain->pRenderTargetFbCopy = NULL;
     1764            pSwapchain->bRTFbCopyUpToDate = FALSE;
     1765        }
    18461766#endif
    18471767        pSwapchain->pSwapChainIf->Release();
     
    21922112    PVBOXWDDMDISP_RENDERTGT pRt = &pSwapchain->aRTs[iRt];
    21932113    HRESULT hr = pSwapchain->pSwapChainIf->GetBackBuffer(iBb, D3DBACKBUFFER_TYPE_MONO, &pD3D9Surf);
    2194     Assert(hr == S_OK);
    2195     if (hr == S_OK)
    2196     {
    2197         PVBOXWDDMDISP_ALLOCATION pAlloc = pRt->pAlloc;
    2198         Assert(pD3D9Surf);
    2199         Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
    2200         if (pAlloc->pD3DIf)
    2201         {
    2202             if (pSwapchain->fFlags.bChanged)
    2203             {
    2204                 IDirect3DSurface9 *pD3D9OldSurf = (IDirect3DSurface9*)pAlloc->pD3DIf;
    2205                 if (pD3D9OldSurf && pD3D9OldSurf != pD3D9Surf)
    2206                 {
    2207                     VOID *pvSwapchain = NULL;
    2208                     HRESULT tmpHr = pD3D9OldSurf->GetContainer(IID_IDirect3DSwapChain9, &pvSwapchain);
    2209                     if (tmpHr == S_OK)
    2210                     {
    2211                         Assert(pvSwapchain);
    2212                         ((IDirect3DSwapChain9 *)pvSwapchain)->Release();
    2213                     }
    2214                     else
    2215                     {
    2216                         Assert(!pvSwapchain);
    2217                     }
    2218                     if (pvSwapchain != pSwapchain->pSwapChainIf)
    2219                     {
     2114    if (FAILED(hr))
     2115    {
     2116        WARN(("GetBackBuffer failed, hr (0x%x)",hr));
     2117        return hr;
     2118    }
     2119
     2120    PVBOXWDDMDISP_ALLOCATION pAlloc = pRt->pAlloc;
     2121    Assert(pD3D9Surf);
     2122    Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
     2123    if (pAlloc->pD3DIf)
     2124    {
     2125        if (pSwapchain->fFlags.bChanged)
     2126        {
     2127            IDirect3DSurface9 *pD3D9OldSurf = (IDirect3DSurface9*)pAlloc->pD3DIf;
     2128            if (pD3D9OldSurf && pD3D9OldSurf != pD3D9Surf)
     2129            {
     2130                VOID *pvSwapchain = NULL;
     2131                /* get the old surface's swapchain */
     2132                HRESULT tmpHr = pD3D9OldSurf->GetContainer(IID_IDirect3DSwapChain9, &pvSwapchain);
     2133                if (tmpHr == S_OK)
     2134                {
     2135                    Assert(pvSwapchain);
     2136                    ((IDirect3DSwapChain9 *)pvSwapchain)->Release();
     2137                }
     2138                else
     2139                {
     2140                    Assert(!pvSwapchain);
     2141                }
     2142
     2143                if (pvSwapchain != pSwapchain->pSwapChainIf)
     2144                {
     2145                    /* the swapchain has changed, copy data to the new surface */
    22202146#ifdef DEBUG_misha
    2221                         /* @todo: we can not generally update the render target directly, implement */
    2222                         Assert(iBb != (~0));
     2147                    /* @todo: we can not generally update the render target directly, implement */
     2148                    Assert(iBb != (~0));
    22232149#endif
    2224                         hr = pDevice->pDevice9If->StretchRect(pD3D9OldSurf, NULL, pD3D9Surf, NULL, D3DTEXF_NONE);
    2225                         Assert(hr == S_OK);
    2226                         if (pSwapchain->cRTs == 1)
    2227                         {
    2228                             /* synch bb and fb */
    2229                             hr = pSwapchain->pSwapChainIf->Present(NULL, NULL, NULL, NULL, 0);
    2230                             Assert(hr == S_OK);
    2231                             if (hr == S_OK)
    2232                             {
    2233                                 pD3D9Surf->Release();
    2234                                 hr = pSwapchain->pSwapChainIf->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pD3D9Surf);
    2235                                 Assert(hr == S_OK);
    2236                                 if (hr == S_OK)
    2237                                 {
    2238                                     hr = pDevice->pDevice9If->StretchRect(pD3D9OldSurf, NULL, pD3D9Surf, NULL, D3DTEXF_NONE);
    2239                                     Assert(hr == S_OK);
    2240                                 }
    2241                             }
    2242                         }
    2243                     }
    2244                 }
    2245             }
    2246             pAlloc->pD3DIf->Release();
    2247         }
    2248         pAlloc->pD3DIf = pD3D9Surf;
    2249         pRt->fFlags.Value = 0;
    2250 
    2251         if (pSwapchain->fFlags.bChanged)
    2252         {
    2253             for (UINT i = 0; i < pDevice->cRTs; ++i)
    2254             {
    2255                 if (pDevice->apRTs[i] == pAlloc)
    2256                 {
    2257                     hr = vboxWddmRenderTargetSet(pDevice, i, pAlloc, TRUE);
     2150                    hr = pDevice->pDevice9If->StretchRect(pD3D9OldSurf, NULL, pD3D9Surf, NULL, D3DTEXF_NONE);
    22582151                    Assert(hr == S_OK);
    22592152                }
    22602153            }
    22612154        }
    2262     }
     2155        pAlloc->pD3DIf->Release();
     2156    }
     2157
     2158    pAlloc->pD3DIf = pD3D9Surf;
     2159    pRt->fFlags.Value = 0;
     2160
     2161    if (pSwapchain->fFlags.bChanged)
     2162    {
     2163        for (UINT i = 0; i < pDevice->cRTs; ++i)
     2164        {
     2165            if (pDevice->apRTs[i] == pAlloc)
     2166            {
     2167                hr = vboxWddmRenderTargetSet(pDevice, i, pAlloc, TRUE);
     2168                Assert(hr == S_OK);
     2169            }
     2170        }
     2171    }
     2172
     2173#ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND
     2174    if (pSwapchain->cRTs == 1)
     2175    {
     2176        /* here we sync the front-buffer with a backbuffer data*/
     2177        IDirect3DSurface9 *pD3D9Bb = (IDirect3DSurface9*)vboxWddmSwapchainGetBb(pSwapchain)->pAlloc->pD3DIf;
     2178        Assert(pD3D9Bb);
     2179        pD3D9Bb->AddRef();
     2180        /* we use backbuffer as a rt frontbuffer copy, so release the old one and assign the current bb */
     2181        if (pSwapchain->pRenderTargetFbCopy)
     2182        {
     2183            pSwapchain->pRenderTargetFbCopy->Release();
     2184        }
     2185        pSwapchain->pRenderTargetFbCopy = pD3D9Bb;
     2186        HRESULT tmpHr = pSwapchain->pSwapChainIf->GetFrontBufferData(pD3D9Bb);
     2187        if (SUCCEEDED(tmpHr))
     2188        {
     2189            VBOXVDBG_DUMP_SYNC_RT(pD3D9Bb);
     2190            pSwapchain->bRTFbCopyUpToDate = TRUE;
     2191        }
     2192        else
     2193        {
     2194            WARN(("GetFrontBufferData failed, hr (0x%x)", hr));
     2195        }
     2196    }
     2197#endif
    22632198    return hr;
    22642199}
     
    22992234    pParams->MultiSampleType = vboxDDI2D3DMultiSampleType(pRc->RcDesc.enmMultisampleType);
    23002235    pParams->MultiSampleQuality = pRc->RcDesc.MultisampleQuality;
    2301 #ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND
     2236#if 0 //def VBOXDISP_WITH_WINE_BB_WORKAROUND /* this does not work so far any way :( */
    23022237    if (pSwapchain->cRTs == 1)
    23032238        pParams->SwapEffect = D3DSWAPEFFECT_COPY;
     
    24782413#ifndef VBOXWDDM_WITH_VISIBLE_FB
    24792414        pSwapchain->bRTFbCopyUpToDate = FALSE;
     2415# ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND
     2416        if (pSwapchain->cRTs == 1)
     2417        {
     2418            /* we will assign it to wine backbuffer on a swapchain synch */
     2419            if (pSwapchain->pRenderTargetFbCopy)
     2420            {
     2421                pSwapchain->pRenderTargetFbCopy->Release();
     2422                pSwapchain->pRenderTargetFbCopy = NULL;
     2423            }
     2424        }
     2425        else
     2426# endif
    24802427        if (!pSwapchain->pRenderTargetFbCopy)
    24812428        {
     
    26112558}
    26122559
     2560/* get the surface for the specified allocation in the swapchain */
     2561static HRESULT vboxWddmSwapchainSurfGet(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_ALLOCATION pAlloc, IDirect3DSurface9 **ppSurf)
     2562{
     2563    Assert(pAlloc->pSwapchain == pSwapchain);
     2564
     2565#ifndef VBOXWDDM_WITH_VISIBLE_FB
     2566    if (vboxWddmSwapchainGetFb(pSwapchain)->pAlloc == pAlloc
     2567# ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND
     2568
     2569            && vboxWddmSwapchainNumRTs(pSwapchain) != 1 /* for swapchains w/o a backbuffer the alloc will contain the back-buffer actually */
     2570            )
     2571    {
     2572        /* this is a front-buffer */
     2573        Assert(vboxWddmSwapchainNumRTs(pSwapchain) > 1);
     2574        IDirect3DSurface9 *pSurf = pSwapchain->pRenderTargetFbCopy;
     2575        Assert(pSurf);
     2576        pSurf->AddRef();
     2577        if (!pSwapchain->bRTFbCopyUpToDate)
     2578        {
     2579            HRESULT hr = pSwapchain->pSwapChainIf->GetFrontBufferData(pSurf);
     2580            if (FAILED(hr))
     2581            {
     2582                WARN(("GetFrontBufferData failed, hr (0x%x)", hr));
     2583                return hr;
     2584            }
     2585            pSwapchain->bRTFbCopyUpToDate = TRUE;
     2586        }
     2587
     2588        *ppSurf = pSurf;
     2589        return S_OK;
     2590    }
     2591# endif
     2592#endif
     2593
     2594    /* if this is not a front-buffer - just return the surface associated with the allocation */
     2595    return vboxWddmSurfGet(pAlloc->pRc, pAlloc->iAlloc, ppSurf);
     2596}
     2597
     2598static HRESULT vboxWddmSwapchainRtSurfGet(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain, UINT iRt, PVBOXWDDMDISP_ALLOCATION pAlloc, BOOL bOnSwapchainSynch, IDirect3DSurface9 **ppSurf)
     2599{
     2600    Assert(pAlloc->pSwapchain == pSwapchain);
     2601    HRESULT hr = S_OK;
     2602
     2603    /* do the necessary swapchain synchronization first,
     2604     * not needed on swapchain synch since it is done already and we're called here just to set RTs */
     2605    if (!bOnSwapchainSynch)
     2606    {
     2607
     2608        /* iRt != 0 is untested here !! */
     2609        Assert(iRt == 0);
     2610        if (iRt == 0)
     2611        {
     2612            hr = vboxWddmSwapchainBbUpdate(pDevice, pSwapchain, pAlloc);
     2613            if (FAILED(hr))
     2614            {
     2615                WARN(("vboxWddmSwapchainBbUpdate failed, hr(0x%)",hr));
     2616                return hr;
     2617            }
     2618        }
     2619
     2620        Assert(!pSwapchain->fFlags.bChanged);
     2621        Assert(pSwapchain->pSwapChainIf);
     2622        hr = vboxWddmSwapchainChkCreateIf(pDevice, pSwapchain);
     2623        if (FAILED(hr))
     2624        {
     2625            WARN(("vboxWddmSwapchainChkCreateIf failed, hr(0x%)",hr));
     2626            return hr;
     2627        }
     2628    }
     2629
     2630
     2631    Assert(vboxWddmSwapchainGetBb(pSwapchain)->pAlloc == pAlloc || iRt != 0);
     2632    IDirect3DSurface9 *pSurf;
     2633    hr = vboxWddmSwapchainSurfGet(pDevice, pSwapchain, pAlloc, &pSurf);
     2634    if (FAILED(hr))
     2635    {
     2636        WARN(("vboxWddmSwapchainSurfGet failed, hr(0x%x)", hr));
     2637        return hr;
     2638    }
     2639
     2640    *ppSurf = pSurf;
     2641    return S_OK;
     2642
     2643}
     2644
    26132645static HRESULT vboxWddmSwapchainPresent(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pBbAlloc)
    26142646{
     
    26892721#endif
    26902722
    2691 #if 0
    2692 static HRESULT vboxWddmD3DDeviceCreate(PVBOXWDDMDISP_DEVICE pDevice, UINT iScreen, PVBOXWDDMDISP_RESOURCE pRc, D3DPRESENT_PARAMETERS * pParams, BOOL bLockable)
    2693 {
    2694     UINT cSurfs = pParams->BackBufferCount + 1;
    2695     Assert(pRc->cAllocations = cSurfs);
    2696     IDirect3DDevice9 *pPrimaryDevice = pDevice->aScreens[pDevice->iPrimaryScreen].pDevice9If;
    2697     PVBOXWDDMDISP_SCREEN pScreen = &pDevice->aScreens[iScreen];
    2698     PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
    2699     HRESULT hr;
    2700     HWND hWnd = NULL;
    2701     Assert(!pScreen->pDevice9If);
    2702     Assert(!pScreen->hWnd);
    2703     hr = VBoxDispWndCreate(pAdapter, pParams->BackBufferWidth, pParams->BackBufferHeight, &hWnd);
    2704     Assert(hr == S_OK);
    2705     if (hr == S_OK)
    2706     {
    2707         pScreen->hWnd = hWnd;
    2708 
    2709         DWORD fFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
    2710         if (pDevice->fFlags.AllowMultithreading)
    2711             fFlags |= D3DCREATE_MULTITHREADED;
    2712 
    2713         IDirect3DDevice9 *pDevice9If = NULL;
    2714         pParams->hDeviceWindow = hWnd;
    2715                     /* @todo: it seems there should be a way to detect this correctly since
    2716                      * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */
    2717         pParams->Windowed = TRUE;
    2718         //            params.EnableAutoDepthStencil = FALSE;
    2719         //            params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
    2720         //            params.Flags;
    2721         //            params.FullScreen_RefreshRateInHz;
    2722         //            params.FullScreen_PresentationInterval;
    2723         hr = pAdapter->pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, fFlags, pParams, &pDevice9If);
    2724         Assert(hr == S_OK);
    2725         if (hr == S_OK)
    2726         {
    2727             pScreen->pDevice9If = pDevice9If;
    2728             pScreen->pRenderTargetRc = pRc;
    2729             ++pDevice->cScreens;
    2730 
    2731             for (UINT i = 0; i < cSurfs; ++i)
    2732             {
    2733                 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
    2734                 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
    2735             }
    2736 
    2737             if (pPrimaryDevice)
    2738             {
    2739                 for (UINT i = 0; i < cSurfs; ++i)
    2740                 {
    2741                     PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
    2742                     IDirect3DSurface9 *pRt;
    2743                     IDirect3DSurface9 *pSecondaryOpenedRt;
    2744                     HANDLE hSharedHandle = NULL;
    2745                     hr = pPrimaryDevice->CreateRenderTarget(
    2746                             pParams->BackBufferWidth, pParams->BackBufferHeight,
    2747                             pParams->BackBufferFormat,
    2748                             pParams->MultiSampleType,
    2749                             pParams->MultiSampleQuality,
    2750                             TRUE, /*BOOL Lockable*/
    2751                             &pRt,
    2752                             &hSharedHandle);
    2753                     Assert(hr == S_OK);
    2754                     if (hr == S_OK)
    2755                     {
    2756                         Assert(hSharedHandle != NULL);
    2757                         /* open render target for primary device */
    2758                         hr = pDevice9If->CreateRenderTarget(
    2759                                     pParams->BackBufferWidth, pParams->BackBufferHeight,
    2760                                     pParams->BackBufferFormat,
    2761                                     pParams->MultiSampleType,
    2762                                     pParams->MultiSampleQuality,
    2763                                     TRUE, /*BOOL Lockable*/
    2764                                     &pSecondaryOpenedRt,
    2765                                     &hSharedHandle);
    2766                         Assert(hr == S_OK);
    2767                         if (hr == S_OK)
    2768                         {
    2769                             pAllocation->pD3DIf = pRt;
    2770                             pAllocation->pSecondaryOpenedD3DIf = pSecondaryOpenedRt;
    2771                             pAllocation->hSharedHandle = hSharedHandle;
    2772                             continue;
    2773                         }
    2774                         pRt->Release();
    2775                     }
    2776 
    2777                     for (UINT j = 0; j < i; ++j)
    2778                     {
    2779                         PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[j];
    2780                         pAlloc->pD3DIf->Release();
    2781                         pAlloc->pSecondaryOpenedD3DIf->Release();
    2782                     }
    2783 
    2784                     break;
    2785                 }
    2786             }
    2787             else
    2788             {
    2789                 pDevice->iPrimaryScreen = iScreen;
    2790                 hr = vboxWddmRenderTargetUpdate(pDevice, pRc, 0);
    2791                 Assert(hr == S_OK);
    2792             }
    2793 
    2794             if (hr == S_OK)
    2795             {
    2796                 for (UINT i = 0; i < cSurfs; ++i)
    2797                 {
    2798                     PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
    2799                     pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
    2800                     hr = vboxWddmSurfSynchMem(pRc, pAllocation);
    2801                     Assert(hr == S_OK);
    2802                     if (hr != S_OK)
    2803                     {
    2804                         break;
    2805                     }
    2806                 }
    2807 
    2808 #ifndef VBOXWDDM_WITH_VISIBLE_FB
    2809                 if (!pPrimaryDevice)
    2810                 {
    2811                     if (hr == S_OK)
    2812                     {
    2813                         IDirect3DSurface9* pD3D9Surf;
    2814                         hr = pDevice9If->CreateRenderTarget(
    2815                                 pParams->BackBufferWidth, pParams->BackBufferHeight,
    2816                                 pParams->BackBufferFormat,
    2817                                 pParams->MultiSampleType,
    2818                                 pParams->MultiSampleQuality,
    2819                                 bLockable,
    2820                                 &pD3D9Surf,
    2821                                 NULL /* HANDLE* pSharedHandle */
    2822                                 );
    2823                         Assert(hr == S_OK);
    2824                         if (hr == S_OK)
    2825                         {
    2826                             pDevice->pRenderTargetFbCopy = pD3D9Surf;
    2827                         }
    2828                     }
    2829                 }
    2830 #endif
    2831 
    2832                 if (hr != S_OK)
    2833                 {
    2834                     for (UINT i = 0; i < cSurfs; ++i)
    2835                     {
    2836                         PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
    2837                         pAllocation->pD3DIf->Release();
    2838                     }
    2839                 }
    2840             }
    2841 
    2842             if (hr != S_OK)
    2843             {
    2844                 pDevice9If->Release();
    2845                 --pDevice->cScreens;
    2846                 Assert(pDevice->cScreens < UINT32_MAX/2);
    2847             }
    2848         }
    2849 
    2850         if (hr != S_OK)
    2851         {
    2852             HRESULT tmpHr = VBoxDispWndDestroy(pAdapter, pScreen->hWnd);
    2853             Assert(tmpHr == S_OK);
    2854         }
    2855     }
    2856 
    2857     return hr;
    2858 }
    2859 #endif
    28602723static HRESULT vboxWddmD3DDeviceCreateDummy(PVBOXWDDMDISP_DEVICE pDevice)
    28612724{
     
    29002763}
    29012764
    2902 #if 0
    2903 static HRESULT APIENTRY vboxWddmDDevDestroyResource(HANDLE hDevice, HANDLE hResource);
    2904 
    2905 static HRESULT vboxWddmD3DDeviceUpdate(PVBOXWDDMDISP_DEVICE pDevice, UINT iScreen, PVBOXWDDMDISP_RESOURCE pRc, D3DPRESENT_PARAMETERS * pParams, BOOL bLockable)
    2906 {
    2907     UINT cSurfs = pParams->BackBufferCount + 1;
    2908     Assert(pRc->cAllocations = cSurfs);
    2909     Assert(iScreen == pDevice->iPrimaryScreen);
    2910     PVBOXWDDMDISP_SCREEN pScreen = &pDevice->aScreens[iScreen];
    2911     PVBOXWDDMDISP_RESOURCE pCurRc = pScreen->pRenderTargetRc;
    2912     IDirect3DDevice9Ex *pNewDevice;
    2913     HRESULT hr = pDevice->pAdapter->D3D.pfnVBoxWineExD3DDev9Update((IDirect3DDevice9Ex*)pScreen->pDevice9If, pParams, &pNewDevice);
    2914     Assert(hr == S_OK);
    2915     if (hr == S_OK)
    2916     {
    2917         pScreen->pDevice9If->Release();
    2918         pScreen->pDevice9If = pNewDevice;
    2919         pScreen->pRenderTargetRc = pRc;
    2920 
    2921         for (UINT i = 0; i < cSurfs; ++i)
    2922         {
    2923             PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
    2924             pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
    2925         }
    2926 
    2927 #ifndef VBOXWDDM_WITH_VISIBLE_FB
    2928         if (pDevice->pRenderTargetFbCopy)
    2929         {
    2930             pDevice->pRenderTargetFbCopy->Release();
    2931         }
    2932         IDirect3DSurface9* pD3D9Surf;
    2933         hr = pNewDevice->CreateRenderTarget(
    2934                     pParams->BackBufferWidth, pParams->BackBufferHeight,
    2935                     pParams->BackBufferFormat,
    2936                     pParams->MultiSampleType,
    2937                     pParams->MultiSampleQuality,
    2938                     bLockable,
    2939                     &pD3D9Surf,
    2940                     NULL /* HANDLE* pSharedHandle */
    2941                     );
    2942         Assert(hr == S_OK);
    2943         if (hr == S_OK)
    2944         {
    2945             pDevice->pRenderTargetFbCopy = pD3D9Surf;
    2946         }
    2947 #endif
    2948         if (hr == S_OK)
    2949         {
    2950             hr = vboxWddmRenderTargetUpdate(pDevice, pRc, 0);
    2951             Assert(hr == S_OK);
    2952             if (hr == S_OK)
    2953             {
    2954                 for (UINT i = 0; i < cSurfs; ++i)
    2955                 {
    2956                     PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
    2957                     pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
    2958                     hr = vboxWddmSurfSynchMem(pRc, pAllocation);
    2959                     Assert(hr == S_OK);
    2960                     if (hr != S_OK)
    2961                     {
    2962                         break;
    2963                     }
    2964                 }
    2965             }
    2966         }
    2967     }
    2968 
    2969 
    2970     if (!pCurRc->hResource)
    2971     {
    2972         HRESULT tmpHr = vboxWddmDDevDestroyResource(pDevice, pCurRc);
    2973         Assert(tmpHr == S_OK);
    2974     }
    2975 
    2976     return hr;
    2977 }
    2978 #endif
    29792765/******/
    29802766
     
    29842770    PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainForAlloc(pAlloc);
    29852771    HRESULT hr = S_OK;
     2772    IDirect3DSurface9 *pD3D9Surf;
    29862773    if (pSwapchain)
    29872774    {
    2988         hr = vboxWddmSwapchainBbUpdate(pDevice, pSwapchain, pAlloc);
     2775        hr = vboxWddmSwapchainRtSurfGet(pDevice, pSwapchain, iRt, pAlloc, bOnSwapchainSynch, &pD3D9Surf);
    29892776        if (FAILED(hr))
     2777        {
     2778            WARN(("vboxWddmSwapchainRtSurfGet failed, hr(0x%)",hr));
    29902779            return hr;
    2991     }
    2992 
    2993     IDirect3DSurface9 *pD3D9Surf;
    2994     if (!bOnSwapchainSynch && pSwapchain)
    2995     {
    2996         /* work-around wine double-buffering for the case we have no backbuffers */
    2997         Assert(!pSwapchain->fFlags.bChanged);
    2998         Assert(pSwapchain->pSwapChainIf);
    2999         vboxWddmSwapchainChkCreateIf(pDevice, pSwapchain);
    3000     }
    3001 
    3002 #ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND
    3003     if (pSwapchain && vboxWddmSwapchainNumRTs(pSwapchain) == 1 && iRt == 0)
    3004     {
    3005         hr = pSwapchain->pSwapChainIf->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pD3D9Surf);
    3006         Assert(hr == S_OK);
    3007         Assert(pD3D9Surf);
     2780        }
    30082781    }
    30092782    else
    3010 #endif
    30112783    {
    30122784        hr = vboxWddmSurfGet(pAlloc->pRc, pAlloc->iAlloc, &pD3D9Surf);
    3013         Assert(hr == S_OK);
    3014         Assert(pD3D9Surf);
    3015     }
    3016 
     2785        if (FAILED(hr))
     2786        {
     2787            WARN(("vboxWddmSurfGet failed, hr(0x%)",hr));
     2788            return hr;
     2789        }
     2790    }
     2791
     2792    Assert(pD3D9Surf);
     2793
     2794    hr = pDevice9If->SetRenderTarget(iRt, pD3D9Surf);
     2795    Assert(hr == S_OK);
    30172796    if (hr == S_OK)
    30182797    {
    3019         Assert(pD3D9Surf);
    3020         hr = pDevice9If->SetRenderTarget(iRt, pD3D9Surf);
    3021         Assert(hr == S_OK);
    3022         if (hr == S_OK)
    3023         {
    3024             Assert(iRt < pDevice->cRTs);
    3025             pDevice->apRTs[iRt] = pAlloc;
    3026         }
    3027         pD3D9Surf->Release();
    3028     }
     2798        Assert(iRt < pDevice->cRTs);
     2799        pDevice->apRTs[iRt] = pAlloc;
     2800    }
     2801    pD3D9Surf->Release();
    30292802
    30302803    return hr;
     
    49734746            if (pResource->Flags.SharedResource)
    49744747            {
    4975                 Assert(0); /* <-- need to test that */
    49764748                bIssueCreateResource = true;
    49774749                bCreateKMResource = true;
     
    61365908    IDirect3DSurface9 *pSrcSurfIf = NULL;
    61375909    IDirect3DSurface9 *pDstSurfIf = NULL;
     5910    Assert(!pDstSwapchain || vboxWddmSwapchainGetFb(pDstSwapchain)->pAlloc != pDstAlloc || vboxWddmSwapchainNumRTs(pDstSwapchain) == 1);
    61385911    hr = vboxWddmSurfGet(pDstRc, pData->DstSubResourceIndex, &pDstSurfIf);
    61395912    Assert(hr == S_OK);
     
    61435916        do
    61445917        {
    6145 #ifndef VBOXWDDM_WITH_VISIBLE_FB
    6146             if (pSrcSwapchain
    6147                     && pSrcSwapchain->pRenderTargetFbCopy
    6148                     && vboxWddmSwapchainGetFb(pSrcSwapchain)->pAlloc == pSrcAlloc
    6149 # ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND
    6150                     && vboxWddmSwapchainNumRTs(pSrcSwapchain) > 1 /* work-around wine backbuffer */
    6151 # endif
    6152                     )
    6153             {
    6154 # if 0
    6155                 if (pData->DstRect.left == 0 && pData->DstRect.top == 0
    6156                         && pData->DstRect.right == pDstAlloc->SurfDesc.width
    6157                         && pData->DstRect.bottom == pDstAlloc->SurfDesc.height
    6158                         && pData->SrcRect.left == 0 && pData->SrcRect.top == 0
    6159                         && pData->SrcRect.right == pSrcAlloc->SurfDesc.width
    6160                         && pData->SrcRect.bottom == pSrcAlloc->SurfDesc.height
    6161                         && pSrcAlloc->SurfDesc.width == pDstAlloc->SurfDesc.width
    6162                         && pSrcAlloc->SurfDesc.height == pDstAlloc->SurfDesc.height
    6163                         && pSrcAlloc->SurfDesc.format == pDstAlloc->SurfDesc.format)
    6164                 {
    6165                     hr = pDevice9If->GetFrontBufferData(0, pDstSurfIf);
    6166                     Assert(hr == S_OK);
    6167                     break;
    6168                 }
    6169                 else
    6170 # endif
    6171                 {
    6172                     pSrcSurfIf = pSrcSwapchain->pRenderTargetFbCopy;
    6173                     Assert(pSrcSurfIf);
    6174                     if (!pSrcSwapchain->bRTFbCopyUpToDate)
    6175                     {
    6176                         hr = pSrcSwapchain->pSwapChainIf->GetFrontBufferData(pSrcSurfIf);
    6177                         Assert(hr == S_OK);
    6178                         if (hr == S_OK)
    6179                         {
    6180                             /* do pSrcSurfIf->AddRef since we do a Release in the following if (hr == S_OK) branch */
    6181                             pSrcSwapchain->bRTFbCopyUpToDate = TRUE;
    6182                             pSrcSurfIf->AddRef();
    6183                         }
    6184                     }
    6185                     else
    6186                     {
    6187                         pSrcSurfIf->AddRef();
    6188                     }
    6189                 }
     5918            if (pSrcSwapchain)
     5919            {
     5920                hr = vboxWddmSwapchainSurfGet(pDevice, pSrcSwapchain, pSrcAlloc, &pSrcSurfIf);
     5921                Assert(hr == S_OK);
    61905922            }
    61915923            else
    6192 #endif
    61935924            {
    61945925                hr = vboxWddmSurfGet(pSrcRc, pData->SrcSubResourceIndex, &pSrcSurfIf);
     
    62255956        Assert(0);
    62265957    }
    6227 
    6228 
    6229 #if 0
    6230     if ((use pAlloc->enmD3DIfType instead!!! pDstRc->RcDesc.fFlags.Texture || pDstRc->RcDesc.fFlags.Value == 0)
    6231             && (pSrcRc->RcDesc.fFlags.Texture || pSrcRc->RcDesc.fFlags.Value == 0))
    6232     {
    6233         IDirect3DBaseTexture9 *pD3DIfSrcTex = (IDirect3DBaseTexture9*)pSrcAlloc->pD3DIf;
    6234         IDirect3DBaseTexture9 *pD3DIfDstTex = (IDirect3DBaseTexture9*)pDstAlloc->pD3DIf;
    6235         Assert(pD3DIfSrcTex);
    6236         Assert(pD3DIfDstTex);
    6237 
    6238         if (pSrcRc->RcDesc.enmFormat == pDstRc->RcDesc.enmFormat)
    6239         {
    6240             if (pSrcRc->aAllocations[0].SurfDesc.width == pDstRc->aAllocations[0].SurfDesc.width
    6241                     && pSrcRc->aAllocations[0].SurfDesc.height == pDstRc->aAllocations[0].SurfDesc.height
    6242                     && pData->DstRect.left == 0 && pData->DstRect.top == 0
    6243                     && pData->SrcRect.left == 0 && pData->SrcRect.top == 0
    6244                     && pData->SrcRect.right - pData->SrcRect.left == pSrcRc->aAllocations[0].SurfDesc.width
    6245                     && pData->SrcRect.bottom - pData->SrcRect.top == pSrcRc->aAllocations[0].SurfDesc.height
    6246                     && pData->DstRect.right - pData->DstRect.left == pDstRc->aAllocations[0].SurfDesc.width
    6247                     && pData->DstRect.bottom - pData->DstRect.top == pDstRc->aAllocations[0].SurfDesc.height
    6248                     )
    6249             {
    6250                 hr = pDevice9If->UpdateTexture(pD3DIfSrcTex, pD3DIfDstTex);
    6251                 Assert(hr == S_OK);
    6252             }
    6253             else if (pData->SrcRect.right - pData->SrcRect.left == pData->DstRect.right - pData->DstRect.left
    6254                     && pData->SrcRect.bottom - pData->SrcRect.top == pData->DstRect.bottom - pData->DstRect.top)
    6255             {
    6256                 Assert(pDstAlloc->SurfDesc.bpp);
    6257                 Assert(pSrcAlloc->SurfDesc.bpp);
    6258                 Assert(pSrcAlloc->SurfDesc.bpp == pDstAlloc->SurfDesc.bpp);
    6259                 D3DLOCKED_RECT DstRect, SrcRect;
    6260                 Assert(!pSrcAlloc->LockInfo.cLocks);
    6261                 Assert(!pDstAlloc->LockInfo.cLocks);
    6262                 hr = pD3DIfDstTex->LockRect(pData->DstSubResourceIndex, &DstRect, &pData->DstRect, D3DLOCK_DISCARD);
    6263                 Assert(hr == S_OK);
    6264                 if (hr == S_OK)
    6265                 {
    6266                     hr = pD3DIfSrcTex->LockRect(pData->SrcSubResourceIndex, &SrcRect, &pData->SrcRect, D3DLOCK_READONLY);
    6267                     Assert(hr == S_OK);
    6268                     if (hr == S_OK)
    6269                     {
    6270                         hr = vboxWddmRectBltPerform((uint8_t *)DstRect.pBits, (uint8_t *)SrcRect.pBits,
    6271                                 &pData->DstRect,  &pData->SrcRect,
    6272                                 DstRect.Pitch, SrcRect.Pitch, pDstAlloc->SurfDesc.bpp);
    6273                         Assert(hr == S_OK);
    6274 
    6275                         pD3DIfSrcTex->UnlockRect(pData->SrcSubResourceIndex);
    6276                     }
    6277                     pD3DIfDstTex->UnlockRect(pData->DstSubResourceIndex);
    6278                 }
    6279             }
    6280             else
    6281             {
    6282 
    6283                 Assert(0);
    6284                 /* @todo: impl */
    6285             }
    6286         }
    6287         else
    6288         {
    6289             Assert(0);
    6290             /* @todo: impl */
    6291         }
    6292     }
    6293     else
    6294     {
    6295         if (pData->SrcRect.right - pData->SrcRect.left == pData->DstRect.right - pData->DstRect.left
    6296                             && pData->SrcRect.bottom - pData->SrcRect.top == pData->DstRect.bottom - pData->DstRect.top)
    6297         {
    6298             Assert(pDstAlloc->SurfDesc.bpp);
    6299             Assert(pSrcAlloc->SurfDesc.bpp);
    6300             Assert(pSrcAlloc->SurfDesc.bpp == pDstAlloc->SurfDesc.bpp);
    6301 
    6302             D3DLOCKED_RECT DstRect, SrcRect;
    6303             hr = vboxWddmLockRect(pDstAlloc, pData->DstSubResourceIndex, pDstRc->RcDesc.fFlags,
    6304                     &DstRect, &pData->DstRect, D3DLOCK_DISCARD);
    6305             Assert(hr == S_OK);
    6306             if (hr == S_OK)
    6307             {
    6308                 hr = vboxWddmLockRect(pSrcAlloc, pData->SrcSubResourceIndex, pSrcRc->RcDesc.fFlags,
    6309                         &SrcRect, &pData->SrcRect, D3DLOCK_READONLY);
    6310                 Assert(hr == S_OK);
    6311                 if (hr == S_OK)
    6312                 {
    6313                     hr = vboxWddmRectBltPerform((uint8_t *)DstRect.pBits, (uint8_t *)SrcRect.pBits,
    6314                             &pData->DstRect,  &pData->SrcRect,
    6315                             DstRect.Pitch, SrcRect.Pitch, pDstAlloc->SurfDesc.bpp);
    6316                     Assert(hr == S_OK);
    6317 
    6318                     HRESULT tmpHr = vboxWddmUnlockRect(pSrcAlloc, pData->SrcSubResourceIndex, pSrcRc->RcDesc.fFlags);
    6319                     Assert(tmpHr == S_OK);
    6320                 }
    6321                 HRESULT tmpHr = vboxWddmUnlockRect(pDstAlloc, pData->DstSubResourceIndex, pDstRc->RcDesc.fFlags);
    6322                 Assert(tmpHr == S_OK);
    6323             }
    6324         }
    6325         else
    6326         {
    6327             Assert(0);
    6328             /* @todo: impl */
    6329         }
    6330     }
    6331 #endif
    63325958
    63335959    PVBOXWDDMDISP_ALLOCATION pDAlloc = &pDstRc->aAllocations[pData->DstSubResourceIndex];
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.cpp

    r37640 r37734  
    5050
    5151#ifdef VBOXWDDMDISP_DEBUG
    52 bool g_bVBoxVDbgFDumpSetTexture = false;
    53 bool g_bVBoxVDbgFDumpDrawPrim = false;
    54 bool g_bVBoxVDbgFDumpTexBlt = false;
    55 bool g_bVBoxVDbgFDumpBlt = false;
     52DWORD g_VBoxVDbgFDumpSetTexture = 0;
     53DWORD g_VBoxVDbgFDumpDrawPrim = 0;
     54DWORD g_VBoxVDbgFDumpTexBlt = 0;
     55DWORD g_VBoxVDbgFDumpBlt = 0;
     56DWORD g_VBoxVDbgFDumpRtSynch = 0;
    5657
    5758typedef enum
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h

    r37300 r37734  
    104104
    105105#ifdef VBOXWDDMDISP_DEBUG
    106 extern bool g_bVBoxVDbgFDumpSetTexture;
    107 extern bool g_bVBoxVDbgFDumpDrawPrim;
    108 extern bool g_bVBoxVDbgFDumpTexBlt;
    109 extern bool g_bVBoxVDbgFDumpBlt;
     106extern DWORD g_VBoxVDbgFDumpSetTexture;
     107extern DWORD g_VBoxVDbgFDumpDrawPrim;
     108extern DWORD g_VBoxVDbgFDumpTexBlt;
     109extern DWORD g_VBoxVDbgFDumpBlt;
     110extern DWORD g_VBoxVDbgFDumpRtSynch;
    110111
    111112void vboxDispLogDrvF(char * szString, ...);
     
    131132
    132133#define VBOXVDBG_DUMP_DRAWPRIM_ENTER(_pDevice) do { \
    133         if (g_bVBoxVDbgFDumpDrawPrim) \
     134        if (g_VBoxVDbgFDumpDrawPrim) \
    134135        { \
    135136            vboxVDbgDoDumpRt("==>"__FUNCTION__": RenderTarget Dump\n", (_pDevice), "\n"); \
     
    138139
    139140#define VBOXVDBG_DUMP_DRAWPRIM_LEAVE(_pDevice) do { \
    140         if (g_bVBoxVDbgFDumpDrawPrim) \
     141        if (g_VBoxVDbgFDumpDrawPrim) \
    141142        { \
    142143            vboxVDbgDoDumpRt("<=="__FUNCTION__": RenderTarget Dump\n", (_pDevice), "\n"); \
     
    145146
    146147#define VBOXVDBG_DUMP_SETTEXTURE(_pRc) do { \
    147         if (g_bVBoxVDbgFDumpSetTexture) \
     148        if (g_VBoxVDbgFDumpSetTexture) \
    148149        { \
    149150            vboxVDbgDoDumpRcRectByRc("== "__FUNCTION__": Texture Dump\n", _pRc, NULL, "\n"); \
     
    152153
    153154#define VBOXVDBG_DUMP_TEXBLT_ENTER(_pSrcRc, _pSrcRect, _pDstRc, _pDstPoint) do { \
    154         if (g_bVBoxVDbgFDumpTexBlt) \
     155        if (g_VBoxVDbgFDumpTexBlt) \
    155156        { \
    156157            RECT _DstRect; \
     
    162163
    163164#define VBOXVDBG_DUMP_TEXBLT_LEAVE(_pSrcRc, _pSrcRect, _pDstRc, _pDstPoint) do { \
    164         if (g_bVBoxVDbgFDumpTexBlt) \
     165        if (g_VBoxVDbgFDumpTexBlt) \
    165166        { \
    166167            RECT _DstRect; \
     
    172173
    173174#define VBOXVDBG_DUMP_BLT_ENTER(_pSrcSurf, _pSrcRect, _pDstSurf, _pDstRect) do { \
    174         if (g_bVBoxVDbgFDumpBlt) \
     175        if (g_VBoxVDbgFDumpBlt) \
    175176        { \
    176177            vboxVDbgDoDumpSurfRect("==>"__FUNCTION__" Src:\n", (_pSrcSurf), (_pSrcRect), "\n", true); \
     
    180181
    181182#define VBOXVDBG_DUMP_BLT_LEAVE(_pSrcSurf, _pSrcRect, _pDstSurf, _pDstRect) do { \
    182         if (g_bVBoxVDbgFDumpBlt) \
     183        if (g_VBoxVDbgFDumpBlt) \
    183184        { \
    184185            vboxVDbgDoDumpSurfRect("<=="__FUNCTION__" Src:\n", (_pSrcSurf), (_pSrcRect), "\n", true); \
    185186            vboxVDbgDoDumpSurfRect("<=="__FUNCTION__" Dst:\n", (_pDstSurf), (_pDstRect), "\n", true); \
     187        } \
     188    } while (0)
     189
     190#define VBOXVDBG_DUMP_SYNC_RT(_pBbSurf) do { \
     191        if (g_VBoxVDbgFDumpRtSynch) \
     192        { \
     193            vboxVDbgDoDumpSurfRect("== "__FUNCTION__" Bb:\n", (_pBbSurf), NULL, "\n", true); \
    186194        } \
    187195    } while (0)
     
    194202#define VBOXVDBG_DUMP_BLT_ENTER(_pSrcSurf, _pSrcRect, _pDstSurf, _pDstRect) do { } while (0)
    195203#define VBOXVDBG_DUMP_BLT_LEAVE(_pSrcSurf, _pSrcRect, _pDstSurf, _pDstRect) do { } while (0)
     204#define VBOXVDBG_DUMP_SYNC_RT(_pBbSurf) do { } while (0)
    196205#endif
    197206
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPCm.cpp

    r37490 r37734  
    223223}
    224224
    225 static void vboxVideoCmSessionDestroy(PVBOXVIDEOCM_SESSION pSession)
     225static void vboxVideoCmSessionDestroyLocked(PVBOXVIDEOCM_SESSION pSession)
    226226{
    227227    /* signal event so that user-space client can figure out the context is destroyed
     
    238238 * @return true iff the given session is destroyed
    239239 */
    240 bool vboxVideoCmSessionCtxRemove(PVBOXVIDEOCM_SESSION pSession, PVBOXVIDEOCM_CTX pContext)
     240bool vboxVideoCmSessionCtxRemoveLocked(PVBOXVIDEOCM_SESSION pSession, PVBOXVIDEOCM_CTX pContext)
    241241{
    242242    bool bDestroy;
     
    287287    if (bDestroy)
    288288    {
    289         vboxVideoCmSessionDestroy(pSession);
     289        vboxVideoCmSessionDestroyLocked(pSession);
    290290    }
    291291
     
    294294
    295295/* the session gets destroyed once the last context is removed from it */
    296 NTSTATUS vboxVideoCmSessionCreate(PVBOXVIDEOCM_MGR pMgr, PVBOXVIDEOCM_SESSION *ppSession, PKEVENT pUmEvent, PVBOXVIDEOCM_CTX pContext)
     296NTSTATUS vboxVideoCmSessionCreateLocked(PVBOXVIDEOCM_MGR pMgr, PVBOXVIDEOCM_SESSION *ppSession, PKEVENT pUmEvent, PVBOXVIDEOCM_CTX pContext)
    297297{
    298298    NTSTATUS Status = STATUS_UNSUCCESSFUL;
     
    355355            if (!bFound)
    356356            {
    357                 Status = vboxVideoCmSessionCreate(pMgr, &pSession, pUmEvent, pContext);
     357                Status = vboxVideoCmSessionCreateLocked(pMgr, &pSession, pUmEvent, pContext);
    358358                Assert(Status == STATUS_SUCCESS);
    359359            }
     
    390390    if (Status == STATUS_SUCCESS)
    391391    {
    392         vboxVideoCmSessionCtxRemove(pSession, pContext);
     392        vboxVideoCmSessionCtxRemoveLocked(pSession, pContext);
    393393        LONG tstL = KeSetEvent(&pMgr->SynchEvent, 0, FALSE);
    394394        Assert(!tstL);
     
    474474            else
    475475            {
    476                 pSession->bEventNeeded = false;
     476                Assert(cbRemainingFirstCmd);
     477                Assert(cbRemainingCmds);
    477478                break;
    478479            }
     
    510511}
    511512
     513static BOOLEAN vboxVideoCmHasUncompletedCmdsLocked(PVBOXVIDEOCM_MGR pMgr)
     514{
     515    PVBOXVIDEOCM_SESSION pSession = NULL;
     516    for (PLIST_ENTRY pEntry = pMgr->SessionList.Flink; pEntry != &pMgr->SessionList; pEntry = pEntry->Flink)
     517    {
     518        pSession = VBOXCMENTRY_2_SESSION(pEntry);
     519        ExAcquireFastMutex(&pSession->Mutex);
     520        if (pSession->bEventNeeded)
     521        {
     522            /* commands still being processed */
     523            ExReleaseFastMutex(&pSession->Mutex);
     524            return TRUE;
     525        }
     526        ExReleaseFastMutex(&pSession->Mutex);
     527    }
     528    return FALSE;
     529}
     530
     531/* waits for all outstanding commands to completed by client
     532 * assumptions here are:
     533 * 1. no new commands are submitted while we are waiting
     534 * 2. it is assumed that a client completes all previously received commands
     535 *    once it queries for the new set of commands */
     536NTSTATUS vboxVideoCmWaitCompletedCmds(PVBOXVIDEOCM_MGR pMgr, uint32_t msTimeout)
     537{
     538    LARGE_INTEGER Timeout;
     539    PLARGE_INTEGER pTimeout;
     540    uint32_t cIters;
     541
     542    if (msTimeout != RT_INDEFINITE_WAIT)
     543    {
     544        uint32_t msIter = 2;
     545        cIters = msTimeout/msIter;
     546        if (!cIters)
     547        {
     548            msIter = msTimeout;
     549            cIters = 1;
     550        }
     551        Timeout.QuadPart = -(int64_t) msIter /* ms */ * 10000;
     552        pTimeout = &Timeout;
     553    }
     554    else
     555    {
     556        pTimeout = NULL;
     557        cIters = 1;
     558    }
     559
     560    Assert(cIters);
     561    do
     562    {
     563        NTSTATUS Status = KeWaitForSingleObject(&pMgr->SynchEvent, Executive, KernelMode,
     564                    FALSE, /* BOOLEAN Alertable */
     565                    pTimeout /* PLARGE_INTEGER Timeout */
     566        );
     567        if (Status == STATUS_TIMEOUT)
     568        {
     569            --cIters;
     570        }
     571        else
     572        {
     573            if (!NT_SUCCESS(Status))
     574            {
     575                WARN(("KeWaitForSingleObject failed with Status (0x%x)", Status));
     576                return Status;
     577            }
     578
     579            /* succeeded */
     580            if (!vboxVideoCmHasUncompletedCmdsLocked(pMgr))
     581            {
     582                LONG tstL = KeSetEvent(&pMgr->SynchEvent, 0, FALSE);
     583                Assert(!tstL);
     584                return STATUS_SUCCESS;
     585            }
     586
     587            LONG tstL = KeSetEvent(&pMgr->SynchEvent, 0, FALSE);
     588            Assert(!tstL);
     589        }
     590
     591        if (!cIters)
     592            break;
     593
     594        KeDelayExecutionThread(KernelMode, FALSE, pTimeout);
     595        --cIters;
     596        if (!cIters)
     597            break;
     598    } while (0);
     599
     600    return STATUS_TIMEOUT;
     601}
     602
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPCm.h

    r36867 r37734  
    5656
    5757NTSTATUS vboxVideoCmEscape(PVBOXVIDEOCM_CTX pContext, PVBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD pCmd, uint32_t cbCmd);
     58
     59NTSTATUS vboxVideoCmWaitCompletedCmds(PVBOXVIDEOCM_MGR pMgr, uint32_t msTimeout);
     60
    5861VOID vboxVideoCmLock(PVBOXVIDEOCM_CTX pContext);
    5962VOID vboxVideoCmUnlock(PVBOXVIDEOCM_CTX pContext);
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPMisc.cpp

    r37640 r37734  
    910910    };
    911911    VBOXUHGSMI_SYNCHOBJECT_TYPE enmSynchType;
     912    volatile uint32_t cRefs;
    912913    MDL Mdl;
    913914} VBOXVIDEOCM_ALLOC_REF, *PVBOXVIDEOCM_ALLOC_REF;
     
    10061007                    NULL);
    10071008            Assert(Status == STATUS_SUCCESS);
     1009            Assert(pSynchEvent);
    10081010            break;
    10091011        case VBOXUHGSMI_SYNCHOBJECT_TYPE_SEMAPHORE:
     
    10121014                    NULL);
    10131015            Assert(Status == STATUS_SUCCESS);
     1016            Assert(pSynchSemaphore);
    10141017            break;
    10151018        case VBOXUHGSMI_SYNCHOBJECT_TYPE_NONE:
     
    10321035        if (pAllocRef)
    10331036        {
     1037            pAllocRef->cRefs = 1;
    10341038            MmInitializeMdl(&pAllocRef->Mdl, BaseVa, cbLength);
    10351039            __try
     
    11051109    if (pAllocRef)
    11061110    {
     1111        /* wait for the dereference, i.e. for all commands involving this allocation to complete */
     1112        vboxWddmCounterU32Wait(&pAllocRef->cRefs, 1);
     1113
    11071114        MmUnlockPages(&pAllocRef->Mdl);
    11081115        *ppAlloc = pAllocRef->pAlloc;
     
    11261133    ExAcquireFastMutex(&pContext->Mutex);
    11271134    PVBOXVIDEOCM_ALLOC_REF pAllocRef = (PVBOXVIDEOCM_ALLOC_REF)vboxWddmHTableGet(&pContext->AllocTable, hSesionHandle);
     1135    ASMAtomicIncU32(&pAllocRef->cRefs);
    11281136    ExReleaseFastMutex(&pContext->Mutex);
    11291137    return pAllocRef;
    11301138}
    11311139
    1132 static VOID vboxVideoCmCtxAllocRefRelease(PVBOXVIDEOCM_ALLOC_REF pRef)
    1133 {
    1134 
     1140static VOID vboxVideoAMgrCtxAllocRefRelease(PVBOXVIDEOCM_ALLOC_REF pRef)
     1141{
     1142    uint32_t cRefs = ASMAtomicDecU32(&pRef->cRefs);
     1143    Assert(cRefs < UINT32_MAX/2);
     1144    Assert(cRefs >= 1); /* we do not do cleanup-on-zero here, instead we wait for the cRefs to reach 1 in vboxVideoAMgrCtxAllocUnmap before unmapping */
    11351145}
    11361146
     
    12111221        }
    12121222
    1213         vboxVideoCmCtxAllocRefRelease(pRef);
     1223        vboxVideoAMgrCtxAllocRefRelease(pRef);
    12141224    }
    12151225
     
    12431253            if (pRef)
    12441254            {
     1255#ifdef DEBUG_misha
     1256                Assert(pRef->cRefs == 2);
     1257#endif
    12451258                pBufCmd->offBuffer = pRef->pAlloc->offData + pBufInfo->Info.offData;
    12461259                pBufCmd->cbBuffer = pBufInfo->Info.cbData;
     
    12501263            else
    12511264            {
    1252                 Assert(0);
     1265                WARN(("vboxVideoAMgrCtxAllocRefAcquire failed for hAlloc(0x%x)\n", pBufInfo->hAlloc));
     1266                /* release all previously acquired aloc references */
     1267                for (UINT j = 0; j < i; ++j)
     1268                {
     1269                    VBOXVDMACMD_CHROMIUM_BUFFER *pBufCmdJ = &pBody->aBuffers[j];
     1270                    PVBOXVIDEOCM_ALLOC_REF pRefJ = (PVBOXVIDEOCM_ALLOC_REF)pBufCmdJ;
     1271                    vboxVideoAMgrCtxAllocRefRelease(pRefJ);
     1272                }
    12531273                Status = STATUS_INVALID_PARAMETER;
    12541274                break;
     
    12631283            vboxVdmaDdiCmdSubmittedNotDx(pDdiCmd);
    12641284            int rc = vboxVdmaCBufDrSubmit(pDevExt, &pDevExt->u.primary.Vdma, pDr);
    1265             Assert(rc == VINF_SUCCESS);
    12661285            if (RT_SUCCESS(rc))
    12671286            {
    12681287                return STATUS_SUCCESS;
     1288            }
     1289
     1290            WARN(("vboxVdmaCBufDrSubmit failed with rc (%d)\n", rc));
     1291
     1292            /* failure branch */
     1293            /* release all previously acquired aloc references */
     1294            for (UINT i = 0; i < cBuffers; ++i)
     1295            {
     1296                VBOXVDMACMD_CHROMIUM_BUFFER *pBufCmd = &pBody->aBuffers[i];
     1297                PVBOXVIDEOCM_ALLOC_REF pRef = (PVBOXVIDEOCM_ALLOC_REF)pBufCmd;
     1298                vboxVideoAMgrCtxAllocRefRelease(pRef);
    12691299            }
    12701300        }
     
    13801410}
    13811411
     1412
     1413VOID vboxWddmSleep(uint32_t u32Val)
     1414{
     1415    LARGE_INTEGER Interval;
     1416    Interval.QuadPart = -(int64_t) 2 /* ms */ * 10000;
     1417
     1418    KeDelayExecutionThread(KernelMode, FALSE, &Interval);
     1419}
     1420
    13821421VOID vboxWddmCounterU32Wait(uint32_t volatile * pu32, uint32_t u32Val)
    13831422{
     
    13861425    uint32_t u32CurVal;
    13871426
     1427    Assert(KeGetCurrentIrql() < DISPATCH_LEVEL);
     1428
    13881429    while ((u32CurVal = ASMAtomicReadU32(pu32)) != u32Val)
    13891430    {
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPMisc.h

    r37626 r37734  
    148148#endif
    149149
    150 
     150VOID vboxWddmSleep(uint32_t u32Val);
    151151VOID vboxWddmCounterU32Wait(uint32_t volatile * pu32, uint32_t u32Val);
    152152
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp

    r37626 r37734  
    14601460    LOGF(("ENTER, context(0x%x)", MiniportDeviceContext));
    14611461
    1462     /* @todo: */
    1463 //    vboxVDbgBreakF();
     1462    vboxVDbgBreakFv();
    14641463
    14651464    LOGF(("LEAVE, context(0x%x)", MiniportDeviceContext));
     
    26732672            PVBOXWDDM_ALLOCATION pDstAlloc = pBlt->Blt.DstAlloc.pAlloc;
    26742673            PVBOXWDDM_ALLOCATION pSrcAlloc = pBlt->Blt.SrcAlloc.pAlloc;
     2674
    26752675            uint32_t cContexts3D = ASMAtomicReadU32(&pDevExt->cContexts3D);
    26762676            BOOLEAN bComplete = TRUE;
     
    37233723                    /* ensure the last char is \0*/
    37243724                    *((uint8_t*)pDbgPrint + pEscape->PrivateDriverDataSize - 1) = '\0';
     3725#ifdef DEBUG_misha
     3726                    DbgPrint("%s", pDbgPrint->aStringBuf);
     3727#else
    37253728                    LOGREL(("%s", pDbgPrint->aStringBuf));
     3729#endif
    37263730                }
    37273731                Status = STATUS_SUCCESS;
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