Changeset 39245 in vbox for trunk/src/VBox
- Timestamp:
- Nov 8, 2011 4:46:46 PM (13 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Video
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h
r39160 r39245 483 483 484 484 /* tooling */ 485 DECLINLINE(UINT) vboxWddmCalcBitsPerPixel(D3DDDIFORMAT format)486 { 487 switch ( format)485 DECLINLINE(UINT) vboxWddmCalcBitsPerPixel(D3DDDIFORMAT enmFormat) 486 { 487 switch (enmFormat) 488 488 { 489 489 case D3DDDIFMT_R8G8B8: … … 563 563 } 564 564 565 DECLINLINE(uint32_t) vboxWddmFormatToFourcc(D3DDDIFORMAT format)566 { 567 uint32_t uFormat = (uint32_t) format;565 DECLINLINE(uint32_t) vboxWddmFormatToFourcc(D3DDDIFORMAT enmFormat) 566 { 567 uint32_t uFormat = (uint32_t)enmFormat; 568 568 /* assume that in case both four bytes are non-zero, this is a fourcc */ 569 if (( format & 0xff000000)570 && ( format & 0x00ff0000)571 && ( format & 0x0000ff00)572 && ( format & 0x000000ff)569 if ((uFormat & 0xff000000) 570 && (uFormat & 0x00ff0000) 571 && (uFormat & 0x0000ff00) 572 && (uFormat & 0x000000ff) 573 573 ) 574 574 return uFormat; … … 578 578 #define VBOXWDDM_ROUNDBOUND(_v, _b) (((_v) + ((_b) - 1)) & ~((_b) - 1)) 579 579 580 DECLINLINE(UINT) vboxWddmCalcPitch(UINT w, UINT bitsPerPixel) 581 { 582 UINT Pitch = bitsPerPixel * w; 583 /* pitch is now in bits, translate in bytes */ 584 return VBOXWDDM_ROUNDBOUND(Pitch, 8) >> 3; 580 DECLINLINE(UINT) vboxWddmCalcOffXru(UINT w, D3DDDIFORMAT enmFormat) 581 { 582 switch (enmFormat) 583 { 584 /* pitch for the DXT* (aka compressed) formats is the size in bytes of blocks that fill in an image width 585 * i.e. each block decompressed into 4 x 4 pixels, so we have ((Width + 3) / 4) blocks for Width. 586 * then each block has 64 bits (8 bytes) for DXT1 and 64+64 bits (16 bytes) for DXT2-DXT5, so.. : */ 587 case D3DDDIFMT_DXT1: 588 { 589 UINT Pitch = (w + 3) / 4; /* <- pitch size in blocks */ 590 Pitch *= 8; /* <- pitch size in bytes */ 591 return Pitch; 592 } 593 case D3DDDIFMT_DXT2: 594 case D3DDDIFMT_DXT3: 595 case D3DDDIFMT_DXT4: 596 case D3DDDIFMT_DXT5: 597 { 598 UINT Pitch = (w + 3) / 4; /* <- pitch size in blocks */ 599 Pitch *= 8; /* <- pitch size in bytes */ 600 return Pitch; 601 } 602 default: 603 { 604 /* the default is just to calculate the pitch from bpp */ 605 UINT bpp = vboxWddmCalcBitsPerPixel(enmFormat); 606 UINT Pitch = bpp * w; 607 /* pitch is now in bits, translate in bytes */ 608 return VBOXWDDM_ROUNDBOUND(Pitch, 8) >> 3; 609 } 610 } 611 } 612 613 DECLINLINE(UINT) vboxWddmCalcOffXrd(UINT w, D3DDDIFORMAT enmFormat) 614 { 615 switch (enmFormat) 616 { 617 /* pitch for the DXT* (aka compressed) formats is the size in bytes of blocks that fill in an image width 618 * i.e. each block decompressed into 4 x 4 pixels, so we have ((Width + 3) / 4) blocks for Width. 619 * then each block has 64 bits (8 bytes) for DXT1 and 64+64 bits (16 bytes) for DXT2-DXT5, so.. : */ 620 case D3DDDIFMT_DXT1: 621 { 622 UINT Pitch = w / 4; /* <- pitch size in blocks */ 623 Pitch *= 8; /* <- pitch size in bytes */ 624 return Pitch; 625 } 626 case D3DDDIFMT_DXT2: 627 case D3DDDIFMT_DXT3: 628 case D3DDDIFMT_DXT4: 629 case D3DDDIFMT_DXT5: 630 { 631 UINT Pitch = w / 4; /* <- pitch size in blocks */ 632 Pitch *= 16; /* <- pitch size in bytes */ 633 return Pitch; 634 } 635 default: 636 { 637 /* the default is just to calculate the pitch from bpp */ 638 UINT bpp = vboxWddmCalcBitsPerPixel(enmFormat); 639 UINT Pitch = bpp * w; 640 /* pitch is now in bits, translate in bytes */ 641 return Pitch >> 3; 642 } 643 } 644 } 645 646 DECLINLINE(UINT) vboxWddmCalcHightPacking(D3DDDIFORMAT enmFormat) 647 { 648 switch (enmFormat) 649 { 650 /* for the DXT* (aka compressed) formats each block is decompressed into 4 x 4 pixels, 651 * so packing is 4 652 */ 653 case D3DDDIFMT_DXT1: 654 case D3DDDIFMT_DXT2: 655 case D3DDDIFMT_DXT3: 656 case D3DDDIFMT_DXT4: 657 case D3DDDIFMT_DXT5: 658 return 4; 659 default: 660 return 1; 661 } 662 } 663 664 DECLINLINE(UINT) vboxWddmCalcOffYru(UINT height, D3DDDIFORMAT enmFormat) 665 { 666 UINT packing = vboxWddmCalcHightPacking(enmFormat); 667 /* round it up */ 668 return (height + packing - 1) / packing; 669 } 670 671 DECLINLINE(UINT) vboxWddmCalcOffYrd(UINT height, D3DDDIFORMAT enmFormat) 672 { 673 UINT packing = vboxWddmCalcHightPacking(enmFormat); 674 /* round it up */ 675 return height / packing; 676 } 677 678 DECLINLINE(UINT) vboxWddmCalcPitch(UINT w, D3DDDIFORMAT enmFormat) 679 { 680 return vboxWddmCalcOffXru(w, enmFormat); 681 } 682 683 DECLINLINE(UINT) vboxWddmCalcWidthForPitch(UINT Pitch, D3DDDIFORMAT enmFormat) 684 { 685 switch (enmFormat) 686 { 687 /* pitch for the DXT* (aka compressed) formats is the size in bytes of blocks that fill in an image width 688 * i.e. each block decompressed into 4 x 4 pixels, so we have ((Width + 3) / 4) blocks for Width. 689 * then each block has 64 bits (8 bytes) for DXT1 and 64+64 bits (16 bytes) for DXT2-DXT5, so.. : */ 690 case D3DDDIFMT_DXT1: 691 { 692 return (Pitch / 8) * 4; 693 } 694 case D3DDDIFMT_DXT2: 695 case D3DDDIFMT_DXT3: 696 case D3DDDIFMT_DXT4: 697 case D3DDDIFMT_DXT5: 698 { 699 return (Pitch / 16) * 4;; 700 } 701 default: 702 { 703 /* the default is just to calculate it from bpp */ 704 UINT bpp = vboxWddmCalcBitsPerPixel(enmFormat); 705 return (Pitch << 3) / bpp; 706 } 707 } 708 } 709 710 DECLINLINE(UINT) vboxWddmCalcNumRows(UINT top, UINT bottom, D3DDDIFORMAT enmFormat) 711 { 712 Assert(bottom > top); 713 top = top ? vboxWddmCalcOffYrd(top, enmFormat) : 0; /* <- just to optimize it a bit */ 714 bottom = vboxWddmCalcOffYru(bottom, enmFormat); 715 return bottom - top; 716 } 717 718 DECLINLINE(UINT) vboxWddmCalcRowSize(UINT left, UINT right, D3DDDIFORMAT enmFormat) 719 { 720 Assert(right > left); 721 left = left ? vboxWddmCalcOffXrd(left, enmFormat) : 0; /* <- just to optimize it a bit */ 722 right = vboxWddmCalcOffXru(right, enmFormat); 723 return right - left; 724 } 725 726 DECLINLINE(UINT) vboxWddmCalcSize(UINT pitch, UINT height, D3DDDIFORMAT enmFormat) 727 { 728 UINT cRows = vboxWddmCalcNumRows(0, height, enmFormat); 729 return pitch * cRows; 730 } 731 732 DECLINLINE(UINT) vboxWddmCalcOffXYrd(UINT x, UINT y, UINT pitch, D3DDDIFORMAT enmFormat) 733 { 734 UINT offY = 0; 735 if (y) 736 offY = vboxWddmCalcSize(pitch, y, enmFormat); 737 738 return offY + vboxWddmCalcOffXrd(x, enmFormat); 585 739 } 586 740 -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
r39160 r39245 1322 1322 if (pAlloc->SurfDesc.pitch == pLockInfo->Pitch) 1323 1323 { 1324 Assert(pAlloc->SurfDesc.cbSize); 1324 1325 if (bToLockInfo) 1325 memcpy(pLockInfo->pBits, pAlloc->pvMem, pAlloc->SurfDesc. pitch * pAlloc->SurfDesc.height);1326 memcpy(pLockInfo->pBits, pAlloc->pvMem, pAlloc->SurfDesc.cbSize); 1326 1327 else 1327 memcpy(pAlloc->pvMem, pLockInfo->pBits, pAlloc->SurfDesc. pitch * pAlloc->SurfDesc.height);1328 memcpy(pAlloc->pvMem, pLockInfo->pBits, pAlloc->SurfDesc.cbSize); 1328 1329 } 1329 1330 else … … 1346 1347 } 1347 1348 1349 uint32_t cRows = vboxWddmCalcNumRows(0, pAlloc->SurfDesc.height, pAlloc->SurfDesc.format); 1348 1350 uint32_t pitch = RT_MIN(srcPitch, dstPitch); 1349 1351 Assert(pitch); 1350 for (UINT j = 0; j < pAlloc->SurfDesc.height; ++j)1352 for (UINT j = 0; j < cRows; ++j) 1351 1353 { 1352 1354 memcpy(pvDst, pvSrc, pitch); … … 1360 1362 uint8_t *pvSrc, *pvDst; 1361 1363 uint32_t srcPitch, dstPitch; 1362 /* @todo: this is not entirely correct */1363 1364 uint8_t * pvAllocMemStart = (uint8_t *)pAlloc->pvMem; 1364 uint32_t cbPP = pAlloc->SurfDesc.pitch/pAlloc->SurfDesc.width;1365 pvAllocMemStart += pAlloc->SurfDesc.pitch * pRect->top + pRect->left * cbPP;1365 uint32_t offAllocMemStart = vboxWddmCalcOffXYrd(pRect->top, pRect->left, pAlloc->SurfDesc.pitch, pAlloc->SurfDesc.format); 1366 pvAllocMemStart += offAllocMemStart; 1366 1367 1367 1368 if (bToLockInfo) … … 1380 1381 } 1381 1382 1382 uint32_t cPixCopyLine = pRect->right - pRect->left; 1383 1384 if (cPixCopyLine == pAlloc->SurfDesc.width && srcPitch == dstPitch) 1385 { 1386 memcpy(pvDst, pvSrc, pAlloc->SurfDesc.pitch * (pRect->bottom - pRect->top)); 1383 if (pRect->right - pRect->left == pAlloc->SurfDesc.width && srcPitch == dstPitch) 1384 { 1385 uint32_t cbSize = vboxWddmCalcSize(pAlloc->SurfDesc.pitch, pRect->bottom - pRect->top, pAlloc->SurfDesc.format); 1386 memcpy(pvDst, pvSrc, cbSize); 1387 1387 } 1388 1388 else 1389 1389 { 1390 1390 uint32_t pitch = RT_MIN(srcPitch, dstPitch); 1391 uint32_t cbCopyLine = cPixCopyLine * cbPP;1391 uint32_t cbCopyLine = vboxWddmCalcRowSize(pRect->left, pRect->right, pAlloc->SurfDesc.format); 1392 1392 Assert(pitch); 1393 for (int j = pRect->top; j < pRect->bottom; ++j) 1393 uint32_t cRows = vboxWddmCalcNumRows(pRect->top, pRect->bottom, pAlloc->SurfDesc.format); 1394 for (UINT j = 0; j < cRows; ++j) 1394 1395 { 1395 1396 memcpy(pvDst, pvSrc, cbCopyLine); … … 1399 1400 } 1400 1401 } 1401 }1402 1403 #if 01404 static HRESULT vboxWddmRectBltPerform(uint8_t *pvDstSurf, const uint8_t *pvSrcSurf,1405 RECT *pDstRect, RECT *pSrcRect,1406 uint32_t DstPitch, uint32_t SrcPitch, uint32_t bpp,1407 RECT *pDstCopyRect, RECT *pSrcCopyRect)1408 {1409 uint32_t DstCopyWidth = pDstCopyRect->left - pDstCopyRect->right;1410 uint32_t DstCopyHeight = pDstCopyRect->bottom - pDstCopyRect->top;1411 uint32_t SrcCopyWidth = pSrcCopyRect->left - pSrcCopyRect->right;1412 uint32_t SrcCopyHeight = pSrcCopyRect->bottom - pSrcCopyRect->top;1413 uint32_t srcBpp = bpp;1414 uint32_t dstBpp = bpp;1415 /* we do not support stretching */1416 Assert(DstCopyWidth == SrcCopyWidth);1417 Assert(DstCopyHeight == SrcCopyWidth);1418 if (DstCopyWidth != SrcCopyWidth)1419 return E_FAIL;1420 if (DstCopyHeight != SrcCopyWidth)1421 return E_FAIL;1422 1423 uint32_t DstWidth = pDstRect->left - pDstRect->right;1424 uint32_t DstHeight = pDstRect->bottom - pDstRect->top;1425 uint32_t SrcWidth = pSrcRect->left - pSrcRect->right;1426 uint32_t SrcHeight = pSrcRect->bottom - pSrcRect->top;1427 1428 if (DstWidth == DstCopyWidth1429 && SrcWidth == SrcCopyWidth1430 && SrcWidth == DstWidth)1431 {1432 Assert(!pDstCopyRect->left);1433 Assert(!pSrcCopyRect->left);1434 uint32_t cbOff = DstPitch * pDstCopyRect->top;1435 uint32_t cbSize = DstPitch * DstCopyHeight;1436 memcpy(pvDstSurf + cbOff, pvSrcSurf + cbOff, cbSize);1437 }1438 else1439 {1440 uint32_t offDstLineStart = pDstCopyRect->left * dstBpp >> 3;1441 uint32_t offDstLineEnd = ((pDstCopyRect->left * dstBpp + 7) >> 3) + ((dstBpp * DstCopyWidth + 7) >> 3);1442 uint32_t cbDstLine = offDstLineEnd - offDstLineStart;1443 uint32_t offDstStart = DstPitch * pDstCopyRect->top + offDstLineStart;1444 Assert(cbDstLine <= DstPitch);1445 uint32_t cbDstSkip = DstPitch;1446 uint8_t * pvDstStart = pvDstSurf + offDstStart;1447 1448 uint32_t offSrcLineStart = pSrcCopyRect->left * srcBpp >> 3;1449 uint32_t offSrcLineEnd = ((pSrcCopyRect->left * srcBpp + 7) >> 3) + ((srcBpp * SrcCopyWidth + 7) >> 3);1450 uint32_t cbSrcLine = offSrcLineEnd - offSrcLineStart;1451 uint32_t offSrcStart = SrcPitch * pSrcCopyRect->top + offSrcLineStart;1452 Assert(cbSrcLine <= SrcPitch);1453 uint32_t cbSrcSkip = SrcPitch;1454 const uint8_t * pvSrcStart = pvSrcSurf + offSrcStart;1455 1456 Assert(cbDstLine == cbSrcLine);1457 1458 for (uint32_t i = 0; ; ++i)1459 {1460 memcpy (pvDstStart, pvSrcStart, cbDstLine);1461 if (i == DstCopyHeight)1462 break;1463 pvDstStart += cbDstSkip;1464 pvSrcStart += cbSrcSkip;1465 }1466 }1467 return S_OK;1468 }1469 #endif1470 1471 static HRESULT vboxWddmRectBltPerform(uint8_t *pvDstSurf, const uint8_t *pvSrcSurf,1472 const RECT *pDstRect, const RECT *pSrcRect,1473 uint32_t DstPitch, uint32_t SrcPitch, uint32_t bpp)1474 {1475 uint32_t DstWidth = pDstRect->left - pDstRect->right;1476 uint32_t DstHeight = pDstRect->bottom - pDstRect->top;1477 uint32_t SrcWidth = pSrcRect->left - pSrcRect->right;1478 uint32_t SrcHeight = pSrcRect->bottom - pSrcRect->top;1479 uint32_t srcBpp = bpp;1480 uint32_t dstBpp = bpp;1481 /* we do not support stretching */1482 Assert(DstWidth == SrcWidth);1483 Assert(DstHeight == SrcWidth);1484 if (DstWidth != SrcWidth)1485 return E_FAIL;1486 if (DstHeight != SrcWidth)1487 return E_FAIL;1488 1489 if (DstPitch == SrcPitch1490 && ((DstWidth * bpp)/8) == DstPitch)1491 {1492 Assert(!pDstRect->left);1493 Assert(!pSrcRect->left);1494 uint32_t cbOff = DstPitch * pDstRect->top;1495 uint32_t cbSize = DstPitch * DstHeight;1496 memcpy(pvDstSurf + cbOff, pvSrcSurf + cbOff, cbSize);1497 }1498 else1499 {1500 1501 uint32_t cbDstLine = (((DstWidth * dstBpp) + 7) >> 3);1502 for (uint32_t i = 0; ; ++i)1503 {1504 memcpy (pvDstSurf, pvSrcSurf, cbDstLine);1505 if (i == DstHeight)1506 break;1507 pvDstSurf += DstPitch;1508 pvSrcSurf += SrcPitch;1509 }1510 }1511 return S_OK;1512 1402 } 1513 1403 … … 1631 1521 } 1632 1522 1633 static HRESULT vboxWddmMemsetAlloc(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc, char c)1634 {1635 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[iAlloc];1636 IDirect3DSurface9 *pD3D9Surf = NULL;1637 HRESULT hr = vboxWddmSurfGet(pRc, iAlloc, &pD3D9Surf);1638 if (SUCCEEDED(hr))1639 {1640 PVBOXWDDMDISP_DEVICE pDevice = pRc->pDevice;1641 hr = pRc->pDevice->pDevice9If->ColorFill(pD3D9Surf, NULL, D3DCOLOR_ARGB(c,c,c,c));1642 pD3D9Surf->Release();1643 if (SUCCEEDED(hr))1644 {1645 return hr;1646 }1647 1648 WARN(("ColorFill failed, hr 0x%x", hr));1649 /* fallback to lock-memset-unlock */1650 }1651 1652 /* unless this is a fallback */1653 Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_VERTEXBUFFER1654 || pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_INDEXBUFFER);1655 1656 D3DLOCKED_RECT Rect;1657 hr = vboxWddmLockRect(pRc, iAlloc, &Rect, NULL, D3DLOCK_DISCARD);1658 if (FAILED(hr))1659 {1660 WARN(("vboxWddmLockRect failed, hr(0x%x)", hr));1661 return hr;1662 }1663 1664 UINT cbAllocPitch = pAlloc->SurfDesc.pitch;1665 if(Rect.Pitch == cbAllocPitch)1666 {1667 memset(Rect.pBits, 0, Rect.Pitch * pAlloc->SurfDesc.height);1668 }1669 else1670 {1671 Assert(0);1672 Assert(cbAllocPitch < (UINT)Rect.Pitch);1673 uint8_t *pData = (uint8_t*)Rect.pBits;1674 for (UINT j = 0; j < pAlloc->SurfDesc.height; ++j)1675 {1676 memset(Rect.pBits, c, cbAllocPitch);1677 pData += Rect.Pitch;1678 }1679 }1680 1681 hr = vboxWddmUnlockRect(pRc, iAlloc);1682 Assert(SUCCEEDED(hr));1683 1684 return S_OK;1685 }1686 1687 static HRESULT vboxWddmMemsetRc(PVBOXWDDMDISP_RESOURCE pRc, char c)1688 {1689 HRESULT hr = S_OK;1690 for (UINT i = 0; i < pRc->cAllocations; ++i)1691 {1692 hr = vboxWddmMemsetAlloc(pRc, i, c);1693 if (FAILED(hr))1694 {1695 WARN(("vboxWddmMemsetAlloc failed, hr(0x%x)", hr));1696 return hr;1697 }1698 }1699 return S_OK;1700 }1701 1702 1523 static HRESULT vboxWddmSurfSynchMem(PVBOXWDDMDISP_RESOURCE pRc) 1703 1524 { … … 1737 1558 if (pAlloc->SurfDesc.pitch == pLockInfo->Pitch) 1738 1559 { 1739 iRc = memcmp(pLockInfo->pBits, pAlloc->pvMem, pAlloc->SurfDesc.pitch * pAlloc->SurfDesc.height); 1560 Assert(pAlloc->SurfDesc.cbSize); 1561 iRc = memcmp(pLockInfo->pBits, pAlloc->pvMem, pAlloc->SurfDesc.cbSize); 1740 1562 Assert(!iRc); 1741 1563 } … … 1762 1584 uint32_t pitch = RT_MIN(srcPitch, dstPitch); 1763 1585 Assert(pitch); 1764 for (UINT j = 0; j < pAlloc->SurfDesc.height; ++j) 1586 uint32_t cRows = vboxWddmCalcNumRows(0, pAlloc->SurfDesc.height, pAlloc->SurfDesc.format); 1587 for (UINT j = 0; j < cRows; ++j) 1765 1588 { 1766 1589 iRc = memcmp(pvDst, pvSrc, pitch); … … 4708 4531 if (hr == S_OK) 4709 4532 { 4710 pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.width; 4533 Assert(pAlloc->SurfDesc.pitch == pAlloc->SurfDesc.width); 4534 pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.pitch; 4711 4535 // Assert(pLockAlloc->LockInfo.fFlags.Value == 0); 4712 4536 pAlloc->LockInfo.fFlags = pData->Flags; … … 4801 4625 if (hr == S_OK) 4802 4626 { 4803 pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.width; 4627 Assert(pAlloc->SurfDesc.pitch == pAlloc->SurfDesc.width); 4628 pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.pitch; 4804 4629 // Assert(pLockAlloc->LockInfo.fFlags.Value == 0); 4805 4630 pAlloc->LockInfo.fFlags = pData->Flags; … … 4867 4692 } 4868 4693 } 4869 else 4694 else /* if !VBOXDISPMODE_IS_3D(pDevice->pAdapter) */ 4870 4695 { 4871 4696 #ifdef DEBUG_misha … … 4893 4718 if (pData->Flags.AreaValid) 4894 4719 { 4895 offset = pAlloc->SurfDesc.pitch * pData->Area.top + 4896 ((pAlloc->SurfDesc.bpp * pData->Area.left) >> 3); 4720 offset = vboxWddmCalcOffXYrd(pData->Area.left, pData->Area.top, pAlloc->SurfDesc.pitch, pAlloc->SurfDesc.format); 4897 4721 } 4898 4722 else if (pData->Flags.RangeValid) … … 5207 5031 5208 5032 PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pResource->SurfCount); 5209 Assert(pRc); 5210 if (pRc) 5211 { 5212 bool bIssueCreateResource = false; 5213 bool bCreateSwapchain = false; 5214 bool bCreateKMResource = false; 5215 5216 pRc->hResource = pResource->hResource; 5217 pRc->hKMResource = NULL; 5218 pRc->pDevice = pDevice; 5219 pRc->fFlags.Value = 0; 5220 pRc->fFlags.Generic = 1; 5221 pRc->RcDesc.fFlags = pResource->Flags; 5222 pRc->RcDesc.enmFormat = pResource->Format; 5223 pRc->RcDesc.enmPool = pResource->Pool; 5224 pRc->RcDesc.enmMultisampleType = pResource->MultisampleType; 5225 pRc->RcDesc.MultisampleQuality = pResource->MultisampleQuality; 5226 pRc->RcDesc.MipLevels = pResource->MipLevels; 5227 pRc->RcDesc.Fvf = pResource->Fvf; 5228 pRc->RcDesc.VidPnSourceId = pResource->VidPnSourceId; 5229 pRc->RcDesc.RefreshRate = pResource->RefreshRate; 5230 pRc->RcDesc.enmRotation = pResource->Rotation; 5231 pRc->cAllocations = pResource->SurfCount; 5232 for (UINT i = 0; i < pResource->SurfCount; ++i) 5233 { 5234 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5235 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5236 5237 /*@fixme: Those formats are actually blocks of 4x4 pixels, 5238 * for some reason we're getting pSurf->SysMemPitch as if took 4x1 column from this block, 5239 * which leads us to having 4x times bigger pitch than actual line takes. 5240 * Simply trying to read here provided pointer 5241 * at (byte*)pSurf->pSysMem + pSurf->pSurf->SysMemPitch*pSurf->Height - 1 causes access violation. 5242 */ 5243 if (pResource->Format == D3DDDIFMT_DXT1 5244 || pResource->Format == D3DDDIFMT_DXT2 5245 || pResource->Format == D3DDDIFMT_DXT3 5246 || pResource->Format == D3DDDIFMT_DXT4 5247 || pResource->Format == D3DDDIFMT_DXT5) 5248 { 5249 *((UINT*)&pSurf->SysMemPitch) = pSurf->SysMemPitch >> 2; 5250 } 5251 5252 pAllocation->hAllocation = NULL; 5253 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 5254 pAllocation->iAlloc = i; 5255 pAllocation->pRc = pRc; 5256 pAllocation->D3DWidth = pSurf->Width; 5257 pAllocation->pvMem = (void*)pSurf->pSysMem; 5258 pAllocation->SurfDesc.slicePitch = pSurf->SysMemSlicePitch; 5259 pAllocation->SurfDesc.depth = pSurf->Depth; 5260 pAllocation->SurfDesc.width = pSurf->Width; 5261 pAllocation->SurfDesc.height = pSurf->Height; 5262 pAllocation->SurfDesc.format = pResource->Format; 5263 if (!vboxWddmFormatToFourcc(pResource->Format)) 5264 pAllocation->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format); 5265 else 5266 pAllocation->SurfDesc.bpp = 0; 5267 5268 if (pSurf->SysMemPitch) 5269 { 5270 pAllocation->SurfDesc.pitch = pSurf->SysMemPitch; 5271 } 5272 else 5273 pAllocation->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pAllocation->SurfDesc.bpp); 5274 } 5275 5276 if (VBOXDISPMODE_IS_3D(pAdapter)) 5277 { 5278 if (pResource->Flags.SharedResource) 5033 if (!pRc) 5034 { 5035 WARN(("vboxResourceAlloc failed")); 5036 return E_OUTOFMEMORY; 5037 } 5038 bool bIssueCreateResource = false; 5039 bool bCreateSwapchain = false; 5040 bool bCreateKMResource = false; 5041 5042 pRc->hResource = pResource->hResource; 5043 pRc->hKMResource = NULL; 5044 pRc->pDevice = pDevice; 5045 pRc->fFlags.Value = 0; 5046 pRc->fFlags.Generic = 1; 5047 pRc->RcDesc.fFlags = pResource->Flags; 5048 pRc->RcDesc.enmFormat = pResource->Format; 5049 pRc->RcDesc.enmPool = pResource->Pool; 5050 pRc->RcDesc.enmMultisampleType = pResource->MultisampleType; 5051 pRc->RcDesc.MultisampleQuality = pResource->MultisampleQuality; 5052 pRc->RcDesc.MipLevels = pResource->MipLevels; 5053 pRc->RcDesc.Fvf = pResource->Fvf; 5054 pRc->RcDesc.VidPnSourceId = pResource->VidPnSourceId; 5055 pRc->RcDesc.RefreshRate = pResource->RefreshRate; 5056 pRc->RcDesc.enmRotation = pResource->Rotation; 5057 pRc->cAllocations = pResource->SurfCount; 5058 for (UINT i = 0; i < pResource->SurfCount; ++i) 5059 { 5060 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5061 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5062 pAllocation->hAllocation = NULL; 5063 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 5064 pAllocation->iAlloc = i; 5065 pAllocation->pRc = pRc; 5066 pAllocation->D3DWidth = pSurf->Width; 5067 pAllocation->pvMem = (void*)pSurf->pSysMem; 5068 pAllocation->SurfDesc.slicePitch = pSurf->SysMemSlicePitch; 5069 pAllocation->SurfDesc.depth = pSurf->Depth; 5070 pAllocation->SurfDesc.width = pSurf->Width; 5071 pAllocation->SurfDesc.height = pSurf->Height; 5072 pAllocation->SurfDesc.format = pResource->Format; 5073 if (!vboxWddmFormatToFourcc(pResource->Format)) 5074 pAllocation->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format); 5075 else 5076 pAllocation->SurfDesc.bpp = 0; 5077 5078 if (pSurf->SysMemPitch) 5079 pAllocation->SurfDesc.pitch = pSurf->SysMemPitch; 5080 else 5081 pAllocation->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pResource->Format); 5082 5083 pAllocation->SurfDesc.cbSize = vboxWddmCalcSize(pAllocation->SurfDesc.pitch, pAllocation->SurfDesc.height, pAllocation->SurfDesc.format); 5084 } 5085 5086 if (VBOXDISPMODE_IS_3D(pAdapter)) 5087 { 5088 if (pResource->Flags.SharedResource) 5089 { 5090 bIssueCreateResource = true; 5091 bCreateKMResource = true; 5092 } 5093 5094 if (pResource->Flags.ZBuffer) 5095 { 5096 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5097 for (UINT i = 0; i < pResource->SurfCount; ++i) 5098 { 5099 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5100 IDirect3DSurface9 *pD3D9Surf; 5101 hr = pDevice9If->CreateDepthStencilSurface(pAllocation->SurfDesc.width, 5102 pAllocation->SurfDesc.height, 5103 vboxDDI2D3DFormat(pResource->Format), 5104 vboxDDI2D3DMultiSampleType(pResource->MultisampleType), 5105 pResource->MultisampleQuality, 5106 TRUE /* @todo: BOOL Discard */, 5107 &pD3D9Surf, 5108 NULL /*HANDLE* pSharedHandle*/); 5109 Assert(hr == S_OK); 5110 if (hr == S_OK) 5111 { 5112 Assert(pD3D9Surf); 5113 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE; 5114 pAllocation->pD3DIf = pD3D9Surf; 5115 } 5116 else 5117 { 5118 for (UINT j = 0; j < i; ++j) 5119 { 5120 pRc->aAllocations[j].pD3DIf->Release(); 5121 } 5122 break; 5123 } 5124 } 5125 5126 if (SUCCEEDED(hr)) 5127 { 5128 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5129 { 5130 vboxWddmSurfSynchMem(pRc); 5131 } 5132 } 5133 } 5134 else if (pResource->Flags.VertexBuffer) 5135 { 5136 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5137 5138 for (UINT i = 0; i < pResource->SurfCount; ++i) 5139 { 5140 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5141 IDirect3DVertexBuffer9 *pD3D9VBuf; 5142 hr = pDevice9If->CreateVertexBuffer(pAllocation->SurfDesc.width, 5143 vboxDDI2D3DUsage(pResource->Flags), 5144 pResource->Fvf, 5145 vboxDDI2D3DPool(pResource->Pool), 5146 &pD3D9VBuf, 5147 NULL /*HANDLE* pSharedHandle*/); 5148 Assert(hr == S_OK); 5149 if (hr == S_OK) 5150 { 5151 Assert(pD3D9VBuf); 5152 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_VERTEXBUFFER; 5153 pAllocation->pD3DIf = pD3D9VBuf; 5154 } 5155 else 5156 { 5157 for (UINT j = 0; j < i; ++j) 5158 { 5159 pRc->aAllocations[j].pD3DIf->Release(); 5160 } 5161 break; 5162 } 5163 } 5164 5165 if (SUCCEEDED(hr)) 5166 { 5167 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5168 { 5169 vboxWddmSurfSynchMem(pRc); 5170 } 5171 } 5172 } 5173 else if (pResource->Flags.IndexBuffer) 5174 { 5175 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5176 5177 for (UINT i = 0; i < pResource->SurfCount; ++i) 5178 { 5179 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5180 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5181 IDirect3DIndexBuffer9 *pD3D9IBuf; 5182 hr = pDevice9If->CreateIndexBuffer(pSurf->Width, 5183 vboxDDI2D3DUsage(pResource->Flags), 5184 vboxDDI2D3DFormat(pResource->Format), 5185 vboxDDI2D3DPool(pResource->Pool), 5186 &pD3D9IBuf, 5187 NULL /*HANDLE* pSharedHandle*/ 5188 ); 5189 Assert(hr == S_OK); 5190 if (hr == S_OK) 5191 { 5192 Assert(pD3D9IBuf); 5193 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_INDEXBUFFER; 5194 pAllocation->pD3DIf = pD3D9IBuf; 5195 } 5196 else 5197 { 5198 for (UINT j = 0; j < i; ++j) 5199 { 5200 pRc->aAllocations[j].pD3DIf->Release(); 5201 } 5202 break; 5203 } 5204 } 5205 5206 if (SUCCEEDED(hr)) 5207 { 5208 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5209 { 5210 vboxWddmSurfSynchMem(pRc); 5211 } 5212 } 5213 } 5214 else if (VBOXWDDMDISP_IS_TEXTURE(pResource->Flags)) 5215 { 5216 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5217 5218 if (pResource->Flags.RenderTarget && !pResource->Flags.Texture) 5279 5219 { 5280 5220 bIssueCreateResource = true; 5281 bCreateKMResource = true; 5282 } 5283 5284 if (pResource->Flags.ZBuffer) 5285 { 5286 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5287 for (UINT i = 0; i < pResource->SurfCount; ++i) 5288 { 5289 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5290 IDirect3DSurface9 *pD3D9Surf; 5291 hr = pDevice9If->CreateDepthStencilSurface(pAllocation->SurfDesc.width, 5292 pAllocation->SurfDesc.height, 5293 vboxDDI2D3DFormat(pResource->Format), 5294 vboxDDI2D3DMultiSampleType(pResource->MultisampleType), 5295 pResource->MultisampleQuality, 5296 TRUE /* @todo: BOOL Discard */, 5297 &pD3D9Surf, 5298 NULL /*HANDLE* pSharedHandle*/); 5221 } 5222 5223 if (!pResource->Flags.CubeMap) 5224 { 5225 #ifdef DEBUG 5226 { 5227 uint32_t tstW = pResource->pSurfList[0].Width; 5228 uint32_t tstH = pResource->pSurfList[0].Height; 5229 for (UINT i = 1; i < pResource->SurfCount; ++i) 5230 { 5231 tstW /= 2; 5232 tstH /= 2; 5233 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5234 Assert((pSurf->Width == tstW) || (!tstW && (pSurf->Width==1))); 5235 Assert((pSurf->Height == tstH) || (!tstH && (pSurf->Height==1))); 5236 } 5237 } 5238 #endif 5239 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0]; 5240 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[0]; 5241 IDirect3DTexture9 *pD3DIfTex; 5242 HANDLE hSharedHandle = NULL; 5243 void **pavClientMem = NULL; 5244 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5245 { 5246 Assert(pSurf->pSysMem); 5247 Assert(pSurf->SysMemPitch); 5248 UINT minPitch = vboxWddmCalcPitch(pAllocation->SurfDesc.width, pAllocation->SurfDesc.format); 5249 Assert(minPitch); 5250 if (minPitch) 5251 { 5252 if (pSurf->SysMemPitch != minPitch) 5253 pAllocation->D3DWidth = vboxWddmCalcWidthForPitch(pSurf->SysMemPitch, pAllocation->SurfDesc.format); 5254 Assert(pAllocation->D3DWidth >= pSurf->Width); 5255 } 5256 else 5257 { 5258 Assert(pAllocation->D3DWidth == pSurf->Width); 5259 } 5260 } 5261 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5262 { 5263 pavClientMem = (void**)RTMemAlloc(sizeof (pavClientMem[0]) * pResource->SurfCount); 5264 Assert(pavClientMem); 5265 if (pavClientMem) 5266 { 5267 for (UINT i = 0; i < pResource->SurfCount; ++i) 5268 { 5269 pavClientMem[i] = pRc->aAllocations[i].pvMem; 5270 } 5271 } 5272 else 5273 hr = E_FAIL; 5274 } 5275 if (hr == S_OK) 5276 { 5277 hr = pDevice->pAdapter->D3D.pfnVBoxWineExD3DDev9CreateTexture((IDirect3DDevice9Ex *)pDevice9If, 5278 pAllocation->D3DWidth, 5279 pSurf->Height, 5280 pResource->SurfCount, 5281 vboxDDI2D3DUsage(pResource->Flags), 5282 vboxDDI2D3DFormat(pResource->Format), 5283 vboxDDI2D3DPool(pResource->Pool), 5284 &pD3DIfTex, 5285 #ifdef VBOXWDDMDISP_DEBUG_NOSHARED 5286 NULL, 5287 #else 5288 pResource->Flags.SharedResource ? &hSharedHandle : NULL, 5289 #endif 5290 pavClientMem); 5299 5291 Assert(hr == S_OK); 5300 5292 if (hr == S_OK) 5301 5293 { 5302 Assert(pD3D9Surf); 5303 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE; 5304 pAllocation->pD3DIf = pD3D9Surf; 5305 } 5306 else 5307 { 5308 for (UINT j = 0; j < i; ++j) 5294 Assert(pD3DIfTex); 5295 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_TEXTURE; 5296 pAllocation->pD3DIf = pD3DIfTex; 5297 #ifndef VBOXWDDMDISP_DEBUG_NOSHARED 5298 Assert(!!(pResource->Flags.SharedResource) == !!(hSharedHandle)); 5299 #endif 5300 pAllocation->hSharedHandle = hSharedHandle; 5301 5302 if (!pavClientMem) 5309 5303 { 5310 pRc->aAllocations[j].pD3DIf->Release(); 5311 } 5312 break; 5313 } 5314 } 5315 5316 if (SUCCEEDED(hr)) 5317 { 5318 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5319 { 5320 vboxWddmSurfSynchMem(pRc); 5321 } 5322 } 5323 } 5324 else if (pResource->Flags.VertexBuffer) 5325 { 5326 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5327 5328 for (UINT i = 0; i < pResource->SurfCount; ++i) 5329 { 5330 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5331 IDirect3DVertexBuffer9 *pD3D9VBuf; 5332 hr = pDevice9If->CreateVertexBuffer(pAllocation->SurfDesc.width, 5333 vboxDDI2D3DUsage(pResource->Flags), 5334 pResource->Fvf, 5335 vboxDDI2D3DPool(pResource->Pool), 5336 &pD3D9VBuf, 5337 NULL /*HANDLE* pSharedHandle*/); 5338 Assert(hr == S_OK); 5339 if (hr == S_OK) 5340 { 5341 Assert(pD3D9VBuf); 5342 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_VERTEXBUFFER; 5343 pAllocation->pD3DIf = pD3D9VBuf; 5344 } 5345 else 5346 { 5347 for (UINT j = 0; j < i; ++j) 5348 { 5349 pRc->aAllocations[j].pD3DIf->Release(); 5350 } 5351 break; 5352 } 5353 } 5354 5355 if (SUCCEEDED(hr)) 5356 { 5357 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5358 { 5359 vboxWddmSurfSynchMem(pRc); 5360 } 5361 } 5362 } 5363 else if (pResource->Flags.IndexBuffer) 5364 { 5365 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5366 5367 for (UINT i = 0; i < pResource->SurfCount; ++i) 5368 { 5369 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5370 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5371 IDirect3DIndexBuffer9 *pD3D9IBuf; 5372 hr = pDevice9If->CreateIndexBuffer(pSurf->Width, 5373 vboxDDI2D3DUsage(pResource->Flags), 5374 vboxDDI2D3DFormat(pResource->Format), 5375 vboxDDI2D3DPool(pResource->Pool), 5376 &pD3D9IBuf, 5377 NULL /*HANDLE* pSharedHandle*/ 5378 ); 5379 Assert(hr == S_OK); 5380 if (hr == S_OK) 5381 { 5382 Assert(pD3D9IBuf); 5383 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_INDEXBUFFER; 5384 pAllocation->pD3DIf = pD3D9IBuf; 5385 } 5386 else 5387 { 5388 for (UINT j = 0; j < i; ++j) 5389 { 5390 pRc->aAllocations[j].pD3DIf->Release(); 5391 } 5392 break; 5393 } 5394 } 5395 5396 if (SUCCEEDED(hr)) 5397 { 5398 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5399 { 5400 vboxWddmSurfSynchMem(pRc); 5401 } 5402 } 5403 } 5404 else if (VBOXWDDMDISP_IS_TEXTURE(pResource->Flags)) 5405 { 5406 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5407 5408 if (pResource->Flags.RenderTarget && !pResource->Flags.Texture) 5409 { 5410 bIssueCreateResource = true; 5411 } 5412 5413 if (!pResource->Flags.CubeMap) 5414 { 5415 #ifdef DEBUG 5416 { 5417 uint32_t tstW = pResource->pSurfList[0].Width; 5418 uint32_t tstH = pResource->pSurfList[0].Height; 5419 for (UINT i = 1; i < pResource->SurfCount; ++i) 5420 { 5421 tstW /= 2; 5422 tstH /= 2; 5423 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5424 Assert((pSurf->Width == tstW) || (!tstW && (pSurf->Width==1))); 5425 Assert((pSurf->Height == tstH) || (!tstH && (pSurf->Height==1))); 5304 /* zero-init texture memory */ 5305 5426 5306 } 5427 5307 } 5428 #endif 5429 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0]; 5430 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[0]; 5431 IDirect3DTexture9 *pD3DIfTex; 5432 HANDLE hSharedHandle = NULL; 5433 void **pavClientMem = NULL; 5434 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5435 { 5436 Assert(pSurf->pSysMem); 5437 Assert(pSurf->SysMemPitch); 5438 UINT bpp = vboxWddmCalcBitsPerPixel(pResource->Format); 5439 Assert(bpp); 5440 if (bpp) 5441 { 5442 pAllocation->D3DWidth = ((pSurf->SysMemPitch << 3) / bpp); 5443 if ((pSurf->SysMemPitch << 3) % bpp) 5444 { 5445 Assert(0); 5446 ++pAllocation->D3DWidth; 5447 } 5448 Assert(pAllocation->D3DWidth >= pSurf->Width); 5449 } 5450 } 5308 5309 if (pavClientMem) 5310 RTMemFree(pavClientMem); 5311 } 5312 } 5313 else /*pResource->Flags.CubeMap*/ 5314 { 5315 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5316 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0]; 5317 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[0]; 5318 IDirect3DCubeTexture9 *pD3DIfCubeTex; 5319 HANDLE hSharedHandle = NULL; 5320 void **pavClientMem = NULL; 5321 5322 if ( (pAllocation->SurfDesc.width!=pAllocation->SurfDesc.height) 5323 || (pResource->SurfCount%6!=0)) 5324 { 5325 Assert(0); 5326 hr = E_INVALIDARG; 5327 } 5328 else 5329 { 5451 5330 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5452 5331 { … … 5463 5342 hr = E_FAIL; 5464 5343 } 5344 5465 5345 if (hr == S_OK) 5466 5346 { 5467 hr = pDevice->pAdapter->D3D.pfnVBoxWineExD3DDev9CreateTexture((IDirect3DDevice9Ex *)pDevice9If, 5468 pAllocation->D3DWidth, 5469 pSurf->Height, 5470 pResource->SurfCount, 5471 vboxDDI2D3DUsage(pResource->Flags), 5472 vboxDDI2D3DFormat(pResource->Format), 5473 vboxDDI2D3DPool(pResource->Pool), 5474 &pD3DIfTex, 5347 hr = pDevice->pAdapter->D3D.pfnVBoxWineExD3DDev9CreateCubeTexture((IDirect3DDevice9Ex *)pDevice9If, 5348 pAllocation->SurfDesc.width, 5349 VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc), 5350 vboxDDI2D3DUsage(pResource->Flags), 5351 vboxDDI2D3DFormat(pResource->Format), 5352 vboxDDI2D3DPool(pResource->Pool), 5353 &pD3DIfCubeTex, 5475 5354 #ifdef VBOXWDDMDISP_DEBUG_NOSHARED 5476 5355 NULL, 5477 5356 #else 5478 5357 pResource->Flags.SharedResource ? &hSharedHandle : NULL, 5479 5358 #endif 5480 5359 pavClientMem); … … 5482 5361 if (hr == S_OK) 5483 5362 { 5484 Assert(pD3DIf Tex);5485 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_ TEXTURE;5486 pAllocation->pD3DIf = pD3DIf Tex;5363 Assert(pD3DIfCubeTex); 5364 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_CUBE_TEXTURE; 5365 pAllocation->pD3DIf = pD3DIfCubeTex; 5487 5366 #ifndef VBOXWDDMDISP_DEBUG_NOSHARED 5488 5367 Assert(!!(pResource->Flags.SharedResource) == !!(hSharedHandle)); 5489 5368 #endif 5490 5369 pAllocation->hSharedHandle = hSharedHandle; 5491 5492 if (!pavClientMem)5493 {5494 /* zero-init texture memory */5495 5496 }5497 5370 } 5498 5371 … … 5501 5374 } 5502 5375 } 5503 else /*pResource->Flags.CubeMap*/ 5504 { 5505 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); 5506 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0]; 5507 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[0]; 5508 IDirect3DCubeTexture9 *pD3DIfCubeTex; 5376 } 5377 } 5378 else if (pResource->Flags.RenderTarget) 5379 { 5380 HWND hWnd = NULL; 5381 bIssueCreateResource = true; 5382 Assert(pResource->SurfCount); 5383 if (RTListIsEmpty(&pDevice->SwapchainList)) 5384 { 5385 bCreateSwapchain = true; 5386 Assert(bIssueCreateResource); 5387 for (UINT i = 0; i < pRc->cAllocations; ++i) 5388 { 5389 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5390 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE; 5391 } 5392 } 5393 else 5394 { 5395 for (UINT i = 0; i < pResource->SurfCount; ++i) 5396 { 5397 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5509 5398 HANDLE hSharedHandle = NULL; 5510 void **pavClientMem = NULL; 5511 5512 if ( (pAllocation->SurfDesc.width!=pAllocation->SurfDesc.height) 5513 || (pResource->SurfCount%6!=0)) 5399 5400 IDirect3DSurface9* pD3D9Surf; 5401 hr = pDevice->pDevice9If->CreateRenderTarget(pAllocation->SurfDesc.width, 5402 pAllocation->SurfDesc.height, 5403 vboxDDI2D3DFormat(pResource->Format), 5404 vboxDDI2D3DMultiSampleType(pResource->MultisampleType), 5405 pResource->MultisampleQuality, 5406 !pResource->Flags.NotLockable /* BOOL Lockable */, 5407 &pD3D9Surf, 5408 #ifdef VBOXWDDMDISP_DEBUG_NOSHARED 5409 NULL 5410 #else 5411 pResource->Flags.SharedResource ? &hSharedHandle : NULL 5412 #endif 5413 ); 5414 Assert(hr == S_OK); 5415 if (hr == S_OK) 5416 { 5417 Assert(pD3D9Surf); 5418 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE; 5419 pAllocation->pD3DIf = pD3D9Surf; 5420 #ifndef VBOXWDDMDISP_DEBUG_NOSHARED 5421 Assert(!!(pResource->Flags.SharedResource) == !!(hSharedHandle)); 5422 #endif 5423 pAllocation->hSharedHandle = hSharedHandle; 5424 continue; 5425 5426 /* fail branch */ 5427 pD3D9Surf->Release(); 5428 } 5429 5430 for (UINT j = 0; j < i; ++j) 5431 { 5432 pRc->aAllocations[j].pD3DIf->Release(); 5433 } 5434 break; 5435 } 5436 5437 if (SUCCEEDED(hr)) 5438 { 5439 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5514 5440 { 5515 5441 Assert(0); 5516 hr = E_INVALIDARG; 5442 vboxWddmSurfSynchMem(pRc); 5443 } 5444 } 5445 } 5446 } 5447 else 5448 { 5449 hr = E_FAIL; 5450 Assert(0); 5451 } 5452 } 5453 else 5454 { 5455 bIssueCreateResource = true; 5456 bCreateKMResource = true; 5457 } 5458 5459 5460 if (hr == S_OK && bIssueCreateResource) 5461 { 5462 pRc->fFlags.KmResource = bCreateKMResource; 5463 D3DDDICB_ALLOCATE *pDdiAllocate = vboxWddmRequestAllocAlloc(pResource); 5464 Assert(pDdiAllocate); 5465 if (pDdiAllocate) 5466 { 5467 Assert(pDdiAllocate->pPrivateDriverData); 5468 Assert(pDdiAllocate->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO)); 5469 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)pDdiAllocate->pPrivateDriverData; 5470 pRcInfo->fFlags = pRc->fFlags; 5471 pRcInfo->RcDesc = pRc->RcDesc; 5472 pRcInfo->cAllocInfos = pResource->SurfCount; 5473 5474 for (UINT i = 0; i < pResource->SurfCount; ++i) 5475 { 5476 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i]; 5477 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5478 Assert(pDdiAllocI->pPrivateDriverData); 5479 Assert(pDdiAllocI->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO)); 5480 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData; 5481 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5482 pDdiAllocI->hAllocation = NULL; 5483 pDdiAllocI->pSystemMem = pSurf->pSysMem; 5484 Assert((!!(pSurf->pSysMem)) == (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)); 5485 pDdiAllocI->VidPnSourceId = pResource->VidPnSourceId; 5486 pDdiAllocI->Flags.Value = 0; 5487 if (pResource->Flags.Primary) 5488 { 5489 Assert(pResource->Flags.RenderTarget); 5490 pDdiAllocI->Flags.Primary = 1; 5491 } 5492 5493 pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 5494 pAllocInfo->fFlags = pResource->Flags; 5495 pAllocInfo->hSharedHandle = (uint64_t)pAllocation->hSharedHandle; 5496 pAllocInfo->SurfDesc = pAllocation->SurfDesc; 5497 } 5498 5499 Assert(!pRc->fFlags.Opened); 5500 // Assert(!pRc->fFlags.KmResource); 5501 Assert(pRc->fFlags.Generic); 5502 5503 if (bCreateKMResource) 5504 { 5505 Assert(pRc->fFlags.KmResource); 5506 5507 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate); 5508 Assert(hr == S_OK); 5509 Assert(pDdiAllocate->hKMResource 5510 || pResource->Flags.SharedResource /* for some reason shared resources 5511 * are created with zero km resource handle on Win7+ */ 5512 ); 5513 } 5514 else 5515 { 5516 Assert(!pRc->fFlags.KmResource); 5517 5518 pDdiAllocate->hResource = NULL; 5519 pDdiAllocate->NumAllocations = 1; 5520 pDdiAllocate->PrivateDriverDataSize = 0; 5521 pDdiAllocate->pPrivateDriverData = NULL; 5522 D3DDDI_ALLOCATIONINFO *pDdiAllocIBase = pDdiAllocate->pAllocationInfo; 5523 5524 for (UINT i = 0; i < pResource->SurfCount; ++i) 5525 { 5526 pDdiAllocate->pAllocationInfo = &pDdiAllocIBase[i]; 5527 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate); 5528 Assert(hr == S_OK); 5529 Assert(!pDdiAllocate->hKMResource); 5530 if (hr == S_OK) 5531 { 5532 Assert(pDdiAllocate->pAllocationInfo->hAllocation); 5517 5533 } 5518 5534 else 5519 5535 { 5520 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)5536 for (UINT j = 0; i < j; ++j) 5521 5537 { 5522 pavClientMem = (void**)RTMemAlloc(sizeof (pavClientMem[0]) * pResource->SurfCount); 5523 Assert(pavClientMem); 5524 if (pavClientMem) 5525 { 5526 for (UINT i = 0; i < pResource->SurfCount; ++i) 5527 { 5528 pavClientMem[i] = pRc->aAllocations[i].pvMem; 5529 } 5530 } 5531 else 5532 hr = E_FAIL; 5533 } 5534 5535 if (hr == S_OK) 5536 { 5537 hr = pDevice->pAdapter->D3D.pfnVBoxWineExD3DDev9CreateCubeTexture((IDirect3DDevice9Ex *)pDevice9If, 5538 pAllocation->SurfDesc.width, 5539 VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc), 5540 vboxDDI2D3DUsage(pResource->Flags), 5541 vboxDDI2D3DFormat(pResource->Format), 5542 vboxDDI2D3DPool(pResource->Pool), 5543 &pD3DIfCubeTex, 5544 #ifdef VBOXWDDMDISP_DEBUG_NOSHARED 5545 NULL, 5546 #else 5547 pResource->Flags.SharedResource ? &hSharedHandle : NULL, 5548 #endif 5549 pavClientMem); 5550 Assert(hr == S_OK); 5551 if (hr == S_OK) 5552 { 5553 Assert(pD3DIfCubeTex); 5554 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_CUBE_TEXTURE; 5555 pAllocation->pD3DIf = pD3DIfCubeTex; 5556 #ifndef VBOXWDDMDISP_DEBUG_NOSHARED 5557 Assert(!!(pResource->Flags.SharedResource) == !!(hSharedHandle)); 5558 #endif 5559 pAllocation->hSharedHandle = hSharedHandle; 5560 } 5561 5562 if (pavClientMem) 5563 RTMemFree(pavClientMem); 5564 } 5565 } 5566 } 5567 5568 if (SUCCEEDED(hr)) 5569 { 5570 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM) 5571 { 5572 vboxWddmSurfSynchMem(pRc); 5573 } 5574 } 5575 } 5576 else if (pResource->Flags.RenderTarget) 5577 { 5578 HWND hWnd = NULL; 5579 bIssueCreateResource = true; 5580 Assert(pResource->SurfCount); 5581 if (RTListIsEmpty(&pDevice->SwapchainList)) 5582 { 5583 bCreateSwapchain = true; 5584 Assert(bIssueCreateResource); 5585 for (UINT i = 0; i < pRc->cAllocations; ++i) 5586 { 5587 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5588 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE; 5589 } 5590 } 5591 else 5592 { 5593 for (UINT i = 0; i < pResource->SurfCount; ++i) 5594 { 5595 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5596 HANDLE hSharedHandle = NULL; 5597 5598 IDirect3DSurface9* pD3D9Surf; 5599 hr = pDevice->pDevice9If->CreateRenderTarget(pAllocation->SurfDesc.width, 5600 pAllocation->SurfDesc.height, 5601 vboxDDI2D3DFormat(pResource->Format), 5602 vboxDDI2D3DMultiSampleType(pResource->MultisampleType), 5603 pResource->MultisampleQuality, 5604 !pResource->Flags.NotLockable /* BOOL Lockable */, 5605 &pD3D9Surf, 5606 #ifdef VBOXWDDMDISP_DEBUG_NOSHARED 5607 NULL 5608 #else 5609 pResource->Flags.SharedResource ? &hSharedHandle : NULL 5610 #endif 5611 ); 5612 Assert(hr == S_OK); 5613 if (hr == S_OK) 5614 { 5615 Assert(pD3D9Surf); 5616 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE; 5617 pAllocation->pD3DIf = pD3D9Surf; 5618 #ifndef VBOXWDDMDISP_DEBUG_NOSHARED 5619 Assert(!!(pResource->Flags.SharedResource) == !!(hSharedHandle)); 5620 #endif 5621 pAllocation->hSharedHandle = hSharedHandle; 5622 continue; 5623 5624 /* fail branch */ 5625 pD3D9Surf->Release(); 5626 } 5627 5628 for (UINT j = 0; j < i; ++j) 5629 { 5630 pRc->aAllocations[j].pD3DIf->Release(); 5538 D3DDDI_ALLOCATIONINFO * pCur = &pDdiAllocIBase[i]; 5539 D3DDDICB_DEALLOCATE Dealloc; 5540 Dealloc.hResource = 0; 5541 Dealloc.NumAllocations = 1; 5542 Dealloc.HandleList = &pCur->hAllocation; 5543 HRESULT tmpHr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc); 5544 Assert(tmpHr == S_OK); 5631 5545 } 5632 5546 break; 5633 5547 } 5634 5635 if (SUCCEEDED(hr)) 5548 } 5549 5550 pDdiAllocate->pAllocationInfo = pDdiAllocIBase; 5551 } 5552 5553 if (hr == S_OK) 5554 { 5555 pRc->hKMResource = pDdiAllocate->hKMResource; 5556 5557 for (UINT i = 0; i < pResource->SurfCount; ++i) 5558 { 5559 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5560 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i]; 5561 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData; 5562 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5563 pAllocation->hAllocation = pDdiAllocI->hAllocation; 5564 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 5565 pAllocation->pvMem = (void*)pSurf->pSysMem; 5566 pAllocation->SurfDesc = pAllocInfo->SurfDesc; 5567 5568 if (pResource->Flags.SharedResource) 5636 5569 { 5637 if (p Resource->Pool == D3DDDIPOOL_SYSTEMMEM)5570 if (pAllocation->hSharedHandle) 5638 5571 { 5639 Assert(0); 5640 vboxWddmSurfSynchMem(pRc); 5572 vboxWddmShRcRefAlloc(pDevice, pAllocation, TRUE, NULL); 5641 5573 } 5574 #ifdef DEBUG_misha 5575 Assert(VBOXWDDMDISP_IS_TEXTURE(pResource->Flags)); 5576 vboxVDbgPrint(("\n\n********\n(0x%x:0n%d)Shared CREATED pAlloc(0x%p), hRc(0x%p), hAl(0x%p), " 5577 "Handle(0x%x), (0n%d) \n***********\n\n", 5578 GetCurrentProcessId(), GetCurrentProcessId(), 5579 pAllocation, pRc->hKMResource, pAllocation->hAllocation, 5580 pAllocation->hSharedHandle, pAllocation->hSharedHandle 5581 )); 5582 #endif 5642 5583 } 5643 5584 } 5644 } 5645 else 5646 { 5647 hr = E_FAIL; 5648 Assert(0); 5649 } 5585 5586 if(bCreateSwapchain) 5587 { 5588 PVBOXWDDMDISP_SWAPCHAIN pSwapchain; 5589 hr = vboxWddmSwapchainCreateIfForRc(pDevice, pRc, &pSwapchain); 5590 Assert(hr == S_OK); 5591 } 5592 } 5593 5594 vboxWddmRequestAllocFree(pDdiAllocate); 5650 5595 } 5651 5596 else 5652 5597 { 5653 bIssueCreateResource = true; 5654 bCreateKMResource = true; 5655 } 5656 5657 5658 if (hr == S_OK && bIssueCreateResource) 5659 { 5660 pRc->fFlags.KmResource = bCreateKMResource; 5661 D3DDDICB_ALLOCATE *pDdiAllocate = vboxWddmRequestAllocAlloc(pResource); 5662 Assert(pDdiAllocate); 5663 if (pDdiAllocate) 5664 { 5665 Assert(pDdiAllocate->pPrivateDriverData); 5666 Assert(pDdiAllocate->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO)); 5667 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)pDdiAllocate->pPrivateDriverData; 5668 pRcInfo->fFlags = pRc->fFlags; 5669 pRcInfo->RcDesc = pRc->RcDesc; 5670 pRcInfo->cAllocInfos = pResource->SurfCount; 5671 5672 for (UINT i = 0; i < pResource->SurfCount; ++i) 5673 { 5674 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i]; 5675 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5676 Assert(pDdiAllocI->pPrivateDriverData); 5677 Assert(pDdiAllocI->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO)); 5678 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData; 5679 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5680 pDdiAllocI->hAllocation = NULL; 5681 pDdiAllocI->pSystemMem = pSurf->pSysMem; 5682 Assert((!!(pSurf->pSysMem)) == (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)); 5683 pDdiAllocI->VidPnSourceId = pResource->VidPnSourceId; 5684 pDdiAllocI->Flags.Value = 0; 5685 if (pResource->Flags.Primary) 5686 { 5687 Assert(pResource->Flags.RenderTarget); 5688 pDdiAllocI->Flags.Primary = 1; 5689 } 5690 5691 pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 5692 pAllocInfo->fFlags = pResource->Flags; 5693 pAllocInfo->hSharedHandle = (uint64_t)pAllocation->hSharedHandle; 5694 pAllocInfo->SurfDesc.width = pSurf->Width; 5695 pAllocInfo->SurfDesc.height = pSurf->Height; 5696 pAllocInfo->SurfDesc.format = pResource->Format; 5697 if (!vboxWddmFormatToFourcc(pResource->Format)) 5698 pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format); 5699 else 5700 pAllocInfo->SurfDesc.bpp = 0; 5701 5702 if (pSurf->SysMemPitch) 5703 { 5704 pAllocInfo->SurfDesc.pitch = pSurf->SysMemPitch; 5705 #ifdef DEBUG 5706 UINT tst = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp); 5707 Assert(tst == pSurf->SysMemPitch); 5708 #endif 5709 } 5710 else 5711 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp); 5712 5713 pAllocInfo->SurfDesc.cbSize = pAllocInfo->SurfDesc.pitch * pAllocInfo->SurfDesc.height; 5714 pAllocInfo->SurfDesc.depth = pSurf->Depth; 5715 pAllocInfo->SurfDesc.slicePitch = pSurf->SysMemSlicePitch; 5716 pAllocInfo->SurfDesc.VidPnSourceId = pResource->VidPnSourceId; 5717 pAllocInfo->SurfDesc.RefreshRate = pResource->RefreshRate; 5718 } 5719 5720 Assert(!pRc->fFlags.Opened); 5721 // Assert(!pRc->fFlags.KmResource); 5722 Assert(pRc->fFlags.Generic); 5723 5724 if (bCreateKMResource) 5725 { 5726 Assert(pRc->fFlags.KmResource); 5727 5728 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate); 5729 Assert(hr == S_OK); 5730 Assert(pDdiAllocate->hKMResource 5731 || pResource->Flags.SharedResource /* for some reason shared resources 5732 * are created with zero km resource handle on Win7+ */ 5733 ); 5734 } 5735 else 5736 { 5737 Assert(!pRc->fFlags.KmResource); 5738 5739 pDdiAllocate->hResource = NULL; 5740 pDdiAllocate->NumAllocations = 1; 5741 pDdiAllocate->PrivateDriverDataSize = 0; 5742 pDdiAllocate->pPrivateDriverData = NULL; 5743 D3DDDI_ALLOCATIONINFO *pDdiAllocIBase = pDdiAllocate->pAllocationInfo; 5744 5745 for (UINT i = 0; i < pResource->SurfCount; ++i) 5746 { 5747 pDdiAllocate->pAllocationInfo = &pDdiAllocIBase[i]; 5748 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate); 5749 Assert(hr == S_OK); 5750 Assert(!pDdiAllocate->hKMResource); 5751 if (hr == S_OK) 5752 { 5753 Assert(pDdiAllocate->pAllocationInfo->hAllocation); 5754 } 5755 else 5756 { 5757 for (UINT j = 0; i < j; ++j) 5758 { 5759 D3DDDI_ALLOCATIONINFO * pCur = &pDdiAllocIBase[i]; 5760 D3DDDICB_DEALLOCATE Dealloc; 5761 Dealloc.hResource = 0; 5762 Dealloc.NumAllocations = 1; 5763 Dealloc.HandleList = &pCur->hAllocation; 5764 HRESULT tmpHr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc); 5765 Assert(tmpHr == S_OK); 5766 } 5767 break; 5768 } 5769 } 5770 5771 pDdiAllocate->pAllocationInfo = pDdiAllocIBase; 5772 } 5773 5774 if (hr == S_OK) 5775 { 5776 pRc->hKMResource = pDdiAllocate->hKMResource; 5777 5778 for (UINT i = 0; i < pResource->SurfCount; ++i) 5779 { 5780 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 5781 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i]; 5782 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData; 5783 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 5784 pAllocation->hAllocation = pDdiAllocI->hAllocation; 5785 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 5786 pAllocation->pvMem = (void*)pSurf->pSysMem; 5787 pAllocation->SurfDesc = pAllocInfo->SurfDesc; 5788 5789 if (pResource->Flags.SharedResource) 5790 { 5791 if (pAllocation->hSharedHandle) 5792 { 5793 vboxWddmShRcRefAlloc(pDevice, pAllocation, TRUE, NULL); 5794 } 5795 #ifdef DEBUG_misha 5796 Assert(VBOXWDDMDISP_IS_TEXTURE(pResource->Flags)); 5797 vboxVDbgPrint(("\n\n********\n(0x%x:0n%d)Shared CREATED pAlloc(0x%p), hRc(0x%p), hAl(0x%p), " 5798 "Handle(0x%x), (0n%d) \n***********\n\n", 5799 GetCurrentProcessId(), GetCurrentProcessId(), 5800 pAllocation, pRc->hKMResource, pAllocation->hAllocation, 5801 pAllocation->hSharedHandle, pAllocation->hSharedHandle 5802 )); 5803 #endif 5804 } 5805 } 5806 5807 if(bCreateSwapchain) 5808 { 5809 PVBOXWDDMDISP_SWAPCHAIN pSwapchain; 5810 hr = vboxWddmSwapchainCreateIfForRc(pDevice, pRc, &pSwapchain); 5811 Assert(hr == S_OK); 5812 } 5813 } 5814 5815 vboxWddmRequestAllocFree(pDdiAllocate); 5816 } 5817 else 5818 { 5819 hr = E_OUTOFMEMORY; 5820 } 5821 } 5822 5823 if (hr == S_OK) 5824 pResource->hResource = pRc; 5825 else 5826 vboxResourceFree(pRc); 5827 } 5598 hr = E_OUTOFMEMORY; 5599 } 5600 } 5601 5602 if (hr == S_OK) 5603 pResource->hResource = pRc; 5828 5604 else 5829 { 5830 hr = E_OUTOFMEMORY; 5831 } 5832 5605 vboxResourceFree(pRc); 5833 5606 5834 5607 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice)); … … 5953 5726 hr = pDevice->RtCallbacks.pfnSetDisplayModeCb(pDevice->hDevice, &DdiDm); 5954 5727 Assert(hr == S_OK); 5955 #if 05956 if (hr == S_OK)5957 {5958 D3DDDICB_LOCK DdiLock = {0};5959 DdiLock.hAllocation = pAlloc->hAllocation;5960 DdiLock.Flags.LockEntire = 1;5961 DdiLock.Flags.ReadOnly = 1;5962 hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &DdiLock);5963 Assert(hr == S_OK);5964 if (hr == S_OK)5965 {5966 D3DLOCKED_RECT LockRect;5967 Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);5968 IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pAlloc->pD3DIf;5969 hr = pD3DIfSurf->LockRect(&LockRect, NULL /* RECT*/, D3DLOCK_DISCARD);5970 Assert(hr == S_OK);5971 if (hr == S_OK)5972 {5973 /** @todo: take pitch into account */5974 Assert(pAlloc->SurfDesc.pitch == LockRect.Pitch);5975 memcpy(LockRect.pBits, DdiLock.pData, LockRect.Pitch * pAlloc->SurfDesc.height);5976 hr = pD3DIfSurf->UnlockRect();5977 Assert(hr == S_OK);5978 }5979 5980 D3DDDICB_UNLOCK DdiUnlock = {0};5981 DdiUnlock.NumAllocations = 1;5982 DdiUnlock.phAllocations = &pAlloc->hAllocation;5983 hr = pDevice->RtCallbacks.pfnUnlockCb(pDevice->hDevice, &DdiUnlock);5984 Assert(hr == S_OK);5985 }5986 hr = S_OK;5987 }5988 #endif5989 5728 } 5990 5729 … … 7622 7361 } 7623 7362 7624 HRESULT APIENTRY OpenAdapter (__inout D3DDDIARG_OPENADAPTER* pOpenData) 7625 { 7626 VBOXDISP_DDI_PROLOGUE(); 7363 HRESULT APIENTRY OpenAdapter(__inout D3DDDIARG_OPENADAPTER* pOpenData) 7364 { 7365 VBOXDISP_DDI_PROLOGUE(); 7366 7627 7367 vboxVDbgPrint(("==> "__FUNCTION__"\n")); 7628 7368 -
trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp
r38112 r39245 699 699 Assert(!pDstRect->left); 700 700 Assert(!pSrcRect->left); 701 uint32_t cbOff = pDstAlloc->SurfDesc.pitch * pDstRect->top; 702 uint32_t cbSize = pDstAlloc->SurfDesc.pitch * dstHeight; 703 memcpy(pvDstSurf + cbOff, pvSrcSurf + cbOff, cbSize); 701 uint32_t cbDstOff = vboxWddmCalcOffXYrd(0 /* x */, pDstRect->top, pDstAlloc->SurfDesc.pitch, pDstAlloc->SurfDesc.format); 702 uint32_t cbSrcOff = vboxWddmCalcOffXYrd(0 /* x */, pSrcRect->top, pSrcAlloc->SurfDesc.pitch, pSrcAlloc->SurfDesc.format); 703 uint32_t cbSize = vboxWddmCalcSize(pDstAlloc->SurfDesc.pitch, dstHeight, pDstAlloc->SurfDesc.format); 704 memcpy(pvDstSurf + cbDstOff, pvSrcSurf + cbSrcOff, cbSize); 704 705 } 705 706 else 706 707 { 707 uint32_t offDstLineStart = pDstRect->left * pDstAlloc->SurfDesc.bpp >> 3; 708 uint32_t offDstLineEnd = ((pDstRect->left * pDstAlloc->SurfDesc.bpp + 7) >> 3) + ((pDstAlloc->SurfDesc.bpp * dstWidth + 7) >> 3); 709 uint32_t cbDstLine = offDstLineEnd - offDstLineStart; 710 uint32_t offDstStart = pDstAlloc->SurfDesc.pitch * pDstRect->top + offDstLineStart; 708 uint32_t cbDstLine = vboxWddmCalcRowSize(pDstRect->left, pDstRect->right, pDstAlloc->SurfDesc.format); 709 uint32_t offDstStart = vboxWddmCalcOffXYrd(pDstRect->left, pDstRect->top, pDstAlloc->SurfDesc.pitch, pDstAlloc->SurfDesc.format); 711 710 Assert(cbDstLine <= pDstAlloc->SurfDesc.pitch); 712 711 uint32_t cbDstSkip = pDstAlloc->SurfDesc.pitch; 713 712 uint8_t * pvDstStart = pvDstSurf + offDstStart; 714 713 715 uint32_t offSrcLineStart = pSrcRect->left * pSrcAlloc->SurfDesc.bpp >> 3; 716 uint32_t offSrcLineEnd = ((pSrcRect->left * pSrcAlloc->SurfDesc.bpp + 7) >> 3) + ((pSrcAlloc->SurfDesc.bpp * srcWidth + 7) >> 3); 717 uint32_t cbSrcLine = offSrcLineEnd - offSrcLineStart; 718 uint32_t offSrcStart = pSrcAlloc->SurfDesc.pitch * pSrcRect->top + offSrcLineStart; 714 uint32_t cbSrcLine = vboxWddmCalcRowSize(pSrcRect->left, pSrcRect->right, pSrcAlloc->SurfDesc.format); 715 uint32_t offSrcStart = vboxWddmCalcOffXYrd(pSrcRect->left, pSrcRect->top, pSrcAlloc->SurfDesc.pitch, pSrcAlloc->SurfDesc.format); 719 716 Assert(cbSrcLine <= pSrcAlloc->SurfDesc.pitch); 720 717 uint32_t cbSrcSkip = pSrcAlloc->SurfDesc.pitch; 721 718 const uint8_t * pvSrcStart = pvSrcSurf + offSrcStart; 722 719 720 uint32_t cRows = vboxWddmCalcNumRows(pDstRect->top, pDstRect->bottom, pDstAlloc->SurfDesc.format); 721 723 722 Assert(cbDstLine == cbSrcLine); 724 723 725 for (uint32_t i = 0; ; ++i)724 for (uint32_t i = 0; i < cRows; ++i) 726 725 { 727 726 memcpy (pvDstStart, pvSrcStart, cbDstLine); 728 if (i == dstHeight)729 break;730 727 pvDstStart += cbDstSkip; 731 728 pvSrcStart += cbSrcSkip; -
trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp
r39160 r39245 2247 2247 pAllocInfo->SurfDesc.format = pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Format; 2248 2248 pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pAllocInfo->SurfDesc.format); 2249 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Width, pAllocInfo->SurfDesc. bpp);2250 pAllocInfo->SurfDesc.cbSize = pAllocInfo->SurfDesc.pitch * pAllocInfo->SurfDesc.height;2249 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateSharedPrimarySurfaceData->Width, pAllocInfo->SurfDesc.format); 2250 pAllocInfo->SurfDesc.cbSize = vboxWddmCalcSize(pAllocInfo->SurfDesc.pitch, pAllocInfo->SurfDesc.height, pAllocInfo->SurfDesc.format); 2251 2251 pAllocInfo->SurfDesc.depth = 0; 2252 2252 pAllocInfo->SurfDesc.slicePitch = 0; … … 2266 2266 if (bpp != 0) 2267 2267 { 2268 UINT Pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Width, bpp);2268 UINT Pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Width, pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Format); 2269 2269 pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Pitch = Pitch; 2270 2270 … … 2279 2279 pAllocInfo->SurfDesc.format = pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Format; 2280 2280 pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pAllocInfo->SurfDesc.format); 2281 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Width, pAllocInfo->SurfDesc. bpp);2282 pAllocInfo->SurfDesc.cbSize = pAllocInfo->SurfDesc.pitch * pAllocInfo->SurfDesc.height;2281 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateShadowSurfaceData->Width, pAllocInfo->SurfDesc.format); 2282 pAllocInfo->SurfDesc.cbSize = vboxWddmCalcSize(pAllocInfo->SurfDesc.pitch, pAllocInfo->SurfDesc.height, pAllocInfo->SurfDesc.format); 2283 2283 pAllocInfo->SurfDesc.depth = 0; 2284 2284 pAllocInfo->SurfDesc.slicePitch = 0; … … 2311 2311 pAllocInfo->SurfDesc.format = D3DDDIFMT_X8R8G8B8; /* staging has always always D3DDDIFMT_X8R8G8B8 */ 2312 2312 pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pAllocInfo->SurfDesc.format); 2313 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Width, pAllocInfo->SurfDesc. bpp);2314 pAllocInfo->SurfDesc.cbSize = pAllocInfo->SurfDesc.pitch * pAllocInfo->SurfDesc.height;2313 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pGetStandardAllocationDriverData->pCreateStagingSurfaceData->Width, pAllocInfo->SurfDesc.format); 2314 pAllocInfo->SurfDesc.cbSize = vboxWddmCalcSize(pAllocInfo->SurfDesc.pitch, pAllocInfo->SurfDesc.height, pAllocInfo->SurfDesc.format); 2315 2315 pAllocInfo->SurfDesc.depth = 0; 2316 2316 pAllocInfo->SurfDesc.slicePitch = 0;
Note:
See TracChangeset
for help on using the changeset viewer.