Changeset 80372 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Aug 21, 2019 2:32:40 PM (5 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp
- Files:
-
- 10 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/Makefile.kmk
r76553 r80372 107 107 VBoxDispD3D_DEFS += VBOX_WITH_VIDEOHWACCEL 108 108 endif 109 ifdef VBOX_WDDMDISP_WITH_PROFILE110 VBoxDispD3D_DEFS += VBOX_WDDMDISP_WITH_PROFILE111 endif112 ifdef VBOXWDDM_TEST_UHGSMI113 VBoxDispD3D_DEFS += VBOXWDDM_TEST_UHGSMI114 endif115 ifdef VBOX_WITH_CROGL116 VBoxDispD3D_DEFS += VBOX_WITH_CROGL117 endif118 109 VBoxDispD3D_INCS = \ 119 110 ../../../include \ … … 125 116 wddm/VBoxDispD3D.cpp \ 126 117 wddm/VBoxDispD3DIf.cpp \ 127 wddm/VBoxDispCm.cpp \128 118 wddm/VBoxDispDbg.cpp \ 129 119 wddm/VBoxD3DIf.cpp \ 130 120 wddm/VBoxDispD3D.rc \ 131 121 wddm/VBoxDispD3D.def 132 ifdef VBOX_WITH_CRHGSMI133 VBoxDispD3D_DEFS += VBOX_WITH_CRHGSMI134 endif135 122 VBoxDispD3D_LIBS = \ 136 123 $(VBOX_LIB_IPRT_GUEST_R3) \ … … 138 125 Psapi.lib \ 139 126 $(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger$(VBOX_SUFF_LIB) \ 140 $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt$(VBOX_SUFF_LIB) \ 141 $(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi$(VBOX_SUFF_LIB) 127 $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt$(VBOX_SUFF_LIB) 142 128 143 129 ifdef VBOX_WITH_MESA3D … … 179 165 Psapi.lib \ 180 166 $(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger-x86$(VBOX_SUFF_LIB) \ 181 $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt-x86$(VBOX_SUFF_LIB) \ 182 $(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi-x86$(VBOX_SUFF_LIB) 167 $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt-x86$(VBOX_SUFF_LIB) 183 168 VBoxDispD3D-x86_DEFS = $(VBoxDispD3D_DEFS) VBOX_WDDM_WOW64 184 185 ifdef VBOX_WITH_CRHGSMI186 #187 # VBoxCrHgsmi - Chromium HGSMI API library188 #189 LIBRARIES += VBoxCrHgsmi190 VBoxCrHgsmi_TEMPLATE = VBoxGuestR3Lib191 VBoxCrHgsmi_SDKS = ReorderCompilerIncs $(VBOX_WINDDK_GST_WLH)192 #use same defines as VBoxDispD3D to ensure structure definitions match193 VBoxCrHgsmi_DEFS = $(subst VBOXWDDMDISP,IN_VBOXCRHGSMI,$(VBoxDispD3D_DEFS))194 VBoxCrHgsmi_INCS = \195 ../../../include \196 .. \197 $(VBOX_PATH_CROGL_INCLUDE) \198 $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \199 $(VBOX_GRAPHICS_INCS)200 ifdef VBOX_WITH_MESA3D201 VBoxCrHgsmi_INCS += $(VBOX_PATH_3D)/win/include202 endif203 VBoxCrHgsmi_SOURCES = \204 wddm/VBoxCrHgsmi.cpp \205 wddm/VBoxDispDbg.cpp \206 wddm/VBoxUhgsmiKmt.cpp \207 wddm/VBoxUhgsmiBase.cpp \208 wddm/VBoxUhgsmiDisp.cpp209 210 #211 # 64-bit systems needs a 32-bit version of VBoxCrHgsmi.212 #213 LIBRARIES.amd64 += VBoxCrHgsmi-x86214 VBoxCrHgsmi-x86_TEMPLATE = VBoxGuestR3Lib215 VBoxCrHgsmi-x86_EXTENDS = VBoxCrHgsmi216 VBoxCrHgsmi-x86_BLD_TRG_ARCH = x86217 VBoxCrHgsmi-x86_DEFS = $(VBoxCrHgsmi_DEFS) VBOX_WDDM_WOW64218 endif #VBOX_WITH_CRHGSMI219 169 220 170 include $(PATH_SUB_CURRENT)/wddm/shared/Makefile.kmk -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.cpp
r76553 r80372 183 183 } 184 184 185 /**/186 187 /* D3DIf API */188 static HRESULT vboxDispD3DIfSurfSynchMem(PVBOXWDDMDISP_RESOURCE pRc)189 {190 if (pRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM)191 {192 return S_OK;193 }194 195 for (UINT i = 0; i < pRc->cAllocations; ++i)196 {197 D3DLOCKED_RECT Rect;198 HRESULT hr = VBoxD3DIfLockRect(pRc, i, &Rect, NULL, D3DLOCK_DISCARD);199 if (FAILED(hr))200 {201 WARN(("VBoxD3DIfLockRect failed, hr(0x%x)", hr));202 return hr;203 }204 205 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];206 Assert(pAlloc->pvMem);207 208 VBoxD3DIfLockUnlockMemSynch(pAlloc, &Rect, NULL, true /*bool bToLockInfo*/);209 210 hr = VBoxD3DIfUnlockRect(pRc, i);211 Assert(SUCCEEDED(hr));212 }213 return S_OK;214 }215 216 185 void VBoxD3DIfLockUnlockMemSynch(PVBOXWDDMDISP_ALLOCATION pAlloc, D3DLOCKED_RECT *pLockInfo, RECT *pRect, bool bToLockInfo) 217 186 { … … 421 390 return hr; 422 391 } 423 424 HRESULT VBoxD3DIfCreateForRc(struct VBOXWDDMDISP_RESOURCE *pRc)425 {426 PVBOXWDDMDISP_DEVICE pDevice = pRc->pDevice;427 HRESULT hr = E_FAIL;428 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);429 430 if (VBOXWDDMDISP_IS_TEXTURE(pRc->RcDesc.fFlags))431 {432 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0];433 IDirect3DBaseTexture9 *pD3DIfTex = NULL; /* Shut up MSC. */434 HANDLE hSharedHandle = pAllocation->hSharedHandle;435 void **pavClientMem = NULL;436 VBOXDISP_D3DIFTYPE enmD3DIfType = VBOXDISP_D3DIFTYPE_UNDEFINED;437 hr = S_OK;438 if (pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM)439 {440 pavClientMem = (void**)RTMemAlloc(sizeof (pavClientMem[0]) * pRc->cAllocations);441 Assert(pavClientMem);442 if (pavClientMem)443 {444 for (UINT i = 0; i < pRc->cAllocations; ++i)445 {446 Assert(pRc->aAllocations[i].pvMem);447 pavClientMem[i] = pRc->aAllocations[i].pvMem;448 }449 }450 else451 hr = E_FAIL;452 }453 454 #ifdef DEBUG455 if (!pRc->RcDesc.fFlags.CubeMap)456 {457 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[0];458 uint32_t tstW = pAlloc->SurfDesc.width;459 uint32_t tstH = pAlloc->SurfDesc.height;460 for (UINT i = 1; i < pRc->cAllocations; ++i)461 {462 tstW /= 2;463 tstH /= 2;464 pAlloc = &pRc->aAllocations[i];465 Assert((pAlloc->SurfDesc.width == tstW) || (!tstW && (pAlloc->SurfDesc.width==1)));466 Assert((pAlloc->SurfDesc.height == tstH) || (!tstH && (pAlloc->SurfDesc.height==1)));467 }468 }469 #endif470 471 if (SUCCEEDED(hr))472 {473 if (pRc->RcDesc.fFlags.CubeMap)474 {475 if ( (pAllocation->SurfDesc.width!=pAllocation->SurfDesc.height)476 || (pRc->cAllocations%6!=0))477 {478 WARN(("unexpected cubemap texture config: (%d ; %d), allocs: %d",479 pAllocation->SurfDesc.width, pAllocation->SurfDesc.height, pRc->cAllocations));480 hr = E_INVALIDARG;481 }482 else483 {484 hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9CreateCubeTexture((IDirect3DDevice9Ex *)pDevice9If,485 pAllocation->SurfDesc.d3dWidth,486 VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc),487 vboxDDI2D3DUsage(pRc->RcDesc.fFlags),488 vboxDDI2D3DFormat(pRc->RcDesc.enmFormat),489 vboxDDI2D3DPool(pRc->RcDesc.enmPool),490 (IDirect3DCubeTexture9**)&pD3DIfTex,491 #ifdef VBOXWDDMDISP_DEBUG_NOSHARED492 NULL,493 #else494 pRc->RcDesc.fFlags.SharedResource ? &hSharedHandle : NULL,495 #endif496 pavClientMem);497 Assert(hr == S_OK);498 Assert(pD3DIfTex);499 enmD3DIfType = VBOXDISP_D3DIFTYPE_CUBE_TEXTURE;500 }501 }502 else if (pRc->RcDesc.fFlags.Volume)503 {504 hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9CreateVolumeTexture((IDirect3DDevice9Ex *)pDevice9If,505 pAllocation->SurfDesc.d3dWidth,506 pAllocation->SurfDesc.height,507 pAllocation->SurfDesc.depth,508 pRc->cAllocations,509 vboxDDI2D3DUsage(pRc->RcDesc.fFlags),510 vboxDDI2D3DFormat(pRc->RcDesc.enmFormat),511 vboxDDI2D3DPool(pRc->RcDesc.enmPool),512 (IDirect3DVolumeTexture9**)&pD3DIfTex,513 #ifdef VBOXWDDMDISP_DEBUG_NOSHARED514 NULL,515 #else516 pRc->RcDesc.fFlags.SharedResource ? &hSharedHandle : NULL,517 #endif518 pavClientMem);519 Assert(hr == S_OK);520 Assert(pD3DIfTex);521 enmD3DIfType = VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE;522 }523 else524 {525 hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9CreateTexture((IDirect3DDevice9Ex *)pDevice9If,526 pAllocation->SurfDesc.d3dWidth,527 pAllocation->SurfDesc.height,528 pRc->cAllocations,529 vboxDDI2D3DUsage(pRc->RcDesc.fFlags),530 vboxDDI2D3DFormat(pRc->RcDesc.enmFormat),531 vboxDDI2D3DPool(pRc->RcDesc.enmPool),532 (IDirect3DTexture9**)&pD3DIfTex,533 #ifdef VBOXWDDMDISP_DEBUG_NOSHARED534 NULL,535 #else536 pRc->RcDesc.fFlags.SharedResource ? &hSharedHandle : NULL,537 #endif538 pavClientMem);539 Assert(hr == S_OK);540 Assert(pD3DIfTex);541 enmD3DIfType = VBOXDISP_D3DIFTYPE_TEXTURE;542 }543 544 if (SUCCEEDED(hr))545 {546 Assert(pD3DIfTex);547 Assert(enmD3DIfType != VBOXDISP_D3DIFTYPE_UNDEFINED);548 #ifndef VBOXWDDMDISP_DEBUG_NOSHARED549 Assert(!!(pRc->RcDesc.fFlags.SharedResource) == !!(hSharedHandle));550 #endif551 for (UINT i = 0; i < pRc->cAllocations; ++i)552 {553 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];554 pAlloc->enmD3DIfType = enmD3DIfType;555 pAlloc->pD3DIf = pD3DIfTex;556 pAlloc->hSharedHandle = hSharedHandle;557 if (i > 0)558 pD3DIfTex->AddRef();559 }560 }561 }562 563 if (pavClientMem)564 RTMemFree(pavClientMem);565 }566 else if (pRc->RcDesc.fFlags.RenderTarget || pRc->RcDesc.fFlags.Primary)567 {568 for (UINT i = 0; i < pRc->cAllocations; ++i)569 {570 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];571 HANDLE hSharedHandle = pAllocation->hSharedHandle;572 IDirect3DSurface9 *pD3D9Surf = NULL; /* Shut up MSC. */573 if (574 #ifdef VBOX_WITH_CROGL575 (pDevice->pAdapter->u32VBox3DCaps & CR_VBOX_CAP_TEX_PRESENT) ||576 #endif577 pAllocation->enmType == VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC)578 {579 hr = pDevice9If->CreateRenderTarget(pAllocation->SurfDesc.width,580 pAllocation->SurfDesc.height,581 vboxDDI2D3DFormat(pRc->RcDesc.enmFormat),582 vboxDDI2D3DMultiSampleType(pRc->RcDesc.enmMultisampleType),583 pRc->RcDesc.MultisampleQuality,584 !pRc->RcDesc.fFlags.NotLockable /* BOOL Lockable */,585 &pD3D9Surf,586 #ifdef VBOXWDDMDISP_DEBUG_NOSHARED587 NULL588 #else589 pRc->RcDesc.fFlags.SharedResource ? &hSharedHandle : NULL590 #endif591 );592 Assert(hr == S_OK);593 }594 else if (pAllocation->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE)595 {596 do {597 BOOL bNeedPresent;598 if (pRc->cAllocations != 1)599 {600 WARN(("unexpected config: more than one (%d) shared primary for rc", pRc->cAllocations));601 hr = E_FAIL;602 break;603 }604 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainFindCreate(pDevice, pAllocation, &bNeedPresent);605 Assert(bNeedPresent);606 if (!pSwapchain)607 {608 WARN(("vboxWddmSwapchainFindCreate failed"));609 hr = E_OUTOFMEMORY;610 break;611 }612 613 hr = vboxWddmSwapchainChkCreateIf(pDevice, pSwapchain);614 if (!SUCCEEDED(hr))615 {616 WARN(("vboxWddmSwapchainChkCreateIf failed hr 0x%x", hr));617 Assert(pAllocation->enmD3DIfType == VBOXDISP_D3DIFTYPE_UNDEFINED);618 Assert(!pAllocation->pD3DIf);619 vboxWddmSwapchainDestroy(pDevice, pSwapchain);620 break;621 }622 623 Assert(pAllocation->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);624 Assert(pAllocation->pD3DIf);625 pD3D9Surf = (IDirect3DSurface9*)pAllocation->pD3DIf;626 break;627 } while (0);628 }629 else630 {631 WARN(("unexpected alloc type %d", pAllocation->enmType));632 hr = E_FAIL;633 }634 635 if (SUCCEEDED(hr))636 {637 Assert(pD3D9Surf);638 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;639 pAllocation->pD3DIf = pD3D9Surf;640 #ifndef VBOXWDDMDISP_DEBUG_NOSHARED641 Assert(!!(pRc->RcDesc.fFlags.SharedResource) == !!(hSharedHandle));642 #endif643 pAllocation->hSharedHandle = hSharedHandle;644 hr = S_OK;645 continue;646 #if 0 /* unreachable */647 /* fail branch */648 pD3D9Surf->Release();649 #endif650 }651 652 for (UINT j = 0; j < i; ++j)653 {654 pRc->aAllocations[j].pD3DIf->Release();655 }656 break;657 }658 659 if (SUCCEEDED(hr))660 {661 if (pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM)662 {663 Assert(0);664 vboxDispD3DIfSurfSynchMem(pRc);665 }666 }667 }668 else if (pRc->RcDesc.fFlags.ZBuffer)669 {670 for (UINT i = 0; i < pRc->cAllocations; ++i)671 {672 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];673 IDirect3DSurface9 *pD3D9Surf;674 hr = pDevice9If->CreateDepthStencilSurface(pAllocation->SurfDesc.width,675 pAllocation->SurfDesc.height,676 vboxDDI2D3DFormat(pRc->RcDesc.enmFormat),677 vboxDDI2D3DMultiSampleType(pRc->RcDesc.enmMultisampleType),678 pRc->RcDesc.MultisampleQuality,679 TRUE /** @todo BOOL Discard */,680 &pD3D9Surf,681 NULL /*HANDLE* pSharedHandle*/);682 Assert(hr == S_OK);683 if (hr == S_OK)684 {685 Assert(pD3D9Surf);686 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;687 pAllocation->pD3DIf = pD3D9Surf;688 }689 else690 {691 for (UINT j = 0; j < i; ++j)692 {693 pRc->aAllocations[j].pD3DIf->Release();694 }695 break;696 }697 }698 699 if (SUCCEEDED(hr))700 {701 if (pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM)702 {703 vboxDispD3DIfSurfSynchMem(pRc);704 }705 }706 }707 else if (pRc->RcDesc.fFlags.VertexBuffer)708 {709 for (UINT i = 0; i < pRc->cAllocations; ++i)710 {711 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];712 IDirect3DVertexBuffer9 *pD3D9VBuf;713 hr = pDevice9If->CreateVertexBuffer(pAllocation->SurfDesc.width,714 vboxDDI2D3DUsage(pRc->RcDesc.fFlags)715 & (~D3DUSAGE_DYNAMIC) /* <- avoid using dynamic to ensure wine does not switch do user buffer */716 ,717 pRc->RcDesc.Fvf,718 vboxDDI2D3DPool(pRc->RcDesc.enmPool),719 &pD3D9VBuf,720 NULL /*HANDLE* pSharedHandle*/);721 Assert(hr == S_OK);722 if (hr == S_OK)723 {724 Assert(pD3D9VBuf);725 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_VERTEXBUFFER;726 pAllocation->pD3DIf = pD3D9VBuf;727 }728 else729 {730 for (UINT j = 0; j < i; ++j)731 {732 pRc->aAllocations[j].pD3DIf->Release();733 }734 break;735 }736 }737 738 if (SUCCEEDED(hr))739 {740 if (pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM)741 {742 vboxDispD3DIfSurfSynchMem(pRc);743 }744 }745 }746 else if (pRc->RcDesc.fFlags.IndexBuffer)747 {748 for (UINT i = 0; i < pRc->cAllocations; ++i)749 {750 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];751 IDirect3DIndexBuffer9 *pD3D9IBuf;752 hr = pDevice9If->CreateIndexBuffer(pAllocation->SurfDesc.width,753 vboxDDI2D3DUsage(pRc->RcDesc.fFlags),754 vboxDDI2D3DFormat(pRc->RcDesc.enmFormat),755 vboxDDI2D3DPool(pRc->RcDesc.enmPool),756 &pD3D9IBuf,757 NULL /*HANDLE* pSharedHandle*/758 );759 Assert(hr == S_OK);760 if (hr == S_OK)761 {762 Assert(pD3D9IBuf);763 pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_INDEXBUFFER;764 pAllocation->pD3DIf = pD3D9IBuf;765 }766 else767 {768 for (UINT j = 0; j < i; ++j)769 {770 pRc->aAllocations[j].pD3DIf->Release();771 }772 break;773 }774 }775 776 if (SUCCEEDED(hr))777 {778 if (pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM)779 {780 vboxDispD3DIfSurfSynchMem(pRc);781 }782 }783 }784 else785 {786 hr = E_FAIL;787 WARN(("unsupported rc flags, %d", pRc->RcDesc.fFlags.Value));788 }789 790 return hr;791 }792 793 VOID VBoxD3DIfFillPresentParams(D3DPRESENT_PARAMETERS *pParams, PVBOXWDDMDISP_RESOURCE pRc, UINT cRTs)794 {795 Assert(cRTs);796 memset(pParams, 0, sizeof (D3DPRESENT_PARAMETERS));797 pParams->BackBufferWidth = pRc->aAllocations[0].SurfDesc.width;798 pParams->BackBufferHeight = pRc->aAllocations[0].SurfDesc.height;799 pParams->BackBufferFormat = vboxDDI2D3DFormat(pRc->aAllocations[0].SurfDesc.format);800 pParams->BackBufferCount = cRTs - 1;801 pParams->MultiSampleType = vboxDDI2D3DMultiSampleType(pRc->RcDesc.enmMultisampleType);802 pParams->MultiSampleQuality = pRc->RcDesc.MultisampleQuality;803 #if 0 //def VBOXDISP_WITH_WINE_BB_WORKAROUND /* this does not work so far any way :( */804 if (cRTs == 1)805 pParams->SwapEffect = D3DSWAPEFFECT_COPY;806 else807 #endif808 if (pRc->RcDesc.fFlags.DiscardRenderTarget)809 pParams->SwapEffect = D3DSWAPEFFECT_DISCARD;810 pParams->Windowed = TRUE;811 }812 813 HRESULT VBoxD3DIfDeviceCreateDummy(PVBOXWDDMDISP_DEVICE pDevice)814 {815 VBOXWDDMDISP_RESOURCE Rc;816 vboxWddmResourceInit(&Rc, 1);817 818 Rc.RcDesc.enmFormat = D3DDDIFMT_A8R8G8B8;819 Rc.RcDesc.enmPool = D3DDDIPOOL_LOCALVIDMEM;820 Rc.RcDesc.enmMultisampleType = D3DDDIMULTISAMPLE_NONE;821 Rc.RcDesc.MultisampleQuality = 0;822 PVBOXWDDMDISP_ALLOCATION pAlloc = &Rc.aAllocations[0];823 pAlloc->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;824 pAlloc->SurfDesc.width = 0x4;825 pAlloc->SurfDesc.height = 0x4;826 pAlloc->SurfDesc.format = D3DDDIFMT_A8R8G8B8;827 Assert(!pDevice->pDevice9If);828 VBOXWINEEX_D3DPRESENT_PARAMETERS Params;829 VBoxD3DIfFillPresentParams(&Params.Base, &Rc, 2);830 #ifdef VBOX_WITH_CRHGSMI831 Params.pHgsmi = &pDevice->Uhgsmi.BasePrivate.Base;832 #else833 Params.pHgsmi = NULL;834 #endif835 DWORD fFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING836 | D3DCREATE_FPU_PRESERVE; /* Do not allow Wine to mess with FPU control word. */837 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;838 IDirect3DDevice9 * pDevice9If = NULL;839 840 HRESULT hr = pAdapter->D3D.pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, fFlags, &Params.Base, &pDevice9If);841 if (SUCCEEDED(hr))842 {843 int32_t hostId = 0;844 hr = pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9GetHostId((IDirect3DDevice9Ex*)pDevice9If, &hostId);845 if (SUCCEEDED(hr))846 {847 Assert(hostId);848 Assert(pDevice->DefaultContext.ContextInfo.hContext);849 850 VBOXDISPIFESCAPE Data;851 Data.escapeCode = VBOXESC_SETCTXHOSTID;852 Data.u32CmdSpecific = (uint32_t)hostId;853 D3DDDICB_ESCAPE DdiEscape = {0};854 DdiEscape.hContext = pDevice->DefaultContext.ContextInfo.hContext;855 DdiEscape.hDevice = pDevice->hDevice;856 // DdiEscape.Flags.Value = 0;857 DdiEscape.pPrivateDriverData = &Data;858 DdiEscape.PrivateDriverDataSize = sizeof (Data);859 hr = pDevice->RtCallbacks.pfnEscapeCb(pDevice->pAdapter->hAdapter, &DdiEscape);860 if (SUCCEEDED(hr))861 {862 pDevice->pDevice9If = pDevice9If;863 return S_OK;864 }865 else866 WARN(("pfnEscapeCb VBOXESC_SETCTXHOSTID failed hr 0x%x", hr));867 }868 else869 WARN(("pfnVBoxWineExD3DDev9GetHostId failed hr 0x%x", hr));870 871 pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Term((IDirect3DDevice9Ex *)pDevice9If);872 }873 else874 WARN(("CreateDevice failed hr 0x%x", hr));875 876 return hr;877 }878 879 static int vboxD3DIfSetHostId(PVBOXWDDMDISP_ALLOCATION pAlloc, uint32_t hostID, uint32_t *pHostID)880 {881 struct VBOXWDDMDISP_RESOURCE *pRc = pAlloc->pRc;882 PVBOXWDDMDISP_DEVICE pDevice = pRc->pDevice;883 884 AssertReturn(pDevice->DefaultContext.ContextInfo.hContext, VERR_GENERAL_FAILURE);885 886 VBOXDISPIFESCAPE_SETALLOCHOSTID SetHostID = {0};887 SetHostID.EscapeHdr.escapeCode = VBOXESC_SETALLOCHOSTID;888 SetHostID.hostID = hostID;889 SetHostID.hAlloc = pAlloc->hAllocation;890 891 D3DDDICB_ESCAPE DdiEscape = {0};892 DdiEscape.hContext = pDevice->DefaultContext.ContextInfo.hContext;893 DdiEscape.hDevice = pDevice->hDevice;894 DdiEscape.Flags.Value = 0;895 DdiEscape.Flags.HardwareAccess = 1;896 DdiEscape.pPrivateDriverData = &SetHostID;897 DdiEscape.PrivateDriverDataSize = sizeof (SetHostID);898 HRESULT hr = pDevice->RtCallbacks.pfnEscapeCb(pDevice->pAdapter->hAdapter, &DdiEscape);899 if (SUCCEEDED(hr))900 {901 if (pHostID)902 *pHostID = SetHostID.EscapeHdr.u32CmdSpecific;903 904 return SetHostID.rc;905 }906 else907 WARN(("pfnEscapeCb VBOXESC_SETALLOCHOSTID failed hr 0x%x", hr));908 909 return VERR_GENERAL_FAILURE;910 }911 912 IUnknown* vboxD3DIfCreateSharedPrimary(PVBOXWDDMDISP_ALLOCATION pAlloc)913 {914 IDirect3DSurface9 *pSurfIf;915 struct VBOXWDDMDISP_RESOURCE *pRc = pAlloc->pRc;916 PVBOXWDDMDISP_DEVICE pDevice = pRc->pDevice;917 918 HRESULT hr = VBoxD3DIfCreateForRc(pRc);919 if (!SUCCEEDED(hr))920 {921 WARN(("VBoxD3DIfCreateForRc failed, hr 0x%x", hr));922 return NULL;923 }924 925 Assert(pAlloc->pD3DIf);926 Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);927 Assert(pAlloc->pRc->RcDesc.fFlags.SharedResource);928 929 hr = VBoxD3DIfSurfGet(pRc, pAlloc->iAlloc, &pSurfIf);930 if (!SUCCEEDED(hr))931 {932 WARN(("VBoxD3DIfSurfGet failed hr %#x", hr));933 return NULL;934 }935 936 uint32_t hostID, usedHostId;937 hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DSurf9GetHostId(pSurfIf, &hostID);938 if (SUCCEEDED(hr))939 {940 Assert(hostID);941 int rc = vboxD3DIfSetHostId(pAlloc, hostID, &usedHostId);942 if (!RT_SUCCESS(rc))943 {944 if (rc == VERR_NOT_EQUAL)945 {946 WARN(("another hostId % is in use, using it instead", usedHostId));947 Assert(hostID != usedHostId);948 Assert(usedHostId);949 pSurfIf->Release();950 pSurfIf = NULL;951 for (UINT i = 0; i < pRc->cAllocations; ++i)952 {953 PVBOXWDDMDISP_ALLOCATION pCurAlloc = &pRc->aAllocations[i];954 if (pCurAlloc->pD3DIf)955 {956 pCurAlloc->pD3DIf->Release();957 pCurAlloc->pD3DIf = NULL;958 }959 }960 961 pAlloc->hSharedHandle = (HANDLE)(uintptr_t)usedHostId;962 963 hr = VBoxD3DIfCreateForRc(pRc);964 if (!SUCCEEDED(hr))965 {966 WARN(("VBoxD3DIfCreateForRc failed, hr 0x%x", hr));967 return NULL;968 }969 970 hr = VBoxD3DIfSurfGet(pRc, pAlloc->iAlloc, &pSurfIf);971 if (!SUCCEEDED(hr))972 {973 WARN(("VBoxD3DIfSurfGet failed hr %#x", hr));974 return NULL;975 }976 }977 else978 {979 WARN(("vboxD3DIfSetHostId failed %#x, ignoring", hr));980 hr = S_OK;981 hostID = 0;982 usedHostId = 0;983 }984 }985 else986 {987 Assert(hostID == usedHostId);988 }989 }990 else991 WARN(("pfnVBoxWineExD3DSurf9GetHostId failed, hr 0x%x", hr));992 993 pSurfIf->Release();994 pSurfIf = NULL;995 996 return pAlloc->pD3DIf;997 } -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
r79792 r80372 26 26 #include <VBox/VBoxGuestLib.h> 27 27 28 #include "VBoxDispD3DCmn.h"29 28 #include "VBoxDispD3D.h" 30 #include <VBoxCrHgsmi.h>29 #include "VBoxDispDbg.h" 31 30 32 31 #include <Psapi.h> 33 34 #ifdef VBOX_WDDMDISP_WITH_PROFILE35 36 volatile uint32_t g_u32VBoxDispProfileFunctionLoggerIndex = 0;37 38 /* the number of frames to collect data before doing dump/reset */39 #define VBOXDISPPROFILE_DDI_DUMP_FRAME_COUNT 0x2040 41 struct VBOXDISPPROFILE_GLOBAL {42 VBoxDispProfileFpsCounter ProfileDdiFps;43 VBoxDispProfileSet ProfileDdiFunc;44 } g_VBoxDispProfile;45 46 /* uncomment to enable particular logging */47 /* allows dumping fps + how much time is spent in ddi functions in comparison with the rest time */48 //# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_ENABLE49 /* allows dumping time spent in each function and the number of calls made for any given function */50 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_ENABLE51 52 # ifdef VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_ENABLE53 54 class VBoxDispProfileDevicePostProcess55 {56 public:57 VBoxDispProfileDevicePostProcess(PVBOXWDDMDISP_DEVICE pDevice) :58 m_pDevice(pDevice)59 {}60 61 void postProcess()62 {63 if (m_pDevice->pDevice9If && m_pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Finish)64 m_pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Finish((IDirect3DDevice9Ex *)m_pDevice->pDevice9If);65 }66 private:67 PVBOXWDDMDISP_DEVICE m_pDevice;68 };69 70 //static VBoxDispProfileSet g_VBoxDispProfileDDI("D3D_DDI");71 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_DEV(_pObj) VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE((_pObj)->ProfileDdiFunc, VBoxDispProfileDevicePostProcess, VBoxDispProfileDevicePostProcess(_pObj))72 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_BASE(_pObj) VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE((_pObj)->ProfileDdiFunc, VBoxDispProfileDummyPostProcess, VBoxDispProfileDummyPostProcess())73 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj) do {\74 (_pObj)->ProfileDdiFunc.dump(_pObj); \75 } while (0)76 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj) do {\77 (_pObj)->ProfileDdiFunc.resetEntries();\78 } while (0)79 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DISABLE_CURRENT() do {\80 VBOXDISPPROFILE_FUNCTION_LOGGER_DISABLE_CURRENT();\81 } while (0)82 83 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_LOG_AND_DISABLE_CURRENT() VBOXDISPPROFILE_FUNCTION_LOGGER_LOG_AND_DISABLE_CURRENT()84 85 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pObj) do { \86 if (!((_pObj)->ProfileDdiFunc.reportIteration() % VBOXDISPPROFILE_DDI_DUMP_FRAME_COUNT) /*&& !VBOXVDBG_IS_DWM()*/) {\87 VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj); \88 VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj); \89 } \90 } while (0)91 92 # else93 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_DEV(_pObj) do {} while(0)94 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_BASE(_pObj) do {} while(0)95 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj) do {} while(0)96 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj) do {} while(0)97 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DISABLE_CURRENT() do {} while (0)98 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_LOG_AND_DISABLE_CURRENT() do {} while (0)99 # define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pDev) do {} while (0)100 # endif101 102 # ifdef VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_ENABLE103 //static VBoxDispProfileFpsCounter g_VBoxDispFpsDDI(64);104 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj) VBOXDISPPROFILE_STATISTIC_LOGGER_DEFINE(&(_pObj)->ProfileDdiFps, VBoxDispProfileDummyPostProcess, VBoxDispProfileDummyPostProcess())105 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DISABLE_CURRENT() do {\106 VBOXDISPPROFILE_STATISTIC_LOGGER_DISABLE_CURRENT();\107 } while (0)108 109 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DUMP(_pObj) do { \110 double fps = (_pObj)->ProfileDdiFps.GetFps(); \111 double cps = (_pObj)->ProfileDdiFps.GetCps(); \112 double tup = (_pObj)->ProfileDdiFps.GetTimeProcPercent(); \113 VBOXDISPPROFILE_DUMP(("[0x%p]: fps: %f, cps: %.1f, host %.1f%%", (_pObj), fps, cps, tup)); \114 } while (0)115 116 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_REPORT_FRAME(_pObj) do { \117 (_pObj)->ProfileDdiFps.ReportFrame(); \118 if(!((_pObj)->ProfileDdiFps.GetNumFrames() % VBOXDISPPROFILE_DDI_DUMP_FRAME_COUNT)) \119 { \120 VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DUMP(_pObj); \121 } \122 } while (0)123 124 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_LOG_AND_DISABLE_CURRENT() VBOXDISPPROFILE_STATISTIC_LOGGER_LOG_AND_DISABLE_CURRENT()125 # else126 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj) do {} while(0)127 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DISABLE_CURRENT() do {} while (0)128 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_LOG_AND_DISABLE_CURRENT() do {} while (0)129 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_REPORT_FRAME(_pDev) do {} while (0)130 # define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DUMP(_pObj) do {} while (0)131 # endif132 133 # define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_DEV(_pObj) \134 VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_DEV(_pObj); \135 VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj);136 137 # define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE(_pObj) \138 VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_BASE(_pObj); \139 VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj);140 141 # define VBOXDISPPROFILE_DDI_LOG_AND_DISABLE_CURRENT() \142 VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_LOG_AND_DISABLE_CURRENT(); \143 VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_LOG_AND_DISABLE_CURRENT();144 145 # define VBOXDISPPROFILE_DDI_REPORT_FRAME(_pDev) do {\146 VBOXDISPPROFILE_DDI_LOG_AND_DISABLE_CURRENT(); \147 VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_REPORT_FRAME(_pDev); \148 VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pDev); \149 } while (0)150 151 #if 0152 # define VBOXDISPPROFILE_DDI_REPORT_FLUSH(_pDev) do {\153 VBOXDISPPROFILE_DDI_LOG_AND_DISABLE_CURRENT(); \154 VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_REPORT_FRAME(_pDev); \155 VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pDev); \156 } while (0)157 #else158 # define VBOXDISPPROFILE_DDI_REPORT_FLUSH(_pDev) do {} while (0)159 #endif160 161 # define VBOXDISPPROFILE_DDI_INIT_CMN(_pObj, _name, _cEntries) do { \162 (_pObj)->ProfileDdiFps = VBoxDispProfileFpsCounter(); \163 (_pObj)->ProfileDdiFps.init(_cEntries); \164 (_pObj)->ProfileDdiFunc = VBoxDispProfileSet(_name); \165 } while (0)166 167 # define VBOXDISPPROFILE_DDI_TERM_CMN(_pObj) do { \168 (_pObj)->ProfileDdiFps.term(); \169 } while (0)170 171 # define VBOXDISPPROFILE_DDI_TERM(_pObj) do {\172 VBOXDISPPROFILE_DDI_LOG_AND_DISABLE_CURRENT(); \173 VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj); \174 VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj); \175 VBOXDISPPROFILE_DDI_TERM_CMN(_pObj); \176 } while (0)177 178 # define VBOXDISPPROFILE_DDI_PRINT(_m) VBOXDISPPROFILE_DUMP(_m)179 180 # define VBOXDISPPROFILE_DDI_INIT_GLBL() VBOXDISPPROFILE_DDI_INIT_CMN(&g_VBoxDispProfile, "DDI_Adp", 64)181 # define VBOXDISPPROFILE_DDI_INIT_ADP(_pAdp) VBOXDISPPROFILE_DDI_INIT_CMN(_pAdp, "DDI_Adp", 64)182 # define VBOXDISPPROFILE_DDI_INIT_DEV(_pDev) VBOXDISPPROFILE_DDI_INIT_CMN(_pDev, "DDI_Dev", 64)183 #else184 # define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_DEV(_pObj) do {} while (0)185 # define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE(_pObj) do {} while (0)186 # define VBOXDISPPROFILE_DDI_REPORT_FRAME(_pDev) do {} while (0)187 # define VBOXDISPPROFILE_DDI_REPORT_FLUSH(_pDev) do {} while (0)188 # define VBOXDISPPROFILE_DDI_INIT_GLBL() do {} while (0)189 # define VBOXDISPPROFILE_DDI_INIT_ADP(_pAdp) do {} while (0)190 # define VBOXDISPPROFILE_DDI_INIT_DEV(_pDev) do {} while (0)191 # define VBOXDISPPROFILE_DDI_TERM(_pObj) do {} while (0)192 # define VBOXDISPPROFILE_DDI_PRINT(_m) do {} while (0)193 #endif194 195 /* debugging/profiling stuff could go here.196 * NOP in release */197 #define VBOXDISP_DDI_PROLOGUE_CMN() \198 VBOXVDBG_BREAK_DDI(); \199 VBOXVDBG_CREATE_CHECK_SWAPCHAIN();200 201 #define VBOXDISP_DDI_PROLOGUE_DEV(_hDevice) \202 NOREF(_hDevice); \203 VBOXDISP_DDI_PROLOGUE_CMN(); \204 VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_DEV((PVBOXWDDMDISP_DEVICE)(_hDevice));205 206 #define VBOXDISP_DDI_PROLOGUE_ADP(_hAdapter) \207 VBOXDISP_DDI_PROLOGUE_CMN(); \208 VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE((PVBOXWDDMDISP_ADAPTER)(_hAdapter));209 210 #define VBOXDISP_DDI_PROLOGUE_GLBL() \211 VBOXDISP_DDI_PROLOGUE_CMN(); \212 VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE(&g_VBoxDispProfile);213 214 #ifdef VBOXDISPMP_TEST215 HRESULT vboxDispMpTstStart();216 HRESULT vboxDispMpTstStop();217 #endif218 219 #define VBOXDISP_WITH_WINE_BB_WORKAROUND220 221 //#define VBOXWDDMOVERLAY_TEST222 223 static D3DDDIQUERYTYPE gVBoxQueryTypes[] = {224 D3DDDIQUERYTYPE_EVENT,225 D3DDDIQUERYTYPE_OCCLUSION226 };227 228 #define VBOX_QUERYTYPE_COUNT() RT_ELEMENTS(gVBoxQueryTypes)229 230 231 #define VBOXDISPCRHGSMI_SCOPE_SET_DEV(_pDev) do {} while(0)232 #define VBOXDISPCRHGSMI_SCOPE_SET_GLOBAL() do {} while(0)233 234 235 typedef struct VBOXWDDMDISP_NSCADD236 {237 VOID* pvCommandBuffer;238 UINT cbCommandBuffer;239 D3DDDI_ALLOCATIONLIST* pAllocationList;240 UINT cAllocationList;241 D3DDDI_PATCHLOCATIONLIST* pPatchLocationList;242 UINT cPatchLocationList;243 UINT cAllocations;244 }VBOXWDDMDISP_NSCADD, *PVBOXWDDMDISP_NSCADD;245 246 static HRESULT vboxWddmNSCAddAlloc(PVBOXWDDMDISP_NSCADD pData, PVBOXWDDMDISP_ALLOCATION pAlloc)247 {248 HRESULT hr = S_OK;249 Assert(pAlloc->fEverWritten || pAlloc->pRc->RcDesc.fFlags.SharedResource);250 if (pData->cAllocationList && pData->cPatchLocationList && pData->cbCommandBuffer >= 4)251 {252 memset(pData->pAllocationList, 0, sizeof (D3DDDI_ALLOCATIONLIST));253 pData->pAllocationList[0].hAllocation = pAlloc->hAllocation;254 if (pAlloc->fDirtyWrite)255 pData->pAllocationList[0].WriteOperation = 1;256 257 memset(pData->pPatchLocationList, 0, sizeof (D3DDDI_PATCHLOCATIONLIST));258 pData->pPatchLocationList[0].PatchOffset = pData->cAllocations*4;259 pData->pPatchLocationList[0].AllocationIndex = pData->cAllocations;260 261 pData->cbCommandBuffer -= 4;262 --pData->cAllocationList;263 --pData->cPatchLocationList;264 ++pData->cAllocations;265 266 ++pData->pAllocationList;267 ++pData->pPatchLocationList;268 pData->pvCommandBuffer = (VOID*)(((uint8_t*)pData->pvCommandBuffer) + 4);269 270 }271 else272 hr = S_FALSE;273 274 return hr;275 }276 277 static VOID vboxWddmDalRemove(PVBOXWDDMDISP_ALLOCATION pAlloc)278 {279 RTListNodeRemove(&pAlloc->DirtyAllocListEntry);280 pAlloc->fDirtyWrite = FALSE;281 }282 283 #ifdef DEBUG_misha284 typedef struct VBOXWDDM_DBG_ALLOC285 {286 BOOLEAN fWrite;287 PVBOXWDDMDISP_ALLOCATION pAlloc;288 } VBOXWDDM_DBG_ALLOC;289 #endif290 291 static HRESULT vboxWddmDalNotifyChange(PVBOXWDDMDISP_DEVICE pDevice)292 {293 if (!pDevice->DefaultContext.ContextInfo.hContext)294 return E_FAIL;295 296 VBOXWDDMDISP_NSCADD NscAdd = { NULL }; /* Shuts up MSC. */297 BOOL bReinitRenderData = TRUE;298 #ifdef DEBUG_misha299 uint32_t cDbgAllocs = 0;300 VBOXWDDM_DBG_ALLOC aDbgAllocs[128];301 #endif302 303 do304 {305 if (bReinitRenderData)306 {307 NscAdd.pvCommandBuffer = pDevice->DefaultContext.ContextInfo.pCommandBuffer;308 NscAdd.cbCommandBuffer = pDevice->DefaultContext.ContextInfo.CommandBufferSize;309 NscAdd.pAllocationList = pDevice->DefaultContext.ContextInfo.pAllocationList;310 NscAdd.cAllocationList = pDevice->DefaultContext.ContextInfo.AllocationListSize;311 NscAdd.pPatchLocationList = pDevice->DefaultContext.ContextInfo.pPatchLocationList;312 NscAdd.cPatchLocationList = pDevice->DefaultContext.ContextInfo.PatchLocationListSize;313 NscAdd.cAllocations = 0;314 Assert(NscAdd.cbCommandBuffer >= sizeof (VBOXWDDM_DMA_PRIVATEDATA_BASEHDR));315 if (NscAdd.cbCommandBuffer < sizeof (VBOXWDDM_DMA_PRIVATEDATA_BASEHDR))316 return E_FAIL;317 318 PVBOXWDDM_DMA_PRIVATEDATA_BASEHDR pHdr = (PVBOXWDDM_DMA_PRIVATEDATA_BASEHDR)NscAdd.pvCommandBuffer;319 pHdr->enmCmd = VBOXVDMACMD_TYPE_DMA_NOP;320 NscAdd.pvCommandBuffer = (VOID*)(((uint8_t*)NscAdd.pvCommandBuffer) + sizeof (*pHdr));321 NscAdd.cbCommandBuffer -= sizeof (*pHdr);322 bReinitRenderData = FALSE;323 324 #ifdef DEBUG_misha325 {326 memset(aDbgAllocs, 0, sizeof (aDbgAllocs));327 uint32_t cAllocs = 0;328 PVBOXWDDMDISP_ALLOCATION pAlloc;329 RTListForEach(&pDevice->DirtyAllocList, pAlloc, VBOXWDDMDISP_ALLOCATION, DirtyAllocListEntry)330 {331 Assert(pAlloc->fEverWritten || pAlloc->pRc->RcDesc.fFlags.SharedResource);332 if (cAllocs < RT_ELEMENTS(aDbgAllocs))333 {334 aDbgAllocs[cAllocs].pAlloc = pAlloc;335 aDbgAllocs[cAllocs].fWrite = pAlloc->fDirtyWrite;336 ++cDbgAllocs;337 }338 ++cAllocs;339 }340 }341 #endif342 }343 344 PVBOXWDDMDISP_ALLOCATION pAlloc = RTListGetFirst(&pDevice->DirtyAllocList, VBOXWDDMDISP_ALLOCATION, DirtyAllocListEntry);345 if (pAlloc)346 {347 HRESULT tmpHr = vboxWddmNSCAddAlloc(&NscAdd, pAlloc);348 #ifdef DEBUG_misha349 Assert(tmpHr == S_OK);350 #endif351 Assert(tmpHr == S_OK || tmpHr == S_FALSE);352 if (tmpHr == S_OK)353 {354 vboxWddmDalRemove(pAlloc);355 continue;356 }357 }358 else359 {360 if (!NscAdd.cAllocations)361 break;362 }363 364 D3DDDICB_RENDER RenderData = {0};365 RenderData.CommandLength = pDevice->DefaultContext.ContextInfo.CommandBufferSize - NscAdd.cbCommandBuffer;366 Assert(RenderData.CommandLength);367 Assert(RenderData.CommandLength < UINT32_MAX/2);368 RenderData.CommandOffset = 0;369 RenderData.NumAllocations = pDevice->DefaultContext.ContextInfo.AllocationListSize - NscAdd.cAllocationList;370 Assert(RenderData.NumAllocations == NscAdd.cAllocations);371 RenderData.NumPatchLocations = pDevice->DefaultContext.ContextInfo.PatchLocationListSize - NscAdd.cPatchLocationList;372 Assert(RenderData.NumPatchLocations == NscAdd.cAllocations);373 // RenderData.NewCommandBufferSize = sizeof (VBOXVDMACMD) + 4 * (100);374 // RenderData.NewAllocationListSize = 100;375 // RenderData.NewPatchLocationListSize = 100;376 RenderData.hContext = pDevice->DefaultContext.ContextInfo.hContext;377 378 HRESULT hr = pDevice->RtCallbacks.pfnRenderCb(pDevice->hDevice, &RenderData);379 Assert(hr == S_OK);380 if (hr == S_OK)381 {382 pDevice->DefaultContext.ContextInfo.CommandBufferSize = RenderData.NewCommandBufferSize;383 pDevice->DefaultContext.ContextInfo.pCommandBuffer = RenderData.pNewCommandBuffer;384 pDevice->DefaultContext.ContextInfo.AllocationListSize = RenderData.NewAllocationListSize;385 pDevice->DefaultContext.ContextInfo.pAllocationList = RenderData.pNewAllocationList;386 pDevice->DefaultContext.ContextInfo.PatchLocationListSize = RenderData.NewPatchLocationListSize;387 pDevice->DefaultContext.ContextInfo.pPatchLocationList = RenderData.pNewPatchLocationList;388 bReinitRenderData = TRUE;389 }390 else391 break;392 } while (1);393 394 return S_OK;395 }396 397 #ifdef VBOXWDDMDISP_DAL_CHECK_LOCK398 static HRESULT vboxWddmDalCheckUnlock(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pAlloc)399 {400 if (!pAlloc->fAllocLocked || pAlloc->LockInfo.cLocks)401 return S_OK;402 403 Assert(pAlloc->hAllocation);404 405 D3DDDICB_UNLOCK Unlock;406 407 Unlock.NumAllocations = 1;408 Unlock.phAllocations = &pAlloc->hAllocation;409 410 HRESULT hr = pDevice->RtCallbacks.pfnUnlockCb(pDevice->hDevice, &Unlock);411 if(hr != S_OK)412 {413 WARN(("pfnUnlockCb failed, hr %#x", hr));414 }415 416 return hr;417 }418 419 static HRESULT vboxWddmDalCheckLock(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pAlloc, D3DDDI_LOCKFLAGS Flags)420 {421 if (!pAlloc->hAllocation || pAlloc->fAllocLocked)422 return S_OK;423 424 HRESULT hr;425 426 if (pAlloc->fDirtyWrite)427 {428 Assert(pAlloc->DirtyAllocListEntry.pNext);429 hr = vboxWddmDalNotifyChange(pDevice);430 if (hr == S_OK)431 {432 Assert(!pAlloc->DirtyAllocListEntry.pNext);433 }434 else435 {436 WARN(("vboxWddmDalNotifyChange failed %#x, ignoring", hr));437 }438 }439 440 D3DDDICB_LOCK LockData;441 LockData.hAllocation = pAlloc->hAllocation;442 LockData.PrivateDriverData = 0;443 LockData.NumPages = 0;444 LockData.pPages = NULL;445 LockData.pData = NULL; /* out */446 LockData.Flags.Value = 0;447 LockData.Flags.Discard = Flags.Discard;448 LockData.Flags.DonotWait = Flags.DoNotWait;449 450 hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &LockData);451 if (hr == S_OK)452 {453 if (!Flags.ReadOnly)454 pAlloc->fEverWritten = TRUE;455 pAlloc->fAllocLocked = TRUE;456 return S_OK;457 }458 459 WARN(("pfnLockCb failed %#x, Flags %#x", hr, Flags.Value));460 461 return hr;462 }463 #endif464 465 BOOLEAN vboxWddmDalCheckNotifyRemove(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pAlloc)466 {467 if (pAlloc->DirtyAllocListEntry.pNext)468 {469 HRESULT hr = vboxWddmDalNotifyChange(pDevice);470 if (hr == S_OK)471 {472 Assert(!pAlloc->DirtyAllocListEntry.pNext);473 }474 else475 {476 // WARN(("vboxWddmDalNotifyChange failed %#x", hr));477 if (pAlloc->DirtyAllocListEntry.pNext)478 vboxWddmDalRemove(pAlloc);479 }480 481 return TRUE;482 }483 484 return FALSE;485 }486 487 static BOOLEAN vboxWddmDalCheckAdd(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pAlloc, BOOLEAN fWrite)488 {489 if (!pAlloc->hAllocation /* only shared resources matter */490 || (/*!fWrite &&*/ !pAlloc->hSharedHandle)491 )492 {493 Assert(!pAlloc->DirtyAllocListEntry.pNext || pAlloc->hSharedHandle /*|| pAlloc->fDirtyWrite*/);494 495 Assert(!pAlloc->hSharedHandle);496 497 return FALSE;498 }499 500 Assert(fWrite || pAlloc->fEverWritten || pAlloc->pRc->RcDesc.fFlags.SharedResource);501 502 if (!pAlloc->DirtyAllocListEntry.pNext)503 {504 Assert(!pAlloc->fDirtyWrite);505 RTListAppend(&pDevice->DirtyAllocList, &pAlloc->DirtyAllocListEntry);506 }507 else508 {509 Assert(pAlloc->fDirtyWrite == fWrite || pAlloc->pRc->RcDesc.fFlags.SharedResource);510 }511 pAlloc->fDirtyWrite |= fWrite;512 pAlloc->fEverWritten |= fWrite;513 514 return TRUE;515 }516 517 DECLINLINE(BOOLEAN) vboxWddmDalCheckAddRc(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_RESOURCE pRc, BOOLEAN fWrite)518 {519 BOOLEAN fChanged = FALSE;520 for (UINT i = 0; i < pRc->cAllocations; ++i)521 {522 PVBOXWDDMDISP_ALLOCATION pDAlloc = &pRc->aAllocations[i];523 fChanged |= vboxWddmDalCheckAdd(pDevice, pDAlloc, fWrite);524 }525 return fChanged;526 }527 528 static VOID vboxWddmDalCheckAddDepthStencil(PVBOXWDDMDISP_DEVICE pDevice)529 {530 if (pDevice->pDepthStencilRc)531 vboxWddmDalCheckAddRc(pDevice, pDevice->pDepthStencilRc, TRUE);532 }533 534 static VOID vboxWddmDalCheckAddRTs(PVBOXWDDMDISP_DEVICE pDevice)535 {536 for (UINT i = 0; i < pDevice->cRTs; ++i)537 {538 if (pDevice->apRTs[i])539 {540 vboxWddmDalCheckAdd(pDevice, pDevice->apRTs[i], TRUE);541 }542 }543 }544 545 static VOID vboxWddmDalCheckAddSamplers(PVBOXWDDMDISP_DEVICE pDevice)546 {547 for (UINT i = 0, iSampler = 0; iSampler < pDevice->cSamplerTextures; ++i)548 {549 Assert(i < RT_ELEMENTS(pDevice->aSamplerTextures));550 if (!pDevice->aSamplerTextures[i]) continue;551 vboxWddmDalCheckAddRc(pDevice, pDevice->aSamplerTextures[i], FALSE);552 ++iSampler;553 }554 }555 556 VOID vboxWddmDalCheckAddOnDraw(PVBOXWDDMDISP_DEVICE pDevice)557 {558 vboxWddmDalCheckAddRTs(pDevice);559 560 vboxWddmDalCheckAddDepthStencil(pDevice);561 562 vboxWddmDalCheckAddSamplers(pDevice);563 }564 565 static BOOLEAN vboxWddmDalIsEmpty(PVBOXWDDMDISP_DEVICE pDevice)566 {567 return RTListIsEmpty(&pDevice->DirtyAllocList);568 }569 570 #ifdef VBOX_WITH_VIDEOHWACCEL571 572 static bool vboxVhwaIsEnabled(PVBOXWDDMDISP_ADAPTER pAdapter)573 {574 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)575 {576 if (pAdapter->aHeads[i].Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED)577 return true;578 }579 return false;580 }581 582 static bool vboxVhwaHasCKeying(PVBOXWDDMDISP_ADAPTER pAdapter)583 {584 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)585 {586 VBOXVHWA_INFO* pSettings = &pAdapter->aHeads[i].Vhwa.Settings;587 if ((pSettings->fFlags & VBOXVHWA_F_ENABLED)588 && ((pSettings->fFlags & VBOXVHWA_F_CKEY_DST)589 || (pSettings->fFlags & VBOXVHWA_F_CKEY_SRC))590 )591 return true;592 }593 return false;594 }595 596 #endif597 598 static void vboxResourceFree(PVBOXWDDMDISP_RESOURCE pRc)599 {600 RTMemFree(pRc);601 }602 603 void vboxWddmResourceInit(PVBOXWDDMDISP_RESOURCE pRc, UINT cAllocs)604 {605 memset(pRc, 0, RT_UOFFSETOF_DYN(VBOXWDDMDISP_RESOURCE, aAllocations[cAllocs]));606 pRc->cAllocations = cAllocs;607 for (UINT i = 0; i < cAllocs; ++i)608 {609 pRc->aAllocations[i].iAlloc = i;610 pRc->aAllocations[i].pRc = pRc;611 }612 }613 614 static PVBOXWDDMDISP_RESOURCE vboxResourceAlloc(UINT cAllocs)615 {616 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)RTMemAlloc(RT_UOFFSETOF_DYN(VBOXWDDMDISP_RESOURCE, aAllocations[cAllocs]));617 Assert(pRc);618 if (pRc)619 {620 vboxWddmResourceInit(pRc, cAllocs);621 return pRc;622 }623 return NULL;624 }625 626 #ifdef VBOXWDDMDISP_DEBUG627 static void vboxWddmDbgSynchMemCheck(PVBOXWDDMDISP_ALLOCATION pAlloc, D3DLOCKED_RECT *pLockInfo)628 {629 Assert(pAlloc->SurfDesc.pitch);630 Assert(pAlloc->pvMem);631 int iRc = 0;632 633 if (pAlloc->SurfDesc.pitch == (UINT)pLockInfo->Pitch)634 {635 Assert(pAlloc->SurfDesc.cbSize);636 iRc = memcmp(pLockInfo->pBits, pAlloc->pvMem, pAlloc->SurfDesc.cbSize);637 Assert(!iRc);638 }639 else640 {641 uint8_t *pvSrc, *pvDst;642 uint32_t srcPitch, dstPitch;643 if (1)644 {645 pvSrc = (uint8_t *)pAlloc->pvMem;646 pvDst = (uint8_t *)pLockInfo->pBits;647 srcPitch = pAlloc->SurfDesc.pitch;648 dstPitch = pLockInfo->Pitch;649 }650 else651 {652 pvDst = (uint8_t *)pAlloc->pvMem;653 pvSrc = (uint8_t *)pLockInfo->pBits;654 dstPitch = pAlloc->SurfDesc.pitch;655 srcPitch = (uint32_t)pLockInfo->Pitch;656 }657 658 Assert(pAlloc->SurfDesc.pitch <= (UINT)pLockInfo->Pitch);659 uint32_t pitch = RT_MIN(srcPitch, dstPitch);660 Assert(pitch);661 uint32_t cRows = vboxWddmCalcNumRows(0, pAlloc->SurfDesc.height, pAlloc->SurfDesc.format);662 for (UINT j = 0; j < cRows; ++j)663 {664 iRc = memcmp(pvDst, pvSrc, pitch);665 Assert(!iRc);666 pvSrc += srcPitch;667 pvDst += dstPitch;668 }669 }670 }671 672 static VOID vboxWddmDbgRcSynchMemCheck(PVBOXWDDMDISP_RESOURCE pRc)673 {674 if (!pRc)675 {676 return;677 }678 679 if (pRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM)680 {681 return;682 }683 684 for (UINT i = 0; i < pRc->cAllocations; ++i)685 {686 D3DLOCKED_RECT Rect;687 HRESULT hr = VBoxD3DIfLockRect(pRc, i, &Rect, NULL, D3DLOCK_READONLY);688 if (FAILED(hr))689 {690 WARN(("VBoxD3DIfLockRect failed, hr(0x%x)", hr));691 return;692 }693 694 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];695 Assert(pAlloc->pvMem);696 697 vboxWddmDbgSynchMemCheck(pAlloc, &Rect);698 699 hr = VBoxD3DIfUnlockRect(pRc, i);700 Assert(SUCCEEDED(hr));701 }702 }703 #endif704 705 706 /******/707 static HRESULT vboxWddmRenderTargetSet(PVBOXWDDMDISP_DEVICE pDevice, UINT iRt, PVBOXWDDMDISP_ALLOCATION pAlloc,708 BOOL bOnSwapchainSynch);709 710 DECLINLINE(VOID) vboxWddmSwapchainInit(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)711 {712 RTLISTNODE ListEntry = pSwapchain->ListEntry;713 memset(pSwapchain, 0, sizeof (VBOXWDDMDISP_SWAPCHAIN));714 pSwapchain->ListEntry = ListEntry;715 pSwapchain->iBB = VBOXWDDMDISP_INDEX_UNDEFINED;716 }717 718 static HRESULT vboxWddmSwapchainKmSynch(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)719 {720 struct721 {722 VBOXDISPIFESCAPE_SWAPCHAININFO SwapchainInfo;723 D3DKMT_HANDLE ahAllocs[VBOXWDDMDISP_MAX_SWAPCHAIN_SIZE];724 } Buf;725 726 memset(&Buf.SwapchainInfo, 0, sizeof (Buf.SwapchainInfo));727 Buf.SwapchainInfo.EscapeHdr.escapeCode = VBOXESC_SWAPCHAININFO;728 Buf.SwapchainInfo.SwapchainInfo.hSwapchainKm = pSwapchain->hSwapchainKm;729 #pragma warning(suppress:4826) /** @todo warning C4826: Conversion from 'PVBOXWDDMDISP_SWAPCHAIN' to 'VBOXDISP_UMHANDLE' is sign-extended. This may cause unexpected runtime behavior. */730 Buf.SwapchainInfo.SwapchainInfo.hSwapchainUm = (VBOXDISP_UMHANDLE)pSwapchain;731 HRESULT hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DSwapchain9GetHostWinID(pSwapchain->pSwapChainIf,732 &Buf.SwapchainInfo.SwapchainInfo.winHostID);733 if (FAILED(hr))734 {735 WARN(("pfnVBoxWineExD3DSwapchain9GetHostWinID failed, hr 0x%x", hr));736 return hr;737 }738 Assert(Buf.SwapchainInfo.SwapchainInfo.winHostID);739 // Buf.SwapchainInfo.SwapchainInfo.Rect;740 // Buf.SwapchainInfo.SwapchainInfo.u32Reserved;741 Buf.SwapchainInfo.SwapchainInfo.cAllocs = pSwapchain->cRTs;742 UINT cAllocsKm = 0;743 for (UINT i = 0; i < Buf.SwapchainInfo.SwapchainInfo.cAllocs; ++i)744 {745 // Assert(pSwapchain->aRTs[i].pAlloc->hAllocation);746 Buf.SwapchainInfo.SwapchainInfo.ahAllocs[i] = pSwapchain->aRTs[i].pAlloc->hAllocation;747 if (Buf.SwapchainInfo.SwapchainInfo.ahAllocs[i])748 ++cAllocsKm;749 }750 751 Assert(cAllocsKm == Buf.SwapchainInfo.SwapchainInfo.cAllocs || !cAllocsKm);752 if (cAllocsKm == Buf.SwapchainInfo.SwapchainInfo.cAllocs)753 {754 AssertReturn(pDevice->DefaultContext.ContextInfo.hContext, E_FAIL);755 756 D3DDDICB_ESCAPE DdiEscape = {0};757 DdiEscape.hContext = pDevice->DefaultContext.ContextInfo.hContext;758 DdiEscape.hDevice = pDevice->hDevice;759 // DdiEscape.Flags.Value = 0;760 DdiEscape.pPrivateDriverData = &Buf.SwapchainInfo;761 DdiEscape.PrivateDriverDataSize = RT_UOFFSETOF_DYN(VBOXDISPIFESCAPE_SWAPCHAININFO,762 SwapchainInfo.ahAllocs[Buf.SwapchainInfo.SwapchainInfo.cAllocs]);763 hr = pDevice->RtCallbacks.pfnEscapeCb(pDevice->pAdapter->hAdapter, &DdiEscape);764 #ifdef DEBUG_misha765 Assert(hr == S_OK);766 #endif767 if (hr == S_OK)768 {769 pSwapchain->hSwapchainKm = Buf.SwapchainInfo.SwapchainInfo.hSwapchainKm;770 }771 }772 773 return S_OK;774 }775 776 static HRESULT vboxWddmSwapchainKmDestroy(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)777 {778 HRESULT hr = S_OK;779 if (pSwapchain->hSwapchainKm)780 {781 /* submit empty swapchain to destroy the KM one */782 UINT cOldRTc = pSwapchain->cRTs;783 pSwapchain->cRTs = 0;784 hr = vboxWddmSwapchainKmSynch(pDevice, pSwapchain);785 Assert(hr == S_OK);786 Assert(!pSwapchain->hSwapchainKm);787 pSwapchain->cRTs = cOldRTc;788 }789 return hr;790 }791 static HRESULT vboxWddmSwapchainDestroyIf(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)792 {793 RT_NOREF(pDevice);794 if (pSwapchain->pSwapChainIf)795 {796 #ifndef VBOXWDDM_WITH_VISIBLE_FB797 if (pSwapchain->pRenderTargetFbCopy)798 {799 pSwapchain->pRenderTargetFbCopy->Release();800 pSwapchain->pRenderTargetFbCopy = NULL;801 pSwapchain->bRTFbCopyUpToDate = FALSE;802 }803 #endif804 pSwapchain->pSwapChainIf->Release();805 Assert(pSwapchain->hWnd);806 pSwapchain->pSwapChainIf = NULL;807 pSwapchain->hWnd = NULL;808 return S_OK;809 }810 811 Assert(!pSwapchain->hWnd);812 return S_OK;813 }814 815 DECLINLINE(VOID) vboxWddmSwapchainClear(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)816 {817 for (UINT i = 0; i < pSwapchain->cRTs; ++i)818 {819 pSwapchain->aRTs[i].pAlloc->pSwapchain = NULL;820 }821 822 /* first do a Km destroy to ensure all km->um region submissions are completed */823 vboxWddmSwapchainKmDestroy(pDevice, pSwapchain);824 vboxWddmSwapchainDestroyIf(pDevice, pSwapchain);825 vboxWddmSwapchainInit(pSwapchain);826 }827 828 VOID vboxWddmSwapchainDestroy(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)829 {830 vboxWddmSwapchainClear(pDevice, pSwapchain);831 RTListNodeRemove(&pSwapchain->ListEntry);832 RTMemFree(pSwapchain);833 }834 835 static VOID vboxWddmSwapchainDestroyAll(PVBOXWDDMDISP_DEVICE pDevice)836 {837 PVBOXWDDMDISP_SWAPCHAIN pCur = RTListGetFirst(&pDevice->SwapchainList, VBOXWDDMDISP_SWAPCHAIN, ListEntry);838 while (pCur)839 {840 PVBOXWDDMDISP_SWAPCHAIN pNext = NULL;841 if (!RTListNodeIsLast(&pDevice->SwapchainList, &pCur->ListEntry))842 {843 pNext = RTListNodeGetNext(&pCur->ListEntry, VBOXWDDMDISP_SWAPCHAIN, ListEntry);844 }845 846 vboxWddmSwapchainDestroy(pDevice, pCur);847 848 pCur = pNext;849 }850 }851 852 static PVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainAlloc(PVBOXWDDMDISP_DEVICE pDevice)853 {854 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = (PVBOXWDDMDISP_SWAPCHAIN)RTMemAllocZ(sizeof (VBOXWDDMDISP_SWAPCHAIN));855 Assert(pSwapchain);856 if (pSwapchain)857 {858 RTListAppend(&pDevice->SwapchainList, &pSwapchain->ListEntry);859 vboxWddmSwapchainInit(pSwapchain);860 return pSwapchain;861 }862 return NULL;863 }864 865 DECLINLINE(VOID) vboxWddmSwapchainRtInit(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_RENDERTGT pRt,866 PVBOXWDDMDISP_ALLOCATION pAlloc)867 {868 pSwapchain->fFlags.bChanged = 1;869 pRt->pAlloc = pAlloc;870 pRt->cNumFlips = 0;871 pRt->fFlags.Value = 0;872 pRt->fFlags.bAdded = 1;873 }874 875 DECLINLINE(VOID) vboxWddmSwapchainBbAddTail(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_ALLOCATION pAlloc, BOOL bAssignAsBb)876 {877 pAlloc->pSwapchain = pSwapchain;878 /*VBOXWDDMDISP_SWAPCHAIN_FLAGS fOldFlags = pSwapchain->fFlags; - unused */879 PVBOXWDDMDISP_RENDERTGT pRt = &pSwapchain->aRTs[pSwapchain->cRTs];880 ++pSwapchain->cRTs;881 vboxWddmSwapchainRtInit(pSwapchain, pRt, pAlloc);882 if (pSwapchain->cRTs == 1)883 {884 Assert(pSwapchain->iBB == VBOXWDDMDISP_INDEX_UNDEFINED);885 pSwapchain->iBB = 0;886 }887 else if (bAssignAsBb)888 {889 pSwapchain->iBB = pSwapchain->cRTs - 1;890 }891 else if (pSwapchain->cRTs == 2) /* the first one is a frontbuffer */892 {893 pSwapchain->iBB = 1;894 }895 }896 897 DECLINLINE(VOID) vboxWddmSwapchainFlip(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)898 {899 pSwapchain->iBB = (pSwapchain->iBB + 1) % pSwapchain->cRTs;900 }901 902 DECLINLINE(UINT) vboxWddmSwapchainNumRTs(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)903 {904 return pSwapchain->cRTs;905 }906 907 908 DECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainRtForAlloc(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_ALLOCATION pAlloc)909 {910 if (pAlloc->pSwapchain != pSwapchain)911 return NULL;912 913 for (UINT i = 0; i < pSwapchain->cRTs; ++i)914 {915 Assert(pSwapchain->aRTs[i].pAlloc->pSwapchain = pSwapchain);916 if (pSwapchain->aRTs[i].pAlloc == pAlloc)917 return &pSwapchain->aRTs[i];918 }919 920 /* should never happen */921 Assert(0);922 return NULL;923 }924 925 DECLINLINE(UINT) vboxWddmSwapchainRtIndex(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_RENDERTGT pRT)926 {927 UINT offFirst = RT_UOFFSETOF(VBOXWDDMDISP_SWAPCHAIN, aRTs);928 UINT offRT = UINT((uintptr_t)pRT - (uintptr_t)pSwapchain);929 Assert(offRT < sizeof (VBOXWDDMDISP_SWAPCHAIN));930 Assert(offRT >= offFirst);931 Assert(!((offRT - offFirst) % sizeof (VBOXWDDMDISP_RENDERTGT)));932 UINT iRt = (offRT - offFirst) / sizeof (VBOXWDDMDISP_RENDERTGT);933 Assert(iRt < pSwapchain->cRTs);934 return iRt;935 }936 937 DECLINLINE(VOID) vboxWddmSwapchainRtRemove(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_RENDERTGT pRT)938 {939 UINT iRt = vboxWddmSwapchainRtIndex(pSwapchain, pRT);940 Assert(iRt < pSwapchain->cRTs);941 pRT->pAlloc->pSwapchain = NULL;942 for (UINT i = iRt; i < pSwapchain->cRTs - 1; ++i)943 {944 pSwapchain->aRTs[i] = pSwapchain->aRTs[i + 1];945 }946 947 --pSwapchain->cRTs;948 if (pSwapchain->cRTs)949 {950 if (pSwapchain->iBB > iRt)951 {952 --pSwapchain->iBB;953 }954 else if (pSwapchain->iBB == iRt)955 {956 pSwapchain->iBB = 0;957 }958 }959 else960 {961 pSwapchain->iBB = VBOXWDDMDISP_INDEX_UNDEFINED;962 }963 pSwapchain->fFlags.bChanged = TRUE;964 pSwapchain->fFlags.bSwitchReportingPresent = TRUE;965 }966 967 DECLINLINE(VOID) vboxWddmSwapchainSetBb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_RENDERTGT pRT)968 {969 UINT iRt = vboxWddmSwapchainRtIndex(pSwapchain, pRT);970 Assert(iRt < pSwapchain->cRTs);971 pSwapchain->iBB = iRt;972 pSwapchain->fFlags.bChanged = TRUE;973 }974 975 PVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainFindCreate(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pBbAlloc,976 BOOL *pbNeedPresent)977 {978 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = pBbAlloc->pSwapchain;979 if (pSwapchain)980 {981 /* check if this is what we expect */982 PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainGetBb(pSwapchain);983 if (pRt->pAlloc != pBbAlloc)984 {985 if (pBbAlloc == vboxWddmSwapchainGetFb(pSwapchain)->pAlloc)986 {987 /* the current front-buffer present is requested, don't do anything */988 *pbNeedPresent = FALSE;989 return pSwapchain;990 }991 /* bad, @todo: correct the swapchain by either removing the Rt and adding it to another swapchain992 * or by removing the pBbAlloc out of it */993 /// @todo Assert(0);994 995 PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainRtForAlloc(pSwapchain, pBbAlloc);996 Assert(pRt);997 vboxWddmSwapchainSetBb(pSwapchain, pRt);998 pSwapchain->fFlags.bSwitchReportingPresent = TRUE;999 }1000 }1001 1002 *pbNeedPresent = TRUE;1003 1004 if (!pSwapchain)1005 {1006 /* first search for the swapchain the alloc might be added to */1007 PVBOXWDDMDISP_SWAPCHAIN pCur = RTListGetFirst(&pDevice->SwapchainList, VBOXWDDMDISP_SWAPCHAIN, ListEntry);1008 while (pCur)1009 {1010 PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainGetBb(pCur);1011 Assert(pRt);1012 if (pRt->cNumFlips < 21013 && vboxWddmSwapchainRtIndex(pCur, pRt) == 0) /* <- in case we add a rt to the swapchain on present this would mean1014 * that the last RT in the swapchain array is now a frontbuffer and1015 * thus the aRTs[0] is a backbuffer */1016 {1017 if (pBbAlloc->SurfDesc.width == pRt->pAlloc->SurfDesc.width1018 && pBbAlloc->SurfDesc.height == pRt->pAlloc->SurfDesc.height1019 && vboxWddmFmtNoAlphaFormat(pBbAlloc->SurfDesc.format) == vboxWddmFmtNoAlphaFormat(pRt->pAlloc->SurfDesc.format)1020 && pBbAlloc->SurfDesc.VidPnSourceId == pRt->pAlloc->SurfDesc.VidPnSourceId1021 )1022 {1023 vboxWddmSwapchainBbAddTail(pCur, pBbAlloc, TRUE);1024 pSwapchain = pCur;1025 break;1026 }1027 }1028 if (RTListNodeIsLast(&pDevice->SwapchainList, &pCur->ListEntry))1029 break;1030 pCur = RTListNodeGetNext(&pCur->ListEntry, VBOXWDDMDISP_SWAPCHAIN, ListEntry);1031 }1032 1033 // if (!pSwapchain) need to create a new one (see below)1034 }1035 1036 if (!pSwapchain)1037 {1038 pSwapchain = vboxWddmSwapchainAlloc(pDevice);1039 Assert(pSwapchain);1040 if (pSwapchain)1041 {1042 vboxWddmSwapchainBbAddTail(pSwapchain, pBbAlloc, FALSE);1043 }1044 }1045 1046 return pSwapchain;1047 }1048 1049 static PVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainCreateForRc(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_RESOURCE pRc)1050 {1051 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainAlloc(pDevice);1052 Assert(pSwapchain);1053 if (pSwapchain)1054 {1055 for (UINT i = 0; i < pRc->cAllocations; ++i)1056 {1057 vboxWddmSwapchainBbAddTail(pSwapchain, &pRc->aAllocations[i], FALSE);1058 }1059 return pSwapchain;1060 }1061 return NULL;1062 }1063 1064 DECLINLINE(UINT) vboxWddmSwapchainIdxBb2Rt(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, uint32_t iBb)1065 {1066 return iBb != (~0) ? (iBb + pSwapchain->iBB) % pSwapchain->cRTs : vboxWddmSwapchainIdxFb(pSwapchain);1067 }1068 1069 static HRESULT vboxWddmSwapchainRtSynch(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain, uint32_t iBb)1070 {1071 if (pSwapchain->fFlags.bRtReportingPresent)1072 return S_OK;1073 1074 IDirect3DSurface9 *pD3D9Surf;1075 #ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND1076 if (pSwapchain->cRTs == 1)1077 {1078 iBb = 0;1079 }1080 #endif1081 UINT iRt = vboxWddmSwapchainIdxBb2Rt(pSwapchain, iBb);1082 Assert(iRt < pSwapchain->cRTs);1083 PVBOXWDDMDISP_RENDERTGT pRt = &pSwapchain->aRTs[iRt];1084 HRESULT hr = pSwapchain->pSwapChainIf->GetBackBuffer(iBb, D3DBACKBUFFER_TYPE_MONO, &pD3D9Surf);1085 if (FAILED(hr))1086 {1087 WARN(("GetBackBuffer failed, hr (0x%x)",hr));1088 return hr;1089 }1090 1091 PVBOXWDDMDISP_ALLOCATION pAlloc = pRt->pAlloc;1092 Assert(pD3D9Surf);1093 Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);1094 if (pAlloc->pD3DIf)1095 {1096 if (pSwapchain->fFlags.bChanged)1097 {1098 IDirect3DSurface9 *pD3D9OldSurf = NULL;1099 if (pAlloc->pD3DIf)1100 {1101 /* since this can be texture, need to do the VBoxD3DIfSurfGet magic */1102 hr = VBoxD3DIfSurfGet(pAlloc->pRc, pAlloc->iAlloc, &pD3D9OldSurf);1103 if (FAILED(hr))1104 {1105 WARN(("VBoxD3DIfSurfGet failed, hr (0x%x)",hr));1106 pD3D9Surf->Release();1107 return hr;1108 }1109 }1110 1111 if (pD3D9OldSurf && pD3D9OldSurf != pD3D9Surf)1112 {1113 VOID *pvSwapchain = NULL;1114 /* get the old surface's swapchain */1115 HRESULT tmpHr = pD3D9OldSurf->GetContainer(IID_IDirect3DSwapChain9, &pvSwapchain);1116 if (tmpHr == S_OK)1117 {1118 Assert(pvSwapchain);1119 ((IDirect3DSwapChain9 *)pvSwapchain)->Release();1120 }1121 else1122 {1123 Assert(!pvSwapchain);1124 }1125 1126 if (pvSwapchain != pSwapchain->pSwapChainIf)1127 {1128 /* the swapchain has changed, copy data to the new surface */1129 #ifdef DEBUG_misha1130 /** @todo we can not generally update the render target directly, implement */1131 Assert(iBb != (~0));1132 #endif1133 VBOXVDBG_CHECK_SWAPCHAIN_SYNC(hr = pDevice->pDevice9If->StretchRect(pD3D9OldSurf, NULL, pD3D9Surf, NULL,1134 D3DTEXF_NONE); Assert(hr == S_OK),1135 pAlloc, pD3D9OldSurf, NULL, pAlloc, pD3D9Surf, NULL);1136 }1137 }1138 1139 if (pD3D9OldSurf)1140 {1141 pD3D9OldSurf->Release();1142 }1143 }1144 else1145 {1146 Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);1147 }1148 pAlloc->pD3DIf->Release();1149 }1150 1151 pAlloc->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;1152 pAlloc->pD3DIf = pD3D9Surf;1153 pRt->fFlags.Value = 0;1154 1155 if (pSwapchain->fFlags.bChanged)1156 {1157 for (UINT i = 0; i < pDevice->cRTs; ++i)1158 {1159 if (pDevice->apRTs[i] == pAlloc)1160 {1161 hr = vboxWddmRenderTargetSet(pDevice, i, pAlloc, TRUE);1162 Assert(hr == S_OK);1163 }1164 }1165 }1166 1167 #ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND1168 if (pSwapchain->cRTs == 1)1169 {1170 IDirect3DSurface9 *pD3D9Bb;1171 /* only use direct bb if wine is able to handle quick blits bewteen surfaces in one swapchain,1172 * this is FALSE by now :( */1173 # ifdef VBOX_WINE_WITH_FAST_INTERSWAPCHAIN_BLT1174 /* here we sync the front-buffer with a backbuffer data*/1175 pD3D9Bb = (IDirect3DSurface9*)vboxWddmSwapchainGetBb(pSwapchain)->pAlloc->pD3DIf;1176 Assert(pD3D9Bb);1177 pD3D9Bb->AddRef();1178 /* we use backbuffer as a rt frontbuffer copy, so release the old one and assign the current bb */1179 if (pSwapchain->pRenderTargetFbCopy)1180 {1181 pSwapchain->pRenderTargetFbCopy->Release();1182 }1183 pSwapchain->pRenderTargetFbCopy = pD3D9Bb;1184 # else1185 pD3D9Bb = pSwapchain->pRenderTargetFbCopy;1186 # endif1187 HRESULT tmpHr = pSwapchain->pSwapChainIf->GetFrontBufferData(pD3D9Bb);1188 if (SUCCEEDED(tmpHr))1189 {1190 VBOXVDBG_DUMP_SYNC_RT(pD3D9Bb);1191 pSwapchain->bRTFbCopyUpToDate = TRUE;1192 # ifndef VBOX_WINE_WITH_FAST_INTERSWAPCHAIN_BLT1193 VBOXVDBG_CHECK_SWAPCHAIN_SYNC(tmpHr = pDevice->pDevice9If->StretchRect(pD3D9Bb, NULL,1194 (IDirect3DSurface9*)vboxWddmSwapchainGetBb(pSwapchain)->pAlloc->pD3DIf,1195 NULL, D3DTEXF_NONE); Assert(tmpHr == S_OK),1196 pAlloc, pD3D9Bb, NULL, pAlloc,1197 (IDirect3DSurface9*)vboxWddmSwapchainGetBb(pSwapchain)->pAlloc->pD3DIf, NULL);1198 1199 if (FAILED(tmpHr))1200 {1201 WARN(("StretchRect failed, hr (0x%x)", tmpHr));1202 }1203 # endif1204 }1205 else1206 {1207 WARN(("GetFrontBufferData failed, hr (0x%x)", tmpHr));1208 }1209 }1210 #endif1211 return hr;1212 }1213 1214 static HRESULT vboxWddmSwapchainSynch(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)1215 {1216 HRESULT hr = S_OK;1217 for (int iBb = -1; iBb < int(pSwapchain->cRTs - 1); ++iBb)1218 {1219 hr = vboxWddmSwapchainRtSynch(pDevice, pSwapchain, (UINT)iBb);1220 Assert(hr == S_OK);1221 }1222 if (pSwapchain->fFlags.bChanged)1223 {1224 hr = vboxWddmSwapchainKmSynch(pDevice, pSwapchain);1225 if (hr == S_OK)1226 {1227 pSwapchain->fFlags.bChanged = 0;1228 }1229 }1230 return hr;1231 }1232 1233 static VOID vboxWddmSwapchainFillPresentParams(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, D3DPRESENT_PARAMETERS *pParams)1234 {1235 Assert(pSwapchain->cRTs);1236 #ifdef DEBUG_misha1237 /* not supported by wine properly, need to use offscreen render targets and blit their data to swapchain RTs*/1238 Assert(pSwapchain->cRTs <= 2);1239 #endif1240 PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainGetBb(pSwapchain);1241 PVBOXWDDMDISP_RESOURCE pRc = pRt->pAlloc->pRc;1242 VBoxD3DIfFillPresentParams(pParams, pRc, pSwapchain->cRTs);1243 }1244 1245 /* copy current rt data to offscreen render targets */1246 static HRESULT vboxWddmSwapchainSwtichOffscreenRt(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain,1247 BOOL fForceCreate)1248 {1249 D3DPRESENT_PARAMETERS Params;1250 vboxWddmSwapchainFillPresentParams(pSwapchain, &Params);1251 IDirect3DSurface9* pD3D9OldFb = NULL;1252 IDirect3DSwapChain9 * pOldIf = pSwapchain->pSwapChainIf;1253 HRESULT hr = S_OK;1254 if (pOldIf)1255 {1256 hr = pOldIf->GetBackBuffer(~0U, D3DBACKBUFFER_TYPE_MONO, &pD3D9OldFb);1257 if (FAILED(hr))1258 {1259 WARN(("GetBackBuffer ~0U failed, hr (%d)", hr));1260 return hr;1261 }1262 /* just need a pointer to match */1263 pD3D9OldFb->Release();1264 }1265 1266 for (UINT i = 0; i < pSwapchain->cRTs; ++i)1267 {1268 PVBOXWDDMDISP_RENDERTGT pRT = &pSwapchain->aRTs[i];1269 if (pRT->pAlloc->enmD3DIfType != VBOXDISP_D3DIFTYPE_SURFACE)1270 continue;1271 BOOL fHasSurf = pRT->pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE ?1272 !!pRT->pAlloc->pD3DIf1273 :1274 !!pRT->pAlloc->pRc->aAllocations[0].pD3DIf;1275 if (!fForceCreate && !fHasSurf)1276 continue;1277 1278 IDirect3DSurface9* pD3D9OldSurf = NULL;1279 if (fHasSurf)1280 {1281 VOID *pvSwapchain = NULL;1282 /* since this can be texture, need to do the VBoxD3DIfSurfGet magic */1283 hr = VBoxD3DIfSurfGet(pRT->pAlloc->pRc, pRT->pAlloc->iAlloc, &pD3D9OldSurf);1284 Assert(hr == S_OK);1285 hr = pD3D9OldSurf->GetContainer(IID_IDirect3DSwapChain9, &pvSwapchain);1286 if (hr == S_OK)1287 {1288 Assert(pvSwapchain);1289 ((IDirect3DSwapChain9 *)pvSwapchain)->Release();1290 }1291 else1292 {1293 hr = S_OK;1294 Assert(!pvSwapchain);1295 }1296 1297 if (!pvSwapchain) /* no swapchain, it is already offscreen */1298 {1299 pD3D9OldSurf->Release();1300 continue;1301 }1302 Assert (pvSwapchain == pOldIf);1303 }1304 1305 IDirect3DSurface9* pD3D9NewSurf;1306 IDirect3DDevice9 *pDevice9If = pDevice->pDevice9If;1307 hr = pDevice9If->CreateRenderTarget(1308 Params.BackBufferWidth, Params.BackBufferHeight,1309 Params.BackBufferFormat,1310 Params.MultiSampleType,1311 Params.MultiSampleQuality,1312 TRUE, /*bLockable*/1313 &pD3D9NewSurf,1314 pRT->pAlloc->hSharedHandle ? &pRT->pAlloc->hSharedHandle : NULL1315 );1316 Assert(hr == S_OK);1317 if (FAILED(hr))1318 {1319 if (pD3D9OldSurf)1320 pD3D9OldSurf->Release();1321 break;1322 }1323 1324 if (pD3D9OldSurf)1325 {1326 if (pD3D9OldSurf != pD3D9OldFb)1327 {1328 VBOXVDBG_CHECK_SWAPCHAIN_SYNC(hr = pDevice9If->StretchRect(pD3D9OldSurf, NULL, pD3D9NewSurf, NULL, D3DTEXF_NONE);1329 Assert(hr == S_OK),1330 pRT->pAlloc, pD3D9OldSurf, NULL, pRT->pAlloc, pD3D9NewSurf, NULL);1331 }1332 else1333 {1334 hr = pOldIf->GetFrontBufferData(pD3D9NewSurf);1335 Assert(hr == S_OK);1336 }1337 }1338 if (FAILED(hr))1339 {1340 if (pD3D9OldSurf)1341 pD3D9OldSurf->Release();1342 break;1343 }1344 1345 Assert(pRT->pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);1346 1347 if (pRT->pAlloc->pD3DIf)1348 pRT->pAlloc->pD3DIf->Release();1349 pRT->pAlloc->pD3DIf = pD3D9NewSurf;1350 if (pD3D9OldSurf)1351 pD3D9OldSurf->Release();1352 }1353 1354 return hr;1355 }1356 1357 1358 /**1359 * @return old RtReportingPresent state1360 */1361 static HRESULT vboxWddmSwapchainSwtichRtPresent(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)1362 {1363 if (pSwapchain->fFlags.bRtReportingPresent)1364 return S_OK;1365 1366 HRESULT hr;1367 pSwapchain->bRTFbCopyUpToDate = FALSE;1368 if (pSwapchain->pRenderTargetFbCopy)1369 {1370 pSwapchain->pRenderTargetFbCopy->Release();1371 pSwapchain->pRenderTargetFbCopy = NULL;1372 }1373 1374 hr = vboxWddmSwapchainSwtichOffscreenRt(pDevice, pSwapchain,1375 TRUE /* force offscreen surface creation right away. This way we ensure the swapchain data1376 * is always uptodate which allows making the vboxWddmSwapchainRtSynch behave as a nop */1377 );1378 Assert(hr == S_OK);1379 if (FAILED(hr))1380 return hr;1381 1382 /* ensure we update device RTs to offscreen ones we just created */1383 for (UINT i = 0; i < pDevice->cRTs; ++i)1384 {1385 PVBOXWDDMDISP_ALLOCATION pRtAlloc = pDevice->apRTs[i];1386 if (!pRtAlloc) continue;1387 for (UINT j = 0; j < pSwapchain->cRTs; ++j)1388 {1389 PVBOXWDDMDISP_ALLOCATION pAlloc = pSwapchain->aRTs[j].pAlloc;1390 if (pRtAlloc == pAlloc)1391 {1392 hr = vboxWddmRenderTargetSet(pDevice, i, pAlloc, TRUE);1393 Assert(hr == S_OK);1394 }1395 }1396 }1397 1398 pSwapchain->fFlags.bRtReportingPresent = TRUE;1399 return hr;1400 }1401 1402 HRESULT vboxWddmSwapchainChkCreateIf(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)1403 {1404 if (!pSwapchain->fFlags.bChanged && pSwapchain->pSwapChainIf)1405 return S_OK;1406 /* preserve the old one */1407 IDirect3DSwapChain9 * pOldIf = pSwapchain->pSwapChainIf;1408 HRESULT hr = S_OK;1409 BOOL bReuseSwapchain = FALSE;1410 BOOL fNeedRtPresentSwitch = FALSE;1411 1412 if (pSwapchain->fFlags.bSwitchReportingPresent || pSwapchain->cRTs > VBOXWDDMDISP_MAX_DIRECT_RTS)1413 {1414 pSwapchain->fFlags.bSwitchReportingPresent = FALSE;1415 /* indicae switch to Render Target Reporting Present mode is needed */1416 fNeedRtPresentSwitch = TRUE;1417 // vboxWddmSwapchainSwtichRtPresent(pDevice, pSwapchain);1418 }1419 else1420 {1421 for (UINT i = 0; i < pSwapchain->cRTs; ++i)1422 {1423 if (pSwapchain->aRTs[i].pAlloc->enmD3DIfType != VBOXDISP_D3DIFTYPE_SURFACE1424 && (pSwapchain->aRTs[i].pAlloc->enmD3DIfType != VBOXDISP_D3DIFTYPE_UNDEFINED1425 || pSwapchain->aRTs[i].pAlloc->enmType != VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE1426 ))1427 {1428 fNeedRtPresentSwitch = TRUE;1429 break;1430 }1431 }1432 }1433 1434 /* check if we need to re-create the swapchain */1435 if (pOldIf)1436 {1437 if (fNeedRtPresentSwitch)1438 {1439 /* the number of swapchain backbuffers does not matter */1440 bReuseSwapchain = TRUE;1441 }1442 else1443 {1444 D3DPRESENT_PARAMETERS OldParams;1445 hr = pOldIf->GetPresentParameters(&OldParams);1446 Assert(hr == S_OK);1447 if (hr == S_OK)1448 {1449 if (OldParams.BackBufferCount == pSwapchain->cRTs-1)1450 {1451 bReuseSwapchain = TRUE;1452 }1453 }1454 }1455 }1456 1457 /* first create the new one */1458 IDirect3DSwapChain9 * pNewIf = NULL; /* Shut up MSC. */1459 ///1460 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;1461 #ifdef DEBUG1462 UINT cSurfs = pSwapchain->cRTs;1463 #endif1464 IDirect3DDevice9 *pDevice9If = NULL;1465 HWND hOldWnd = pSwapchain->hWnd;1466 if (!bReuseSwapchain)1467 {1468 VBOXWINEEX_D3DPRESENT_PARAMETERS Params;1469 vboxWddmSwapchainFillPresentParams(pSwapchain, &Params.Base);1470 Params.pHgsmi = NULL;1471 1472 if (hr == S_OK)1473 {1474 DWORD fFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;1475 1476 Params.Base.hDeviceWindow = NULL;1477 /** @todo it seems there should be a way to detect this correctly since1478 * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */1479 Params.Base.Windowed = TRUE;1480 // params.EnableAutoDepthStencil = FALSE;1481 // params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;1482 // params.Flags;1483 // params.FullScreen_RefreshRateInHz;1484 // params.FullScreen_PresentationInterval;1485 if (!pDevice->pDevice9If)1486 {1487 #ifdef VBOX_WITH_CRHGSMI1488 Params.pHgsmi = &pDevice->Uhgsmi.BasePrivate.Base;1489 #else1490 Params.pHgsmi = NULL;1491 #endif1492 hr = pAdapter->D3D.pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, fFlags,1493 &Params.Base, &pDevice9If);1494 Assert(hr == S_OK);1495 if (hr == S_OK)1496 {1497 Assert(Params.Base.hDeviceWindow);1498 pSwapchain->hWnd = Params.Base.hDeviceWindow;1499 pDevice->pDevice9If = pDevice9If;1500 hr = pDevice9If->GetSwapChain(0, &pNewIf);1501 Assert(hr == S_OK);1502 if (hr == S_OK)1503 {1504 Assert(pNewIf);1505 }1506 else1507 {1508 pDevice9If->Release();1509 }1510 }1511 }1512 else1513 {1514 pDevice9If = pDevice->pDevice9If;1515 1516 if (pOldIf)1517 {1518 /* need to copy data to offscreen rt to ensure the data is preserved1519 * since the swapchain data may become invalid once we create a new swapchain1520 * and pass the current swapchain's window to it1521 * thus vboxWddmSwapchainSynch will not be able to do synchronization */1522 hr = vboxWddmSwapchainSwtichOffscreenRt(pDevice, pSwapchain, FALSE);1523 Assert(hr == S_OK);1524 }1525 1526 /* re-use swapchain window1527 * this will invalidate the previusly used swapchain */1528 Params.Base.hDeviceWindow = pSwapchain->hWnd;1529 1530 hr = pDevice->pDevice9If->CreateAdditionalSwapChain(&Params.Base, &pNewIf);1531 Assert(hr == S_OK);1532 if (hr == S_OK)1533 {1534 Assert(Params.Base.hDeviceWindow);1535 pSwapchain->hWnd = Params.Base.hDeviceWindow;1536 Assert(pNewIf);1537 }1538 }1539 }1540 }1541 else1542 {1543 Assert(pOldIf);1544 Assert(hOldWnd); NOREF(hOldWnd);1545 pNewIf = pOldIf;1546 /* to ensure the swapchain is not deleted once we release the pOldIf */1547 pNewIf->AddRef();1548 }1549 1550 if (FAILED(hr))1551 return hr;1552 1553 Assert(pNewIf);1554 pSwapchain->pSwapChainIf = pNewIf;1555 1556 if (fNeedRtPresentSwitch)1557 {1558 hr = vboxWddmSwapchainSwtichRtPresent(pDevice, pSwapchain);1559 }1560 else1561 {1562 #ifndef VBOXWDDM_WITH_VISIBLE_FB1563 if (!pSwapchain->fFlags.bRtReportingPresent)1564 {1565 pSwapchain->bRTFbCopyUpToDate = FALSE;1566 # if defined(VBOXDISP_WITH_WINE_BB_WORKAROUND) && defined(VBOX_WINE_WITH_FAST_INTERSWAPCHAIN_BLT)1567 /* if wine is able to do fast fb->bb blits, we will use backbuffer directly,1568 * this is NOT possible currently */1569 if (pSwapchain->cRTs == 1)1570 {1571 /* we will assign it to wine backbuffer on a swapchain synch */1572 if (pSwapchain->pRenderTargetFbCopy)1573 {1574 pSwapchain->pRenderTargetFbCopy->Release();1575 pSwapchain->pRenderTargetFbCopy = NULL;1576 }1577 }1578 else1579 # endif1580 if (!pSwapchain->pRenderTargetFbCopy)1581 {1582 D3DPRESENT_PARAMETERS Params;1583 vboxWddmSwapchainFillPresentParams(pSwapchain, &Params);1584 IDirect3DSurface9* pD3D9Surf;1585 hr = pDevice9If->CreateRenderTarget(1586 Params.BackBufferWidth, Params.BackBufferHeight,1587 Params.BackBufferFormat,1588 Params.MultiSampleType,1589 Params.MultiSampleQuality,1590 TRUE, /*bLockable*/1591 &pD3D9Surf,1592 NULL /* HANDLE* pSharedHandle */1593 );1594 Assert(hr == S_OK);1595 if (hr == S_OK)1596 {1597 Assert(pD3D9Surf);1598 pSwapchain->pRenderTargetFbCopy = pD3D9Surf;1599 }1600 }1601 }1602 #endif1603 }1604 1605 /* ignore any subsequen failures */1606 Assert(hr == S_OK);1607 1608 1609 #ifdef DEBUG1610 for (UINT i = 0; i < cSurfs; ++i)1611 {1612 PVBOXWDDMDISP_RENDERTGT pRt = &pSwapchain->aRTs[i];1613 Assert(pRt->pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE1614 || pRt->pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE);1615 Assert(pRt->pAlloc->pRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM);1616 }1617 #endif1618 1619 hr = vboxWddmSwapchainSynch(pDevice, pSwapchain);1620 Assert(hr == S_OK);1621 1622 Assert(!pSwapchain->fFlags.bChanged);1623 Assert(!pSwapchain->fFlags.bSwitchReportingPresent);1624 if (pOldIf)1625 {1626 Assert(hOldWnd);1627 pOldIf->Release();1628 }1629 else1630 {1631 Assert(!hOldWnd);1632 }1633 return S_OK;1634 }1635 1636 static HRESULT vboxWddmSwapchainCreateIfForRc(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_RESOURCE pRc,1637 PVBOXWDDMDISP_SWAPCHAIN *ppSwapchain)1638 {1639 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainCreateForRc(pDevice, pRc);1640 Assert(pSwapchain);1641 *ppSwapchain = NULL;1642 if (pSwapchain)1643 {1644 HRESULT hr = vboxWddmSwapchainChkCreateIf(pDevice, pSwapchain);1645 Assert(hr == S_OK);1646 if (hr == S_OK)1647 {1648 *ppSwapchain = pSwapchain;1649 }1650 return hr;1651 }1652 return E_OUTOFMEMORY;1653 }1654 1655 static HRESULT vboxWddmSwapchainPresentPerform(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);1656 1657 static HRESULT vboxWddmSwapchainBbUpdate(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain,1658 PVBOXWDDMDISP_ALLOCATION pBbAlloc)1659 {1660 Assert(!pSwapchain->fFlags.bRtReportingPresent);1661 for (UINT i = 0; i < pSwapchain->cRTs; ++i)1662 {1663 PVBOXWDDMDISP_ALLOCATION pCurBb = vboxWddmSwapchainGetBb(pSwapchain)->pAlloc;1664 if (pCurBb == pBbAlloc)1665 return S_OK;1666 1667 HRESULT hr = vboxWddmSwapchainPresentPerform(pDevice, pSwapchain);1668 if (FAILED(hr))1669 {1670 WARN(("vboxWddmSwapchainPresentPerform failed, hr (0x%x)", hr));1671 return hr;1672 }1673 }1674 1675 AssertMsgFailed(("the given allocation not par of the swapchain\n"));1676 return E_FAIL;1677 }1678 1679 /* get the surface for the specified allocation in the swapchain */1680 static HRESULT vboxWddmSwapchainSurfGet(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain,1681 PVBOXWDDMDISP_ALLOCATION pAlloc, IDirect3DSurface9 **ppSurf)1682 {1683 RT_NOREF(pDevice);1684 Assert(pAlloc->pSwapchain == pSwapchain);1685 1686 #ifndef VBOXWDDM_WITH_VISIBLE_FB1687 if (!pSwapchain->fFlags.bRtReportingPresent1688 && vboxWddmSwapchainGetFb(pSwapchain)->pAlloc == pAlloc1689 # ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND1690 1691 && vboxWddmSwapchainNumRTs(pSwapchain) != 1 /* for swapchains w/o a backbuffer the alloc will contain the back-buffer actually */1692 )1693 {1694 /* this is a front-buffer */1695 Assert(vboxWddmSwapchainNumRTs(pSwapchain) > 1);1696 IDirect3DSurface9 *pSurf = pSwapchain->pRenderTargetFbCopy;1697 Assert(pSurf);1698 pSurf->AddRef();1699 if (!pSwapchain->bRTFbCopyUpToDate)1700 {1701 HRESULT hr = pSwapchain->pSwapChainIf->GetFrontBufferData(pSurf);1702 if (FAILED(hr))1703 {1704 WARN(("GetFrontBufferData failed, hr (0x%x)", hr));1705 pSurf->Release();1706 return hr;1707 }1708 pSwapchain->bRTFbCopyUpToDate = TRUE;1709 }1710 1711 *ppSurf = pSurf;1712 return S_OK;1713 }1714 # endif1715 #endif1716 1717 /* if this is not a front-buffer - just return the surface associated with the allocation */1718 return VBoxD3DIfSurfGet(pAlloc->pRc, pAlloc->iAlloc, ppSurf);1719 }1720 1721 static HRESULT vboxWddmSwapchainRtSurfGet(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain, UINT iRt,1722 PVBOXWDDMDISP_ALLOCATION pAlloc, BOOL bOnSwapchainSynch, IDirect3DSurface9 **ppSurf)1723 {1724 Assert(pAlloc->pSwapchain == pSwapchain);1725 HRESULT hr = S_OK;1726 1727 /* do the necessary swapchain synchronization first,1728 * not needed on swapchain synch since it is done already and we're called here just to set RTs */1729 if (!bOnSwapchainSynch)1730 {1731 1732 if (!pSwapchain->fFlags.bRtReportingPresent)1733 {1734 /* iRt != 0 is untested here !! */1735 Assert(iRt == 0);1736 if (iRt == 0)1737 {1738 hr = vboxWddmSwapchainBbUpdate(pDevice, pSwapchain, pAlloc);1739 if (FAILED(hr))1740 {1741 WARN(("vboxWddmSwapchainBbUpdate failed, hr(0x%x)",hr));1742 return hr;1743 }1744 }1745 }1746 1747 /// @todo Assert(!pSwapchain->fFlags.bChanged);1748 Assert(pSwapchain->pSwapChainIf);1749 hr = vboxWddmSwapchainChkCreateIf(pDevice, pSwapchain);1750 if (FAILED(hr))1751 {1752 WARN(("vboxWddmSwapchainChkCreateIf failed, hr(0x%x)",hr));1753 return hr;1754 }1755 }1756 1757 /// @todo Assert(vboxWddmSwapchainGetBb(pSwapchain)->pAlloc == pAlloc || iRt != 0);1758 IDirect3DSurface9 *pSurf;1759 hr = vboxWddmSwapchainSurfGet(pDevice, pSwapchain, pAlloc, &pSurf);1760 if (FAILED(hr))1761 {1762 WARN(("vboxWddmSwapchainSurfGet failed, hr(0x%x)", hr));1763 return hr;1764 }1765 1766 *ppSurf = pSurf;1767 return S_OK;1768 1769 }1770 1771 static HRESULT vboxWddmSwapchainPresentPerform(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)1772 {1773 HRESULT hr;1774 1775 VBOXVDBG_DUMP_PRESENT_ENTER(pDevice, pSwapchain);1776 1777 if (!pSwapchain->fFlags.bRtReportingPresent)1778 {1779 hr = pSwapchain->pSwapChainIf->Present(NULL, NULL, NULL, NULL, 0);1780 Assert(hr == S_OK);1781 if (FAILED(hr))1782 return hr;1783 }1784 else1785 {1786 PVBOXWDDMDISP_ALLOCATION pCurBb = vboxWddmSwapchainGetBb(pSwapchain)->pAlloc;1787 IDirect3DSurface9 *pSurf;1788 hr = vboxWddmSwapchainSurfGet(pDevice, pSwapchain, pCurBb, &pSurf);1789 Assert(hr == S_OK);1790 if (FAILED(hr))1791 return hr;1792 hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DSwapchain9Present(pSwapchain->pSwapChainIf, pSurf);1793 Assert(hr == S_OK);1794 pSurf->Release();1795 if (FAILED(hr))1796 return hr;1797 }1798 1799 VBOXVDBG_DUMP_PRESENT_LEAVE(pDevice, pSwapchain);1800 1801 pSwapchain->bRTFbCopyUpToDate = FALSE;1802 vboxWddmSwapchainFlip(pSwapchain);1803 Assert(!pSwapchain->fFlags.bChanged);1804 Assert(!pSwapchain->fFlags.bSwitchReportingPresent);1805 hr = vboxWddmSwapchainSynch(pDevice, pSwapchain);1806 Assert(hr == S_OK);1807 return hr;1808 }1809 1810 static HRESULT vboxWddmSwapchainPresent(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pBbAlloc)1811 {1812 /* we currently *assume* that presenting shared resource is only possible when 3d app is rendering with composited desktop on,1813 * no need to do anything else since dwm will present everything for us */1814 if (pBbAlloc->hSharedHandle)1815 {1816 VBOXVDBG_ASSERT_IS_DWM(FALSE);1817 1818 HRESULT hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Flush((IDirect3DDevice9Ex*)pDevice->pDevice9If);1819 Assert(hr == S_OK); NOREF(hr);1820 1821 vboxWddmDalNotifyChange(pDevice);1822 1823 return S_OK;1824 }1825 1826 VBOXVDBG_ASSERT_IS_DWM(TRUE);1827 1828 BOOL bNeedPresent;1829 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainFindCreate(pDevice, pBbAlloc, &bNeedPresent);1830 Assert(pSwapchain);1831 if (!bNeedPresent)1832 return S_OK;1833 if (pSwapchain)1834 {1835 HRESULT hr = vboxWddmSwapchainChkCreateIf(pDevice, pSwapchain);1836 Assert(hr == S_OK);1837 if (hr == S_OK)1838 {1839 hr = vboxWddmSwapchainPresentPerform(pDevice, pSwapchain);1840 Assert(hr == S_OK);1841 }1842 return hr;1843 }1844 return E_OUTOFMEMORY;1845 }1846 1847 #if 0 //def DEBUG1848 static void vboxWddmDbgRenderTargetUpdateCheckSurface(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pAlloc, uint32_t iBBuf)1849 {1850 IDirect3DSurface9 *pD3D9Surf;1851 Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);1852 IDirect3DDevice9 * pDevice9If = pDevice->aScreens[pDevice->iPrimaryScreen].pDevice9If;1853 HRESULT hr = pDevice9If->GetBackBuffer(0 /*UINT iSwapChain*/,1854 iBBuf, D3DBACKBUFFER_TYPE_MONO, &pD3D9Surf);1855 Assert(hr == S_OK);1856 if (hr == S_OK)1857 {1858 Assert(pD3D9Surf);1859 Assert(pD3D9Surf == pAlloc->pD3DIf);1860 pD3D9Surf->Release();1861 }1862 }1863 1864 static void vboxWddmDbgRenderTargetCheck(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_RESOURCE pRc, uint32_t iNewRTFB)1865 {1866 PVBOXWDDMDISP_ALLOCATION pAlloc;1867 UINT iBBuf = 0;1868 Assert(iNewRTFB < pRc->cAllocations);1869 1870 for (UINT i = 1; i < pRc->cAllocations; ++i, ++iBBuf)1871 {1872 UINT iAlloc = (iNewRTFB + i) % pRc->cAllocations;1873 Assert(iAlloc != iNewRTFB);1874 pAlloc = &pRc->aAllocations[iAlloc];1875 vboxWddmDbgRenderTargetUpdateCheckSurface(pDevice, pAlloc, iBBuf);1876 }1877 1878 pAlloc = &pRc->aAllocations[iNewRTFB];1879 #ifdef VBOXWDDM_WITH_VISIBLE_FB1880 vboxWddmDbgRenderTargetUpdateCheckSurface(pDevice, pAlloc, ~0UL /* <- for the frontbuffer */);1881 #else1882 Assert((!pAlloc->pD3DIf) == (pRc->cAllocations > 1));1883 #endif1884 1885 for (UINT i = 0; i < pRc->cAllocations; ++i)1886 {1887 pAlloc = &pRc->aAllocations[i];1888 if (iNewRTFB == i)1889 {1890 Assert((!pAlloc->pD3DIf) == (pRc->cAllocations > 1));1891 }1892 1893 for (UINT j = i+1; j < pRc->cAllocations; ++j)1894 {1895 PVBOXWDDMDISP_ALLOCATION pAllocJ = &pRc->aAllocations[j];1896 Assert(pAlloc->pD3DIf != pAllocJ->pD3DIf);1897 }1898 }1899 }1900 1901 # define VBOXVDBG_RTGT_STATECHECK(_pDev) (vboxWddmDbgRenderTargetCheck((_pDev), (_pDev)->aScreens[(_pDev)->iPrimaryScreen].pRenderTargetRc, (_pDev)->aScreens[(_pDev)->iPrimaryScreen].iRenderTargetFrontBuf))1902 #else1903 # define VBOXVDBG_RTGT_STATECHECK(_pDev) do{}while(0)1904 #endif1905 1906 /******/1907 1908 static HRESULT vboxWddmRenderTargetSet(PVBOXWDDMDISP_DEVICE pDevice, UINT iRt, PVBOXWDDMDISP_ALLOCATION pAlloc,1909 BOOL bOnSwapchainSynch)1910 {1911 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);1912 HRESULT hr = S_OK;1913 IDirect3DSurface9 *pD3D9Surf = NULL;1914 if (pAlloc)1915 {1916 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainForAlloc(pAlloc);1917 if (pSwapchain)1918 {1919 hr = vboxWddmSwapchainRtSurfGet(pDevice, pSwapchain, iRt, pAlloc, bOnSwapchainSynch, &pD3D9Surf);1920 if (FAILED(hr))1921 {1922 WARN(("vboxWddmSwapchainRtSurfGet failed, hr(0x%x)",hr));1923 return hr;1924 }1925 }1926 else1927 {1928 hr = VBoxD3DIfSurfGet(pAlloc->pRc, pAlloc->iAlloc, &pD3D9Surf);1929 if (FAILED(hr))1930 {1931 WARN(("VBoxD3DIfSurfGet failed, hr(0x%x)",hr));1932 return hr;1933 }1934 }1935 1936 Assert(pD3D9Surf);1937 }1938 1939 hr = pDevice9If->SetRenderTarget(iRt, pD3D9Surf);1940 if (hr == S_OK)1941 {1942 Assert(iRt < pDevice->cRTs);1943 pDevice->apRTs[iRt] = pAlloc;1944 }1945 else1946 {1947 /** @todo This is workaround for wine 1 render target. */1948 if (!pAlloc)1949 {1950 pDevice->apRTs[iRt] = NULL;1951 hr = S_OK;1952 }1953 else1954 {1955 AssertFailed();1956 }1957 }1958 1959 if (pD3D9Surf)1960 {1961 pD3D9Surf->Release();1962 }1963 1964 return hr;1965 }1966 1967 static HRESULT APIENTRY vboxWddmDispGetCaps (HANDLE hAdapter, CONST D3DDDIARG_GETCAPS* pData)1968 {1969 VBOXDISP_DDI_PROLOGUE_ADP(hAdapter);1970 1971 vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p), caps type(%d)\n", hAdapter, pData->Type));1972 1973 VBOXDISPCRHGSMI_SCOPE_SET_GLOBAL();1974 1975 HRESULT hr = S_OK;1976 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;1977 1978 switch (pData->Type)1979 {1980 case D3DDDICAPS_DDRAW:1981 {1982 Assert(!VBOXDISPMODE_IS_3D(pAdapter));1983 Assert(pData->DataSize == sizeof (DDRAW_CAPS));1984 if (pData->DataSize >= sizeof (DDRAW_CAPS))1985 {1986 memset(pData->pData, 0, sizeof (DDRAW_CAPS));1987 #ifdef VBOX_WITH_VIDEOHWACCEL1988 if (!VBOXDISPMODE_IS_3D(pAdapter))1989 {1990 if (vboxVhwaHasCKeying(pAdapter))1991 {1992 DDRAW_CAPS *pCaps = (DDRAW_CAPS*)pData->pData;1993 pCaps->Caps |= DDRAW_CAPS_COLORKEY;1994 // pCaps->Caps2 |= DDRAW_CAPS2_FLIPNOVSYNC;1995 }1996 }1997 else1998 {1999 WARN(("D3DDDICAPS_DDRAW query for D3D mode!"));2000 }2001 #endif2002 }2003 else2004 hr = E_INVALIDARG;2005 break;2006 }2007 case D3DDDICAPS_DDRAW_MODE_SPECIFIC:2008 {2009 Assert(!VBOXDISPMODE_IS_3D(pAdapter));2010 Assert(pData->DataSize == sizeof (DDRAW_MODE_SPECIFIC_CAPS));2011 if (pData->DataSize >= sizeof (DDRAW_MODE_SPECIFIC_CAPS))2012 {2013 DDRAW_MODE_SPECIFIC_CAPS * pCaps = (DDRAW_MODE_SPECIFIC_CAPS*)pData->pData;2014 memset(&pCaps->Caps /* do not cleanup the first "Head" field,2015 zero starting with the one following "Head", i.e. Caps */,2016 0, sizeof(DDRAW_MODE_SPECIFIC_CAPS) - RT_UOFFSETOF(DDRAW_MODE_SPECIFIC_CAPS, Caps));2017 #ifdef VBOX_WITH_VIDEOHWACCEL2018 if (!VBOXDISPMODE_IS_3D(pAdapter))2019 {2020 VBOXVHWA_INFO *pSettings = &pAdapter->aHeads[pCaps->Head].Vhwa.Settings;2021 if (pSettings->fFlags & VBOXVHWA_F_ENABLED)2022 {2023 pCaps->Caps |= MODE_CAPS_OVERLAY | MODE_CAPS_OVERLAYSTRETCH;2024 2025 if (pSettings->fFlags & VBOXVHWA_F_CKEY_DST)2026 {2027 pCaps->CKeyCaps |= MODE_CKEYCAPS_DESTOVERLAY2028 | MODE_CKEYCAPS_DESTOVERLAYYUV /* ?? */2029 ;2030 }2031 2032 if (pSettings->fFlags & VBOXVHWA_F_CKEY_SRC)2033 {2034 pCaps->CKeyCaps |= MODE_CKEYCAPS_SRCOVERLAY2035 | MODE_CKEYCAPS_SRCOVERLAYCLRSPACE /* ?? */2036 | MODE_CKEYCAPS_SRCOVERLAYCLRSPACEYUV /* ?? */2037 | MODE_CKEYCAPS_SRCOVERLAYYUV /* ?? */2038 ;2039 }2040 2041 pCaps->FxCaps = MODE_FXCAPS_OVERLAYSHRINKX2042 | MODE_FXCAPS_OVERLAYSHRINKY2043 | MODE_FXCAPS_OVERLAYSTRETCHX2044 | MODE_FXCAPS_OVERLAYSTRETCHY;2045 2046 2047 pCaps->MaxVisibleOverlays = pSettings->cOverlaysSupported;2048 pCaps->MinOverlayStretch = 1;2049 pCaps->MaxOverlayStretch = 32000;2050 }2051 }2052 else2053 {2054 WARN(("D3DDDICAPS_DDRAW_MODE_SPECIFIC query for D3D mode!"));2055 }2056 #endif2057 }2058 else2059 hr = E_INVALIDARG;2060 break;2061 }2062 case D3DDDICAPS_GETFORMATCOUNT:2063 *((uint32_t*)pData->pData) = pAdapter->Formats.cFormatOps;2064 break;2065 case D3DDDICAPS_GETFORMATDATA:2066 Assert(pData->DataSize == pAdapter->Formats.cFormatOps * sizeof (FORMATOP));2067 memcpy(pData->pData, pAdapter->Formats.paFormatOps, pAdapter->Formats.cFormatOps * sizeof (FORMATOP));2068 break;2069 case D3DDDICAPS_GETD3DQUERYCOUNT:2070 #if 12071 *((uint32_t*)pData->pData) = VBOX_QUERYTYPE_COUNT();2072 #else2073 *((uint32_t*)pData->pData) = 0;2074 #endif2075 break;2076 case D3DDDICAPS_GETD3DQUERYDATA:2077 #if 12078 Assert(pData->DataSize == VBOX_QUERYTYPE_COUNT() * sizeof (D3DDDIQUERYTYPE));2079 memcpy(pData->pData, gVBoxQueryTypes, VBOX_QUERYTYPE_COUNT() * sizeof (D3DDDIQUERYTYPE));2080 #else2081 Assert(0);2082 memset(pData->pData, 0, pData->DataSize);2083 #endif2084 break;2085 case D3DDDICAPS_GETD3D3CAPS:2086 Assert(!VBOXDISPMODE_IS_3D(pAdapter));2087 Assert(pData->DataSize == sizeof (D3DHAL_GLOBALDRIVERDATA));2088 if (pData->DataSize >= sizeof (D3DHAL_GLOBALDRIVERDATA))2089 {2090 D3DHAL_GLOBALDRIVERDATA *pCaps = (D3DHAL_GLOBALDRIVERDATA *)pData->pData;2091 memset (pCaps, 0, sizeof (D3DHAL_GLOBALDRIVERDATA));2092 pCaps->dwSize = sizeof (D3DHAL_GLOBALDRIVERDATA);2093 pCaps->hwCaps.dwSize = sizeof (D3DDEVICEDESC_V1);2094 pCaps->hwCaps.dwFlags = D3DDD_COLORMODEL2095 | D3DDD_DEVCAPS2096 | D3DDD_DEVICERENDERBITDEPTH;2097 2098 pCaps->hwCaps.dcmColorModel = D3DCOLOR_RGB;2099 pCaps->hwCaps.dwDevCaps = D3DDEVCAPS_CANRENDERAFTERFLIP2100 // | D3DDEVCAPS_DRAWPRIMTLVERTEX2101 | D3DDEVCAPS_EXECUTESYSTEMMEMORY2102 | D3DDEVCAPS_EXECUTEVIDEOMEMORY2103 // | D3DDEVCAPS_FLOATTLVERTEX2104 | D3DDEVCAPS_HWRASTERIZATION2105 // | D3DDEVCAPS_HWTRANSFORMANDLIGHT2106 // | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY2107 // | D3DDEVCAPS_TEXTUREVIDEOMEMORY2108 ;2109 pCaps->hwCaps.dtcTransformCaps.dwSize = sizeof (D3DTRANSFORMCAPS);2110 pCaps->hwCaps.dtcTransformCaps.dwCaps = 0;2111 pCaps->hwCaps.bClipping = FALSE;2112 pCaps->hwCaps.dlcLightingCaps.dwSize = sizeof (D3DLIGHTINGCAPS);2113 pCaps->hwCaps.dlcLightingCaps.dwCaps = 0;2114 pCaps->hwCaps.dlcLightingCaps.dwLightingModel = 0;2115 pCaps->hwCaps.dlcLightingCaps.dwNumLights = 0;2116 pCaps->hwCaps.dpcLineCaps.dwSize = sizeof (D3DPRIMCAPS);2117 pCaps->hwCaps.dpcLineCaps.dwMiscCaps = 0;2118 pCaps->hwCaps.dpcLineCaps.dwRasterCaps = 0;2119 pCaps->hwCaps.dpcLineCaps.dwZCmpCaps = 0;2120 pCaps->hwCaps.dpcLineCaps.dwSrcBlendCaps = 0;2121 pCaps->hwCaps.dpcLineCaps.dwDestBlendCaps = 0;2122 pCaps->hwCaps.dpcLineCaps.dwAlphaCmpCaps = 0;2123 pCaps->hwCaps.dpcLineCaps.dwShadeCaps = 0;2124 pCaps->hwCaps.dpcLineCaps.dwTextureCaps = 0;2125 pCaps->hwCaps.dpcLineCaps.dwTextureFilterCaps = 0;2126 pCaps->hwCaps.dpcLineCaps.dwTextureBlendCaps = 0;2127 pCaps->hwCaps.dpcLineCaps.dwTextureAddressCaps = 0;2128 pCaps->hwCaps.dpcLineCaps.dwStippleWidth = 0;2129 pCaps->hwCaps.dpcLineCaps.dwStippleHeight = 0;2130 2131 pCaps->hwCaps.dpcTriCaps.dwSize = sizeof (D3DPRIMCAPS);2132 pCaps->hwCaps.dpcTriCaps.dwMiscCaps = 0;2133 pCaps->hwCaps.dpcTriCaps.dwRasterCaps = 0;2134 pCaps->hwCaps.dpcTriCaps.dwZCmpCaps = 0;2135 pCaps->hwCaps.dpcTriCaps.dwSrcBlendCaps = 0;2136 pCaps->hwCaps.dpcTriCaps.dwDestBlendCaps = 0;2137 pCaps->hwCaps.dpcTriCaps.dwAlphaCmpCaps = 0;2138 pCaps->hwCaps.dpcTriCaps.dwShadeCaps = 0;2139 pCaps->hwCaps.dpcTriCaps.dwTextureCaps = 0;2140 pCaps->hwCaps.dpcTriCaps.dwTextureFilterCaps = 0;2141 pCaps->hwCaps.dpcTriCaps.dwTextureBlendCaps = 0;2142 pCaps->hwCaps.dpcTriCaps.dwTextureAddressCaps = 0;2143 pCaps->hwCaps.dpcTriCaps.dwStippleWidth = 0;2144 pCaps->hwCaps.dpcTriCaps.dwStippleHeight = 0;2145 pCaps->hwCaps.dwDeviceRenderBitDepth = DDBD_8 | DDBD_16 | DDBD_24 | DDBD_32;2146 pCaps->hwCaps.dwDeviceZBufferBitDepth = 0;2147 pCaps->hwCaps.dwMaxBufferSize = 0;2148 pCaps->hwCaps.dwMaxVertexCount = 0;2149 2150 2151 pCaps->dwNumVertices = 0;2152 pCaps->dwNumClipVertices = 0;2153 pCaps->dwNumTextureFormats = 0;//pAdapter->cSurfDescs;2154 pCaps->lpTextureFormats = NULL;//pAdapter->paSurfDescs;2155 }2156 else2157 hr = E_INVALIDARG;2158 break;2159 case D3DDDICAPS_GETD3D7CAPS:2160 Assert(!VBOXDISPMODE_IS_3D(pAdapter));2161 Assert(pData->DataSize == sizeof (D3DHAL_D3DEXTENDEDCAPS));2162 if (pData->DataSize >= sizeof (D3DHAL_D3DEXTENDEDCAPS))2163 {2164 memset(pData->pData, 0, sizeof (D3DHAL_D3DEXTENDEDCAPS));2165 D3DHAL_D3DEXTENDEDCAPS *pCaps = (D3DHAL_D3DEXTENDEDCAPS*)pData->pData;2166 pCaps->dwSize = sizeof (D3DHAL_D3DEXTENDEDCAPS);2167 }2168 else2169 hr = E_INVALIDARG;2170 break;2171 case D3DDDICAPS_GETD3D9CAPS:2172 {2173 Assert(pData->DataSize == sizeof (D3DCAPS9));2174 if (pData->DataSize >= sizeof (D3DCAPS9))2175 {2176 Assert(VBOXDISPMODE_IS_3D(pAdapter));2177 if (VBOXDISPMODE_IS_3D(pAdapter))2178 {2179 memcpy(pData->pData, &pAdapter->D3D.Caps, sizeof (D3DCAPS9));2180 hr = S_OK;2181 break;2182 }2183 2184 memset(pData->pData, 0, sizeof (D3DCAPS9));2185 }2186 else2187 hr = E_INVALIDARG;2188 break;2189 }2190 case D3DDDICAPS_GETD3D8CAPS:2191 {2192 Assert(pData->DataSize == RT_UOFFSETOF(D3DCAPS9, DevCaps2));2193 if (pData->DataSize == RT_UOFFSETOF(D3DCAPS9, DevCaps2))2194 {2195 Assert(VBOXDISPMODE_IS_3D(pAdapter));2196 if (VBOXDISPMODE_IS_3D(pAdapter))2197 {2198 memcpy(pData->pData, &pAdapter->D3D.Caps, RT_UOFFSETOF(D3DCAPS9, DevCaps2));2199 hr = S_OK;2200 break;2201 }2202 }2203 else2204 hr = E_INVALIDARG;2205 break;2206 }2207 case D3DDDICAPS_GETGAMMARAMPCAPS:2208 *((uint32_t*)pData->pData) = 0;2209 break;2210 case D3DDDICAPS_GETVIDEOPROCESSORCAPS:2211 case D3DDDICAPS_GETEXTENSIONGUIDCOUNT:2212 case D3DDDICAPS_GETDECODEGUIDCOUNT:2213 case D3DDDICAPS_GETVIDEOPROCESSORDEVICEGUIDCOUNT:2214 case D3DDDICAPS_GETVIDEOPROCESSORRTFORMATCOUNT:2215 case D3DDDICAPS_GETCONTENTPROTECTIONCAPS:2216 if (pData->pData && pData->DataSize)2217 memset(pData->pData, 0, pData->DataSize);2218 break;2219 case D3DDDICAPS_GETMULTISAMPLEQUALITYLEVELS:2220 case D3DDDICAPS_GETD3D5CAPS:2221 case D3DDDICAPS_GETD3D6CAPS:2222 case D3DDDICAPS_GETDECODEGUIDS:2223 case D3DDDICAPS_GETDECODERTFORMATCOUNT:2224 case D3DDDICAPS_GETDECODERTFORMATS:2225 case D3DDDICAPS_GETDECODECOMPRESSEDBUFFERINFOCOUNT:2226 case D3DDDICAPS_GETDECODECOMPRESSEDBUFFERINFO:2227 case D3DDDICAPS_GETDECODECONFIGURATIONCOUNT:2228 case D3DDDICAPS_GETDECODECONFIGURATIONS:2229 case D3DDDICAPS_GETVIDEOPROCESSORDEVICEGUIDS:2230 case D3DDDICAPS_GETVIDEOPROCESSORRTFORMATS:2231 case D3DDDICAPS_GETVIDEOPROCESSORRTSUBSTREAMFORMATCOUNT:2232 case D3DDDICAPS_GETVIDEOPROCESSORRTSUBSTREAMFORMATS:2233 case D3DDDICAPS_GETPROCAMPRANGE:2234 case D3DDDICAPS_FILTERPROPERTYRANGE:2235 case D3DDDICAPS_GETEXTENSIONGUIDS:2236 case D3DDDICAPS_GETEXTENSIONCAPS:2237 vboxVDbgPrint((__FUNCTION__": unimplemented caps type(%d)\n", pData->Type));2238 Assert(0);2239 if (pData->pData && pData->DataSize)2240 memset(pData->pData, 0, pData->DataSize);2241 break;2242 default:2243 vboxVDbgPrint((__FUNCTION__": unknown caps type(%d)\n", pData->Type));2244 Assert(0);2245 }2246 2247 vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p), caps type(%d)\n", hAdapter, pData->Type));2248 2249 return S_OK;2250 }2251 2252 static HRESULT APIENTRY vboxWddmDDevSetRenderState(HANDLE hDevice, CONST D3DDDIARG_RENDERSTATE* pData)2253 {2254 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2255 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2256 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2257 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2258 Assert(pDevice);2259 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2260 HRESULT hr = pDevice9If->SetRenderState(vboxDDI2D3DRenderStateType(pData->State), pData->Value);2261 Assert(hr == S_OK);2262 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2263 return hr;2264 }2265 2266 static HRESULT APIENTRY vboxWddmDDevUpdateWInfo(HANDLE hDevice, CONST D3DDDIARG_WINFO* pData)2267 {2268 RT_NOREF(hDevice, pData);2269 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2270 // PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2271 // VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2272 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2273 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));2274 return S_OK;2275 }2276 2277 static HRESULT APIENTRY vboxWddmDDevValidateDevice(HANDLE hDevice, D3DDDIARG_VALIDATETEXTURESTAGESTATE* pData)2278 {2279 RT_NOREF(pData);2280 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2281 // PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2282 // VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2283 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));2284 #ifdef DEBUG_misha2285 /** @todo check if it's ok to always return success */2286 vboxVDbgPrint((__FUNCTION__": @todo: check if it's ok to always return success\n"));2287 Assert(0);2288 #endif2289 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2290 return S_OK;2291 }2292 2293 static HRESULT APIENTRY vboxWddmDDevSetTextureStageState(HANDLE hDevice, CONST D3DDDIARG_TEXTURESTAGESTATE* pData)2294 {2295 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2296 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2297 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2298 Assert(pDevice);2299 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2300 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2301 2302 VBOXWDDMDISP_TSS_LOOKUP lookup = vboxDDI2D3DTestureStageStateType(pData->State);2303 HRESULT hr;2304 2305 if (!lookup.bSamplerState)2306 {2307 hr = pDevice9If->SetTextureStageState(pData->Stage, D3DTEXTURESTAGESTATETYPE(lookup.dType), pData->Value);2308 }2309 else2310 {2311 hr = pDevice9If->SetSamplerState(pData->Stage, D3DSAMPLERSTATETYPE(lookup.dType), pData->Value);2312 }2313 2314 Assert(hr == S_OK);2315 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2316 return hr;2317 }2318 2319 static HRESULT APIENTRY vboxWddmDDevSetTexture(HANDLE hDevice, UINT Stage, HANDLE hTexture)2320 {2321 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2322 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2323 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2324 Assert(pDevice);2325 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2326 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2327 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hTexture;2328 // Assert(pRc);2329 IDirect3DBaseTexture9 *pD3DIfTex;2330 if (pRc)2331 {2332 VBOXVDBG_CHECK_SMSYNC(pRc);2333 if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE)2334 {2335 pD3DIfTex = (IDirect3DTexture9*)pRc->aAllocations[0].pD3DIf;2336 2337 VBOXVDBG_BREAK_SHARED(pRc);2338 VBOXVDBG_DUMP_SETTEXTURE(pRc);2339 }2340 else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE)2341 {2342 pD3DIfTex = (IDirect3DCubeTexture9*)pRc->aAllocations[0].pD3DIf;2343 2344 VBOXVDBG_BREAK_SHARED(pRc);2345 VBOXVDBG_DUMP_SETTEXTURE(pRc);2346 }2347 else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE)2348 {2349 pD3DIfTex = (IDirect3DVolumeTexture9*)pRc->aAllocations[0].pD3DIf;2350 2351 VBOXVDBG_BREAK_SHARED(pRc);2352 VBOXVDBG_DUMP_SETTEXTURE(pRc);2353 }2354 else2355 {2356 Assert(0);2357 pD3DIfTex = NULL;2358 }2359 2360 Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));2361 int idx = VBOXWDDMDISP_SAMPLER_IDX(Stage);2362 if (idx >= 0)2363 {2364 Assert(idx < RT_ELEMENTS(pDevice->aSamplerTextures));2365 #ifdef DEBUG_misha2366 if (VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(Stage))2367 {2368 WARN(("non-zero special sampler index not tested!\n"));2369 }2370 #endif2371 if (!pDevice->aSamplerTextures[idx])2372 {2373 ++pDevice->cSamplerTextures;2374 }2375 Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));2376 pDevice->aSamplerTextures[idx] = pRc;2377 }2378 else2379 {2380 WARN(("incorrect dampler index1! (%d)\n", Stage));2381 }2382 }2383 else2384 {2385 pD3DIfTex = NULL;2386 Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));2387 int idx = VBOXWDDMDISP_SAMPLER_IDX(Stage);2388 if (idx >= 0)2389 {2390 Assert(idx < RT_ELEMENTS(pDevice->aSamplerTextures));2391 if (pDevice->aSamplerTextures[idx])2392 {2393 Assert(pDevice->cSamplerTextures);2394 --pDevice->cSamplerTextures;2395 }2396 Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));2397 pDevice->aSamplerTextures[idx] = NULL;2398 }2399 else2400 {2401 WARN(("incorrect dampler index2! (%d)\n", Stage));2402 }2403 }2404 2405 HRESULT hr = pDevice9If->SetTexture(Stage, pD3DIfTex);2406 Assert(hr == S_OK);2407 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2408 return hr;2409 }2410 2411 static HRESULT APIENTRY vboxWddmDDevSetPixelShader(HANDLE hDevice, HANDLE hShaderHandle)2412 {2413 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2414 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2415 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2416 Assert(pDevice);2417 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2418 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2419 IDirect3DPixelShader9 *pShader = (IDirect3DPixelShader9*)hShaderHandle;2420 HRESULT hr = pDevice9If->SetPixelShader(pShader);2421 Assert(hr == S_OK);2422 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2423 return hr;2424 }2425 2426 static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConst(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONST* pData,2427 CONST FLOAT* pRegisters)2428 {2429 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2430 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2431 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2432 Assert(pDevice);2433 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2434 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2435 HRESULT hr = pDevice9If->SetPixelShaderConstantF(pData->Register, pRegisters, pData->Count);2436 Assert(hr == S_OK);2437 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2438 return hr;2439 }2440 2441 static HRESULT APIENTRY vboxWddmDDevSetStreamSourceUm(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCEUM* pData,2442 CONST VOID* pUMBuffer )2443 {2444 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2445 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2446 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2447 Assert(pDevice);2448 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2449 HRESULT hr = S_OK;2450 2451 Assert(pData->Stream < RT_ELEMENTS(pDevice->aStreamSourceUm));2452 PVBOXWDDMDISP_STREAMSOURCEUM pStrSrcUm = &pDevice->aStreamSourceUm[pData->Stream];2453 if (pStrSrcUm->pvBuffer && !pUMBuffer)2454 {2455 --pDevice->cStreamSourcesUm;2456 Assert(pDevice->cStreamSourcesUm < UINT32_MAX/2);2457 }2458 else if (!pStrSrcUm->pvBuffer && pUMBuffer)2459 {2460 ++pDevice->cStreamSourcesUm;2461 Assert(pDevice->cStreamSourcesUm <= RT_ELEMENTS(pDevice->aStreamSourceUm));2462 }2463 2464 pStrSrcUm->pvBuffer = pUMBuffer;2465 pStrSrcUm->cbStride = pData->Stride;2466 2467 if (pDevice->aStreamSource[pData->Stream])2468 {2469 hr = pDevice->pDevice9If->SetStreamSource(pData->Stream, NULL, 0, 0);2470 --pDevice->cStreamSources;2471 Assert(pDevice->cStreamSources < UINT32_MAX/2);2472 pDevice->aStreamSource[pData->Stream] = NULL;2473 }2474 2475 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2476 return hr;2477 }2478 2479 static HRESULT APIENTRY vboxWddmDDevSetIndices(HANDLE hDevice, CONST D3DDDIARG_SETINDICES* pData)2480 {2481 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2482 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2483 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2484 Assert(pDevice);2485 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2486 2487 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2488 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hIndexBuffer;2489 PVBOXWDDMDISP_ALLOCATION pAlloc = NULL;2490 IDirect3DIndexBuffer9 *pIndexBuffer = NULL;2491 if (pRc)2492 {2493 VBOXVDBG_CHECK_SMSYNC(pRc);2494 Assert(pRc->cAllocations == 1);2495 pAlloc = &pRc->aAllocations[0];2496 Assert(pAlloc->pD3DIf);2497 pIndexBuffer = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;2498 }2499 HRESULT hr = pDevice9If->SetIndices(pIndexBuffer);2500 Assert(hr == S_OK);2501 if (hr == S_OK)2502 {2503 pDevice->IndiciesInfo.pIndicesAlloc = pAlloc;2504 pDevice->IndiciesInfo.uiStride = pData->Stride;2505 pDevice->IndiciesInfo.pvIndicesUm = NULL;2506 }2507 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2508 return hr;2509 }2510 2511 static HRESULT APIENTRY vboxWddmDDevSetIndicesUm(HANDLE hDevice, UINT IndexSize, CONST VOID* pUMBuffer)2512 {2513 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2514 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2515 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2516 Assert(pDevice);2517 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2518 2519 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2520 2521 HRESULT hr = S_OK;2522 if (pDevice->IndiciesInfo.pIndicesAlloc)2523 {2524 hr = pDevice9If->SetIndices(NULL);2525 }2526 2527 if (SUCCEEDED(hr))2528 {2529 pDevice->IndiciesInfo.pvIndicesUm = pUMBuffer;2530 pDevice->IndiciesInfo.uiStride = IndexSize;2531 pDevice->IndiciesInfo.pIndicesAlloc = NULL;2532 hr = S_OK;2533 }2534 else2535 {2536 WARN(("SetIndices failed hr 0x%x", hr));2537 }2538 2539 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2540 return hr;2541 }2542 2543 static HRESULT APIENTRY vboxWddmDDevDrawPrimitive(HANDLE hDevice, CONST D3DDDIARG_DRAWPRIMITIVE* pData, CONST UINT* pFlagBuffer)2544 {2545 RT_NOREF(pFlagBuffer);2546 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2547 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2548 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2549 Assert(pDevice);2550 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2551 2552 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2553 Assert(!pFlagBuffer);2554 HRESULT hr = S_OK;2555 2556 VBOXVDBG_BREAK_SHARED_DEV(pDevice);2557 2558 VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);2559 2560 if (pDevice->cStreamSourcesUm)2561 {2562 #ifdef DEBUG2563 uint32_t cStreams = 0;2564 for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)2565 {2566 if(pDevice->aStreamSourceUm[i].pvBuffer)2567 {2568 ++cStreams;2569 }2570 }2571 2572 Assert(cStreams);2573 Assert(cStreams == pDevice->cStreamSourcesUm);2574 #endif2575 if (pDevice->cStreamSourcesUm == 1)2576 {2577 for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)2578 {2579 if(pDevice->aStreamSourceUm[i].pvBuffer)2580 {2581 hr = pDevice9If->DrawPrimitiveUP(pData->PrimitiveType,2582 pData->PrimitiveCount,2583 ((uint8_t*)pDevice->aStreamSourceUm[i].pvBuffer)2584 + pData->VStart * pDevice->aStreamSourceUm[i].cbStride,2585 pDevice->aStreamSourceUm[i].cbStride);2586 Assert(hr == S_OK);2587 break;2588 }2589 }2590 }2591 else2592 {2593 /** @todo impl */2594 WARN(("multiple user stream sources (%d) not implemented!!", pDevice->cStreamSourcesUm));2595 }2596 }2597 else2598 {2599 2600 #ifdef DEBUG2601 Assert(!pDevice->cStreamSourcesUm);2602 for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)2603 {2604 Assert(!pDevice->aStreamSourceUm[i].pvBuffer);2605 }2606 2607 uint32_t cStreams = 0;2608 for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSource); ++i)2609 {2610 if (pDevice->aStreamSource[i])2611 {2612 ++cStreams;2613 Assert(!pDevice->aStreamSource[i]->LockInfo.cLocks);2614 }2615 }2616 2617 Assert(cStreams);2618 Assert(cStreams == pDevice->cStreamSources);2619 #endif2620 hr = pDevice9If->DrawPrimitive(pData->PrimitiveType,2621 pData->VStart,2622 pData->PrimitiveCount);2623 Assert(hr == S_OK);2624 2625 // vboxVDbgMpPrintF((pDevice, __FUNCTION__": DrawPrimitive\n"));2626 }2627 2628 vboxWddmDalCheckAddOnDraw(pDevice);2629 2630 VBOXVDBG_DUMP_DRAWPRIM_LEAVE(pDevice);2631 2632 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2633 return hr;2634 }2635 2636 static HRESULT APIENTRY vboxWddmDDevDrawIndexedPrimitive(HANDLE hDevice, CONST D3DDDIARG_DRAWINDEXEDPRIMITIVE* pData)2637 {2638 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2639 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2640 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2641 Assert(pDevice);2642 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2643 2644 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2645 2646 VBOXVDBG_BREAK_SHARED_DEV(pDevice);2647 2648 VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);2649 2650 2651 #ifdef DEBUG2652 uint32_t cStreams = 0;2653 for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)2654 {2655 if(pDevice->aStreamSourceUm[i].pvBuffer)2656 ++cStreams;2657 }2658 2659 Assert(cStreams == pDevice->cStreamSourcesUm);2660 2661 cStreams = 0;2662 2663 for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSource); ++i)2664 {2665 if (pDevice->aStreamSource[i])2666 {2667 ++cStreams;2668 Assert(!pDevice->aStreamSource[i]->LockInfo.cLocks);2669 }2670 }2671 2672 Assert(cStreams == pDevice->cStreamSources);2673 #endif2674 2675 HRESULT hr;2676 2677 if (pDevice->cStreamSources)2678 {2679 Assert(pDevice->IndiciesInfo.pIndicesAlloc);2680 Assert(!pDevice->IndiciesInfo.pvIndicesUm);2681 Assert(!pDevice->IndiciesInfo.pIndicesAlloc->LockInfo.cLocks);2682 Assert(!pDevice->cStreamSourcesUm);2683 2684 hr = pDevice9If->DrawIndexedPrimitive(2685 pData->PrimitiveType,2686 pData->BaseVertexIndex,2687 pData->MinIndex,2688 pData->NumVertices,2689 pData->StartIndex,2690 pData->PrimitiveCount);2691 2692 if(SUCCEEDED(hr))2693 hr = S_OK;2694 else2695 WARN(("DrawIndexedPrimitive failed hr = 0x%x", hr));2696 }2697 else2698 {2699 Assert(pDevice->cStreamSourcesUm == 1);2700 Assert(pDevice->IndiciesInfo.uiStride == 2 || pDevice->IndiciesInfo.uiStride == 4);2701 const uint8_t * pvIndexBuffer;2702 hr = S_OK;2703 2704 if (pDevice->IndiciesInfo.pIndicesAlloc)2705 {2706 Assert(!pDevice->IndiciesInfo.pvIndicesUm);2707 if (pDevice->IndiciesInfo.pIndicesAlloc->pvMem)2708 pvIndexBuffer = (const uint8_t*)pDevice->IndiciesInfo.pIndicesAlloc->pvMem;2709 else2710 {2711 WARN(("not expected!"));2712 hr = E_FAIL;2713 pvIndexBuffer = NULL;2714 }2715 }2716 else2717 {2718 pvIndexBuffer = (const uint8_t*)pDevice->IndiciesInfo.pvIndicesUm;2719 if (!pvIndexBuffer)2720 {2721 WARN(("not expected!"));2722 hr = E_FAIL;2723 }2724 }2725 2726 if (SUCCEEDED(hr))2727 {2728 for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)2729 {2730 if(pDevice->aStreamSourceUm[i].pvBuffer)2731 {2732 hr = pDevice9If->DrawIndexedPrimitiveUP(pData->PrimitiveType,2733 pData->MinIndex,2734 pData->NumVertices,2735 pData->PrimitiveCount,2736 pvIndexBuffer + pDevice->IndiciesInfo.uiStride * pData->StartIndex,2737 pDevice->IndiciesInfo.uiStride == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32,2738 pDevice->aStreamSourceUm[i].pvBuffer,2739 pDevice->aStreamSourceUm[i].cbStride);2740 if(SUCCEEDED(hr))2741 {2742 if (pDevice->IndiciesInfo.pIndicesAlloc)2743 {2744 HRESULT hr2 = pDevice9If->SetIndices((IDirect3DIndexBuffer9*)pDevice->IndiciesInfo.pIndicesAlloc->pD3DIf);2745 if(!SUCCEEDED(hr2))2746 WARN(("SetIndices failed hr = 0x%x", hr2));2747 }2748 2749 hr = S_OK;2750 }2751 else2752 WARN(("DrawIndexedPrimitiveUP failed hr = 0x%x", hr));2753 break;2754 }2755 }2756 }2757 }2758 2759 vboxWddmDalCheckAddOnDraw(pDevice);2760 2761 VBOXVDBG_DUMP_DRAWPRIM_LEAVE(pDevice);2762 2763 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2764 return hr;2765 }2766 2767 static HRESULT APIENTRY vboxWddmDDevDrawRectPatch(HANDLE hDevice, CONST D3DDDIARG_DRAWRECTPATCH* pData,2768 CONST D3DDDIRECTPATCH_INFO* pInfo, CONST FLOAT* pPatch)2769 {2770 RT_NOREF(pData, pInfo, pPatch);2771 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2772 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));2773 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2774 Assert(pDevice);2775 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2776 Assert(0);2777 vboxWddmDalCheckAddOnDraw(pDevice);2778 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2779 return E_FAIL;2780 }2781 2782 static HRESULT APIENTRY vboxWddmDDevDrawTriPatch(HANDLE hDevice, CONST D3DDDIARG_DRAWTRIPATCH* pData,2783 CONST D3DDDITRIPATCH_INFO* pInfo, CONST FLOAT* pPatch)2784 {2785 RT_NOREF(pData, pInfo, pPatch);2786 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2787 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));2788 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2789 Assert(pDevice);2790 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2791 Assert(0);2792 vboxWddmDalCheckAddOnDraw(pDevice);2793 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2794 return E_FAIL;2795 }2796 2797 static HRESULT APIENTRY vboxWddmDDevDrawPrimitive2(HANDLE hDevice, CONST D3DDDIARG_DRAWPRIMITIVE2* pData)2798 {2799 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2800 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2801 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2802 Assert(pDevice);2803 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2804 2805 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2806 HRESULT hr = S_OK;2807 #pragma message("TODO: figure initial value of hr in vboxWddmDDevDrawPrimitive2, was being used uninitalized!")2808 2809 #if 02810 int stream;2811 for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)2812 {2813 if (pDevice->aStreamSource[stream] && pDevice->aStreamSource[stream]->LockInfo.cLocks)2814 {2815 VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;2816 if (pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite))2817 {2818 IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf;2819 Assert(pLock->fFlags.RangeValid);2820 pD3D9VBuf->Lock(pLock->Range.Offset, pLock->Range.Size,2821 &pLock->LockedRect.pBits,2822 vboxDDI2D3DLockFlags(pLock->fFlags));2823 RECT r;2824 r.top = 0;2825 r.left = pLock->Range.Offset;2826 r.bottom = 1;2827 r.right = pLock->Range.Offset + pLock->Range.Size;2828 2829 VBoxD3DIfLockUnlockMemSynch(pDevice->aStreamSource[stream], &pLock->LockedRect, &r, true /*bool bToLockInfo*/);2830 2831 pD3D9VBuf->Unlock();2832 }2833 }2834 }2835 2836 hr = pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset, pData->PrimitiveCount);2837 #else2838 VBOXVDBG_BREAK_SHARED_DEV(pDevice);2839 2840 VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);2841 2842 #ifdef DEBUG2843 uint32_t cStreams = 0;2844 #endif2845 2846 int stream;2847 for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)2848 {2849 if (pDevice->aStreamSource[stream])2850 {2851 #ifdef DEBUG2852 ++cStreams;2853 #endif2854 Assert(stream==0); /*only stream 0 should be accessed here*/2855 Assert(pDevice->StreamSourceInfo[stream].uiStride!=0);2856 VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;2857 2858 if (pLock->cLocks)2859 {2860 // vboxVDbgMpPrintF((pDevice, __FUNCTION__": DrawPrimitiveUP\n"));2861 2862 Assert(pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite));2863 hr = pDevice9If->DrawPrimitiveUP(pData->PrimitiveType, pData->PrimitiveCount,2864 (void *)( (uintptr_t)pDevice->aStreamSource[stream]->pvMem2865 + pDevice->StreamSourceInfo[stream].uiOffset + pData->FirstVertexOffset),2866 pDevice->StreamSourceInfo[stream].uiStride);2867 Assert(hr == S_OK);2868 hr = pDevice9If->SetStreamSource(stream, (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf,2869 pDevice->StreamSourceInfo[stream].uiOffset,2870 pDevice->StreamSourceInfo[stream].uiStride);2871 Assert(hr == S_OK);2872 }2873 else2874 {2875 // vboxVDbgMpPrintF((pDevice, __FUNCTION__": DrawPrimitive\n"));2876 2877 hr = pDevice9If->DrawPrimitive(pData->PrimitiveType,2878 pData->FirstVertexOffset / pDevice->StreamSourceInfo[stream].uiStride,2879 pData->PrimitiveCount);2880 Assert(hr == S_OK);2881 }2882 }2883 }2884 2885 #ifdef DEBUG2886 Assert(cStreams);2887 Assert(cStreams == pDevice->cStreamSources);2888 #endif2889 #endif2890 2891 vboxWddmDalCheckAddOnDraw(pDevice);2892 2893 VBOXVDBG_DUMP_DRAWPRIM_LEAVE(pDevice);2894 2895 Assert(hr == S_OK);2896 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));2897 return hr;2898 }2899 2900 static UINT vboxWddmVertexCountFromPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount)2901 {2902 Assert(PrimitiveCount > 0); /* Callers ensure this. */2903 2904 UINT cVertices;2905 switch (PrimitiveType)2906 {2907 case D3DPT_POINTLIST:2908 cVertices = PrimitiveCount; /* Vertex per point. */2909 break;2910 2911 case D3DPT_LINELIST:2912 cVertices = PrimitiveCount * 2; /* Two vertices for each line. */2913 break;2914 2915 case D3DPT_LINESTRIP:2916 cVertices = PrimitiveCount + 1; /* Two vertices for the first line and one vertex for each subsequent. */2917 break;2918 2919 case D3DPT_TRIANGLELIST:2920 cVertices = PrimitiveCount * 3; /* Three vertices for each triangle. */2921 break;2922 2923 case D3DPT_TRIANGLESTRIP:2924 case D3DPT_TRIANGLEFAN:2925 cVertices = PrimitiveCount + 2; /* Three vertices for the first triangle and one vertex for each subsequent. */2926 break;2927 2928 default:2929 cVertices = 0; /* No such primitive in d3d9types.h. */2930 break;2931 }2932 2933 return cVertices;2934 }2935 2936 static HRESULT APIENTRY vboxWddmDDevDrawIndexedPrimitive2(HANDLE hDevice, CONST D3DDDIARG_DRAWINDEXEDPRIMITIVE2* pData,2937 UINT dwIndicesSize, CONST VOID* pIndexBuffer, CONST UINT* pFlagBuffer)2938 {2939 RT_NOREF(pFlagBuffer);2940 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);2941 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));2942 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;2943 Assert(pDevice);2944 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);2945 HRESULT hr = S_OK;2946 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);2947 const uint8_t *pvVertexBuffer = NULL;2948 DWORD cbVertexStride = 0;2949 2950 LOGF(("\n PrimitiveType %d, BaseVertexOffset %d, MinIndex %d, NumVertices %d, StartIndexOffset %d, PrimitiveCount %d,\n"2951 " dwIndicesSize %d, pIndexBuffer %p, pFlagBuffer %p\n",2952 pData->PrimitiveType,2953 pData->BaseVertexOffset,2954 pData->MinIndex,2955 pData->NumVertices,2956 pData->StartIndexOffset,2957 pData->PrimitiveCount,2958 dwIndicesSize,2959 pIndexBuffer,2960 pFlagBuffer));2961 2962 if (dwIndicesSize != 2 && dwIndicesSize != 4)2963 {2964 WARN(("unsupported dwIndicesSize %d", dwIndicesSize));2965 return E_INVALIDARG;2966 }2967 2968 if (pData->PrimitiveCount == 0)2969 {2970 /* Nothing to draw. */2971 return S_OK;2972 }2973 2974 /* Fetch the appropriate stream source:2975 * "Stream zero contains transform indices and is the only stream that should be accessed."2976 */2977 if (pDevice->aStreamSourceUm[0].pvBuffer)2978 {2979 Assert(pDevice->aStreamSourceUm[0].cbStride);2980 2981 pvVertexBuffer = (const uint8_t *)pDevice->aStreamSourceUm[0].pvBuffer;2982 cbVertexStride = pDevice->aStreamSourceUm[0].cbStride;2983 LOGF(("aStreamSourceUm %p, stride %d\n",2984 pvVertexBuffer, cbVertexStride));2985 }2986 else if (pDevice->aStreamSource[0])2987 {2988 PVBOXWDDMDISP_ALLOCATION pAlloc = pDevice->aStreamSource[0];2989 if (pAlloc->pvMem)2990 {2991 Assert(pDevice->StreamSourceInfo[0].uiStride);2992 pvVertexBuffer = ((const uint8_t *)pAlloc->pvMem) + pDevice->StreamSourceInfo[0].uiOffset;2993 cbVertexStride = pDevice->StreamSourceInfo[0].uiStride;2994 LOGF(("aStreamSource %p, cbSize %d, stride %d, uiOffset %d (elements %d)\n",2995 pvVertexBuffer, pAlloc->SurfDesc.cbSize, cbVertexStride, pDevice->StreamSourceInfo[0].uiOffset,2996 cbVertexStride? pAlloc->SurfDesc.cbSize / cbVertexStride: 0));2997 }2998 else2999 {3000 WARN(("unsupported!!"));3001 hr = E_FAIL;3002 }3003 }3004 else3005 {3006 WARN(("not expected!"));3007 hr = E_FAIL;3008 }3009 3010 if (SUCCEEDED(hr))3011 {3012 /* Convert input data to appropriate DrawIndexedPrimitiveUP parameters.3013 * In particular prepare zero based vertex array becuase wine does not3014 * handle MinVertexIndex correctly.3015 */3016 3017 /* Take the offset, which corresponds to the index == 0, into account. */3018 const uint8_t *pu8VertexStart = pvVertexBuffer + pData->BaseVertexOffset;3019 3020 /* Where the pData->MinIndex starts. */3021 pu8VertexStart += pData->MinIndex * cbVertexStride;3022 3023 /* Convert indexes to zero based relative to pData->MinIndex. */3024 const uint8_t *pu8IndicesStartSrc = (uint8_t *)pIndexBuffer + pData->StartIndexOffset;3025 UINT cIndices = vboxWddmVertexCountFromPrimitive(pData->PrimitiveType, pData->PrimitiveCount);3026 3027 /* Allocate memory for converted indices. */3028 uint8_t *pu8IndicesStartConv = (uint8_t *)RTMemAlloc(cIndices * dwIndicesSize);3029 if (pu8IndicesStartConv != NULL)3030 {3031 UINT i;3032 if (dwIndicesSize == 2)3033 {3034 uint16_t *pu16Src = (uint16_t *)pu8IndicesStartSrc;3035 uint16_t *pu16Dst = (uint16_t *)pu8IndicesStartConv;3036 for (i = 0; i < cIndices; ++i, ++pu16Dst, ++pu16Src)3037 {3038 *pu16Dst = *pu16Src - pData->MinIndex;3039 }3040 }3041 else3042 {3043 uint32_t *pu32Src = (uint32_t *)pu8IndicesStartSrc;3044 uint32_t *pu32Dst = (uint32_t *)pu8IndicesStartConv;3045 for (i = 0; i < cIndices; ++i, ++pu32Dst, ++pu32Src)3046 {3047 *pu32Dst = *pu32Src - pData->MinIndex;3048 }3049 }3050 3051 hr = pDevice9If->DrawIndexedPrimitiveUP(pData->PrimitiveType,3052 0,3053 pData->NumVertices,3054 pData->PrimitiveCount,3055 pu8IndicesStartConv,3056 dwIndicesSize == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32,3057 pu8VertexStart,3058 cbVertexStride);3059 3060 if (SUCCEEDED(hr))3061 hr = S_OK;3062 else3063 WARN(("DrawIndexedPrimitiveUP failed hr = 0x%x", hr));3064 3065 RTMemFree(pu8IndicesStartConv);3066 3067 /* Following any IDirect3DDevice9::DrawIndexedPrimitiveUP call, the stream 0 settings,3068 * referenced by IDirect3DDevice9::GetStreamSource, are set to NULL. Also, the index3069 * buffer setting for IDirect3DDevice9::SetIndices is set to NULL.3070 */3071 if (pDevice->aStreamSource[0])3072 {3073 HRESULT tmpHr = pDevice9If->SetStreamSource(0, (IDirect3DVertexBuffer9*)pDevice->aStreamSource[0]->pD3DIf,3074 pDevice->StreamSourceInfo[0].uiOffset,3075 pDevice->StreamSourceInfo[0].uiStride);3076 if(!SUCCEEDED(tmpHr))3077 WARN(("SetStreamSource failed hr = 0x%x", tmpHr));3078 }3079 3080 if (pDevice->IndiciesInfo.pIndicesAlloc)3081 {3082 HRESULT tmpHr = pDevice9If->SetIndices((IDirect3DIndexBuffer9*)pDevice->IndiciesInfo.pIndicesAlloc->pD3DIf);3083 if(!SUCCEEDED(tmpHr))3084 WARN(("SetIndices failed hr = 0x%x", tmpHr));3085 }3086 }3087 else3088 {3089 hr = E_OUTOFMEMORY;3090 }3091 }3092 3093 vboxWddmDalCheckAddOnDraw(pDevice);3094 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3095 return hr;3096 }3097 3098 AssertCompile(sizeof (D3DDDIBOX) == sizeof (VBOXBOX3D));3099 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Left) == RT_SIZEOFMEMB(VBOXBOX3D, Left));3100 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Top) == RT_SIZEOFMEMB(VBOXBOX3D, Top));3101 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Right) == RT_SIZEOFMEMB(VBOXBOX3D, Right));3102 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Bottom) == RT_SIZEOFMEMB(VBOXBOX3D, Bottom));3103 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Front) == RT_SIZEOFMEMB(VBOXBOX3D, Front));3104 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Back) == RT_SIZEOFMEMB(VBOXBOX3D, Back));3105 3106 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Left) == RT_OFFSETOF(VBOXBOX3D, Left));3107 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Top) == RT_OFFSETOF(VBOXBOX3D, Top));3108 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Right) == RT_OFFSETOF(VBOXBOX3D, Right));3109 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Bottom) == RT_OFFSETOF(VBOXBOX3D, Bottom));3110 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Front) == RT_OFFSETOF(VBOXBOX3D, Front));3111 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Back) == RT_OFFSETOF(VBOXBOX3D, Back));3112 3113 static HRESULT APIENTRY vboxWddmDDevVolBlt(HANDLE hDevice, CONST D3DDDIARG_VOLUMEBLT* pData)3114 {3115 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3116 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3117 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3118 Assert(pDevice);3119 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3120 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);3121 PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;3122 PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;3123 /* requirements for D3DDevice9::UpdateTexture */3124 Assert(pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);3125 Assert(pSrcRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);3126 IDirect3DVolumeTexture9 * pSrcTex = (IDirect3DVolumeTexture9*)pSrcRc->aAllocations[0].pD3DIf;3127 IDirect3DVolumeTexture9 * pDstTex = (IDirect3DVolumeTexture9*)pDstRc->aAllocations[0].pD3DIf;3128 VBOXPOINT3D Point;3129 Point.x = pData->DstX;3130 Point.y = pData->DstY;3131 Point.z = pData->DstZ;3132 3133 HRESULT hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9VolTexBlt((IDirect3DDevice9Ex*)pDevice9If, pSrcTex, pDstTex,3134 (VBOXBOX3D*)&pData->SrcBox, &Point);3135 if (FAILED(hr))3136 WARN(("pfnVBoxWineExD3DDev9VolTexBlt failed hr 0x%x", hr));3137 else3138 hr = S_OK;3139 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3140 return hr;;3141 }3142 3143 static HRESULT APIENTRY vboxWddmDDevBufBlt(HANDLE hDevice, CONST D3DDDIARG_BUFFERBLT* pData)3144 {3145 RT_NOREF(pData);3146 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3147 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3148 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3149 Assert(pDevice); NOREF(pDevice);3150 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3151 Assert(0);3152 /// @todo vboxWddmDalCheckAdd(pDevice);3153 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3154 return E_FAIL;3155 }3156 3157 static HRESULT APIENTRY vboxWddmDDevTexBlt(HANDLE hDevice, CONST D3DDDIARG_TEXBLT* pData)3158 {3159 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3160 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3161 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3162 Assert(pDevice);3163 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3164 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);3165 PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;3166 PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;3167 /* requirements for D3DDevice9::UpdateTexture */3168 Assert(pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE3169 || pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE3170 || pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);3171 Assert(pSrcRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE3172 || pSrcRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE3173 || pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);3174 Assert(pSrcRc->aAllocations[0].enmD3DIfType == pDstRc->aAllocations[0].enmD3DIfType);3175 Assert(pSrcRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);3176 Assert(pDstRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM);3177 HRESULT hr = S_OK;3178 VBOXVDBG_CHECK_SMSYNC(pDstRc);3179 VBOXVDBG_CHECK_SMSYNC(pSrcRc);3180 3181 if ( pSrcRc->aAllocations[0].SurfDesc.d3dWidth == pDstRc->aAllocations[0].SurfDesc.d3dWidth3182 && pSrcRc->aAllocations[0].SurfDesc.height == pDstRc->aAllocations[0].SurfDesc.height3183 && pSrcRc->RcDesc.enmFormat == pDstRc->RcDesc.enmFormat3184 && pData->DstPoint.x == 03185 && pData->DstPoint.y == 03186 && pData->SrcRect.left == 03187 && pData->SrcRect.top == 03188 && pData->SrcRect.right - pData->SrcRect.left == (LONG)pSrcRc->aAllocations[0].SurfDesc.width3189 && pData->SrcRect.bottom - pData->SrcRect.top == (LONG)pSrcRc->aAllocations[0].SurfDesc.height)3190 {3191 IDirect3DBaseTexture9 *pD3DIfSrcTex = (IDirect3DBaseTexture9*)pSrcRc->aAllocations[0].pD3DIf;3192 IDirect3DBaseTexture9 *pD3DIfDstTex = (IDirect3DBaseTexture9*)pDstRc->aAllocations[0].pD3DIf;3193 Assert(pD3DIfSrcTex);3194 Assert(pD3DIfDstTex);3195 VBOXVDBG_CHECK_TEXBLT(3196 hr = pDevice9If->UpdateTexture(pD3DIfSrcTex, pD3DIfDstTex); Assert(hr == S_OK),3197 pSrcRc,3198 &pData->SrcRect,3199 pDstRc,3200 &pData->DstPoint);3201 }3202 else3203 {3204 Assert(pDstRc->aAllocations[0].enmD3DIfType != VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);3205 Assert(pSrcRc->aAllocations[0].enmD3DIfType != VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);3206 3207 IDirect3DSurface9 *pSrcSurfIf = NULL;3208 IDirect3DSurface9 *pDstSurfIf = NULL;3209 hr = VBoxD3DIfSurfGet(pDstRc, 0, &pDstSurfIf);3210 Assert(hr == S_OK);3211 if (hr == S_OK)3212 {3213 hr = VBoxD3DIfSurfGet(pSrcRc, 0, &pSrcSurfIf);3214 Assert(hr == S_OK);3215 if (hr == S_OK)3216 {3217 RECT DstRect;3218 vboxWddmRectMoved(&DstRect, &pData->SrcRect, pData->DstPoint.x, pData->DstPoint.y);3219 #ifdef DEBUG3220 RECT tstRect = {0,0, pDstRc->aAllocations[0].SurfDesc.width, pDstRc->aAllocations[0].SurfDesc.height};3221 Assert(vboxWddmRectIsCoveres(&tstRect, &DstRect));3222 #endif3223 VBOXVDBG_CHECK_TEXBLT(hr = pDevice9If->StretchRect(pSrcSurfIf, &pData->SrcRect, pDstSurfIf, &DstRect, D3DTEXF_NONE);3224 Assert(hr == S_OK),3225 pSrcRc, &pData->SrcRect,3226 pDstRc, &pData->DstPoint);3227 pSrcSurfIf->Release();3228 }3229 pDstSurfIf->Release();3230 }3231 }3232 3233 vboxWddmDalCheckAddRc(pDevice, pDstRc, TRUE);3234 vboxWddmDalCheckAddRc(pDevice, pSrcRc, FALSE);3235 3236 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));3237 return hr;3238 }3239 3240 static HRESULT APIENTRY vboxWddmDDevStateSet(HANDLE hDevice, D3DDDIARG_STATESET* pData)3241 {3242 RT_NOREF(pData);3243 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3244 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3245 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3246 Assert(pDevice); NOREF(pDevice);3247 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3248 Assert(0);3249 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3250 return E_FAIL;3251 }3252 static HRESULT APIENTRY vboxWddmDDevSetPriority(HANDLE hDevice, CONST D3DDDIARG_SETPRIORITY* pData)3253 {3254 RT_NOREF(pData);3255 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3256 // PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3257 // Assert(pDevice);3258 // VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3259 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3260 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3261 return S_OK;3262 }3263 AssertCompile(sizeof (RECT) == sizeof (D3DRECT));3264 AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(D3DRECT, x1));3265 AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(D3DRECT, x2));3266 AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(D3DRECT, y1));3267 AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(D3DRECT, y2));3268 AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(D3DRECT, x1));3269 AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(D3DRECT, x2));3270 AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(D3DRECT, y1));3271 AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(D3DRECT, y2));3272 3273 static HRESULT APIENTRY vboxWddmDDevClear(HANDLE hDevice, CONST D3DDDIARG_CLEAR* pData, UINT NumRect, CONST RECT* pRect)3274 {3275 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3276 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3277 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3278 Assert(pDevice);3279 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3280 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);3281 HRESULT hr = pDevice9If->Clear(NumRect, (D3DRECT*)pRect /* see AssertCompile above */,3282 pData->Flags,3283 pData->FillColor,3284 pData->FillDepth,3285 pData->FillStencil);3286 if (SUCCEEDED(hr))3287 {3288 if (pData->Flags & D3DCLEAR_TARGET)3289 vboxWddmDalCheckAddRTs(pDevice);3290 if ((pData->Flags & D3DCLEAR_STENCIL)3291 || (pData->Flags & D3DCLEAR_ZBUFFER))3292 vboxWddmDalCheckAddDepthStencil(pDevice);3293 }3294 else3295 WARN(("Clear failed %#x", hr));3296 3297 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));3298 return hr;3299 }3300 static HRESULT APIENTRY vboxWddmDDevUpdatePalette(HANDLE hDevice, CONST D3DDDIARG_UPDATEPALETTE* pData,3301 CONST PALETTEENTRY* pPaletteData)3302 {3303 RT_NOREF(pData, pPaletteData);3304 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3305 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3306 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3307 Assert(pDevice); NOREF(pDevice);3308 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3309 Assert(0);3310 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3311 return E_FAIL;3312 }3313 3314 static HRESULT APIENTRY vboxWddmDDevSetPalette(HANDLE hDevice, CONST D3DDDIARG_SETPALETTE* pData)3315 {3316 RT_NOREF(pData);3317 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3318 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3319 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3320 Assert(pDevice); NOREF(pDevice);3321 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3322 Assert(0);3323 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3324 return E_FAIL;3325 }3326 3327 static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConst(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONST* pData ,3328 CONST VOID* pRegisters)3329 {3330 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3331 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3332 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3333 Assert(pDevice);3334 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3335 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);3336 HRESULT hr = pDevice9If->SetVertexShaderConstantF(3337 pData->Register,3338 (CONST float*)pRegisters,3339 pData->Count);3340 Assert(hr == S_OK);3341 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));3342 return hr;3343 }3344 static HRESULT APIENTRY vboxWddmDDevMultiplyTransform(HANDLE hDevice, CONST D3DDDIARG_MULTIPLYTRANSFORM* pData)3345 {3346 RT_NOREF(pData);3347 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3348 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3349 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3350 Assert(pDevice); NOREF(pDevice);3351 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3352 Assert(0);3353 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3354 return E_FAIL;3355 }3356 static HRESULT APIENTRY vboxWddmDDevSetTransform(HANDLE hDevice, CONST D3DDDIARG_SETTRANSFORM* pData)3357 {3358 RT_NOREF(pData);3359 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3360 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3361 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3362 Assert(pDevice); NOREF(pDevice);3363 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3364 Assert(0);3365 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3366 return E_FAIL;3367 }3368 static HRESULT APIENTRY vboxWddmDDevSetViewport(HANDLE hDevice, CONST D3DDDIARG_VIEWPORTINFO* pData)3369 {3370 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3371 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3372 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3373 Assert(pDevice);3374 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3375 3376 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);3377 pDevice->ViewPort.X = pData->X;3378 pDevice->ViewPort.Y = pData->Y;3379 pDevice->ViewPort.Width = pData->Width;3380 pDevice->ViewPort.Height = pData->Height;3381 HRESULT hr = pDevice9If->SetViewport(&pDevice->ViewPort);3382 Assert(hr == S_OK);3383 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));3384 return hr;3385 }3386 static HRESULT APIENTRY vboxWddmDDevSetZRange(HANDLE hDevice, CONST D3DDDIARG_ZRANGE* pData)3387 {3388 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3389 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3390 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3391 Assert(pDevice);3392 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3393 3394 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);3395 pDevice->ViewPort.MinZ = pData->MinZ;3396 pDevice->ViewPort.MaxZ = pData->MaxZ;3397 HRESULT hr = pDevice9If->SetViewport(&pDevice->ViewPort);3398 Assert(hr == S_OK);3399 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));3400 return hr;3401 }3402 static HRESULT APIENTRY vboxWddmDDevSetMaterial(HANDLE hDevice, CONST D3DDDIARG_SETMATERIAL* pData)3403 {3404 RT_NOREF(pData);3405 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3406 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3407 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3408 Assert(pDevice); NOREF(pDevice);3409 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3410 Assert(0);3411 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3412 return E_FAIL;3413 }3414 static HRESULT APIENTRY vboxWddmDDevSetLight(HANDLE hDevice, CONST D3DDDIARG_SETLIGHT* pData, CONST D3DDDI_LIGHT* pLightProperties)3415 {3416 RT_NOREF(pData, pLightProperties);3417 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3418 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3419 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3420 Assert(pDevice); NOREF(pDevice);3421 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3422 Assert(0);3423 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3424 return E_FAIL;3425 }3426 static HRESULT APIENTRY vboxWddmDDevCreateLight(HANDLE hDevice, CONST D3DDDIARG_CREATELIGHT* pData)3427 {3428 RT_NOREF(pData);3429 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3430 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3431 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3432 Assert(pDevice); NOREF(pDevice);3433 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3434 Assert(0);3435 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3436 return E_FAIL;3437 }3438 static HRESULT APIENTRY vboxWddmDDevDestroyLight(HANDLE hDevice, CONST D3DDDIARG_DESTROYLIGHT* pData)3439 {3440 RT_NOREF(pData);3441 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3442 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));3443 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3444 Assert(pDevice); NOREF(pDevice);3445 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3446 Assert(0);3447 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3448 return E_FAIL;3449 }3450 static HRESULT APIENTRY vboxWddmDDevSetClipPlane(HANDLE hDevice, CONST D3DDDIARG_SETCLIPPLANE* pData)3451 {3452 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3453 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3454 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3455 Assert(pDevice);3456 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3457 3458 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);3459 HRESULT hr = pDevice9If->SetClipPlane(pData->Index, pData->Plane);3460 Assert(hr == S_OK);3461 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));3462 return hr;3463 }3464 3465 static HRESULT APIENTRY vboxWddmDDevGetInfo(HANDLE hDevice, UINT DevInfoID, VOID* pDevInfoStruct, UINT DevInfoSize)3466 {3467 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3468 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3469 // PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3470 // Assert(pDevice);3471 // VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3472 HRESULT hr = S_OK;3473 switch (DevInfoID)3474 {3475 case D3DDDIDEVINFOID_VCACHE:3476 {3477 Assert(DevInfoSize == sizeof (D3DDDIDEVINFO_VCACHE));3478 if (DevInfoSize == sizeof (D3DDDIDEVINFO_VCACHE))3479 {3480 D3DDDIDEVINFO_VCACHE *pVCache = (D3DDDIDEVINFO_VCACHE*)pDevInfoStruct;3481 pVCache->Pattern = MAKEFOURCC('C', 'A', 'C', 'H');3482 pVCache->OptMethod = 0 /* D3DXMESHOPT_STRIPREORDER */;3483 pVCache->CacheSize = 0;3484 pVCache->MagicNumber = 0;3485 }3486 else3487 hr = E_INVALIDARG;3488 break;3489 }3490 default:3491 Assert(0);3492 hr = E_NOTIMPL;3493 }3494 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));3495 return hr;3496 }3497 3498 AssertCompile(sizeof (D3DDDIBOX) == sizeof (D3DBOX));3499 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Left) == RT_SIZEOFMEMB(D3DBOX, Left));3500 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Top) == RT_SIZEOFMEMB(D3DBOX, Top));3501 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Right) == RT_SIZEOFMEMB(D3DBOX, Right));3502 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Bottom) == RT_SIZEOFMEMB(D3DBOX, Bottom));3503 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Front) == RT_SIZEOFMEMB(D3DBOX, Front));3504 AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Back) == RT_SIZEOFMEMB(D3DBOX, Back));3505 3506 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Left) == RT_OFFSETOF(D3DBOX, Left));3507 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Top) == RT_OFFSETOF(D3DBOX, Top));3508 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Right) == RT_OFFSETOF(D3DBOX, Right));3509 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Bottom) == RT_OFFSETOF(D3DBOX, Bottom));3510 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Front) == RT_OFFSETOF(D3DBOX, Front));3511 AssertCompile(RT_OFFSETOF(D3DDDIBOX, Back) == RT_OFFSETOF(D3DBOX, Back));3512 3513 static HRESULT APIENTRY vboxWddmDDevLock(HANDLE hDevice, D3DDDIARG_LOCK* pData)3514 {3515 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);3516 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));3517 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;3518 Assert(pDevice);3519 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);3520 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;3521 if (pData->SubResourceIndex >= pRc->cAllocations)3522 return E_INVALIDARG;3523 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];3524 Assert(pData->SubResourceIndex < pRc->cAllocations);3525 3526 HRESULT hr = S_OK;3527 3528 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))3529 {3530 // Assert(pRc != pScreen->pRenderTargetRc || pScreen->iRenderTargetFrontBuf != pData->SubResourceIndex);3531 #ifdef VBOXWDDMDISP_DAL_CHECK_LOCK3532 hr = vboxWddmDalCheckLock(pDevice, pAlloc, pData->Flags);3533 if (!SUCCEEDED(hr))3534 {3535 WARN(("vboxWddmDalCheckLock failed %#x", hr));3536 return hr;3537 }3538 #endif3539 3540 if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE3541 || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE3542 || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE)3543 {3544 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];3545 Assert(pData->SubResourceIndex < pRc->cAllocations);3546 IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;3547 IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pTexAlloc->pD3DIf;3548 IDirect3DSurface9 *pD3DIfSurface = (IDirect3DSurface9*)pTexAlloc->pD3DIf;3549 Assert(pTexAlloc->pD3DIf);3550 RECT *pRect = NULL;3551 BOOL fNeedLock = TRUE;3552 Assert(!pData->Flags.RangeValid);3553 Assert(!pData->Flags.BoxValid);3554 if (pData->Flags.AreaValid)3555 {3556 pRect = &pData->Area;3557 }3558 3559 /* else - we lock the entire texture, pRect == NULL */3560 3561 if (pAlloc->LockInfo.cLocks)3562 {3563 Assert(pAlloc->LockInfo.fFlags.AreaValid == pData->Flags.AreaValid);3564 if (pAlloc->LockInfo.fFlags.AreaValid && pData->Flags.AreaValid)3565 {3566 Assert(pAlloc->LockInfo.Area.left == pData->Area.left);3567 Assert(pAlloc->LockInfo.Area.top == pData->Area.top);3568 Assert(pAlloc->LockInfo.Area.right == pData->Area.right);3569 Assert(pAlloc->LockInfo.Area.bottom == pData->Area.bottom);3570 }3571 Assert(pAlloc->LockInfo.LockedRect.pBits);3572 Assert((pAlloc->LockInfo.fFlags.Value & ~1) == (pData->Flags.Value & ~1)); /* <- 1 is "ReadOnly" flag */3573 3574 if (pAlloc->LockInfo.fFlags.ReadOnly && !pData->Flags.ReadOnly)3575 {3576 switch (pTexAlloc->enmD3DIfType)3577 {3578 case VBOXDISP_D3DIFTYPE_TEXTURE:3579 hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);3580 break;3581 case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:3582 hr = pD3DIfCubeTex->UnlockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),3583 VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex));3584 break;3585 case VBOXDISP_D3DIFTYPE_SURFACE:3586 hr = pD3DIfSurface->UnlockRect();3587 break;3588 default:3589 Assert(0);3590 break;3591 }3592 Assert(hr == S_OK);3593 }3594 else3595 {3596 fNeedLock = FALSE;3597 }3598 }3599 3600 if (fNeedLock && SUCCEEDED(hr))3601 {3602 VBOXVDBG_CHECK_SMSYNC(pRc);3603 3604 pAlloc->LockInfo.fFlags = pData->Flags;3605 if (pRect)3606 {3607 pAlloc->LockInfo.Area = *pRect;3608 Assert(pAlloc->LockInfo.fFlags.AreaValid == 1);3609 }3610 else3611 {3612 Assert(pAlloc->LockInfo.fFlags.AreaValid == 0);3613 }3614 3615 switch (pTexAlloc->enmD3DIfType)3616 {3617 case VBOXDISP_D3DIFTYPE_TEXTURE:3618 hr = pD3DIfTex->LockRect(pData->SubResourceIndex,3619 &pAlloc->LockInfo.LockedRect,3620 pRect,3621 vboxDDI2D3DLockFlags(pData->Flags));3622 break;3623 case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:3624 hr = pD3DIfCubeTex->LockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),3625 VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex),3626 &pAlloc->LockInfo.LockedRect,3627 pRect,3628 vboxDDI2D3DLockFlags(pData->Flags));3629 break;3630 case VBOXDISP_D3DIFTYPE_SURFACE:3631 hr = pD3DIfSurface->LockRect(&pAlloc->LockInfo.LockedRect,3632 pRect,3633 vboxDDI2D3DLockFlags(pData->Flags));3634 break;3635 default:3636 Assert(0);3637 break;3638 }3639 3640 if (FAILED(hr))3641 {3642 WARN(("LockRect failed, hr", hr));3643 }3644 }3645 3646 if (SUCCEEDED(hr))3647 {3648 ++pAlloc->LockInfo.cLocks;3649 3650 if (!pData->Flags.NotifyOnly)3651 {3652 pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;3653 pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;3654 pData->SlicePitch = 0;3655 Assert(pAlloc->SurfDesc.slicePitch == 0);3656 Assert(!pAlloc->pvMem);3657 }3658 else3659 {3660 Assert(pAlloc->pvMem);3661 Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);3662 }3663 3664 VBOXVDBG_DUMP_LOCK_ST(pData);3665 3666 hr = S_OK;3667 }3668 }3669 else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE)3670 {3671 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];3672 Assert(pData->SubResourceIndex < pRc->cAllocations);3673 IDirect3DVolumeTexture9 *pD3DIfTex = (IDirect3DVolumeTexture9*)pTexAlloc->pD3DIf;3674 Assert(pTexAlloc->pD3DIf);3675 D3DDDIBOX *pBox = NULL;3676 BOOL fNeedLock = TRUE;3677 Assert(!pData->Flags.AreaValid);3678 Assert(!pData->Flags.BoxValid);3679 if (pData->Flags.BoxValid)3680 {3681 pBox = &pData->Box;3682 }3683 3684 /* else - we lock the entire texture, pBox == NULL */3685 3686 if (pAlloc->LockInfo.cLocks)3687 {3688 Assert(pAlloc->LockInfo.fFlags.BoxValid == pData->Flags.BoxValid);3689 if (pAlloc->LockInfo.fFlags.BoxValid && pData->Flags.BoxValid)3690 {3691 Assert(pAlloc->LockInfo.Box.Left == pData->Box.Left);3692 Assert(pAlloc->LockInfo.Box.Top == pData->Box.Top);3693 Assert(pAlloc->LockInfo.Box.Right == pData->Box.Right);3694 Assert(pAlloc->LockInfo.Box.Bottom == pData->Box.Bottom);3695 Assert(pAlloc->LockInfo.Box.Front == pData->Box.Front);3696 Assert(pAlloc->LockInfo.Box.Back == pData->Box.Back);3697 }3698 Assert(pAlloc->LockInfo.LockedBox.pBits);3699 Assert((pAlloc->LockInfo.fFlags.Value & ~1) == (pData->Flags.Value & ~1)); /* <- 1 is "ReadOnly" flag */3700 3701 if (pAlloc->LockInfo.fFlags.ReadOnly && !pData->Flags.ReadOnly)3702 {3703 hr = pD3DIfTex->UnlockBox(pData->SubResourceIndex);3704 Assert(hr == S_OK);3705 }3706 else3707 {3708 fNeedLock = FALSE;3709 }3710 }3711 3712 if (fNeedLock && SUCCEEDED(hr))3713 {3714 VBOXVDBG_CHECK_SMSYNC(pRc);3715 3716 pAlloc->LockInfo.fFlags = pData->Flags;3717 if (pBox)3718 {3719 pAlloc->LockInfo.Box = *pBox;3720 Assert(pAlloc->LockInfo.fFlags.BoxValid == 1);3721 }3722 else3723 {3724 Assert(pAlloc->LockInfo.fFlags.BoxValid == 0);3725 }3726 3727 hr = pD3DIfTex->LockBox(pData->SubResourceIndex,3728 &pAlloc->LockInfo.LockedBox,3729 (D3DBOX*)pBox,3730 vboxDDI2D3DLockFlags(pData->Flags));3731 if (FAILED(hr))3732 {3733 WARN(("LockRect failed, hr", hr));3734 }3735 }3736 3737 if (SUCCEEDED(hr))3738 {3739 ++pAlloc->LockInfo.cLocks;3740 3741 if (!pData->Flags.NotifyOnly)3742 {3743 pData->pSurfData = pAlloc->LockInfo.LockedBox.pBits;3744 pData->Pitch = pAlloc->LockInfo.LockedBox.RowPitch;3745 pData->SlicePitch = pAlloc->LockInfo.LockedBox.SlicePitch;3746 Assert(!pAlloc->pvMem);3747 }3748 else3749 {3750 Assert(pAlloc->pvMem);3751 Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);3752 }3753 3754 VBOXVDBG_DUMP_LOCK_ST(pData);3755 3756 hr = S_OK;3757 }3758 }3759 else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VERTEXBUFFER)3760 {3761 Assert(pData->SubResourceIndex < pRc->cAllocations);3762 IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;3763 BOOL bLocked = false;3764 Assert(pD3D9VBuf);3765 Assert(!pData->Flags.AreaValid);3766 Assert(!pData->Flags.BoxValid);3767 D3DDDIRANGE *pRange = NULL;3768 if (pData->Flags.RangeValid)3769 {3770 pRange = &pData->Range;3771 }3772 3773 /* else - we lock the entire vertex buffer, pRect == NULL */3774 3775 if (!pAlloc->LockInfo.cLocks)3776 {3777 VBOXVDBG_CHECK_SMSYNC(pRc);3778 if (!pData->Flags.MightDrawFromLocked || (!pData->Flags.Discard && !pData->Flags.NoOverwrite))3779 {3780 hr = pD3D9VBuf->Lock(pRange ? pRange->Offset : 0,3781 pRange ? pRange->Size : 0,3782 &pAlloc->LockInfo.LockedRect.pBits,3783 vboxDDI2D3DLockFlags(pData->Flags));3784 bLocked = true;3785 }3786 3787 Assert(hr == S_OK);3788 if (hr == S_OK)3789 {3790 Assert(pAlloc->SurfDesc.pitch == pAlloc->SurfDesc.width);3791 pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.pitch;3792 // Assert(pAlloc->LockInfo.fFlags.Value == 0);3793 pAlloc->LockInfo.fFlags = pData->Flags;3794 if (pRange)3795 {3796 pAlloc->LockInfo.Range = *pRange;3797 Assert(pAlloc->LockInfo.fFlags.RangeValid == 1);3798 // pAlloc->LockInfo.fFlags.RangeValid = 1;3799 }3800 else3801 {3802 Assert(pAlloc->LockInfo.fFlags.RangeValid == 0);3803 // pAlloc->LockInfo.fFlags.RangeValid = 0;3804 }3805 }3806 }3807 else3808 {3809 Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);3810 if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)3811 {3812 Assert(pAlloc->LockInfo.Range.Offset == pData->Range.Offset);3813 Assert(pAlloc->LockInfo.Range.Size == pData->Range.Size);3814 }3815 Assert(pAlloc->LockInfo.LockedRect.pBits);3816 }3817 3818 if (hr == S_OK)3819 {3820 ++pAlloc->LockInfo.cLocks;3821 3822 if (!pData->Flags.NotifyOnly)3823 {3824 pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;3825 pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;3826 pData->SlicePitch = 0;3827 Assert(pAlloc->SurfDesc.slicePitch == 0);3828 Assert(!pAlloc->pvMem);3829 }3830 else3831 {3832 Assert(pAlloc->pvMem);3833 Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);3834 if (bLocked && !pData->Flags.Discard)3835 {3836 RECT r, *pr;3837 if (pRange)3838 {3839 r.top = 0;3840 r.left = pRange->Offset;3841 r.bottom = 1;3842 r.right = pRange->Offset + pRange->Size;3843 pr = &r;3844 }3845 else3846 pr = NULL;3847 VBoxD3DIfLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, false /*bool bToLockInfo*/);3848 }3849 }3850 }3851 }3852 else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_INDEXBUFFER)3853 {3854 Assert(pData->SubResourceIndex < pRc->cAllocations);3855 IDirect3DIndexBuffer9 *pD3D9IBuf = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;3856 BOOL bLocked = false;3857 Assert(pD3D9IBuf);3858 Assert(!pData->Flags.AreaValid);3859 Assert(!pData->Flags.BoxValid);3860 D3DDDIRANGE *pRange = NULL;3861 if (pData->Flags.RangeValid)3862 {3863 pRange = &pData->Range;3864 }3865 3866 /* else - we lock the entire vertex buffer, pRect == NULL */3867 3868 if (!pAlloc->LockInfo.cLocks)3869 {3870 VBOXVDBG_CHECK_SMSYNC(pRc);3871 if (!pData->Flags.MightDrawFromLocked || (!pData->Flags.Discard && !pData->Flags.NoOverwrite))3872 {3873 hr = pD3D9IBuf->Lock(pRange ? pRange->Offset : 0,3874 pRange ? pRange->Size : 0,3875 &pAlloc->LockInfo.LockedRect.pBits,3876 vboxDDI2D3DLockFlags(pData->Flags));3877 bLocked = true;3878 }3879 3880 Assert(hr == S_OK);3881 if (hr == S_OK)3882 {3883 Assert(pAlloc->SurfDesc.pitch == pAlloc->SurfDesc.width);3884 pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.pitch;3885 // Assert(pAlloc->LockInfo.fFlags.Value == 0);3886 pAlloc->LockInfo.fFlags = pData->Flags;3887 if (pRange)3888 {3889 pAlloc->LockInfo.Range = *pRange;3890 Assert(pAlloc->LockInfo.fFlags.RangeValid == 1);3891 // pAlloc->LockInfo.fFlags.RangeValid = 1;3892 }3893 else3894 {3895 Assert(pAlloc->LockInfo.fFlags.RangeValid == 0);3896 // pAlloc->LockInfo.fFlags.RangeValid = 0;3897 }3898 }3899 }3900 else3901 {3902 Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);3903 if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)3904 {3905 Assert(pAlloc->LockInfo.Range.Offset == pData->Range.Offset);3906 Assert(pAlloc->LockInfo.Range.Size == pData->Range.Size);3907 }3908 Assert(pAlloc->LockInfo.LockedRect.pBits);3909 }3910 3911 if (hr == S_OK)3912 {3913 ++pAlloc->LockInfo.cLocks;3914 3915 if (!pData->Flags.NotifyOnly)3916 {3917 pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;3918 pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;3919 pData->SlicePitch = 0;3920 Assert(pAlloc->SurfDesc.slicePitch == 0);3921 Assert(!pAlloc->pvMem);3922 }3923 else3924 {3925 Assert(pAlloc->pvMem);3926 Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);3927 if (bLocked && !pData->Flags.Discard)3928 {3929 RECT r, *pr;3930 if (pRange)3931 {3932 r.top = 0;3933 r.left = pRange->Offset;3934 r.bottom = 1;3935 r.right = pRange->Offset + pRange->Size;3936 pr = &r;3937 }3938 else3939 pr = NULL;3940 VBoxD3DIfLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, false /*bool bToLockInfo*/);3941 }3942 }3943 }3944 }3945 else3946 {3947 WARN(("not implemented %d", pRc->aAllocations[0].enmD3DIfType));3948 }3949 3950 #ifdef VBOXWDDMDISP_DAL_CHECK_LOCK3951 if (!SUCCEEDED(hr))3952 {3953 WARN(("lock failed %#x", hr));3954 vboxWddmDalCheckUnlock(pDevice, pAlloc);3955 }3956 #endif3957 }3958 else /* if !VBOXDISPMODE_IS_3D(pDevice->pAdapter) */3959 {3960 if (pAlloc->hAllocation)3961 {3962 if (pRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM)3963 {3964 D3DDDICB_LOCK LockData;3965 LockData.hAllocation = pAlloc->hAllocation;3966 LockData.PrivateDriverData = 0;3967 LockData.NumPages = 0;3968 LockData.pPages = NULL;3969 LockData.pData = NULL; /* out */3970 LockData.Flags.Value = 0;3971 LockData.Flags.Discard = pData->Flags.Discard;3972 LockData.Flags.DonotWait = pData->Flags.DoNotWait;3973 3974 uintptr_t offset;3975 if (pData->Flags.AreaValid)3976 {3977 offset = vboxWddmCalcOffXYrd(pData->Area.left, pData->Area.top, pAlloc->SurfDesc.pitch,3978 pAlloc->SurfDesc.format);3979 }3980 else if (pData->Flags.RangeValid)3981 {3982 offset = pData->Range.Offset;3983 }3984 else if (pData->Flags.BoxValid)3985 {3986 vboxVDbgPrintF((__FUNCTION__": Implement Box area"));3987 Assert(0);3988 offset = 0;3989 }3990 else3991 {3992 offset = 0;3993 }3994 3995 hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &LockData);3996 Assert(hr == S_OK || (hr == D3DERR_WASSTILLDRAWING && pData->Flags.DoNotWait));3997 if (hr == S_OK)3998 {3999 pData->pSurfData = ((uint8_t*)LockData.pData) + offset;4000 pData->Pitch = pAlloc->SurfDesc.pitch;4001 pData->SlicePitch = pAlloc->SurfDesc.slicePitch;4002 4003 if (pData->Flags.Discard)4004 {4005 /* check if the surface was renamed */4006 if (LockData.hAllocation)4007 pAlloc->hAllocation = LockData.hAllocation;4008 }4009 }4010 }4011 /* else - d3d may create sysmem render targets and call our Present callbacks for those4012 * to make it work properly we need to create a VRAM surface corresponding to sysmem one4013 * and copy stuff to VRAM on lock/unlock4014 *4015 * so we don't do any locking here, but still track the lock info here4016 * and do lock-memcopy-unlock to VRAM surface on sysmem surface unlock4017 * */4018 4019 if (hr == S_OK)4020 {4021 Assert(!pAlloc->LockInfo.cLocks);4022 4023 if (!pData->Flags.ReadOnly)4024 {4025 if (pData->Flags.AreaValid)4026 vboxWddmDirtyRegionAddRect(&pAlloc->DirtyRegion, &pData->Area);4027 else4028 {4029 Assert(!pData->Flags.RangeValid);4030 Assert(!pData->Flags.BoxValid);4031 vboxWddmDirtyRegionAddRect(&pAlloc->DirtyRegion, NULL); /* <- NULL means the entire surface */4032 }4033 }4034 4035 ++pAlloc->LockInfo.cLocks;4036 }4037 }4038 }4039 4040 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(%d)\n", hDevice, hr));4041 return hr;4042 }4043 4044 static HRESULT APIENTRY vboxWddmDDevUnlock(HANDLE hDevice, CONST D3DDDIARG_UNLOCK* pData)4045 {4046 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4047 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4048 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4049 Assert(pDevice);4050 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4051 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;4052 HRESULT hr = S_OK;4053 4054 Assert(pData->SubResourceIndex < pRc->cAllocations);4055 if (pData->SubResourceIndex >= pRc->cAllocations)4056 return E_INVALIDARG;4057 4058 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];4059 4060 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))4061 {4062 if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE4063 || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE4064 || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE)4065 {4066 Assert(pData->SubResourceIndex < pRc->cAllocations);4067 4068 VBOXVDBG_DUMP_UNLOCK_ST(pData);4069 4070 --pAlloc->LockInfo.cLocks;4071 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);4072 if (!pAlloc->LockInfo.cLocks)4073 {4074 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];4075 Assert(pTexAlloc->pD3DIf);4076 switch (pRc->aAllocations[0].enmD3DIfType)4077 {4078 case VBOXDISP_D3DIFTYPE_TEXTURE:4079 {4080 IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;4081 hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);4082 break;4083 }4084 case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:4085 {4086 IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pTexAlloc->pD3DIf;4087 hr = pD3DIfCubeTex->UnlockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),4088 VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex));4089 break;4090 }4091 case VBOXDISP_D3DIFTYPE_SURFACE:4092 {4093 IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pTexAlloc->pD3DIf;4094 hr = pD3DIfSurf->UnlockRect();4095 break;4096 }4097 default:4098 Assert(0);4099 break;4100 }4101 if (FAILED(hr))4102 WARN(("UnlockRect failed, hr 0x%x", hr));4103 VBOXVDBG_CHECK_SMSYNC(pRc);4104 }4105 }4106 else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE)4107 {4108 Assert(pData->SubResourceIndex < pRc->cAllocations);4109 4110 VBOXVDBG_DUMP_UNLOCK_ST(pData);4111 4112 --pAlloc->LockInfo.cLocks;4113 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);4114 if (!pAlloc->LockInfo.cLocks)4115 {4116 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];4117 Assert(pTexAlloc->pD3DIf);4118 IDirect3DVolumeTexture9 *pD3DIfTex = (IDirect3DVolumeTexture9*)pTexAlloc->pD3DIf;4119 hr = pD3DIfTex->UnlockBox(pData->SubResourceIndex);4120 if (FAILED(hr))4121 WARN(("UnlockBox failed, hr 0x%x", hr));4122 VBOXVDBG_CHECK_SMSYNC(pRc);4123 }4124 }4125 else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VERTEXBUFFER)4126 {4127 Assert(pData->SubResourceIndex < pRc->cAllocations);4128 4129 --pAlloc->LockInfo.cLocks;4130 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);4131 if (!pAlloc->LockInfo.cLocks4132 && (!pAlloc->LockInfo.fFlags.MightDrawFromLocked4133 || (!pAlloc->LockInfo.fFlags.Discard && !pAlloc->LockInfo.fFlags.NoOverwrite)))4134 {4135 // Assert(!pAlloc->LockInfo.cLocks);4136 IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;4137 Assert(pD3D9VBuf);4138 /* this is a sysmem texture, update */4139 if (pAlloc->pvMem && !pAlloc->LockInfo.fFlags.ReadOnly)4140 {4141 RECT r, *pr;4142 if (pAlloc->LockInfo.fFlags.RangeValid)4143 {4144 r.top = 0;4145 r.left = pAlloc->LockInfo.Range.Offset;4146 r.bottom = 1;4147 r.right = pAlloc->LockInfo.Range.Offset + pAlloc->LockInfo.Range.Size;4148 pr = &r;4149 }4150 else4151 pr = NULL;4152 VBoxD3DIfLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect,4153 pr,4154 true /*bool bToLockInfo*/);4155 }4156 hr = pD3D9VBuf->Unlock();4157 Assert(hr == S_OK);4158 VBOXVDBG_CHECK_SMSYNC(pRc);4159 }4160 else4161 {4162 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);4163 }4164 }4165 else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_INDEXBUFFER)4166 {4167 Assert(pData->SubResourceIndex < pRc->cAllocations);4168 4169 --pAlloc->LockInfo.cLocks;4170 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);4171 if (!pAlloc->LockInfo.cLocks4172 && (!pAlloc->LockInfo.fFlags.MightDrawFromLocked4173 || (!pAlloc->LockInfo.fFlags.Discard && !pAlloc->LockInfo.fFlags.NoOverwrite)))4174 {4175 // Assert(!pAlloc->LockInfo.cLocks);4176 IDirect3DIndexBuffer9 *pD3D9IBuf = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;4177 Assert(pD3D9IBuf);4178 /* this is a sysmem texture, update */4179 if (pAlloc->pvMem && !pAlloc->LockInfo.fFlags.ReadOnly)4180 {4181 RECT r, *pr;4182 if (pAlloc->LockInfo.fFlags.RangeValid)4183 {4184 r.top = 0;4185 r.left = pAlloc->LockInfo.Range.Offset;4186 r.bottom = 1;4187 r.right = pAlloc->LockInfo.Range.Offset + pAlloc->LockInfo.Range.Size;4188 pr = &r;4189 }4190 else4191 pr = NULL;4192 VBoxD3DIfLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect,4193 pr,4194 true /*bool bToLockInfo*/);4195 }4196 hr = pD3D9IBuf->Unlock();4197 Assert(hr == S_OK);4198 VBOXVDBG_CHECK_SMSYNC(pRc);4199 }4200 else4201 {4202 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);4203 }4204 }4205 else4206 {4207 WARN(("Unlock unsupported %d", pRc->aAllocations[0].enmD3DIfType));4208 }4209 4210 #ifdef VBOXWDDMDISP_DAL_CHECK_LOCK4211 if (SUCCEEDED(hr))4212 {4213 hr = vboxWddmDalCheckUnlock(pDevice, pAlloc);4214 if (!SUCCEEDED(hr))4215 WARN(("vboxWddmDalCheckUnlock failed %#x", hr));4216 }4217 else4218 WARN(("unlock failed %#x", hr));4219 #endif4220 }4221 else4222 {4223 if (pAlloc->hAllocation)4224 {4225 BOOL fDoUnlock = FALSE;4226 4227 Assert(pAlloc->LockInfo.cLocks);4228 --pAlloc->LockInfo.cLocks;4229 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);4230 4231 if (pRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM)4232 {4233 fDoUnlock = TRUE;4234 }4235 else4236 {4237 if (!pAlloc->LockInfo.cLocks)4238 {4239 D3DDDICB_LOCK LockData;4240 LockData.hAllocation = pAlloc->hAllocation;4241 LockData.PrivateDriverData = 0;4242 LockData.NumPages = 0;4243 LockData.pPages = NULL;4244 LockData.pData = NULL; /* out */4245 LockData.Flags.Value = 0;4246 4247 hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &LockData);4248 if (hr == S_OK)4249 {4250 D3DLOCKED_RECT LRect;4251 LRect.pBits = LockData.pData;4252 LRect.Pitch = pAlloc->SurfDesc.pitch;4253 Assert(pAlloc->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_VALID);4254 VBoxD3DIfLockUnlockMemSynch(pAlloc, &LRect, &pAlloc->DirtyRegion.Rect, TRUE /* bool bToLockInfo*/);4255 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);4256 fDoUnlock = TRUE;4257 }4258 else4259 {4260 WARN(("pfnLockCb failed, hr 0x%x", hr));4261 }4262 }4263 }4264 4265 if (fDoUnlock)4266 {4267 D3DDDICB_UNLOCK Unlock;4268 4269 Unlock.NumAllocations = 1;4270 Unlock.phAllocations = &pAlloc->hAllocation;4271 4272 hr = pDevice->RtCallbacks.pfnUnlockCb(pDevice->hDevice, &Unlock);4273 if(hr != S_OK)4274 {4275 WARN(("pfnUnlockCb failed, hr 0x%x", hr));4276 }4277 }4278 4279 if (!SUCCEEDED(hr))4280 {4281 WARN(("unlock failure!"));4282 ++pAlloc->LockInfo.cLocks;4283 }4284 }4285 }4286 4287 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));4288 return hr;4289 }4290 static HRESULT APIENTRY vboxWddmDDevLockAsync(HANDLE hDevice, D3DDDIARG_LOCKASYNC* pData)4291 {4292 RT_NOREF(pData);4293 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4294 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));4295 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4296 Assert(pDevice); NOREF(pDevice);4297 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4298 Assert(0);4299 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4300 return E_FAIL;4301 }4302 static HRESULT APIENTRY vboxWddmDDevUnlockAsync(HANDLE hDevice, CONST D3DDDIARG_UNLOCKASYNC* pData)4303 {4304 RT_NOREF(pData);4305 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4306 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));4307 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4308 Assert(pDevice); NOREF(pDevice);4309 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4310 Assert(0);4311 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4312 return E_FAIL;4313 }4314 static HRESULT APIENTRY vboxWddmDDevRename(HANDLE hDevice, CONST D3DDDIARG_RENAME* pData)4315 {4316 RT_NOREF(pData);4317 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4318 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));4319 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4320 Assert(pDevice); NOREF(pDevice);4321 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4322 Assert(0);4323 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4324 return E_FAIL;4325 }4326 4327 static void vboxWddmRequestAllocFree(D3DDDICB_ALLOCATE* pAlloc)4328 {4329 RTMemFree(pAlloc);4330 }4331 4332 static D3DDDICB_ALLOCATE* vboxWddmRequestAllocAlloc(D3DDDIARG_CREATERESOURCE* pResource)4333 {4334 /* allocate buffer for D3DDDICB_ALLOCATE + D3DDDI_ALLOCATIONINFO * numAllocs + PVBOXWDDM_RCINFO with aAllocInfos[numAllocs] */4335 uint32_t cbBuf = sizeof (D3DDDICB_ALLOCATE);4336 uint32_t offDdiAllocInfos = (cbBuf + 7) & ~3;4337 uint32_t cbDdiAllocInfos = sizeof (D3DDDI_ALLOCATIONINFO) * pResource->SurfCount;4338 cbBuf = offDdiAllocInfos + cbDdiAllocInfos;4339 uint32_t offRcInfo = (cbBuf + 7) & ~3;4340 uint32_t cbRcInfo = sizeof (VBOXWDDM_RCINFO);4341 cbBuf = offRcInfo + cbRcInfo;4342 uint32_t offAllocInfos = (cbBuf + 7) & ~3;4343 uint32_t cbAllocInfos = sizeof (VBOXWDDM_ALLOCINFO) * pResource->SurfCount;4344 cbBuf = offAllocInfos + cbAllocInfos;4345 uint8_t *pvBuf = (uint8_t*)RTMemAllocZ(cbBuf);4346 Assert(pvBuf);4347 if (pvBuf)4348 {4349 D3DDDICB_ALLOCATE* pAlloc = (D3DDDICB_ALLOCATE*)pvBuf;4350 pAlloc->NumAllocations = pResource->SurfCount;4351 pAlloc->pAllocationInfo = (D3DDDI_ALLOCATIONINFO*)(pvBuf + offDdiAllocInfos);4352 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)(pvBuf + offRcInfo);4353 pAlloc->PrivateDriverDataSize = cbRcInfo;4354 pAlloc->pPrivateDriverData = pRcInfo;4355 pAlloc->hResource = pResource->hResource;4356 PVBOXWDDM_ALLOCINFO pAllocInfos = (PVBOXWDDM_ALLOCINFO)(pvBuf + offAllocInfos);4357 for (UINT i = 0; i < pResource->SurfCount; ++i)4358 {4359 D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pAlloc->pAllocationInfo[i];4360 PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i];4361 pDdiAllocInfo->pPrivateDriverData = pAllocInfo;4362 pDdiAllocInfo->PrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO);4363 }4364 return pAlloc;4365 }4366 return NULL;4367 }4368 4369 static HRESULT APIENTRY vboxWddmDDevCreateResource(HANDLE hDevice, D3DDDIARG_CREATERESOURCE* pResource)4370 {4371 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4372 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4373 HRESULT hr = S_OK;4374 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4375 Assert(pDevice);4376 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4377 Assert(pResource);4378 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;4379 4380 PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pResource->SurfCount);4381 if (!pRc)4382 {4383 WARN(("vboxResourceAlloc failed"));4384 return E_OUTOFMEMORY;4385 }4386 bool bIssueCreateResource = false;4387 bool bCreateKMResource = false;4388 bool bSetHostID = false;4389 4390 pRc->hResource = pResource->hResource;4391 pRc->hKMResource = NULL;4392 pRc->pDevice = pDevice;4393 pRc->fFlags.Value = 0;4394 pRc->fFlags.Generic = 1;4395 pRc->RcDesc.fFlags = pResource->Flags;4396 pRc->RcDesc.enmFormat = pResource->Format;4397 pRc->RcDesc.enmPool = pResource->Pool;4398 pRc->RcDesc.enmMultisampleType = pResource->MultisampleType;4399 pRc->RcDesc.MultisampleQuality = pResource->MultisampleQuality;4400 pRc->RcDesc.MipLevels = pResource->MipLevels;4401 pRc->RcDesc.Fvf = pResource->Fvf;4402 pRc->RcDesc.VidPnSourceId = pResource->VidPnSourceId;4403 pRc->RcDesc.RefreshRate = pResource->RefreshRate;4404 pRc->RcDesc.enmRotation = pResource->Rotation;4405 pRc->cAllocations = pResource->SurfCount;4406 for (UINT i = 0; i < pResource->SurfCount; ++i)4407 {4408 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];4409 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];4410 pAllocation->hAllocation = NULL;4411 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;4412 pAllocation->iAlloc = i;4413 pAllocation->pRc = pRc;4414 pAllocation->SurfDesc.d3dWidth = pSurf->Width;4415 pAllocation->pvMem = (void*)pSurf->pSysMem;4416 pAllocation->SurfDesc.slicePitch = pSurf->SysMemSlicePitch;4417 pAllocation->SurfDesc.depth = pSurf->Depth;4418 pAllocation->SurfDesc.width = pSurf->Width;4419 pAllocation->SurfDesc.height = pSurf->Height;4420 pAllocation->SurfDesc.format = pResource->Format;4421 if (!vboxWddmFormatToFourcc(pResource->Format))4422 pAllocation->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format);4423 else4424 pAllocation->SurfDesc.bpp = 0;4425 4426 if (pSurf->SysMemPitch)4427 pAllocation->SurfDesc.pitch = pSurf->SysMemPitch;4428 else4429 pAllocation->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pResource->Format);4430 4431 pAllocation->SurfDesc.cbSize = vboxWddmCalcSize(pAllocation->SurfDesc.pitch, pAllocation->SurfDesc.height,4432 pAllocation->SurfDesc.format);4433 4434 pAllocation->SurfDesc.VidPnSourceId = pResource->VidPnSourceId;4435 4436 if (pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM)4437 {4438 Assert(pAllocation->pvMem);4439 Assert(pAllocation->SurfDesc.pitch);4440 UINT minPitch = vboxWddmCalcPitch(pAllocation->SurfDesc.width, pAllocation->SurfDesc.format);4441 Assert(minPitch);4442 if (minPitch)4443 {4444 if (pAllocation->SurfDesc.pitch != minPitch)4445 {4446 Assert(pAllocation->SurfDesc.pitch > minPitch);4447 pAllocation->SurfDesc.d3dWidth = vboxWddmCalcWidthForPitch(pAllocation->SurfDesc.pitch,4448 pAllocation->SurfDesc.format);4449 Assert(VBOXWDDMDISP_IS_TEXTURE(pRc->RcDesc.fFlags) && !pRc->RcDesc.fFlags.CubeMap); /* <- tested for textures only! */4450 }4451 Assert(pAllocation->SurfDesc.d3dWidth >= pAllocation->SurfDesc.width);4452 }4453 else4454 {4455 Assert(pAllocation->SurfDesc.d3dWidth == pAllocation->SurfDesc.width);4456 }4457 }4458 4459 }4460 4461 if (VBOXDISPMODE_IS_3D(pAdapter))4462 {4463 if (pRc->RcDesc.fFlags.SharedResource)4464 {4465 bIssueCreateResource = true;4466 bCreateKMResource = true;4467 }4468 4469 if (pRc->RcDesc.fFlags.RenderTarget || pRc->RcDesc.fFlags.Primary)4470 {4471 bIssueCreateResource = true;4472 bSetHostID = true;4473 }4474 4475 hr = VBoxD3DIfCreateForRc(pRc);4476 if (!SUCCEEDED(hr))4477 {4478 WARN(("VBoxD3DIfCreateForRc failed, hr 0x%x", hr));4479 }4480 }4481 else4482 {4483 bIssueCreateResource = (pResource->Pool != D3DDDIPOOL_SYSTEMMEM) || pResource->Flags.RenderTarget;4484 bCreateKMResource = bIssueCreateResource;4485 }4486 4487 if (SUCCEEDED(hr) && bIssueCreateResource)4488 {4489 pRc->fFlags.KmResource = bCreateKMResource;4490 D3DDDICB_ALLOCATE *pDdiAllocate = vboxWddmRequestAllocAlloc(pResource);4491 Assert(pDdiAllocate);4492 if (pDdiAllocate)4493 {4494 Assert(pDdiAllocate->pPrivateDriverData);4495 Assert(pDdiAllocate->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO));4496 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)pDdiAllocate->pPrivateDriverData;4497 pRcInfo->fFlags = pRc->fFlags;4498 pRcInfo->RcDesc = pRc->RcDesc;4499 pRcInfo->cAllocInfos = pResource->SurfCount;4500 4501 for (UINT i = 0; i < pResource->SurfCount; ++i)4502 {4503 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i];4504 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];4505 Assert(pDdiAllocI->pPrivateDriverData);4506 Assert(pDdiAllocI->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));4507 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData;4508 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];4509 pDdiAllocI->hAllocation = NULL;4510 pDdiAllocI->pSystemMem = pSurf->pSysMem;4511 Assert((!!(pSurf->pSysMem)) == (pResource->Pool == D3DDDIPOOL_SYSTEMMEM));4512 pDdiAllocI->VidPnSourceId = pResource->VidPnSourceId;4513 pDdiAllocI->Flags.Value = 0;4514 if (pResource->Flags.Primary)4515 {4516 Assert(pResource->Flags.RenderTarget);4517 pDdiAllocI->Flags.Primary = 1;4518 }4519 4520 pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;4521 pAllocInfo->fFlags = pResource->Flags;4522 pAllocInfo->hSharedHandle = (uintptr_t)pAllocation->hSharedHandle;4523 pAllocInfo->SurfDesc = pAllocation->SurfDesc;4524 if (bSetHostID)4525 {4526 IDirect3DSurface9 *pSurfIf = NULL;4527 hr = VBoxD3DIfSurfGet(pRc, i, &pSurfIf);4528 if (SUCCEEDED(hr))4529 {4530 hr = pAdapter->D3D.D3D.pfnVBoxWineExD3DSurf9GetHostId(pSurfIf, &pAllocInfo->hostID);4531 if (SUCCEEDED(hr))4532 {4533 Assert(pAllocInfo->hostID);4534 }4535 else4536 {4537 WARN(("pfnVBoxWineExD3DSurf9GetHostId failed, hr 0x%x", hr));4538 break;4539 }4540 pSurfIf->Release();4541 }4542 else4543 {4544 WARN(("VBoxD3DIfSurfGet failed, hr 0x%x", hr));4545 break;4546 }4547 }4548 else4549 pAllocInfo->hostID = 0;4550 }4551 4552 Assert(!pRc->fFlags.Opened);4553 // Assert(!pRc->fFlags.KmResource);4554 Assert(pRc->fFlags.Generic);4555 4556 if (SUCCEEDED(hr))4557 {4558 if (bCreateKMResource)4559 {4560 Assert(pRc->fFlags.KmResource);4561 4562 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate);4563 Assert(hr == S_OK);4564 Assert(pDdiAllocate->hKMResource4565 || pResource->Flags.SharedResource /* for some reason shared resources4566 * are created with zero km resource handle on Win7+ */4567 );4568 }4569 else4570 {4571 Assert(!pRc->fFlags.KmResource);4572 4573 pDdiAllocate->hResource = NULL;4574 pDdiAllocate->NumAllocations = 1;4575 pDdiAllocate->PrivateDriverDataSize = 0;4576 pDdiAllocate->pPrivateDriverData = NULL;4577 D3DDDI_ALLOCATIONINFO *pDdiAllocIBase = pDdiAllocate->pAllocationInfo;4578 4579 for (UINT i = 0; i < pResource->SurfCount; ++i)4580 {4581 pDdiAllocate->pAllocationInfo = &pDdiAllocIBase[i];4582 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate);4583 Assert(hr == S_OK);4584 Assert(!pDdiAllocate->hKMResource);4585 if (SUCCEEDED(hr))4586 {4587 Assert(pDdiAllocate->pAllocationInfo->hAllocation);4588 }4589 else4590 {4591 for (UINT j = 0; j < i; ++j)4592 {4593 D3DDDI_ALLOCATIONINFO * pCur = &pDdiAllocIBase[i];4594 D3DDDICB_DEALLOCATE Dealloc;4595 Dealloc.hResource = 0;4596 Dealloc.NumAllocations = 1;4597 Dealloc.HandleList = &pCur->hAllocation;4598 HRESULT hr2 = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);4599 Assert(hr2 == S_OK); NOREF(hr2);4600 }4601 break;4602 }4603 }4604 4605 pDdiAllocate->pAllocationInfo = pDdiAllocIBase;4606 }4607 4608 if (SUCCEEDED(hr))4609 {4610 pRc->hKMResource = pDdiAllocate->hKMResource;4611 4612 for (UINT i = 0; i < pResource->SurfCount; ++i)4613 {4614 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];4615 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i];4616 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData;4617 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];4618 pAllocation->hAllocation = pDdiAllocI->hAllocation;4619 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;4620 pAllocation->pvMem = (void*)pSurf->pSysMem;4621 pAllocation->SurfDesc = pAllocInfo->SurfDesc;4622 4623 if (pResource->Flags.SharedResource)4624 {4625 #ifdef VBOXWDDMDISP_DEBUG_PRINT_SHARED_CREATE4626 Assert(VBOXWDDMDISP_IS_TEXTURE(pResource->Flags));4627 vboxVDbgPrint(("\n\n********\n(0x%x:0n%d)Shared CREATED pAlloc(0x%p), hRc(0x%p), hAl(0x%p), "4628 "Handle(0x%x), (0n%d) \n***********\n\n",4629 GetCurrentProcessId(), GetCurrentProcessId(),4630 pAllocation, pRc->hKMResource, pAllocation->hAllocation,4631 pAllocation->hSharedHandle, pAllocation->hSharedHandle ));4632 #endif4633 }4634 }4635 4636 VBOXVDBG_CREATE_CHECK_SWAPCHAIN();4637 }4638 }4639 4640 vboxWddmRequestAllocFree(pDdiAllocate);4641 }4642 else4643 {4644 hr = E_OUTOFMEMORY;4645 }4646 }4647 4648 VBOXVDBG_BREAK_SHARED(pRc);4649 4650 if (SUCCEEDED(hr))4651 {4652 pResource->hResource = pRc;4653 hr = S_OK;4654 }4655 else4656 vboxResourceFree(pRc);4657 4658 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));4659 return hr;4660 }4661 4662 static HRESULT APIENTRY vboxWddmDDevDestroyResource(HANDLE hDevice, HANDLE hResource)4663 {4664 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4665 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4666 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4667 Assert(pDevice);4668 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4669 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;4670 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hResource;4671 4672 HRESULT hr = S_OK;4673 4674 Assert(pDevice);4675 Assert(hResource);4676 4677 if (VBOXDISPMODE_IS_3D(pAdapter))4678 {4679 for (UINT i = 0; i < pRc->cAllocations; ++i)4680 {4681 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];4682 if (pAlloc->hSharedHandle)4683 {4684 #ifdef VBOXWDDMDISP_DEBUG_PRINT_SHARED_CREATE4685 vboxVDbgPrint(("\n\n********\n(0x%x:0n%d)Shared DESTROYED pAlloc(0x%p), hRc(0x%p), hAl(0x%p), "4686 "Handle(0x%x), (0n%d) \n***********\n\n",4687 GetCurrentProcessId(), GetCurrentProcessId(),4688 pAlloc, pRc->hKMResource, pAlloc->hAllocation,4689 pAlloc->hSharedHandle, pAlloc->hSharedHandle4690 ));4691 #endif4692 }4693 4694 if (pAlloc->pD3DIf)4695 pAlloc->pD3DIf->Release();4696 4697 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainForAlloc(pAlloc);4698 if (pSwapchain)4699 {4700 PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainRtForAlloc(pSwapchain, pAlloc);4701 vboxWddmSwapchainRtRemove(pSwapchain, pRt);4702 Assert(!vboxWddmSwapchainForAlloc(pAlloc));4703 if (!vboxWddmSwapchainNumRTs(pSwapchain))4704 vboxWddmSwapchainDestroy(pDevice, pSwapchain);4705 }4706 4707 vboxWddmDalCheckNotifyRemove(pDevice, pAlloc);4708 }4709 }4710 4711 if (pRc->fFlags.KmResource)4712 {4713 D3DDDICB_DEALLOCATE Dealloc;4714 Assert(pRc->hResource);4715 Dealloc.hResource = pRc->hResource;4716 /* according to the docs the below two are ignored in case we set the hResource */4717 Dealloc.NumAllocations = 0;4718 Dealloc.HandleList = NULL;4719 hr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);4720 Assert(hr == S_OK);4721 }4722 else4723 {4724 Assert(!(pRc->fFlags.Opened));4725 for (UINT j = 0; j < pRc->cAllocations; ++j)4726 {4727 if (pRc->aAllocations[j].hAllocation)4728 {4729 D3DDDICB_DEALLOCATE Dealloc;4730 Dealloc.hResource = NULL;4731 Dealloc.NumAllocations = 1;4732 Dealloc.HandleList = &pRc->aAllocations[j].hAllocation;4733 HRESULT hr2 = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);4734 Assert(hr2 == S_OK); NOREF(hr2);4735 }4736 }4737 }4738 4739 vboxResourceFree(pRc);4740 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));4741 return hr;4742 }4743 static HRESULT APIENTRY vboxWddmDDevSetDisplayMode(HANDLE hDevice, CONST D3DDDIARG_SETDISPLAYMODE* pData)4744 {4745 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4746 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4747 HRESULT hr = S_OK;4748 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4749 Assert(pDevice);4750 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4751 Assert(VBOXDISPMODE_IS_3D(pDevice->pAdapter));4752 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;4753 Assert(pRc);4754 Assert(pRc->cAllocations > pData->SubResourceIndex);4755 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];4756 Assert(pRc->RcDesc.fFlags.RenderTarget);4757 Assert(pRc->RcDesc.fFlags.Primary);4758 Assert(pAlloc->hAllocation);4759 D3DDDICB_SETDISPLAYMODE DdiDm = {0};4760 DdiDm.hPrimaryAllocation = pAlloc->hAllocation;4761 4762 {4763 hr = pDevice->RtCallbacks.pfnSetDisplayModeCb(pDevice->hDevice, &DdiDm);4764 Assert(hr == S_OK);4765 }4766 4767 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));4768 return hr;4769 }4770 4771 #ifdef VBOXWDDM_TEST_UHGSMI4772 int vboxUhgsmiTst(PVBOXUHGSMI pUhgsmi, uint32_t cbBuf, uint32_t cNumCals, uint64_t * pTimeMs);4773 #endif4774 4775 static HRESULT APIENTRY vboxWddmDDevPresent(HANDLE hDevice, CONST D3DDDIARG_PRESENT* pData)4776 {4777 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4778 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4779 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4780 // VBOXDISPPROFILE_DDI_CHKDUMPRESET(pDevice);4781 Assert(pDevice);4782 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4783 HRESULT hr = S_OK;4784 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;4785 PVBOXWDDMDISP_RESOURCE pSrcRc = NULL, pDstRc = NULL;4786 PVBOXWDDMDISP_ALLOCATION pSrcAlloc = NULL, pDstAlloc = NULL;4787 4788 Assert(vboxWddmDalIsEmpty(pDevice));4789 4790 if (pData->hSrcResource)4791 {4792 pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;4793 Assert(pSrcRc->cAllocations > pData->SrcSubResourceIndex);4794 pSrcAlloc = &pSrcRc->aAllocations[pData->SrcSubResourceIndex];4795 Assert(pSrcAlloc->hAllocation);4796 }4797 4798 if (pData->hDstResource)4799 {4800 pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;4801 Assert(pDstRc->cAllocations > pData->DstSubResourceIndex);4802 pDstAlloc = &pDstRc->aAllocations[pData->DstSubResourceIndex];4803 Assert(pDstAlloc->hAllocation);4804 }4805 4806 if (VBOXDISPMODE_IS_3D(pAdapter))4807 {4808 #ifdef VBOXWDDM_TEST_UHGSMI4809 {4810 static uint32_t cCals = 100000;4811 static uint32_t cbData = 8 * 1024 * 1024;4812 uint64_t TimeMs;4813 int rc = vboxUhgsmiTst(&pDevice->Uhgsmi.Base, cbData, cCals, &TimeMs);4814 uint32_t cCPS = (((uint64_t)cCals) * 1000ULL)/TimeMs;4815 }4816 #endif4817 #ifdef VBOX_WITH_CROGL4818 if (pAdapter->u32VBox3DCaps & CR_VBOX_CAP_TEX_PRESENT)4819 {4820 IDirect3DSurface9 *pSrcSurfIf = NULL;4821 hr = VBoxD3DIfSurfGet(pSrcRc, pData->SrcSubResourceIndex, &pSrcSurfIf);4822 if (SUCCEEDED(hr))4823 {4824 pAdapter->D3D.D3D.pfnVBoxWineExD3DSurf9SyncToHost(pSrcSurfIf);4825 pSrcSurfIf->Release();4826 }4827 else4828 {4829 WARN(("VBoxD3DIfSurfGet failed, hr = 0x%x", hr));4830 return hr;4831 }4832 4833 pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9FlushToHost((IDirect3DDevice9Ex*)pDevice->pDevice9If);4834 }4835 else4836 #endif4837 {4838 pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9FlushToHost((IDirect3DDevice9Ex*)pDevice->pDevice9If);4839 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;4840 Assert(pRc);4841 Assert(pRc->cAllocations > pData->SrcSubResourceIndex);4842 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SrcSubResourceIndex];4843 hr = vboxWddmSwapchainPresent(pDevice, pAlloc);4844 Assert(hr == S_OK);4845 }4846 }4847 4848 D3DDDICB_PRESENT DdiPresent = {0};4849 if (pSrcAlloc)4850 DdiPresent.hSrcAllocation = pSrcAlloc->hAllocation;4851 4852 if (pDstAlloc)4853 DdiPresent.hDstAllocation = pDstAlloc->hAllocation;4854 4855 DdiPresent.hContext = pDevice->DefaultContext.ContextInfo.hContext;4856 4857 #if 0 //def VBOX_WDDMDISP_WITH_PROFILE4858 VBoxDispProfileScopeLogger<VBoxDispProfileEntry> profilePresentCbLogger(pDevice->ProfileDdiPresentCb.alloc("pfnPresentCb"));4859 #endif4860 4861 #ifdef VBOXWDDMDISP_DEBUG_TIMER4862 HANDLE hTimer = NULL;4863 vboxVDbgTimerStart(pDevice->hTimerQueue, &hTimer, 1000);4864 #endif4865 hr = pDevice->RtCallbacks.pfnPresentCb(pDevice->hDevice, &DdiPresent);4866 #ifdef VBOXWDDMDISP_DEBUG_TIMER4867 vboxVDbgTimerStop(pDevice->hTimerQueue, hTimer);4868 #endif4869 #if 0 //def VBOX_WDDMDISP_WITH_PROFILE4870 profilePresentCbLogger.logAndDisable();4871 if (pDevice->ProfileDdiPresentCb.getNumEntries() == 64)4872 {4873 pDevice->ProfileDdiPresentCb.dump(pDevice);4874 pDevice->ProfileDdiPresentCb.reset();4875 }4876 #endif4877 Assert(hr == S_OK);4878 4879 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));4880 4881 VBOXDISPPROFILE_DDI_REPORT_FRAME(pDevice);4882 4883 return hr;4884 }4885 4886 static HRESULT APIENTRY vboxWddmDDevFlush(HANDLE hDevice)4887 {4888 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4889 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4890 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4891 Assert(pDevice);4892 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4893 HRESULT hr = S_OK;4894 if ( VBOXDISPMODE_IS_3D(pDevice->pAdapter)4895 && pDevice->pDevice9If) /* Windows 10 can call the Flush when pDevice9If is not yet initialized. */4896 {4897 4898 hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Flush((IDirect3DDevice9Ex*)pDevice->pDevice9If);4899 Assert(hr == S_OK);4900 4901 vboxWddmDalNotifyChange(pDevice);4902 4903 VBOXVDBG_DUMP_FLUSH(pDevice);4904 }4905 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));4906 4907 VBOXDISPPROFILE_DDI_REPORT_FLUSH(pDevice);4908 4909 return hr;4910 }4911 4912 AssertCompile(sizeof (D3DDDIVERTEXELEMENT) == sizeof (D3DVERTEXELEMENT9));4913 AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Stream) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Stream));4914 AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Offset) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Offset));4915 AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Type) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Type));4916 AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Method) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Method));4917 AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Usage) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Usage));4918 AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, UsageIndex) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, UsageIndex));4919 4920 AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Stream) == RT_OFFSETOF(D3DVERTEXELEMENT9, Stream));4921 AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Offset) == RT_OFFSETOF(D3DVERTEXELEMENT9, Offset));4922 AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Type) == RT_OFFSETOF(D3DVERTEXELEMENT9, Type));4923 AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Method) == RT_OFFSETOF(D3DVERTEXELEMENT9, Method));4924 AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Usage) == RT_OFFSETOF(D3DVERTEXELEMENT9, Usage));4925 AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, UsageIndex) == RT_OFFSETOF(D3DVERTEXELEMENT9, UsageIndex));4926 4927 static HRESULT APIENTRY vboxWddmDDevCreateVertexShaderDecl(HANDLE hDevice, D3DDDIARG_CREATEVERTEXSHADERDECL* pData,4928 CONST D3DDDIVERTEXELEMENT* pVertexElements)4929 {4930 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4931 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4932 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4933 Assert(pDevice);4934 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4935 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);4936 IDirect3DVertexDeclaration9 *pDecl;4937 static D3DVERTEXELEMENT9 DeclEnd = D3DDECL_END();4938 D3DVERTEXELEMENT9* pVe;4939 HRESULT hr = S_OK;4940 bool bFreeVe = false;4941 if(memcmp(&DeclEnd, &pVertexElements[pData->NumVertexElements], sizeof (DeclEnd)))4942 {4943 pVe = (D3DVERTEXELEMENT9*)RTMemAlloc(sizeof (D3DVERTEXELEMENT9) * (pData->NumVertexElements + 1));4944 if (pVe)4945 {4946 memcpy(pVe, pVertexElements, sizeof (D3DVERTEXELEMENT9) * pData->NumVertexElements);4947 pVe[pData->NumVertexElements] = DeclEnd;4948 bFreeVe = true;4949 }4950 else4951 hr = E_OUTOFMEMORY;4952 }4953 else4954 pVe = (D3DVERTEXELEMENT9*)pVertexElements;4955 4956 if (hr == S_OK)4957 {4958 hr = pDevice9If->CreateVertexDeclaration(4959 pVe,4960 &pDecl4961 );4962 Assert(hr == S_OK);4963 if (hr == S_OK)4964 {4965 Assert(pDecl);4966 pData->ShaderHandle = pDecl;4967 }4968 }4969 4970 if (bFreeVe)4971 RTMemFree((void*)pVe);4972 4973 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));4974 return hr;4975 }4976 static HRESULT APIENTRY vboxWddmDDevSetVertexShaderDecl(HANDLE hDevice, HANDLE hShaderHandle)4977 {4978 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4979 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4980 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4981 Assert(pDevice);4982 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4983 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);4984 IDirect3DVertexDeclaration9 *pDecl = (IDirect3DVertexDeclaration9*)hShaderHandle;4985 Assert(pDecl);4986 HRESULT hr = pDevice9If->SetVertexDeclaration(pDecl);4987 Assert(hr == S_OK);4988 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));4989 return hr;4990 }4991 static HRESULT APIENTRY vboxWddmDDevDeleteVertexShaderDecl(HANDLE hDevice, HANDLE hShaderHandle)4992 {4993 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);4994 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));4995 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;4996 Assert(pDevice); NOREF(pDevice);4997 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);4998 IDirect3DVertexDeclaration9 *pDecl = (IDirect3DVertexDeclaration9*)hShaderHandle;4999 HRESULT hr = S_OK;5000 pDecl->Release();5001 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5002 return hr;5003 }5004 static HRESULT APIENTRY vboxWddmDDevCreateVertexShaderFunc(HANDLE hDevice, D3DDDIARG_CREATEVERTEXSHADERFUNC* pData,5005 CONST UINT* pCode)5006 {5007 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5008 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5009 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5010 Assert(pDevice);5011 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5012 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5013 IDirect3DVertexShader9 *pShader;5014 Assert(*((UINT*)((uint8_t*)pCode + pData->Size-4)) == 0x0000FFFF /* end token */);5015 HRESULT hr = pDevice9If->CreateVertexShader((const DWORD *)pCode, &pShader);5016 Assert(hr == S_OK);5017 if (hr == S_OK)5018 {5019 Assert(pShader);5020 pData->ShaderHandle = pShader;5021 }5022 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5023 return hr;5024 }5025 static HRESULT APIENTRY vboxWddmDDevSetVertexShaderFunc(HANDLE hDevice, HANDLE hShaderHandle)5026 {5027 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5028 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5029 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5030 Assert(pDevice);5031 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5032 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5033 IDirect3DVertexShader9 *pShader = (IDirect3DVertexShader9*)hShaderHandle;5034 HRESULT hr = pDevice9If->SetVertexShader(pShader);5035 Assert(hr == S_OK);5036 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5037 return hr;5038 }5039 static HRESULT APIENTRY vboxWddmDDevDeleteVertexShaderFunc(HANDLE hDevice, HANDLE hShaderHandle)5040 {5041 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5042 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5043 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5044 Assert(pDevice); NOREF(pDevice);5045 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5046 IDirect3DVertexShader9 *pShader = (IDirect3DVertexShader9*)hShaderHandle;5047 HRESULT hr = S_OK;5048 pShader->Release();5049 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5050 return hr;5051 }5052 static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConstI(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONSTI* pData,5053 CONST INT* pRegisters)5054 {5055 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5056 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5057 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5058 Assert(pDevice);5059 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5060 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5061 HRESULT hr = pDevice9If->SetVertexShaderConstantI(pData->Register, pRegisters, pData->Count);5062 Assert(hr == S_OK);5063 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5064 return hr;5065 }5066 static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConstB(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONSTB* pData,5067 CONST BOOL* pRegisters)5068 {5069 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5070 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5071 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5072 Assert(pDevice);5073 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5074 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5075 HRESULT hr = pDevice9If->SetVertexShaderConstantB(pData->Register, pRegisters, pData->Count);5076 Assert(hr == S_OK);5077 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5078 return hr;5079 }5080 static HRESULT APIENTRY vboxWddmDDevSetScissorRect(HANDLE hDevice, CONST RECT* pRect)5081 {5082 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5083 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5084 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5085 Assert(pDevice);5086 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5087 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5088 HRESULT hr = pDevice9If->SetScissorRect(pRect);5089 Assert(hr == S_OK);5090 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5091 return hr;5092 }5093 static HRESULT APIENTRY vboxWddmDDevSetStreamSource(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCE* pData)5094 {5095 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5096 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5097 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5098 Assert(pDevice);5099 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5100 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5101 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hVertexBuffer;5102 PVBOXWDDMDISP_ALLOCATION pAlloc = NULL;5103 IDirect3DVertexBuffer9 *pStreamData = NULL;5104 if (pRc)5105 {5106 VBOXVDBG_CHECK_SMSYNC(pRc);5107 Assert(pRc->cAllocations == 1);5108 pAlloc = &pRc->aAllocations[0];5109 Assert(pAlloc->pD3DIf);5110 pStreamData = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;5111 }5112 HRESULT hr = pDevice9If->SetStreamSource(pData->Stream, pStreamData, pData->Offset, pData->Stride);5113 Assert(hr == S_OK);5114 Assert(pData->Stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS);5115 if (hr == S_OK)5116 {5117 if (pDevice->aStreamSource[pData->Stream] && !pAlloc)5118 {5119 --pDevice->cStreamSources;5120 Assert(pDevice->cStreamSources < UINT32_MAX/2);5121 }5122 else if (!pDevice->aStreamSource[pData->Stream] && pAlloc)5123 {5124 ++pDevice->cStreamSources;5125 Assert(pDevice->cStreamSources <= RT_ELEMENTS(pDevice->aStreamSource));5126 }5127 pDevice->aStreamSource[pData->Stream] = pAlloc;5128 pDevice->StreamSourceInfo[pData->Stream].uiOffset = pData->Offset;5129 pDevice->StreamSourceInfo[pData->Stream].uiStride = pData->Stride;5130 5131 PVBOXWDDMDISP_STREAMSOURCEUM pStrSrcUm = &pDevice->aStreamSourceUm[pData->Stream];5132 if (pStrSrcUm->pvBuffer)5133 {5134 --pDevice->cStreamSourcesUm;5135 Assert(pDevice->cStreamSourcesUm < UINT32_MAX/2);5136 pStrSrcUm->pvBuffer = NULL;5137 pStrSrcUm->cbStride = 0;5138 }5139 }5140 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5141 return hr;5142 }5143 static HRESULT APIENTRY vboxWddmDDevSetStreamSourceFreq(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCEFREQ* pData)5144 {5145 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5146 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5147 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5148 Assert(pDevice);5149 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5150 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5151 HRESULT hr = pDevice9If->SetStreamSourceFreq(pData->Stream, pData->Divider);5152 if (SUCCEEDED(hr))5153 hr = S_OK;5154 else5155 WARN(("SetStreamSourceFreq failed hr 0x%x", hr));5156 5157 #ifdef DEBUG_misha5158 /* test it more */5159 Assert(0);5160 #endif5161 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5162 return hr;5163 }5164 static HRESULT APIENTRY vboxWddmDDevSetConvolutionKernelMono(HANDLE hDevice, CONST D3DDDIARG_SETCONVOLUTIONKERNELMONO* pData)5165 {5166 RT_NOREF(pData);5167 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5168 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5169 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5170 Assert(pDevice); NOREF(pDevice);5171 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5172 Assert(0);5173 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5174 return E_FAIL;5175 }5176 static HRESULT APIENTRY vboxWddmDDevComposeRects(HANDLE hDevice, CONST D3DDDIARG_COMPOSERECTS* pData)5177 {5178 RT_NOREF(pData);5179 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5180 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5181 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5182 Assert(pDevice); NOREF(pDevice);5183 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5184 Assert(0);5185 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5186 return E_FAIL;5187 }5188 5189 static HRESULT APIENTRY vboxWddmDDevBlt(HANDLE hDevice, CONST D3DDDIARG_BLT* pData)5190 {5191 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5192 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5193 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5194 Assert(pDevice);5195 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5196 // PVBOXWDDMDISP_SCREEN pScreen = &pDevice->aScreens[pDevice->iPrimaryScreen];5197 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5198 PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;5199 PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;5200 VBOXVDBG_CHECK_SMSYNC(pDstRc);5201 VBOXVDBG_CHECK_SMSYNC(pSrcRc);5202 Assert(pDstRc->cAllocations > pData->DstSubResourceIndex);5203 Assert(pSrcRc->cAllocations > pData->SrcSubResourceIndex);5204 HRESULT hr = S_OK;5205 PVBOXWDDMDISP_ALLOCATION pSrcAlloc = &pSrcRc->aAllocations[pData->SrcSubResourceIndex];5206 PVBOXWDDMDISP_ALLOCATION pDstAlloc = &pDstRc->aAllocations[pData->DstSubResourceIndex];5207 PVBOXWDDMDISP_SWAPCHAIN pSrcSwapchain = vboxWddmSwapchainForAlloc(pSrcAlloc);5208 PVBOXWDDMDISP_SWAPCHAIN pDstSwapchain = vboxWddmSwapchainForAlloc(pDstAlloc);5209 /* try StretchRect */5210 IDirect3DSurface9 *pSrcSurfIf = NULL;5211 IDirect3DSurface9 *pDstSurfIf = NULL;5212 Assert( !pDstSwapchain5213 || vboxWddmSwapchainGetFb(pDstSwapchain)->pAlloc != pDstAlloc5214 || vboxWddmSwapchainNumRTs(pDstSwapchain) == 1); NOREF(pDstSwapchain);5215 5216 VBOXVDBG_BREAK_SHARED(pSrcRc);5217 VBOXVDBG_BREAK_SHARED(pDstRc);5218 5219 hr = VBoxD3DIfSurfGet(pDstRc, pData->DstSubResourceIndex, &pDstSurfIf);5220 Assert(hr == S_OK);5221 if (hr == S_OK)5222 {5223 Assert(pDstSurfIf);5224 do5225 {5226 if (pSrcSwapchain)5227 {5228 hr = vboxWddmSwapchainSurfGet(pDevice, pSrcSwapchain, pSrcAlloc, &pSrcSurfIf);5229 Assert(hr == S_OK);5230 }5231 else5232 {5233 hr = VBoxD3DIfSurfGet(pSrcRc, pData->SrcSubResourceIndex, &pSrcSurfIf);5234 Assert(hr == S_OK);5235 }5236 5237 if (hr == S_OK)5238 {5239 Assert(pSrcSurfIf);5240 5241 VBOXVDBG_BREAK_SHARED(pSrcRc);5242 VBOXVDBG_BREAK_SHARED(pDstRc);5243 5244 /* we support only Point & Linear, we ignore [Begin|Continue|End]PresentToDwm */5245 Assert((pData->Flags.Value & (~(0x00000100 | 0x00000200 | 0x00000400 | 0x00000001 | 0x00000002))) == 0);5246 VBOXVDBG_CHECK_BLT(hr = pDevice9If->StretchRect(pSrcSurfIf, &pData->SrcRect, pDstSurfIf, &pData->DstRect,5247 vboxDDI2D3DBltFlags(pData->Flags)); Assert(hr == S_OK),5248 pSrcAlloc, pSrcSurfIf, &pData->SrcRect, pDstAlloc, pDstSurfIf, &pData->DstRect);5249 5250 pSrcSurfIf->Release();5251 }5252 } while (0);5253 5254 pDstSurfIf->Release();5255 }5256 5257 if (hr != S_OK)5258 {5259 /** @todo fallback to memcpy or whatever ? */5260 Assert(0);5261 }5262 5263 PVBOXWDDMDISP_ALLOCATION pDAlloc = &pDstRc->aAllocations[pData->DstSubResourceIndex];5264 vboxWddmDalCheckAdd(pDevice, pDAlloc, TRUE);5265 pDAlloc = &pSrcRc->aAllocations[pData->SrcSubResourceIndex];5266 vboxWddmDalCheckAdd(pDevice, pDAlloc, FALSE);5267 5268 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5269 return hr;5270 }5271 static HRESULT APIENTRY vboxWddmDDevColorFill(HANDLE hDevice, CONST D3DDDIARG_COLORFILL* pData)5272 {5273 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5274 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5275 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5276 Assert(pDevice);5277 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5278 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5279 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;5280 Assert(pRc);5281 IDirect3DSurface9 *pSurfIf = NULL;5282 HRESULT hr = VBoxD3DIfSurfGet(pRc, pData->SubResourceIndex, &pSurfIf);5283 Assert(hr == S_OK);5284 if (hr == S_OK)5285 {5286 VBOXVDBG_CHECK_SMSYNC(pRc);5287 Assert(pSurfIf);5288 hr = pDevice9If->ColorFill(pSurfIf, &pData->DstRect, pData->Color);5289 Assert(hr == S_OK);5290 /** @todo check what need to do when PresentToDwm flag is set */5291 Assert(pData->Flags.Value == 0);5292 5293 pSurfIf->Release();5294 5295 PVBOXWDDMDISP_ALLOCATION pDAlloc = &pRc->aAllocations[pData->SubResourceIndex];5296 vboxWddmDalCheckAdd(pDevice, pDAlloc, TRUE);5297 }5298 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5299 return hr;5300 }5301 static HRESULT APIENTRY vboxWddmDDevDepthFill(HANDLE hDevice, CONST D3DDDIARG_DEPTHFILL* pData)5302 {5303 RT_NOREF(pData);5304 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5305 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5306 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5307 Assert(pDevice); NOREF(pDevice);5308 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5309 Assert(0);5310 /// @todo vboxWddmDalCheckAdd(pDevice, pDAlloc, TRUE);5311 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5312 return E_FAIL;5313 }5314 static HRESULT APIENTRY vboxWddmDDevCreateQuery(HANDLE hDevice, D3DDDIARG_CREATEQUERY* pData)5315 {5316 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5317 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5318 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5319 Assert(pDevice);5320 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5321 5322 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5323 HRESULT hr = S_OK;5324 PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)RTMemAllocZ(sizeof (VBOXWDDMDISP_QUERY));5325 if (!pQuery)5326 {5327 WARN(("RTMemAllocZ failed"));5328 return E_OUTOFMEMORY;5329 }5330 5331 hr = pDevice9If->CreateQuery(vboxDDI2D3DQueryType(pData->QueryType), &pQuery->pQueryIf);5332 if (FAILED(hr))5333 {5334 WARN(("CreateQuery failed, hr 0x%x", hr));5335 RTMemFree(pQuery);5336 return hr;5337 }5338 5339 Assert(hr == S_OK);5340 5341 pQuery->enmType = pData->QueryType;5342 pData->hQuery = pQuery;5343 5344 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5345 return hr;5346 }5347 static HRESULT APIENTRY vboxWddmDDevDestroyQuery(HANDLE hDevice, HANDLE hQuery)5348 {5349 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5350 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5351 HRESULT hr = S_OK;5352 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5353 Assert(pDevice); NOREF(pDevice);5354 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5355 5356 PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)hQuery;5357 Assert(pQuery);5358 pQuery->pQueryIf->Release();5359 RTMemFree(pQuery);5360 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5361 return hr;5362 }5363 static HRESULT APIENTRY vboxWddmDDevIssueQuery(HANDLE hDevice, CONST D3DDDIARG_ISSUEQUERY* pData)5364 {5365 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5366 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5367 HRESULT hr = S_OK;5368 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5369 Assert(pDevice); NOREF(pDevice);5370 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5371 5372 PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)pData->hQuery;5373 Assert(pQuery);5374 pQuery->fQueryState.Value |= pData->Flags.Value;5375 hr = pQuery->pQueryIf->Issue(vboxDDI2D3DIssueQueryFlags(pData->Flags));5376 if (hr != S_OK)5377 WARN(("Issue failed, hr = 0x%x", hr));5378 5379 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5380 return hr;5381 }5382 static HRESULT APIENTRY vboxWddmDDevGetQueryData(HANDLE hDevice, CONST D3DDDIARG_GETQUERYDATA* pData)5383 {5384 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5385 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5386 HRESULT hr = S_OK;5387 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5388 Assert(pDevice); NOREF(pDevice);5389 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5390 5391 PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)pData->hQuery;5392 Assert(pQuery);5393 DWORD cbData = pQuery->pQueryIf->GetDataSize();5394 #ifdef DEBUG5395 switch (pQuery->enmType)5396 {5397 case D3DDDIQUERYTYPE_EVENT:5398 Assert(cbData == sizeof (BOOL));5399 break;5400 case D3DDDIQUERYTYPE_OCCLUSION:5401 Assert(cbData == sizeof (UINT));5402 break;5403 default:5404 Assert(0);5405 break;5406 }5407 #endif5408 hr = pQuery->pQueryIf->GetData(pData->pData, cbData, 0);5409 if (hr != S_OK && hr != S_FALSE)5410 WARN(("GetData failed, hr = 0x%x", hr));5411 5412 #ifdef DEBUG5413 switch (pQuery->enmType)5414 {5415 case D3DDDIQUERYTYPE_EVENT:5416 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p) D3DDDIQUERYTYPE_EVENT %d\n", hDevice, *(BOOL *)pData->pData));5417 break;5418 case D3DDDIQUERYTYPE_OCCLUSION:5419 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p) D3DDDIQUERYTYPE_OCCLUSION %d\n", hDevice, *(UINT *)pData->pData));5420 break;5421 default:5422 break;5423 }5424 #endif5425 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5426 return hr;5427 }5428 static HRESULT APIENTRY vboxWddmDDevSetRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETRENDERTARGET* pData)5429 {5430 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5431 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5432 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5433 Assert(pDevice);5434 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5435 5436 /*IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice); - unused */5437 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hRenderTarget;5438 PVBOXWDDMDISP_ALLOCATION pAlloc = NULL;5439 if (pRc)5440 {5441 VBOXVDBG_CHECK_SMSYNC(pRc);5442 Assert(pRc);5443 Assert(pData->SubResourceIndex < pRc->cAllocations);5444 pAlloc = &pRc->aAllocations[pData->SubResourceIndex];5445 }5446 HRESULT hr = vboxWddmRenderTargetSet(pDevice, pData->RenderTargetIndex, pAlloc, FALSE);5447 Assert(hr == S_OK);5448 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5449 return hr;5450 }5451 static HRESULT APIENTRY vboxWddmDDevSetDepthStencil(HANDLE hDevice, CONST D3DDDIARG_SETDEPTHSTENCIL* pData)5452 {5453 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5454 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5455 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5456 Assert(pDevice);5457 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5458 5459 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5460 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hZBuffer;5461 IDirect3DSurface9 *pD3D9Surf = NULL;5462 HRESULT hr = S_OK;5463 if (pRc)5464 {5465 VBOXVDBG_CHECK_SMSYNC(pRc);5466 Assert(pRc->cAllocations == 1);5467 hr = VBoxD3DIfSurfGet(pRc, 0, &pD3D9Surf);5468 if (FAILED(hr))5469 WARN(("VBoxD3DIfSurfGet failed, hr (0x%x)",hr));5470 else5471 Assert(pD3D9Surf);5472 }5473 5474 if (SUCCEEDED(hr))5475 {5476 hr = pDevice9If->SetDepthStencilSurface(pD3D9Surf);5477 if (SUCCEEDED(hr))5478 {5479 pDevice->pDepthStencilRc = pRc;5480 hr = S_OK;5481 }5482 else5483 WARN(("VBoxD3DIfSurfGet failed, hr (0x%x)",hr));5484 5485 if (pD3D9Surf)5486 pD3D9Surf->Release();5487 }5488 5489 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5490 return hr;5491 }5492 static HRESULT APIENTRY vboxWddmDDevGenerateMipSubLevels(HANDLE hDevice, CONST D3DDDIARG_GENERATEMIPSUBLEVELS* pData)5493 {5494 RT_NOREF(pData);5495 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5496 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5497 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5498 Assert(pDevice); NOREF(pDevice);5499 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5500 5501 Assert(0);5502 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5503 return E_FAIL;5504 }5505 static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConstI(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONSTI* pData,5506 CONST INT* pRegisters)5507 {5508 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5509 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5510 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5511 Assert(pDevice);5512 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5513 5514 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5515 HRESULT hr = pDevice9If->SetPixelShaderConstantI(pData->Register, pRegisters, pData->Count);5516 Assert(hr == S_OK);5517 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5518 return hr;5519 }5520 static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConstB(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONSTB* pData,5521 CONST BOOL* pRegisters)5522 {5523 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5524 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5525 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5526 Assert(pDevice);5527 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5528 5529 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5530 HRESULT hr = pDevice9If->SetPixelShaderConstantB(pData->Register, pRegisters, pData->Count);5531 Assert(hr == S_OK);5532 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5533 return hr;5534 }5535 static HRESULT APIENTRY vboxWddmDDevCreatePixelShader(HANDLE hDevice, D3DDDIARG_CREATEPIXELSHADER* pData, CONST UINT* pCode)5536 {5537 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5538 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5539 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5540 Assert(pDevice);5541 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5542 5543 IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);5544 IDirect3DPixelShader9 *pShader;5545 Assert(*((UINT*)((uint8_t*)pCode + pData->CodeSize-4)) == 0x0000FFFF /* end token */);5546 HRESULT hr = pDevice9If->CreatePixelShader((const DWORD *)pCode, &pShader);5547 Assert(hr == S_OK);5548 if (hr == S_OK)5549 {5550 Assert(pShader);5551 pData->ShaderHandle = pShader;5552 }5553 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5554 return hr;5555 }5556 static HRESULT APIENTRY vboxWddmDDevDeletePixelShader(HANDLE hDevice, HANDLE hShaderHandle)5557 {5558 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5559 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5560 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5561 Assert(pDevice); NOREF(pDevice);5562 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5563 5564 IDirect3DPixelShader9 *pShader = (IDirect3DPixelShader9*)hShaderHandle;5565 HRESULT hr = S_OK;5566 pShader->Release();5567 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));5568 return hr;5569 }5570 static HRESULT APIENTRY vboxWddmDDevCreateDecodeDevice(HANDLE hDevice, D3DDDIARG_CREATEDECODEDEVICE* pData)5571 {5572 RT_NOREF(pData);5573 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5574 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5575 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5576 Assert(pDevice); NOREF(pDevice);5577 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5578 5579 Assert(0);5580 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5581 return E_FAIL;5582 }5583 static HRESULT APIENTRY vboxWddmDDevDestroyDecodeDevice(HANDLE hDevice, HANDLE hDecodeDevice)5584 {5585 RT_NOREF(hDecodeDevice);5586 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5587 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5588 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5589 Assert(pDevice); NOREF(pDevice);5590 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5591 5592 Assert(0);5593 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5594 return E_FAIL;5595 }5596 static HRESULT APIENTRY vboxWddmDDevSetDecodeRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETDECODERENDERTARGET* pData)5597 {5598 RT_NOREF(pData);5599 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5600 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5601 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5602 Assert(pDevice); NOREF(pDevice);5603 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5604 5605 Assert(0);5606 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5607 return E_FAIL;5608 }5609 static HRESULT APIENTRY vboxWddmDDevDecodeBeginFrame(HANDLE hDevice, D3DDDIARG_DECODEBEGINFRAME* pData)5610 {5611 RT_NOREF(pData);5612 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5613 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5614 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5615 Assert(pDevice); NOREF(pDevice);5616 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5617 5618 Assert(0);5619 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5620 return E_FAIL;5621 }5622 static HRESULT APIENTRY vboxWddmDDevDecodeEndFrame(HANDLE hDevice, D3DDDIARG_DECODEENDFRAME* pData)5623 {5624 RT_NOREF(pData);5625 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5626 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5627 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5628 Assert(pDevice); NOREF(pDevice);5629 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5630 5631 Assert(0);5632 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5633 return E_FAIL;5634 }5635 static HRESULT APIENTRY vboxWddmDDevDecodeExecute(HANDLE hDevice, CONST D3DDDIARG_DECODEEXECUTE* pData)5636 {5637 RT_NOREF(pData);5638 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5639 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5640 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5641 Assert(pDevice); NOREF(pDevice);5642 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5643 5644 Assert(0);5645 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5646 return E_FAIL;5647 }5648 static HRESULT APIENTRY vboxWddmDDevDecodeExtensionExecute(HANDLE hDevice, CONST D3DDDIARG_DECODEEXTENSIONEXECUTE* pData)5649 {5650 RT_NOREF(pData);5651 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5652 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5653 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5654 Assert(pDevice); NOREF(pDevice);5655 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5656 5657 Assert(0);5658 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5659 return E_FAIL;5660 }5661 static HRESULT APIENTRY vboxWddmDDevCreateVideoProcessDevice(HANDLE hDevice, D3DDDIARG_CREATEVIDEOPROCESSDEVICE* pData)5662 {5663 RT_NOREF(pData);5664 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5665 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5666 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5667 Assert(pDevice); NOREF(pDevice);5668 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5669 5670 Assert(0);5671 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5672 return E_FAIL;5673 }5674 static HRESULT APIENTRY vboxWddmDDevDestroyVideoProcessDevice(HANDLE hDevice, HANDLE hVideoProcessor)5675 {5676 RT_NOREF(hVideoProcessor);5677 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5678 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5679 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5680 Assert(pDevice); NOREF(pDevice);5681 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5682 5683 Assert(0);5684 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5685 return E_FAIL;5686 }5687 static HRESULT APIENTRY vboxWddmDDevVideoProcessBeginFrame(HANDLE hDevice, HANDLE hVideoProcessor)5688 {5689 RT_NOREF(hVideoProcessor);5690 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5691 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5692 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5693 Assert(pDevice); NOREF(pDevice);5694 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5695 5696 Assert(0);5697 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5698 return E_FAIL;5699 }5700 static HRESULT APIENTRY vboxWddmDDevVideoProcessEndFrame(HANDLE hDevice, D3DDDIARG_VIDEOPROCESSENDFRAME* pData)5701 {5702 RT_NOREF(pData);5703 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5704 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5705 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5706 Assert(pDevice); NOREF(pDevice);5707 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5708 5709 Assert(0);5710 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5711 return E_FAIL;5712 }5713 static HRESULT APIENTRY vboxWddmDDevSetVideoProcessRenderTarget(HANDLE hDevice,5714 CONST D3DDDIARG_SETVIDEOPROCESSRENDERTARGET* pData)5715 {5716 RT_NOREF(pData);5717 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5718 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5719 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5720 Assert(pDevice); NOREF(pDevice);5721 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5722 5723 Assert(0);5724 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5725 return E_FAIL;5726 }5727 static HRESULT APIENTRY vboxWddmDDevVideoProcessBlt(HANDLE hDevice, CONST D3DDDIARG_VIDEOPROCESSBLT* pData)5728 {5729 RT_NOREF(pData);5730 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5731 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5732 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5733 Assert(pDevice); NOREF(pDevice);5734 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5735 5736 Assert(0);5737 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5738 return E_FAIL;5739 }5740 static HRESULT APIENTRY vboxWddmDDevCreateExtensionDevice(HANDLE hDevice, D3DDDIARG_CREATEEXTENSIONDEVICE* pData)5741 {5742 RT_NOREF(pData);5743 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5744 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5745 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5746 Assert(pDevice); NOREF(pDevice);5747 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5748 5749 Assert(0);5750 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5751 return E_FAIL;5752 }5753 static HRESULT APIENTRY vboxWddmDDevDestroyExtensionDevice(HANDLE hDevice, HANDLE hExtension)5754 {5755 RT_NOREF(hExtension);5756 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5757 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5758 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5759 Assert(pDevice); NOREF(pDevice);5760 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5761 5762 Assert(0);5763 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5764 return E_FAIL;5765 }5766 static HRESULT APIENTRY vboxWddmDDevExtensionExecute(HANDLE hDevice, CONST D3DDDIARG_EXTENSIONEXECUTE* pData)5767 {5768 RT_NOREF(pData);5769 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5770 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5771 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5772 Assert(pDevice); NOREF(pDevice);5773 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5774 5775 Assert(0);5776 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5777 return E_FAIL;5778 }5779 static HRESULT APIENTRY vboxWddmDDevDestroyDevice(IN HANDLE hDevice)5780 {5781 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5782 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5783 5784 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5785 Assert(pDevice);5786 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);5787 5788 VBOXDISPPROFILE_DDI_PRINT(("Dumping on DestroyDevice: 0x%p", pDevice));5789 VBOXDISPPROFILE_DDI_TERM(pDevice);5790 5791 AssertReturn(pDevice->pAdapter->enmHwType == VBOXVIDEO_HWTYPE_VBOX, E_INVALIDARG);5792 5793 #ifdef VBOXWDDMDISP_DEBUG_TIMER5794 DeleteTimerQueueEx(pDevice->hTimerQueue, INVALID_HANDLE_VALUE /* see term */);5795 pDevice->hTimerQueue = NULL;5796 #endif5797 5798 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;5799 if (VBOXDISPMODE_IS_3D(pAdapter))5800 {5801 vboxWddmSwapchainDestroyAll(pDevice);5802 /* ensure the device is destroyed in any way.5803 * Release may not work in case of some leaking, which will leave the crOgl context refering the destroyed VBOXUHGSMI */5804 if (pDevice->pDevice9If)5805 {5806 pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Term((IDirect3DDevice9Ex *)pDevice->pDevice9If);5807 }5808 }5809 5810 HRESULT hr = vboxDispCmCtxDestroy(pDevice, &pDevice->DefaultContext);5811 Assert(hr == S_OK);5812 if (hr == S_OK)5813 {5814 if (pDevice->hHgsmiTransportModule)5815 FreeLibrary(pDevice->hHgsmiTransportModule);5816 RTMemFree(pDevice);5817 }5818 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5819 return hr;5820 }5821 5822 AssertCompile(sizeof (RECT) == sizeof (D3DDDIRECT));5823 AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(D3DDDIRECT, left));5824 AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(D3DDDIRECT, right));5825 AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(D3DDDIRECT, top));5826 AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(D3DDDIRECT, bottom));5827 AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(D3DDDIRECT, left));5828 AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(D3DDDIRECT, right));5829 AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(D3DDDIRECT, top));5830 AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(D3DDDIRECT, bottom));5831 5832 static HRESULT APIENTRY vboxWddmDDevCreateOverlay(HANDLE hDevice, D3DDDIARG_CREATEOVERLAY* pData)5833 {5834 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5835 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5836 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5837 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->OverlayInfo.hResource;5838 Assert(pRc);5839 Assert(pRc->cAllocations > pData->OverlayInfo.SubResourceIndex);5840 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->OverlayInfo.SubResourceIndex];5841 HRESULT hr = S_OK;5842 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)RTMemAllocZ(sizeof (VBOXWDDMDISP_OVERLAY));5843 Assert(pOverlay);5844 if (pOverlay)5845 {5846 VBOXWDDM_OVERLAY_INFO OurInfo;5847 OurInfo.OverlayDesc.DstColorKeyLow = pData->OverlayInfo.DstColorKeyLow;5848 OurInfo.OverlayDesc.DstColorKeyHigh = pData->OverlayInfo.DstColorKeyHigh;5849 OurInfo.OverlayDesc.SrcColorKeyLow = pData->OverlayInfo.SrcColorKeyLow;5850 OurInfo.OverlayDesc.SrcColorKeyHigh = pData->OverlayInfo.SrcColorKeyHigh;5851 OurInfo.OverlayDesc.fFlags = pData->OverlayInfo.Flags.Value;5852 vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);5853 Assert(!pAlloc->LockInfo.cLocks);5854 vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);5855 D3DDDICB_CREATEOVERLAY OverInfo;5856 OverInfo.VidPnSourceId = pData->VidPnSourceId;5857 OverInfo.OverlayInfo.hAllocation = pAlloc->hAllocation;5858 Assert(pAlloc->hAllocation);5859 OverInfo.OverlayInfo.DstRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.DstRect);5860 OverInfo.OverlayInfo.SrcRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.SrcRect);5861 OverInfo.OverlayInfo.pPrivateDriverData = &OurInfo;5862 OverInfo.OverlayInfo.PrivateDriverDataSize = sizeof (OurInfo);5863 OverInfo.hKernelOverlay = NULL; /* <-- out */5864 #ifndef VBOXWDDMOVERLAY_TEST5865 hr = pDevice->RtCallbacks.pfnCreateOverlayCb(pDevice->hDevice, &OverInfo);5866 Assert(hr == S_OK);5867 if (hr == S_OK)5868 {5869 Assert(OverInfo.hKernelOverlay);5870 pOverlay->hOverlay = OverInfo.hKernelOverlay;5871 pOverlay->VidPnSourceId = pData->VidPnSourceId;5872 5873 Assert(!pAlloc->LockInfo.cLocks);5874 if (!pAlloc->LockInfo.cLocks)5875 {5876 /* we have reported the dirty rect, may clear it if no locks are pending currently */5877 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);5878 }5879 5880 pData->hOverlay = pOverlay;5881 }5882 else5883 {5884 RTMemFree(pOverlay);5885 }5886 #else5887 pData->hOverlay = pOverlay;5888 #endif5889 }5890 else5891 hr = E_OUTOFMEMORY;5892 5893 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5894 return hr;5895 }5896 static HRESULT APIENTRY vboxWddmDDevUpdateOverlay(HANDLE hDevice, CONST D3DDDIARG_UPDATEOVERLAY* pData)5897 {5898 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5899 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5900 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5901 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->OverlayInfo.hResource;5902 Assert(pRc);5903 Assert(pRc->cAllocations > pData->OverlayInfo.SubResourceIndex);5904 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->OverlayInfo.SubResourceIndex];5905 HRESULT hr = S_OK;5906 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;5907 VBOXWDDM_OVERLAY_INFO OurInfo;5908 OurInfo.OverlayDesc.DstColorKeyLow = pData->OverlayInfo.DstColorKeyLow;5909 OurInfo.OverlayDesc.DstColorKeyHigh = pData->OverlayInfo.DstColorKeyHigh;5910 OurInfo.OverlayDesc.SrcColorKeyLow = pData->OverlayInfo.SrcColorKeyLow;5911 OurInfo.OverlayDesc.SrcColorKeyHigh = pData->OverlayInfo.SrcColorKeyHigh;5912 OurInfo.OverlayDesc.fFlags = pData->OverlayInfo.Flags.Value;5913 vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);5914 Assert(!pAlloc->LockInfo.cLocks);5915 vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);5916 D3DDDICB_UPDATEOVERLAY OverInfo;5917 OverInfo.hKernelOverlay = pOverlay->hOverlay;5918 OverInfo.OverlayInfo.hAllocation = pAlloc->hAllocation;5919 OverInfo.OverlayInfo.DstRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.DstRect);5920 OverInfo.OverlayInfo.SrcRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.SrcRect);5921 OverInfo.OverlayInfo.pPrivateDriverData = &OurInfo;5922 OverInfo.OverlayInfo.PrivateDriverDataSize = sizeof (OurInfo);5923 #ifndef VBOXWDDMOVERLAY_TEST5924 hr = pDevice->RtCallbacks.pfnUpdateOverlayCb(pDevice->hDevice, &OverInfo);5925 Assert(hr == S_OK);5926 if (hr == S_OK)5927 #endif5928 {5929 Assert(!pAlloc->LockInfo.cLocks);5930 if (!pAlloc->LockInfo.cLocks)5931 {5932 /* we have reported the dirty rect, may clear it if no locks are pending currently */5933 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);5934 }5935 }5936 5937 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5938 return hr;5939 }5940 static HRESULT APIENTRY vboxWddmDDevFlipOverlay(HANDLE hDevice, CONST D3DDDIARG_FLIPOVERLAY* pData)5941 {5942 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5943 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5944 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;5945 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSource;5946 Assert(pRc);5947 Assert(pRc->cAllocations > pData->SourceIndex);5948 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SourceIndex];5949 HRESULT hr = S_OK;5950 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;5951 VBOXWDDM_OVERLAYFLIP_INFO OurInfo;5952 vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);5953 Assert(!pAlloc->LockInfo.cLocks);5954 vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);5955 D3DDDICB_FLIPOVERLAY OverInfo;5956 OverInfo.hKernelOverlay = pOverlay->hOverlay;5957 OverInfo.hSource = pAlloc->hAllocation;5958 OverInfo.pPrivateDriverData = &OurInfo;5959 OverInfo.PrivateDriverDataSize = sizeof (OurInfo);5960 #ifndef VBOXWDDMOVERLAY_TEST5961 hr = pDevice->RtCallbacks.pfnFlipOverlayCb(pDevice->hDevice, &OverInfo);5962 Assert(hr == S_OK);5963 if (hr == S_OK)5964 #endif5965 {5966 Assert(!pAlloc->LockInfo.cLocks);5967 if (!pAlloc->LockInfo.cLocks)5968 {5969 /* we have reported the dirty rect, may clear it if no locks are pending currently */5970 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);5971 }5972 }5973 5974 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5975 return hr;5976 }5977 static HRESULT APIENTRY vboxWddmDDevGetOverlayColorControls(HANDLE hDevice, D3DDDIARG_GETOVERLAYCOLORCONTROLS* pData)5978 {5979 RT_NOREF(pData);5980 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5981 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5982 Assert(0);5983 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5984 return E_FAIL;5985 }5986 static HRESULT APIENTRY vboxWddmDDevSetOverlayColorControls(HANDLE hDevice, CONST D3DDDIARG_SETOVERLAYCOLORCONTROLS* pData)5987 {5988 RT_NOREF(pData);5989 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5990 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));5991 Assert(0);5992 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5993 return E_FAIL;5994 }5995 static HRESULT APIENTRY vboxWddmDDevDestroyOverlay(HANDLE hDevice, CONST D3DDDIARG_DESTROYOVERLAY* pData)5996 {5997 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);5998 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));5999 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;6000 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;6001 D3DDDICB_DESTROYOVERLAY OverInfo;6002 OverInfo.hKernelOverlay = pOverlay->hOverlay;6003 #ifndef VBOXWDDMOVERLAY_TEST6004 HRESULT hr = pDevice->RtCallbacks.pfnDestroyOverlayCb(pDevice->hDevice, &OverInfo);6005 Assert(hr == S_OK);6006 if (hr == S_OK)6007 #else6008 HRESULT hr = S_OK;6009 #endif6010 {6011 RTMemFree(pOverlay);6012 }6013 6014 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));6015 return hr;6016 }6017 static HRESULT APIENTRY vboxWddmDDevQueryResourceResidency(HANDLE hDevice, CONST D3DDDIARG_QUERYRESOURCERESIDENCY* pData)6018 {6019 RT_NOREF(pData);6020 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);6021 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));6022 #if 06023 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;6024 #endif6025 6026 HRESULT hr = S_OK;6027 /** @todo check residency for the "real" allocations */6028 #if 06029 for (UINT i = 0; i < pData->NumResources; ++i)6030 {6031 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->pHandleList[i];6032 Assert(pRc->pDevice == pDevice);6033 if (pRc->hKMResource)6034 {6035 6036 }6037 }6038 #endif6039 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));6040 return hr;6041 }6042 6043 static HRESULT APIENTRY vboxWddmDDevOpenResource(HANDLE hDevice, D3DDDIARG_OPENRESOURCE* pData)6044 {6045 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);6046 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));6047 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;6048 Assert(pDevice);6049 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);6050 6051 HRESULT hr = S_OK;6052 6053 Assert(pData->hKMResource);6054 6055 Assert(pData->NumAllocations);6056 PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pData->NumAllocations);6057 Assert(pRc);6058 if (pRc)6059 {6060 pRc->hResource = pData->hResource;6061 pRc->hKMResource = pData->hKMResource;6062 pRc->pDevice = pDevice;6063 pRc->RcDesc.enmRotation = pData->Rotation;6064 pRc->fFlags.Value = 0;6065 pRc->fFlags.Opened = 1;6066 pRc->fFlags.KmResource = 1;6067 6068 for (UINT i = 0; i < pData->NumAllocations; ++i)6069 {6070 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];6071 D3DDDI_OPENALLOCATIONINFO* pOAI = pData->pOpenAllocationInfo;6072 Assert(pOAI->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));6073 if (pOAI->PrivateDriverDataSize != sizeof (VBOXWDDM_ALLOCINFO))6074 {6075 hr = E_INVALIDARG;6076 break;6077 }6078 Assert(pOAI->pPrivateDriverData);6079 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pOAI->pPrivateDriverData;6080 pAllocation->hAllocation = pOAI->hAllocation;6081 pAllocation->enmType = pAllocInfo->enmType;6082 pAllocation->hSharedHandle = (HANDLE)pAllocInfo->hSharedHandle;6083 pAllocation->SurfDesc = pAllocInfo->SurfDesc;6084 pAllocation->pvMem = NULL;6085 #ifndef VBOXWDDMDISP_DEBUG_NOSHARED6086 Assert(!pAllocation->hSharedHandle == (pAllocation->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE));6087 #endif6088 #ifdef VBOXWDDMDISP_DEBUG_PRINT_SHARED_CREATE6089 vboxVDbgPrint(("\n\n********\n(0x%x:0n%d)Shared OPENNED pAlloc(0x%p), hRc(0x%p), hAl(0x%p), "6090 "Handle(0x%x), (0n%d) \n***********\n\n",6091 GetCurrentProcessId(), GetCurrentProcessId(),6092 pAllocation, pRc->hKMResource, pAllocation->hAllocation,6093 pAllocation->hSharedHandle, pAllocation->hSharedHandle6094 ));6095 #endif6096 }6097 if (!pData->pPrivateDriverData || !pData->PrivateDriverDataSize)6098 {6099 /* this is a "standard" allocation resource */6100 6101 /* both should be actually zero */6102 Assert(!pData->pPrivateDriverData && !pData->PrivateDriverDataSize);6103 pRc->RcDesc.enmPool = D3DDDIPOOL_LOCALVIDMEM;6104 pRc->RcDesc.enmMultisampleType = D3DDDIMULTISAMPLE_NONE;6105 pRc->RcDesc.MultisampleQuality = 0;6106 pRc->RcDesc.MipLevels = 0;6107 /*pRc->RcDesc.Fvf;*/6108 pRc->RcDesc.fFlags.SharedResource = 1;6109 6110 if (pData->NumAllocations != 1)6111 {6112 WARN(("NumAllocations is expected to be 1, but was %d", pData->NumAllocations));6113 }6114 6115 for (UINT i = 0; i < pData->NumAllocations; ++i)6116 {6117 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];6118 pAlloc->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;6119 pAlloc->pD3DIf = NULL;6120 }6121 6122 D3DDDI_OPENALLOCATIONINFO* pDdiAllocInfo = &pData->pOpenAllocationInfo[0];6123 Assert(pDdiAllocInfo->pPrivateDriverData);6124 Assert(pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO));6125 if (pDdiAllocInfo->pPrivateDriverData && pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO))6126 {6127 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocInfo->pPrivateDriverData;6128 switch(pAllocInfo->enmType)6129 {6130 case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:6131 pRc->RcDesc.fFlags.Primary = 1;6132 case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:6133 case VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE:6134 pRc->RcDesc.enmFormat = pAllocInfo->SurfDesc.format;6135 pRc->RcDesc.VidPnSourceId = pAllocInfo->SurfDesc.VidPnSourceId;6136 pRc->RcDesc.RefreshRate = pAllocInfo->SurfDesc.RefreshRate;6137 break;6138 default:6139 Assert(0);6140 hr = E_INVALIDARG;6141 }6142 }6143 else6144 hr = E_INVALIDARG;6145 }6146 else6147 {6148 /* this is a "generic" resource whose creation is initiated by the UMD */6149 Assert(pData->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO));6150 if (pData->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO))6151 {6152 VBOXWDDM_RCINFO *pRcInfo = (VBOXWDDM_RCINFO*)pData->pPrivateDriverData;6153 Assert(pRcInfo->fFlags.Generic);6154 Assert(!pRcInfo->fFlags.Opened);6155 Assert(pRcInfo->cAllocInfos == pData->NumAllocations);6156 pRc->fFlags.Value |= pRcInfo->fFlags.Value;6157 pRc->fFlags.Generic = 1;6158 pRc->RcDesc = pRcInfo->RcDesc;6159 pRc->cAllocations = pData->NumAllocations;6160 Assert(pRc->RcDesc.fFlags.SharedResource);6161 6162 hr = VBoxD3DIfCreateForRc(pRc);6163 if (!SUCCEEDED(hr))6164 {6165 WARN(("VBoxD3DIfCreateForRc failed, hr %d", hr));6166 }6167 }6168 else6169 hr = E_INVALIDARG;6170 }6171 6172 if (hr == S_OK)6173 pData->hResource = pRc;6174 else6175 vboxResourceFree(pRc);6176 }6177 else6178 {6179 vboxVDbgPrintR((__FUNCTION__": vboxResourceAlloc failed for hDevice(0x%p), NumAllocations(%d)\n", hDevice, pData->NumAllocations));6180 hr = E_OUTOFMEMORY;6181 }6182 6183 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));6184 return hr;6185 }6186 static HRESULT APIENTRY vboxWddmDDevGetCaptureAllocationHandle(HANDLE hDevice, D3DDDIARG_GETCAPTUREALLOCATIONHANDLE* pData)6187 {6188 RT_NOREF(pData);6189 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);6190 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));6191 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;6192 Assert(pDevice); NOREF(pDevice);6193 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);6194 6195 Assert(0);6196 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));6197 return E_FAIL;6198 }6199 6200 static HRESULT APIENTRY vboxWddmDDevCaptureToSysMem(HANDLE hDevice, CONST D3DDDIARG_CAPTURETOSYSMEM* pData)6201 {6202 RT_NOREF(pData);6203 VBOXDISP_DDI_PROLOGUE_DEV(hDevice);6204 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));6205 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;6206 Assert(pDevice); NOREF(pDevice);6207 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);6208 6209 Assert(0);6210 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));6211 return E_FAIL;6212 }6213 6214 static HRESULT APIENTRY vboxWddmDispCreateDevice (IN HANDLE hAdapter, IN D3DDDIARG_CREATEDEVICE* pCreateData)6215 {6216 VBOXDISP_DDI_PROLOGUE_ADP(hAdapter);6217 HRESULT hr = S_OK;6218 vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p), Interface(%d), Version(%d)\n", hAdapter, pCreateData->Interface, pCreateData->Version));6219 6220 // Assert(0);6221 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;6222 AssertReturn(pAdapter->enmHwType == VBOXVIDEO_HWTYPE_VBOX, E_INVALIDARG);6223 6224 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)RTMemAllocZ(RT_UOFFSETOF_DYN(VBOXWDDMDISP_DEVICE,6225 apRTs[pAdapter->D3D.cMaxSimRTs]));6226 if (pDevice)6227 {6228 pDevice->cRTs = pAdapter->D3D.cMaxSimRTs;6229 pDevice->pfnCreateDirect3DDevice = VBoxD3DIfDeviceCreateDummy;6230 pDevice->pfnCreateSharedPrimary = vboxD3DIfCreateSharedPrimary;6231 pDevice->hDevice = pCreateData->hDevice;6232 pDevice->pAdapter = pAdapter;6233 pDevice->u32IfVersion = pCreateData->Interface;6234 pDevice->uRtVersion = pCreateData->Version;6235 pDevice->RtCallbacks = *pCreateData->pCallbacks;6236 pDevice->pvCmdBuffer = pCreateData->pCommandBuffer;6237 pDevice->cbCmdBuffer = pCreateData->CommandBufferSize;6238 pDevice->fFlags = pCreateData->Flags;6239 /* Set Viewport to some default values */6240 pDevice->ViewPort.X = 0;6241 pDevice->ViewPort.Y = 0;6242 pDevice->ViewPort.Width = 1;6243 pDevice->ViewPort.Height = 1;6244 pDevice->ViewPort.MinZ = 0.;6245 pDevice->ViewPort.MaxZ = 1.;6246 6247 RTListInit(&pDevice->DirtyAllocList);6248 6249 Assert(!pCreateData->AllocationListSize);6250 Assert(!pCreateData->PatchLocationListSize);6251 6252 pCreateData->hDevice = pDevice;6253 6254 pCreateData->pDeviceFuncs->pfnSetRenderState = vboxWddmDDevSetRenderState;6255 pCreateData->pDeviceFuncs->pfnUpdateWInfo = vboxWddmDDevUpdateWInfo;6256 pCreateData->pDeviceFuncs->pfnValidateDevice = vboxWddmDDevValidateDevice;6257 pCreateData->pDeviceFuncs->pfnSetTextureStageState = vboxWddmDDevSetTextureStageState;6258 pCreateData->pDeviceFuncs->pfnSetTexture = vboxWddmDDevSetTexture;6259 pCreateData->pDeviceFuncs->pfnSetPixelShader = vboxWddmDDevSetPixelShader;6260 pCreateData->pDeviceFuncs->pfnSetPixelShaderConst = vboxWddmDDevSetPixelShaderConst;6261 pCreateData->pDeviceFuncs->pfnSetStreamSourceUm = vboxWddmDDevSetStreamSourceUm;6262 pCreateData->pDeviceFuncs->pfnSetIndices = vboxWddmDDevSetIndices;6263 pCreateData->pDeviceFuncs->pfnSetIndicesUm = vboxWddmDDevSetIndicesUm;6264 pCreateData->pDeviceFuncs->pfnDrawPrimitive = vboxWddmDDevDrawPrimitive;6265 pCreateData->pDeviceFuncs->pfnDrawIndexedPrimitive = vboxWddmDDevDrawIndexedPrimitive;6266 pCreateData->pDeviceFuncs->pfnDrawRectPatch = vboxWddmDDevDrawRectPatch;6267 pCreateData->pDeviceFuncs->pfnDrawTriPatch = vboxWddmDDevDrawTriPatch;6268 pCreateData->pDeviceFuncs->pfnDrawPrimitive2 = vboxWddmDDevDrawPrimitive2;6269 pCreateData->pDeviceFuncs->pfnDrawIndexedPrimitive2 = vboxWddmDDevDrawIndexedPrimitive2;6270 pCreateData->pDeviceFuncs->pfnVolBlt = vboxWddmDDevVolBlt;6271 pCreateData->pDeviceFuncs->pfnBufBlt = vboxWddmDDevBufBlt;6272 pCreateData->pDeviceFuncs->pfnTexBlt = vboxWddmDDevTexBlt;6273 pCreateData->pDeviceFuncs->pfnStateSet = vboxWddmDDevStateSet;6274 pCreateData->pDeviceFuncs->pfnSetPriority = vboxWddmDDevSetPriority;6275 pCreateData->pDeviceFuncs->pfnClear = vboxWddmDDevClear;6276 pCreateData->pDeviceFuncs->pfnUpdatePalette = vboxWddmDDevUpdatePalette;6277 pCreateData->pDeviceFuncs->pfnSetPalette = vboxWddmDDevSetPalette;6278 pCreateData->pDeviceFuncs->pfnSetVertexShaderConst = vboxWddmDDevSetVertexShaderConst;6279 pCreateData->pDeviceFuncs->pfnMultiplyTransform = vboxWddmDDevMultiplyTransform;6280 pCreateData->pDeviceFuncs->pfnSetTransform = vboxWddmDDevSetTransform;6281 pCreateData->pDeviceFuncs->pfnSetViewport = vboxWddmDDevSetViewport;6282 pCreateData->pDeviceFuncs->pfnSetZRange = vboxWddmDDevSetZRange;6283 pCreateData->pDeviceFuncs->pfnSetMaterial = vboxWddmDDevSetMaterial;6284 pCreateData->pDeviceFuncs->pfnSetLight = vboxWddmDDevSetLight;6285 pCreateData->pDeviceFuncs->pfnCreateLight = vboxWddmDDevCreateLight;6286 pCreateData->pDeviceFuncs->pfnDestroyLight = vboxWddmDDevDestroyLight;6287 pCreateData->pDeviceFuncs->pfnSetClipPlane = vboxWddmDDevSetClipPlane;6288 pCreateData->pDeviceFuncs->pfnGetInfo = vboxWddmDDevGetInfo;6289 pCreateData->pDeviceFuncs->pfnLock = vboxWddmDDevLock;6290 pCreateData->pDeviceFuncs->pfnUnlock = vboxWddmDDevUnlock;6291 pCreateData->pDeviceFuncs->pfnCreateResource = vboxWddmDDevCreateResource;6292 pCreateData->pDeviceFuncs->pfnDestroyResource = vboxWddmDDevDestroyResource;6293 pCreateData->pDeviceFuncs->pfnSetDisplayMode = vboxWddmDDevSetDisplayMode;6294 pCreateData->pDeviceFuncs->pfnPresent = vboxWddmDDevPresent;6295 pCreateData->pDeviceFuncs->pfnFlush = vboxWddmDDevFlush;6296 pCreateData->pDeviceFuncs->pfnCreateVertexShaderFunc = vboxWddmDDevCreateVertexShaderFunc;6297 pCreateData->pDeviceFuncs->pfnDeleteVertexShaderFunc = vboxWddmDDevDeleteVertexShaderFunc;6298 pCreateData->pDeviceFuncs->pfnSetVertexShaderFunc = vboxWddmDDevSetVertexShaderFunc;6299 pCreateData->pDeviceFuncs->pfnCreateVertexShaderDecl = vboxWddmDDevCreateVertexShaderDecl;6300 pCreateData->pDeviceFuncs->pfnDeleteVertexShaderDecl = vboxWddmDDevDeleteVertexShaderDecl;6301 pCreateData->pDeviceFuncs->pfnSetVertexShaderDecl = vboxWddmDDevSetVertexShaderDecl;6302 pCreateData->pDeviceFuncs->pfnSetVertexShaderConstI = vboxWddmDDevSetVertexShaderConstI;6303 pCreateData->pDeviceFuncs->pfnSetVertexShaderConstB = vboxWddmDDevSetVertexShaderConstB;6304 pCreateData->pDeviceFuncs->pfnSetScissorRect = vboxWddmDDevSetScissorRect;6305 pCreateData->pDeviceFuncs->pfnSetStreamSource = vboxWddmDDevSetStreamSource;6306 pCreateData->pDeviceFuncs->pfnSetStreamSourceFreq = vboxWddmDDevSetStreamSourceFreq;6307 pCreateData->pDeviceFuncs->pfnSetConvolutionKernelMono = vboxWddmDDevSetConvolutionKernelMono;6308 pCreateData->pDeviceFuncs->pfnComposeRects = vboxWddmDDevComposeRects;6309 pCreateData->pDeviceFuncs->pfnBlt = vboxWddmDDevBlt;6310 pCreateData->pDeviceFuncs->pfnColorFill = vboxWddmDDevColorFill;6311 pCreateData->pDeviceFuncs->pfnDepthFill = vboxWddmDDevDepthFill;6312 pCreateData->pDeviceFuncs->pfnCreateQuery = vboxWddmDDevCreateQuery;6313 pCreateData->pDeviceFuncs->pfnDestroyQuery = vboxWddmDDevDestroyQuery;6314 pCreateData->pDeviceFuncs->pfnIssueQuery = vboxWddmDDevIssueQuery;6315 pCreateData->pDeviceFuncs->pfnGetQueryData = vboxWddmDDevGetQueryData;6316 pCreateData->pDeviceFuncs->pfnSetRenderTarget = vboxWddmDDevSetRenderTarget;6317 pCreateData->pDeviceFuncs->pfnSetDepthStencil = vboxWddmDDevSetDepthStencil;6318 pCreateData->pDeviceFuncs->pfnGenerateMipSubLevels = vboxWddmDDevGenerateMipSubLevels;6319 pCreateData->pDeviceFuncs->pfnSetPixelShaderConstI = vboxWddmDDevSetPixelShaderConstI;6320 pCreateData->pDeviceFuncs->pfnSetPixelShaderConstB = vboxWddmDDevSetPixelShaderConstB;6321 pCreateData->pDeviceFuncs->pfnCreatePixelShader = vboxWddmDDevCreatePixelShader;6322 pCreateData->pDeviceFuncs->pfnDeletePixelShader = vboxWddmDDevDeletePixelShader;6323 pCreateData->pDeviceFuncs->pfnCreateDecodeDevice = vboxWddmDDevCreateDecodeDevice;6324 pCreateData->pDeviceFuncs->pfnDestroyDecodeDevice = vboxWddmDDevDestroyDecodeDevice;6325 pCreateData->pDeviceFuncs->pfnSetDecodeRenderTarget = vboxWddmDDevSetDecodeRenderTarget;6326 pCreateData->pDeviceFuncs->pfnDecodeBeginFrame = vboxWddmDDevDecodeBeginFrame;6327 pCreateData->pDeviceFuncs->pfnDecodeEndFrame = vboxWddmDDevDecodeEndFrame;6328 pCreateData->pDeviceFuncs->pfnDecodeExecute = vboxWddmDDevDecodeExecute;6329 pCreateData->pDeviceFuncs->pfnDecodeExtensionExecute = vboxWddmDDevDecodeExtensionExecute;6330 pCreateData->pDeviceFuncs->pfnCreateVideoProcessDevice = vboxWddmDDevCreateVideoProcessDevice;6331 pCreateData->pDeviceFuncs->pfnDestroyVideoProcessDevice = vboxWddmDDevDestroyVideoProcessDevice;6332 pCreateData->pDeviceFuncs->pfnVideoProcessBeginFrame = vboxWddmDDevVideoProcessBeginFrame;6333 pCreateData->pDeviceFuncs->pfnVideoProcessEndFrame = vboxWddmDDevVideoProcessEndFrame;6334 pCreateData->pDeviceFuncs->pfnSetVideoProcessRenderTarget = vboxWddmDDevSetVideoProcessRenderTarget;6335 pCreateData->pDeviceFuncs->pfnVideoProcessBlt = vboxWddmDDevVideoProcessBlt;6336 pCreateData->pDeviceFuncs->pfnCreateExtensionDevice = vboxWddmDDevCreateExtensionDevice;6337 pCreateData->pDeviceFuncs->pfnDestroyExtensionDevice = vboxWddmDDevDestroyExtensionDevice;6338 pCreateData->pDeviceFuncs->pfnExtensionExecute = vboxWddmDDevExtensionExecute;6339 pCreateData->pDeviceFuncs->pfnCreateOverlay = vboxWddmDDevCreateOverlay;6340 pCreateData->pDeviceFuncs->pfnUpdateOverlay = vboxWddmDDevUpdateOverlay;6341 pCreateData->pDeviceFuncs->pfnFlipOverlay = vboxWddmDDevFlipOverlay;6342 pCreateData->pDeviceFuncs->pfnGetOverlayColorControls = vboxWddmDDevGetOverlayColorControls;6343 pCreateData->pDeviceFuncs->pfnSetOverlayColorControls = vboxWddmDDevSetOverlayColorControls;6344 pCreateData->pDeviceFuncs->pfnDestroyOverlay = vboxWddmDDevDestroyOverlay;6345 pCreateData->pDeviceFuncs->pfnDestroyDevice = vboxWddmDDevDestroyDevice;6346 pCreateData->pDeviceFuncs->pfnQueryResourceResidency = vboxWddmDDevQueryResourceResidency;6347 pCreateData->pDeviceFuncs->pfnOpenResource = vboxWddmDDevOpenResource;6348 pCreateData->pDeviceFuncs->pfnGetCaptureAllocationHandle = vboxWddmDDevGetCaptureAllocationHandle;6349 pCreateData->pDeviceFuncs->pfnCaptureToSysMem = vboxWddmDDevCaptureToSysMem;6350 pCreateData->pDeviceFuncs->pfnLockAsync = NULL; //vboxWddmDDevLockAsync;6351 pCreateData->pDeviceFuncs->pfnUnlockAsync = NULL; //vboxWddmDDevUnlockAsync;6352 pCreateData->pDeviceFuncs->pfnRename = NULL; //vboxWddmDDevRename;6353 6354 VBOXDISPPROFILE_DDI_INIT_DEV(pDevice);6355 #ifdef VBOX_WDDMDISP_WITH_PROFILE6356 pDevice->ProfileDdiPresentCb = VBoxDispProfileSet("pfnPresentCb");6357 #endif6358 6359 #ifdef VBOXWDDMDISP_DEBUG_TIMER6360 pDevice->hTimerQueue = CreateTimerQueue();6361 Assert(pDevice->hTimerQueue);6362 #endif6363 6364 do6365 {6366 RTListInit(&pDevice->SwapchainList);6367 Assert(!pCreateData->AllocationListSize6368 && !pCreateData->PatchLocationListSize);6369 if (!pCreateData->AllocationListSize6370 && !pCreateData->PatchLocationListSize)6371 {6372 {6373 VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);6374 6375 hr = vboxDispCmCtxCreate(pDevice, &pDevice->DefaultContext);6376 Assert(hr == S_OK);6377 if (hr == S_OK)6378 {6379 //# define VBOXDISP_TEST_SWAPCHAIN6380 # ifdef VBOXDISP_TEST_SWAPCHAIN6381 VBOXDISP_D3DEV(pDevice);6382 # endif6383 break;6384 }6385 }6386 }6387 else6388 {6389 vboxVDbgPrintR((__FUNCTION__": Not implemented: PatchLocationListSize(%d), AllocationListSize(%d)\n",6390 pCreateData->PatchLocationListSize, pCreateData->AllocationListSize));6391 //pCreateData->pAllocationList = ??6392 hr = E_FAIL;6393 }6394 6395 RTMemFree(pDevice);6396 } while (0);6397 }6398 else6399 {6400 vboxVDbgPrintR((__FUNCTION__": RTMemAllocZ returned NULL\n"));6401 hr = E_OUTOFMEMORY;6402 }6403 6404 if (SUCCEEDED(hr))6405 {6406 /* Get system D3D DLL handle and prevent its unloading until entire process termination (GET_MODULE_HANDLE_EX_FLAG_PIN).6407 * This is important because even after guest App issued CloseAdatper() call, we still use pointers provided by DLL. */6408 if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN,6409 (LPCWSTR)pDevice->RtCallbacks.pfnAllocateCb,6410 &pDevice->hHgsmiTransportModule))6411 {6412 Assert(pDevice->hHgsmiTransportModule);6413 vboxVDbgPrintR((__FUNCTION__": system D3D DLL referenced with GET_MODULE_HANDLE_EX_FLAG_PIN flag\n"));6414 }6415 else6416 {6417 DWORD winEr = GetLastError(); NOREF(winEr);6418 WARN(("GetModuleHandleEx failed winEr %d, ignoring", winEr));6419 pDevice->hHgsmiTransportModule = 0;6420 }6421 }6422 6423 vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));6424 6425 return hr;6426 }6427 6428 static HRESULT APIENTRY vboxWddmDispCloseAdapter (IN HANDLE hAdapter)6429 {6430 VBOXDISP_DDI_PROLOGUE_ADP(hAdapter);6431 vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));6432 6433 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;6434 if (VBOXDISPMODE_IS_3D(pAdapter))6435 {6436 VBOXDISPCRHGSMI_SCOPE_SET_GLOBAL();6437 VBoxDispD3DGlobalClose(&pAdapter->D3D, &pAdapter->Formats);6438 }6439 #ifdef VBOX_WITH_VIDEOHWACCEL6440 else6441 {6442 VBoxDispD3DGlobal2DFormatsTerm(pAdapter);6443 }6444 #endif6445 6446 VBOXDISPPROFILE_DDI_TERM(pAdapter);6447 6448 RTMemFree(pAdapter);6449 6450 vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));6451 6452 return S_OK;6453 }6454 32 6455 33 #define VBOXDISP_IS_MODULE_FUNC(_pvModule, _cbModule, _pfn) ( \ … … 6549 127 HRESULT APIENTRY OpenAdapter(__inout D3DDDIARG_OPENADAPTER *pOpenData) 6550 128 { 6551 VBOXDISP_DDI_PROLOGUE_GLBL();6552 6553 129 LOG_EXACT(("==> "__FUNCTION__"\n")); 6554 130 … … 6567 143 if (pAdapter->f3D) 6568 144 { 6569 /* 3D adapter. */ 6570 VBOXDISPCRHGSMI_SCOPE_SET_GLOBAL(); 6571 6572 /* Try enable the 3D. */ 145 /* 3D adapter. Try enable the 3D. */ 6573 146 hr = VBoxDispD3DGlobalOpen(&pAdapter->D3D, &pAdapter->Formats, &pAdapter->AdapterInfo); 6574 147 if (hr == S_OK) … … 6593 166 if (SUCCEEDED(hr)) 6594 167 { 6595 VBOXDISPPROFILE_DDI_INIT_ADP(pAdapter);6596 6597 168 /* Return data to the OS. */ 6598 169 if (pAdapter->enmHwType == VBOXVIDEO_HWTYPE_VBOX) 6599 170 { 6600 pOpenData->hAdapter = pAdapter; 6601 pOpenData->pAdapterFuncs->pfnGetCaps = vboxWddmDispGetCaps; 6602 pOpenData->pAdapterFuncs->pfnCreateDevice = vboxWddmDispCreateDevice; 6603 pOpenData->pAdapterFuncs->pfnCloseAdapter = vboxWddmDispCloseAdapter; 6604 pOpenData->DriverVersion = D3D_UMD_INTERFACE_VERSION_VISTA; 171 /* Not supposed to work with this. */ 172 hr = E_FAIL; 6605 173 } 6606 174 #ifdef VBOX_WITH_MESA3D … … 6652 220 if (RT_SUCCESS(rc)) 6653 221 { 6654 // rc = VbglR3Init(); 6655 // AssertRC(rc); 6656 // if (RT_SUCCESS(rc)) 6657 { 6658 HRESULT hr = vboxDispCmInit(); 6659 Assert(hr == S_OK); 6660 if (hr == S_OK) 6661 { 6662 VBoxDispD3DGlobalInit(); 6663 vboxVDbgPrint(("VBoxDispD3D: DLL loaded OK\n")); 6664 return TRUE; 6665 } 6666 // VbglR3Term(); 6667 } 222 VBoxDispD3DGlobalInit(); 223 vboxVDbgPrint(("VBoxDispD3D: DLL loaded OK\n")); 224 return TRUE; 6668 225 } 6669 226 … … 6679 236 vboxVDbgVEHandlerUnregister(); 6680 237 #endif 6681 HRESULT hr = vboxDispCmTerm(); 6682 Assert(hr == S_OK); 6683 if (hr == S_OK) 6684 { 6685 // VbglR3Term(); 6686 /// @todo RTR3Term(); 6687 VBoxDispD3DGlobalTerm(); 6688 return TRUE; 6689 } 238 /// @todo RTR3Term(); 239 VBoxDispD3DGlobalTerm(); 240 return TRUE; 6690 241 6691 242 break; -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h
r76563 r80372 24 24 #include "VBoxDispD3DIf.h" 25 25 #include "../../common/wddm/VBoxMPIf.h" 26 #ifdef VBOX_WITH_CRHGSMI27 #include "VBoxUhgsmiDisp.h"28 #endif29 30 #ifdef VBOX_WDDMDISP_WITH_PROFILE31 #include <iprt/asm.h>32 extern volatile uint32_t g_u32VBoxDispProfileFunctionLoggerIndex;33 # define VBOXDISPPROFILE_FUNCTION_LOGGER_INDEX_GEN() ASMAtomicIncU32(&g_u32VBoxDispProfileFunctionLoggerIndex);34 # include "VBoxDispProfile.h"35 #endif36 26 37 27 #include <iprt/cdefs.h> … … 90 80 VBOXWDDM_QAI AdapterInfo; 91 81 92 #ifdef VBOX_WDDMDISP_WITH_PROFILE93 VBoxDispProfileFpsCounter ProfileDdiFps;94 VBoxDispProfileSet ProfileDdiFunc;95 #endif96 82 #ifdef VBOX_WITH_VIDEOHWACCEL 97 83 uint32_t cHeads; … … 191 177 } VBOXWDDMDISP_SWAPCHAIN, *PVBOXWDDMDISP_SWAPCHAIN; 192 178 179 typedef struct VBOXWDDMDISP_DEVICE *PVBOXWDDMDISP_DEVICE; 193 180 typedef HRESULT FNVBOXWDDMCREATEDIRECT3DDEVICE(PVBOXWDDMDISP_DEVICE pDevice); 194 181 typedef FNVBOXWDDMCREATEDIRECT3DDEVICE *PFNVBOXWDDMCREATEDIRECT3DDEVICE; … … 222 209 D3DVIEWPORT9 ViewPort; 223 210 VBOXWDDMDISP_CONTEXT DefaultContext; 224 #ifdef VBOX_WITH_CRHGSMI225 VBOXUHGSMI_PRIVATE_D3D Uhgsmi;226 #endif227 211 228 212 /* no lock is needed for this since we're guaranteed the per-device calls are not reentrant */ … … 235 219 236 220 HMODULE hHgsmiTransportModule; 237 238 #ifdef VBOX_WDDMDISP_WITH_PROFILE239 VBoxDispProfileFpsCounter ProfileDdiFps;240 VBoxDispProfileSet ProfileDdiFunc;241 242 VBoxDispProfileSet ProfileDdiPresentCb;243 #endif244 245 #ifdef VBOXWDDMDISP_DEBUG_TIMER246 HANDLE hTimerQueue;247 #endif248 221 249 222 UINT cRTs; … … 373 346 void vboxWddmResourceInit(PVBOXWDDMDISP_RESOURCE pRc, UINT cAllocs); 374 347 375 #ifndef IN_VBOXCRHGSMI376 PVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainFindCreate(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pBbAlloc, BOOL *pbNeedPresent);377 HRESULT vboxWddmSwapchainChkCreateIf(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);378 VOID vboxWddmSwapchainDestroy(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);379 380 #endif381 382 348 #endif /* !GA_INCLUDED_SRC_WINNT_Graphics_Video_disp_wddm_VBoxDispD3D_h */ -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DCmn.h
r76563 r80372 36 36 #include "VBoxDispD3DIf.h" 37 37 #include "../../common/wddm/VBoxMPIf.h" 38 #include "VBoxDispCm.h"39 38 #include "VBoxDispMpInternal.h" 40 39 #include <VBoxDispKmt.h> 41 #ifdef VBOX_WITH_CRHGSMI42 #include "VBoxUhgsmiBase.h"43 #include "VBoxUhgsmiDisp.h"44 #include "VBoxUhgsmiKmt.h"45 #endif46 40 #include "VBoxDispD3D.h" 47 #ifndef IN_VBOXCRHGSMI48 41 #include "VBoxD3DIf.h" 49 #endif50 #ifdef VBOX_WITH_CROGL51 #include <cr_protocol.h>52 #endif53 42 54 43 # ifdef VBOXWDDMDISP -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp
r79792 r80372 24 24 #define VBOXWDDM_D3DDDIFORMAT_FROM_FOURCC(_a, _b, _c, _d) \ 25 25 ((D3DDDIFORMAT)MAKEFOURCC(_a, _b, _c, _d)) 26 27 void VBoxDispD3DClose(VBOXDISPD3D *pD3D)28 {29 FreeLibrary(pD3D->hD3DLib);30 pD3D->hD3DLib = NULL;31 }32 33 /**34 * Loads a system DLL.35 *36 * @returns Module handle or NULL37 * @param pszName The DLL name.38 */39 static HMODULE loadSystemDll(const char *pszName)40 {41 /* Assumed here that DEBUG version of VBoxDispD3D.dll will not be installed system wide42 but will be loaded from local folder of an application being debugged. */43 #ifndef DEBUG44 char szPath[MAX_PATH];45 UINT cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));46 size_t cbName = strlen(pszName) + 1;47 if (cchPath + 1 + cbName > sizeof(szPath))48 {49 SetLastError(ERROR_FILENAME_EXCED_RANGE);50 return NULL;51 }52 szPath[cchPath] = '\\';53 memcpy(&szPath[cchPath + 1], pszName, cbName);54 return LoadLibraryA(szPath);55 #else56 return LoadLibraryA(pszName);57 #endif58 }59 60 HRESULT VBoxDispD3DOpen(VBOXDISPD3D *pD3D)61 {62 #ifdef VBOX_WDDM_WOW6463 pD3D->hD3DLib = loadSystemDll("VBoxD3D9wddm-x86.dll");64 #else65 pD3D->hD3DLib = loadSystemDll("VBoxD3D9wddm.dll");66 #endif67 if (!pD3D->hD3DLib)68 {69 DWORD winErr = GetLastError(); NOREF(winErr);70 WARN((__FUNCTION__": LoadLibrary failed, winErr = (%d)", winErr));71 return E_FAIL;72 }73 74 do75 {76 pD3D->pfnDirect3DCreate9Ex = (PFNVBOXDISPD3DCREATE9EX)GetProcAddress(pD3D->hD3DLib, "Direct3DCreate9Ex");77 if (!pD3D->pfnDirect3DCreate9Ex)78 {79 WARN(("no Direct3DCreate9Ex"));80 break;81 }82 83 pD3D->pfnVBoxWineExD3DDev9CreateTexture = (PFNVBOXWINEEXD3DDEV9_CREATETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateTexture");84 if (!pD3D->pfnVBoxWineExD3DDev9CreateTexture)85 {86 WARN(("no VBoxWineExD3DDev9CreateTexture"));87 break;88 }89 90 pD3D->pfnVBoxWineExD3DDev9CreateCubeTexture = (PFNVBOXWINEEXD3DDEV9_CREATECUBETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateCubeTexture");91 if (!pD3D->pfnVBoxWineExD3DDev9CreateCubeTexture)92 {93 WARN(("no VBoxWineExD3DDev9CreateCubeTexture"));94 break;95 }96 97 pD3D->pfnVBoxWineExD3DDev9CreateVolumeTexture = (PFNVBOXWINEEXD3DDEV9_CREATEVOLUMETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateVolumeTexture");98 if (!pD3D->pfnVBoxWineExD3DDev9CreateVolumeTexture)99 {100 WARN(("no VBoxWineExD3DDev9CreateVolumeTexture"));101 break;102 }103 104 pD3D->pfnVBoxWineExD3DDev9Flush = (PFNVBOXWINEEXD3DDEV9_FLUSH)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Flush");105 if (!pD3D->pfnVBoxWineExD3DDev9Flush)106 {107 WARN(("no VBoxWineExD3DDev9Flush"));108 break;109 }110 111 pD3D->pfnVBoxWineExD3DDev9FlushToHost = (PFNVBOXWINEEXD3DDEV9_FLUSHTOHOST)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9FlushToHost");112 if (!pD3D->pfnVBoxWineExD3DDev9FlushToHost)113 {114 WARN(("no VBoxWineExD3DDev9FlushToHost"));115 break;116 }117 118 pD3D->pfnVBoxWineExD3DDev9Finish = (PFNVBOXWINEEXD3DDEV9_FINISH)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Finish");119 if (!pD3D->pfnVBoxWineExD3DDev9Finish)120 {121 WARN(("no VBoxWineExD3DDev9Finish"));122 break;123 }124 125 pD3D->pfnVBoxWineExD3DDev9VolBlt = (PFNVBOXWINEEXD3DDEV9_VOLBLT)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9VolBlt");126 if (!pD3D->pfnVBoxWineExD3DDev9VolBlt)127 {128 WARN(("no VBoxWineExD3DDev9VolBlt"));129 break;130 }131 132 pD3D->pfnVBoxWineExD3DDev9VolTexBlt = (PFNVBOXWINEEXD3DDEV9_VOLTEXBLT)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9VolTexBlt");133 if (!pD3D->pfnVBoxWineExD3DDev9VolTexBlt)134 {135 WARN(("no VBoxWineExD3DDev9VolTexBlt"));136 break;137 }138 139 pD3D->pfnVBoxWineExD3DDev9Term = (PFNVBOXWINEEXD3DDEV9_TERM)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Term");140 if (!pD3D->pfnVBoxWineExD3DDev9Term)141 {142 WARN(("no VBoxWineExD3DDev9Term"));143 break;144 }145 146 pD3D->pfnVBoxWineExD3DSwapchain9Present = (PFNVBOXWINEEXD3DSWAPCHAIN9_PRESENT)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DSwapchain9Present");147 if (!pD3D->pfnVBoxWineExD3DSwapchain9Present)148 {149 WARN(("no VBoxWineExD3DSwapchain9Present"));150 break;151 }152 153 pD3D->pfnVBoxWineExD3DSurf9GetHostId = (PFNVBOXWINEEXD3DSURF9_GETHOSTID)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DSurf9GetHostId");154 if (!pD3D->pfnVBoxWineExD3DSurf9GetHostId)155 {156 WARN(("no VBoxWineExD3DSurf9GetHostId"));157 break;158 }159 160 pD3D->pfnVBoxWineExD3DSurf9SyncToHost = (PFNVBOXWINEEXD3DSURF9_SYNCTOHOST)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DSurf9SyncToHost");161 if (!pD3D->pfnVBoxWineExD3DSurf9SyncToHost)162 {163 WARN(("no VBoxWineExD3DSurf9SyncToHost"));164 break;165 }166 167 pD3D->pfnVBoxWineExD3DSwapchain9GetHostWinID = (PFNVBOXWINEEXD3DSWAPCHAIN9_GETHOSTWINID)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DSwapchain9GetHostWinID");168 if (!pD3D->pfnVBoxWineExD3DSwapchain9GetHostWinID)169 {170 WARN(("no VBoxWineExD3DSwapchain9GetHostWinID"));171 break;172 }173 174 pD3D->pfnVBoxWineExD3DDev9GetHostId = (PFNVBOXWINEEXD3DDEV9_GETHOSTID)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9GetHostId");175 if (!pD3D->pfnVBoxWineExD3DDev9GetHostId)176 {177 WARN(("no VBoxWineExD3DDev9GetHostId"));178 break;179 }180 181 return S_OK;182 183 } while (0);184 185 VBoxDispD3DClose(pD3D);186 187 return E_FAIL;188 }189 190 191 192 static FORMATOP gVBoxFormatOps3D[] = {193 {D3DDDIFMT_A8R8G8B8,194 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|195 FORMATOP_SAME_FORMAT_RENDERTARGET|196 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|197 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|198 FORMATOP_MEMBEROFGROUP_ARGB|199 FORMATOP_SRGBWRITE|FORMATOP_VERTEXTEXTURE, 0, 0, 0},200 201 {D3DDDIFMT_X8R8G8B8,202 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|203 FORMATOP_SAME_FORMAT_RENDERTARGET|204 FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|205 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|206 FORMATOP_MEMBEROFGROUP_ARGB|207 FORMATOP_SRGBWRITE|FORMATOP_VERTEXTEXTURE, 0, 0, 0},208 209 {D3DDDIFMT_A2R10G10B10,210 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|211 FORMATOP_SAME_FORMAT_RENDERTARGET|212 0|213 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|214 FORMATOP_MEMBEROFGROUP_ARGB|215 FORMATOP_VERTEXTEXTURE, 0, 0, 0},216 217 {D3DDDIFMT_X1R5G5B5,218 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|219 FORMATOP_SAME_FORMAT_RENDERTARGET|220 0|221 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|222 FORMATOP_MEMBEROFGROUP_ARGB|223 FORMATOP_VERTEXTEXTURE, 0, 0, 0},224 225 {D3DDDIFMT_A1R5G5B5,226 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|227 FORMATOP_SAME_FORMAT_RENDERTARGET|228 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|229 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|230 FORMATOP_MEMBEROFGROUP_ARGB|231 FORMATOP_VERTEXTEXTURE, 0, 0, 0},232 233 {D3DDDIFMT_A4R4G4B4,234 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|235 FORMATOP_SAME_FORMAT_RENDERTARGET|236 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|237 FORMATOP_OFFSCREENPLAIN|238 0|239 FORMATOP_VERTEXTEXTURE, 0, 0, 0},240 241 {D3DDDIFMT_R5G6B5,242 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|243 FORMATOP_SAME_FORMAT_RENDERTARGET|244 FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|245 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|246 FORMATOP_MEMBEROFGROUP_ARGB|247 FORMATOP_VERTEXTEXTURE, 0, 0, 0},248 249 {D3DDDIFMT_L16,250 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|251 0|252 0|253 FORMATOP_OFFSCREENPLAIN|254 0|255 FORMATOP_VERTEXTEXTURE, 0, 0, 0},256 257 {D3DDDIFMT_A8L8,258 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|259 0|260 0|261 FORMATOP_OFFSCREENPLAIN|262 0|263 FORMATOP_VERTEXTEXTURE, 0, 0, 0},264 265 {D3DDDIFMT_A8,266 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|267 0|268 0|269 FORMATOP_OFFSCREENPLAIN|270 0|271 FORMATOP_VERTEXTEXTURE, 0, 0, 0},272 273 {D3DDDIFMT_L8,274 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|275 0|276 0|277 FORMATOP_OFFSCREENPLAIN|278 0|279 FORMATOP_VERTEXTEXTURE, 0, 0, 0},280 281 {D3DDDIFMT_D16, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},282 {D3DDDIFMT_D24S8, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},283 {D3DDDIFMT_D24X8, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},284 {D3DDDIFMT_D16_LOCKABLE, FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},285 {D3DDDIFMT_X8D24, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},286 {D3DDDIFMT_D32F_LOCKABLE, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},287 {D3DDDIFMT_S8D24, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},288 289 {D3DDDIFMT_DXT1,290 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|291 0|292 0|293 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|294 0|295 FORMATOP_VERTEXTEXTURE, 0, 0, 0},296 297 {D3DDDIFMT_DXT2,298 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|299 0|300 0|301 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|302 0|303 FORMATOP_VERTEXTEXTURE, 0, 0, 0},304 305 {D3DDDIFMT_DXT3,306 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|307 0|308 0|309 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|310 0|311 FORMATOP_VERTEXTEXTURE, 0, 0, 0},312 313 {D3DDDIFMT_DXT4,314 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|315 0|316 0|317 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|318 0|319 FORMATOP_VERTEXTEXTURE, 0, 0, 0},320 321 {D3DDDIFMT_DXT5,322 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|323 0|324 0|325 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|326 0|327 FORMATOP_VERTEXTEXTURE, 0, 0, 0},328 329 {D3DDDIFMT_X8L8V8U8,330 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|331 0|332 0|333 0|334 FORMATOP_BUMPMAP|335 FORMATOP_VERTEXTEXTURE, 0, 0, 0},336 337 {D3DDDIFMT_A2W10V10U10,338 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|339 0|340 0|341 0|342 FORMATOP_BUMPMAP|343 FORMATOP_VERTEXTEXTURE, 0, 0, 0},344 345 {D3DDDIFMT_V8U8,346 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|347 0|348 0|349 0|350 FORMATOP_BUMPMAP|351 FORMATOP_VERTEXTEXTURE, 0, 0, 0},352 353 {D3DDDIFMT_Q8W8V8U8,354 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|355 0|356 0|357 FORMATOP_OFFSCREENPLAIN|358 FORMATOP_BUMPMAP|359 FORMATOP_VERTEXTEXTURE, 0, 0, 0},360 361 {D3DDDIFMT_CxV8U8, FORMATOP_NOFILTER|FORMATOP_NOALPHABLEND|FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},362 363 {D3DDDIFMT_R16F,364 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|365 FORMATOP_SAME_FORMAT_RENDERTARGET|366 0|367 FORMATOP_OFFSCREENPLAIN|368 0|369 FORMATOP_VERTEXTEXTURE, 0, 0, 0},370 371 {D3DDDIFMT_R32F,372 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|373 FORMATOP_SAME_FORMAT_RENDERTARGET|374 0|375 FORMATOP_OFFSCREENPLAIN|376 0|377 FORMATOP_VERTEXTEXTURE, 0, 0, 0},378 379 {D3DDDIFMT_G16R16F,380 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|381 FORMATOP_SAME_FORMAT_RENDERTARGET|382 0|383 FORMATOP_OFFSCREENPLAIN|384 0|385 FORMATOP_VERTEXTEXTURE, 0, 0, 0},386 387 {D3DDDIFMT_G32R32F,388 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|389 FORMATOP_SAME_FORMAT_RENDERTARGET|390 0|391 FORMATOP_OFFSCREENPLAIN|392 0|393 FORMATOP_VERTEXTEXTURE, 0, 0, 0},394 395 // Floating-point formats are not implemented in Chromium.396 {D3DDDIFMT_A16B16G16R16F,397 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|398 FORMATOP_SAME_FORMAT_RENDERTARGET|399 0|400 FORMATOP_OFFSCREENPLAIN|401 0|402 FORMATOP_VERTEXTEXTURE, 0, 0, 0},403 404 {D3DDDIFMT_A32B32G32R32F,405 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|406 FORMATOP_SAME_FORMAT_RENDERTARGET|407 0|408 FORMATOP_OFFSCREENPLAIN|409 0|410 FORMATOP_VERTEXTEXTURE, 0, 0, 0},411 412 {D3DDDIFMT_G16R16,413 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|414 FORMATOP_SAME_FORMAT_RENDERTARGET|415 0|416 FORMATOP_OFFSCREENPLAIN|417 0|418 FORMATOP_VERTEXTEXTURE, 0, 0, 0},419 420 {D3DDDIFMT_A16B16G16R16,421 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|422 FORMATOP_SAME_FORMAT_RENDERTARGET|423 0|424 FORMATOP_OFFSCREENPLAIN|425 0|426 FORMATOP_VERTEXTEXTURE, 0, 0, 0},427 428 {D3DDDIFMT_V16U16,429 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|430 0|431 0|432 0|433 FORMATOP_BUMPMAP|434 FORMATOP_VERTEXTEXTURE, 0, 0, 0},435 436 {D3DDDIFMT_P8, FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|FORMATOP_OFFSCREENPLAIN, 0, 0, 0},437 438 {D3DDDIFMT_UYVY,439 0|440 0|441 0|442 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|443 FORMATOP_NOFILTER|444 FORMATOP_NOALPHABLEND|445 FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},446 447 {D3DDDIFMT_YUY2,448 0|449 0|450 0|451 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|452 FORMATOP_NOFILTER|453 FORMATOP_NOALPHABLEND|454 FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},455 456 {VBOXWDDM_D3DDDIFORMAT_FROM_FOURCC('Y', 'V', '1', '2'),457 0|458 0|459 0|460 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|461 FORMATOP_NOFILTER|462 FORMATOP_NOALPHABLEND|463 FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},464 465 {D3DDDIFMT_Q16W16V16U16,466 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|467 FORMATOP_SAME_FORMAT_RENDERTARGET|468 0|469 FORMATOP_OFFSCREENPLAIN|470 FORMATOP_BUMPMAP|FORMATOP_DMAP|471 FORMATOP_VERTEXTEXTURE, 0, 0, 0},472 473 {D3DDDIFMT_X8B8G8R8,474 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|475 FORMATOP_SAME_FORMAT_RENDERTARGET|476 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|477 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|478 FORMATOP_DMAP|FORMATOP_MEMBEROFGROUP_ARGB|479 FORMATOP_SRGBWRITE|FORMATOP_AUTOGENMIPMAP|FORMATOP_VERTEXTEXTURE|480 FORMATOP_OVERLAY, 0, 0, 0},481 482 {D3DDDIFMT_BINARYBUFFER, FORMATOP_OFFSCREENPLAIN, 0, 0, 0},483 484 {D3DDDIFMT_A4L4,485 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|486 0|487 0|488 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|489 FORMATOP_DMAP|490 FORMATOP_VERTEXTEXTURE, 0, 0, 0},491 492 {D3DDDIFMT_A2B10G10R10,493 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|494 FORMATOP_SAME_FORMAT_RENDERTARGET|495 0|496 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|497 FORMATOP_DMAP|FORMATOP_MEMBEROFGROUP_ARGB|498 FORMATOP_AUTOGENMIPMAP|FORMATOP_VERTEXTEXTURE, 0, 0, 0},499 };500 26 501 27 static FORMATOP gVBoxFormatOpsBase[] = { … … 996 522 { 997 523 DeleteCriticalSection(&g_VBoxDispD3DGlobalCritSect); 998 }999 1000 static void vboxDispD3DGlobalD3DFormatsInit(PVBOXWDDMDISP_FORMATS pFormats)1001 {1002 memset(pFormats, 0, sizeof (*pFormats));1003 pFormats->paFormatOps = gVBoxFormatOps3D;1004 pFormats->cFormatOps = RT_ELEMENTS(gVBoxFormatOps3D);1005 524 } 1006 525 … … 1145 664 #endif /* DEBUG */ 1146 665 1147 static HRESULT vboxWddmGetD3D9Caps(IDirect3D9Ex *pD3D9If, D3DCAPS9 *pCaps)1148 {1149 HRESULT hr = pD3D9If->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pCaps);1150 if (FAILED(hr))1151 {1152 WARN(("GetDeviceCaps failed hr(0x%x)",hr));1153 return hr;1154 }1155 1156 #ifdef DEBUG1157 vboxDispCheckCapsLevel(pCaps);1158 #endif1159 1160 /* needed for Windows Media Player to work properly */1161 pCaps->Caps |= D3DCAPS_READ_SCANLINE;1162 pCaps->Caps2 |= 0x00080000 /*D3DCAPS2_CANRENDERWINDOWED*/;1163 pCaps->Caps2 |= D3DCAPS2_CANSHARERESOURCE;1164 pCaps->DevCaps |= D3DDEVCAPS_FLOATTLVERTEX /* <- must be set according to the docs */1165 /*| D3DDEVCAPS_HWVERTEXBUFFER | D3DDEVCAPS_HWINDEXBUFFER | D3DDEVCAPS_SUBVOLUMELOCK */;1166 pCaps->PrimitiveMiscCaps |= D3DPMISCCAPS_INDEPENDENTWRITEMASKS1167 | D3DPMISCCAPS_FOGINFVF1168 | D3DPMISCCAPS_SEPARATEALPHABLEND | D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS;1169 pCaps->RasterCaps |= D3DPRASTERCAPS_SUBPIXEL | D3DPRASTERCAPS_STIPPLE | D3DPRASTERCAPS_ZBIAS | D3DPRASTERCAPS_COLORPERSPECTIVE /* keep */;1170 pCaps->TextureCaps |= D3DPTEXTURECAPS_TRANSPARENCY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE;1171 pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;1172 pCaps->VolumeTextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;1173 pCaps->StencilCaps |= D3DSTENCILCAPS_TWOSIDED;1174 pCaps->DeclTypes |= D3DDTCAPS_FLOAT16_2 | D3DDTCAPS_FLOAT16_4;1175 pCaps->VertexTextureFilterCaps |= D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MAGFPOINT;1176 pCaps->GuardBandLeft = -8192.;1177 pCaps->GuardBandTop = -8192.;1178 pCaps->GuardBandRight = 8192.;1179 pCaps->GuardBandBottom = 8192.;1180 pCaps->VS20Caps.DynamicFlowControlDepth = 24;1181 pCaps->VS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;1182 pCaps->PS20Caps.DynamicFlowControlDepth = 24;1183 pCaps->PS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;1184 1185 /* workaround for wine not returning InstructionSlots correctly for shaders v3.0 */1186 if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)1187 {1188 pCaps->MaxVertexShader30InstructionSlots = RT_MIN(32768, pCaps->MaxVertexShader30InstructionSlots);1189 pCaps->MaxPixelShader30InstructionSlots = RT_MIN(32768, pCaps->MaxPixelShader30InstructionSlots);1190 }1191 #if defined(DEBUG)1192 if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)1193 {1194 Assert(pCaps->MaxVertexShader30InstructionSlots >= 512);1195 Assert(pCaps->MaxVertexShader30InstructionSlots <= 32768);1196 Assert(pCaps->MaxPixelShader30InstructionSlots >= 512);1197 Assert(pCaps->MaxPixelShader30InstructionSlots <= 32768);1198 }1199 else if ((pCaps->VertexShaderVersion & 0xff00) == 0x0200)1200 {1201 Assert(pCaps->MaxVertexShader30InstructionSlots == 0);1202 Assert(pCaps->MaxPixelShader30InstructionSlots == 0);1203 }1204 else1205 {1206 WARN(("incorect shader caps!"));1207 }1208 #endif1209 1210 pCaps->MaxVertexW = 10000000000.f; /* Required by D3D feature level 9.3. */1211 1212 #ifdef DEBUG1213 vboxDispCheckCapsLevel(pCaps);1214 #endif1215 1216 vboxDispDumpD3DCAPS9(pCaps);1217 1218 return S_OK;1219 }1220 1221 static void vboxDispD3DGlobalDoCloseWine(PVBOXWDDMDISP_D3D pD3D)1222 {1223 pD3D->pD3D9If->Release();1224 pD3D->pD3D9If = NULL;1225 VBoxDispD3DClose(&pD3D->D3D);1226 }1227 1228 static HRESULT vboxDispD3DGlobalDoOpenWine(PVBOXWDDMDISP_D3D pD3D)1229 {1230 HRESULT hr = VBoxDispD3DOpen(&pD3D->D3D);1231 if (SUCCEEDED(hr))1232 {1233 IDirect3D9Ex *pD3D9 = NULL;1234 hr = pD3D->D3D.pfnDirect3DCreate9Ex(D3D_SDK_VERSION, &pD3D9);1235 if (SUCCEEDED(hr))1236 {1237 hr = vboxWddmGetD3D9Caps(pD3D9, &pD3D->Caps);1238 if (SUCCEEDED(hr))1239 {1240 pD3D->pfnD3DBackendClose = vboxDispD3DGlobalDoCloseWine;1241 pD3D->pD3D9If = pD3D9;1242 1243 return S_OK;1244 }1245 1246 WARN(("vboxWddmGetD3D9Caps failed hr = 0x%x", hr));1247 pD3D9->Release();1248 }1249 else1250 {1251 WARN(("Direct3DCreate9Ex failed hr = 0x%x", hr));1252 }1253 VBoxDispD3DClose(&pD3D->D3D);1254 }1255 else1256 {1257 WARN(("VBoxDispD3DOpen failed hr = 0x%x", hr));1258 }1259 return hr;1260 }1261 1262 666 #ifdef VBOX_WITH_MESA3D 1263 667 HRESULT GaWddmD3DBackendOpen(PVBOXWDDMDISP_D3D pD3D, VBOXWDDM_QAI const *pAdapterInfo, PVBOXWDDMDISP_FORMATS pFormats); … … 1271 675 if (pAdapterInfo->enmHwType == VBOXVIDEO_HWTYPE_VBOX) 1272 676 { 1273 vboxDispD3DGlobalD3DFormatsInit(pFormats); 1274 hr = vboxDispD3DGlobalDoOpenWine(pD3D); 677 hr = E_FAIL; 1275 678 } 1276 679 #ifdef VBOX_WITH_MESA3D -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.cpp
r79938 r80372 61 61 } 62 62 63 #if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE)63 #if defined(VBOXWDDMDISP_DEBUG) 64 64 LONG g_VBoxVDbgFIsDwm = -1; 65 65 … … 78 78 #ifdef VBOXWDDMDISP_DEBUG 79 79 80 # ifndef IN_VBOXCRHGSMI81 80 #define VBOXWDDMDISP_DEBUG_DUMP_DEFAULT 0 82 81 DWORD g_VBoxVDbgFDumpSetTexture = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT; … … 627 626 } 628 627 629 # endif630 631 628 static VOID CALLBACK vboxVDbgTimerCb(__in PVOID lpParameter, __in BOOLEAN TimerOrWaitFired) 632 629 { … … 662 659 #endif 663 660 664 #if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE)661 #if defined(VBOXWDDMDISP_DEBUG) 665 662 BOOL vboxVDbgDoCheckExe(const char * pszName) 666 663 { -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h
r79938 r80372 52 52 //# define VBOXWDDMDISP_DEBUG_TIMER 53 53 54 # ifndef IN_VBOXCRHGSMI55 54 /* debug config vars */ 56 55 extern DWORD g_VBoxVDbgFDumpSetTexture; … … 85 84 extern DWORD g_VBoxVDbgCfgCreateSwapchainOnDdiOnce; 86 85 87 # endif /* #ifndef IN_VBOXCRHGSMI */ 88 #endif 89 90 #if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE) 86 #endif 87 88 #if defined(VBOXWDDMDISP_DEBUG) 91 89 /* log enable flags */ 92 90 extern DWORD g_VBoxVDbgFLogRel; … … 120 118 #endif 121 119 122 #if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE)120 #if defined(VBOXWDDMDISP_DEBUG) 123 121 #define vboxVDbgInternalLog(_p) if (g_VBoxVDbgFLog) { _p } 124 122 #define vboxVDbgInternalLogFlow(_p) if (g_VBoxVDbgFLogFlow) { _p } … … 159 157 } while (0) 160 158 161 #if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE)159 #if defined(VBOXWDDMDISP_DEBUG) 162 160 extern DWORD g_VBoxVDbgPid; 163 161 extern LONG g_VBoxVDbgFIsDwm; … … 203 201 void vboxDispLogDbgPrintF(char * szString, ...); 204 202 205 # ifndef IN_VBOXCRHGSMI206 203 typedef struct VBOXWDDMDISP_ALLOCATION *PVBOXWDDMDISP_ALLOCATION; 207 204 typedef struct VBOXWDDMDISP_RESOURCE *PVBOXWDDMDISP_RESOURCE; … … 632 629 } while (0) 633 630 634 # endif /* # ifndef IN_VBOXCRHGSMI */635 631 #else 636 632 #define VBOXVDBG_DUMP_DRAWPRIM_ENTER(_pDevice) do { } while (0) -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/Makefile.kmk
r76553 r80372 26 26 VBoxDispMpLogger_TEMPLATE = VBoxGuestR3Lib 27 27 VBoxDispMpLogger_SDKS = ReorderCompilerIncs $(VBOX_WINDDK_GST_WLH) 28 VBoxDispMpLogger_DEFS = UNICODE _UNICODE VBOX_WITH_ CRHGSMI IN_VBOXCRHGSMI VBOX_WITH_WDDM VBOX_WITH_VDMA VBOX_WITH_HGCM28 VBoxDispMpLogger_DEFS = UNICODE _UNICODE VBOX_WITH_WDDM VBOX_WITH_VDMA VBOX_WITH_HGCM 29 29 VBoxDispMpLogger_INCS = \ 30 30 $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \ … … 49 49 VBoxWddmUmKmt_TEMPLATE = VBoxGuestR3Lib 50 50 VBoxWddmUmKmt_SDKS = ReorderCompilerIncs $(VBOX_WINDDK_GST_WLH) 51 VBoxWddmUmKmt_DEFS = UNICODE _UNICODE VBOX_WITH_ CRHGSMI IN_VBOXCRHGSMI VBOX_WITH_WDDM VBOX_WITH_VDMA VBOX_WITH_HGCM51 VBoxWddmUmKmt_DEFS = UNICODE _UNICODE VBOX_WITH_WDDM VBOX_WITH_VDMA VBOX_WITH_HGCM 52 52 VBoxWddmUmKmt_INCS = \ 53 53 $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \ -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispMpLogger.h
r76563 r80372 29 29 #include <iprt/cdefs.h> 30 30 31 #if 032 /* enable this in case we include this in a dll*/33 # ifdef IN_VBOXCRHGSMI34 # define VBOXDISPMPLOGGER_DECL(a_Type) DECLEXPORT(a_Type) RTCALL35 # else36 # define VBOXDISPMPLOGGER_DECL(a_Type) DECLIMPORT(a_Type) RTCALL37 # endif38 #else39 31 /*enable this in case we include this in a static lib*/ 40 32 # define VBOXDISPMPLOGGER_DECL(a_Type) a_Type RTCALL 41 #endif42 33 43 34 RT_C_DECLS_BEGIN
Note:
See TracChangeset
for help on using the changeset viewer.