VirtualBox

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

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

crOpenGL: command blocks: enable in guest if host supports it; bugfixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
1/* $Id: VBoxUhgsmiBase.h 50984 2014-04-07 10:57:41Z 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 pDdiAllocInfo->pPrivateDriverData = pAllocInfo;
148 pDdiAllocInfo->PrivateDriverDataSize = sizeof (*pAllocInfo);
149 pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_HGSMI_BUFFER;
150 pAllocInfo->cbBuffer = cbBuffer;
151 pAllocInfo->fUhgsmiType = fUhgsmiType;
152
153}
154
155DECLINLINE(int) vboxUhgsmiBaseDxDmaFill(PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers,
156 VOID* pCommandBuffer, UINT *pCommandBufferSize,
157 D3DDDI_ALLOCATIONLIST *pAllocationList, UINT AllocationListSize,
158 D3DDDI_PATCHLOCATIONLIST *pPatchLocationList, UINT PatchLocationListSize)
159{
160 const uint32_t cbDmaCmd = RT_OFFSETOF(VBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD, aBufInfos[cBuffers]);
161 if (*pCommandBufferSize < cbDmaCmd)
162 {
163 Assert(0);
164 return VERR_GENERAL_FAILURE;
165 }
166 if (AllocationListSize < cBuffers)
167 {
168 Assert(0);
169 return VERR_GENERAL_FAILURE;
170 }
171
172 *pCommandBufferSize = cbDmaCmd;
173
174 PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD pHdr = (PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD)pCommandBuffer;
175 pHdr->Base.enmCmd = VBOXVDMACMD_TYPE_CHROMIUM_CMD;
176 pHdr->Base.u32CmdReserved = 0;
177
178 PVBOXWDDM_UHGSMI_BUFFER_UI_SUBMIT_INFO pBufSubmInfo = pHdr->aBufInfos;
179
180 for (uint32_t i = 0; i < cBuffers; ++i)
181 {
182 PVBOXUHGSMI_BUFFER_SUBMIT pBufInfo = &aBuffers[i];
183 PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pBuffer = VBOXUHGSMDXALLOCBASE_GET_BUFFER(pBufInfo->pBuf);
184
185 memset(pAllocationList, 0, sizeof (D3DDDI_ALLOCATIONLIST));
186 pAllocationList->hAllocation = pBuffer->hAllocation;
187 pAllocationList->Value = 0;
188 pAllocationList->WriteOperation = !pBufInfo->fFlags.bHostReadOnly;
189 pAllocationList->DoNotRetireInstance = pBufInfo->fFlags.bDoNotRetire;
190 if (pBufInfo->fFlags.bEntireBuffer)
191 {
192 pBufSubmInfo->offData = 0;
193 pBufSubmInfo->cbData = pBuffer->BasePrivate.Base.cbBuffer;
194 }
195 else
196 {
197 pBufSubmInfo->offData = pBufInfo->offData;
198 pBufSubmInfo->cbData = pBufInfo->cbData;
199 }
200
201 ++pAllocationList;
202 ++pBufSubmInfo;
203 }
204
205 return VINF_SUCCESS;
206}
207
208DECLCALLBACK(int) vboxUhgsmiBaseEscBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock);
209DECLCALLBACK(int) vboxUhgsmiBaseEscBufferUnlock(PVBOXUHGSMI_BUFFER pBuf);
210int vboxUhgsmiBaseBufferTerm(PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE pBuffer);
211static int vboxUhgsmiBaseEventChkCreate(VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, HANDLE *phSynch);
212int vboxUhgsmiKmtEscBufferInit(PVBOXUHGSMI_PRIVATE_BASE pPrivate, PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE pBuffer, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, PFNVBOXUHGSMI_BUFFER_DESTROY pfnDestroy);
213DECLCALLBACK(int) vboxUhgsmiBaseEscBufferSubmit(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers);
214DECLCALLBACK(int) vboxUhgsmiBaseEscBufferDestroy(PVBOXUHGSMI_BUFFER pBuf);
215DECLCALLBACK(int) vboxUhgsmiBaseEscBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, PVBOXUHGSMI_BUFFER* ppBuf);
216DECLINLINE(void) vboxUhgsmiBaseInit(PVBOXUHGSMI_PRIVATE_BASE pHgsmi, PFNVBOXCRHGSMI_ESCAPE pfnEscape)
217{
218 pHgsmi->Base.pfnBufferCreate = vboxUhgsmiBaseEscBufferCreate;
219 pHgsmi->Base.pfnBufferSubmit = vboxUhgsmiBaseEscBufferSubmit;
220 pHgsmi->pfnEscape = pfnEscape;
221}
222
223#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