VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxUhgsmiDisp.cpp@ 76553

Last change on this file since 76553 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/* $Id: VBoxUhgsmiDisp.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * VBoxVideo Display D3D User mode dll
4 */
5
6/*
7 * Copyright (C) 2011-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "VBoxDispD3DCmn.h"
19
20#define VBOXUHGSMID3D_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, BasePrivate.Base)))
21#define VBOXUHGSMID3D_GET(_p) VBOXUHGSMID3D_GET_PRIVATE(_p, VBOXUHGSMI_PRIVATE_D3D)
22
23#include <iprt/mem.h>
24#include <iprt/errcore.h>
25
26DECLCALLBACK(int) vboxUhgsmiD3DBufferDestroy(PVBOXUHGSMI_BUFFER pBuf)
27{
28 PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE pBuffer = VBOXUHGSMDXALLOCBASE_GET_BUFFER(pBuf);
29 struct VBOXWDDMDISP_DEVICE *pDevice = VBOXUHGSMID3D_GET(pBuffer->BasePrivate.pHgsmi)->pDevice;
30 D3DDDICB_DEALLOCATE DdiDealloc;
31 DdiDealloc.hResource = 0;
32 DdiDealloc.NumAllocations = 1;
33 DdiDealloc.HandleList = &pBuffer->hAllocation;
34 HRESULT hr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &DdiDealloc);
35 if (hr == S_OK)
36 {
37#ifdef DEBUG_misha
38 memset(pBuffer, 0, sizeof (*pBuffer));
39#endif
40 RTMemFree(pBuffer);
41 return VINF_SUCCESS;
42 }
43
44 WARN(("pfnDeallocateCb failed, hr %#x", hr));
45 return VERR_GENERAL_FAILURE;
46}
47
48/* typedef DECLCALLBACK(int) FNVBOXUHGSMI_BUFFER_LOCK(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock); */
49DECLCALLBACK(int) vboxUhgsmiD3DBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock,
50 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
82DECLCALLBACK(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);*/
98DECLCALLBACK(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;
112 pBuf = (PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE)RTMemAllocZ(RT_UOFFSETOF_DYN(VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE,
113 aLockPageIndices[cPages]));
114 if (pBuf)
115 {
116 D3DDDICB_ALLOCATE DdiAlloc;
117 D3DDDI_ALLOCATIONINFO DdiAllocInfo;
118 VBOXWDDM_ALLOCINFO AllocInfo;
119
120 memset(&DdiAlloc, 0, sizeof (DdiAlloc));
121 DdiAlloc.hResource = NULL;
122 DdiAlloc.hKMResource = NULL;
123 DdiAlloc.NumAllocations = 1;
124 DdiAlloc.pAllocationInfo = &DdiAllocInfo;
125 vboxUhgsmiBaseDxAllocInfoFill(&DdiAllocInfo, &AllocInfo, cbBuf, fType);
126
127 HRESULT hr = pPrivate->pDevice->RtCallbacks.pfnAllocateCb(pPrivate->pDevice->hDevice, &DdiAlloc);
128 if (hr == S_OK)
129 {
130 Assert(DdiAllocInfo.hAllocation);
131 pBuf->BasePrivate.Base.pfnLock = vboxUhgsmiD3DBufferLock;
132 pBuf->BasePrivate.Base.pfnUnlock = vboxUhgsmiD3DBufferUnlock;
133 pBuf->BasePrivate.Base.pfnDestroy = vboxUhgsmiD3DBufferDestroy;
134
135 pBuf->BasePrivate.Base.fType = fType;
136 pBuf->BasePrivate.Base.cbBuffer = cbBuf;
137
138 pBuf->BasePrivate.pHgsmi = &pPrivate->BasePrivate;
139
140 pBuf->hAllocation = DdiAllocInfo.hAllocation;
141
142 *ppBuf = &pBuf->BasePrivate.Base;
143
144 return VINF_SUCCESS;
145 }
146 else
147 {
148 WARN(("pfnAllocateCb failed hr %#x"));
149 rc = VERR_GENERAL_FAILURE;
150 }
151
152 RTMemFree(pBuf);
153 }
154 else
155 {
156 WARN(("RTMemAllocZ failed"));
157 rc = VERR_NO_MEMORY;
158 }
159
160 return rc;
161}
162
163/* typedef DECLCALLBACK(int) FNVBOXUHGSMI_BUFFER_SUBMIT(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers); */
164DECLCALLBACK(int) vboxUhgsmiD3DBufferSubmit(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers)
165{
166 PVBOXUHGSMI_PRIVATE_D3D pHg = VBOXUHGSMID3D_GET(pHgsmi);
167 PVBOXWDDMDISP_DEVICE pDevice = pHg->pDevice;
168
169 AssertReturn(pDevice->DefaultContext.ContextInfo.hContext, VERR_GENERAL_FAILURE);
170
171 UINT cbDmaCmd = pDevice->DefaultContext.ContextInfo.CommandBufferSize;
172 int rc = vboxUhgsmiBaseDxDmaFill(aBuffers, cBuffers,
173 pDevice->DefaultContext.ContextInfo.pCommandBuffer, &cbDmaCmd,
174 pDevice->DefaultContext.ContextInfo.pAllocationList, pDevice->DefaultContext.ContextInfo.AllocationListSize,
175 pDevice->DefaultContext.ContextInfo.pPatchLocationList, pDevice->DefaultContext.ContextInfo.PatchLocationListSize);
176 if (RT_FAILURE(rc))
177 {
178 WARN(("vboxUhgsmiBaseDxDmaFill failed, rc %d", rc));
179 return rc;
180 }
181
182 D3DDDICB_RENDER DdiRender = {0};
183 DdiRender.CommandLength = cbDmaCmd;
184 Assert(DdiRender.CommandLength);
185 Assert(DdiRender.CommandLength < UINT32_MAX/2);
186 DdiRender.CommandOffset = 0;
187 DdiRender.NumAllocations = cBuffers;
188 DdiRender.NumPatchLocations = 0;
189// DdiRender.NewCommandBufferSize = sizeof (VBOXVDMACMD) + 4 * (100);
190// DdiRender.NewAllocationListSize = 100;
191// DdiRender.NewPatchLocationListSize = 100;
192 DdiRender.hContext = pDevice->DefaultContext.ContextInfo.hContext;
193
194 HRESULT hr = pDevice->RtCallbacks.pfnRenderCb(pDevice->hDevice, &DdiRender);
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 WARN(("pfnRenderCb failed, hr %#x", hr));
208 return VERR_GENERAL_FAILURE;
209}
210
211static DECLCALLBACK(int) vboxCrHhgsmiDispEscape(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, void *pvData, uint32_t cbData, BOOL fHwAccess)
212{
213 PVBOXUHGSMI_PRIVATE_D3D pPrivate = VBOXUHGSMID3D_GET(pHgsmi);
214 PVBOXWDDMDISP_DEVICE pDevice = pPrivate->pDevice;
215
216 AssertReturn(pDevice->DefaultContext.ContextInfo.hContext, VERR_GENERAL_FAILURE);
217
218 D3DDDICB_ESCAPE DdiEscape = {0};
219 DdiEscape.hContext = pDevice->DefaultContext.ContextInfo.hContext;
220 DdiEscape.hDevice = pDevice->hDevice;
221 DdiEscape.Flags.HardwareAccess = !!fHwAccess;
222 DdiEscape.pPrivateDriverData = pvData;
223 DdiEscape.PrivateDriverDataSize = cbData;
224 HRESULT hr = pDevice->RtCallbacks.pfnEscapeCb(pDevice->pAdapter->hAdapter, &DdiEscape);
225 if (SUCCEEDED(hr))
226 {
227 return VINF_SUCCESS;
228 }
229
230 WARN(("pfnEscapeCb failed, hr 0x%x", hr));
231 return VERR_GENERAL_FAILURE;
232}
233
234void vboxUhgsmiD3DInit(PVBOXUHGSMI_PRIVATE_D3D pHgsmi, PVBOXWDDMDISP_DEVICE pDevice)
235{
236 pHgsmi->BasePrivate.Base.pfnBufferCreate = vboxUhgsmiD3DBufferCreate;
237 pHgsmi->BasePrivate.Base.pfnBufferSubmit = vboxUhgsmiD3DBufferSubmit;
238 /* escape is still needed, since Ugfsmi uses it e.g. to query connection id */
239 pHgsmi->BasePrivate.pfnEscape = vboxCrHhgsmiDispEscape;
240 pHgsmi->pDevice = pDevice;
241}
242
243void vboxUhgsmiD3DEscInit(PVBOXUHGSMI_PRIVATE_D3D pHgsmi, struct VBOXWDDMDISP_DEVICE *pDevice)
244{
245 vboxUhgsmiBaseInit(&pHgsmi->BasePrivate, vboxCrHhgsmiDispEscape);
246 pHgsmi->pDevice = pDevice;
247}
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