VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVdma.cpp@ 32823

Last change on this file since 32823 was 32823, checked in by vboxsync, 14 years ago

wddm/2d: 2D video accel support fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 56.5 KB
Line 
1/*
2 * Copyright (C) 2010 Oracle Corporation
3 *
4 * This file is part of VirtualBox Open Source Edition (OSE), as
5 * available from http://www.virtualbox.org. This file is free software;
6 * you can redistribute it and/or modify it under the terms of the GNU
7 * General Public License (GPL) as published by the Free Software
8 * Foundation, in version 2 as it comes in the "COPYING" file of the
9 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
10 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
11 */
12
13#include "../VBoxVideo.h"
14#include "../Helper.h"
15
16#include <VBox/VBoxGuestLib.h>
17#include <VBox/VBoxVideo.h>
18#include "VBoxVideoVdma.h"
19#include "../VBoxVideo.h"
20
21#include <iprt/asm.h>
22
23NTSTATUS vboxVdmaPipeConstruct(PVBOXVDMAPIPE pPipe)
24{
25 KeInitializeSpinLock(&pPipe->SinchLock);
26 KeInitializeEvent(&pPipe->Event, SynchronizationEvent, FALSE);
27 InitializeListHead(&pPipe->CmdListHead);
28 pPipe->enmState = VBOXVDMAPIPE_STATE_CREATED;
29 pPipe->bNeedNotify = true;
30 return STATUS_SUCCESS;
31}
32
33NTSTATUS vboxVdmaPipeSvrOpen(PVBOXVDMAPIPE pPipe)
34{
35 NTSTATUS Status = STATUS_SUCCESS;
36 KIRQL OldIrql;
37 KeAcquireSpinLock(&pPipe->SinchLock, &OldIrql);
38 Assert(pPipe->enmState == VBOXVDMAPIPE_STATE_CREATED);
39 switch (pPipe->enmState)
40 {
41 case VBOXVDMAPIPE_STATE_CREATED:
42 pPipe->enmState = VBOXVDMAPIPE_STATE_OPENNED;
43 pPipe->bNeedNotify = false;
44 break;
45 case VBOXVDMAPIPE_STATE_OPENNED:
46 pPipe->bNeedNotify = false;
47 break;
48 default:
49 AssertBreakpoint();
50 Status = STATUS_INVALID_PIPE_STATE;
51 break;
52 }
53
54 KeReleaseSpinLock(&pPipe->SinchLock, OldIrql);
55 return Status;
56}
57
58NTSTATUS vboxVdmaPipeSvrClose(PVBOXVDMAPIPE pPipe)
59{
60 NTSTATUS Status = STATUS_SUCCESS;
61 KIRQL OldIrql;
62 KeAcquireSpinLock(&pPipe->SinchLock, &OldIrql);
63 Assert(pPipe->enmState == VBOXVDMAPIPE_STATE_CLOSED
64 || pPipe->enmState == VBOXVDMAPIPE_STATE_CLOSING);
65 switch (pPipe->enmState)
66 {
67 case VBOXVDMAPIPE_STATE_CLOSING:
68 pPipe->enmState = VBOXVDMAPIPE_STATE_CLOSED;
69 break;
70 case VBOXVDMAPIPE_STATE_CLOSED:
71 break;
72 default:
73 AssertBreakpoint();
74 Status = STATUS_INVALID_PIPE_STATE;
75 break;
76 }
77
78 KeReleaseSpinLock(&pPipe->SinchLock, OldIrql);
79 return Status;
80}
81
82NTSTATUS vboxVdmaPipeCltClose(PVBOXVDMAPIPE pPipe)
83{
84 NTSTATUS Status = STATUS_SUCCESS;
85 KIRQL OldIrql;
86 KeAcquireSpinLock(&pPipe->SinchLock, &OldIrql);
87 bool bNeedNotify = false;
88 Assert(pPipe->enmState == VBOXVDMAPIPE_STATE_OPENNED
89 || pPipe->enmState == VBOXVDMAPIPE_STATE_CREATED
90 || pPipe->enmState == VBOXVDMAPIPE_STATE_CLOSED);
91 switch (pPipe->enmState)
92 {
93 case VBOXVDMAPIPE_STATE_OPENNED:
94 pPipe->enmState = VBOXVDMAPIPE_STATE_CLOSING;
95 bNeedNotify = pPipe->bNeedNotify;
96 pPipe->bNeedNotify = false;
97 break;
98 case VBOXVDMAPIPE_STATE_CREATED:
99 pPipe->enmState = VBOXVDMAPIPE_STATE_CLOSED;
100 pPipe->bNeedNotify = false;
101 break;
102 case VBOXVDMAPIPE_STATE_CLOSED:
103 break;
104 default:
105 AssertBreakpoint();
106 Status = STATUS_INVALID_PIPE_STATE;
107 break;
108 }
109
110 KeReleaseSpinLock(&pPipe->SinchLock, OldIrql);
111
112 if (bNeedNotify)
113 {
114 KeSetEvent(&pPipe->Event, 0, FALSE);
115 }
116 return Status;
117}
118
119NTSTATUS vboxVdmaPipeDestruct(PVBOXVDMAPIPE pPipe)
120{
121 Assert(pPipe->enmState == VBOXVDMAPIPE_STATE_CLOSED
122 || pPipe->enmState == VBOXVDMAPIPE_STATE_CREATED);
123 /* ensure the pipe is closed */
124 NTSTATUS Status = vboxVdmaPipeCltClose(pPipe);
125 Assert(Status == STATUS_SUCCESS);
126
127 Assert(pPipe->enmState == VBOXVDMAPIPE_STATE_CLOSED);
128
129 return Status;
130}
131
132NTSTATUS vboxVdmaPipeSvrCmdGetList(PVBOXVDMAPIPE pPipe, PLIST_ENTRY pDetachHead)
133{
134 PLIST_ENTRY pEntry = NULL;
135 KIRQL OldIrql;
136 NTSTATUS Status = STATUS_SUCCESS;
137 VBOXVDMAPIPE_STATE enmState = VBOXVDMAPIPE_STATE_CLOSED;
138 do
139 {
140 bool bListEmpty = true;
141 KeAcquireSpinLock(&pPipe->SinchLock, &OldIrql);
142 Assert(pPipe->enmState == VBOXVDMAPIPE_STATE_OPENNED
143 || pPipe->enmState == VBOXVDMAPIPE_STATE_CLOSING);
144 Assert(pPipe->enmState >= VBOXVDMAPIPE_STATE_OPENNED);
145 enmState = pPipe->enmState;
146 if (enmState >= VBOXVDMAPIPE_STATE_OPENNED)
147 {
148 vboxVideoLeDetach(&pPipe->CmdListHead, pDetachHead);
149 bListEmpty = !!(IsListEmpty(pDetachHead));
150 pPipe->bNeedNotify = bListEmpty;
151 }
152 else
153 {
154 KeReleaseSpinLock(&pPipe->SinchLock, OldIrql);
155 Status = STATUS_INVALID_PIPE_STATE;
156 break;
157 }
158
159 KeReleaseSpinLock(&pPipe->SinchLock, OldIrql);
160
161 if (!bListEmpty)
162 {
163 Assert(Status == STATUS_SUCCESS);
164 break;
165 }
166
167 if (enmState == VBOXVDMAPIPE_STATE_OPENNED)
168 {
169 Status = KeWaitForSingleObject(&pPipe->Event, Executive, KernelMode, FALSE, NULL /* PLARGE_INTEGER Timeout */);
170 Assert(Status == STATUS_SUCCESS);
171 if (Status != STATUS_SUCCESS)
172 break;
173 }
174 else
175 {
176 Assert(enmState == VBOXVDMAPIPE_STATE_CLOSING);
177 Status = STATUS_PIPE_CLOSING;
178 break;
179 }
180 } while (1);
181
182 return Status;
183}
184
185NTSTATUS vboxVdmaPipeCltCmdPut(PVBOXVDMAPIPE pPipe, PVBOXVDMAPIPE_CMD_HDR pCmd)
186{
187 NTSTATUS Status = STATUS_SUCCESS;
188 KIRQL OldIrql;
189 bool bNeedNotify = false;
190
191 KeAcquireSpinLock(&pPipe->SinchLock, &OldIrql);
192
193 Assert(pPipe->enmState == VBOXVDMAPIPE_STATE_OPENNED);
194 if (pPipe->enmState == VBOXVDMAPIPE_STATE_OPENNED)
195 {
196 bNeedNotify = pPipe->bNeedNotify;
197 InsertHeadList(&pPipe->CmdListHead, &pCmd->ListEntry);
198 pPipe->bNeedNotify = false;
199 }
200 else
201 Status = STATUS_INVALID_PIPE_STATE;
202
203 KeReleaseSpinLock(&pPipe->SinchLock, OldIrql);
204
205 if (bNeedNotify)
206 {
207 KeSetEvent(&pPipe->Event, 0, FALSE);
208 }
209
210 return Status;
211}
212
213PVBOXVDMAPIPE_CMD_DR vboxVdmaGgCmdCreate(PVBOXVDMAGG pVdma, VBOXVDMAPIPE_CMD_TYPE enmType, uint32_t cbCmd)
214{
215 PVBOXVDMAPIPE_CMD_DR pHdr = (PVBOXVDMAPIPE_CMD_DR)vboxWddmMemAllocZero(cbCmd);
216 Assert(pHdr);
217 if (pHdr)
218 {
219 pHdr->enmType = enmType;
220 return pHdr;
221 }
222 return NULL;
223}
224
225void vboxVdmaGgCmdDestroy(PVBOXVDMAPIPE_CMD_DR pDr)
226{
227 vboxWddmMemFree(pDr);
228}
229
230DECLCALLBACK(VOID) vboxVdmaGgDdiCmdDestroy(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext)
231{
232 vboxVdmaGgCmdDestroy((PVBOXVDMAPIPE_CMD_DR)pvContext);
233}
234
235/**
236 * helper function used for system thread creation
237 */
238static NTSTATUS vboxVdmaGgThreadCreate(PKTHREAD * ppThread, PKSTART_ROUTINE pStartRoutine, PVOID pStartContext)
239{
240 NTSTATUS fStatus;
241 HANDLE hThread;
242 OBJECT_ATTRIBUTES fObjectAttributes;
243
244 Assert(KeGetCurrentIrql() == PASSIVE_LEVEL);
245
246 InitializeObjectAttributes(&fObjectAttributes, NULL, OBJ_KERNEL_HANDLE,
247 NULL, NULL);
248
249 fStatus = PsCreateSystemThread(&hThread, THREAD_ALL_ACCESS,
250 &fObjectAttributes, NULL, NULL,
251 (PKSTART_ROUTINE) pStartRoutine, pStartContext);
252 if (!NT_SUCCESS(fStatus))
253 return fStatus;
254
255 ObReferenceObjectByHandle(hThread, THREAD_ALL_ACCESS, NULL,
256 KernelMode, (PVOID*) ppThread, NULL);
257 ZwClose(hThread);
258 return STATUS_SUCCESS;
259}
260
261DECLINLINE(void) vboxVdmaDirtyRectsCalcIntersection(const RECT *pArea, const PVBOXWDDM_RECTS_INFO pRects, PVBOXWDDM_RECTS_INFO pResult)
262{
263 uint32_t cRects = 0;
264 for (uint32_t i = 0; i < pRects->cRects; ++i)
265 {
266 if (vboxWddmRectIntersection(pArea, &pRects->aRects[i], &pResult->aRects[cRects]))
267 {
268 ++cRects;
269 }
270 }
271
272 pResult->cRects = cRects;
273}
274
275DECLINLINE(bool) vboxVdmaDirtyRectsHasIntersections(const RECT *paRects1, uint32_t cRects1, const RECT *paRects2, uint32_t cRects2)
276{
277 RECT tmpRect;
278 for (uint32_t i = 0; i < cRects1; ++i)
279 {
280 const RECT * pRect1 = &paRects1[i];
281 for (uint32_t j = 0; j < cRects2; ++j)
282 {
283 const RECT * pRect2 = &paRects2[j];
284 if (vboxWddmRectIntersection(pRect1, pRect2, &tmpRect))
285 return true;
286 }
287 }
288 return false;
289}
290
291DECLINLINE(bool) vboxVdmaDirtyRectsIsCover(const RECT *paRects, uint32_t cRects, const RECT *paRectsCovered, uint32_t cRectsCovered)
292{
293 for (uint32_t i = 0; i < cRectsCovered; ++i)
294 {
295 const RECT * pRectCovered = &paRectsCovered[i];
296 uint32_t j = 0;
297 for (; j < cRects; ++j)
298 {
299 const RECT * pRect = &paRects[j];
300 if (vboxWddmRectIsCoveres(pRect, pRectCovered))
301 break;
302 }
303 if (j == cRects)
304 return false;
305 }
306 return true;
307}
308
309/**
310 * @param pDevExt
311 */
312static NTSTATUS vboxVdmaGgDirtyRectsProcess(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_CONTEXT pContext, PVBOXWDDM_SWAPCHAIN pSwapchain, VBOXVDMAPIPE_RECTS *pContextRects)
313{
314 PVBOXWDDM_RECTS_INFO pRects = &pContextRects->UpdateRects;
315 NTSTATUS Status = STATUS_SUCCESS;
316 PVBOXVIDEOCM_CMD_RECTS_INTERNAL pCmdInternal = NULL;
317 uint32_t cbCmdInternal = VBOXVIDEOCM_CMD_RECTS_INTERNAL_SIZE4CRECTS(pRects->cRects);
318 Assert(KeGetCurrentIrql() < DISPATCH_LEVEL);
319 ExAcquireFastMutex(&pDevExt->ContextMutex);
320 for (PLIST_ENTRY pCur = pDevExt->SwapchainList3D.Flink; pCur != &pDevExt->SwapchainList3D; pCur = pCur->Flink)
321 {
322 if (pCur != &pSwapchain->DevExtListEntry)
323 {
324 PVBOXWDDM_SWAPCHAIN pCurSwapchain = VBOXWDDMENTRY_2_SWAPCHAIN(pCur);
325 if (!pCmdInternal)
326 {
327 pCmdInternal = (PVBOXVIDEOCM_CMD_RECTS_INTERNAL)vboxVideoCmCmdCreate(&pCurSwapchain->pContext->CmContext, cbCmdInternal);
328 Assert(pCmdInternal);
329 if (!pCmdInternal)
330 {
331 Status = STATUS_NO_MEMORY;
332 break;
333 }
334 }
335 else
336 {
337 pCmdInternal = (PVBOXVIDEOCM_CMD_RECTS_INTERNAL)vboxVideoCmCmdReinitForContext(pCmdInternal, &pCurSwapchain->pContext->CmContext);
338 }
339
340 vboxVdmaDirtyRectsCalcIntersection(&pCurSwapchain->ViewRect, pRects, &pCmdInternal->Cmd.RectsInfo);
341 if (pCmdInternal->Cmd.RectsInfo.cRects)
342 {
343 bool bSend = false;
344 pCmdInternal->Cmd.fFlags.Value = 0;
345 pCmdInternal->Cmd.fFlags.bAddHiddenRects = 1;
346 if (pCurSwapchain->pLastReportedRects)
347 {
348 if (pCurSwapchain->pLastReportedRects->Cmd.fFlags.bSetVisibleRects)
349 {
350 RECT *paPrevRects;
351 uint32_t cPrevRects;
352 if (pCurSwapchain->pLastReportedRects->Cmd.fFlags.bSetViewRect)
353 {
354 paPrevRects = &pCurSwapchain->pLastReportedRects->Cmd.RectsInfo.aRects[1];
355 cPrevRects = pCurSwapchain->pLastReportedRects->Cmd.RectsInfo.cRects - 1;
356 }
357 else
358 {
359 paPrevRects = &pCurSwapchain->pLastReportedRects->Cmd.RectsInfo.aRects[0];
360 cPrevRects = pCurSwapchain->pLastReportedRects->Cmd.RectsInfo.cRects;
361 }
362
363 if (vboxVdmaDirtyRectsHasIntersections(paPrevRects, cPrevRects,
364 pCmdInternal->Cmd.RectsInfo.aRects, pCmdInternal->Cmd.RectsInfo.cRects))
365 {
366 bSend = true;
367 }
368 }
369 else
370 {
371 Assert(pCurSwapchain->pLastReportedRects->Cmd.fFlags.bAddHiddenRects);
372 if (!vboxVdmaDirtyRectsIsCover(pCurSwapchain->pLastReportedRects->Cmd.RectsInfo.aRects,
373 pCurSwapchain->pLastReportedRects->Cmd.RectsInfo.cRects,
374 pCmdInternal->Cmd.RectsInfo.aRects, pCmdInternal->Cmd.RectsInfo.cRects))
375 {
376 bSend = true;
377 }
378 }
379 }
380 else
381 bSend = true;
382
383 if (bSend)
384 {
385 if (pCurSwapchain->pLastReportedRects)
386 vboxVideoCmCmdRelease(pCurSwapchain->pLastReportedRects);
387
388 pCmdInternal->hSwapchainUm = pCurSwapchain->hSwapchainUm;
389
390 vboxVideoCmCmdRetain(pCmdInternal);
391 pCurSwapchain->pLastReportedRects = pCmdInternal;
392 vboxVideoCmCmdSubmit(pCmdInternal, VBOXVIDEOCM_CMD_RECTS_INTERNAL_SIZE4CRECTS(pCmdInternal->Cmd.RectsInfo.cRects));
393 pCmdInternal = NULL;
394 }
395 }
396 }
397 else
398 {
399 RECT * pContextRect = &pContextRects->ContextRect;
400 bool bRectShanged = (pSwapchain->ViewRect.left != pContextRect->left
401 || pSwapchain->ViewRect.top != pContextRect->top
402 || pSwapchain->ViewRect.right != pContextRect->right
403 || pSwapchain->ViewRect.bottom != pContextRect->bottom);
404 PVBOXVIDEOCM_CMD_RECTS_INTERNAL pDrCmdInternal;
405
406 bool bSend = false;
407
408 if (bRectShanged)
409 {
410 uint32_t cbDrCmdInternal = VBOXVIDEOCM_CMD_RECTS_INTERNAL_SIZE4CRECTS(pRects->cRects + 1);
411 pDrCmdInternal = (PVBOXVIDEOCM_CMD_RECTS_INTERNAL)vboxVideoCmCmdCreate(&pContext->CmContext, cbDrCmdInternal);
412 Assert(pDrCmdInternal);
413 if (!pDrCmdInternal)
414 {
415 Status = STATUS_NO_MEMORY;
416 break;
417 }
418 pDrCmdInternal->Cmd.fFlags.Value = 0;
419 pDrCmdInternal->Cmd.RectsInfo.cRects = pRects->cRects + 1;
420 pDrCmdInternal->Cmd.fFlags.bSetViewRect = 1;
421 pDrCmdInternal->Cmd.RectsInfo.aRects[0] = *pContextRect;
422 pSwapchain->ViewRect = *pContextRect;
423 memcpy(&pDrCmdInternal->Cmd.RectsInfo.aRects[1], pRects->aRects, sizeof (RECT) * pRects->cRects);
424 bSend = true;
425 }
426 else
427 {
428 if (pCmdInternal)
429 {
430 pDrCmdInternal = (PVBOXVIDEOCM_CMD_RECTS_INTERNAL)vboxVideoCmCmdReinitForContext(pCmdInternal, &pContext->CmContext);
431 pCmdInternal = NULL;
432 }
433 else
434 {
435 pDrCmdInternal = (PVBOXVIDEOCM_CMD_RECTS_INTERNAL)vboxVideoCmCmdCreate(&pContext->CmContext, cbCmdInternal);
436 Assert(pDrCmdInternal);
437 if (!pDrCmdInternal)
438 {
439 Status = STATUS_NO_MEMORY;
440 break;
441 }
442 }
443 pDrCmdInternal->Cmd.fFlags.Value = 0;
444 pDrCmdInternal->Cmd.RectsInfo.cRects = pRects->cRects;
445 memcpy(&pDrCmdInternal->Cmd.RectsInfo.aRects[0], pRects->aRects, sizeof (RECT) * pRects->cRects);
446
447 if (pSwapchain->pLastReportedRects)
448 {
449 if (pSwapchain->pLastReportedRects->Cmd.fFlags.bSetVisibleRects)
450 {
451 RECT *paRects;
452 uint32_t cRects;
453 if (pSwapchain->pLastReportedRects->Cmd.fFlags.bSetViewRect)
454 {
455 paRects = &pSwapchain->pLastReportedRects->Cmd.RectsInfo.aRects[1];
456 cRects = pSwapchain->pLastReportedRects->Cmd.RectsInfo.cRects - 1;
457 }
458 else
459 {
460 paRects = &pSwapchain->pLastReportedRects->Cmd.RectsInfo.aRects[0];
461 cRects = pSwapchain->pLastReportedRects->Cmd.RectsInfo.cRects;
462 }
463 bSend = (pDrCmdInternal->Cmd.RectsInfo.cRects != cRects)
464 || memcmp(paRects, pDrCmdInternal->Cmd.RectsInfo.aRects, cRects * sizeof (RECT));
465 }
466 else
467 {
468 Assert(pSwapchain->pLastReportedRects->Cmd.fFlags.bAddHiddenRects);
469 bSend = true;
470 }
471 }
472 else
473 bSend = true;
474
475 }
476
477 Assert(pRects->cRects);
478 if (bSend)
479 {
480 if (pSwapchain->pLastReportedRects)
481 vboxVideoCmCmdRelease(pSwapchain->pLastReportedRects);
482
483 pDrCmdInternal->Cmd.fFlags.bSetVisibleRects = 1;
484 pDrCmdInternal->hSwapchainUm = pSwapchain->hSwapchainUm;
485
486 vboxVideoCmCmdRetain(pDrCmdInternal);
487 pSwapchain->pLastReportedRects = pDrCmdInternal;
488 vboxVideoCmCmdSubmit(pDrCmdInternal, VBOXVIDEOCM_SUBMITSIZE_DEFAULT);
489 }
490 else
491 {
492 if (!pCmdInternal)
493 pCmdInternal = pDrCmdInternal;
494 else
495 vboxVideoCmCmdRelease(pDrCmdInternal);
496 }
497 }
498 }
499 ExReleaseFastMutex(&pDevExt->ContextMutex);
500
501
502 if (pCmdInternal)
503 vboxVideoCmCmdRelease(pCmdInternal);
504
505 return Status;
506}
507
508static NTSTATUS vboxVdmaGgDmaColorFill(PVBOXVDMAPIPE_CMD_DMACMD_CLRFILL pCF)
509{
510 NTSTATUS Status = STATUS_UNSUCCESSFUL;
511 PVBOXWDDM_CONTEXT pContext = pCF->Hdr.DdiCmd.pContext;
512 PDEVICE_EXTENSION pDevExt = pContext->pDevice->pAdapter;
513 Assert (pDevExt->pvVisibleVram);
514 if (pDevExt->pvVisibleVram)
515 {
516 PVBOXWDDM_ALLOCATION pAlloc = pCF->ClrFill.Alloc.pAlloc;
517 Assert(pAlloc->offVram != VBOXVIDEOOFFSET_VOID);
518 if (pAlloc->offVram != VBOXVIDEOOFFSET_VOID)
519 {
520 RECT UnionRect = {0};
521 uint8_t *pvMem = pDevExt->pvVisibleVram + pAlloc->offVram;
522 UINT bpp = pAlloc->SurfDesc.bpp;
523 Assert(bpp);
524 Assert(((bpp * pAlloc->SurfDesc.width) >> 3) == pAlloc->SurfDesc.pitch);
525 switch (bpp)
526 {
527 case 32:
528 {
529 uint8_t bytestPP = bpp >> 3;
530 for (UINT i = 0; i < pCF->ClrFill.Rects.cRects; ++i)
531 {
532 RECT *pRect = &pCF->ClrFill.Rects.aRects[i];
533 for (LONG ir = pRect->top; ir < pRect->bottom; ++ir)
534 {
535 uint32_t * pvU32Mem = (uint32_t*)(pvMem + (ir * pAlloc->SurfDesc.pitch) + (pRect->left * bytestPP));
536 uint32_t cRaw = pRect->right - pRect->left;
537 Assert(pRect->left >= 0);
538 Assert(pRect->right <= (LONG)pAlloc->SurfDesc.width);
539 Assert(pRect->top >= 0);
540 Assert(pRect->bottom <= (LONG)pAlloc->SurfDesc.height);
541 for (UINT j = 0; j < cRaw; ++j)
542 {
543 *pvU32Mem = pCF->ClrFill.Color;
544 ++pvU32Mem;
545 }
546 }
547 vboxWddmRectUnited(&UnionRect, &UnionRect, pRect);
548 }
549 Status = STATUS_SUCCESS;
550 break;
551 }
552 case 16:
553 case 8:
554 default:
555 AssertBreakpoint();
556 break;
557 }
558
559 if (Status == STATUS_SUCCESS)
560 {
561 if (pAlloc->SurfDesc.VidPnSourceId != D3DDDI_ID_UNINITIALIZED
562 && pAlloc->bAssigned
563#if 0//def VBOXWDDM_RENDER_FROM_SHADOW
564 && pAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE
565#else
566 && pAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
567#endif
568 )
569 {
570 if (!vboxWddmRectIsEmpty(&UnionRect))
571 {
572 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pCF->ClrFill.Alloc.pAlloc->SurfDesc.VidPnSourceId];
573 VBOXVBVA_OP_WITHLOCK(ReportDirtyRect, pDevExt, pSource, &UnionRect);
574 }
575 }
576 else
577 {
578 AssertBreakpoint();
579 }
580 }
581 }
582 }
583
584 return Status;
585}
586
587NTSTATUS vboxVdmaGgDmaBltPerform(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_ALLOCATION pSrcAlloc, RECT* pSrcRect,
588 PVBOXWDDM_ALLOCATION pDstAlloc, RECT* pDstRect)
589{
590 uint8_t* pvVramBase = pDevExt->pvVisibleVram;
591 /* we do not support color conversion */
592 Assert(pSrcAlloc->SurfDesc.format == pDstAlloc->SurfDesc.format);
593 /* we do not support stretching */
594 uint32_t srcWidth = pSrcRect->right - pSrcRect->left;
595 uint32_t srcHeight = pSrcRect->bottom - pSrcRect->top;
596 uint32_t dstWidth = pDstRect->right - pDstRect->left;
597 uint32_t dstHeight = pDstRect->bottom - pDstRect->top;
598 Assert(srcHeight == dstHeight);
599 Assert(dstWidth == srcWidth);
600 Assert(pDstAlloc->offVram != VBOXVIDEOOFFSET_VOID);
601 Assert(pSrcAlloc->offVram != VBOXVIDEOOFFSET_VOID);
602
603 if (pSrcAlloc->SurfDesc.format != pDstAlloc->SurfDesc.format)
604 return STATUS_INVALID_PARAMETER;
605 if (srcHeight != dstHeight)
606 return STATUS_INVALID_PARAMETER;
607 if (srcWidth != dstWidth)
608 return STATUS_INVALID_PARAMETER;
609 if (pDstAlloc->offVram == VBOXVIDEOOFFSET_VOID)
610 return STATUS_INVALID_PARAMETER;
611 if (pSrcAlloc->offVram == VBOXVIDEOOFFSET_VOID)
612 return STATUS_INVALID_PARAMETER;
613
614 uint8_t *pvDstSurf = pvVramBase + pDstAlloc->offVram;
615 uint8_t *pvSrcSurf = pvVramBase + pSrcAlloc->offVram;
616
617 if (pDstAlloc->SurfDesc.width == dstWidth
618 && pSrcAlloc->SurfDesc.width == srcWidth
619 && pSrcAlloc->SurfDesc.width == pDstAlloc->SurfDesc.width)
620 {
621 Assert(!pDstRect->left);
622 Assert(!pSrcRect->left);
623 uint32_t cbOff = pDstAlloc->SurfDesc.pitch * pDstRect->top;
624 uint32_t cbSize = pDstAlloc->SurfDesc.pitch * dstHeight;
625 memcpy(pvDstSurf + cbOff, pvSrcSurf + cbOff, cbSize);
626 }
627 else
628 {
629 uint32_t offDstLineStart = pDstRect->left * pDstAlloc->SurfDesc.bpp >> 3;
630 uint32_t offDstLineEnd = ((pDstRect->left * pDstAlloc->SurfDesc.bpp + 7) >> 3) + ((pDstAlloc->SurfDesc.bpp * dstWidth + 7) >> 3);
631 uint32_t cbDstLine = offDstLineEnd - offDstLineStart;
632 uint32_t offDstStart = pDstAlloc->SurfDesc.pitch * pDstRect->top + offDstLineStart;
633 Assert(cbDstLine <= pDstAlloc->SurfDesc.pitch);
634 uint32_t cbDstSkip = pDstAlloc->SurfDesc.pitch;
635 uint8_t * pvDstStart = pvDstSurf + offDstStart;
636
637 uint32_t offSrcLineStart = pSrcRect->left * pSrcAlloc->SurfDesc.bpp >> 3;
638 uint32_t offSrcLineEnd = ((pSrcRect->left * pSrcAlloc->SurfDesc.bpp + 7) >> 3) + ((pSrcAlloc->SurfDesc.bpp * srcWidth + 7) >> 3);
639 uint32_t cbSrcLine = offSrcLineEnd - offSrcLineStart;
640 uint32_t offSrcStart = pSrcAlloc->SurfDesc.pitch * pSrcRect->top + offSrcLineStart;
641 Assert(cbSrcLine <= pSrcAlloc->SurfDesc.pitch);
642 uint32_t cbSrcSkip = pSrcAlloc->SurfDesc.pitch;
643 const uint8_t * pvSrcStart = pvSrcSurf + offSrcStart;
644
645 Assert(cbDstLine == cbSrcLine);
646
647 for (uint32_t i = 0; ; ++i)
648 {
649 memcpy (pvDstStart, pvSrcStart, cbDstLine);
650 if (i == dstHeight)
651 break;
652 pvDstStart += cbDstSkip;
653 pvSrcStart += cbSrcSkip;
654 }
655 }
656 return STATUS_SUCCESS;
657}
658
659/*
660 * @return on success the number of bytes the command contained, otherwise - VERR_xxx error code
661 */
662static NTSTATUS vboxVdmaGgDmaBlt(PVBOXVDMAPIPE_CMD_DMACMD_BLT pBlt)
663{
664 /* we do not support stretching for now */
665 Assert(pBlt->Blt.SrcRect.right - pBlt->Blt.SrcRect.left == pBlt->Blt.DstRects.ContextRect.right - pBlt->Blt.DstRects.ContextRect.left);
666 Assert(pBlt->Blt.SrcRect.bottom - pBlt->Blt.SrcRect.top == pBlt->Blt.DstRects.ContextRect.bottom - pBlt->Blt.DstRects.ContextRect.top);
667 if (pBlt->Blt.SrcRect.right - pBlt->Blt.SrcRect.left != pBlt->Blt.DstRects.ContextRect.right - pBlt->Blt.DstRects.ContextRect.left)
668 return STATUS_INVALID_PARAMETER;
669 if (pBlt->Blt.SrcRect.bottom - pBlt->Blt.SrcRect.top != pBlt->Blt.DstRects.ContextRect.bottom - pBlt->Blt.DstRects.ContextRect.top)
670 return STATUS_INVALID_PARAMETER;
671 Assert(pBlt->Blt.DstRects.UpdateRects.cRects);
672
673 NTSTATUS Status = STATUS_SUCCESS;
674 PDEVICE_EXTENSION pDevExt = pBlt->Hdr.pDevExt;
675
676 if (pBlt->Blt.DstRects.UpdateRects.cRects)
677 {
678 for (uint32_t i = 0; i < pBlt->Blt.DstRects.UpdateRects.cRects; ++i)
679 {
680 RECT DstRect;
681 RECT SrcRect;
682 vboxWddmRectTranslated(&DstRect, &pBlt->Blt.DstRects.UpdateRects.aRects[i], pBlt->Blt.DstRects.ContextRect.left, pBlt->Blt.DstRects.ContextRect.top);
683 vboxWddmRectTranslated(&SrcRect, &pBlt->Blt.DstRects.UpdateRects.aRects[i], pBlt->Blt.SrcRect.left, pBlt->Blt.SrcRect.top);
684
685 Status = vboxVdmaGgDmaBltPerform(pDevExt, pBlt->Blt.SrcAlloc.pAlloc, &SrcRect,
686 pBlt->Blt.DstAlloc.pAlloc, &DstRect);
687 Assert(Status == STATUS_SUCCESS);
688 if (Status != STATUS_SUCCESS)
689 return Status;
690 }
691 }
692 else
693 {
694 Status = vboxVdmaGgDmaBltPerform(pDevExt, pBlt->Blt.SrcAlloc.pAlloc, &pBlt->Blt.SrcRect,
695 pBlt->Blt.DstAlloc.pAlloc, &pBlt->Blt.DstRects.ContextRect);
696 Assert(Status == STATUS_SUCCESS);
697 if (Status != STATUS_SUCCESS)
698 return Status;
699 }
700
701 return Status;
702}
703
704static VOID vboxWddmBltPipeRectsTranslate(VBOXVDMAPIPE_RECTS *pRects, int x, int y)
705{
706 vboxWddmRectTranslate(&pRects->ContextRect, x, y);
707
708 for (UINT i = 0; i < pRects->UpdateRects.cRects; ++i)
709 {
710 vboxWddmRectTranslate(&pRects->UpdateRects.aRects[i], x, y);
711 }
712}
713
714static NTSTATUS vboxVdmaGgDmaCmdProcess(VBOXVDMAPIPE_CMD_DMACMD *pDmaCmd)
715{
716 PDEVICE_EXTENSION pDevExt = pDmaCmd->pDevExt;
717 PVBOXWDDM_CONTEXT pContext = pDmaCmd->DdiCmd.pContext;
718 NTSTATUS Status = STATUS_SUCCESS;
719 switch (pDmaCmd->enmCmd)
720 {
721 case VBOXVDMACMD_TYPE_DMA_PRESENT_BLT:
722 {
723 PVBOXVDMAPIPE_CMD_DMACMD_BLT pBlt = (PVBOXVDMAPIPE_CMD_DMACMD_BLT)pDmaCmd;
724 PVBOXWDDM_ALLOCATION pDstAlloc = pBlt->Blt.DstAlloc.pAlloc;
725 PVBOXWDDM_ALLOCATION pSrcAlloc = pBlt->Blt.SrcAlloc.pAlloc;
726 BOOLEAN bComplete = TRUE;
727 switch (pDstAlloc->enmType)
728 {
729 case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
730 case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
731 {
732 if (pDstAlloc->bAssigned)
733 {
734 VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
735 Assert(pSource->pPrimaryAllocation == pDstAlloc);
736 switch (pSrcAlloc->enmType)
737 {
738 case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
739 {
740 Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_SYSTEM);
741
742 if (pBlt->Hdr.fFlags.b2DRelated || pBlt->Hdr.fFlags.b3DRelated)
743 {
744 POINT pos;
745 BOOLEAN bPosMoved = FALSE;
746 if (pBlt->Hdr.fFlags.b3DRelated)
747 {
748 pos = pSource->VScreenPos;
749 if (pos.x || pos.y)
750 {
751 vboxWddmBltPipeRectsTranslate(&pBlt->Blt.DstRects, pos.x, pos.y);
752 bPosMoved = TRUE;
753 }
754 Status = vboxVdmaGgDirtyRectsProcess(pDevExt, pContext, NULL, &pBlt->Blt.DstRects);
755 Assert(Status == STATUS_SUCCESS);
756 }
757
758
759 if (pBlt->Hdr.fFlags.b2DRelated)
760 {
761 if (bPosMoved)
762 {
763 vboxWddmBltPipeRectsTranslate(&pBlt->Blt.DstRects, -pos.x, -pos.y);
764 }
765
766 RECT OverlayUnionRect;
767 RECT UpdateRect;
768 UpdateRect = pBlt->Blt.DstRects.UpdateRects.aRects[0];
769 for (UINT i = 1; i < pBlt->Blt.DstRects.UpdateRects.cRects; ++i)
770 {
771 vboxWddmRectUnite(&UpdateRect, &pBlt->Blt.DstRects.UpdateRects.aRects[i]);
772 }
773 vboxVhwaHlpOverlayDstRectUnion(pDevExt, pDstAlloc->SurfDesc.VidPnSourceId, &OverlayUnionRect);
774 Assert(pBlt->Blt.DstRects.ContextRect.left == 0); /* <-| otherwise we would probably need to translate the UpdateRects to left;top first??*/
775 Assert(pBlt->Blt.DstRects.ContextRect.top == 0); /* <--| */
776 vboxVdmaDirtyRectsCalcIntersection(&OverlayUnionRect, &pBlt->Blt.DstRects.UpdateRects, &pBlt->Blt.DstRects.UpdateRects);
777 if (pBlt->Blt.DstRects.UpdateRects.cRects)
778 {
779 vboxVdmaGgDmaBlt(pBlt);
780 }
781 VBOXVBVA_OP_WITHLOCK(ReportDirtyRect, pDevExt, pSource, &UpdateRect);
782 }
783 }
784
785 break;
786 }
787 case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
788 {
789 Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D);
790 Assert(pSrcAlloc->fRcFlags.RenderTarget);
791 if (pSrcAlloc->fRcFlags.RenderTarget)
792 {
793 if (pBlt->Hdr.fFlags.b3DRelated)
794 {
795 PVBOXWDDM_SWAPCHAIN pSwapchain;
796 pSwapchain = vboxWddmSwapchainRetainByAlloc(pDevExt, pSrcAlloc);
797 if (pSwapchain)
798 {
799 Status = vboxVdmaGgDirtyRectsProcess(pDevExt, pContext, pSwapchain, &pBlt->Blt.DstRects);
800 Assert(Status == STATUS_SUCCESS);
801 vboxWddmSwapchainRelease(pSwapchain);
802 }
803 }
804 }
805 break;
806 }
807 default:
808 AssertBreakpoint();
809 break;
810 }
811 }
812 break;
813 }
814 default:
815 Assert(0);
816 }
817
818 break;
819 }
820 case VBOXVDMACMD_TYPE_DMA_PRESENT_FLIP:
821 {
822 PVBOXVDMAPIPE_CMD_DMACMD_FLIP pFlip = (PVBOXVDMAPIPE_CMD_DMACMD_FLIP)pDmaCmd;
823 Assert(pFlip->Hdr.fFlags.b3DRelated);
824 Assert(!pFlip->Hdr.fFlags.bDecVBVAUnlock);
825 Assert(!pFlip->Hdr.fFlags.b2DRelated);
826 PVBOXWDDM_ALLOCATION pAlloc = pFlip->Flip.Alloc.pAlloc;
827 VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pAlloc->SurfDesc.VidPnSourceId];
828 if (pFlip->Hdr.fFlags.b3DRelated)
829 {
830 PVBOXWDDM_SWAPCHAIN pSwapchain;
831 pSwapchain = vboxWddmSwapchainRetainByAlloc(pDevExt, pAlloc);
832 if (pSwapchain)
833 {
834 POINT pos = pSource->VScreenPos;
835 VBOXVDMAPIPE_RECTS Rects;
836 Rects.ContextRect.left = pos.x;
837 Rects.ContextRect.top = pos.y;
838 Rects.ContextRect.right = pAlloc->SurfDesc.width + pos.x;
839 Rects.ContextRect.bottom = pAlloc->SurfDesc.height + pos.y;
840 Rects.UpdateRects.cRects = 1;
841 Rects.UpdateRects.aRects[0] = Rects.ContextRect;
842 Status = vboxVdmaGgDirtyRectsProcess(pDevExt, pContext, pSwapchain, &Rects);
843 Assert(Status == STATUS_SUCCESS);
844 vboxWddmSwapchainRelease(pSwapchain);
845 }
846 }
847
848 break;
849 }
850 case VBOXVDMACMD_TYPE_DMA_PRESENT_CLRFILL:
851 {
852 PVBOXVDMAPIPE_CMD_DMACMD_CLRFILL pCF = (PVBOXVDMAPIPE_CMD_DMACMD_CLRFILL)pDmaCmd;
853 Assert(pCF->Hdr.fFlags.b2DRelated);
854 Assert(pCF->Hdr.fFlags.bDecVBVAUnlock);
855 Assert(!pCF->Hdr.fFlags.b3DRelated);
856 Status = vboxVdmaGgDmaColorFill(pCF);
857 Assert(Status == STATUS_SUCCESS);
858 break;
859 }
860 default:
861 Assert(0);
862 break;
863 }
864
865 if (pDmaCmd->fFlags.bDecVBVAUnlock)
866 {
867 uint32_t cNew = ASMAtomicDecU32(&pDevExt->cUnlockedVBVADisabled);
868 Assert(cNew < UINT32_MAX/2);
869 }
870
871 Status = vboxVdmaDdiCmdCompleted(pDevExt, &pDevExt->DdiCmdQueue, &pDmaCmd->DdiCmd);
872 Assert(Status == STATUS_SUCCESS);
873
874 return Status;
875}
876
877static VOID vboxVdmaGgWorkerThread(PVOID pvUser)
878{
879 PVBOXVDMAGG pVdma = (PVBOXVDMAGG)pvUser;
880
881 NTSTATUS Status = vboxVdmaPipeSvrOpen(&pVdma->CmdPipe);
882 Assert(Status == STATUS_SUCCESS);
883 if (Status == STATUS_SUCCESS)
884 {
885 do
886 {
887 LIST_ENTRY CmdList;
888 Status = vboxVdmaPipeSvrCmdGetList(&pVdma->CmdPipe, &CmdList);
889 Assert(Status == STATUS_SUCCESS || Status == STATUS_PIPE_CLOSING);
890 if (Status == STATUS_SUCCESS)
891 {
892 for (PLIST_ENTRY pCur = CmdList.Blink; pCur != &CmdList;)
893 {
894 PVBOXVDMAPIPE_CMD_DR pDr = VBOXVDMAPIPE_CMD_DR_FROM_ENTRY(pCur);
895 RemoveEntryList(pCur);
896 pCur = CmdList.Blink;
897 switch (pDr->enmType)
898 {
899#if 0
900 case VBOXVDMAPIPE_CMD_TYPE_RECTSINFO:
901 {
902 PVBOXVDMAPIPE_CMD_RECTSINFO pRects = (PVBOXVDMAPIPE_CMD_RECTSINFO)pDr;
903 Status = vboxVdmaGgDirtyRectsProcess(pRects);
904 Assert(Status == STATUS_SUCCESS);
905 vboxVdmaGgCmdDestroy(pDr);
906 break;
907 }
908#endif
909 case VBOXVDMAPIPE_CMD_TYPE_DMACMD:
910 {
911 PVBOXVDMAPIPE_CMD_DMACMD pDmaCmd = (PVBOXVDMAPIPE_CMD_DMACMD)pDr;
912 Status = vboxVdmaGgDmaCmdProcess(pDmaCmd);
913 Assert(Status == STATUS_SUCCESS);
914 } break;
915 default:
916 AssertBreakpoint();
917 }
918 }
919 }
920 else
921 break;
922 } while (1);
923 }
924
925 /* always try to close the pipe to make sure the client side is notified */
926 Status = vboxVdmaPipeSvrClose(&pVdma->CmdPipe);
927 Assert(Status == STATUS_SUCCESS);
928}
929
930NTSTATUS vboxVdmaGgConstruct(PVBOXVDMAGG pVdma)
931{
932 NTSTATUS Status = vboxVdmaPipeConstruct(&pVdma->CmdPipe);
933 Assert(Status == STATUS_SUCCESS);
934 if (Status == STATUS_SUCCESS)
935 {
936 Status = vboxVdmaGgThreadCreate(&pVdma->pThread, vboxVdmaGgWorkerThread, pVdma);
937 Assert(Status == STATUS_SUCCESS);
938 if (Status == STATUS_SUCCESS)
939 return STATUS_SUCCESS;
940
941 NTSTATUS tmpStatus = vboxVdmaPipeDestruct(&pVdma->CmdPipe);
942 Assert(tmpStatus == STATUS_SUCCESS);
943 }
944
945 /* we're here ONLY in case of an error */
946 Assert(Status != STATUS_SUCCESS);
947 return Status;
948}
949
950NTSTATUS vboxVdmaGgDestruct(PVBOXVDMAGG pVdma)
951{
952 /* this informs the server thread that it should complete all current commands and exit */
953 NTSTATUS Status = vboxVdmaPipeCltClose(&pVdma->CmdPipe);
954 Assert(Status == STATUS_SUCCESS);
955 if (Status == STATUS_SUCCESS)
956 {
957 Status = KeWaitForSingleObject(pVdma->pThread, Executive, KernelMode, FALSE, NULL /* PLARGE_INTEGER Timeout */);
958 Assert(Status == STATUS_SUCCESS);
959 if (Status == STATUS_SUCCESS)
960 {
961 Status = vboxVdmaPipeDestruct(&pVdma->CmdPipe);
962 Assert(Status == STATUS_SUCCESS);
963 }
964 }
965
966 return Status;
967}
968
969NTSTATUS vboxVdmaGgCmdSubmit(PVBOXVDMAGG pVdma, PVBOXVDMAPIPE_CMD_DR pCmd)
970{
971 return vboxVdmaPipeCltCmdPut(&pVdma->CmdPipe, &pCmd->PipeHdr);
972}
973
974/* end */
975
976#ifdef VBOXVDMA
977/*
978 * This is currently used by VDMA. It is invisible for Vdma API clients since
979 * Vdma transport may change if we choose to use another (e.g. more light-weight)
980 * transport for DMA commands submission
981 */
982
983#ifdef VBOXVDMA_WITH_VBVA
984static int vboxWddmVdmaSubmitVbva(struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo, HGSMIOFFSET offDr)
985{
986 int rc;
987 if (vboxVbvaBufferBeginUpdate (pDevExt, &pDevExt->u.primary.Vbva))
988 {
989 rc = vboxVbvaReportCmdOffset(pDevExt, &pDevExt->u.primary.Vbva, offDr);
990 vboxVbvaBufferEndUpdate (pDevExt, &pDevExt->u.primary.Vbva);
991 }
992 else
993 {
994 AssertBreakpoint();
995 rc = VERR_INVALID_STATE;
996 }
997 return rc;
998}
999#define vboxWddmVdmaSubmit vboxWddmVdmaSubmitVbva
1000#else
1001static int vboxWddmVdmaSubmitHgsmi(struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo, HGSMIOFFSET offDr)
1002{
1003 VBoxHGSMIGuestWrite(pDevExt, offDr);
1004 return VINF_SUCCESS;
1005}
1006#define vboxWddmVdmaSubmit vboxWddmVdmaSubmitHgsmi
1007#endif
1008
1009static int vboxVdmaInformHost(PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo, VBOXVDMA_CTL_TYPE enmCtl)
1010{
1011 int rc = VINF_SUCCESS;
1012
1013 PVBOXVDMA_CTL pCmd = (PVBOXVDMA_CTL)VBoxSHGSMICommandAlloc(&pDevExt->u.primary.hgsmiAdapterHeap, sizeof (VBOXVDMA_CTL), HGSMI_CH_VBVA, VBVA_VDMA_CTL);
1014 if (pCmd)
1015 {
1016 pCmd->enmCtl = enmCtl;
1017 pCmd->u32Offset = pInfo->CmdHeap.area.offBase;
1018 pCmd->i32Result = VERR_NOT_SUPPORTED;
1019
1020 const VBOXSHGSMIHEADER* pHdr = VBoxSHGSMICommandPrepSynch(&pDevExt->u.primary.hgsmiAdapterHeap, pCmd);
1021 Assert(pHdr);
1022 if (pHdr)
1023 {
1024 do
1025 {
1026 HGSMIOFFSET offCmd = VBoxSHGSMICommandOffset(&pDevExt->u.primary.hgsmiAdapterHeap, pHdr);
1027 Assert(offCmd != HGSMIOFFSET_VOID);
1028 if (offCmd != HGSMIOFFSET_VOID)
1029 {
1030 rc = vboxWddmVdmaSubmit(pDevExt, pInfo, offCmd);
1031 AssertRC(rc);
1032 if (RT_SUCCESS(rc))
1033 {
1034 rc = VBoxSHGSMICommandDoneSynch(&pDevExt->u.primary.hgsmiAdapterHeap, pHdr);
1035 AssertRC(rc);
1036 if (RT_SUCCESS(rc))
1037 {
1038 rc = pCmd->i32Result;
1039 AssertRC(rc);
1040 }
1041 break;
1042 }
1043 }
1044 else
1045 rc = VERR_INVALID_PARAMETER;
1046 /* fail to submit, cancel it */
1047 VBoxSHGSMICommandCancelSynch(&pDevExt->u.primary.hgsmiAdapterHeap, pHdr);
1048 } while (0);
1049 }
1050
1051 VBoxSHGSMICommandFree (&pDevExt->u.primary.hgsmiAdapterHeap, pCmd);
1052 }
1053 else
1054 {
1055 drprintf((__FUNCTION__": HGSMIHeapAlloc failed\n"));
1056 rc = VERR_OUT_OF_RESOURCES;
1057 }
1058
1059 return rc;
1060}
1061#endif
1062
1063/* create a DMACommand buffer */
1064int vboxVdmaCreate(PDEVICE_EXTENSION pDevExt, VBOXVDMAINFO *pInfo
1065#ifdef VBOXVDMA
1066 , ULONG offBuffer, ULONG cbBuffer
1067#endif
1068 )
1069{
1070 int rc;
1071 pInfo->fEnabled = FALSE;
1072
1073#ifdef VBOXVDMA
1074 Assert((offBuffer & 0xfff) == 0);
1075 Assert((cbBuffer & 0xfff) == 0);
1076 Assert(offBuffer);
1077 Assert(cbBuffer);
1078
1079 if((offBuffer & 0xfff)
1080 || (cbBuffer & 0xfff)
1081 || !offBuffer
1082 || !cbBuffer)
1083 {
1084 drprintf((__FUNCTION__": invalid parameters: offBuffer(0x%x), cbBuffer(0x%x)", offBuffer, cbBuffer));
1085 return VERR_INVALID_PARAMETER;
1086 }
1087 PVOID pvBuffer;
1088
1089 rc = VBoxMapAdapterMemory (pDevExt,
1090 &pvBuffer,
1091 offBuffer,
1092 cbBuffer);
1093 Assert(RT_SUCCESS(rc));
1094 if (RT_SUCCESS(rc))
1095 {
1096 /* Setup a HGSMI heap within the adapter information area. */
1097 rc = HGSMIHeapSetup (&pInfo->CmdHeap,
1098 pvBuffer,
1099 cbBuffer,
1100 offBuffer,
1101 false /*fOffsetBased*/);
1102 Assert(RT_SUCCESS(rc));
1103 if(RT_SUCCESS(rc))
1104#endif
1105 {
1106 NTSTATUS Status = vboxVdmaGgConstruct(&pInfo->DmaGg);
1107 Assert(Status == STATUS_SUCCESS);
1108 if (Status == STATUS_SUCCESS)
1109 return VINF_SUCCESS;
1110 rc = VERR_GENERAL_FAILURE;
1111 }
1112#ifdef VBOXVDMA
1113 else
1114 drprintf((__FUNCTION__": HGSMIHeapSetup failed rc = 0x%x\n", rc));
1115
1116 VBoxUnmapAdapterMemory(pDevExt, &pvBuffer, cbBuffer);
1117 }
1118 else
1119 drprintf((__FUNCTION__": VBoxMapAdapterMemory failed rc = 0x%x\n", rc));
1120#endif
1121 return rc;
1122}
1123
1124int vboxVdmaDisable (PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo)
1125{
1126 dfprintf((__FUNCTION__"\n"));
1127
1128 Assert(pInfo->fEnabled);
1129 if (!pInfo->fEnabled)
1130 return VINF_ALREADY_INITIALIZED;
1131
1132 /* ensure nothing else is submitted */
1133 pInfo->fEnabled = FALSE;
1134#ifdef VBOXVDMA
1135 int rc = vboxVdmaInformHost (pDevExt, pInfo, VBOXVDMA_CTL_TYPE_DISABLE);
1136 AssertRC(rc);
1137 return rc;
1138#else
1139 return VINF_SUCCESS;
1140#endif
1141}
1142
1143int vboxVdmaEnable (PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo)
1144{
1145 dfprintf((__FUNCTION__"\n"));
1146
1147 Assert(!pInfo->fEnabled);
1148 if (pInfo->fEnabled)
1149 return VINF_ALREADY_INITIALIZED;
1150#ifdef VBOXVDMA
1151 int rc = vboxVdmaInformHost (pDevExt, pInfo, VBOXVDMA_CTL_TYPE_ENABLE);
1152 Assert(RT_SUCCESS(rc));
1153 if (RT_SUCCESS(rc))
1154 pInfo->fEnabled = TRUE;
1155
1156 return rc;
1157#else
1158 return VINF_SUCCESS;
1159#endif
1160}
1161
1162#ifdef VBOXVDMA
1163int vboxVdmaFlush (PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo)
1164{
1165 dfprintf((__FUNCTION__"\n"));
1166
1167 Assert(pInfo->fEnabled);
1168 if (!pInfo->fEnabled)
1169 return VINF_ALREADY_INITIALIZED;
1170
1171 int rc = vboxVdmaInformHost (pDevExt, pInfo, VBOXVDMA_CTL_TYPE_FLUSH);
1172 Assert(RT_SUCCESS(rc));
1173
1174 return rc;
1175}
1176#endif
1177
1178int vboxVdmaDestroy (PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo)
1179{
1180 int rc = VINF_SUCCESS;
1181 NTSTATUS Status = vboxVdmaGgDestruct(&pInfo->DmaGg);
1182 Assert(Status == STATUS_SUCCESS);
1183 if (Status == STATUS_SUCCESS)
1184 {
1185 Assert(!pInfo->fEnabled);
1186 if (pInfo->fEnabled)
1187 rc = vboxVdmaDisable (pDevExt, pInfo);
1188#ifdef VBOXVDMA
1189 VBoxUnmapAdapterMemory (pDevExt, (void**)&pInfo->CmdHeap.area.pu8Base, pInfo->CmdHeap.area.cbArea);
1190#endif
1191 }
1192 else
1193 rc = VERR_GENERAL_FAILURE;
1194 return rc;
1195}
1196
1197#ifdef VBOXVDMA
1198void vboxVdmaCBufDrFree (PVBOXVDMAINFO pInfo, PVBOXVDMACBUF_DR pDr)
1199{
1200 VBoxSHGSMICommandFree (&pInfo->CmdHeap, pDr);
1201}
1202
1203PVBOXVDMACBUF_DR vboxVdmaCBufDrCreate (PVBOXVDMAINFO pInfo, uint32_t cbTrailingData)
1204{
1205 uint32_t cbDr = VBOXVDMACBUF_DR_SIZE(cbTrailingData);
1206 PVBOXVDMACBUF_DR pDr = (PVBOXVDMACBUF_DR)VBoxSHGSMICommandAlloc (&pInfo->CmdHeap, cbDr, HGSMI_CH_VBVA, VBVA_VDMA_CMD);
1207 Assert(pDr);
1208 if (pDr)
1209 memset (pDr, 0, cbDr);
1210 else
1211 drprintf((__FUNCTION__": VBoxSHGSMICommandAlloc returned NULL\n"));
1212
1213 return pDr;
1214}
1215
1216static DECLCALLBACK(void) vboxVdmaCBufDrCompletion(struct _HGSMIHEAP * pHeap, void *pvCmd, void *pvContext)
1217{
1218 PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION)pvContext;
1219 PVBOXVDMAINFO pInfo = &pDevExt->u.primary.Vdma;
1220
1221 vboxVdmaCBufDrFree (pInfo, (PVBOXVDMACBUF_DR)pvCmd);
1222}
1223
1224static DECLCALLBACK(void) vboxVdmaCBufDrCompletionIrq(struct _HGSMIHEAP * pHeap, void *pvCmd, void *pvContext,
1225 PFNVBOXSHGSMICMDCOMPLETION *ppfnCompletion, void **ppvCompletion)
1226{
1227 PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION)pvContext;
1228 PVBOXVDMAINFO pVdma = &pDevExt->u.primary.Vdma;
1229 DXGKARGCB_NOTIFY_INTERRUPT_DATA notify;
1230 PVBOXVDMACBUF_DR pDr = (PVBOXVDMACBUF_DR)pvCmd;
1231
1232 memset(&notify, 0, sizeof(DXGKARGCB_NOTIFY_INTERRUPT_DATA));
1233
1234 PVBOXWDDM_CONTEXT pContext = (PVBOXWDDM_CONTEXT)pDr->u64GuestContext;
1235
1236 if (RT_SUCCESS(pDr->rc))
1237 {
1238 notify.InterruptType = DXGK_INTERRUPT_DMA_COMPLETED;
1239 notify.DmaCompleted.SubmissionFenceId = pDr->u32FenceId;
1240 if (pContext)
1241 {
1242 notify.DmaCompleted.NodeOrdinal = pContext->NodeOrdinal;
1243 notify.DmaCompleted.EngineOrdinal = 0;
1244 pContext->uLastCompletedCmdFenceId = pDr->u32FenceId;
1245 }
1246 else
1247 pVdma->uLastCompletedPagingBufferCmdFenceId = pDr->u32FenceId;
1248 pDevExt->bSetNotifyDxDpc = TRUE;
1249 }
1250 else if (pDr->rc == VERR_INTERRUPTED)
1251 {
1252 notify.InterruptType = DXGK_INTERRUPT_DMA_PREEMPTED;
1253 notify.DmaPreempted.PreemptionFenceId = pDr->u32FenceId;
1254 if (pContext)
1255 {
1256 notify.DmaPreempted.LastCompletedFenceId = pContext->uLastCompletedCmdFenceId;
1257 notify.DmaPreempted.NodeOrdinal = pContext->NodeOrdinal;
1258 notify.DmaPreempted.EngineOrdinal = 0;
1259 }
1260 else
1261 notify.DmaPreempted.LastCompletedFenceId = pVdma->uLastCompletedPagingBufferCmdFenceId;
1262
1263 pDevExt->bSetNotifyDxDpc = TRUE;
1264 }
1265 else
1266 {
1267 AssertBreakpoint();
1268 notify.InterruptType = DXGK_INTERRUPT_DMA_FAULTED;
1269 notify.DmaFaulted.FaultedFenceId = pDr->u32FenceId;
1270 notify.DmaFaulted.Status = STATUS_UNSUCCESSFUL; /* @todo: better status ? */
1271 if (pContext)
1272 {
1273 notify.DmaFaulted.NodeOrdinal = pContext->NodeOrdinal;
1274 notify.DmaFaulted.EngineOrdinal = 0;
1275 }
1276 pDevExt->bSetNotifyDxDpc = TRUE;
1277 }
1278
1279 pDevExt->u.primary.DxgkInterface.DxgkCbNotifyInterrupt(pDevExt->u.primary.DxgkInterface.DeviceHandle, &notify);
1280
1281 /* inform SHGSMI we want to be called at DPC later */
1282 *ppfnCompletion = vboxVdmaCBufDrCompletion;
1283 *ppvCompletion = pvContext;
1284}
1285
1286int vboxVdmaCBufDrSubmit(PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo, PVBOXVDMACBUF_DR pDr)
1287{
1288 const VBOXSHGSMIHEADER* pHdr = VBoxSHGSMICommandPrepAsynchIrq (&pInfo->CmdHeap, pDr, vboxVdmaCBufDrCompletionIrq, pDevExt, VBOXSHGSMI_FLAG_GH_ASYNCH_FORCE);
1289 Assert(pHdr);
1290 int rc = VERR_GENERAL_FAILURE;
1291 if (pHdr)
1292 {
1293 do
1294 {
1295 HGSMIOFFSET offCmd = VBoxSHGSMICommandOffset(&pInfo->CmdHeap, pHdr);
1296 Assert(offCmd != HGSMIOFFSET_VOID);
1297 if (offCmd != HGSMIOFFSET_VOID)
1298 {
1299 rc = vboxWddmVdmaSubmit(pDevExt, pInfo, offCmd);
1300 AssertRC(rc);
1301 if (RT_SUCCESS(rc))
1302 {
1303 VBoxSHGSMICommandDoneAsynch(&pInfo->CmdHeap, pHdr);
1304 AssertRC(rc);
1305 break;
1306 }
1307 }
1308 else
1309 rc = VERR_INVALID_PARAMETER;
1310 /* fail to submit, cancel it */
1311 VBoxSHGSMICommandCancelAsynch(&pInfo->CmdHeap, pHdr);
1312 } while (0);
1313 }
1314 else
1315 rc = VERR_INVALID_PARAMETER;
1316 return rc;
1317}
1318#endif
1319
1320
1321/* ddi dma command queue */
1322DECLINLINE(BOOLEAN) vboxVdmaDdiCmdCanComplete(PVBOXVDMADDI_CMD_QUEUE pQueue)
1323{
1324 return ASMAtomicUoReadU32(&pQueue->cQueuedCmds) == 0;
1325}
1326
1327DECLCALLBACK(VOID) vboxVdmaDdiCmdCompletionCbFree(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext)
1328{
1329 vboxWddmMemFree(pCmd);
1330}
1331
1332static VOID vboxVdmaDdiCmdNotifyCompletedIrq(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1333{
1334 DXGKARGCB_NOTIFY_INTERRUPT_DATA notify;
1335 memset(&notify, 0, sizeof(DXGKARGCB_NOTIFY_INTERRUPT_DATA));
1336 notify.InterruptType = DXGK_INTERRUPT_DMA_COMPLETED;
1337 notify.DmaCompleted.SubmissionFenceId = pCmd->u32FenceId;
1338 notify.DmaCompleted.NodeOrdinal = pCmd->pContext->NodeOrdinal;
1339 notify.DmaCompleted.EngineOrdinal = 0;
1340 pCmd->pContext->uLastCompletedCmdFenceId = pCmd->u32FenceId;
1341
1342 pDevExt->u.primary.DxgkInterface.DxgkCbNotifyInterrupt(pDevExt->u.primary.DxgkInterface.DeviceHandle, &notify);
1343
1344 InsertTailList(&pQueue->DpcCmdQueue, &pCmd->QueueEntry);
1345}
1346
1347DECLINLINE(VOID) vboxVdmaDdiCmdDequeueIrq(PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1348{
1349 ASMAtomicDecU32(&pQueue->cQueuedCmds);
1350 RemoveEntryList(&pCmd->QueueEntry);
1351}
1352
1353DECLINLINE(VOID) vboxVdmaDdiCmdEnqueueIrq(PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1354{
1355 ASMAtomicIncU32(&pQueue->cQueuedCmds);
1356 InsertTailList(&pQueue->CmdQueue, &pCmd->QueueEntry);
1357}
1358
1359VOID vboxVdmaDdiQueueInit(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue)
1360{
1361 pQueue->cQueuedCmds = 0;
1362 InitializeListHead(&pQueue->CmdQueue);
1363 InitializeListHead(&pQueue->DpcCmdQueue);
1364}
1365
1366BOOLEAN vboxVdmaDdiCmdCompletedIrq(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1367{
1368 BOOLEAN bQueued = pCmd->enmState > VBOXVDMADDI_STATE_NOT_QUEUED;
1369 BOOLEAN bComplete = FALSE;
1370 Assert(!bQueued || pQueue->cQueuedCmds);
1371 Assert(!bQueued || !IsListEmpty(&pQueue->CmdQueue));
1372 pCmd->enmState = VBOXVDMADDI_STATE_COMPLETED;
1373 if (bQueued)
1374 {
1375 if (pQueue->CmdQueue.Flink == &pCmd->QueueEntry)
1376 {
1377 vboxVdmaDdiCmdDequeueIrq(pQueue, pCmd);
1378 bComplete = TRUE;
1379 }
1380 }
1381 else if (IsListEmpty(&pQueue->CmdQueue))
1382 {
1383 bComplete = TRUE;
1384 }
1385 else
1386 {
1387 vboxVdmaDdiCmdEnqueueIrq(pQueue, pCmd);
1388 }
1389
1390 if (bComplete)
1391 {
1392 vboxVdmaDdiCmdNotifyCompletedIrq(pDevExt, pQueue, pCmd);
1393
1394 while (!IsListEmpty(&pQueue->CmdQueue))
1395 {
1396 pCmd = VBOXVDMADDI_CMD_FROM_ENTRY(pQueue->CmdQueue.Flink);
1397 if (pCmd->enmState == VBOXVDMADDI_STATE_COMPLETED)
1398 {
1399 vboxVdmaDdiCmdDequeueIrq(pQueue, pCmd);
1400 vboxVdmaDdiCmdNotifyCompletedIrq(pDevExt, pQueue, pCmd);
1401 }
1402 else
1403 break;
1404 }
1405 }
1406 else
1407 {
1408 pCmd->enmState = VBOXVDMADDI_STATE_COMPLETED;
1409 }
1410
1411 return bComplete;
1412}
1413
1414VOID vboxVdmaDdiCmdSubmittedIrq(PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1415{
1416 BOOLEAN bQueued = pCmd->enmState >= VBOXVDMADDI_STATE_PENDING;
1417 Assert(pCmd->enmState < VBOXVDMADDI_STATE_SUBMITTED);
1418 pCmd->enmState = VBOXVDMADDI_STATE_SUBMITTED;
1419 if (!bQueued)
1420 vboxVdmaDdiCmdEnqueueIrq(pQueue, pCmd);
1421}
1422
1423typedef struct VBOXVDMADDI_CMD_COMPLETED_CB
1424{
1425 PDEVICE_EXTENSION pDevExt;
1426 PVBOXVDMADDI_CMD_QUEUE pQueue;
1427 PVBOXVDMADDI_CMD pCmd;
1428} VBOXVDMADDI_CMD_COMPLETED_CB, *PVBOXVDMADDI_CMD_COMPLETED_CB;
1429
1430static BOOLEAN vboxVdmaDdiCmdCompletedCb(PVOID Context)
1431{
1432 PVBOXVDMADDI_CMD_COMPLETED_CB pdc = (PVBOXVDMADDI_CMD_COMPLETED_CB)Context;
1433 BOOLEAN bNeedDps = vboxVdmaDdiCmdCompletedIrq(pdc->pDevExt, pdc->pQueue, pdc->pCmd);
1434 pdc->pDevExt->bNotifyDxDpc |= bNeedDps;
1435
1436 return bNeedDps;
1437}
1438
1439NTSTATUS vboxVdmaDdiCmdCompleted(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1440{
1441 VBOXVDMADDI_CMD_COMPLETED_CB context;
1442 context.pDevExt = pDevExt;
1443 context.pQueue = pQueue;
1444 context.pCmd = pCmd;
1445 BOOLEAN bNeedDps;
1446 NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbSynchronizeExecution(
1447 pDevExt->u.primary.DxgkInterface.DeviceHandle,
1448 vboxVdmaDdiCmdCompletedCb,
1449 &context,
1450 0, /* IN ULONG MessageNumber */
1451 &bNeedDps);
1452 Assert(Status == STATUS_SUCCESS);
1453 if (Status == STATUS_SUCCESS && bNeedDps)
1454 {
1455 BOOLEAN bRc = pDevExt->u.primary.DxgkInterface.DxgkCbQueueDpc(pDevExt->u.primary.DxgkInterface.DeviceHandle);
1456 Assert(bRc);
1457 }
1458 return Status;
1459}
1460
1461typedef struct VBOXVDMADDI_CMD_SUBMITTED_CB
1462{
1463// PDEVICE_EXTENSION pDevExt;
1464 PVBOXVDMADDI_CMD_QUEUE pQueue;
1465 PVBOXVDMADDI_CMD pCmd;
1466} VBOXVDMADDI_CMD_SUBMITTED_CB, *PVBOXVDMADDI_CMD_SUBMITTED_CB;
1467
1468static BOOLEAN vboxVdmaDdiCmdSubmittedCb(PVOID Context)
1469{
1470 PVBOXVDMADDI_CMD_SUBMITTED_CB pdc = (PVBOXVDMADDI_CMD_SUBMITTED_CB)Context;
1471 vboxVdmaDdiCmdSubmittedIrq(pdc->pQueue, pdc->pCmd);
1472
1473 return FALSE;
1474}
1475
1476NTSTATUS vboxVdmaDdiCmdSubmitted(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1477{
1478 VBOXVDMADDI_CMD_SUBMITTED_CB context;
1479 context.pQueue = pQueue;
1480 context.pCmd = pCmd;
1481 BOOLEAN bRc;
1482 NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbSynchronizeExecution(
1483 pDevExt->u.primary.DxgkInterface.DeviceHandle,
1484 vboxVdmaDdiCmdSubmittedCb,
1485 &context,
1486 0, /* IN ULONG MessageNumber */
1487 &bRc);
1488 Assert(Status == STATUS_SUCCESS);
1489 return Status;
1490}
1491
1492typedef struct VBOXVDMADDI_CMD_COMPLETE_CB
1493{
1494 PDEVICE_EXTENSION pDevExt;
1495 PVBOXWDDM_CONTEXT pContext;
1496 uint32_t u32FenceId;
1497} VBOXVDMADDI_CMD_COMPLETE_CB, *PVBOXVDMADDI_CMD_COMPLETE_CB;
1498
1499static BOOLEAN vboxVdmaDdiCmdFenceCompleteCb(PVOID Context)
1500{
1501 PVBOXVDMADDI_CMD_COMPLETE_CB pdc = (PVBOXVDMADDI_CMD_COMPLETE_CB)Context;
1502 PDEVICE_EXTENSION pDevExt = pdc->pDevExt;
1503 DXGKARGCB_NOTIFY_INTERRUPT_DATA notify;
1504 memset(&notify, 0, sizeof(DXGKARGCB_NOTIFY_INTERRUPT_DATA));
1505
1506 notify.InterruptType = DXGK_INTERRUPT_DMA_COMPLETED;
1507 notify.DmaCompleted.SubmissionFenceId = pdc->u32FenceId;
1508 notify.DmaCompleted.NodeOrdinal = pdc->pContext->NodeOrdinal;
1509 notify.DmaCompleted.EngineOrdinal = 0;
1510
1511 pDevExt->u.primary.DxgkInterface.DxgkCbNotifyInterrupt(pDevExt->u.primary.DxgkInterface.DeviceHandle, &notify);
1512
1513 pDevExt->bNotifyDxDpc = TRUE;
1514 BOOLEAN bDpcQueued = pDevExt->u.primary.DxgkInterface.DxgkCbQueueDpc(pDevExt->u.primary.DxgkInterface.DeviceHandle);
1515 Assert(bDpcQueued);
1516
1517 return bDpcQueued;
1518}
1519
1520static NTSTATUS vboxVdmaDdiCmdFenceNotifyComplete(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_CONTEXT pContext, uint32_t u32FenceId)
1521{
1522 VBOXVDMADDI_CMD_COMPLETE_CB context;
1523 context.pDevExt = pDevExt;
1524 context.pContext = pContext;
1525 context.u32FenceId = u32FenceId;
1526 BOOLEAN bRet;
1527 NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbSynchronizeExecution(
1528 pDevExt->u.primary.DxgkInterface.DeviceHandle,
1529 vboxVdmaDdiCmdFenceCompleteCb,
1530 &context,
1531 0, /* IN ULONG MessageNumber */
1532 &bRet);
1533 Assert(Status == STATUS_SUCCESS);
1534 return Status;
1535}
1536
1537NTSTATUS vboxVdmaDdiCmdFenceComplete(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_CONTEXT pContext, uint32_t u32FenceId)
1538{
1539 if (vboxVdmaDdiCmdCanComplete(&pDevExt->DdiCmdQueue))
1540 return vboxVdmaDdiCmdFenceNotifyComplete(pDevExt, pContext, u32FenceId);
1541
1542 PVBOXVDMADDI_CMD pCmd = (PVBOXVDMADDI_CMD)vboxWddmMemAlloc(sizeof (VBOXVDMADDI_CMD));
1543 Assert(pCmd);
1544 if (pCmd)
1545 {
1546 vboxVdmaDdiCmdInit(pCmd, u32FenceId, pContext, vboxVdmaDdiCmdCompletionCbFree, NULL);
1547 NTSTATUS Status = vboxVdmaDdiCmdCompleted(pDevExt, &pDevExt->DdiCmdQueue, pCmd);
1548 Assert(Status == STATUS_SUCCESS);
1549 if (Status == STATUS_SUCCESS)
1550 return STATUS_SUCCESS;
1551 vboxWddmMemFree(pCmd);
1552 return Status;
1553 }
1554 return STATUS_NO_MEMORY;
1555}
1556
1557#ifdef VBOXWDDM_RENDER_FROM_SHADOW
1558NTSTATUS vboxVdmaHlpUpdatePrimary(PDEVICE_EXTENSION pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, RECT* pRect)
1559{
1560 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
1561 Assert(pSource->pPrimaryAllocation);
1562 Assert(pSource->pShadowAllocation);
1563 if (!pSource->pPrimaryAllocation)
1564 return STATUS_INVALID_PARAMETER;
1565 if (!pSource->pShadowAllocation)
1566 return STATUS_INVALID_PARAMETER;
1567
1568 Assert(pSource->pPrimaryAllocation->offVram != VBOXVIDEOOFFSET_VOID);
1569 Assert(pSource->pShadowAllocation->offVram != VBOXVIDEOOFFSET_VOID);
1570 if (pSource->pPrimaryAllocation->offVram == VBOXVIDEOOFFSET_VOID)
1571 return STATUS_INVALID_PARAMETER;
1572 if (pSource->pShadowAllocation->offVram == VBOXVIDEOOFFSET_VOID)
1573 return STATUS_INVALID_PARAMETER;
1574
1575 NTSTATUS Status = vboxVdmaGgDmaBltPerform(pDevExt, pSource->pShadowAllocation, pRect, pSource->pPrimaryAllocation, pRect);
1576 Assert(Status == STATUS_SUCCESS);
1577 return Status;
1578}
1579#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette