VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxUhgsmiDisp.cpp@ 32891

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

wddm/3d: chromium over hgsmi transport fixing & perf measurement

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
1/** @file
2 *
3 * VBoxVideo Display D3D User mode dll
4 *
5 * Copyright (C) 2010 Oracle Corporation
6 *
7 * This file is part of VirtualBox Open Source Edition (OSE), as
8 * available from http://www.virtualbox.org. This file is free software;
9 * you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License (GPL) as published by the Free Software
11 * Foundation, in version 2 as it comes in the "COPYING" file of the
12 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14 */
15#include "VBoxDispD3DCmn.h"
16
17#include <iprt/mem.h>
18#include <iprt/err.h>
19
20typedef struct VBOXUHGSMI_BUFFER_PRIVATE_D3D
21{
22 VBOXUHGSMI_BUFFER Base;
23 PVBOXWDDMDISP_DEVICE pDevice;
24 D3DKMT_HANDLE hAllocation;
25 UINT aLockPageIndices[1];
26} VBOXUHGSMI_BUFFER_PRIVATE_D3D, *PVBOXUHGSMI_BUFFER_PRIVATE_D3D;
27
28#define VBOXUHGSMID3D_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, Base)))
29#define VBOXUHGSMID3D_GET(_p) VBOXUHGSMID3D_GET_PRIVATE(_p, VBOXUHGSMI_PRIVATE_D3D)
30#define VBOXUHGSMID3D_GET_BUFFER(_p) VBOXUHGSMID3D_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_D3D)
31
32DECLCALLBACK(int) vboxUhgsmiD3DBufferDestroy(PVBOXUHGSMI_BUFFER pBuf)
33{
34 PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuffer = VBOXUHGSMID3D_GET_BUFFER(pBuf);
35 D3DDDICB_DEALLOCATE DdiDealloc;
36 DdiDealloc.hResource = 0;
37 DdiDealloc.NumAllocations = 1;
38 DdiDealloc.HandleList = &pBuffer->hAllocation;
39 HRESULT hr = pBuffer->pDevice->RtCallbacks.pfnDeallocateCb(pBuffer->pDevice->hDevice, &DdiDealloc);
40 Assert(hr == S_OK);
41 if (hr == S_OK)
42 {
43 if (pBuffer->Base.bSynchCreated)
44 {
45 CloseHandle(pBuffer->Base.hSynch);
46 }
47 RTMemFree(pBuffer);
48 return VINF_SUCCESS;
49 }
50 return VERR_GENERAL_FAILURE;
51}
52
53DECLCALLBACK(int) vboxUhgsmiD3DBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock)
54{
55 PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuffer = VBOXUHGSMID3D_GET_BUFFER(pBuf);
56 D3DDDICB_LOCK DdiLock;
57 DdiLock.hAllocation = pBuffer->hAllocation;
58 DdiLock.PrivateDriverData = 0;
59
60 if (fFlags.bLockEntire)
61 {
62 offLock = 0;
63 DdiLock.Flags.Value = 0;
64 DdiLock.Flags.LockEntire = 1;
65 }
66 else
67 {
68 if (!cbLock)
69 {
70 Assert(0);
71 return VERR_INVALID_PARAMETER;
72 }
73 if (offLock + cbLock > pBuf->cbBuffer)
74 {
75 Assert(0);
76 return VERR_INVALID_PARAMETER;
77 }
78
79 uint32_t iFirstPage = offLock >> 0x1000;
80 uint32_t iAfterLastPage = (cbLock + 0xfff) >> 0x1000;
81 uint32_t cPages = iAfterLastPage - iFirstPage;
82 uint32_t cBufPages = pBuf->cbBuffer >> 0x1000;
83 Assert(cPages <= (cBufPages));
84
85 if (cPages == cBufPages)
86 {
87 DdiLock.NumPages = 0;
88 DdiLock.pPages = NULL;
89 DdiLock.Flags.Value = 0;
90 DdiLock.Flags.LockEntire = 1;
91 }
92 else
93 {
94 DdiLock.NumPages = cPages;
95 DdiLock.pPages = pBuffer->aLockPageIndices;
96 DdiLock.Flags.Value = 0;
97 for (UINT i = 0, j = iFirstPage; i < cPages; ++i, ++j)
98 {
99 pBuffer->aLockPageIndices[i] = j;
100 }
101 }
102
103 }
104 DdiLock.pData = NULL;
105 DdiLock.Flags.ReadOnly = fFlags.bReadOnly;
106 DdiLock.Flags.WriteOnly = fFlags.bWriteOnly;
107 DdiLock.Flags.DonotWait = fFlags.bDonotWait;
108// DdiLock.Flags.Discard = fFlags.bDiscard;
109
110 HRESULT hr = pBuffer->pDevice->RtCallbacks.pfnLockCb(pBuffer->pDevice->hDevice, &DdiLock);
111 Assert(hr == S_OK);
112 if (hr == S_OK)
113 {
114 *pvLock = (void*)(((uint8_t*)DdiLock.pData) + (offLock & 0xfff));
115 return VINF_SUCCESS;
116 }
117 return VERR_GENERAL_FAILURE;
118}
119
120DECLCALLBACK(int) vboxUhgsmiD3DBufferUnlock(PVBOXUHGSMI_BUFFER pBuf)
121{
122 PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuffer = VBOXUHGSMID3D_GET_BUFFER(pBuf);
123 D3DDDICB_UNLOCK DdiUnlock;
124 DdiUnlock.NumAllocations = 1;
125 DdiUnlock.phAllocations = &pBuffer->hAllocation;
126 HRESULT hr = pBuffer->pDevice->RtCallbacks.pfnUnlockCb(pBuffer->pDevice->hDevice, &DdiUnlock);
127 Assert(hr == S_OK);
128 if (hr == S_OK)
129 return VINF_SUCCESS;
130 return VERR_GENERAL_FAILURE;
131}
132
133DECLCALLBACK(int) vboxUhgsmiD3DBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf,
134 VBOXUHGSMI_SYNCHOBJECT_TYPE enmSynchType, HVBOXUHGSMI_SYNCHOBJECT hSynch,
135 PVBOXUHGSMI_BUFFER* ppBuf)
136{
137 bool bSynchCreated = false;
138 if (!cbBuf)
139 return VERR_INVALID_PARAMETER;
140
141 switch (enmSynchType)
142 {
143 case VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT:
144 if (!hSynch)
145 {
146 hSynch = CreateEvent(
147 NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes */
148 FALSE, /* BOOL bManualReset */
149 FALSE, /* BOOL bInitialState */
150 NULL /* LPCTSTR lpName */
151 );
152 Assert(hSynch);
153 if (!hSynch)
154 {
155 DWORD winEr = GetLastError();
156 /* todo: translate winer */
157 return VERR_GENERAL_FAILURE;
158 }
159 bSynchCreated = true;
160 }
161 break;
162 case VBOXUHGSMI_SYNCHOBJECT_TYPE_SEMAPHORE:
163 if (!hSynch)
164 {
165 hSynch = CreateSemaphore(
166 NULL, /* LPSECURITY_ATTRIBUTES lpSemaphoreAttributes */
167 0, /* LONG lInitialCount */
168 ~0L, /* LONG lMaximumCount */
169 NULL /* LPCTSTR lpName */
170 );
171 Assert(hSynch);
172 if (!hSynch)
173 {
174 DWORD winEr = GetLastError();
175 /* todo: translate winer */
176 return VERR_GENERAL_FAILURE;
177 }
178 bSynchCreated = true;
179 }
180 break;
181 default:
182 Assert(0);
183 return VERR_INVALID_PARAMETER;
184 }
185
186 cbBuf = VBOXWDDM_ROUNDBOUND(cbBuf, 0x1000);
187 Assert(cbBuf);
188 uint32_t cPages = cbBuf >> 0x1000;
189 Assert(cPages);
190
191 int rc;
192 PVBOXUHGSMI_PRIVATE_D3D pPrivate = VBOXUHGSMID3D_GET(pHgsmi);
193 PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuf = (PVBOXUHGSMI_BUFFER_PRIVATE_D3D)RTMemAllocZ(RT_OFFSETOF(VBOXUHGSMI_BUFFER_PRIVATE_D3D, aLockPageIndices));
194 Assert(pBuf);
195 if (pBuf)
196 {
197 struct
198 {
199 D3DDDICB_ALLOCATE DdiAlloc;
200 D3DDDI_ALLOCATIONINFO DdiAllocInfo;
201 VBOXWDDM_ALLOCINFO AllocInfo;
202 } Buf;
203 memset(&Buf, 0, sizeof (Buf));
204 Buf.DdiAlloc.hResource = NULL;
205 Buf.DdiAlloc.hKMResource = NULL;
206 Buf.DdiAlloc.NumAllocations = 1;
207 Buf.DdiAlloc.pAllocationInfo = &Buf.DdiAllocInfo;
208 Buf.DdiAllocInfo.pPrivateDriverData = &Buf.AllocInfo;
209 Buf.DdiAllocInfo.PrivateDriverDataSize = sizeof (Buf.AllocInfo);
210 Buf.AllocInfo.enmType = VBOXWDDM_ALLOC_TYPE_UMD_HGSMI_BUFFER;
211 Buf.AllocInfo.cbBuffer = cbBuf;
212 Buf.AllocInfo.hSynch = hSynch;
213 Buf.AllocInfo.enmSynchType = enmSynchType;
214
215 HRESULT hr = pPrivate->pDevice->RtCallbacks.pfnAllocateCb(pPrivate->pDevice->hDevice, &Buf.DdiAlloc);
216 Assert(hr == S_OK);
217 if (hr == S_OK)
218 {
219 Assert(Buf.DdiAllocInfo.hAllocation);
220 pBuf->Base.pfnLock = vboxUhgsmiD3DBufferLock;
221 pBuf->Base.pfnUnlock = vboxUhgsmiD3DBufferUnlock;
222// pBuf->Base.pfnAdjustValidDataRange = vboxUhgsmiD3DBufferAdjustValidDataRange;
223 pBuf->Base.pfnDestroy = vboxUhgsmiD3DBufferDestroy;
224
225 pBuf->Base.hSynch = hSynch;
226 pBuf->Base.enmSynchType =enmSynchType;
227 pBuf->Base.cbBuffer = cbBuf;
228 pBuf->Base.bSynchCreated = bSynchCreated;
229
230 pBuf->pDevice = pPrivate->pDevice;
231 pBuf->hAllocation = Buf.DdiAllocInfo.hAllocation;
232
233 *ppBuf = &pBuf->Base;
234
235 return VINF_SUCCESS;
236 }
237
238 RTMemFree(pBuf);
239 }
240 else
241 rc = VERR_NO_MEMORY;
242
243 if (bSynchCreated)
244 CloseHandle(hSynch);
245
246 return rc;
247}
248
249DECLCALLBACK(int) vboxUhgsmiD3DBufferSubmitAsynch(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers)
250{
251 PVBOXUHGSMI_PRIVATE_D3D pHg = VBOXUHGSMID3D_GET(pHgsmi);
252 PVBOXWDDMDISP_DEVICE pDevice = pHg->pDevice;
253 const uint32_t cbDmaCmd = RT_OFFSETOF(VBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD, aBufInfos[cBuffers]);
254 if (pDevice->DefaultContext.ContextInfo.CommandBufferSize < cbDmaCmd)
255 {
256 Assert(0);
257 return VERR_GENERAL_FAILURE;
258 }
259 if (pDevice->DefaultContext.ContextInfo.AllocationListSize < cBuffers)
260 {
261 Assert(0);
262 return VERR_GENERAL_FAILURE;
263 }
264
265 PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD pHdr = (PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD)pDevice->DefaultContext.ContextInfo.pCommandBuffer;
266 pHdr->Base.enmCmd = VBOXVDMACMD_TYPE_CHROMIUM_CMD;
267 pHdr->Base.u32CmdReserved = cBuffers;
268
269 D3DDDI_ALLOCATIONLIST* pAllocationList = pDevice->DefaultContext.ContextInfo.pAllocationList;
270 PVBOXWDDM_UHGSMI_BUFFER_UI_SUBMIT_INFO pBufSubmInfo = pHdr->aBufInfos;
271
272 for (uint32_t i = 0; i < cBuffers; ++i)
273 {
274 PVBOXUHGSMI_BUFFER_SUBMIT pBufInfo = &aBuffers[i];
275 PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuffer = VBOXUHGSMID3D_GET_BUFFER(pBufInfo->pBuf);
276
277 memset(pAllocationList, 0, sizeof (D3DDDI_ALLOCATIONLIST));
278 pAllocationList->hAllocation = pBuffer->hAllocation;
279 pAllocationList->WriteOperation = !pBufInfo->fFlags.bHostReadOnly;
280 pAllocationList->DoNotRetireInstance = pBufInfo->fFlags.bDoNotRetire;
281 pBufSubmInfo->fSubFlags = pBufInfo->fFlags;
282 if (pBufInfo->fFlags.bEntireBuffer)
283 {
284 pBufSubmInfo->offData = 0;
285 pBufSubmInfo->cbData = pBuffer->Base.cbBuffer;
286 }
287 else
288 {
289 pBufSubmInfo->offData = pBufInfo->offData;
290 pBufSubmInfo->cbData = pBufInfo->cbData;
291 }
292
293 ++pAllocationList;
294 ++pBufSubmInfo;
295 }
296
297
298 D3DDDICB_RENDER DdiRender = {0};
299 DdiRender.CommandLength = cbDmaCmd;
300 Assert(DdiRender.CommandLength);
301 Assert(DdiRender.CommandLength < UINT32_MAX/2);
302 DdiRender.CommandOffset = 0;
303 DdiRender.NumAllocations = cBuffers;
304 DdiRender.NumPatchLocations = 0;
305// DdiRender.NewCommandBufferSize = sizeof (VBOXVDMACMD) + 4 * (100);
306// DdiRender.NewAllocationListSize = 100;
307// DdiRender.NewPatchLocationListSize = 100;
308 DdiRender.hContext = pDevice->DefaultContext.ContextInfo.hContext;
309
310 HRESULT hr = pDevice->RtCallbacks.pfnRenderCb(pDevice->hDevice, &DdiRender);
311 Assert(hr == S_OK);
312 if (hr == S_OK)
313 {
314 pDevice->DefaultContext.ContextInfo.CommandBufferSize = DdiRender.NewCommandBufferSize;
315 pDevice->DefaultContext.ContextInfo.pCommandBuffer = DdiRender.pNewCommandBuffer;
316 pDevice->DefaultContext.ContextInfo.AllocationListSize = DdiRender.NewAllocationListSize;
317 pDevice->DefaultContext.ContextInfo.pAllocationList = DdiRender.pNewAllocationList;
318 pDevice->DefaultContext.ContextInfo.PatchLocationListSize = DdiRender.NewPatchLocationListSize;
319 pDevice->DefaultContext.ContextInfo.pPatchLocationList = DdiRender.pNewPatchLocationList;
320
321 return VINF_SUCCESS;
322 }
323
324 return VERR_GENERAL_FAILURE;
325}
326
327HRESULT vboxUhgsmiD3DInit(PVBOXUHGSMI_PRIVATE_D3D pHgsmi, PVBOXWDDMDISP_DEVICE pDevice)
328{
329 pHgsmi->Base.pfnBufferCreate = vboxUhgsmiD3DBufferCreate;
330 pHgsmi->Base.pfnBufferSubmitAsynch = vboxUhgsmiD3DBufferSubmitAsynch;
331 pHgsmi->pDevice = pDevice;
332 return S_OK;
333}
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