VirtualBox

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

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

wddm/3d: chromium hgsmi fixes

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