VirtualBox

Ignore:
Timestamp:
May 30, 2010 7:27:02 PM (15 years ago)
Author:
vboxsync
Message:

wddm: open,create,destroy,lock,unlock resource

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

Legend:

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

    r29798 r29883  
    857857}
    858858
     859static PVBOXWDDMDISP_RESOURCE vboxResourceAlloc(UINT cAllocs)
     860{
     861    PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)RTMemAllocZ(RT_OFFSETOF(VBOXWDDMDISP_RESOURCE, aAllocations[cAllocs]));
     862    Assert(pRc);
     863    if (pRc)
     864    {
     865        pRc->cAllocations = cAllocs;
     866        return pRc;
     867    }
     868    return NULL;
     869}
     870
     871static void vboxResourceFree(PVBOXWDDMDISP_RESOURCE pRc)
     872{
     873    RTMemFree(pRc);
     874}
     875
    859876/**
    860877 * DLL entry point.
     
    13961413static HRESULT APIENTRY vboxWddmDDevLock(HANDLE hDevice, D3DDDIARG_LOCK* pData)
    13971414{
    1398     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1399     AssertBreakpoint();
    1400     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1401     return E_FAIL;
     1415    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     1416    AssertBreakpoint();
     1417    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
     1418    PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
     1419    Assert(pData->SubResourceIndex < pRc->cAllocations);
     1420    if (pData->SubResourceIndex >= pRc->cAllocations)
     1421        return E_INVALIDARG;
     1422
     1423    PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
     1424    D3DDDICB_LOCK LockData;
     1425    LockData.hAllocation = pAlloc->hAllocation;
     1426    LockData.PrivateDriverData = 0;
     1427    LockData.NumPages = 0;
     1428    LockData.pPages = NULL;
     1429    LockData.pData = NULL; /* out */
     1430    LockData.Flags.Value = 0;
     1431    LockData.Flags.Discard = pData->Flags.Discard;
     1432    LockData.Flags.DonotWait = pData->Flags.DoNotWait;
     1433
     1434
     1435    HRESULT hr = pDevice->RtCallbacks.pfnLockCb(hDevice, &LockData);
     1436    Assert(hr == S_OK || (hr == D3DERR_WASSTILLDRAWING && pData->Flags.DoNotWait));
     1437    if (hr == S_OK)
     1438    {
     1439        uintptr_t offset;
     1440        if (pData->Flags.AreaValid)
     1441        {
     1442            offset = pAlloc->SurfDesc.pitch * pData->Area.top +
     1443                    ((pAlloc->SurfDesc.bpp * pData->Area.left) >> 3);
     1444        }
     1445        else if (pData->Flags.RangeValid)
     1446        {
     1447            offset = pData->Range.Offset;
     1448        }
     1449        else if (pData->Flags.BoxValid)
     1450        {
     1451            vboxVDbgPrintF((__FUNCTION__": Implement Box area"));
     1452            AssertBreakpoint();
     1453        }
     1454        else
     1455        {
     1456            AssertBreakpoint();
     1457        }
     1458
     1459        if (pData->Flags.Discard)
     1460        {
     1461            /* check if the surface was renamed */
     1462            if (LockData.hAllocation)
     1463                pAlloc->hAllocation = LockData.hAllocation;
     1464        }
     1465
     1466        pData->pSurfData = ((uint8_t*)LockData.pData) + offset;
     1467        pData->Pitch = pAlloc->SurfDesc.pitch;
     1468        pData->SlicePitch = pAlloc->SurfDesc.slicePitch;
     1469    }
     1470
     1471    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     1472    return hr;
    14021473}
    14031474static HRESULT APIENTRY vboxWddmDDevUnlock(HANDLE hDevice, CONST D3DDDIARG_UNLOCK* pData)
    14041475{
    1405     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1406     AssertBreakpoint();
    1407     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1408     return E_FAIL;
     1476    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     1477    AssertBreakpoint();
     1478    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
     1479    PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
     1480    HRESULT hr = S_OK;
     1481
     1482    Assert(pData->SubResourceIndex < pRc->cAllocations);
     1483    if (pData->SubResourceIndex >= pRc->cAllocations)
     1484        return E_INVALIDARG;
     1485
     1486    struct
     1487    {
     1488        D3DDDICB_UNLOCK Unlock;
     1489        D3DKMT_HANDLE hAllocation;
     1490    } UnlockData;
     1491
     1492    UnlockData.Unlock.NumAllocations = 1;
     1493    UnlockData.Unlock.phAllocations = &UnlockData.hAllocation;
     1494    UnlockData.hAllocation = pRc->aAllocations[pData->SubResourceIndex].hAllocation;
     1495
     1496    hr = pDevice->RtCallbacks.pfnUnlockCb(hDevice, &UnlockData.Unlock);
     1497    Assert(hr == S_OK);
     1498
     1499    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     1500    return hr;
    14091501}
    14101502static HRESULT APIENTRY vboxWddmDDevLockAsync(HANDLE hDevice, D3DDDIARG_LOCKASYNC* pData)
     
    14291521    return E_FAIL;
    14301522}
     1523
    14311524static HRESULT APIENTRY vboxWddmDDevCreateResource(HANDLE hDevice, D3DDDIARG_CREATERESOURCE* pResource)
    14321525{
    1433     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1434     AssertBreakpoint();
    1435     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1436     return E_FAIL;
    1437 }
     1526    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     1527    HRESULT hr = S_OK;
     1528    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
     1529    Assert(pDevice);
     1530    Assert(pResource);
     1531
     1532    /* allocate buffer for D3DDDICB_ALLOCATE + D3DDDI_ALLOCATIONINFO * numAllocs + PVBOXWDDM_RCINFO with aAllocInfos[numAllocs] */
     1533    uint32_t cbBuf = sizeof (D3DDDICB_ALLOCATE);
     1534    uint32_t offDdiAllocInfos = (cbBuf + 7) & ~3;
     1535    uint32_t cbDdiAllocInfos = sizeof (D3DDDI_ALLOCATIONINFO) * pResource->SurfCount;
     1536    cbBuf = offDdiAllocInfos + cbDdiAllocInfos;
     1537    uint32_t offRcInfo = (cbBuf + 7) & ~3;
     1538    uint32_t cbRcInfo = sizeof (VBOXWDDM_RCINFO);
     1539    cbBuf = offRcInfo + cbRcInfo;
     1540    uint32_t offAllocInfos = (cbBuf + 7) & ~3;
     1541    uint32_t cbAllocInfos = sizeof (VBOXWDDM_ALLOCINFO) * pResource->SurfCount;
     1542    cbBuf = offAllocInfos + cbAllocInfos;
     1543    uint8_t *pvBuf = (uint8_t*)RTMemAllocZ(cbBuf);
     1544    if (pvBuf)
     1545    {
     1546        D3DDDICB_ALLOCATE *pAllocate = (D3DDDICB_ALLOCATE*)pvBuf;
     1547        D3DDDI_ALLOCATIONINFO* pDdiAllocInfos = (D3DDDI_ALLOCATIONINFO*)(pvBuf + offDdiAllocInfos);
     1548        PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)(pvBuf + offRcInfo);
     1549        PVBOXWDDM_ALLOCINFO pAllocInfos = (PVBOXWDDM_ALLOCINFO)(pvBuf + offAllocInfos);
     1550        pAllocate->pPrivateDriverData = pRcInfo;
     1551        pAllocate->PrivateDriverDataSize = cbRcInfo;
     1552        pAllocate->hResource = pResource->hResource;
     1553        pAllocate->hKMResource = NULL;
     1554        pAllocate->NumAllocations = pResource->SurfCount;
     1555        pAllocate->pAllocationInfo = pDdiAllocInfos;
     1556
     1557        pRcInfo->fFlags = VBOXWDDM_RESOURCE_F_TYPE_GENERIC;
     1558        pRcInfo->RcDesc.fFlags = pResource->Flags;
     1559        pRcInfo->RcDesc.enmFormat = pResource->Format;
     1560        pRcInfo->RcDesc.enmPool = pResource->Pool;
     1561        pRcInfo->RcDesc.enmMultisampleType = pResource->MultisampleType;
     1562        pRcInfo->RcDesc.MultisampleQuality = pResource->MultisampleQuality;
     1563        pRcInfo->RcDesc.MipLevels = pResource->MipLevels;
     1564        pRcInfo->RcDesc.Fvf = pResource->Fvf;
     1565        pRcInfo->RcDesc.VidPnSourceId = pResource->VidPnSourceId;
     1566        pRcInfo->RcDesc.RefreshRate = pResource->RefreshRate;
     1567        pRcInfo->RcDesc.enmRotation = pResource->Rotation;
     1568        pRcInfo->cAllocInfos = pResource->SurfCount;
     1569
     1570        for (UINT i = 0; i < pResource->SurfCount; ++i)
     1571        {
     1572            PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i];
     1573            D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pDdiAllocInfos[i];
     1574            CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
     1575            pDdiAllocInfo->hAllocation = NULL;
     1576            pDdiAllocInfo->pSystemMem = pSurf->pSysMem;
     1577            Assert((!!(pSurf->pSysMem)) == (pResource->Pool == D3DDDIPOOL_SYSTEMMEM));
     1578            pDdiAllocInfo->pPrivateDriverData = pAllocInfo;
     1579            pDdiAllocInfo->PrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO);
     1580            pDdiAllocInfo->VidPnSourceId = pResource->VidPnSourceId;
     1581            pDdiAllocInfo->Flags.Value = 0;
     1582            if (pResource->Flags.Primary)
     1583                pDdiAllocInfo->Flags.Primary = 1;
     1584
     1585            pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
     1586            pAllocInfo->SurfDesc.width = pSurf->Width;
     1587            pAllocInfo->SurfDesc.height = pSurf->Height;
     1588            pAllocInfo->SurfDesc.format = pResource->Format;
     1589            pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format);
     1590
     1591            if (pSurf->SysMemPitch)
     1592            {
     1593                pAllocInfo->SurfDesc.pitch = pSurf->SysMemPitch;
     1594#ifdef DEBUG
     1595                UINT tst = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp);
     1596                Assert(tst == pSurf->SysMemPitch);
     1597#endif
     1598            }
     1599            else
     1600                pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp);
     1601
     1602            pAllocInfo->SurfDesc.depth = pSurf->Depth;
     1603            pAllocInfo->SurfDesc.slicePitch = pSurf->SysMemSlicePitch;
     1604            pAllocInfo->SurfDesc.VidPnSourceId = pResource->VidPnSourceId;
     1605            pAllocInfo->SurfDesc.RefreshRate = pResource->RefreshRate;
     1606        }
     1607
     1608        hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pAllocate);
     1609        Assert(hr == S_OK);
     1610        if (hr == S_OK)
     1611        {
     1612            Assert(pAllocate->hKMResource);
     1613            PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pResource->SurfCount);
     1614            if (pRc)
     1615            {
     1616                pRc->hResource = pResource->hResource;
     1617                pRc->hKMResource = pAllocate->hKMResource;
     1618                pRc->pDevice = pDevice;
     1619                pRc->fFlags = pRcInfo->fFlags;
     1620                pRc->RcDesc = pRcInfo->RcDesc;
     1621                pRc->cAllocations = pRcInfo->cAllocInfos;
     1622                for (UINT i = 0; i < pRcInfo->cAllocInfos; ++i)
     1623                {
     1624                    PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[1];
     1625                    D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pDdiAllocInfos[i];
     1626                    PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i];
     1627                    CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
     1628                    pAllocation->hAllocation = pDdiAllocInfo->hAllocation;
     1629                    pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
     1630                    pAllocation->pvMem = pSurf->pSysMem;
     1631                    pAllocation->SurfDesc = pAllocInfo->SurfDesc;
     1632                }
     1633
     1634                pResource->hResource = pRc;
     1635//                vboxResourceFree(pRc);
     1636            }
     1637            else
     1638            {
     1639                hr = E_OUTOFMEMORY;
     1640            }
     1641        }
     1642
     1643        RTMemFree(pvBuf);
     1644    }
     1645    else
     1646    {
     1647        hr = E_OUTOFMEMORY;
     1648    }
     1649
     1650    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     1651    return hr;
     1652}
     1653
    14381654static HRESULT APIENTRY vboxWddmDDevDestroyResource(HANDLE hDevice, HANDLE hResource)
    14391655{
    1440     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1441     AssertBreakpoint();
    1442     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1443     return E_FAIL;
     1656    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     1657    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
     1658    HRESULT hr = S_OK;
     1659
     1660    Assert(pDevice);
     1661    Assert(hResource);
     1662    PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hResource;
     1663    if (!(pRc->fFlags & VBOXWDDM_RESOURCE_F_OPENNED))
     1664    {
     1665        D3DDDICB_DEALLOCATE Dealloc;
     1666        Dealloc.hResource = pRc->hResource;
     1667        Assert(pRc->hResource);
     1668        /* according to the docs the below two are ignored in case we set the hResource */
     1669        Dealloc.NumAllocations = 0;
     1670        Dealloc.HandleList = NULL;
     1671        hr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);
     1672        Assert(hr == S_OK);
     1673    }
     1674
     1675    vboxResourceFree(pRc);
     1676    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     1677    return hr;
    14441678}
    14451679static HRESULT APIENTRY vboxWddmDDevSetDisplayMode(HANDLE hDevice, CONST D3DDDIARG_SETDISPLAYMODE* pData)
     
    18302064    return E_FAIL;
    18312065}
     2066
     2067static HRESULT vboxAllocationInit(PVBOXWDDMDISP_ALLOCATION pAlloc, D3DDDI_OPENALLOCATIONINFO *pInfo)
     2068{
     2069    HRESULT hr = S_OK;
     2070    pAlloc->hAllocation = pInfo->hAllocation;
     2071    Assert(pInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));
     2072    Assert(pInfo->pPrivateDriverData);
     2073    if (pInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO))
     2074    {
     2075        PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pInfo->pPrivateDriverData;
     2076        pAlloc->enmType = pAllocInfo->enmType;
     2077        Assert(pAllocInfo->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
     2078                || VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE
     2079                || VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE);
     2080        pAlloc->pvMem = NULL;
     2081        pAlloc->SurfDesc = pAllocInfo->SurfDesc;
     2082    }
     2083    else
     2084    {
     2085        vboxVDbgPrintR((__FUNCTION__": ERROR: PrivateDriverDataSize(%d) < (%d)\n", pInfo->PrivateDriverDataSize, sizeof (VBOXWDDM_ALLOCINFO)));
     2086        hr = E_INVALIDARG;
     2087    }
     2088    return hr;
     2089}
     2090
    18322091static HRESULT APIENTRY vboxWddmDDevOpenResource(HANDLE hDevice, D3DDDIARG_OPENRESOURCE* pData)
    18332092{
    1834     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1835     AssertBreakpoint();
    1836     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
    1837     return E_FAIL;
     2093    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     2094    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
     2095    HRESULT hr = S_OK;
     2096
     2097    Assert(pDevice);
     2098    Assert(pData->NumAllocations);
     2099    PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pData->NumAllocations);
     2100    Assert(pRc);
     2101    if (pRc)
     2102    {
     2103        pRc->hResource = pData->hResource;
     2104        pRc->hKMResource = pData->hKMResource;
     2105        pRc->pDevice = pDevice;
     2106        pRc->RcDesc.enmRotation = pData->Rotation;
     2107        pRc->fFlags = VBOXWDDM_RESOURCE_F_OPENNED;
     2108        if (!pData->pPrivateDriverData || !pData->PrivateDriverDataSize)
     2109        {
     2110            /* this is a "standard" allocation resource */
     2111
     2112            /* both should be actually zero */
     2113            Assert(!pData->pPrivateDriverData && !pData->PrivateDriverDataSize);
     2114            pRc->RcDesc.enmPool = D3DDDIPOOL_LOCALVIDMEM;
     2115            pRc->RcDesc.enmMultisampleType = D3DDDIMULTISAMPLE_NONE;
     2116            pRc->RcDesc.MultisampleQuality = 0;
     2117            pRc->RcDesc.MipLevels = 0;
     2118            pRc->RcDesc.Fvf;
     2119            pRc->RcDesc.fFlags.Value = 0;
     2120
     2121            Assert(pData->NumAllocations);
     2122            D3DDDI_OPENALLOCATIONINFO* pDdiAllocInfo = &pData->pOpenAllocationInfo[0];
     2123            Assert(pDdiAllocInfo->pPrivateDriverData);
     2124            Assert(pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO));
     2125            if (pDdiAllocInfo->pPrivateDriverData && pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO))
     2126            {
     2127                PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocInfo->pPrivateDriverData;
     2128                switch(pAllocInfo->enmType)
     2129                {
     2130                    case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
     2131                        pRc->RcDesc.fFlags.Primary = 1;
     2132                    case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
     2133                    case VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE:
     2134                        pRc->RcDesc.enmFormat = pAllocInfo->SurfDesc.format;
     2135                        pRc->RcDesc.VidPnSourceId = pAllocInfo->SurfDesc.VidPnSourceId;
     2136                        pRc->RcDesc.RefreshRate = pAllocInfo->SurfDesc.RefreshRate;
     2137                        break;
     2138                    default:
     2139                        AssertBreakpoint();
     2140                        hr = E_INVALIDARG;
     2141                }
     2142            }
     2143            else
     2144                hr = E_INVALIDARG;
     2145        }
     2146        else
     2147        {
     2148            /* this is a "generic" resource whose creation is initiaded by the UMD */
     2149            Assert(pData->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO));
     2150            if (pData->PrivateDriverDataSize >= sizeof (VBOXWDDM_RCINFO))
     2151            {
     2152                VBOXWDDM_RCINFO *pRcInfo = (VBOXWDDM_RCINFO*)pData->pPrivateDriverData;
     2153                Assert(pRcInfo->fFlags == VBOXWDDM_RESOURCE_F_TYPE_GENERIC);
     2154                Assert(pRcInfo->cAllocInfos == pData->NumAllocations);
     2155                pRc->fFlags = pRcInfo->fFlags | VBOXWDDM_RESOURCE_F_OPENNED;
     2156                pRc->RcDesc = pRcInfo->RcDesc;
     2157                pRc->cAllocations = pData->NumAllocations;
     2158            }
     2159            else
     2160                hr = E_INVALIDARG;
     2161        }
     2162
     2163        if (hr == S_OK)
     2164        {
     2165            for (UINT i = 0; i < pData->NumAllocations; ++i)
     2166            {
     2167                hr = vboxAllocationInit(&pRc->aAllocations[i], &pData->pOpenAllocationInfo[i]);
     2168                Assert(hr == S_OK);
     2169                if (hr != S_OK)
     2170                    break;
     2171            }
     2172        }
     2173
     2174        if (hr == S_OK)
     2175            pData->hResource = pRc;
     2176        else
     2177            vboxResourceFree(pRc);
     2178    }
     2179    else
     2180    {
     2181        vboxVDbgPrintR((__FUNCTION__": vboxResourceAlloc failed for hDevice(0x%p), NumAllocations(%d)\n", hDevice, pData->NumAllocations));
     2182        hr = E_OUTOFMEMORY;
     2183    }
     2184
     2185    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     2186    return hr;
    18382187}
    18392188static HRESULT APIENTRY vboxWddmDDevGetCaptureAllocationHandle(HANDLE hDevice, D3DDDIARG_GETCAPTUREALLOCATIONHANDLE* pData)
  • trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h

    r29798 r29883  
    7474} VBOXWDDMDISP_DEVICE, *PVBOXWDDMDISP_DEVICE;
    7575
     76typedef struct VBOXWDDMDISP_ALLOCATION
     77{
     78    D3DKMT_HANDLE hAllocation;
     79    VBOXWDDM_ALLOC_TYPE enmType;
     80    CONST VOID* pvMem;
     81    VBOXWDDM_SURFACE_DESC SurfDesc;
     82} VBOXWDDMDISP_ALLOCATION, *PVBOXWDDMDISP_ALLOCATION;
     83
     84typedef struct VBOXWDDMDISP_RESOURCE
     85{
     86    HANDLE hResource;
     87    D3DKMT_HANDLE hKMResource;
     88    PVBOXWDDMDISP_DEVICE pDevice;
     89    uint32_t fFlags;
     90    VBOXWDDM_RC_DESC RcDesc;
     91    UINT cAllocations;
     92    VBOXWDDMDISP_ALLOCATION aAllocations[1];
     93} VBOXWDDMDISP_RESOURCE, *PVBOXWDDMDISP_RESOURCE;
     94
    7695DECLINLINE(bool) vboxDispD3DIs3DEnabled(VBOXWDDMDISP_ADAPTER * pAdapter)
    7796{
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp

    r29625 r29883  
    985985        {
    986986            if (!xres)
    987                 xres = DeviceExtension->aSources[0].pPrimaryAllocation->u.SurfInfo.width;
     987                xres = DeviceExtension->aSources[0].pPrimaryAllocation->SurfDesc.width;
    988988            if (!yres)
    989                 yres = DeviceExtension->aSources[0].pPrimaryAllocation->u.SurfInfo.height;
     989                yres = DeviceExtension->aSources[0].pPrimaryAllocation->SurfDesc.height;
    990990            if (!bpp)
    991                 bpp  = DeviceExtension->aSources[0].pPrimaryAllocation->u.SurfInfo.bpp;
     991                bpp  = DeviceExtension->aSources[0].pPrimaryAllocation->SurfDesc.bpp;
    992992        }
    993993#endif
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h

    r29798 r29883  
    166166    struct VBOXWDDM_ALLOCATION * pShadowAllocation;
    167167    VBOXVIDEOOFFSET offVram;
    168     VBOXWDDM_SURFACE_DESC SurfInfo;
     168    VBOXWDDM_SURFACE_DESC SurfDesc;
    169169    VBOXVBVAINFO Vbva;
    170170#endif
     
    636636
    637637D3DDDIFORMAT vboxWddmCalcPixelFormat(VIDEO_MODE_INFORMATION *pInfo);
    638 UINT vboxWddmCalcBitsPerPixel(D3DDDIFORMAT format);
    639638
    640639DECLINLINE(ULONG) vboxWddmVramCpuVisibleSize(PDEVICE_EXTENSION pDevExt)
     
    668667}
    669668
    670 DECLINLINE(bool) vboxWddmCmpSurfDescs(VBOXWDDM_SURFACE_DESC *pDesc1, VBOXWDDM_SURFACE_DESC *pDesc2)
     669DECLINLINE(bool) vboxWddmCmpSurfDescsBase(VBOXWDDM_SURFACE_DESC *pDesc1, VBOXWDDM_SURFACE_DESC *pDesc2)
    671670{
    672671    if (pDesc1->width != pDesc2->width)
     
    691690    {
    692691        PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pShadowAllocation;
    693         PVBOXWDDM_ALLOCATION_SHADOWSURFACE pOldShadowInfo = VBOXWDDM_ALLOCATION_BODY(pOldAlloc, VBOXWDDM_ALLOCATION_SHADOWSURFACE);
    694692        /* clear the visibility info fo the current primary */
    695         pOldShadowInfo->bVisible = FALSE;
    696         pOldShadowInfo->bAssigned = FALSE;
    697         Assert(pOldShadowInfo->VidPnSourceId == srcId);
     693        pOldAlloc->bVisible = FALSE;
     694        pOldAlloc->bAssigned = FALSE;
     695        Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
    698696        /* release the shadow surface */
    699         pOldShadowInfo->VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
     697        pOldAlloc->SurfDesc.VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
    700698    }
    701699
    702700    if (pAllocation)
    703701    {
    704         PVBOXWDDM_ALLOCATION_SHADOWSURFACE pShadowInfo = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHADOWSURFACE);
    705         pShadowInfo->bVisible = FALSE;
     702        pAllocation->bVisible = FALSE;
    706703        /* this check ensures the shadow is not used for other source simultaneously */
    707         Assert(pShadowInfo->VidPnSourceId == D3DDDI_ID_UNINITIALIZED);
    708         pShadowInfo->VidPnSourceId = srcId;
    709         pShadowInfo->bAssigned = TRUE;
    710         if (!vboxWddmCmpSurfDescs(&pSource->SurfInfo, &pAllocation->u.SurfInfo))
     704        Assert(pAllocation->SurfDesc.VidPnSourceId == D3DDDI_ID_UNINITIALIZED);
     705        pAllocation->SurfDesc.VidPnSourceId = srcId;
     706        pAllocation->bAssigned = TRUE;
     707        if (!vboxWddmCmpSurfDescsBase(&pSource->SurfDesc, &pAllocation->SurfDesc))
    711708            pSource->offVram = VBOXVIDEOOFFSET_VOID; /* force guest->host notification */
    712         pSource->SurfInfo = pAllocation->u.SurfInfo;
     709        pSource->SurfDesc = pAllocation->SurfDesc;
    713710    }
    714711
     
    725722    {
    726723        PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pPrimaryAllocation;
    727         PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pOldPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pOldAlloc, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    728724        /* clear the visibility info fo the current primary */
    729         pOldPrimaryInfo->bVisible = FALSE;
    730         pOldPrimaryInfo->bAssigned = FALSE;
    731         Assert(pOldPrimaryInfo->VidPnSourceId == srcId);
     725        pOldAlloc->bVisible = FALSE;
     726        pOldAlloc->bAssigned = FALSE;
     727        Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
    732728    }
    733729
    734730    if (pAllocation)
    735731    {
    736         PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    737         pPrimaryInfo->bVisible = FALSE;
    738         Assert(pPrimaryInfo->VidPnSourceId == srcId);
    739         pPrimaryInfo->VidPnSourceId = srcId;
    740         pPrimaryInfo->bAssigned = TRUE;
     732        pAllocation->bVisible = FALSE;
     733        Assert(pAllocation->SurfDesc.VidPnSourceId == srcId);
     734        pAllocation->SurfDesc.VidPnSourceId = srcId;
     735        pAllocation->bAssigned = TRUE;
    741736    }
    742737
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideoHGSMI.cpp

    r29798 r29883  
    10481048int VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension)
    10491049{
    1050     int rc;
     1050    int rc = VINF_SUCCESS;
    10511051    for (int i = PrimaryExtension->cSources-1; i >= 0; --i)
    10521052    {
     
    10571057            rc = vboxVbvaDestroy(PrimaryExtension, &PrimaryExtension->aSources[i].Vbva);
    10581058            AssertRC(rc);
     1059            if (RT_FAILURE(rc))
     1060            {
     1061                /* @todo: */
     1062            }
     1063        }
     1064    }
     1065
     1066    rc = vboxVdmaDisable(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
     1067    AssertRC(rc);
     1068    if (RT_SUCCESS(rc))
     1069    {
     1070        rc = vboxVdmaDestroy(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
     1071        AssertRC(rc);
     1072        if (RT_SUCCESS(rc))
     1073        {
     1074            /*rc = */VBoxUnmapAdapterMemory(PrimaryExtension, &PrimaryExtension->u.primary.pvMiniportHeap, PrimaryExtension->u.primary.cbMiniportHeap);
     1075/*
     1076            AssertRC(rc);
    10591077            if (RT_SUCCESS(rc))
    1060             {
    1061                 rc = vboxVdmaDisable(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
     1078*/
     1079            {
     1080                HGSMIHeapDestroy(&PrimaryExtension->u.primary.hgsmiAdapterHeap);
     1081
     1082                /* Map the adapter information. It will be needed for HGSMI IO. */
     1083                /*rc = */VBoxUnmapAdapterMemory(PrimaryExtension, &PrimaryExtension->u.primary.pvAdapterInformation, VBVA_ADAPTER_INFORMATION_SIZE);
     1084/*
    10621085                AssertRC(rc);
    1063                 if (RT_SUCCESS(rc))
    1064                 {
    1065                     rc = vboxVdmaDestroy(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
    1066                     AssertRC(rc);
    1067                     if (RT_SUCCESS(rc))
    1068                     {
    1069                         /*rc = */VBoxUnmapAdapterMemory(PrimaryExtension, &PrimaryExtension->u.primary.pvMiniportHeap, PrimaryExtension->u.primary.cbMiniportHeap);
    1070 /*
    1071                         AssertRC(rc);
    1072                         if (RT_SUCCESS(rc))
     1086                if (RT_FAILURE(rc))
     1087                    drprintf((__FUNCTION__"VBoxUnmapAdapterMemory PrimaryExtension->u.primary.pvAdapterInformation failed, rc(%d)\n", rc));
    10731088*/
    1074                         {
    1075                             HGSMIHeapDestroy(&PrimaryExtension->u.primary.hgsmiAdapterHeap);
    1076 
    1077                             /* Map the adapter information. It will be needed for HGSMI IO. */
    1078                             /*rc = */VBoxUnmapAdapterMemory(PrimaryExtension, &PrimaryExtension->u.primary.pvAdapterInformation, VBVA_ADAPTER_INFORMATION_SIZE);
    1079 /*
    1080                             AssertRC(rc);
    1081                             if (RT_FAILURE(rc))
    1082                                 drprintf((__FUNCTION__"VBoxUnmapAdapterMemory PrimaryExtension->u.primary.pvAdapterInformation failed, rc(%d)\n", rc));
    1083 */
    1084 
    1085                         }
    1086                     }
    1087                 }
     1089
    10881090            }
    10891091        }
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoIf.h

    r29710 r29883  
    2424#include <VBox/VBoxVideo.h>
    2525
    26 /* @todo: implement a check to ensure display & miniport versions match
    27  * one would increase this whenever defines in this file change */
    28 #define VBOXVIDEOIF_VERSION 1
     26/* @todo: implement a check to ensure display & miniport versions match.
     27 * One would increase this whenever definitions in this file are changed */
     28#define VBOXVIDEOIF_VERSION 2
    2929
    3030/* create allocation func */
     
    3838    VBOXWDDM_ALLOC_TYPE_STD_GDISURFACE
    3939    /* custom allocation types requested from user-mode d3d module will go here */
     40    , VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC
    4041} VBOXWDDM_ALLOC_TYPE;
    4142
     
    4748    UINT bpp;
    4849    UINT pitch;
     50    UINT depth;
     51    UINT slicePitch;
     52    D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
     53    D3DDDI_RATIONAL RefreshRate;
    4954} VBOXWDDM_SURFACE_DESC, *PVBOXWDDM_SURFACE_DESC;
    5055
     
    5257{
    5358    VBOXWDDM_ALLOC_TYPE enmType;
    54     union
    55     {
    56         VBOXWDDM_SURFACE_DESC SurfInfo;
    57     } u;
     59    VBOXWDDM_SURFACE_DESC SurfDesc;
    5860} VBOXWDDM_ALLOCINFO, *PVBOXWDDM_ALLOCINFO;
    5961
    60 #define VBOXWDDM_ALLOCINFO_HEADSIZE() (sizeof (VBOXWDDM_ALLOCINFO))
    61 #define VBOXWDDM_ALLOCINFO_SIZE_FROMBODYSIZE(_s) (VBOXWDDM_ALLOCINFO_HEADSIZE() + (_s))
    62 #define VBOXWDDM_ALLOCINFO_SIZE(_tCmd) (VBOXWDDM_ALLOCINFO_SIZE_FROMBODYSIZE(sizeof(_tCmd)))
    63 #define VBOXWDDM_ALLOCINFO_BODY(_p, _t) ( (_t*)(((uint8_t*)(_p)) + VBOXWDDM_ALLOCINFO_HEADSIZE()) )
    64 #define VBOXWDDM_ALLOCINFO_HEAD(_pb) ((VBOXWDDM_ALLOCINFO*)((uint8_t *)(_pb) - VBOXWDDM_ALLOCATION_HEADSIZE()))
     62//#define VBOXWDDM_ALLOCINFO_HEADSIZE() (sizeof (VBOXWDDM_ALLOCINFO))
     63//#define VBOXWDDM_ALLOCINFO_SIZE_FROMBODYSIZE(_s) (VBOXWDDM_ALLOCINFO_HEADSIZE() + (_s))
     64//#define VBOXWDDM_ALLOCINFO_SIZE(_tCmd) (VBOXWDDM_ALLOCINFO_SIZE_FROMBODYSIZE(sizeof(_tCmd)))
     65//#define VBOXWDDM_ALLOCINFO_BODY(_p, _t) ( (_t*)(((uint8_t*)(_p)) + VBOXWDDM_ALLOCINFO_HEADSIZE()) )
     66//#define VBOXWDDM_ALLOCINFO_HEAD(_pb) ((VBOXWDDM_ALLOCINFO*)((uint8_t *)(_pb) - VBOXWDDM_ALLOCATION_HEADSIZE()))
    6567
     68/* this resource is OpenResource'd rather than CreateResource'd */
     69#define VBOXWDDM_RESOURCE_F_OPENNED      0x00000001
     70/* identifies this is a resource created with CreateResource, the VBOXWDDMDISP_RESOURCE::fRcFlags is valid */
     71#define VBOXWDDM_RESOURCE_F_TYPE_GENERIC 0x00000002
     72
     73typedef struct VBOXWDDM_RC_DESC
     74{
     75    D3DDDI_RESOURCEFLAGS fFlags;
     76    D3DDDIFORMAT enmFormat;
     77    D3DDDI_POOL enmPool;
     78    D3DDDIMULTISAMPLE_TYPE enmMultisampleType;
     79    UINT MultisampleQuality;
     80    UINT MipLevels;
     81    UINT Fvf;
     82    D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
     83    D3DDDI_RATIONAL RefreshRate;
     84    D3DDDI_ROTATION enmRotation;
     85} VBOXWDDM_RC_DESC, *PVBOXWDDM_RC_DESC;
     86
     87typedef struct VBOXWDDM_RCINFO
     88{
     89    uint32_t fFlags;
     90    VBOXWDDM_RC_DESC RcDesc;
     91    uint32_t cAllocInfos;
     92//    VBOXWDDM_ALLOCINFO aAllocInfos[1];
     93} VBOXWDDM_RCINFO, *PVBOXWDDM_RCINFO;
    6694
    6795#define VBOXVHWA_F_ENABLED  0x00000001
     
    89117/* submit cmd func */
    90118
     119
     120
     121
     122/* tooling */
     123DECLINLINE(UINT) vboxWddmCalcBitsPerPixel(D3DDDIFORMAT format)
     124{
     125    switch (format)
     126    {
     127        case D3DDDIFMT_R8G8B8:
     128            return 24;
     129        case D3DDDIFMT_A8R8G8B8:
     130        case D3DDDIFMT_X8R8G8B8:
     131            return 32;
     132        case D3DDDIFMT_R5G6B5:
     133        case D3DDDIFMT_X1R5G5B5:
     134        case D3DDDIFMT_A1R5G5B5:
     135        case D3DDDIFMT_A4R4G4B4:
     136            return 16;
     137        case D3DDDIFMT_R3G3B2:
     138        case D3DDDIFMT_A8:
     139            return 8;
     140        case D3DDDIFMT_A8R3G3B2:
     141        case D3DDDIFMT_X4R4G4B4:
     142            return 16;
     143        case D3DDDIFMT_A2B10G10R10:
     144        case D3DDDIFMT_A8B8G8R8:
     145        case D3DDDIFMT_X8B8G8R8:
     146        case D3DDDIFMT_G16R16:
     147        case D3DDDIFMT_A2R10G10B10:
     148            return 32;
     149        case D3DDDIFMT_A16B16G16R16:
     150            return 64;
     151        case D3DDDIFMT_A8P8:
     152            return 16;
     153        case D3DDDIFMT_P8:
     154            return 8;
     155        default:
     156            AssertBreakpoint();
     157            return 0;
     158    }
     159}
     160
     161#define VBOXWDDM_ROUNDBOUND(_v, _b) (((_v) + ((_b) - 1)) & ~((_b) - 1))
     162
     163DECLINLINE(UINT) vboxWddmCalcPitch(UINT w, UINT bitsPerPixel)
     164{
     165    UINT Pitch = bitsPerPixel * w;
     166    /* pitch is now in bits, translate in bytes */
     167    return VBOXWDDM_ROUNDBOUND(Pitch, 8) >> 3;
     168}
     169
    91170#endif /* #ifndef ___VBoxVideoIf_h___ */
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp

    r29798 r29883  
    7676}
    7777
    78 NTSTATUS vboxWddmGhDisplayPostInfoScreen (PDEVICE_EXTENSION pDevExt, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
     78NTSTATUS vboxWddmGhDisplayPostInfoScreen (PDEVICE_EXTENSION pDevExt, PVBOXWDDM_ALLOCATION pAllocation)
    7979{
    8080    VBOXVIDEOOFFSET offVram = pAllocation->offVram;
     
    8383//        return STATUS_INVALID_PARAMETER;
    8484
    85 //    PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    8685    /* Issue the screen info command. */
    8786    void *p = vboxHGSMIBufferAlloc (pDevExt,
     
    9493        VBVAINFOSCREEN *pScreen = (VBVAINFOSCREEN *)p;
    9594
    96         pScreen->u32ViewIndex    = /*pPrimaryInfo->*/VidPnSourceId;
     95        pScreen->u32ViewIndex    = pAllocation->SurfDesc.VidPnSourceId;
    9796        pScreen->i32OriginX      = 0;
    9897        pScreen->i32OriginY      = 0;
    9998        pScreen->u32StartOffset  = 0; //(uint32_t)offVram; /* we pretend the view is located at the start of each framebuffer */
    100         pScreen->u32LineSize     = pAllocation->u.SurfInfo.pitch;
    101         pScreen->u32Width        = pAllocation->u.SurfInfo.width;
    102         pScreen->u32Height       = pAllocation->u.SurfInfo.height;
    103         pScreen->u16BitsPerPixel = (uint16_t)pAllocation->u.SurfInfo.bpp;
     99        pScreen->u32LineSize     = pAllocation->SurfDesc.pitch;
     100        pScreen->u32Width        = pAllocation->SurfDesc.width;
     101        pScreen->u32Height       = pAllocation->SurfDesc.height;
     102        pScreen->u16BitsPerPixel = (uint16_t)pAllocation->SurfDesc.bpp;
    104103        pScreen->u16Flags        = VBVA_SCREEN_F_ACTIVE;
    105104
     
    112111}
    113112
    114 NTSTATUS vboxWddmGhDisplayPostInfoView (PDEVICE_EXTENSION pDevExt, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
     113NTSTATUS vboxWddmGhDisplayPostInfoView(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_ALLOCATION pAllocation)
    115114{
    116115    VBOXVIDEOOFFSET offVram = pAllocation->offVram;
     
    119118        return STATUS_INVALID_PARAMETER;
    120119
    121 //    PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    122120    /* Issue the screen info command. */
    123121    void *p = vboxHGSMIBufferAlloc (pDevExt,
     
    130128        VBVAINFOVIEW *pView = (VBVAINFOVIEW *)p;
    131129
    132         pView->u32ViewIndex     = /*pPrimaryInfo->*/VidPnSourceId;
     130        pView->u32ViewIndex     = pAllocation->SurfDesc.VidPnSourceId;
    133131        pView->u32ViewOffset    = (uint32_t)offVram; /* we pretend the view is located at the start of each framebuffer */
    134132        pView->u32ViewSize      = vboxWddmVramCpuVisibleSegmentSize(pDevExt)/pDevExt->cSources;
     
    144142}
    145143
    146 NTSTATUS vboxWddmGhDisplaySetMode (PDEVICE_EXTENSION pDevExt, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
     144NTSTATUS vboxWddmGhDisplaySetMode(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_ALLOCATION pAllocation)
    147145{
    148146//    PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    149     if (/*pPrimaryInfo->*/VidPnSourceId)
     147    if (/*pPrimaryInfo->*/pAllocation->SurfDesc.VidPnSourceId)
    150148        return STATUS_SUCCESS;
    151149
    152     if (VBoxVideoSetCurrentModePerform(pDevExt, pAllocation->u.SurfInfo.width,
    153             pAllocation->u.SurfInfo.height, pAllocation->u.SurfInfo.bpp,
     150    if (VBoxVideoSetCurrentModePerform(pDevExt, pAllocation->SurfDesc.width,
     151            pAllocation->SurfDesc.height, pAllocation->SurfDesc.bpp,
    154152            (ULONG)pAllocation->offVram))
    155153        return STATUS_SUCCESS;
     
    166164#ifndef VBOXWDDM_RENDER_FROM_SHADOW
    167165    PVBOXWDDM_ALLOCATION pAllocation = pSource->pPrimaryAllocation;
    168     PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    169166#else
    170167    PVBOXWDDM_ALLOCATION pAllocation = pSource->pShadowAllocation;
    171     PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pSource->pPrimaryAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    172168#endif
    173169    VBOXVIDEOOFFSET offVram = vboxWddmValidatePrimary(pAllocation);
     
    179175     * Set the current mode into the hardware.
    180176     */
    181     NTSTATUS Status = vboxWddmGhDisplaySetMode (pDevExt, pAllocation, pPrimaryInfo->VidPnSourceId);
     177    NTSTATUS Status = vboxWddmGhDisplaySetMode(pDevExt, pAllocation);
    182178    Assert(Status == STATUS_SUCCESS);
    183179    if (Status == STATUS_SUCCESS)
    184180    {
    185         Status = vboxWddmGhDisplayPostInfoView (pDevExt, pAllocation, pPrimaryInfo->VidPnSourceId);
     181        Status = vboxWddmGhDisplayPostInfoView(pDevExt, pAllocation);
    186182        Assert(Status == STATUS_SUCCESS);
    187183        if (Status == STATUS_SUCCESS)
    188184        {
    189             Status = vboxWddmGhDisplayPostInfoScreen (pDevExt, pAllocation, pPrimaryInfo->VidPnSourceId);
     185            Status = vboxWddmGhDisplayPostInfoScreen(pDevExt, pAllocation);
    190186            Assert(Status == STATUS_SUCCESS);
    191187            if (Status != STATUS_SUCCESS)
     
    407403}
    408404
    409 UINT vboxWddmCalcBitsPerPixel(D3DDDIFORMAT format)
    410 {
    411     switch (format)
    412     {
    413         case D3DDDIFMT_R8G8B8:
    414             return 24;
    415         case D3DDDIFMT_A8R8G8B8:
    416         case D3DDDIFMT_X8R8G8B8:
    417             return 32;
    418         case D3DDDIFMT_R5G6B5:
    419         case D3DDDIFMT_X1R5G5B5:
    420         case D3DDDIFMT_A1R5G5B5:
    421         case D3DDDIFMT_A4R4G4B4:
    422             return 16;
    423         case D3DDDIFMT_R3G3B2:
    424         case D3DDDIFMT_A8:
    425             return 8;
    426         case D3DDDIFMT_A8R3G3B2:
    427         case D3DDDIFMT_X4R4G4B4:
    428             return 16;
    429         case D3DDDIFMT_A2B10G10R10:
    430         case D3DDDIFMT_A8B8G8R8:
    431         case D3DDDIFMT_X8B8G8R8:
    432         case D3DDDIFMT_G16R16:
    433         case D3DDDIFMT_A2R10G10B10:
    434             return 32;
    435         case D3DDDIFMT_A16B16G16R16:
    436             return 64;
    437         case D3DDDIFMT_A8P8:
    438             return 16;
    439         case D3DDDIFMT_P8:
    440             return 8;
    441         default:
    442             AssertBreakpoint();
    443             return 0;
    444     }
    445 }
    446 
    447405D3DDDIFORMAT vboxWddmCalcPixelFormat(VIDEO_MODE_INFORMATION *pInfo)
    448406{
     
    509467
    510468    return D3DDDIFMT_UNKNOWN;
    511 }
    512 
    513 UINT vboxWddmCalcPitch(UINT w, UINT bitsPerPixel)
    514 {
    515     UINT Pitch = bitsPerPixel * w;
    516     /* pitch is now in bits, translate in bytes */
    517     if(Pitch & 7)
    518         Pitch = (Pitch >> 3) + 1;
    519     else
    520         Pitch = (Pitch >> 3);
    521 
    522     return Pitch;
    523469}
    524470
     
    14341380        case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
    14351381        {
    1436             PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pAlloc = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    1437             if (pAlloc->bAssigned)
     1382            if (pAllocation->bAssigned)
    14381383            {
    14391384                /* @todo: do we need to notify host? */
    1440                 vboxWddmAssignPrimary(pDevExt, &pDevExt->aSources[pAlloc->VidPnSourceId], NULL, pAlloc->VidPnSourceId);
     1385                vboxWddmAssignPrimary(pDevExt, &pDevExt->aSources[pAllocation->SurfDesc.VidPnSourceId], NULL, pAllocation->SurfDesc.VidPnSourceId);
    14411386            }
    14421387            break;
     
    14451390        case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
    14461391        {
    1447             PVBOXWDDM_ALLOCATION_SHADOWSURFACE pAlloc = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHADOWSURFACE);
    1448             if (pAlloc->bAssigned)
    1449             {
    1450                 Assert(pAlloc->VidPnSourceId != D3DDDI_ID_UNINITIALIZED);
     1392            if (pAllocation->bAssigned)
     1393            {
     1394                Assert(pAllocation->SurfDesc.VidPnSourceId != D3DDDI_ID_UNINITIALIZED);
    14511395                /* @todo: do we need to notify host? */
    1452                 vboxWddmAssignShadow(pDevExt, &pDevExt->aSources[pAlloc->VidPnSourceId], NULL, pAlloc->VidPnSourceId);
     1396                vboxWddmAssignShadow(pDevExt, &pDevExt->aSources[pAllocation->SurfDesc.VidPnSourceId], NULL, pAllocation->SurfDesc.VidPnSourceId);
    14531397            }
    14541398            break;
     
    14681412    NTSTATUS Status = STATUS_SUCCESS;
    14691413
    1470     Assert(pAllocationInfo->PrivateDriverDataSize >= VBOXWDDM_ALLOCINFO_HEADSIZE());
    1471     if (pAllocationInfo->PrivateDriverDataSize >= VBOXWDDM_ALLOCINFO_HEADSIZE())
     1414    Assert(pAllocationInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));
     1415    if (pAllocationInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO))
    14721416    {
    14731417        PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pAllocationInfo->pPrivateDriverData;
    1474         switch (pAllocInfo->enmType)
    1475         {
    1476             case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
    1477             {
    1478                 Assert(pAllocationInfo->PrivateDriverDataSize >= VBOXWDDM_ALLOCINFO_SIZE(VBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE));
    1479                 if (pAllocationInfo->PrivateDriverDataSize >= VBOXWDDM_ALLOCINFO_SIZE(VBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE))
    1480                 {
    1481                     if (pAllocInfo->u.SurfInfo.bpp != 0)
    1482                     {
    1483                         PVBOXWDDM_ALLOCATION pAllocation = (PVBOXWDDM_ALLOCATION)vboxWddmMemAllocZero(VBOXWDDM_ALLOCATION_SIZE(VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE));
    1484                         Assert(pAllocation);
    1485                         if (pAllocation)
    1486                         {
    1487                             pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE;
    1488                             pAllocation->offVram = VBOXVIDEOOFFSET_VOID;
    1489                             pAllocation->u.SurfInfo = pAllocInfo->u.SurfInfo;
    1490                             PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pAlloc = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    1491                             PVBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE pAllocI = VBOXWDDM_ALLOCINFO_BODY(pAllocInfo, VBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE);
    1492                             pAlloc->RefreshRate = pAllocI->RefreshRate;
    1493                             pAlloc->VidPnSourceId = pAllocI->VidPnSourceId;
    1494 //                            pAlloc->offAddress = VBOXVIDEOOFFSET_VOID;
    1495                             pAlloc->bVisible = FALSE;
    1496 
    1497                             pAllocationInfo->pPrivateDriverData = NULL;
    1498                             pAllocationInfo->PrivateDriverDataSize = 0;
    1499                             pAllocationInfo->Alignment = 0;
    1500                             pAllocationInfo->Size = pAllocInfo->u.SurfInfo.pitch * pAllocInfo->u.SurfInfo.height;
    1501                             pAllocationInfo->PitchAlignedSize = 0;
    1502                             pAllocationInfo->HintedBank.Value = 0;
    1503                             pAllocationInfo->PreferredSegment.Value = 0;
    1504 #if 1 //defined(VBOXWDDM_RENDER_FROM_SHADOW)
    1505                             pAllocationInfo->SupportedReadSegmentSet = 1;
    1506                             pAllocationInfo->SupportedWriteSegmentSet = 1;
    1507 #else
    1508                             pAllocationInfo->SupportedReadSegmentSet = 2;
    1509                             pAllocationInfo->SupportedWriteSegmentSet = 2;
     1418        PVBOXWDDM_ALLOCATION pAllocation = (PVBOXWDDM_ALLOCATION)vboxWddmMemAllocZero(sizeof (VBOXWDDM_ALLOCATION));
     1419        Assert(pAllocation);
     1420        if (pAllocation)
     1421        {
     1422            pAllocation->enmType = pAllocInfo->enmType;
     1423            pAllocation->offVram = VBOXVIDEOOFFSET_VOID;
     1424            pAllocation->SurfDesc = pAllocInfo->SurfDesc;
     1425            pAllocation->bVisible = FALSE;
     1426            pAllocation->bAssigned = FALSE;
     1427
     1428            pAllocationInfo->pPrivateDriverData = NULL;
     1429            pAllocationInfo->PrivateDriverDataSize = 0;
     1430            pAllocationInfo->Alignment = 0;
     1431            pAllocationInfo->Size = pAllocInfo->SurfDesc.pitch * pAllocInfo->SurfDesc.height;
     1432            pAllocationInfo->PitchAlignedSize = 0;
     1433            pAllocationInfo->HintedBank.Value = 0;
     1434            pAllocationInfo->PreferredSegment.Value = 0;
     1435            pAllocationInfo->SupportedReadSegmentSet = 1;
     1436            pAllocationInfo->SupportedWriteSegmentSet = 1;
     1437            pAllocationInfo->EvictionSegmentSet = 0;
     1438            pAllocationInfo->MaximumRenamingListLength = 0;
     1439            pAllocationInfo->hAllocation = pAllocation;
     1440            pAllocationInfo->Flags.Value = 0;
     1441            pAllocationInfo->pAllocationUsageHint = NULL;
     1442            pAllocationInfo->AllocationPriority = D3DDDI_ALLOCATIONPRIORITY_NORMAL;
     1443
     1444            switch (pAllocInfo->enmType)
     1445            {
     1446                case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
     1447#if 0 //defined(VBOXWDDM_RENDER_FROM_SHADOW)
     1448                    pAllocationInfo->SupportedReadSegmentSet = 2;
     1449                    pAllocationInfo->SupportedWriteSegmentSet = 2;
    15101450#endif
    1511                             pAllocationInfo->EvictionSegmentSet = 0;
    1512                             pAllocationInfo->MaximumRenamingListLength = 0;
    1513                             pAllocationInfo->hAllocation = pAllocation;
    1514                             pAllocationInfo->Flags.Value = 0;
    15151451#ifndef VBOXWDDM_RENDER_FROM_SHADOW
    1516                             pAllocationInfo->Flags.CpuVisible = 1;
     1452                    pAllocationInfo->Flags.CpuVisible = 1;
    15171453#endif
    1518                             pAllocationInfo->pAllocationUsageHint = NULL;
    1519                             pAllocationInfo->AllocationPriority = D3DDDI_ALLOCATIONPRIORITY_NORMAL;
    1520                         }
    1521                         else
    1522                         {
    1523                             drprintf((__FUNCTION__ ": ERROR: failed to create allocation description\n"));
    1524                             Status = STATUS_NO_MEMORY;
    1525                         }
    1526                     }
    1527                     else
    1528                     {
    1529                         drprintf((__FUNCTION__ ": Invalid format (%d)\n", pAllocInfo->u.SurfInfo.format));
    1530                         Status = STATUS_INVALID_PARAMETER;
    1531                     }
    1532                 }
    1533                 else
    1534                 {
    1535                     drprintf((__FUNCTION__ ": ERROR: PrivateDriverDataSize(%d) less than VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE cmd size(%d)\n", pAllocationInfo->PrivateDriverDataSize, VBOXWDDM_ALLOCINFO_SIZE(VBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE)));
     1454                    break;
     1455                case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
     1456                case VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE:
     1457                case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
     1458                    pAllocationInfo->Flags.Value = 0;
     1459                    pAllocationInfo->Flags.CpuVisible = 1;
     1460                    break;
     1461                default:
     1462                    drprintf((__FUNCTION__ ": ERROR: invalid alloc info type(%d)\n", pAllocInfo->enmType));
     1463                    AssertBreakpoint();
    15361464                    Status = STATUS_INVALID_PARAMETER;
    1537                 }
    1538                 break;
    1539             }
    1540             case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
    1541 #ifdef VBOXWDDM_RENDER_FROM_SHADOW
    1542             {
    1543                 Assert(pAllocationInfo->PrivateDriverDataSize >= VBOXWDDM_ALLOCINFO_HEADSIZE());
    1544                 if (pAllocationInfo->PrivateDriverDataSize >= VBOXWDDM_ALLOCINFO_HEADSIZE())
    1545                 {
    1546                     PVBOXWDDM_ALLOCATION pAllocation = (PVBOXWDDM_ALLOCATION)vboxWddmMemAllocZero(VBOXWDDM_ALLOCATION_SIZE(VBOXWDDM_ALLOCATION_SHADOWSURFACE));
    1547                     Assert(pAllocation);
    1548                     if (pAllocation)
    1549                     {
    1550                         pAllocation->enmType = pAllocInfo->enmType;
    1551                         pAllocation->offVram = VBOXVIDEOOFFSET_VOID;
    1552                         pAllocation->u.SurfInfo = pAllocInfo->u.SurfInfo;
    1553 
    1554                         pAllocationInfo->pPrivateDriverData = NULL;
    1555                         pAllocationInfo->PrivateDriverDataSize = 0;
    1556                         pAllocationInfo->Alignment = 0;
    1557                         pAllocationInfo->Size = pAllocInfo->u.SurfInfo.pitch * pAllocInfo->u.SurfInfo.height;
    1558                         pAllocationInfo->PitchAlignedSize = 0;
    1559                         pAllocationInfo->HintedBank.Value = 0;
    1560                         pAllocationInfo->PreferredSegment.Value = 0;
    1561                         pAllocationInfo->SupportedReadSegmentSet = 1;
    1562                         pAllocationInfo->SupportedWriteSegmentSet = 1;
    1563                         pAllocationInfo->EvictionSegmentSet = 0;
    1564                         pAllocationInfo->MaximumRenamingListLength = 0;
    1565                         pAllocationInfo->hAllocation = pAllocation;
    1566                         pAllocationInfo->Flags.Value = 0;
    1567                         pAllocationInfo->Flags.CpuVisible = 1;
    1568                         pAllocationInfo->pAllocationUsageHint = NULL;
    1569                         pAllocationInfo->AllocationPriority = D3DDDI_ALLOCATIONPRIORITY_NORMAL;
    1570                         PVBOXWDDM_ALLOCATION_SHADOWSURFACE pAlloc = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHADOWSURFACE);
    1571                         pAlloc->VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
    1572 //                        pAlloc->bVisible = FALSE;
    1573 //                        pAlloc->bAssigned = FALSE;
    1574                     }
    1575                     else
    1576                     {
    1577                         drprintf((__FUNCTION__ ": ERROR: failed to create allocation description\n"));
    1578                         Status = STATUS_NO_MEMORY;
    1579                     }
    1580                 }
    1581                 else
    1582                 {
    1583                     drprintf((__FUNCTION__ ": ERROR: PrivateDriverDataSize(%d) less than cmd size(%d)\n", pAllocationInfo->PrivateDriverDataSize, VBOXWDDM_ALLOCINFO_HEADSIZE()));
    1584                     Status = STATUS_INVALID_PARAMETER;
    1585                 }
    1586                 break;
    1587             }
    1588 #endif
    1589             case VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE:
    1590             {
    1591                 Assert(pAllocationInfo->PrivateDriverDataSize >= VBOXWDDM_ALLOCINFO_HEADSIZE());
    1592                 if (pAllocationInfo->PrivateDriverDataSize >= VBOXWDDM_ALLOCINFO_HEADSIZE())
    1593                 {
    1594                     PVBOXWDDM_ALLOCATION pAllocation = (PVBOXWDDM_ALLOCATION)vboxWddmMemAllocZero(VBOXWDDM_ALLOCATION_HEADSIZE());
    1595                     Assert(pAllocation);
    1596                     if (pAllocation)
    1597                     {
    1598                         pAllocation->enmType = pAllocInfo->enmType;
    1599                         pAllocation->offVram = VBOXVIDEOOFFSET_VOID;
    1600                         pAllocation->u.SurfInfo = pAllocInfo->u.SurfInfo;
    1601 
    1602                         pAllocationInfo->pPrivateDriverData = NULL;
    1603                         pAllocationInfo->PrivateDriverDataSize = 0;
    1604                         pAllocationInfo->Alignment = 0;
    1605                         pAllocationInfo->Size = pAllocInfo->u.SurfInfo.pitch * pAllocInfo->u.SurfInfo.height;
    1606                         pAllocationInfo->PitchAlignedSize = 0;
    1607                         pAllocationInfo->HintedBank.Value = 0;
    1608                         pAllocationInfo->PreferredSegment.Value = 0;
    1609                         pAllocationInfo->SupportedReadSegmentSet = 1;
    1610                         pAllocationInfo->SupportedWriteSegmentSet = 1;
    1611                         pAllocationInfo->EvictionSegmentSet = 0;
    1612                         pAllocationInfo->MaximumRenamingListLength = 0;
    1613                         pAllocationInfo->hAllocation = pAllocation;
    1614                         pAllocationInfo->Flags.Value = 0;
    1615                         pAllocationInfo->Flags.CpuVisible = 1;
    1616                         pAllocationInfo->pAllocationUsageHint = NULL;
    1617                         pAllocationInfo->AllocationPriority = D3DDDI_ALLOCATIONPRIORITY_NORMAL;
    1618                     }
    1619                     else
    1620                     {
    1621                         drprintf((__FUNCTION__ ": ERROR: failed to create allocation description\n"));
    1622                         Status = STATUS_NO_MEMORY;
    1623                     }
    1624                 }
    1625                 else
    1626                 {
    1627                     drprintf((__FUNCTION__ ": ERROR: PrivateDriverDataSize(%d) less than cmd size(%d)\n", pAllocationInfo->PrivateDriverDataSize, VBOXWDDM_ALLOCINFO_HEADSIZE()));
    1628                     Status = STATUS_INVALID_PARAMETER;
    1629                 }
    1630                 break;
    1631             }
    1632             default:
    1633                 drprintf((__FUNCTION__ ": ERROR: invalid alloc info type(%d)\n", pAllocInfo->enmType));
    1634                 Status = STATUS_INVALID_PARAMETER;
    1635                 break;
    1636         }
     1465                    break;
     1466            }
     1467
     1468            if (Status != STATUS_SUCCESS)
     1469                vboxWddmMemFree(pAllocation);
     1470        }
     1471        else
     1472        {
     1473            drprintf((__FUNCTION__ ": ERROR: failed to create allocation description\n"));
     1474            Status = STATUS_NO_MEMORY;
     1475        }
     1476
    16371477    }
    16381478    else
    16391479    {
    1640         drprintf((__FUNCTION__ ": ERROR: PrivateDriverDataSize(%d) less than header size(%d)\n", pAllocationInfo->PrivateDriverDataSize, VBOXWDDM_ALLOCINFO_HEADSIZE()));
     1480        drprintf((__FUNCTION__ ": ERROR: PrivateDriverDataSize(%d) less than header size(%d)\n", pAllocationInfo->PrivateDriverDataSize, sizeof (VBOXWDDM_ALLOCINFO)));
    16411481        Status = STATUS_INVALID_PARAMETER;
    16421482    }
     
    16581498    NTSTATUS Status = STATUS_SUCCESS;
    16591499
     1500    if (pCreateAllocation->PrivateDriverDataSize)
     1501    {
     1502        /* @todo: Implement Resource Data Handling */
     1503        drprintf((__FUNCTION__ ": WARNING: Implement Resource Data Handling\n"));
     1504    }
     1505
    16601506    for (UINT i = 0; i < pCreateAllocation->NumAllocations; ++i)
    16611507    {
     
    17171563
    17181564    PVBOXWDDM_ALLOCATION pAllocation = (PVBOXWDDM_ALLOCATION)pDescribeAllocation->hAllocation;
    1719     pDescribeAllocation->Width = pAllocation->u.SurfInfo.width;
    1720     pDescribeAllocation->Height = pAllocation->u.SurfInfo.height;
    1721     pDescribeAllocation->Format = pAllocation->u.SurfInfo.format;
     1565    pDescribeAllocation->Width = pAllocation->SurfDesc.width;
     1566    pDescribeAllocation->Height = pAllocation->SurfDesc.height;
     1567    pDescribeAllocation->Format = pAllocation->SurfDesc.format;
    17221568    memset (&pDescribeAllocation->MultisampleMethod, 0, sizeof (pDescribeAllocation->MultisampleMethod));
    17231569    pDescribeAllocation->RefreshRate.Numerator = 60000;
     
    17571603            {
    17581604                pAllocInfo = (PVBOXWDDM_ALLOCINFO)pGetStandardAllocationDriverData->pAllocationPrivateDriverData;
     1605                memset (pAllocInfo, 0, sizeof (VBOXWDDM_ALLOCINFO));
    17591606                pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE;
    1760                 pAllocInfo->u.SurfInfo.width = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Width;
    1761                 pAllocInfo->u.SurfInfo.height = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Height;
    1762                 pAllocInfo->u.SurfInfo.format = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Format;
    1763                 pAllocInfo->u.SurfInfo.bpp = vboxWddmCalcBitsPerPixel(pAllocInfo->u.SurfInfo.format);
    1764                 pAllocInfo->u.SurfInfo.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Width, pAllocInfo->u.SurfInfo.bpp);
    1765                 PVBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE pInfo = VBOXWDDM_ALLOCINFO_BODY(pAllocInfo, VBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE);
    1766                 pInfo->RefreshRate = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->RefreshRate;
    1767                 pInfo->VidPnSourceId = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->VidPnSourceId;
    1768             }
    1769             pGetStandardAllocationDriverData->AllocationPrivateDriverDataSize = VBOXWDDM_ALLOCINFO_SIZE(VBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE);
     1607                pAllocInfo->SurfDesc.width = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Width;
     1608                pAllocInfo->SurfDesc.height = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Height;
     1609                pAllocInfo->SurfDesc.format = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Format;
     1610                pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pAllocInfo->SurfDesc.format);
     1611                pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Width, pAllocInfo->SurfDesc.bpp);
     1612                pAllocInfo->SurfDesc.depth = 0;
     1613                pAllocInfo->SurfDesc.slicePitch = 0;
     1614                pAllocInfo->SurfDesc.RefreshRate = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->RefreshRate;
     1615                pAllocInfo->SurfDesc.VidPnSourceId = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->VidPnSourceId;
     1616            }
     1617            pGetStandardAllocationDriverData->AllocationPrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO);
    17701618
    17711619            pGetStandardAllocationDriverData->ResourcePrivateDriverDataSize = 0;
     
    17881636                    pAllocInfo = (PVBOXWDDM_ALLOCINFO)pGetStandardAllocationDriverData->pAllocationPrivateDriverData;
    17891637                    pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE;
    1790                     pAllocInfo->u.SurfInfo.width = pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Width;
    1791                     pAllocInfo->u.SurfInfo.height = pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Height;
    1792                     pAllocInfo->u.SurfInfo.format = pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Format;
    1793                     pAllocInfo->u.SurfInfo.bpp = vboxWddmCalcBitsPerPixel(pAllocInfo->u.SurfInfo.format);
    1794                     pAllocInfo->u.SurfInfo.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Width, pAllocInfo->u.SurfInfo.bpp);
    1795 
    1796                     pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Pitch = pAllocInfo->u.SurfInfo.pitch;
     1638                    pAllocInfo->SurfDesc.width = pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Width;
     1639                    pAllocInfo->SurfDesc.height = pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Height;
     1640                    pAllocInfo->SurfDesc.format = pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Format;
     1641                    pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pAllocInfo->SurfDesc.format);
     1642                    pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Width, pAllocInfo->SurfDesc.bpp);
     1643                    pAllocInfo->SurfDesc.depth = 0;
     1644                    pAllocInfo->SurfDesc.slicePitch = 0;
     1645                    pAllocInfo->SurfDesc.RefreshRate.Numerator = 0;
     1646                    pAllocInfo->SurfDesc.RefreshRate.Denominator = 1000;
     1647                    pAllocInfo->SurfDesc.VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
     1648
     1649                    pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Pitch = pAllocInfo->SurfDesc.pitch;
    17971650                }
    1798                 pGetStandardAllocationDriverData->AllocationPrivateDriverDataSize = VBOXWDDM_ALLOCINFO_HEADSIZE();
     1651                pGetStandardAllocationDriverData->AllocationPrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO);
    17991652
    18001653                pGetStandardAllocationDriverData->ResourcePrivateDriverDataSize = 0;
     
    18141667                pAllocInfo = (PVBOXWDDM_ALLOCINFO)pGetStandardAllocationDriverData->pAllocationPrivateDriverData;
    18151668                pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE;
    1816                 pAllocInfo->u.SurfInfo.width = pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Width;
    1817                 pAllocInfo->u.SurfInfo.height = pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Height;
    1818                 pAllocInfo->u.SurfInfo.format = D3DDDIFMT_X8R8G8B8; /* staging has always always D3DDDIFMT_X8R8G8B8 */
    1819                 pAllocInfo->u.SurfInfo.bpp = vboxWddmCalcBitsPerPixel(pAllocInfo->u.SurfInfo.format);
    1820                 pAllocInfo->u.SurfInfo.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Width, pAllocInfo->u.SurfInfo.bpp);
    1821 
    1822                 pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Pitch = pAllocInfo->u.SurfInfo.pitch;
    1823             }
    1824             pGetStandardAllocationDriverData->AllocationPrivateDriverDataSize = VBOXWDDM_ALLOCINFO_HEADSIZE();
     1669                pAllocInfo->SurfDesc.width = pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Width;
     1670                pAllocInfo->SurfDesc.height = pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Height;
     1671                pAllocInfo->SurfDesc.format = D3DDDIFMT_X8R8G8B8; /* staging has always always D3DDDIFMT_X8R8G8B8 */
     1672                pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pAllocInfo->SurfDesc.format);
     1673                pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Width, pAllocInfo->SurfDesc.bpp);
     1674                pAllocInfo->SurfDesc.depth = 0;
     1675                pAllocInfo->SurfDesc.slicePitch = 0;
     1676                pAllocInfo->SurfDesc.RefreshRate.Numerator = 0;
     1677                pAllocInfo->SurfDesc.RefreshRate.Denominator = 1000;
     1678                pAllocInfo->SurfDesc.VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
     1679
     1680                pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Pitch = pAllocInfo->SurfDesc.pitch;
     1681            }
     1682            pGetStandardAllocationDriverData->AllocationPrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO);
    18251683
    18261684            pGetStandardAllocationDriverData->ResourcePrivateDriverDataSize = 0;
     
    29292787        {
    29302788            Assert(pAllocation->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE);
    2931             PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimary = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    29322789            pAllocation->offVram = (VBOXVIDEOOFFSET)pSetVidPnSourceAddress->PrimaryAddress.QuadPart;
    29332790            pAllocation->SegmentId = pSetVidPnSourceAddress->PrimarySegment;
    29342791            Assert (pAllocation->SegmentId);
    2935             Assert (!pPrimary->bVisible);
     2792            Assert (!pAllocation->bVisible);
    29362793#ifndef VBOXWDDM_RENDER_FROM_SHADOW
    2937             if (pPrimary->bVisible)
     2794            if (pAllocation->bVisible)
    29382795            {
    29392796                /* should not generally happen, but still inform host*/
     
    29832840        PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pSetVidPnSourceVisibility->VidPnSourceId];
    29842841        PVBOXWDDM_ALLOCATION pAllocation = pSource->pPrimaryAllocation;
    2985         PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimary = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    2986 
    2987         Assert(pPrimary->bVisible != pSetVidPnSourceVisibility->Visible);
    2988         if (pPrimary->bVisible != pSetVidPnSourceVisibility->Visible)
    2989         {
    2990             pPrimary->bVisible = pSetVidPnSourceVisibility->Visible;
     2842
     2843        Assert(pAllocation->bVisible != pSetVidPnSourceVisibility->Visible);
     2844        if (pAllocation->bVisible != pSetVidPnSourceVisibility->Visible)
     2845        {
     2846            pAllocation->bVisible = pSetVidPnSourceVisibility->Visible;
    29912847#ifndef VBOXWDDM_RENDER_FROM_SHADOW
    2992             if (pPrimary->bVisible)
     2848            if (pAllocation->bVisible)
    29932849            {
    29942850                Status = vboxWddmGhDisplaySetInfo(pDevExt, pSource);
     
    33683224DECLINLINE(VOID) vboxWddmSurfDescFromAllocation(PVBOXWDDM_ALLOCATION pAllocation, PVBOXVDMA_SURF_DESC pDesc)
    33693225{
    3370     pDesc->width = pAllocation->u.SurfInfo.width;
    3371     pDesc->height = pAllocation->u.SurfInfo.height;
    3372     pDesc->format = vboxWddmFromPixFormat(pAllocation->u.SurfInfo.format);
    3373     pDesc->bpp = pAllocation->u.SurfInfo.bpp;
    3374     pDesc->pitch = pAllocation->u.SurfInfo.pitch;
     3226    pDesc->width = pAllocation->SurfDesc.width;
     3227    pDesc->height = pAllocation->SurfDesc.height;
     3228    pDesc->format = vboxWddmFromPixFormat(pAllocation->SurfDesc.format);
     3229    pDesc->bpp = pAllocation->SurfDesc.bpp;
     3230    pDesc->pitch = pAllocation->SurfDesc.pitch;
    33753231    pDesc->fFlags = 0;
    33763232}
     
    33843240}
    33853241
    3386 DECLINLINE(PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE) vboxWddmCheckForVisiblePrimary(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_ALLOCATION pAllocation)
     3242DECLINLINE(bool) vboxWddmCheckForVisiblePrimary(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_ALLOCATION pAllocation)
    33873243{
    33883244    if (pAllocation->enmType != VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE)
    3389         return NULL;
    3390 
    3391     PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimary = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    3392     if (!pPrimary->bVisible)
    3393         return NULL;
    3394 
    3395     D3DDDI_VIDEO_PRESENT_SOURCE_ID id = pPrimary->VidPnSourceId;
     3245        return false;
     3246
     3247    if (!pAllocation->bVisible)
     3248        return false;
     3249
     3250    D3DDDI_VIDEO_PRESENT_SOURCE_ID id = pAllocation->SurfDesc.VidPnSourceId;
    33963251    if (id >=  pDevExt->cSources)
    3397         return NULL;
     3252        return false;
    33983253
    33993254    PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[id];
    34003255    if (pSource->pPrimaryAllocation != pAllocation)
    3401         return NULL;
    3402 
    3403     return pPrimary;
     3256        return false;
     3257
     3258    return true;
    34043259}
    34053260
     
    34563311                            && pSrcAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE)
    34573312                    {
    3458                         PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pDstAlloc, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
    3459                         Assert(pPrimaryInfo->bAssigned);
    3460                         Assert(pPrimaryInfo->bVisible);
    3461                         if (pPrimaryInfo->bAssigned
    3462                                 && pPrimaryInfo->bVisible)
     3313                        Assert(pDstAlloc->bAssigned);
     3314                        Assert(pDstAlloc->bVisible);
     3315                        if (pDstAlloc->bAssigned
     3316                                && pDstAlloc->bVisible)
    34633317                        {
    3464                             VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pPrimaryInfo->VidPnSourceId];
    3465                             vboxWddmAssignShadow(pDevExt, pSource, pSrcAlloc, pPrimaryInfo->VidPnSourceId);
     3318                            VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
     3319                            vboxWddmAssignShadow(pDevExt, pSource, pSrcAlloc, pDstAlloc->SurfDesc.VidPnSourceId);
    34663320                            Assert(pPresent->SrcRect.left == pPresent->DstRect.left);
    34673321                            Assert(pPresent->SrcRect.right == pPresent->DstRect.right);
     
    35073361                                    /* we do not know the shadow address yet, perform dummy DMA cycle */
    35083362                                    pPrivateData->rect = rect;
    3509                                     pPrivateData->srcId = pPrimaryInfo->VidPnSourceId;
     3363                                    pPrivateData->srcId = pDstAlloc->SurfDesc.VidPnSourceId;
    35103364                                    pPrivateData->enmCmd = VBOXVDMACMD_TYPE_DMA_PRESENT_SHADOW2PRIMARY;
    35113365                                    if (pSrc->SegmentId)
     
    35373391                    if (cbCmd >= VBOXVDMACMD_DMA_PRESENT_BLT_MINSIZE())
    35383392                    {
    3539                         if (vboxWddmPixFormatConversionSupported(pSrcAlloc->u.SurfInfo.format, pDstAlloc->u.SurfInfo.format))
     3393                        if (vboxWddmPixFormatConversionSupported(pSrcAlloc->SurfDesc.format, pDstAlloc->SurfDesc.format))
    35403394                        {
    35413395                            memset(pPresent->pPatchLocationListOut, 0, 2*sizeof (D3DDDI_PATCHLOCATIONLIST));
     
    35823436                        {
    35833437                            AssertBreakpoint();
    3584                             drprintf((__FUNCTION__": unsupported format conversion from(%d) to (%d)\n",pSrcAlloc->u.SurfInfo.format, pDstAlloc->u.SurfInfo.format));
     3438                            drprintf((__FUNCTION__": unsupported format conversion from(%d) to (%d)\n",pSrcAlloc->SurfDesc.format, pDstAlloc->SurfDesc.format));
    35853439                            Status = STATUS_GRAPHICS_CANNOTCOLORCONVERT;
    35863440                        }
     
    36263480                if (pDstAlloc)
    36273481                {
    3628                     if (vboxWddmPixFormatConversionSupported(pSrcAlloc->u.SurfInfo.format, pDstAlloc->u.SurfInfo.format))
     3482                    if (vboxWddmPixFormatConversionSupported(pSrcAlloc->SurfDesc.format, pDstAlloc->SurfDesc.format))
    36293483                    {
    36303484                        memset(pPresent->pPatchLocationListOut, 0, 2*sizeof (D3DDDI_PATCHLOCATIONLIST));
     
    36703524                    {
    36713525                        AssertBreakpoint();
    3672                         drprintf((__FUNCTION__": unsupported format conversion from(%d) to (%d)\n",pSrcAlloc->u.SurfInfo.format, pDstAlloc->u.SurfInfo.format));
     3526                        drprintf((__FUNCTION__": unsupported format conversion from(%d) to (%d)\n",pSrcAlloc->SurfDesc.format, pDstAlloc->SurfDesc.format));
    36733527                        Status = STATUS_GRAPHICS_CANNOTCOLORCONVERT;
    36743528                    }
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.h

    r29710 r29883  
    4444#endif
    4545
    46 #define VBOXWDDM_ROUNDBOUND(_v, _b) (((_v) + ((_b) - 1)) & ~((_b) - 1))
    47 
    4846PVOID vboxWddmMemAlloc(IN SIZE_T cbSize);
    4947PVOID vboxWddmMemAllocZero(IN SIZE_T cbSize);
    5048VOID vboxWddmMemFree(PVOID pvMem);
    51 
    52 typedef struct VBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE
    53 {
    54     D3DDDI_RATIONAL                 RefreshRate;
    55     D3DDDI_VIDEO_PRESENT_SOURCE_ID  VidPnSourceId;
    56 } VBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE, *PVBOXWDDM_ALLOCINFO_SHAREDPRIMARYSURFACE;
    5749
    5850/* allocation */
     
    6254    UINT SegmentId;
    6355    VBOXVIDEOOFFSET offVram;
    64     union
    65     {
    66         VBOXWDDM_SURFACE_DESC SurfInfo;
    67     } u;
     56    BOOLEAN bVisible;
     57    BOOLEAN bAssigned;
     58    VBOXWDDM_SURFACE_DESC SurfDesc;
    6859} VBOXWDDM_ALLOCATION, *PVBOXWDDM_ALLOCATION;
    6960
    70 #define VBOXWDDM_ALLOCATION_HEADSIZE() (sizeof (VBOXWDDM_ALLOCATION))
    71 #define VBOXWDDM_ALLOCATION_SIZE_FROMBODYSIZE(_s) (VBOXWDDM_ALLOCATION_HEADSIZE() + (_s))
    72 #define VBOXWDDM_ALLOCATION_SIZE(_tCmd) (VBOXWDDM_ALLOCATION_SIZE_FROMBODYSIZE(sizeof(_tCmd)))
    73 #define VBOXWDDM_ALLOCATION_BODY(_p, _t) ( (_t*)(((uint8_t*)(_p)) + VBOXWDDM_ALLOCATION_HEADSIZE()) )
    74 #define VBOXWDDM_ALLOCATION_HEAD(_pb) ((VBOXWDDM_ALLOCATION*)((uint8_t *)(_pb) - VBOXWDDM_ALLOCATION_HEADSIZE()))
    75 
    76 
    77 typedef struct VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE
     61typedef struct VBOXWDDM_RESOURCE
    7862{
     63    VBOXWDDM_ALLOC_TYPE enmType;
     64    UINT SegmentId;
     65    VBOXVIDEOOFFSET offVram;
    7966    D3DDDI_RATIONAL RefreshRate;
    8067    D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
    81 //    VBOXVIDEOOFFSET offAddress;
    8268    BOOLEAN bVisible;
    8369    BOOLEAN bAssigned;
    84 } VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE, *PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE;
     70    VBOXWDDM_SURFACE_DESC SurfDesc;
     71    uint32_t cAllocations;
     72} VBOXWDDM_RESOURCE, *PVBOXWDDM_RESOURCE;
    8573
    86 #ifdef VBOXWDDM_RENDER_FROM_SHADOW
    87 typedef struct VBOXWDDM_ALLOCATION_SHADOWSURFACE
    88 {
    89     D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
    90 //    VBOXVIDEOOFFSET offAddress;
    91     BOOLEAN bVisible;
    92     BOOLEAN bAssigned;
    93 } VBOXWDDM_ALLOCATION_SHADOWSURFACE, *PVBOXWDDM_ALLOCATION_SHADOWSURFACE;
    94 #endif
    9574
    9675typedef enum
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