VirtualBox

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