VirtualBox

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

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

Additions/WINNT/Graphics: more refactoring

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 57.1 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 DXGK_INTERRUPT_TYPE enmComplType = DXGK_INTERRUPT_DMA_COMPLETED;
720 switch (pDmaCmd->enmCmd)
721 {
722 case VBOXVDMACMD_TYPE_DMA_PRESENT_BLT:
723 {
724 PVBOXVDMAPIPE_CMD_DMACMD_BLT pBlt = (PVBOXVDMAPIPE_CMD_DMACMD_BLT)pDmaCmd;
725 PVBOXWDDM_ALLOCATION pDstAlloc = pBlt->Blt.DstAlloc.pAlloc;
726 PVBOXWDDM_ALLOCATION pSrcAlloc = pBlt->Blt.SrcAlloc.pAlloc;
727 BOOLEAN bComplete = TRUE;
728 switch (pDstAlloc->enmType)
729 {
730 case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
731 case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
732 {
733 if (pDstAlloc->bAssigned)
734 {
735 VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
736 Assert(pSource->pPrimaryAllocation == pDstAlloc);
737 switch (pSrcAlloc->enmType)
738 {
739 case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
740 {
741 Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_SYSTEM);
742
743 if (pBlt->Hdr.fFlags.b2DRelated || pBlt->Hdr.fFlags.b3DRelated)
744 {
745 POINT pos;
746 BOOLEAN bPosMoved = FALSE;
747 if (pBlt->Hdr.fFlags.b3DRelated)
748 {
749 pos = pSource->VScreenPos;
750 if (pos.x || pos.y)
751 {
752 vboxWddmBltPipeRectsTranslate(&pBlt->Blt.DstRects, pos.x, pos.y);
753 bPosMoved = TRUE;
754 }
755 Status = vboxVdmaGgDirtyRectsProcess(pDevExt, pContext, NULL, &pBlt->Blt.DstRects);
756 Assert(Status == STATUS_SUCCESS);
757 }
758
759
760 if (pBlt->Hdr.fFlags.b2DRelated)
761 {
762 if (bPosMoved)
763 {
764 vboxWddmBltPipeRectsTranslate(&pBlt->Blt.DstRects, -pos.x, -pos.y);
765 }
766
767 RECT OverlayUnionRect;
768 RECT UpdateRect;
769 UpdateRect = pBlt->Blt.DstRects.UpdateRects.aRects[0];
770 for (UINT i = 1; i < pBlt->Blt.DstRects.UpdateRects.cRects; ++i)
771 {
772 vboxWddmRectUnite(&UpdateRect, &pBlt->Blt.DstRects.UpdateRects.aRects[i]);
773 }
774 vboxVhwaHlpOverlayDstRectUnion(pDevExt, pDstAlloc->SurfDesc.VidPnSourceId, &OverlayUnionRect);
775 Assert(pBlt->Blt.DstRects.ContextRect.left == 0); /* <-| otherwise we would probably need to translate the UpdateRects to left;top first??*/
776 Assert(pBlt->Blt.DstRects.ContextRect.top == 0); /* <--| */
777 vboxVdmaDirtyRectsCalcIntersection(&OverlayUnionRect, &pBlt->Blt.DstRects.UpdateRects, &pBlt->Blt.DstRects.UpdateRects);
778 if (pBlt->Blt.DstRects.UpdateRects.cRects)
779 {
780 vboxVdmaGgDmaBlt(pBlt);
781 }
782 VBOXVBVA_OP_WITHLOCK(ReportDirtyRect, pDevExt, pSource, &UpdateRect);
783 }
784 }
785
786 break;
787 }
788 case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
789 {
790 Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D);
791 Assert(pSrcAlloc->fRcFlags.RenderTarget);
792 if (pSrcAlloc->fRcFlags.RenderTarget)
793 {
794 if (pBlt->Hdr.fFlags.b3DRelated)
795 {
796 PVBOXWDDM_SWAPCHAIN pSwapchain;
797 pSwapchain = vboxWddmSwapchainRetainByAlloc(pDevExt, pSrcAlloc);
798 if (pSwapchain)
799 {
800 Status = vboxVdmaGgDirtyRectsProcess(pDevExt, pContext, pSwapchain, &pBlt->Blt.DstRects);
801 Assert(Status == STATUS_SUCCESS);
802 vboxWddmSwapchainRelease(pSwapchain);
803 }
804 }
805 }
806 break;
807 }
808 default:
809 AssertBreakpoint();
810 break;
811 }
812 }
813 break;
814 }
815 default:
816 Assert(0);
817 }
818
819 break;
820 }
821 case VBOXVDMACMD_TYPE_DMA_PRESENT_FLIP:
822 {
823 PVBOXVDMAPIPE_CMD_DMACMD_FLIP pFlip = (PVBOXVDMAPIPE_CMD_DMACMD_FLIP)pDmaCmd;
824 Assert(pFlip->Hdr.fFlags.b3DRelated);
825 Assert(!pFlip->Hdr.fFlags.bDecVBVAUnlock);
826 Assert(!pFlip->Hdr.fFlags.b2DRelated);
827 PVBOXWDDM_ALLOCATION pAlloc = pFlip->Flip.Alloc.pAlloc;
828 VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pAlloc->SurfDesc.VidPnSourceId];
829 if (pFlip->Hdr.fFlags.b3DRelated)
830 {
831 PVBOXWDDM_SWAPCHAIN pSwapchain;
832 pSwapchain = vboxWddmSwapchainRetainByAlloc(pDevExt, pAlloc);
833 if (pSwapchain)
834 {
835 POINT pos = pSource->VScreenPos;
836 VBOXVDMAPIPE_RECTS Rects;
837 Rects.ContextRect.left = pos.x;
838 Rects.ContextRect.top = pos.y;
839 Rects.ContextRect.right = pAlloc->SurfDesc.width + pos.x;
840 Rects.ContextRect.bottom = pAlloc->SurfDesc.height + pos.y;
841 Rects.UpdateRects.cRects = 1;
842 Rects.UpdateRects.aRects[0] = Rects.ContextRect;
843 Status = vboxVdmaGgDirtyRectsProcess(pDevExt, pContext, pSwapchain, &Rects);
844 Assert(Status == STATUS_SUCCESS);
845 vboxWddmSwapchainRelease(pSwapchain);
846 }
847 }
848
849 break;
850 }
851 case VBOXVDMACMD_TYPE_DMA_PRESENT_CLRFILL:
852 {
853 PVBOXVDMAPIPE_CMD_DMACMD_CLRFILL pCF = (PVBOXVDMAPIPE_CMD_DMACMD_CLRFILL)pDmaCmd;
854 Assert(pCF->Hdr.fFlags.b2DRelated);
855 Assert(pCF->Hdr.fFlags.bDecVBVAUnlock);
856 Assert(!pCF->Hdr.fFlags.b3DRelated);
857 Status = vboxVdmaGgDmaColorFill(pCF);
858 Assert(Status == STATUS_SUCCESS);
859 break;
860 }
861 default:
862 Assert(0);
863 break;
864 }
865
866 if (pDmaCmd->fFlags.bDecVBVAUnlock)
867 {
868 uint32_t cNew = ASMAtomicDecU32(&pDevExt->cUnlockedVBVADisabled);
869 Assert(cNew < UINT32_MAX/2);
870 }
871
872 Status = vboxVdmaDdiCmdCompleted(pDevExt, &pDevExt->DdiCmdQueue, &pDmaCmd->DdiCmd, enmComplType);
873 Assert(Status == STATUS_SUCCESS);
874
875 return Status;
876}
877
878static VOID vboxVdmaGgWorkerThread(PVOID pvUser)
879{
880 PVBOXVDMAGG pVdma = (PVBOXVDMAGG)pvUser;
881
882 NTSTATUS Status = vboxVdmaPipeSvrOpen(&pVdma->CmdPipe);
883 Assert(Status == STATUS_SUCCESS);
884 if (Status == STATUS_SUCCESS)
885 {
886 do
887 {
888 LIST_ENTRY CmdList;
889 Status = vboxVdmaPipeSvrCmdGetList(&pVdma->CmdPipe, &CmdList);
890 Assert(Status == STATUS_SUCCESS || Status == STATUS_PIPE_CLOSING);
891 if (Status == STATUS_SUCCESS)
892 {
893 for (PLIST_ENTRY pCur = CmdList.Blink; pCur != &CmdList;)
894 {
895 PVBOXVDMAPIPE_CMD_DR pDr = VBOXVDMAPIPE_CMD_DR_FROM_ENTRY(pCur);
896 RemoveEntryList(pCur);
897 pCur = CmdList.Blink;
898 switch (pDr->enmType)
899 {
900#if 0
901 case VBOXVDMAPIPE_CMD_TYPE_RECTSINFO:
902 {
903 PVBOXVDMAPIPE_CMD_RECTSINFO pRects = (PVBOXVDMAPIPE_CMD_RECTSINFO)pDr;
904 Status = vboxVdmaGgDirtyRectsProcess(pRects);
905 Assert(Status == STATUS_SUCCESS);
906 vboxVdmaGgCmdDestroy(pDr);
907 break;
908 }
909#endif
910 case VBOXVDMAPIPE_CMD_TYPE_DMACMD:
911 {
912 PVBOXVDMAPIPE_CMD_DMACMD pDmaCmd = (PVBOXVDMAPIPE_CMD_DMACMD)pDr;
913 Status = vboxVdmaGgDmaCmdProcess(pDmaCmd);
914 Assert(Status == STATUS_SUCCESS);
915 } break;
916 default:
917 AssertBreakpoint();
918 }
919 }
920 }
921 else
922 break;
923 } while (1);
924 }
925
926 /* always try to close the pipe to make sure the client side is notified */
927 Status = vboxVdmaPipeSvrClose(&pVdma->CmdPipe);
928 Assert(Status == STATUS_SUCCESS);
929}
930
931NTSTATUS vboxVdmaGgConstruct(PVBOXVDMAGG pVdma)
932{
933 NTSTATUS Status = vboxVdmaPipeConstruct(&pVdma->CmdPipe);
934 Assert(Status == STATUS_SUCCESS);
935 if (Status == STATUS_SUCCESS)
936 {
937 Status = vboxVdmaGgThreadCreate(&pVdma->pThread, vboxVdmaGgWorkerThread, pVdma);
938 Assert(Status == STATUS_SUCCESS);
939 if (Status == STATUS_SUCCESS)
940 return STATUS_SUCCESS;
941
942 NTSTATUS tmpStatus = vboxVdmaPipeDestruct(&pVdma->CmdPipe);
943 Assert(tmpStatus == STATUS_SUCCESS);
944 }
945
946 /* we're here ONLY in case of an error */
947 Assert(Status != STATUS_SUCCESS);
948 return Status;
949}
950
951NTSTATUS vboxVdmaGgDestruct(PVBOXVDMAGG pVdma)
952{
953 /* this informs the server thread that it should complete all current commands and exit */
954 NTSTATUS Status = vboxVdmaPipeCltClose(&pVdma->CmdPipe);
955 Assert(Status == STATUS_SUCCESS);
956 if (Status == STATUS_SUCCESS)
957 {
958 Status = KeWaitForSingleObject(pVdma->pThread, Executive, KernelMode, FALSE, NULL /* PLARGE_INTEGER Timeout */);
959 Assert(Status == STATUS_SUCCESS);
960 if (Status == STATUS_SUCCESS)
961 {
962 Status = vboxVdmaPipeDestruct(&pVdma->CmdPipe);
963 Assert(Status == STATUS_SUCCESS);
964 }
965 }
966
967 return Status;
968}
969
970NTSTATUS vboxVdmaGgCmdSubmit(PVBOXVDMAGG pVdma, PVBOXVDMAPIPE_CMD_DR pCmd)
971{
972 return vboxVdmaPipeCltCmdPut(&pVdma->CmdPipe, &pCmd->PipeHdr);
973}
974
975/* end */
976
977#ifdef VBOX_WITH_VDMA
978/*
979 * This is currently used by VDMA. It is invisible for Vdma API clients since
980 * Vdma transport may change if we choose to use another (e.g. more light-weight)
981 * transport for DMA commands submission
982 */
983
984#ifdef VBOXVDMA_WITH_VBVA
985static int vboxWddmVdmaSubmitVbva(struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo, HGSMIOFFSET offDr)
986{
987 int rc;
988 if (vboxVbvaBufferBeginUpdate (pDevExt, &pDevExt->u.primary.Vbva))
989 {
990 rc = vboxVbvaReportCmdOffset(pDevExt, &pDevExt->u.primary.Vbva, offDr);
991 vboxVbvaBufferEndUpdate (pDevExt, &pDevExt->u.primary.Vbva);
992 }
993 else
994 {
995 AssertBreakpoint();
996 rc = VERR_INVALID_STATE;
997 }
998 return rc;
999}
1000#define vboxWddmVdmaSubmit vboxWddmVdmaSubmitVbva
1001#else
1002static int vboxWddmVdmaSubmitHgsmi(struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo, HGSMIOFFSET offDr)
1003{
1004 VBoxHGSMIGuestWrite(commonFromDeviceExt(pDevExt), offDr);
1005 return VINF_SUCCESS;
1006}
1007#define vboxWddmVdmaSubmit vboxWddmVdmaSubmitHgsmi
1008#endif
1009
1010static int vboxVdmaInformHost(PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo, VBOXVDMA_CTL_TYPE enmCtl)
1011{
1012 int rc = VINF_SUCCESS;
1013
1014 PVBOXVDMA_CTL pCmd = (PVBOXVDMA_CTL)VBoxSHGSMICommandAlloc(&commonFromDeviceExt(pDevExt)->hgsmiAdapterHeap, sizeof (VBOXVDMA_CTL), HGSMI_CH_VBVA, VBVA_VDMA_CTL);
1015 if (pCmd)
1016 {
1017 pCmd->enmCtl = enmCtl;
1018 pCmd->u32Offset = pInfo->CmdHeap.area.offBase;
1019 pCmd->i32Result = VERR_NOT_SUPPORTED;
1020
1021 const VBOXSHGSMIHEADER* pHdr = VBoxSHGSMICommandPrepSynch(&commonFromDeviceExt(pDevExt)->hgsmiAdapterHeap, pCmd);
1022 Assert(pHdr);
1023 if (pHdr)
1024 {
1025 do
1026 {
1027 HGSMIOFFSET offCmd = VBoxSHGSMICommandOffset(&commonFromDeviceExt(pDevExt)->hgsmiAdapterHeap, pHdr);
1028 Assert(offCmd != HGSMIOFFSET_VOID);
1029 if (offCmd != HGSMIOFFSET_VOID)
1030 {
1031 rc = vboxWddmVdmaSubmit(pDevExt, pInfo, offCmd);
1032 AssertRC(rc);
1033 if (RT_SUCCESS(rc))
1034 {
1035 rc = VBoxSHGSMICommandDoneSynch(&commonFromDeviceExt(pDevExt)->hgsmiAdapterHeap, pHdr);
1036 AssertRC(rc);
1037 if (RT_SUCCESS(rc))
1038 {
1039 rc = pCmd->i32Result;
1040 AssertRC(rc);
1041 }
1042 break;
1043 }
1044 }
1045 else
1046 rc = VERR_INVALID_PARAMETER;
1047 /* fail to submit, cancel it */
1048 VBoxSHGSMICommandCancelSynch(&commonFromDeviceExt(pDevExt)->hgsmiAdapterHeap, pHdr);
1049 } while (0);
1050 }
1051
1052 VBoxSHGSMICommandFree (&commonFromDeviceExt(pDevExt)->hgsmiAdapterHeap, pCmd);
1053 }
1054 else
1055 {
1056 drprintf((__FUNCTION__": HGSMIHeapAlloc failed\n"));
1057 rc = VERR_OUT_OF_RESOURCES;
1058 }
1059
1060 return rc;
1061}
1062#endif
1063
1064/* create a DMACommand buffer */
1065int vboxVdmaCreate(PDEVICE_EXTENSION pDevExt, VBOXVDMAINFO *pInfo
1066#ifdef VBOX_WITH_VDMA
1067 , ULONG offBuffer, ULONG cbBuffer
1068#endif
1069 )
1070{
1071 int rc;
1072 pInfo->fEnabled = FALSE;
1073
1074#ifdef VBOX_WITH_VDMA
1075 Assert((offBuffer & 0xfff) == 0);
1076 Assert((cbBuffer & 0xfff) == 0);
1077 Assert(offBuffer);
1078 Assert(cbBuffer);
1079
1080 if((offBuffer & 0xfff)
1081 || (cbBuffer & 0xfff)
1082 || !offBuffer
1083 || !cbBuffer)
1084 {
1085 drprintf((__FUNCTION__": invalid parameters: offBuffer(0x%x), cbBuffer(0x%x)", offBuffer, cbBuffer));
1086 return VERR_INVALID_PARAMETER;
1087 }
1088 PVOID pvBuffer;
1089
1090 rc = VBoxMapAdapterMemory (pDevExt,
1091 &pvBuffer,
1092 offBuffer,
1093 cbBuffer);
1094 Assert(RT_SUCCESS(rc));
1095 if (RT_SUCCESS(rc))
1096 {
1097 /* Setup a HGSMI heap within the adapter information area. */
1098 rc = HGSMIHeapSetup (&pInfo->CmdHeap,
1099 pvBuffer,
1100 cbBuffer,
1101 offBuffer,
1102 false /*fOffsetBased*/);
1103 Assert(RT_SUCCESS(rc));
1104 if(RT_SUCCESS(rc))
1105#endif
1106 {
1107 NTSTATUS Status = vboxVdmaGgConstruct(&pInfo->DmaGg);
1108 Assert(Status == STATUS_SUCCESS);
1109 if (Status == STATUS_SUCCESS)
1110 return VINF_SUCCESS;
1111 rc = VERR_GENERAL_FAILURE;
1112 }
1113#ifdef VBOX_WITH_VDMA
1114 else
1115 drprintf((__FUNCTION__": HGSMIHeapSetup failed rc = 0x%x\n", rc));
1116
1117 VBoxUnmapAdapterMemory(pDevExt, &pvBuffer, cbBuffer);
1118 }
1119 else
1120 drprintf((__FUNCTION__": VBoxMapAdapterMemory failed rc = 0x%x\n", rc));
1121#endif
1122 return rc;
1123}
1124
1125int vboxVdmaDisable (PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo)
1126{
1127 dfprintf((__FUNCTION__"\n"));
1128
1129 Assert(pInfo->fEnabled);
1130 if (!pInfo->fEnabled)
1131 return VINF_ALREADY_INITIALIZED;
1132
1133 /* ensure nothing else is submitted */
1134 pInfo->fEnabled = FALSE;
1135#ifdef VBOX_WITH_VDMA
1136 int rc = vboxVdmaInformHost (pDevExt, pInfo, VBOXVDMA_CTL_TYPE_DISABLE);
1137 AssertRC(rc);
1138 return rc;
1139#else
1140 return VINF_SUCCESS;
1141#endif
1142}
1143
1144int vboxVdmaEnable (PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo)
1145{
1146 dfprintf((__FUNCTION__"\n"));
1147
1148 Assert(!pInfo->fEnabled);
1149 if (pInfo->fEnabled)
1150 return VINF_ALREADY_INITIALIZED;
1151#ifdef VBOX_WITH_VDMA
1152 int rc = vboxVdmaInformHost (pDevExt, pInfo, VBOXVDMA_CTL_TYPE_ENABLE);
1153 Assert(RT_SUCCESS(rc));
1154 if (RT_SUCCESS(rc))
1155 pInfo->fEnabled = TRUE;
1156
1157 return rc;
1158#else
1159 return VINF_SUCCESS;
1160#endif
1161}
1162
1163#ifdef VBOX_WITH_VDMA
1164int vboxVdmaFlush (PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo)
1165{
1166 dfprintf((__FUNCTION__"\n"));
1167
1168 Assert(pInfo->fEnabled);
1169 if (!pInfo->fEnabled)
1170 return VINF_ALREADY_INITIALIZED;
1171
1172 int rc = vboxVdmaInformHost (pDevExt, pInfo, VBOXVDMA_CTL_TYPE_FLUSH);
1173 Assert(RT_SUCCESS(rc));
1174
1175 return rc;
1176}
1177#endif
1178
1179int vboxVdmaDestroy (PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo)
1180{
1181 int rc = VINF_SUCCESS;
1182 NTSTATUS Status = vboxVdmaGgDestruct(&pInfo->DmaGg);
1183 Assert(Status == STATUS_SUCCESS);
1184 if (Status == STATUS_SUCCESS)
1185 {
1186 Assert(!pInfo->fEnabled);
1187 if (pInfo->fEnabled)
1188 rc = vboxVdmaDisable (pDevExt, pInfo);
1189#ifdef VBOX_WITH_VDMA
1190 VBoxUnmapAdapterMemory (pDevExt, (void**)&pInfo->CmdHeap.area.pu8Base, pInfo->CmdHeap.area.cbArea);
1191#endif
1192 }
1193 else
1194 rc = VERR_GENERAL_FAILURE;
1195 return rc;
1196}
1197
1198#ifdef VBOX_WITH_VDMA
1199void vboxVdmaCBufDrFree (PVBOXVDMAINFO pInfo, PVBOXVDMACBUF_DR pDr)
1200{
1201 VBoxSHGSMICommandFree (&pInfo->CmdHeap, pDr);
1202}
1203
1204PVBOXVDMACBUF_DR vboxVdmaCBufDrCreate (PVBOXVDMAINFO pInfo, uint32_t cbTrailingData)
1205{
1206 uint32_t cbDr = VBOXVDMACBUF_DR_SIZE(cbTrailingData);
1207 PVBOXVDMACBUF_DR pDr = (PVBOXVDMACBUF_DR)VBoxSHGSMICommandAlloc (&pInfo->CmdHeap, cbDr, HGSMI_CH_VBVA, VBVA_VDMA_CMD);
1208 Assert(pDr);
1209 if (pDr)
1210 memset (pDr, 0, cbDr);
1211 else
1212 drprintf((__FUNCTION__": VBoxSHGSMICommandAlloc returned NULL\n"));
1213
1214 return pDr;
1215}
1216
1217static DECLCALLBACK(void) vboxVdmaCBufDrCompletion(struct _HGSMIHEAP * pHeap, void *pvCmd, void *pvContext)
1218{
1219 PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION)pvContext;
1220 PVBOXVDMAINFO pInfo = &pDevExt->u.primary.Vdma;
1221
1222 vboxVdmaCBufDrFree (pInfo, (PVBOXVDMACBUF_DR)pvCmd);
1223}
1224
1225static DECLCALLBACK(void) vboxVdmaCBufDrCompletionIrq(struct _HGSMIHEAP * pHeap, void *pvCmd, void *pvContext,
1226 PFNVBOXSHGSMICMDCOMPLETION *ppfnCompletion, void **ppvCompletion)
1227{
1228 PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION)pvContext;
1229 PVBOXVDMAINFO pVdma = &pDevExt->u.primary.Vdma;
1230 PVBOXVDMACBUF_DR pDr = (PVBOXVDMACBUF_DR)pvCmd;
1231
1232 DXGK_INTERRUPT_TYPE enmComplType;
1233
1234 if (RT_SUCCESS(pDr->rc))
1235 {
1236 enmComplType = DXGK_INTERRUPT_DMA_COMPLETED;
1237 }
1238 else if (pDr->rc == VERR_INTERRUPTED)
1239 {
1240 Assert(0);
1241 enmComplType = DXGK_INTERRUPT_DMA_PREEMPTED;
1242 }
1243 else
1244 {
1245 Assert(0);
1246 enmComplType = DXGK_INTERRUPT_DMA_FAULTED;
1247 }
1248
1249 if (vboxVdmaDdiCmdCompletedIrq(pDevExt, &pDevExt->DdiCmdQueue, VBOXVDMADDI_CMD_FROM_BUF_DR(pDr), enmComplType))
1250 {
1251 pDevExt->bNotifyDxDpc = TRUE;
1252 }
1253
1254 /* inform SHGSMI we DO NOT want to be called at DPC later */
1255 *ppfnCompletion = NULL;
1256// *ppvCompletion = pvContext;
1257}
1258
1259int vboxVdmaCBufDrSubmit(PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo, PVBOXVDMACBUF_DR pDr)
1260{
1261 const VBOXSHGSMIHEADER* pHdr = VBoxSHGSMICommandPrepAsynchIrq (&pInfo->CmdHeap, pDr, vboxVdmaCBufDrCompletionIrq, pDevExt, VBOXSHGSMI_FLAG_GH_ASYNCH_FORCE);
1262 Assert(pHdr);
1263 int rc = VERR_GENERAL_FAILURE;
1264 if (pHdr)
1265 {
1266 do
1267 {
1268 HGSMIOFFSET offCmd = VBoxSHGSMICommandOffset(&pInfo->CmdHeap, pHdr);
1269 Assert(offCmd != HGSMIOFFSET_VOID);
1270 if (offCmd != HGSMIOFFSET_VOID)
1271 {
1272 rc = vboxWddmVdmaSubmit(pDevExt, pInfo, offCmd);
1273 AssertRC(rc);
1274 if (RT_SUCCESS(rc))
1275 {
1276 VBoxSHGSMICommandDoneAsynch(&pInfo->CmdHeap, pHdr);
1277 AssertRC(rc);
1278 break;
1279 }
1280 }
1281 else
1282 rc = VERR_INVALID_PARAMETER;
1283 /* fail to submit, cancel it */
1284 VBoxSHGSMICommandCancelAsynch(&pInfo->CmdHeap, pHdr);
1285 } while (0);
1286 }
1287 else
1288 rc = VERR_INVALID_PARAMETER;
1289 return rc;
1290}
1291#endif
1292
1293
1294/* ddi dma command queue */
1295DECLINLINE(BOOLEAN) vboxVdmaDdiCmdCanComplete(PVBOXVDMADDI_CMD_QUEUE pQueue)
1296{
1297 return ASMAtomicUoReadU32(&pQueue->cQueuedCmds) == 0;
1298}
1299
1300DECLCALLBACK(VOID) vboxVdmaDdiCmdCompletionCbFree(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext)
1301{
1302 vboxWddmMemFree(pCmd);
1303}
1304
1305static VOID vboxVdmaDdiCmdNotifyCompletedIrq(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd, DXGK_INTERRUPT_TYPE enmComplType)
1306{
1307 DXGKARGCB_NOTIFY_INTERRUPT_DATA notify;
1308 memset(&notify, 0, sizeof(DXGKARGCB_NOTIFY_INTERRUPT_DATA));
1309 switch (enmComplType)
1310 {
1311 case DXGK_INTERRUPT_DMA_COMPLETED:
1312 notify.InterruptType = DXGK_INTERRUPT_DMA_COMPLETED;
1313 notify.DmaCompleted.SubmissionFenceId = pCmd->u32FenceId;
1314 if (pCmd->pContext)
1315 {
1316 notify.DmaCompleted.NodeOrdinal = pCmd->pContext->NodeOrdinal;
1317 pCmd->pContext->uLastCompletedCmdFenceId = pCmd->u32FenceId;
1318 }
1319 else
1320 {
1321 pDevExt->u.primary.Vdma.uLastCompletedPagingBufferCmdFenceId = pCmd->u32FenceId;
1322 }
1323
1324 InsertTailList(&pQueue->DpcCmdQueue, &pCmd->QueueEntry);
1325
1326 break;
1327 case DXGK_INTERRUPT_DMA_PREEMPTED:
1328 Assert(0);
1329 notify.InterruptType = DXGK_INTERRUPT_DMA_PREEMPTED;
1330 notify.DmaPreempted.PreemptionFenceId = pCmd->u32FenceId;
1331 if (pCmd->pContext)
1332 {
1333 notify.DmaPreempted.LastCompletedFenceId = pCmd->pContext->uLastCompletedCmdFenceId;
1334 notify.DmaPreempted.NodeOrdinal = pCmd->pContext->NodeOrdinal;
1335 }
1336 else
1337 {
1338 notify.DmaPreempted.LastCompletedFenceId = pDevExt->u.primary.Vdma.uLastCompletedPagingBufferCmdFenceId;
1339 }
1340 break;
1341
1342 case DXGK_INTERRUPT_DMA_FAULTED:
1343 Assert(0);
1344 notify.InterruptType = DXGK_INTERRUPT_DMA_FAULTED;
1345 notify.DmaFaulted.FaultedFenceId = pCmd->u32FenceId;
1346 notify.DmaFaulted.Status = STATUS_UNSUCCESSFUL; /* @todo: better status ? */
1347 if (pCmd->pContext)
1348 {
1349 notify.DmaFaulted.NodeOrdinal = pCmd->pContext->NodeOrdinal;
1350 }
1351 break;
1352 default:
1353 Assert(0);
1354 break;
1355 }
1356
1357 pDevExt->u.primary.DxgkInterface.DxgkCbNotifyInterrupt(pDevExt->u.primary.DxgkInterface.DeviceHandle, &notify);
1358}
1359
1360DECLINLINE(VOID) vboxVdmaDdiCmdDequeueIrq(PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1361{
1362 ASMAtomicDecU32(&pQueue->cQueuedCmds);
1363 RemoveEntryList(&pCmd->QueueEntry);
1364}
1365
1366DECLINLINE(VOID) vboxVdmaDdiCmdEnqueueIrq(PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1367{
1368 ASMAtomicIncU32(&pQueue->cQueuedCmds);
1369 InsertTailList(&pQueue->CmdQueue, &pCmd->QueueEntry);
1370}
1371
1372VOID vboxVdmaDdiQueueInit(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue)
1373{
1374 pQueue->cQueuedCmds = 0;
1375 InitializeListHead(&pQueue->CmdQueue);
1376 InitializeListHead(&pQueue->DpcCmdQueue);
1377}
1378
1379BOOLEAN vboxVdmaDdiCmdCompletedIrq(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd, DXGK_INTERRUPT_TYPE enmComplType)
1380{
1381 BOOLEAN bQueued = pCmd->enmState > VBOXVDMADDI_STATE_NOT_QUEUED;
1382 BOOLEAN bComplete = FALSE;
1383 Assert(!bQueued || pQueue->cQueuedCmds);
1384 Assert(!bQueued || !IsListEmpty(&pQueue->CmdQueue));
1385 pCmd->enmState = VBOXVDMADDI_STATE_COMPLETED;
1386 if (bQueued)
1387 {
1388 if (pQueue->CmdQueue.Flink == &pCmd->QueueEntry)
1389 {
1390 vboxVdmaDdiCmdDequeueIrq(pQueue, pCmd);
1391 bComplete = TRUE;
1392 }
1393 }
1394 else if (IsListEmpty(&pQueue->CmdQueue))
1395 {
1396 bComplete = TRUE;
1397 }
1398 else
1399 {
1400 vboxVdmaDdiCmdEnqueueIrq(pQueue, pCmd);
1401 }
1402
1403 if (bComplete)
1404 {
1405 vboxVdmaDdiCmdNotifyCompletedIrq(pDevExt, pQueue, pCmd, enmComplType);
1406
1407 while (!IsListEmpty(&pQueue->CmdQueue))
1408 {
1409 pCmd = VBOXVDMADDI_CMD_FROM_ENTRY(pQueue->CmdQueue.Flink);
1410 if (pCmd->enmState == VBOXVDMADDI_STATE_COMPLETED)
1411 {
1412 vboxVdmaDdiCmdDequeueIrq(pQueue, pCmd);
1413 vboxVdmaDdiCmdNotifyCompletedIrq(pDevExt, pQueue, pCmd, pCmd->enmComplType);
1414 }
1415 else
1416 break;
1417 }
1418 }
1419 else
1420 {
1421 pCmd->enmState = VBOXVDMADDI_STATE_COMPLETED;
1422 pCmd->enmComplType = enmComplType;
1423 }
1424
1425 return bComplete;
1426}
1427
1428VOID vboxVdmaDdiCmdSubmittedIrq(PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1429{
1430 BOOLEAN bQueued = pCmd->enmState >= VBOXVDMADDI_STATE_PENDING;
1431 Assert(pCmd->enmState < VBOXVDMADDI_STATE_SUBMITTED);
1432 pCmd->enmState = VBOXVDMADDI_STATE_SUBMITTED;
1433 if (!bQueued)
1434 vboxVdmaDdiCmdEnqueueIrq(pQueue, pCmd);
1435}
1436
1437typedef struct VBOXVDMADDI_CMD_COMPLETED_CB
1438{
1439 PDEVICE_EXTENSION pDevExt;
1440 PVBOXVDMADDI_CMD_QUEUE pQueue;
1441 PVBOXVDMADDI_CMD pCmd;
1442 DXGK_INTERRUPT_TYPE enmComplType;
1443} VBOXVDMADDI_CMD_COMPLETED_CB, *PVBOXVDMADDI_CMD_COMPLETED_CB;
1444
1445static BOOLEAN vboxVdmaDdiCmdCompletedCb(PVOID Context)
1446{
1447 PVBOXVDMADDI_CMD_COMPLETED_CB pdc = (PVBOXVDMADDI_CMD_COMPLETED_CB)Context;
1448 BOOLEAN bNeedDps = vboxVdmaDdiCmdCompletedIrq(pdc->pDevExt, pdc->pQueue, pdc->pCmd, pdc->enmComplType);
1449 pdc->pDevExt->bNotifyDxDpc |= bNeedDps;
1450
1451 return bNeedDps;
1452}
1453
1454NTSTATUS vboxVdmaDdiCmdCompleted(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd, DXGK_INTERRUPT_TYPE enmComplType)
1455{
1456 VBOXVDMADDI_CMD_COMPLETED_CB context;
1457 context.pDevExt = pDevExt;
1458 context.pQueue = pQueue;
1459 context.pCmd = pCmd;
1460 context.enmComplType = enmComplType;
1461 BOOLEAN bNeedDps;
1462 NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbSynchronizeExecution(
1463 pDevExt->u.primary.DxgkInterface.DeviceHandle,
1464 vboxVdmaDdiCmdCompletedCb,
1465 &context,
1466 0, /* IN ULONG MessageNumber */
1467 &bNeedDps);
1468 Assert(Status == STATUS_SUCCESS);
1469 if (Status == STATUS_SUCCESS && bNeedDps)
1470 {
1471 BOOLEAN bRc = pDevExt->u.primary.DxgkInterface.DxgkCbQueueDpc(pDevExt->u.primary.DxgkInterface.DeviceHandle);
1472 Assert(bRc);
1473 }
1474 return Status;
1475}
1476
1477typedef struct VBOXVDMADDI_CMD_SUBMITTED_CB
1478{
1479// PDEVICE_EXTENSION pDevExt;
1480 PVBOXVDMADDI_CMD_QUEUE pQueue;
1481 PVBOXVDMADDI_CMD pCmd;
1482} VBOXVDMADDI_CMD_SUBMITTED_CB, *PVBOXVDMADDI_CMD_SUBMITTED_CB;
1483
1484static BOOLEAN vboxVdmaDdiCmdSubmittedCb(PVOID Context)
1485{
1486 PVBOXVDMADDI_CMD_SUBMITTED_CB pdc = (PVBOXVDMADDI_CMD_SUBMITTED_CB)Context;
1487 vboxVdmaDdiCmdSubmittedIrq(pdc->pQueue, pdc->pCmd);
1488
1489 return FALSE;
1490}
1491
1492NTSTATUS vboxVdmaDdiCmdSubmitted(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd)
1493{
1494 VBOXVDMADDI_CMD_SUBMITTED_CB context;
1495 context.pQueue = pQueue;
1496 context.pCmd = pCmd;
1497 BOOLEAN bRc;
1498 NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbSynchronizeExecution(
1499 pDevExt->u.primary.DxgkInterface.DeviceHandle,
1500 vboxVdmaDdiCmdSubmittedCb,
1501 &context,
1502 0, /* IN ULONG MessageNumber */
1503 &bRc);
1504 Assert(Status == STATUS_SUCCESS);
1505 return Status;
1506}
1507
1508typedef struct VBOXVDMADDI_CMD_COMPLETE_CB
1509{
1510 PDEVICE_EXTENSION pDevExt;
1511 PVBOXWDDM_CONTEXT pContext;
1512 uint32_t u32FenceId;
1513} VBOXVDMADDI_CMD_COMPLETE_CB, *PVBOXVDMADDI_CMD_COMPLETE_CB;
1514
1515static BOOLEAN vboxVdmaDdiCmdFenceCompleteCb(PVOID Context)
1516{
1517 PVBOXVDMADDI_CMD_COMPLETE_CB pdc = (PVBOXVDMADDI_CMD_COMPLETE_CB)Context;
1518 PDEVICE_EXTENSION pDevExt = pdc->pDevExt;
1519 DXGKARGCB_NOTIFY_INTERRUPT_DATA notify;
1520 memset(&notify, 0, sizeof(DXGKARGCB_NOTIFY_INTERRUPT_DATA));
1521
1522 notify.InterruptType = DXGK_INTERRUPT_DMA_COMPLETED;
1523 notify.DmaCompleted.SubmissionFenceId = pdc->u32FenceId;
1524 notify.DmaCompleted.NodeOrdinal = pdc->pContext->NodeOrdinal;
1525 notify.DmaCompleted.EngineOrdinal = 0;
1526
1527 pDevExt->u.primary.DxgkInterface.DxgkCbNotifyInterrupt(pDevExt->u.primary.DxgkInterface.DeviceHandle, &notify);
1528
1529 pDevExt->bNotifyDxDpc = TRUE;
1530 BOOLEAN bDpcQueued = pDevExt->u.primary.DxgkInterface.DxgkCbQueueDpc(pDevExt->u.primary.DxgkInterface.DeviceHandle);
1531 Assert(bDpcQueued);
1532
1533 return bDpcQueued;
1534}
1535
1536static NTSTATUS vboxVdmaDdiCmdFenceNotifyComplete(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_CONTEXT pContext, uint32_t u32FenceId)
1537{
1538 VBOXVDMADDI_CMD_COMPLETE_CB context;
1539 context.pDevExt = pDevExt;
1540 context.pContext = pContext;
1541 context.u32FenceId = u32FenceId;
1542 BOOLEAN bRet;
1543 NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbSynchronizeExecution(
1544 pDevExt->u.primary.DxgkInterface.DeviceHandle,
1545 vboxVdmaDdiCmdFenceCompleteCb,
1546 &context,
1547 0, /* IN ULONG MessageNumber */
1548 &bRet);
1549 Assert(Status == STATUS_SUCCESS);
1550 return Status;
1551}
1552
1553NTSTATUS vboxVdmaDdiCmdFenceComplete(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_CONTEXT pContext, uint32_t u32FenceId, DXGK_INTERRUPT_TYPE enmComplType)
1554{
1555 if (vboxVdmaDdiCmdCanComplete(&pDevExt->DdiCmdQueue))
1556 return vboxVdmaDdiCmdFenceNotifyComplete(pDevExt, pContext, u32FenceId);
1557
1558 PVBOXVDMADDI_CMD pCmd = (PVBOXVDMADDI_CMD)vboxWddmMemAlloc(sizeof (VBOXVDMADDI_CMD));
1559 Assert(pCmd);
1560 if (pCmd)
1561 {
1562 vboxVdmaDdiCmdInit(pCmd, u32FenceId, pContext, vboxVdmaDdiCmdCompletionCbFree, NULL);
1563 NTSTATUS Status = vboxVdmaDdiCmdCompleted(pDevExt, &pDevExt->DdiCmdQueue, pCmd, enmComplType);
1564 Assert(Status == STATUS_SUCCESS);
1565 if (Status == STATUS_SUCCESS)
1566 return STATUS_SUCCESS;
1567 vboxWddmMemFree(pCmd);
1568 return Status;
1569 }
1570 return STATUS_NO_MEMORY;
1571}
1572
1573#ifdef VBOXWDDM_RENDER_FROM_SHADOW
1574NTSTATUS vboxVdmaHlpUpdatePrimary(PDEVICE_EXTENSION pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, RECT* pRect)
1575{
1576 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
1577 Assert(pSource->pPrimaryAllocation);
1578 Assert(pSource->pShadowAllocation);
1579 if (!pSource->pPrimaryAllocation)
1580 return STATUS_INVALID_PARAMETER;
1581 if (!pSource->pShadowAllocation)
1582 return STATUS_INVALID_PARAMETER;
1583
1584 Assert(pSource->pPrimaryAllocation->offVram != VBOXVIDEOOFFSET_VOID);
1585 Assert(pSource->pShadowAllocation->offVram != VBOXVIDEOOFFSET_VOID);
1586 if (pSource->pPrimaryAllocation->offVram == VBOXVIDEOOFFSET_VOID)
1587 return STATUS_INVALID_PARAMETER;
1588 if (pSource->pShadowAllocation->offVram == VBOXVIDEOOFFSET_VOID)
1589 return STATUS_INVALID_PARAMETER;
1590
1591 NTSTATUS Status = vboxVdmaGgDmaBltPerform(pDevExt, pSource->pShadowAllocation, pRect, pSource->pPrimaryAllocation, pRect);
1592 Assert(Status == STATUS_SUCCESS);
1593 return Status;
1594}
1595#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