1 | /* $Id: VBoxUhgsmiDisp.cpp 50928 2014-03-31 14:14:11Z 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 | #include "VBoxDispD3DCmn.h"
|
---|
20 |
|
---|
21 | #define VBOXUHGSMID3D_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, BasePrivate.Base)))
|
---|
22 | #define VBOXUHGSMID3D_GET(_p) VBOXUHGSMID3D_GET_PRIVATE(_p, VBOXUHGSMI_PRIVATE_D3D)
|
---|
23 |
|
---|
24 | #include <iprt/mem.h>
|
---|
25 | #include <iprt/err.h>
|
---|
26 |
|
---|
27 | DECLCALLBACK(int) vboxUhgsmiD3DBufferDestroy(PVBOXUHGSMI_BUFFER pBuf)
|
---|
28 | {
|
---|
29 | PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pBuffer = VBOXUHGSMDXALLOCBASE_GET_BUFFER(pBuf);
|
---|
30 | struct VBOXWDDMDISP_DEVICE *pDevice = VBOXUHGSMID3D_GET(pBuffer->BasePrivate.pHgsmi)->pDevice;
|
---|
31 | D3DDDICB_DEALLOCATE DdiDealloc;
|
---|
32 | DdiDealloc.hResource = 0;
|
---|
33 | DdiDealloc.NumAllocations = 1;
|
---|
34 | DdiDealloc.HandleList = &pBuffer->hAllocation;
|
---|
35 | HRESULT hr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &DdiDealloc);
|
---|
36 | if (hr == S_OK)
|
---|
37 | {
|
---|
38 | #ifdef DEBUG_misha
|
---|
39 | memset(pBuffer, 0, sizeof (*pBuffer));
|
---|
40 | #endif
|
---|
41 | RTMemFree(pBuffer);
|
---|
42 | return VINF_SUCCESS;
|
---|
43 | }
|
---|
44 |
|
---|
45 | WARN(("pfnDeallocateCb failed, hr %#x", hr));
|
---|
46 | return VERR_GENERAL_FAILURE;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /* typedef DECLCALLBACK(int) FNVBOXUHGSMI_BUFFER_LOCK(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock); */
|
---|
50 | DECLCALLBACK(int) vboxUhgsmiD3DBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock)
|
---|
51 | {
|
---|
52 | PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pBuffer = VBOXUHGSMDXALLOCBASE_GET_BUFFER(pBuf);
|
---|
53 | struct VBOXWDDMDISP_DEVICE *pDevice = VBOXUHGSMID3D_GET(pBuffer->BasePrivate.pHgsmi)->pDevice;
|
---|
54 | D3DDDICB_LOCK DdiLock = {0};
|
---|
55 | DdiLock.hAllocation = pBuffer->hAllocation;
|
---|
56 | DdiLock.PrivateDriverData = 0;
|
---|
57 |
|
---|
58 | int rc = vboxUhgsmiBaseDxLockData(pBuffer, offLock, cbLock, fFlags,
|
---|
59 | &DdiLock.Flags, &DdiLock.NumPages);
|
---|
60 | if (!RT_SUCCESS(rc))
|
---|
61 | {
|
---|
62 | WARN(("vboxUhgsmiBaseDxLockData failed rc %d", rc));
|
---|
63 | return rc;
|
---|
64 | }
|
---|
65 |
|
---|
66 | if (DdiLock.NumPages)
|
---|
67 | DdiLock.pPages = pBuffer->aLockPageIndices;
|
---|
68 | else
|
---|
69 | DdiLock.pPages = NULL;
|
---|
70 |
|
---|
71 | HRESULT hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &DdiLock);
|
---|
72 | if (hr == S_OK)
|
---|
73 | {
|
---|
74 | *pvLock = (void*)(((uint8_t*)DdiLock.pData) + (offLock & 0xfff));
|
---|
75 | return VINF_SUCCESS;
|
---|
76 | }
|
---|
77 |
|
---|
78 | WARN(("pfnLockCb failed, hr %#x", hr));
|
---|
79 | return VERR_GENERAL_FAILURE;
|
---|
80 | }
|
---|
81 |
|
---|
82 | DECLCALLBACK(int) vboxUhgsmiD3DBufferUnlock(PVBOXUHGSMI_BUFFER pBuf)
|
---|
83 | {
|
---|
84 | PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pBuffer = VBOXUHGSMDXALLOCBASE_GET_BUFFER(pBuf);
|
---|
85 | struct VBOXWDDMDISP_DEVICE *pDevice = VBOXUHGSMID3D_GET(pBuffer->BasePrivate.pHgsmi)->pDevice;
|
---|
86 | D3DDDICB_UNLOCK DdiUnlock;
|
---|
87 | DdiUnlock.NumAllocations = 1;
|
---|
88 | DdiUnlock.phAllocations = &pBuffer->hAllocation;
|
---|
89 | HRESULT hr = pDevice->RtCallbacks.pfnUnlockCb(pDevice->hDevice, &DdiUnlock);
|
---|
90 | if (hr == S_OK)
|
---|
91 | return VINF_SUCCESS;
|
---|
92 |
|
---|
93 | WARN(("pfnUnlockCb failed, hr %#x", hr));
|
---|
94 | return VERR_GENERAL_FAILURE;
|
---|
95 | }
|
---|
96 |
|
---|
97 | /*typedef DECLCALLBACK(int) FNVBOXUHGSMI_BUFFER_CREATE(PVBOXUHGSMI pHgsmi, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fType, PVBOXUHGSMI_BUFFER* ppBuf);*/
|
---|
98 | DECLCALLBACK(int) vboxUhgsmiD3DBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fType, PVBOXUHGSMI_BUFFER* ppBuf)
|
---|
99 | {
|
---|
100 | if (!cbBuf)
|
---|
101 | return VERR_INVALID_PARAMETER;
|
---|
102 |
|
---|
103 | int rc = VINF_SUCCESS;
|
---|
104 |
|
---|
105 | cbBuf = VBOXWDDM_ROUNDBOUND(cbBuf, 0x1000);
|
---|
106 | Assert(cbBuf);
|
---|
107 | uint32_t cPages = cbBuf >> 12;
|
---|
108 | Assert(cPages);
|
---|
109 |
|
---|
110 | PVBOXUHGSMI_PRIVATE_D3D pPrivate = VBOXUHGSMID3D_GET(pHgsmi);
|
---|
111 | PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pBuf = (PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE)RTMemAllocZ(RT_OFFSETOF(VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE, aLockPageIndices[cPages]));
|
---|
112 | if (pBuf)
|
---|
113 | {
|
---|
114 | D3DDDICB_ALLOCATE DdiAlloc;
|
---|
115 | D3DDDI_ALLOCATIONINFO DdiAllocInfo;
|
---|
116 | VBOXWDDM_ALLOCINFO AllocInfo;
|
---|
117 |
|
---|
118 | memset(&DdiAlloc, 0, sizeof (DdiAlloc));
|
---|
119 | DdiAlloc.hResource = NULL;
|
---|
120 | DdiAlloc.hKMResource = NULL;
|
---|
121 | DdiAlloc.NumAllocations = 1;
|
---|
122 | DdiAlloc.pAllocationInfo = &DdiAllocInfo;
|
---|
123 | vboxUhgsmiBaseDxAllocInfoFill(&DdiAllocInfo, &AllocInfo, cbBuf, fType);
|
---|
124 |
|
---|
125 | HRESULT hr = pPrivate->pDevice->RtCallbacks.pfnAllocateCb(pPrivate->pDevice->hDevice, &DdiAlloc);
|
---|
126 | if (hr == S_OK)
|
---|
127 | {
|
---|
128 | Assert(DdiAllocInfo.hAllocation);
|
---|
129 | pBuf->BasePrivate.Base.pfnLock = vboxUhgsmiD3DBufferLock;
|
---|
130 | pBuf->BasePrivate.Base.pfnUnlock = vboxUhgsmiD3DBufferUnlock;
|
---|
131 | pBuf->BasePrivate.Base.pfnDestroy = vboxUhgsmiD3DBufferDestroy;
|
---|
132 |
|
---|
133 | pBuf->BasePrivate.Base.fType = fType;
|
---|
134 | pBuf->BasePrivate.Base.cbBuffer = cbBuf;
|
---|
135 |
|
---|
136 | pBuf->BasePrivate.pHgsmi = &pPrivate->BasePrivate;
|
---|
137 |
|
---|
138 | pBuf->hAllocation = DdiAllocInfo.hAllocation;
|
---|
139 |
|
---|
140 | *ppBuf = &pBuf->BasePrivate.Base;
|
---|
141 |
|
---|
142 | return VINF_SUCCESS;
|
---|
143 | }
|
---|
144 | else
|
---|
145 | {
|
---|
146 | WARN(("pfnAllocateCb failed hr %#x"));
|
---|
147 | rc = VERR_GENERAL_FAILURE;
|
---|
148 | }
|
---|
149 |
|
---|
150 | RTMemFree(pBuf);
|
---|
151 | }
|
---|
152 | else
|
---|
153 | {
|
---|
154 | WARN(("RTMemAllocZ failed"));
|
---|
155 | rc = VERR_NO_MEMORY;
|
---|
156 | }
|
---|
157 |
|
---|
158 | return rc;
|
---|
159 | }
|
---|
160 |
|
---|
161 | /* typedef DECLCALLBACK(int) FNVBOXUHGSMI_BUFFER_SUBMIT(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers); */
|
---|
162 | DECLCALLBACK(int) vboxUhgsmiD3DBufferSubmit(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers)
|
---|
163 | {
|
---|
164 | PVBOXUHGSMI_PRIVATE_D3D pHg = VBOXUHGSMID3D_GET(pHgsmi);
|
---|
165 | PVBOXWDDMDISP_DEVICE pDevice = pHg->pDevice;
|
---|
166 | UINT cbDmaCmd = pDevice->DefaultContext.ContextInfo.CommandBufferSize;
|
---|
167 | int rc = vboxUhgsmiBaseDxDmaFill(aBuffers, cBuffers,
|
---|
168 | pDevice->DefaultContext.ContextInfo.pCommandBuffer, &cbDmaCmd,
|
---|
169 | pDevice->DefaultContext.ContextInfo.pAllocationList, pDevice->DefaultContext.ContextInfo.AllocationListSize,
|
---|
170 | pDevice->DefaultContext.ContextInfo.pPatchLocationList, pDevice->DefaultContext.ContextInfo.PatchLocationListSize);
|
---|
171 | if (RT_FAILURE(rc))
|
---|
172 | {
|
---|
173 | WARN(("vboxUhgsmiBaseDxDmaFill failed, rc %d", rc));
|
---|
174 | return rc;
|
---|
175 | }
|
---|
176 |
|
---|
177 | D3DDDICB_RENDER DdiRender = {0};
|
---|
178 | DdiRender.CommandLength = cbDmaCmd;
|
---|
179 | Assert(DdiRender.CommandLength);
|
---|
180 | Assert(DdiRender.CommandLength < UINT32_MAX/2);
|
---|
181 | DdiRender.CommandOffset = 0;
|
---|
182 | DdiRender.NumAllocations = cBuffers;
|
---|
183 | DdiRender.NumPatchLocations = 0;
|
---|
184 | // DdiRender.NewCommandBufferSize = sizeof (VBOXVDMACMD) + 4 * (100);
|
---|
185 | // DdiRender.NewAllocationListSize = 100;
|
---|
186 | // DdiRender.NewPatchLocationListSize = 100;
|
---|
187 | DdiRender.hContext = pDevice->DefaultContext.ContextInfo.hContext;
|
---|
188 |
|
---|
189 | HRESULT hr = pDevice->RtCallbacks.pfnRenderCb(pDevice->hDevice, &DdiRender);
|
---|
190 | if (hr == S_OK)
|
---|
191 | {
|
---|
192 | pDevice->DefaultContext.ContextInfo.CommandBufferSize = DdiRender.NewCommandBufferSize;
|
---|
193 | pDevice->DefaultContext.ContextInfo.pCommandBuffer = DdiRender.pNewCommandBuffer;
|
---|
194 | pDevice->DefaultContext.ContextInfo.AllocationListSize = DdiRender.NewAllocationListSize;
|
---|
195 | pDevice->DefaultContext.ContextInfo.pAllocationList = DdiRender.pNewAllocationList;
|
---|
196 | pDevice->DefaultContext.ContextInfo.PatchLocationListSize = DdiRender.NewPatchLocationListSize;
|
---|
197 | pDevice->DefaultContext.ContextInfo.pPatchLocationList = DdiRender.pNewPatchLocationList;
|
---|
198 |
|
---|
199 | return VINF_SUCCESS;
|
---|
200 | }
|
---|
201 |
|
---|
202 | WARN(("pfnRenderCb failed, hr %#x", hr));
|
---|
203 | return VERR_GENERAL_FAILURE;
|
---|
204 | }
|
---|
205 |
|
---|
206 | static DECLCALLBACK(int) vboxCrHhgsmiDispEscape(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, void *pvData, uint32_t cbData, BOOL fHwAccess)
|
---|
207 | {
|
---|
208 | PVBOXUHGSMI_PRIVATE_D3D pPrivate = VBOXUHGSMID3D_GET(pHgsmi);
|
---|
209 | PVBOXWDDMDISP_DEVICE pDevice = pPrivate->pDevice;
|
---|
210 | D3DDDICB_ESCAPE DdiEscape = {0};
|
---|
211 | DdiEscape.hContext = pDevice->DefaultContext.ContextInfo.hContext;
|
---|
212 | DdiEscape.hDevice = pDevice->hDevice;
|
---|
213 | DdiEscape.Flags.HardwareAccess = !!fHwAccess;
|
---|
214 | DdiEscape.pPrivateDriverData = pvData;
|
---|
215 | DdiEscape.PrivateDriverDataSize = cbData;
|
---|
216 | HRESULT hr = pDevice->RtCallbacks.pfnEscapeCb(pDevice->pAdapter->hAdapter, &DdiEscape);
|
---|
217 | if (SUCCEEDED(hr))
|
---|
218 | {
|
---|
219 | return VINF_SUCCESS;
|
---|
220 | }
|
---|
221 |
|
---|
222 | WARN(("pfnEscapeCb failed, hr 0x%x", hr));
|
---|
223 | return VERR_GENERAL_FAILURE;
|
---|
224 | }
|
---|
225 |
|
---|
226 | void vboxUhgsmiD3DInit(PVBOXUHGSMI_PRIVATE_D3D pHgsmi, PVBOXWDDMDISP_DEVICE pDevice)
|
---|
227 | {
|
---|
228 | pHgsmi->BasePrivate.Base.pfnBufferCreate = vboxUhgsmiD3DBufferCreate;
|
---|
229 | pHgsmi->BasePrivate.Base.pfnBufferSubmit = vboxUhgsmiD3DBufferSubmit;
|
---|
230 | /* escape is still needed, since Ugfsmi uses it e.g. to query connection id */
|
---|
231 | pHgsmi->BasePrivate.pfnEscape = vboxCrHhgsmiDispEscape;
|
---|
232 | pHgsmi->pDevice = pDevice;
|
---|
233 | }
|
---|
234 |
|
---|
235 | void vboxUhgsmiD3DEscInit(PVBOXUHGSMI_PRIVATE_D3D pHgsmi, struct VBOXWDDMDISP_DEVICE *pDevice)
|
---|
236 | {
|
---|
237 | vboxUhgsmiBaseInit(&pHgsmi->BasePrivate, vboxCrHhgsmiDispEscape);
|
---|
238 | pHgsmi->pDevice = pDevice;
|
---|
239 | }
|
---|