1 | /* $Id: VBoxUhgsmiBase.h 63018 2016-08-04 23:14:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxVideo Display D3D User mode dll
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___VBoxUhgsmiBase_h__
|
---|
19 | #define ___VBoxUhgsmiBase_h__
|
---|
20 |
|
---|
21 | #include <VBox/VBoxUhgsmi.h>
|
---|
22 | #include <VBox/VBoxCrHgsmi.h>
|
---|
23 |
|
---|
24 | #include <iprt/win/windows.h>
|
---|
25 | #include <D3dkmthk.h>
|
---|
26 | //#include <D3dumddi.h>
|
---|
27 | #include "common/wddm/VBoxMPIf.h"
|
---|
28 |
|
---|
29 |
|
---|
30 | #ifndef VBOX_WITH_CRHGSMI
|
---|
31 | #error "VBOX_WITH_CRHGSMI not defined!"
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #if 0
|
---|
35 | typedef DECLCALLBACK(int) FNVBOXCRHGSMI_CTLCON_CALL(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, struct VBoxGuestHGCMCallInfo *pCallInfo, int cbCallInfo);
|
---|
36 | typedef FNVBOXCRHGSMI_CTLCON_CALL *PFNVBOXCRHGSMI_CTLCON_CALL;
|
---|
37 |
|
---|
38 | #define vboxCrHgsmiPrivateCtlConCall(_pHgsmi, _pCallInfo, _cbCallInfo) (_pHgsmi->pfnCtlConCall((_pHgsmi), (_pCallInfo), (_cbCallInfo)))
|
---|
39 |
|
---|
40 |
|
---|
41 | typedef DECLCALLBACK(int) FNVBOXCRHGSMI_CTLCON_GETCLIENTID(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, uint32_t *pu32ClientID);
|
---|
42 | typedef FNVBOXCRHGSMI_CTLCON_GETCLIENTID *PFNVBOXCRHGSMI_CTLCON_GETCLIENTID;
|
---|
43 |
|
---|
44 | #define vboxCrHgsmiPrivateCtlConGetClientID(_pHgsmi, _pu32ClientID) (_pHgsmi->pfnCtlConGetClientID((_pHgsmi), (_pu32ClientID)))
|
---|
45 | #else
|
---|
46 | int vboxCrHgsmiPrivateCtlConCall(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, struct VBoxGuestHGCMCallInfo *pCallInfo, int cbCallInfo);
|
---|
47 | int vboxCrHgsmiPrivateCtlConGetClientID(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, uint32_t *pu32ClientID);
|
---|
48 | int vboxCrHgsmiPrivateCtlConGetHostCaps(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, uint32_t *pu32HostCaps);
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | typedef DECLCALLBACK(int) FNVBOXCRHGSMI_ESCAPE(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, void *pvData, uint32_t cbData, BOOL fHwAccess);
|
---|
52 | typedef FNVBOXCRHGSMI_ESCAPE *PFNVBOXCRHGSMI_ESCAPE;
|
---|
53 |
|
---|
54 | #define vboxCrHgsmiPrivateEscape(_pHgsmi, _pvData, _cbData, _fHwAccess) (_pHgsmi->pfnEscape((_pHgsmi), (_pvData), (_cbData), (_fHwAccess)))
|
---|
55 |
|
---|
56 | typedef struct VBOXUHGSMI_PRIVATE_BASE
|
---|
57 | {
|
---|
58 | VBOXUHGSMI Base;
|
---|
59 | PFNVBOXCRHGSMI_ESCAPE pfnEscape;
|
---|
60 | } VBOXUHGSMI_PRIVATE_BASE, *PVBOXUHGSMI_PRIVATE_BASE;
|
---|
61 |
|
---|
62 | typedef struct VBOXUHGSMI_BUFFER_PRIVATE_BASE
|
---|
63 | {
|
---|
64 | VBOXUHGSMI_BUFFER Base;
|
---|
65 | PVBOXUHGSMI_PRIVATE_BASE pHgsmi;
|
---|
66 | } VBOXUHGSMI_BUFFER_PRIVATE_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_BASE;
|
---|
67 |
|
---|
68 | typedef struct VBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE
|
---|
69 | {
|
---|
70 | VBOXUHGSMI_BUFFER_PRIVATE_BASE BasePrivate;
|
---|
71 | VBOXVIDEOCM_UM_ALLOC Alloc;
|
---|
72 | HANDLE hSynch;
|
---|
73 | } VBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE;
|
---|
74 |
|
---|
75 | typedef struct VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE
|
---|
76 | {
|
---|
77 | VBOXUHGSMI_BUFFER_PRIVATE_BASE BasePrivate;
|
---|
78 | D3DKMT_HANDLE hAllocation;
|
---|
79 | UINT aLockPageIndices[1];
|
---|
80 | } VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE;
|
---|
81 |
|
---|
82 | #define VBOXUHGSMIBASE_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, Base)))
|
---|
83 | #define VBOXUHGSMIBASE_GET(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_PRIVATE_BASE)
|
---|
84 | #define VBOXUHGSMIBASE_GET_BUFFER(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_BASE)
|
---|
85 |
|
---|
86 | #define VBOXUHGSMIPRIVATEBASE_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, BasePrivate.Base)))
|
---|
87 | #define VBOXUHGSMIESCBASE_GET_BUFFER(_p) VBOXUHGSMIPRIVATEBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE)
|
---|
88 | #define VBOXUHGSMDXALLOCBASE_GET_BUFFER(_p) VBOXUHGSMIPRIVATEBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE)
|
---|
89 |
|
---|
90 | DECLINLINE(int) vboxUhgsmiBaseDxLockData(PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pPrivate, uint32_t offLock, uint32_t cbLock,
|
---|
91 | VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, D3DDDICB_LOCKFLAGS *pfFlags, UINT *pNumPages)
|
---|
92 | {
|
---|
93 | PVBOXUHGSMI_BUFFER pBuf = &pPrivate->BasePrivate.Base;
|
---|
94 | D3DDDICB_LOCKFLAGS fLockFlags;
|
---|
95 | fLockFlags.Value = 0;
|
---|
96 | if (fFlags.bLockEntire)
|
---|
97 | {
|
---|
98 | Assert(!offLock);
|
---|
99 | fLockFlags.LockEntire = 1;
|
---|
100 | }
|
---|
101 | else
|
---|
102 | {
|
---|
103 | AssertReturn(cbLock, VERR_INVALID_PARAMETER);
|
---|
104 | AssertReturn(offLock + cbLock <= pBuf->cbBuffer, VERR_INVALID_PARAMETER);
|
---|
105 |
|
---|
106 | uint32_t iFirstPage = offLock >> 12;
|
---|
107 | uint32_t iAfterLastPage = (cbLock + 0xfff) >> 12;
|
---|
108 | uint32_t cPages = iAfterLastPage - iFirstPage;
|
---|
109 | uint32_t cBufPages = pBuf->cbBuffer >> 12;
|
---|
110 | Assert(cPages <= (cBufPages));
|
---|
111 |
|
---|
112 | if (cPages == cBufPages)
|
---|
113 | {
|
---|
114 | *pNumPages = 0;
|
---|
115 | fLockFlags.LockEntire = 1;
|
---|
116 | }
|
---|
117 | else
|
---|
118 | {
|
---|
119 | *pNumPages = cPages;
|
---|
120 | for (UINT i = 0, j = iFirstPage; i < cPages; ++i, ++j)
|
---|
121 | {
|
---|
122 | pPrivate->aLockPageIndices[i] = j;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | }
|
---|
127 |
|
---|
128 | fLockFlags.ReadOnly = fFlags.bReadOnly;
|
---|
129 | fLockFlags.WriteOnly = fFlags.bWriteOnly;
|
---|
130 | fLockFlags.DonotWait = fFlags.bDonotWait;
|
---|
131 | // fLockFlags.Discard = fFlags.bDiscard;
|
---|
132 | *pfFlags = fLockFlags;
|
---|
133 | return VINF_SUCCESS;
|
---|
134 | }
|
---|
135 |
|
---|
136 | DECLINLINE(void) vboxUhgsmiBaseDxAllocInfoFill(D3DDDI_ALLOCATIONINFO *pDdiAllocInfo, VBOXWDDM_ALLOCINFO *pAllocInfo,
|
---|
137 | uint32_t cbBuffer, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType)
|
---|
138 | {
|
---|
139 | memset(pDdiAllocInfo, 0, sizeof (*pDdiAllocInfo));
|
---|
140 | pDdiAllocInfo->pPrivateDriverData = pAllocInfo;
|
---|
141 | pDdiAllocInfo->PrivateDriverDataSize = sizeof (*pAllocInfo);
|
---|
142 | memset(pAllocInfo, 0, sizeof (*pAllocInfo));
|
---|
143 | pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_HGSMI_BUFFER;
|
---|
144 | pAllocInfo->cbBuffer = cbBuffer;
|
---|
145 | pAllocInfo->fUhgsmiType = fUhgsmiType;
|
---|
146 | }
|
---|
147 |
|
---|
148 | DECLINLINE(int) vboxUhgsmiBaseDxDmaFill(PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers,
|
---|
149 | VOID *pCommandBuffer, UINT *pCommandBufferSize,
|
---|
150 | D3DDDI_ALLOCATIONLIST *pAllocationList, UINT AllocationListSize,
|
---|
151 | D3DDDI_PATCHLOCATIONLIST *pPatchLocationList, UINT PatchLocationListSize)
|
---|
152 | {
|
---|
153 | const uint32_t cbDmaCmd = RT_OFFSETOF(VBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD, aBufInfos[cBuffers]);
|
---|
154 | RT_NOREF(pPatchLocationList, PatchLocationListSize);
|
---|
155 |
|
---|
156 | AssertReturn(*pCommandBufferSize >= cbDmaCmd, VERR_GENERAL_FAILURE);
|
---|
157 | AssertReturn(AllocationListSize >= cBuffers, VERR_GENERAL_FAILURE);
|
---|
158 |
|
---|
159 | *pCommandBufferSize = cbDmaCmd;
|
---|
160 |
|
---|
161 | PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD pHdr = (PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD)pCommandBuffer;
|
---|
162 | pHdr->Base.enmCmd = VBOXVDMACMD_TYPE_CHROMIUM_CMD;
|
---|
163 | pHdr->Base.u32CmdReserved = 0;
|
---|
164 |
|
---|
165 | PVBOXWDDM_UHGSMI_BUFFER_UI_SUBMIT_INFO pBufSubmInfo = pHdr->aBufInfos;
|
---|
166 |
|
---|
167 | for (uint32_t i = 0; i < cBuffers; ++i)
|
---|
168 | {
|
---|
169 | PVBOXUHGSMI_BUFFER_SUBMIT pBufInfo = &aBuffers[i];
|
---|
170 | PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pBuffer = VBOXUHGSMDXALLOCBASE_GET_BUFFER(pBufInfo->pBuf);
|
---|
171 |
|
---|
172 | memset(pAllocationList, 0, sizeof (D3DDDI_ALLOCATIONLIST));
|
---|
173 | pAllocationList->hAllocation = pBuffer->hAllocation;
|
---|
174 | pAllocationList->Value = 0;
|
---|
175 | pAllocationList->WriteOperation = !pBufInfo->fFlags.bHostReadOnly;
|
---|
176 | pAllocationList->DoNotRetireInstance = pBufInfo->fFlags.bDoNotRetire;
|
---|
177 | if (pBufInfo->fFlags.bEntireBuffer)
|
---|
178 | {
|
---|
179 | pBufSubmInfo->offData = 0;
|
---|
180 | pBufSubmInfo->cbData = pBuffer->BasePrivate.Base.cbBuffer;
|
---|
181 | }
|
---|
182 | else
|
---|
183 | {
|
---|
184 | pBufSubmInfo->offData = pBufInfo->offData;
|
---|
185 | pBufSubmInfo->cbData = pBufInfo->cbData;
|
---|
186 | }
|
---|
187 |
|
---|
188 | ++pAllocationList;
|
---|
189 | ++pBufSubmInfo;
|
---|
190 | }
|
---|
191 |
|
---|
192 | return VINF_SUCCESS;
|
---|
193 | }
|
---|
194 |
|
---|
195 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock);
|
---|
196 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferUnlock(PVBOXUHGSMI_BUFFER pBuf);
|
---|
197 | int vboxUhgsmiBaseBufferTerm(PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE pBuffer);
|
---|
198 | static int vboxUhgsmiBaseEventChkCreate(VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, HANDLE *phSynch);
|
---|
199 | int vboxUhgsmiKmtEscBufferInit(PVBOXUHGSMI_PRIVATE_BASE pPrivate, PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE pBuffer, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, PFNVBOXUHGSMI_BUFFER_DESTROY pfnDestroy);
|
---|
200 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferSubmit(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers);
|
---|
201 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferDestroy(PVBOXUHGSMI_BUFFER pBuf);
|
---|
202 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, PVBOXUHGSMI_BUFFER* ppBuf);
|
---|
203 |
|
---|
204 | DECLINLINE(void) vboxUhgsmiBaseInit(PVBOXUHGSMI_PRIVATE_BASE pHgsmi, PFNVBOXCRHGSMI_ESCAPE pfnEscape)
|
---|
205 | {
|
---|
206 | pHgsmi->Base.pfnBufferCreate = vboxUhgsmiBaseEscBufferCreate;
|
---|
207 | pHgsmi->Base.pfnBufferSubmit = vboxUhgsmiBaseEscBufferSubmit;
|
---|
208 | pHgsmi->pfnEscape = pfnEscape;
|
---|
209 | }
|
---|
210 |
|
---|
211 | #endif /* #ifndef ___VBoxUhgsmiBase_h__ */
|
---|