VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxUhgsmiBase.h@ 51457

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

wddm: fix sporadic hangs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
1/* $Id: VBoxUhgsmiBase.h 51457 2014-05-29 09:24:09Z 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);
49int vboxCrHgsmiPrivateCtlConGetHostCaps(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, uint32_t *pu32HostCaps);
50#endif
51
52typedef DECLCALLBACK(int) FNVBOXCRHGSMI_ESCAPE(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, void *pvData, uint32_t cbData, BOOL fHwAccess);
53typedef FNVBOXCRHGSMI_ESCAPE *PFNVBOXCRHGSMI_ESCAPE;
54
55#define vboxCrHgsmiPrivateEscape(_pHgsmi, _pvData, _cbData, _fHwAccess) (_pHgsmi->pfnEscape((_pHgsmi), (_pvData), (_cbData), (_fHwAccess)))
56
57typedef struct VBOXUHGSMI_PRIVATE_BASE
58{
59 VBOXUHGSMI Base;
60 PFNVBOXCRHGSMI_ESCAPE pfnEscape;
61} VBOXUHGSMI_PRIVATE_BASE, *PVBOXUHGSMI_PRIVATE_BASE;
62
63typedef struct VBOXUHGSMI_BUFFER_PRIVATE_BASE
64{
65 VBOXUHGSMI_BUFFER Base;
66 PVBOXUHGSMI_PRIVATE_BASE pHgsmi;
67} VBOXUHGSMI_BUFFER_PRIVATE_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_BASE;
68
69typedef struct VBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE
70{
71 VBOXUHGSMI_BUFFER_PRIVATE_BASE BasePrivate;
72 VBOXVIDEOCM_UM_ALLOC Alloc;
73 HANDLE hSynch;
74} VBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE;
75
76typedef struct VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE
77{
78 VBOXUHGSMI_BUFFER_PRIVATE_BASE BasePrivate;
79 D3DKMT_HANDLE hAllocation;
80 UINT aLockPageIndices[1];
81} VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE;
82
83#define VBOXUHGSMIBASE_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, Base)))
84#define VBOXUHGSMIBASE_GET(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_PRIVATE_BASE)
85#define VBOXUHGSMIBASE_GET_BUFFER(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_BASE)
86
87#define VBOXUHGSMIPRIVATEBASE_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, BasePrivate.Base)))
88#define VBOXUHGSMIESCBASE_GET_BUFFER(_p) VBOXUHGSMIPRIVATEBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE)
89#define VBOXUHGSMDXALLOCBASE_GET_BUFFER(_p) VBOXUHGSMIPRIVATEBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE)
90
91DECLINLINE(int) vboxUhgsmiBaseDxLockData(PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pPrivate, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags,
92 D3DDDICB_LOCKFLAGS *pfFlags, UINT *pNumPages)
93{
94 PVBOXUHGSMI_BUFFER pBuf = &pPrivate->BasePrivate.Base;
95 D3DDDICB_LOCKFLAGS fLockFlags;
96 fLockFlags.Value = 0;
97 if (fFlags.bLockEntire)
98 {
99 Assert(!offLock);
100 fLockFlags.LockEntire = 1;
101 }
102 else
103 {
104 if (!cbLock)
105 {
106 Assert(0);
107 return VERR_INVALID_PARAMETER;
108 }
109 if (offLock + cbLock > pBuf->cbBuffer)
110 {
111 Assert(0);
112 return VERR_INVALID_PARAMETER;
113 }
114
115 uint32_t iFirstPage = offLock >> 12;
116 uint32_t iAfterLastPage = (cbLock + 0xfff) >> 12;
117 uint32_t cPages = iAfterLastPage - iFirstPage;
118 uint32_t cBufPages = pBuf->cbBuffer >> 12;
119 Assert(cPages <= (cBufPages));
120
121 if (cPages == cBufPages)
122 {
123 *pNumPages = 0;
124 fLockFlags.LockEntire = 1;
125 }
126 else
127 {
128 *pNumPages = cPages;
129 for (UINT i = 0, j = iFirstPage; i < cPages; ++i, ++j)
130 {
131 pPrivate->aLockPageIndices[i] = j;
132 }
133 }
134
135 }
136
137 fLockFlags.ReadOnly = fFlags.bReadOnly;
138 fLockFlags.WriteOnly = fFlags.bWriteOnly;
139 fLockFlags.DonotWait = fFlags.bDonotWait;
140// fLockFlags.Discard = fFlags.bDiscard;
141 *pfFlags = fLockFlags;
142 return VINF_SUCCESS;
143}
144
145DECLINLINE(void) vboxUhgsmiBaseDxAllocInfoFill(D3DDDI_ALLOCATIONINFO *pDdiAllocInfo, VBOXWDDM_ALLOCINFO *pAllocInfo, uint32_t cbBuffer, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType)
146{
147 memset(pDdiAllocInfo, 0, sizeof (*pDdiAllocInfo));
148 pDdiAllocInfo->pPrivateDriverData = pAllocInfo;
149 pDdiAllocInfo->PrivateDriverDataSize = sizeof (*pAllocInfo);
150 memset(pAllocInfo, 0, sizeof (*pAllocInfo));
151 pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_HGSMI_BUFFER;
152 pAllocInfo->cbBuffer = cbBuffer;
153 pAllocInfo->fUhgsmiType = fUhgsmiType;
154}
155
156DECLINLINE(int) vboxUhgsmiBaseDxDmaFill(PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers,
157 VOID* pCommandBuffer, UINT *pCommandBufferSize,
158 D3DDDI_ALLOCATIONLIST *pAllocationList, UINT AllocationListSize,
159 D3DDDI_PATCHLOCATIONLIST *pPatchLocationList, UINT PatchLocationListSize)
160{
161 const uint32_t cbDmaCmd = RT_OFFSETOF(VBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD, aBufInfos[cBuffers]);
162 if (*pCommandBufferSize < cbDmaCmd)
163 {
164 Assert(0);
165 return VERR_GENERAL_FAILURE;
166 }
167 if (AllocationListSize < cBuffers)
168 {
169 Assert(0);
170 return VERR_GENERAL_FAILURE;
171 }
172
173 *pCommandBufferSize = cbDmaCmd;
174
175 PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD pHdr = (PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD)pCommandBuffer;
176 pHdr->Base.enmCmd = VBOXVDMACMD_TYPE_CHROMIUM_CMD;
177 pHdr->Base.u32CmdReserved = 0;
178
179 PVBOXWDDM_UHGSMI_BUFFER_UI_SUBMIT_INFO pBufSubmInfo = pHdr->aBufInfos;
180
181 for (uint32_t i = 0; i < cBuffers; ++i)
182 {
183 PVBOXUHGSMI_BUFFER_SUBMIT pBufInfo = &aBuffers[i];
184 PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pBuffer = VBOXUHGSMDXALLOCBASE_GET_BUFFER(pBufInfo->pBuf);
185
186 memset(pAllocationList, 0, sizeof (D3DDDI_ALLOCATIONLIST));
187 pAllocationList->hAllocation = pBuffer->hAllocation;
188 pAllocationList->Value = 0;
189 pAllocationList->WriteOperation = !pBufInfo->fFlags.bHostReadOnly;
190 pAllocationList->DoNotRetireInstance = pBufInfo->fFlags.bDoNotRetire;
191 if (pBufInfo->fFlags.bEntireBuffer)
192 {
193 pBufSubmInfo->offData = 0;
194 pBufSubmInfo->cbData = pBuffer->BasePrivate.Base.cbBuffer;
195 }
196 else
197 {
198 pBufSubmInfo->offData = pBufInfo->offData;
199 pBufSubmInfo->cbData = pBufInfo->cbData;
200 }
201
202 ++pAllocationList;
203 ++pBufSubmInfo;
204 }
205
206 return VINF_SUCCESS;
207}
208
209DECLCALLBACK(int) vboxUhgsmiBaseEscBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock);
210DECLCALLBACK(int) vboxUhgsmiBaseEscBufferUnlock(PVBOXUHGSMI_BUFFER pBuf);
211int vboxUhgsmiBaseBufferTerm(PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE pBuffer);
212static int vboxUhgsmiBaseEventChkCreate(VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, HANDLE *phSynch);
213int vboxUhgsmiKmtEscBufferInit(PVBOXUHGSMI_PRIVATE_BASE pPrivate, PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE pBuffer, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, PFNVBOXUHGSMI_BUFFER_DESTROY pfnDestroy);
214DECLCALLBACK(int) vboxUhgsmiBaseEscBufferSubmit(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers);
215DECLCALLBACK(int) vboxUhgsmiBaseEscBufferDestroy(PVBOXUHGSMI_BUFFER pBuf);
216DECLCALLBACK(int) vboxUhgsmiBaseEscBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, PVBOXUHGSMI_BUFFER* ppBuf);
217DECLINLINE(void) vboxUhgsmiBaseInit(PVBOXUHGSMI_PRIVATE_BASE pHgsmi, PFNVBOXCRHGSMI_ESCAPE pfnEscape)
218{
219 pHgsmi->Base.pfnBufferCreate = vboxUhgsmiBaseEscBufferCreate;
220 pHgsmi->Base.pfnBufferSubmit = vboxUhgsmiBaseEscBufferSubmit;
221 pHgsmi->pfnEscape = pfnEscape;
222}
223
224#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