VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVbva.h@ 49591

Last change on this file since 49591 was 49591, checked in by vboxsync, 11 years ago

wddm: more on new comand mechanism, guest side almost done, some cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/* $Id: VBoxMPVbva.h 49591 2013-11-20 17:53:55Z vboxsync $ */
2
3/** @file
4 * VBox WDDM Miniport driver
5 */
6
7/*
8 * Copyright (C) 2011 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef ___VBoxMPVbva_h___
20#define ___VBoxMPVbva_h___
21
22typedef struct VBOXVBVAINFO
23{
24 VBVABUFFERCONTEXT Vbva;
25 D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId;
26 KSPIN_LOCK Lock;
27} VBOXVBVAINFO;
28
29int vboxVbvaEnable(PVBOXMP_DEVEXT pDevExt, VBOXVBVAINFO *pVbva);
30int vboxVbvaDisable(PVBOXMP_DEVEXT pDevExt, VBOXVBVAINFO *pVbva);
31int vboxVbvaDestroy(PVBOXMP_DEVEXT pDevExt, VBOXVBVAINFO *pVbva);
32int vboxVbvaCreate(PVBOXMP_DEVEXT pDevExt, VBOXVBVAINFO *pVbva, ULONG offBuffer, ULONG cbBuffer, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId);
33int vboxVbvaReportDirtyRect(PVBOXMP_DEVEXT pDevExt, struct VBOXWDDM_SOURCE *pSrc, RECT *pRectOrig);
34
35#define VBOXVBVA_OP(_op, _pdext, _psrc, _arg) \
36 do { \
37 if (VBoxVBVABufferBeginUpdate(&(_psrc)->Vbva.Vbva, &VBoxCommonFromDeviceExt(_pdext)->guestCtx)) \
38 { \
39 vboxVbva##_op(_pdext, _psrc, _arg); \
40 VBoxVBVABufferEndUpdate(&(_psrc)->Vbva.Vbva); \
41 } \
42 } while (0)
43
44#define VBOXVBVA_OP_WITHLOCK_ATDPC(_op, _pdext, _psrc, _arg) \
45 do { \
46 Assert(KeGetCurrentIrql() == DISPATCH_LEVEL); \
47 KeAcquireSpinLockAtDpcLevel(&(_psrc)->Vbva.Lock); \
48 VBOXVBVA_OP(_op, _pdext, _psrc, _arg); \
49 KeReleaseSpinLockFromDpcLevel(&(_psrc)->Vbva.Lock);\
50 } while (0)
51
52#define VBOXVBVA_OP_WITHLOCK(_op, _pdext, _psrc, _arg) \
53 do { \
54 KIRQL OldIrql; \
55 KeAcquireSpinLock(&(_psrc)->Vbva.Lock, &OldIrql); \
56 VBOXVBVA_OP(_op, _pdext, _psrc, _arg); \
57 KeReleaseSpinLock(&(_psrc)->Vbva.Lock, OldIrql); \
58 } while (0)
59
60
61/* customized VBVA implementation */
62struct VBVAEXBUFFERCONTEXT;
63
64typedef DECLCALLBACKPTR(void, PFNVBVAEXBUFFERFLUSH) (struct VBVAEXBUFFERCONTEXT *pCtx, PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx, void *pvFlush);
65
66/**
67 * Structure grouping the context needed for sending graphics acceleration
68 * information to the host via VBVA. Each screen has its own VBVA buffer.
69 */
70typedef struct VBVAEXBUFFERCONTEXT
71{
72 /** Offset of the buffer in the VRAM section for the screen */
73 uint32_t offVRAMBuffer;
74 /** Length of the buffer in bytes */
75 uint32_t cbBuffer;
76 /** This flag is set if we wrote to the buffer faster than the host could
77 * read it. */
78 bool fHwBufferOverflow;
79 /* VBVA operation used to enable/disable VBVA */
80 uint16_t u16EnableOp;
81 /* the window between indexRecordFirstUncompleted and pVBVA->::indexRecordFirst represents
82 * command records processed by the host, but not completed by the guest yet */
83 volatile uint32_t indexRecordFirstUncompleted;
84 /* the window between off32DataUncompleted and pVBVA->::off32Data represents
85 * command data processed by the host, but not completed by the guest yet */
86 uint32_t off32DataUncompleted;
87 /* flush function */
88 PFNVBVAEXBUFFERFLUSH pfnFlush;
89 void *pvFlush;
90 /** The VBVA record that we are currently preparing for the host, NULL if
91 * none. */
92 struct VBVARECORD *pRecord;
93 /** Pointer to the VBVA buffer mapped into the current address space. Will
94 * be NULL if VBVA is not enabled. */
95 struct VBVABUFFER *pVBVA;
96} VBVAEXBUFFERCONTEXT, *PVBVAEXBUFFERCONTEXT;
97
98typedef struct VBVAEXBUFFERITERBASE
99{
100 struct VBVAEXBUFFERCONTEXT *pCtx;
101 /* index of the current record */
102 uint32_t iCurRecord;
103 /* offset of the current command */
104 uint32_t off32CurCmd;
105} VBVAEXBUFFERITERBASE, *PVBVAEXBUFFERITERBASE;
106
107typedef struct VBVAEXBUFFERFORWARDITER
108{
109 VBVAEXBUFFERITERBASE Base;
110} VBVAEXBUFFERFORWARDITER, *PVBVAEXBUFFERFORWARDITER;
111
112typedef struct VBVAEXBUFFERBACKWARDITER
113{
114 VBVAEXBUFFERITERBASE Base;
115} VBVAEXBUFFERBACKWARDITER, *PVBVAEXBUFFERBACKWARDITER;
116
117#define VBOXCMDVBVA_BUFFERSIZE(_cbCmdApprox) (RT_OFFSETOF(VBVABUFFER, au8Data) + ((RT_SIZEOFMEMB(VBVABUFFER, aRecords)/RT_SIZEOFMEMB(VBVABUFFER, aRecords[0])) * (_cbCmdApprox)))
118
119typedef struct VBOXCMDVBVA
120{
121 VBVAEXBUFFERCONTEXT Vbva;
122
123 /* last completted fence id */
124 uint32_t u32FenceCompleted;
125 /* last submitted fence id */
126 uint32_t u32FenceSubmitted;
127
128 /* node ordinal */
129 uint32_t idNode;
130} VBOXCMDVBVA;
131
132/** @name VBVAEx APIs
133 * @{ */
134RTDECL(bool) VBoxVBVAExEnable(PVBVAEXBUFFERCONTEXT pCtx,
135 PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
136 struct VBVABUFFER *pVBVA);
137RTDECL(void) VBoxVBVAExDisable(PVBVAEXBUFFERCONTEXT pCtx,
138 PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx);
139RTDECL(bool) VBoxVBVAExBufferBeginUpdate(PVBVAEXBUFFERCONTEXT pCtx,
140 PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx);
141RTDECL(void) VBoxVBVAExBufferEndUpdate(PVBVAEXBUFFERCONTEXT pCtx);
142RTDECL(bool) VBoxVBVAExWrite(PVBVAEXBUFFERCONTEXT pCtx,
143 PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
144 const void *pv, uint32_t cb);
145
146RTDECL(bool) VBoxVBVAExOrderSupported(PVBVAEXBUFFERCONTEXT pCtx, unsigned code);
147
148RTDECL(void) VBoxVBVAExSetupBufferContext(PVBVAEXBUFFERCONTEXT pCtx,
149 uint32_t offVRAMBuffer,
150 uint32_t cbBuffer,
151 PFNVBVAEXBUFFERFLUSH pfnFlush,
152 void *pvFlush,
153 uint16_t u16EnableOp);
154
155DECLINLINE(uint32_t) VBoxVBVAExGetSize(PVBVAEXBUFFERCONTEXT pCtx)
156{
157 return pCtx->pVBVA->cbData;
158}
159
160/* can be used to ensure the command will not cross the ring buffer boundary,
161 * and thus will not be splitted */
162RTDECL(uint32_t) VBoxVBVAExGetFreeTail(PVBVAEXBUFFERCONTEXT pCtx);
163/* allocates a contiguous buffer of a given size, i.e. the one that is not splitted across ringbuffer boundaries */
164RTDECL(void*) VBoxVBVAExAllocContiguous(PVBVAEXBUFFERCONTEXT pCtx, PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx, uint32_t cb);
165/* answers whether host is in "processing" state now,
166 * i.e. if "processing" is true after the command is submitted, no notification is required to be posted to host to make the commandbe processed,
167 * otherwise, host should be notified about the command */
168RTDECL(bool) VBoxVBVAExIsProcessing(PVBVAEXBUFFERCONTEXT pCtx);
169
170/* initializes iterator that starts with free record,
171 * i.e. VBoxVBVAExIterNext would return the first uncompleted record.
172 *
173 * can be used by submitter only */
174RTDECL(void) VBoxVBVAExBIterInit(PVBVAEXBUFFERCONTEXT pCtx, PVBVAEXBUFFERBACKWARDITER pIter);
175/* can be used by submitter only */
176RTDECL(void*) VBoxVBVAExBIterNext(PVBVAEXBUFFERBACKWARDITER pIter, uint32_t *pcbBuffer, bool *pfProcessed);
177
178/* completer functions
179 * completer can only use below ones, and submitter is NOT allowed to use them.
180 * Completter functions are prefixed with VBoxVBVAExC as opposed to submitter ones,
181 * that do not have the last "C" in the prefix */
182/* initializes iterator that starts with completed record,
183 * i.e. VBoxVBVAExIterPrev would return the first uncompleted record.
184 * note that we can not have iterator that starts at processed record
185 * (i.e. the one processed by host, but not completed by guest, since host modifies
186 * VBVABUFFER::off32Data and VBVABUFFER::indexRecordFirst concurrently,
187 * and so we may end up with inconsistent index-offData pair
188 *
189 * can be used by completter only */
190RTDECL(void) VBoxVBVAExCFIterInit(PVBVAEXBUFFERCONTEXT pCtx, PVBVAEXBUFFERFORWARDITER pIter);
191/* can be used by completter only */
192RTDECL(void*) VBoxVBVAExCFIterNext(PVBVAEXBUFFERFORWARDITER pIter, uint32_t *pcbBuffer, bool *pfProcessed);
193
194RTDECL(void) VBoxVBVAExCBufferCompleted(PVBVAEXBUFFERCONTEXT pCtx);
195
196/** @} */
197
198struct VBOXCMDVBVA_HDR;
199
200int VBoxCmdVbvaEnable(PVBOXMP_DEVEXT pDevExt, VBOXCMDVBVA *pVbva);
201int VBoxCmdVbvaDisable(PVBOXMP_DEVEXT pDevExt, VBOXCMDVBVA *pVbva);
202int VBoxCmdVbvaDestroy(PVBOXMP_DEVEXT pDevExt, VBOXCMDVBVA *pVbva);
203int VBoxCmdVbvaCreate(PVBOXMP_DEVEXT pDevExt, VBOXCMDVBVA *pVbva, ULONG offBuffer, ULONG cbBuffer);
204int VBoxCmdVbvaSubmit(PVBOXMP_DEVEXT pDevExt, VBOXCMDVBVA *pVbva, struct VBOXCMDVBVA_HDR *pCmd, uint32_t cbCmd);
205bool VBoxCmdVbvaPreempt(PVBOXMP_DEVEXT pDevExt, VBOXCMDVBVA *pVbva, uint32_t u32FenceID);
206uint32_t VBoxCmdVbvaCheckCompleted(PVBOXMP_DEVEXT pDevExt, VBOXCMDVBVA *pVbva, bool fPingHost);
207bool VBoxCmdVbvaCheckCompletedIrq(PVBOXMP_DEVEXT pDevExt, VBOXCMDVBVA *pVbva);
208
209/*helper functions for filling vbva commands */
210DECLINLINE(void) VBoxCVDdiPackRect(VBOXCMDVBVA_RECT *pVbvaRect, const RECT *pRect)
211{
212 pVbvaRect->xLeft = (int16_t)pRect->left;
213 pVbvaRect->yTop = (int16_t)pRect->top;
214 pVbvaRect->xRight = (int16_t)pRect->right;
215 pVbvaRect->yBottom = (int16_t)pRect->bottom;
216}
217
218DECLINLINE(void) VBoxCVDdiPackRects(VBOXCMDVBVA_RECT *paVbvaRects, const RECT *paRects, uint32_t cRects)
219{
220 for (uint32_t i = 0; i < cRects; ++i)
221 {
222 VBoxCVDdiPackRect(&paVbvaRects[i], &paRects[i]);
223 }
224
225}
226
227uint32_t VBoxCVDdiPTransferVRamSysBuildEls(VBOXCMDVBVA_PAGING_TRANSFER *pCmd, PMDL pMdl, uint32_t iPfn, uint32_t cPages, uint32_t cbBuffer, uint32_t *pcPagesWritten);
228
229#endif /* #ifndef ___VBoxMPVbva_h___ */
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