1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxVideo Display D3D User mode dll
|
---|
4 | *
|
---|
5 | * Copyright (C) 2010 Oracle Corporation
|
---|
6 | *
|
---|
7 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | * available from http://www.virtualbox.org. This file is free software;
|
---|
9 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | * General Public License (GPL) as published by the Free Software
|
---|
11 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | */
|
---|
15 | #include "VBoxDispD3DCmn.h"
|
---|
16 |
|
---|
17 | #include <iprt/mem.h>
|
---|
18 | #include <iprt/err.h>
|
---|
19 |
|
---|
20 | typedef struct VBOXUHGSMI_BUFFER_PRIVATE_KMT
|
---|
21 | {
|
---|
22 | VBOXUHGSMI_BUFFER_PRIVATE_BASE BasePrivate;
|
---|
23 | PVBOXUHGSMI_PRIVATE_KMT pHgsmi;
|
---|
24 | CRITICAL_SECTION CritSect;
|
---|
25 | UINT aLockPageIndices[1];
|
---|
26 | } VBOXUHGSMI_BUFFER_PRIVATE_KMT, *PVBOXUHGSMI_BUFFER_PRIVATE_KMT;
|
---|
27 |
|
---|
28 | typedef struct VBOXUHGSMI_BUFFER_PRIVATE_KMT_ESC
|
---|
29 | {
|
---|
30 | VBOXUHGSMI_BUFFER Base;
|
---|
31 | PVBOXUHGSMI_PRIVATE_KMT pHgsmi;
|
---|
32 | VBOXVIDEOCM_UM_ALLOC Alloc;
|
---|
33 | } VBOXUHGSMI_BUFFER_PRIVATE_KMT_ESC, *PVBOXUHGSMI_BUFFER_PRIVATE_KMT_ESC;
|
---|
34 |
|
---|
35 | #define VBOXUHGSMIKMT_GET_BUFFER(_p) VBOXUHGSMIKMT_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_KMT)
|
---|
36 | #define VBOXUHGSMIKMTESC_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, Base)))
|
---|
37 | #define VBOXUHGSMIKMTESC_GET_BUFFER(_p) VBOXUHGSMIKMTESC_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_KMT_ESC)
|
---|
38 |
|
---|
39 | DECLCALLBACK(int) vboxUhgsmiKmtBufferDestroy(PVBOXUHGSMI_BUFFER pBuf)
|
---|
40 | {
|
---|
41 | PVBOXUHGSMI_BUFFER_PRIVATE_KMT pBuffer = VBOXUHGSMIKMT_GET_BUFFER(pBuf);
|
---|
42 | D3DKMT_DESTROYALLOCATION DdiDealloc;
|
---|
43 | DdiDealloc.hDevice = pBuffer->pHgsmi->Device.hDevice;
|
---|
44 | DdiDealloc.hResource = NULL;
|
---|
45 | DdiDealloc.phAllocationList = &pBuffer->BasePrivate.hAllocation;
|
---|
46 | DdiDealloc.AllocationCount = 1;
|
---|
47 | NTSTATUS Status = pBuffer->pHgsmi->Callbacks.pfnD3DKMTDestroyAllocation(&DdiDealloc);
|
---|
48 | Assert(!Status);
|
---|
49 | if (!Status)
|
---|
50 | {
|
---|
51 | if (pBuffer->BasePrivate.Base.bSynchCreated)
|
---|
52 | {
|
---|
53 | CloseHandle(pBuffer->BasePrivate.Base.hSynch);
|
---|
54 | }
|
---|
55 | RTMemFree(pBuffer);
|
---|
56 | return VINF_SUCCESS;
|
---|
57 | }
|
---|
58 | return VERR_GENERAL_FAILURE;
|
---|
59 | }
|
---|
60 |
|
---|
61 | DECLCALLBACK(int) vboxUhgsmiKmtBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock)
|
---|
62 | {
|
---|
63 | PVBOXUHGSMI_BUFFER_PRIVATE_KMT pBuffer = VBOXUHGSMIKMT_GET_BUFFER(pBuf);
|
---|
64 | D3DKMT_LOCK DdiLock = {0};
|
---|
65 | DdiLock.hDevice = pBuffer->pHgsmi->Device.hDevice;
|
---|
66 | DdiLock.hAllocation = pBuffer->BasePrivate.hAllocation;
|
---|
67 | DdiLock.PrivateDriverData = NULL;
|
---|
68 |
|
---|
69 | EnterCriticalSection(&pBuffer->CritSect);
|
---|
70 |
|
---|
71 | int rc = vboxUhgsmiBaseLockData(pBuf, offLock, cbLock, fFlags,
|
---|
72 | &DdiLock.Flags, &DdiLock.NumPages, pBuffer->aLockPageIndices);
|
---|
73 | AssertRC(rc);
|
---|
74 | if (RT_FAILURE(rc))
|
---|
75 | return rc;
|
---|
76 |
|
---|
77 | if (DdiLock.NumPages)
|
---|
78 | DdiLock.pPages = pBuffer->aLockPageIndices;
|
---|
79 | else
|
---|
80 | DdiLock.pPages = NULL;
|
---|
81 |
|
---|
82 | NTSTATUS Status = pBuffer->pHgsmi->Callbacks.pfnD3DKMTLock(&DdiLock);
|
---|
83 | Assert(!Status);
|
---|
84 | LeaveCriticalSection(&pBuffer->CritSect);
|
---|
85 | if (!Status)
|
---|
86 | {
|
---|
87 | *pvLock = (void*)(((uint8_t*)DdiLock.pData) + (offLock & 0xfff));
|
---|
88 | return VINF_SUCCESS;
|
---|
89 | }
|
---|
90 | return VERR_GENERAL_FAILURE;
|
---|
91 | }
|
---|
92 |
|
---|
93 | DECLCALLBACK(int) vboxUhgsmiKmtBufferUnlock(PVBOXUHGSMI_BUFFER pBuf)
|
---|
94 | {
|
---|
95 | PVBOXUHGSMI_BUFFER_PRIVATE_KMT pBuffer = VBOXUHGSMIKMT_GET_BUFFER(pBuf);
|
---|
96 | D3DKMT_UNLOCK DdiUnlock;
|
---|
97 |
|
---|
98 | DdiUnlock.hDevice = pBuffer->pHgsmi->Device.hDevice;
|
---|
99 | DdiUnlock.NumAllocations = 1;
|
---|
100 | DdiUnlock.phAllocations = &pBuffer->BasePrivate.hAllocation;
|
---|
101 | NTSTATUS Status = pBuffer->pHgsmi->Callbacks.pfnD3DKMTUnlock(&DdiUnlock);
|
---|
102 | Assert(!Status);
|
---|
103 | if (!Status)
|
---|
104 | return VINF_SUCCESS;
|
---|
105 | return VERR_GENERAL_FAILURE;
|
---|
106 | }
|
---|
107 |
|
---|
108 | DECLCALLBACK(int) vboxUhgsmiKmtBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf,
|
---|
109 | VBOXUHGSMI_SYNCHOBJECT_TYPE enmSynchType, HVBOXUHGSMI_SYNCHOBJECT hSynch,
|
---|
110 | PVBOXUHGSMI_BUFFER* ppBuf)
|
---|
111 | {
|
---|
112 | bool bSynchCreated = false;
|
---|
113 | if (!cbBuf)
|
---|
114 | return VERR_INVALID_PARAMETER;
|
---|
115 |
|
---|
116 | int rc = vboxUhgsmiBaseEventChkCreate(enmSynchType, &hSynch, &bSynchCreated);
|
---|
117 | AssertRC(rc);
|
---|
118 | if (RT_FAILURE(rc))
|
---|
119 | return rc;
|
---|
120 |
|
---|
121 | cbBuf = VBOXWDDM_ROUNDBOUND(cbBuf, 0x1000);
|
---|
122 | Assert(cbBuf);
|
---|
123 | uint32_t cPages = cbBuf >> 12;
|
---|
124 | Assert(cPages);
|
---|
125 |
|
---|
126 | PVBOXUHGSMI_PRIVATE_KMT pPrivate = VBOXUHGSMIKMT_GET(pHgsmi);
|
---|
127 | PVBOXUHGSMI_BUFFER_PRIVATE_KMT pBuf = (PVBOXUHGSMI_BUFFER_PRIVATE_KMT)RTMemAllocZ(RT_OFFSETOF(VBOXUHGSMI_BUFFER_PRIVATE_KMT, aLockPageIndices[cPages]));
|
---|
128 | Assert(pBuf);
|
---|
129 | if (pBuf)
|
---|
130 | {
|
---|
131 | struct
|
---|
132 | {
|
---|
133 | D3DKMT_CREATEALLOCATION DdiAlloc;
|
---|
134 | D3DDDI_ALLOCATIONINFO DdiAllocInfo;
|
---|
135 | VBOXWDDM_ALLOCINFO AllocInfo;
|
---|
136 | } Buf;
|
---|
137 | memset(&Buf, 0, sizeof (Buf));
|
---|
138 | Buf.DdiAlloc.hDevice = pPrivate->Device.hDevice;
|
---|
139 | Buf.DdiAlloc.NumAllocations = 1;
|
---|
140 | Buf.DdiAlloc.pAllocationInfo = &Buf.DdiAllocInfo;
|
---|
141 | Buf.DdiAllocInfo.pPrivateDriverData = &Buf.AllocInfo;
|
---|
142 | Buf.DdiAllocInfo.PrivateDriverDataSize = sizeof (Buf.AllocInfo);
|
---|
143 | Buf.AllocInfo.enmType = VBOXWDDM_ALLOC_TYPE_UMD_HGSMI_BUFFER;
|
---|
144 | Buf.AllocInfo.cbBuffer = cbBuf;
|
---|
145 | Buf.AllocInfo.hSynch = (uint64_t)hSynch;
|
---|
146 | Buf.AllocInfo.enmSynchType = enmSynchType;
|
---|
147 |
|
---|
148 | HRESULT hr = pPrivate->Callbacks.pfnD3DKMTCreateAllocation(&Buf.DdiAlloc);
|
---|
149 | Assert(hr == S_OK);
|
---|
150 | if (hr == S_OK)
|
---|
151 | {
|
---|
152 | InitializeCriticalSection(&pBuf->CritSect);
|
---|
153 |
|
---|
154 | Assert(Buf.DdiAllocInfo.hAllocation);
|
---|
155 | pBuf->BasePrivate.Base.pfnLock = vboxUhgsmiKmtBufferLock;
|
---|
156 | pBuf->BasePrivate.Base.pfnUnlock = vboxUhgsmiKmtBufferUnlock;
|
---|
157 | // pBuf->Base.pfnAdjustValidDataRange = vboxUhgsmiKmtBufferAdjustValidDataRange;
|
---|
158 | pBuf->BasePrivate.Base.pfnDestroy = vboxUhgsmiKmtBufferDestroy;
|
---|
159 |
|
---|
160 | pBuf->BasePrivate.Base.hSynch = hSynch;
|
---|
161 | pBuf->BasePrivate.Base.enmSynchType = enmSynchType;
|
---|
162 | pBuf->BasePrivate.Base.cbBuffer = cbBuf;
|
---|
163 | pBuf->BasePrivate.Base.bSynchCreated = bSynchCreated;
|
---|
164 |
|
---|
165 | pBuf->pHgsmi = pPrivate;
|
---|
166 | pBuf->BasePrivate.hAllocation = Buf.DdiAllocInfo.hAllocation;
|
---|
167 |
|
---|
168 | *ppBuf = &pBuf->BasePrivate.Base;
|
---|
169 |
|
---|
170 | return VINF_SUCCESS;
|
---|
171 | }
|
---|
172 | else
|
---|
173 | {
|
---|
174 | rc = VERR_OUT_OF_RESOURCES;
|
---|
175 | }
|
---|
176 |
|
---|
177 | RTMemFree(pBuf);
|
---|
178 | }
|
---|
179 | else
|
---|
180 | rc = VERR_NO_MEMORY;
|
---|
181 |
|
---|
182 | if (bSynchCreated)
|
---|
183 | CloseHandle(hSynch);
|
---|
184 |
|
---|
185 | return rc;
|
---|
186 | }
|
---|
187 |
|
---|
188 | DECLCALLBACK(int) vboxUhgsmiKmtBufferSubmitAsynch(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers)
|
---|
189 | {
|
---|
190 | PVBOXUHGSMI_PRIVATE_KMT pHg = VBOXUHGSMIKMT_GET(pHgsmi);
|
---|
191 | UINT cbDmaCmd = pHg->Context.CommandBufferSize;
|
---|
192 | int rc = vboxUhgsmiBaseDmaFill(aBuffers, cBuffers,
|
---|
193 | pHg->Context.pCommandBuffer, &cbDmaCmd,
|
---|
194 | pHg->Context.pAllocationList, pHg->Context.AllocationListSize,
|
---|
195 | pHg->Context.pPatchLocationList, pHg->Context.PatchLocationListSize);
|
---|
196 | AssertRC(rc);
|
---|
197 | if (RT_FAILURE(rc))
|
---|
198 | return rc;
|
---|
199 |
|
---|
200 | D3DKMT_RENDER DdiRender = {0};
|
---|
201 | DdiRender.hContext = pHg->Context.hContext;
|
---|
202 | DdiRender.CommandLength = cbDmaCmd;
|
---|
203 | DdiRender.AllocationCount = cBuffers;
|
---|
204 | Assert(DdiRender.CommandLength);
|
---|
205 | Assert(DdiRender.CommandLength < UINT32_MAX/2);
|
---|
206 |
|
---|
207 | HRESULT hr = pHg->Callbacks.pfnD3DKMTRender(&DdiRender);
|
---|
208 | Assert(hr == S_OK);
|
---|
209 | if (hr == S_OK)
|
---|
210 | {
|
---|
211 | pHg->Context.CommandBufferSize = DdiRender.NewCommandBufferSize;
|
---|
212 | pHg->Context.pCommandBuffer = DdiRender.pNewCommandBuffer;
|
---|
213 | pHg->Context.AllocationListSize = DdiRender.NewAllocationListSize;
|
---|
214 | pHg->Context.pAllocationList = DdiRender.pNewAllocationList;
|
---|
215 | pHg->Context.PatchLocationListSize = DdiRender.NewPatchLocationListSize;
|
---|
216 | pHg->Context.pPatchLocationList = DdiRender.pNewPatchLocationList;
|
---|
217 |
|
---|
218 | return VINF_SUCCESS;
|
---|
219 | }
|
---|
220 |
|
---|
221 | return VERR_GENERAL_FAILURE;
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 | DECLCALLBACK(int) vboxUhgsmiKmtEscBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock)
|
---|
226 | {
|
---|
227 | PVBOXUHGSMI_BUFFER_PRIVATE_KMT_ESC pBuffer = VBOXUHGSMIKMTESC_GET_BUFFER(pBuf);
|
---|
228 | *pvLock = (void*)(pBuffer->Alloc.pvData + offLock);
|
---|
229 | return VINF_SUCCESS;
|
---|
230 | }
|
---|
231 |
|
---|
232 | DECLCALLBACK(int) vboxUhgsmiKmtEscBufferUnlock(PVBOXUHGSMI_BUFFER pBuf)
|
---|
233 | {
|
---|
234 | return VINF_SUCCESS;
|
---|
235 | }
|
---|
236 |
|
---|
237 | DECLCALLBACK(int) vboxUhgsmiKmtEscBufferDestroy(PVBOXUHGSMI_BUFFER pBuf)
|
---|
238 | {
|
---|
239 | PVBOXUHGSMI_BUFFER_PRIVATE_KMT_ESC pBuffer = VBOXUHGSMIKMTESC_GET_BUFFER(pBuf);
|
---|
240 | PVBOXUHGSMI_PRIVATE_KMT pPrivate = pBuffer->pHgsmi;
|
---|
241 | D3DKMT_ESCAPE DdiEscape = {0};
|
---|
242 | VBOXDISPIFESCAPE_UHGSMI_DEALLOCATE DeallocInfo = {0};
|
---|
243 | DdiEscape.hAdapter = pPrivate->Adapter.hAdapter;
|
---|
244 | DdiEscape.hDevice = pPrivate->Device.hDevice;
|
---|
245 | DdiEscape.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
|
---|
246 | //Buf.DdiEscape.Flags.HardwareAccess = 1;
|
---|
247 | DdiEscape.pPrivateDriverData = &DeallocInfo;
|
---|
248 | DdiEscape.PrivateDriverDataSize = sizeof (DeallocInfo);
|
---|
249 | DdiEscape.hContext = pPrivate->Context.hContext;
|
---|
250 |
|
---|
251 | DeallocInfo.EscapeHdr.escapeCode = VBOXESC_UHGSMI_DEALLOCATE;
|
---|
252 | DeallocInfo.hAlloc = pBuffer->Alloc.hAlloc;
|
---|
253 |
|
---|
254 | HRESULT hr = pPrivate->Callbacks.pfnD3DKMTEscape(&DdiEscape);
|
---|
255 | Assert(hr == S_OK);
|
---|
256 | if (hr == S_OK)
|
---|
257 | {
|
---|
258 | if (pBuffer->Base.bSynchCreated)
|
---|
259 | {
|
---|
260 | CloseHandle(pBuffer->Base.hSynch);
|
---|
261 | }
|
---|
262 | RTMemFree(pBuffer);
|
---|
263 | return VINF_SUCCESS;
|
---|
264 | }
|
---|
265 |
|
---|
266 | return VERR_GENERAL_FAILURE;
|
---|
267 | }
|
---|
268 |
|
---|
269 | DECLCALLBACK(int) vboxUhgsmiKmtEscBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf,
|
---|
270 | VBOXUHGSMI_SYNCHOBJECT_TYPE enmSynchType, HVBOXUHGSMI_SYNCHOBJECT hSynch,
|
---|
271 | PVBOXUHGSMI_BUFFER* ppBuf)
|
---|
272 | {
|
---|
273 | bool bSynchCreated = false;
|
---|
274 | if (!cbBuf)
|
---|
275 | return VERR_INVALID_PARAMETER;
|
---|
276 |
|
---|
277 | int rc = vboxUhgsmiBaseEventChkCreate(enmSynchType, &hSynch, &bSynchCreated);
|
---|
278 | AssertRC(rc);
|
---|
279 | if (RT_FAILURE(rc))
|
---|
280 | return rc;
|
---|
281 |
|
---|
282 | cbBuf = VBOXWDDM_ROUNDBOUND(cbBuf, 0x1000);
|
---|
283 | Assert(cbBuf);
|
---|
284 | uint32_t cPages = cbBuf >> 12;
|
---|
285 | Assert(cPages);
|
---|
286 |
|
---|
287 | PVBOXUHGSMI_PRIVATE_KMT pPrivate = VBOXUHGSMIKMT_GET(pHgsmi);
|
---|
288 | PVBOXUHGSMI_BUFFER_PRIVATE_KMT_ESC pBuf = (PVBOXUHGSMI_BUFFER_PRIVATE_KMT_ESC)RTMemAllocZ(RT_OFFSETOF(VBOXUHGSMI_BUFFER_PRIVATE_KMT, aLockPageIndices[cPages]));
|
---|
289 | Assert(pBuf);
|
---|
290 | if (pBuf)
|
---|
291 | {
|
---|
292 | struct
|
---|
293 | {
|
---|
294 | D3DKMT_ESCAPE DdiEscape;
|
---|
295 | VBOXDISPIFESCAPE_UHGSMI_ALLOCATE AllocInfo;
|
---|
296 | } Buf;
|
---|
297 | memset(&Buf, 0, sizeof (Buf));
|
---|
298 | Buf.DdiEscape.hAdapter = pPrivate->Adapter.hAdapter;
|
---|
299 | Buf.DdiEscape.hDevice = pPrivate->Device.hDevice;
|
---|
300 | Buf.DdiEscape.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
|
---|
301 | //Buf.DdiEscape.Flags.HardwareAccess = 1;
|
---|
302 | Buf.DdiEscape.pPrivateDriverData = &Buf.AllocInfo;
|
---|
303 | Buf.DdiEscape.PrivateDriverDataSize = sizeof (Buf.AllocInfo);
|
---|
304 | Buf.DdiEscape.hContext = pPrivate->Context.hContext;
|
---|
305 |
|
---|
306 | Buf.AllocInfo.EscapeHdr.escapeCode = VBOXESC_UHGSMI_ALLOCATE;
|
---|
307 | Buf.AllocInfo.Alloc.cbData = cbBuf;
|
---|
308 | Buf.AllocInfo.Alloc.hSynch = (uint64_t)hSynch;
|
---|
309 | Buf.AllocInfo.Alloc.enmSynchType = enmSynchType;
|
---|
310 |
|
---|
311 | HRESULT hr = pPrivate->Callbacks.pfnD3DKMTEscape(&Buf.DdiEscape);
|
---|
312 | Assert(hr == S_OK);
|
---|
313 | if (hr == S_OK)
|
---|
314 | {
|
---|
315 | pBuf->Alloc = Buf.AllocInfo.Alloc;
|
---|
316 | Assert(pBuf->Alloc.pvData);
|
---|
317 | pBuf->pHgsmi = pPrivate;
|
---|
318 | pBuf->Base.pfnLock = vboxUhgsmiKmtEscBufferLock;
|
---|
319 | pBuf->Base.pfnUnlock = vboxUhgsmiKmtEscBufferUnlock;
|
---|
320 | // pBuf->Base.pfnAdjustValidDataRange = vboxUhgsmiKmtBufferAdjustValidDataRange;
|
---|
321 | pBuf->Base.pfnDestroy = vboxUhgsmiKmtEscBufferDestroy;
|
---|
322 |
|
---|
323 | pBuf->Base.hSynch = hSynch;
|
---|
324 | pBuf->Base.enmSynchType = enmSynchType;
|
---|
325 | pBuf->Base.cbBuffer = Buf.AllocInfo.Alloc.cbData;
|
---|
326 | pBuf->Base.bSynchCreated = bSynchCreated;
|
---|
327 |
|
---|
328 | *ppBuf = &pBuf->Base;
|
---|
329 |
|
---|
330 | return VINF_SUCCESS;
|
---|
331 | }
|
---|
332 | else
|
---|
333 | {
|
---|
334 | rc = VERR_OUT_OF_RESOURCES;
|
---|
335 | }
|
---|
336 |
|
---|
337 | RTMemFree(pBuf);
|
---|
338 | }
|
---|
339 | else
|
---|
340 | rc = VERR_NO_MEMORY;
|
---|
341 |
|
---|
342 | if (bSynchCreated)
|
---|
343 | CloseHandle(hSynch);
|
---|
344 |
|
---|
345 | return rc;
|
---|
346 | }
|
---|
347 |
|
---|
348 | DECLCALLBACK(int) vboxUhgsmiKmtEscBufferSubmitAsynch(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers)
|
---|
349 | {
|
---|
350 | /* we no chromium will not submit more than three buffers actually,
|
---|
351 | * for simplicity allocate it statically on the stack */
|
---|
352 | struct
|
---|
353 | {
|
---|
354 | VBOXDISPIFESCAPE_UHGSMI_SUBMIT SubmitInfo;
|
---|
355 | VBOXWDDM_UHGSMI_BUFFER_UI_INFO_ESCAPE aBufInfos[3];
|
---|
356 | } Buf;
|
---|
357 |
|
---|
358 | if (cBuffers > RT_ELEMENTS(Buf.aBufInfos) + 1)
|
---|
359 | {
|
---|
360 | Assert(0);
|
---|
361 | return VERR_INVALID_PARAMETER;
|
---|
362 | }
|
---|
363 |
|
---|
364 |
|
---|
365 | PVBOXUHGSMI_PRIVATE_KMT pPrivate = VBOXUHGSMIKMT_GET(pHgsmi);
|
---|
366 | D3DKMT_ESCAPE DdiEscape = {0};
|
---|
367 |
|
---|
368 | DdiEscape.hAdapter = pPrivate->Adapter.hAdapter;
|
---|
369 | DdiEscape.hDevice = pPrivate->Device.hDevice;
|
---|
370 | DdiEscape.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
|
---|
371 | //Buf.DdiEscape.Flags.HardwareAccess = 1;
|
---|
372 | DdiEscape.pPrivateDriverData = &Buf.SubmitInfo;
|
---|
373 | DdiEscape.PrivateDriverDataSize = RT_OFFSETOF(VBOXDISPIFESCAPE_UHGSMI_SUBMIT, aBuffers[cBuffers]);
|
---|
374 | DdiEscape.hContext = pPrivate->Context.hContext;
|
---|
375 |
|
---|
376 | Buf.SubmitInfo.EscapeHdr.escapeCode = VBOXESC_UHGSMI_SUBMIT;
|
---|
377 | Buf.SubmitInfo.EscapeHdr.u32CmdSpecific = cBuffers;
|
---|
378 | for (UINT i = 0; i < cBuffers; ++i)
|
---|
379 | {
|
---|
380 | VBOXWDDM_UHGSMI_BUFFER_UI_INFO_ESCAPE *pSubmInfo = &Buf.SubmitInfo.aBuffers[i];
|
---|
381 | PVBOXUHGSMI_BUFFER_SUBMIT pBufInfo = &aBuffers[i];
|
---|
382 | PVBOXUHGSMI_BUFFER_PRIVATE_KMT_ESC pBuf = VBOXUHGSMIKMTESC_GET_BUFFER(pBufInfo->pBuf);
|
---|
383 | pSubmInfo->hAlloc = pBuf->Alloc.hAlloc;
|
---|
384 | pSubmInfo->Info.fSubFlags = pBufInfo->fFlags;
|
---|
385 | if (pBufInfo->fFlags.bEntireBuffer)
|
---|
386 | {
|
---|
387 | pSubmInfo->Info.offData = 0;
|
---|
388 | pSubmInfo->Info.cbData = pBuf->Base.cbBuffer;
|
---|
389 | }
|
---|
390 | else
|
---|
391 | {
|
---|
392 | pSubmInfo->Info.offData = pBufInfo->offData;
|
---|
393 | pSubmInfo->Info.cbData = pBufInfo->cbData;
|
---|
394 | }
|
---|
395 | }
|
---|
396 |
|
---|
397 | HRESULT hr = pPrivate->Callbacks.pfnD3DKMTEscape(&DdiEscape);
|
---|
398 | Assert(hr == S_OK);
|
---|
399 | if (hr == S_OK)
|
---|
400 | {
|
---|
401 | return VINF_SUCCESS;
|
---|
402 | }
|
---|
403 |
|
---|
404 | return VERR_GENERAL_FAILURE;
|
---|
405 | }
|
---|
406 |
|
---|
407 | static HRESULT vboxUhgsmiKmtEngineCreate(PVBOXUHGSMI_PRIVATE_KMT pHgsmi, BOOL bD3D)
|
---|
408 | {
|
---|
409 | HRESULT hr = vboxDispKmtCallbacksInit(&pHgsmi->Callbacks);
|
---|
410 | Assert(hr == S_OK);
|
---|
411 | if (hr == S_OK)
|
---|
412 | {
|
---|
413 | hr = vboxDispKmtOpenAdapter(&pHgsmi->Callbacks, &pHgsmi->Adapter);
|
---|
414 | #ifdef DEBUG_misha
|
---|
415 | /* may fail with xpdm driver */
|
---|
416 | Assert(hr == S_OK);
|
---|
417 | #endif
|
---|
418 | if (hr == S_OK)
|
---|
419 | {
|
---|
420 | hr = vboxDispKmtCreateDevice(&pHgsmi->Adapter, &pHgsmi->Device);
|
---|
421 | Assert(hr == S_OK);
|
---|
422 | if (hr == S_OK)
|
---|
423 | {
|
---|
424 | hr = vboxDispKmtCreateContext(&pHgsmi->Device, &pHgsmi->Context,
|
---|
425 | bD3D ? VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_3D : VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_GL,
|
---|
426 | NULL, 0);
|
---|
427 | Assert(hr == S_OK);
|
---|
428 | if (hr == S_OK)
|
---|
429 | {
|
---|
430 | return S_OK;
|
---|
431 | }
|
---|
432 | vboxDispKmtDestroyDevice(&pHgsmi->Device);
|
---|
433 | }
|
---|
434 | vboxDispKmtCloseAdapter(&pHgsmi->Adapter);
|
---|
435 | }
|
---|
436 | vboxDispKmtCallbacksTerm(&pHgsmi->Callbacks);
|
---|
437 | }
|
---|
438 | return hr;
|
---|
439 | }
|
---|
440 | HRESULT vboxUhgsmiKmtCreate(PVBOXUHGSMI_PRIVATE_KMT pHgsmi, BOOL bD3D)
|
---|
441 | {
|
---|
442 | pHgsmi->BasePrivate.Base.pfnBufferCreate = vboxUhgsmiKmtBufferCreate;
|
---|
443 | pHgsmi->BasePrivate.Base.pfnBufferSubmitAsynch = vboxUhgsmiKmtBufferSubmitAsynch;
|
---|
444 | #ifdef VBOX_CRHGSMI_WITH_D3DDEV
|
---|
445 | pHgsmi->BasePrivate.hClient = NULL;
|
---|
446 | #endif
|
---|
447 | return vboxUhgsmiKmtEngineCreate(pHgsmi, bD3D);
|
---|
448 | }
|
---|
449 |
|
---|
450 | HRESULT vboxUhgsmiKmtEscCreate(PVBOXUHGSMI_PRIVATE_KMT pHgsmi, BOOL bD3D)
|
---|
451 | {
|
---|
452 | pHgsmi->BasePrivate.Base.pfnBufferCreate = vboxUhgsmiKmtEscBufferCreate;
|
---|
453 | pHgsmi->BasePrivate.Base.pfnBufferSubmitAsynch = vboxUhgsmiKmtEscBufferSubmitAsynch;
|
---|
454 | #ifdef VBOX_CRHGSMI_WITH_D3DDEV
|
---|
455 | pHgsmi->BasePrivate.hClient = NULL;
|
---|
456 | #endif
|
---|
457 | return vboxUhgsmiKmtEngineCreate(pHgsmi, bD3D);
|
---|
458 | }
|
---|
459 |
|
---|
460 | HRESULT vboxUhgsmiKmtDestroy(PVBOXUHGSMI_PRIVATE_KMT pHgsmi)
|
---|
461 | {
|
---|
462 | HRESULT hr = vboxDispKmtDestroyContext(&pHgsmi->Context);
|
---|
463 | Assert(hr == S_OK);
|
---|
464 | if (hr == S_OK)
|
---|
465 | {
|
---|
466 | hr = vboxDispKmtDestroyDevice(&pHgsmi->Device);
|
---|
467 | Assert(hr == S_OK);
|
---|
468 | if (hr == S_OK)
|
---|
469 | {
|
---|
470 | hr = vboxDispKmtCloseAdapter(&pHgsmi->Adapter);
|
---|
471 | Assert(hr == S_OK);
|
---|
472 | if (hr == S_OK)
|
---|
473 | {
|
---|
474 | hr = vboxDispKmtCallbacksTerm(&pHgsmi->Callbacks);
|
---|
475 | Assert(hr == S_OK);
|
---|
476 | if (hr == S_OK)
|
---|
477 | return S_OK;
|
---|
478 | }
|
---|
479 | }
|
---|
480 | }
|
---|
481 | return hr;
|
---|
482 | }
|
---|