VirtualBox

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

Last change on this file since 34801 was 33241, checked in by vboxsync, 14 years ago

wddm/3d: chromium hgsmi working (still disabled to make some cleaning)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 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_PRIVATE_BASE BasePrivate;
23 PVBOXWDDMDISP_DEVICE pDevice;
24 UINT aLockPageIndices[1];
25} VBOXUHGSMI_BUFFER_PRIVATE_D3D, *PVBOXUHGSMI_BUFFER_PRIVATE_D3D;
26
27#define VBOXUHGSMID3D_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, BasePrivate.Base)))
28#define VBOXUHGSMID3D_GET(_p) VBOXUHGSMID3D_GET_PRIVATE(_p, VBOXUHGSMI_PRIVATE_D3D)
29#define VBOXUHGSMID3D_GET_BUFFER(_p) VBOXUHGSMID3D_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_D3D)
30
31DECLCALLBACK(int) vboxUhgsmiD3DBufferDestroy(PVBOXUHGSMI_BUFFER pBuf)
32{
33 PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuffer = VBOXUHGSMID3D_GET_BUFFER(pBuf);
34 D3DDDICB_DEALLOCATE DdiDealloc;
35 DdiDealloc.hResource = 0;
36 DdiDealloc.NumAllocations = 1;
37 DdiDealloc.HandleList = &pBuffer->BasePrivate.hAllocation;
38 HRESULT hr = pBuffer->pDevice->RtCallbacks.pfnDeallocateCb(pBuffer->pDevice->hDevice, &DdiDealloc);
39 Assert(hr == S_OK);
40 if (hr == S_OK)
41 {
42 if (pBuffer->BasePrivate.Base.bSynchCreated)
43 {
44 CloseHandle(pBuffer->BasePrivate.Base.hSynch);
45 }
46 RTMemFree(pBuffer);
47 return VINF_SUCCESS;
48 }
49 return VERR_GENERAL_FAILURE;
50}
51
52DECLCALLBACK(int) vboxUhgsmiD3DBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock)
53{
54 PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuffer = VBOXUHGSMID3D_GET_BUFFER(pBuf);
55 D3DDDICB_LOCK DdiLock = {0};
56 DdiLock.hAllocation = pBuffer->BasePrivate.hAllocation;
57 DdiLock.PrivateDriverData = 0;
58
59 int rc = vboxUhgsmiBaseLockData(pBuf, offLock, cbLock, fFlags,
60 &DdiLock.Flags, &DdiLock.NumPages, pBuffer->aLockPageIndices);
61 AssertRC(rc);
62 if (RT_FAILURE(rc))
63 return rc;
64
65 if (DdiLock.NumPages)
66 DdiLock.pPages = pBuffer->aLockPageIndices;
67 else
68 DdiLock.pPages = NULL;
69
70 HRESULT hr = pBuffer->pDevice->RtCallbacks.pfnLockCb(pBuffer->pDevice->hDevice, &DdiLock);
71 Assert(hr == S_OK);
72 if (hr == S_OK)
73 {
74 *pvLock = (void*)(((uint8_t*)DdiLock.pData) + (offLock & 0xfff));
75 return VINF_SUCCESS;
76 }
77 return VERR_GENERAL_FAILURE;
78}
79
80DECLCALLBACK(int) vboxUhgsmiD3DBufferUnlock(PVBOXUHGSMI_BUFFER pBuf)
81{
82 PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuffer = VBOXUHGSMID3D_GET_BUFFER(pBuf);
83 D3DDDICB_UNLOCK DdiUnlock;
84 DdiUnlock.NumAllocations = 1;
85 DdiUnlock.phAllocations = &pBuffer->BasePrivate.hAllocation;
86 HRESULT hr = pBuffer->pDevice->RtCallbacks.pfnUnlockCb(pBuffer->pDevice->hDevice, &DdiUnlock);
87 Assert(hr == S_OK);
88 if (hr == S_OK)
89 return VINF_SUCCESS;
90 return VERR_GENERAL_FAILURE;
91}
92
93DECLCALLBACK(int) vboxUhgsmiD3DBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf,
94 VBOXUHGSMI_SYNCHOBJECT_TYPE enmSynchType, HVBOXUHGSMI_SYNCHOBJECT hSynch,
95 PVBOXUHGSMI_BUFFER* ppBuf)
96{
97 bool bSynchCreated = false;
98 if (!cbBuf)
99 return VERR_INVALID_PARAMETER;
100
101 int rc = vboxUhgsmiBaseEventChkCreate(enmSynchType, &hSynch, &bSynchCreated);
102 AssertRC(rc);
103 if (RT_FAILURE(rc))
104 return rc;
105
106 cbBuf = VBOXWDDM_ROUNDBOUND(cbBuf, 0x1000);
107 Assert(cbBuf);
108 uint32_t cPages = cbBuf >> 12;
109 Assert(cPages);
110
111 PVBOXUHGSMI_PRIVATE_D3D pPrivate = VBOXUHGSMID3D_GET(pHgsmi);
112 PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuf = (PVBOXUHGSMI_BUFFER_PRIVATE_D3D)RTMemAllocZ(RT_OFFSETOF(VBOXUHGSMI_BUFFER_PRIVATE_D3D, aLockPageIndices[cPages]));
113 Assert(pBuf);
114 if (pBuf)
115 {
116 struct
117 {
118 D3DDDICB_ALLOCATE DdiAlloc;
119 D3DDDI_ALLOCATIONINFO DdiAllocInfo;
120 VBOXWDDM_ALLOCINFO AllocInfo;
121 } Buf;
122 memset(&Buf, 0, sizeof (Buf));
123 Buf.DdiAlloc.hResource = NULL;
124 Buf.DdiAlloc.hKMResource = NULL;
125 Buf.DdiAlloc.NumAllocations = 1;
126 Buf.DdiAlloc.pAllocationInfo = &Buf.DdiAllocInfo;
127 Buf.DdiAllocInfo.pPrivateDriverData = &Buf.AllocInfo;
128 Buf.DdiAllocInfo.PrivateDriverDataSize = sizeof (Buf.AllocInfo);
129 Buf.AllocInfo.enmType = VBOXWDDM_ALLOC_TYPE_UMD_HGSMI_BUFFER;
130 Buf.AllocInfo.cbBuffer = cbBuf;
131 Buf.AllocInfo.hSynch = hSynch;
132 Buf.AllocInfo.enmSynchType = enmSynchType;
133
134 HRESULT hr = pPrivate->pDevice->RtCallbacks.pfnAllocateCb(pPrivate->pDevice->hDevice, &Buf.DdiAlloc);
135 Assert(hr == S_OK);
136 if (hr == S_OK)
137 {
138 Assert(Buf.DdiAllocInfo.hAllocation);
139 pBuf->BasePrivate.Base.pfnLock = vboxUhgsmiD3DBufferLock;
140 pBuf->BasePrivate.Base.pfnUnlock = vboxUhgsmiD3DBufferUnlock;
141// pBuf->Base.pfnAdjustValidDataRange = vboxUhgsmiD3DBufferAdjustValidDataRange;
142 pBuf->BasePrivate.Base.pfnDestroy = vboxUhgsmiD3DBufferDestroy;
143
144 pBuf->BasePrivate.Base.hSynch = hSynch;
145 pBuf->BasePrivate.Base.enmSynchType = enmSynchType;
146 pBuf->BasePrivate.Base.cbBuffer = cbBuf;
147 pBuf->BasePrivate.Base.bSynchCreated = bSynchCreated;
148
149 pBuf->pDevice = pPrivate->pDevice;
150 pBuf->BasePrivate.hAllocation = Buf.DdiAllocInfo.hAllocation;
151
152 *ppBuf = &pBuf->BasePrivate.Base;
153
154 return VINF_SUCCESS;
155 }
156
157 RTMemFree(pBuf);
158 }
159 else
160 rc = VERR_NO_MEMORY;
161
162 if (bSynchCreated)
163 CloseHandle(hSynch);
164
165 return rc;
166}
167
168DECLCALLBACK(int) vboxUhgsmiD3DBufferSubmitAsynch(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers)
169{
170 PVBOXUHGSMI_PRIVATE_D3D pHg = VBOXUHGSMID3D_GET(pHgsmi);
171 PVBOXWDDMDISP_DEVICE pDevice = pHg->pDevice;
172 UINT cbDmaCmd = pDevice->DefaultContext.ContextInfo.CommandBufferSize;
173 int rc = vboxUhgsmiBaseDmaFill(aBuffers, cBuffers,
174 pDevice->DefaultContext.ContextInfo.pCommandBuffer, &cbDmaCmd,
175 pDevice->DefaultContext.ContextInfo.pAllocationList, pDevice->DefaultContext.ContextInfo.AllocationListSize,
176 pDevice->DefaultContext.ContextInfo.pPatchLocationList, pDevice->DefaultContext.ContextInfo.PatchLocationListSize);
177 AssertRC(rc);
178 if (RT_FAILURE(rc))
179 return rc;
180
181 D3DDDICB_RENDER DdiRender = {0};
182 DdiRender.CommandLength = cbDmaCmd;
183 Assert(DdiRender.CommandLength);
184 Assert(DdiRender.CommandLength < UINT32_MAX/2);
185 DdiRender.CommandOffset = 0;
186 DdiRender.NumAllocations = cBuffers;
187 DdiRender.NumPatchLocations = 0;
188// DdiRender.NewCommandBufferSize = sizeof (VBOXVDMACMD) + 4 * (100);
189// DdiRender.NewAllocationListSize = 100;
190// DdiRender.NewPatchLocationListSize = 100;
191 DdiRender.hContext = pDevice->DefaultContext.ContextInfo.hContext;
192
193 HRESULT hr = pDevice->RtCallbacks.pfnRenderCb(pDevice->hDevice, &DdiRender);
194 Assert(hr == S_OK);
195 if (hr == S_OK)
196 {
197 pDevice->DefaultContext.ContextInfo.CommandBufferSize = DdiRender.NewCommandBufferSize;
198 pDevice->DefaultContext.ContextInfo.pCommandBuffer = DdiRender.pNewCommandBuffer;
199 pDevice->DefaultContext.ContextInfo.AllocationListSize = DdiRender.NewAllocationListSize;
200 pDevice->DefaultContext.ContextInfo.pAllocationList = DdiRender.pNewAllocationList;
201 pDevice->DefaultContext.ContextInfo.PatchLocationListSize = DdiRender.NewPatchLocationListSize;
202 pDevice->DefaultContext.ContextInfo.pPatchLocationList = DdiRender.pNewPatchLocationList;
203
204 return VINF_SUCCESS;
205 }
206
207 return VERR_GENERAL_FAILURE;
208}
209
210HRESULT vboxUhgsmiD3DInit(PVBOXUHGSMI_PRIVATE_D3D pHgsmi, PVBOXWDDMDISP_DEVICE pDevice)
211{
212 pHgsmi->BasePrivate.Base.pfnBufferCreate = vboxUhgsmiD3DBufferCreate;
213 pHgsmi->BasePrivate.Base.pfnBufferSubmitAsynch = vboxUhgsmiD3DBufferSubmitAsynch;
214 pHgsmi->BasePrivate.hClient = NULL;
215 pHgsmi->pDevice = pDevice;
216 return S_OK;
217}
218
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