VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h@ 39900

Last change on this file since 39900 was 39900, checked in by vboxsync, 13 years ago

wddm/3d: debugging stuff

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
1/* $Id: VBoxDispD3D.h 39900 2012-01-27 15:47:30Z vboxsync $ */
2
3/** @file
4 * VBoxVideo Display D3D User mode dll
5 */
6
7/*
8 * Copyright (C) 2011 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#ifndef ___VBoxDispD3D_h___
20#define ___VBoxDispD3D_h___
21
22#include "VBoxDispD3DIf.h"
23#include "common/wddm/VBoxMPIf.h"
24#ifdef VBOX_WITH_CRHGSMI
25#include "VBoxUhgsmiDisp.h"
26#endif
27
28#include <iprt/cdefs.h>
29#include <iprt/list.h>
30
31#define VBOXWDDMDISP_MAX_VERTEX_STREAMS 16
32#define VBOXWDDMDISP_MAX_SWAPCHAIN_SIZE 16
33#ifdef VBOXWDDMDISP_DEBUG
34# define VBOXWDDMDISP_MAX_TEX_SAMPLERS 16
35# define VBOXWDDMDISP_TOTAL_SAMPLERS VBOXWDDMDISP_MAX_TEX_SAMPLERS + 5
36# define VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(_i) ((_i) >= D3DDMAPSAMPLER && (_i) <= D3DVERTEXTEXTURESAMPLER3)
37# define VBOXWDDMDISP_SAMPLER_IDX_SPECIAL(_i) (VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(_i) ? (int)((_i) - D3DDMAPSAMPLER + VBOXWDDMDISP_MAX_TEX_SAMPLERS) : (int)-1)
38# define VBOXWDDMDISP_SAMPLER_IDX(_i) (((_i) < VBOXWDDMDISP_MAX_TEX_SAMPLERS) ? (int)(_i) : VBOXWDDMDISP_SAMPLER_IDX_SPECIAL(_i))
39#endif
40/* maximum number of direct render targets to be used before
41 * switching to offscreen rendering */
42#ifdef VBOXWDDMDISP_DEBUG
43# define VBOXWDDMDISP_MAX_DIRECT_RTS g_VBoxVDbgCfgMaxDirectRts
44#else
45# define VBOXWDDMDISP_MAX_DIRECT_RTS 3
46#endif
47
48#define VBOXWDDMDISP_IS_TEXTURE(_f) ((_f).Texture || (_f).Value == 0)
49
50#ifdef VBOX_WITH_VIDEOHWACCEL
51typedef struct VBOXDISPVHWA_INFO
52{
53 VBOXVHWA_INFO Settings;
54}VBOXDISPVHWA_INFO;
55
56/* represents settings secific to
57 * display device (head) on the multiple-head graphics card
58 * currently used for 2D (overlay) only since in theory its settings
59 * can differ per each frontend's framebuffer. */
60typedef struct VBOXWDDMDISP_HEAD
61{
62 VBOXDISPVHWA_INFO Vhwa;
63} VBOXWDDMDISP_HEAD;
64#endif
65
66typedef struct VBOXWDDMDISP_ADAPTER
67{
68 HANDLE hAdapter;
69 UINT uIfVersion;
70 UINT uRtVersion;
71 VBOXDISPD3D D3D;
72 IDirect3D9Ex * pD3D9If;
73 D3DDDI_ADAPTERCALLBACKS RtCallbacks;
74 uint32_t cFormstOps;
75 FORMATOP *paFormstOps;
76 uint32_t cSurfDescs;
77 DDSURFACEDESC *paSurfDescs;
78 UINT cMaxSimRTs;
79#ifdef VBOX_WITH_VIDEOHWACCEL
80 uint32_t cHeads;
81 VBOXWDDMDISP_HEAD aHeads[1];
82#endif
83} VBOXWDDMDISP_ADAPTER, *PVBOXWDDMDISP_ADAPTER;
84
85typedef struct VBOXWDDMDISP_CONTEXT
86{
87 RTLISTNODE ListNode;
88 struct VBOXWDDMDISP_DEVICE *pDevice;
89 D3DDDICB_CREATECONTEXT ContextInfo;
90} VBOXWDDMDISP_CONTEXT, *PVBOXWDDMDISP_CONTEXT;
91
92typedef struct VBOXWDDMDISP_STREAMSOURCEUM
93{
94 CONST VOID* pvBuffer;
95 UINT cbStride;
96} VBOXWDDMDISP_STREAMSOURCEUM, *PVBOXWDDMDISP_STREAMSOURCEUM;
97
98typedef struct VBOXWDDMDISP_INDICIESUM
99{
100 CONST VOID* pvBuffer;
101 UINT cbSize;
102} VBOXWDDMDISP_INDICIESUM, *PVBOXWDDMDISP_INDICIESUM;
103
104struct VBOXWDDMDISP_ALLOCATION;
105
106typedef struct VBOXWDDMDISP_STREAM_SOURCE_INFO
107{
108 UINT uiOffset;
109 UINT uiStride;
110} VBOXWDDMDISP_STREAM_SOURCE_INFO;
111
112typedef struct VBOXWDDMDISP_INDICES_INFO
113{
114 UINT uiStride;
115} VBOXWDDMDISP_INDICES_INFO;
116
117typedef struct VBOXWDDMDISP_RENDERTGT_FLAGS
118{
119 union
120 {
121 struct
122 {
123 UINT bAdded : 1;
124 UINT bRemoved : 1;
125 UINT Reserved : 30;
126 };
127 uint32_t Value;
128 };
129}VBOXWDDMDISP_RENDERTGT_FLAGS;
130
131typedef struct VBOXWDDMDISP_RENDERTGT
132{
133 struct VBOXWDDMDISP_ALLOCATION *pAlloc;
134 UINT cNumFlips;
135 VBOXWDDMDISP_RENDERTGT_FLAGS fFlags;
136} VBOXWDDMDISP_RENDERTGT, *PVBOXWDDMDISP_RENDERTGT;
137
138#define VBOXWDDMDISP_INDEX_UNDEFINED (~0)
139typedef struct VBOXWDDMDISP_SWAPCHAIN_FLAGS
140{
141 union
142 {
143 struct
144 {
145 UINT bChanged : 1;
146 UINT bRtReportingPresent : 1; /* use VBox extension method for performing present */
147 UINT bSwitchReportingPresent : 1; /* switch to use VBox extension method for performing present on next present */
148 UINT Reserved : 29;
149 };
150 uint32_t Value;
151 };
152}VBOXWDDMDISP_SWAPCHAIN_FLAGS;
153
154typedef struct VBOXWDDMDISP_SWAPCHAIN
155{
156 RTLISTNODE ListEntry;
157 UINT iBB; /* Backbuffer index */
158 UINT cRTs; /* Number of render targets in the swapchain */
159 VBOXWDDMDISP_SWAPCHAIN_FLAGS fFlags;
160#ifndef VBOXWDDM_WITH_VISIBLE_FB
161 IDirect3DSurface9 *pRenderTargetFbCopy;
162 BOOL bRTFbCopyUpToDate;
163#endif
164 IDirect3DSwapChain9 *pSwapChainIf;
165 /* a read-only hWnd we receive from wine
166 * we use it for visible region notifications only,
167 * it MUST NOT be destroyed on swapchain destruction,
168 * wine will handle that for us */
169 HWND hWnd;
170 VBOXDISP_KMHANDLE hSwapchainKm;
171 VBOXWDDMDISP_RENDERTGT aRTs[VBOXWDDMDISP_MAX_SWAPCHAIN_SIZE];
172} VBOXWDDMDISP_SWAPCHAIN, *PVBOXWDDMDISP_SWAPCHAIN;
173
174typedef struct VBOXWDDMDISP_DEVICE
175{
176 HANDLE hDevice;
177 PVBOXWDDMDISP_ADAPTER pAdapter;
178 IDirect3DDevice9 *pDevice9If;
179 RTLISTANCHOR SwapchainList;
180 UINT u32IfVersion;
181 UINT uRtVersion;
182 D3DDDI_DEVICECALLBACKS RtCallbacks;
183 VOID *pvCmdBuffer;
184 UINT cbCmdBuffer;
185 D3DDDI_CREATEDEVICEFLAGS fFlags;
186 /* number of StreamSources set */
187 UINT cStreamSources;
188 VBOXWDDMDISP_STREAMSOURCEUM aStreamSourceUm[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
189 struct VBOXWDDMDISP_ALLOCATION *aStreamSource[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
190 VBOXWDDMDISP_STREAM_SOURCE_INFO StreamSourceInfo[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
191 VBOXWDDMDISP_INDICIESUM IndiciesUm;
192 struct VBOXWDDMDISP_ALLOCATION *pIndicesAlloc;
193 VBOXWDDMDISP_INDICES_INFO IndiciesInfo;
194 /* need to cache the ViewPort data because IDirect3DDevice9::SetViewport
195 * is split into two calls : SetViewport & SetZRange */
196 D3DVIEWPORT9 ViewPort;
197 VBOXWDDMDISP_CONTEXT DefaultContext;
198#ifdef VBOX_WITH_CRHGSMI
199 VBOXUHGSMI_PRIVATE_D3D Uhgsmi;
200#endif
201
202 /* no lock is needed for this since we're guaranteed the per-device calls are not reentrant */
203 RTLISTANCHOR DirtyAllocList;
204
205#ifdef VBOXWDDMDISP_DEBUG
206 UINT cSamplerTextures;
207 struct VBOXWDDMDISP_RESOURCE *aSamplerTextures[VBOXWDDMDISP_TOTAL_SAMPLERS];
208#endif
209
210 UINT cRTs;
211 struct VBOXWDDMDISP_ALLOCATION * apRTs[1];
212} VBOXWDDMDISP_DEVICE, *PVBOXWDDMDISP_DEVICE;
213
214typedef struct VBOXWDDMDISP_LOCKINFO
215{
216 uint32_t cLocks;
217 union {
218 D3DDDIRANGE Range;
219 RECT Area;
220 D3DDDIBOX Box;
221 };
222 D3DDDI_LOCKFLAGS fFlags;
223 D3DLOCKED_RECT LockedRect;
224#ifdef VBOXWDDMDISP_DEBUG
225 PVOID pvData;
226#endif
227} VBOXWDDMDISP_LOCKINFO;
228
229typedef enum
230{
231 VBOXDISP_D3DIFTYPE_UNDEFINED = 0,
232 VBOXDISP_D3DIFTYPE_SURFACE,
233 VBOXDISP_D3DIFTYPE_TEXTURE,
234 VBOXDISP_D3DIFTYPE_CUBE_TEXTURE,
235 VBOXDISP_D3DIFTYPE_VERTEXBUFFER,
236 VBOXDISP_D3DIFTYPE_INDEXBUFFER
237} VBOXDISP_D3DIFTYPE;
238
239typedef struct VBOXWDDMDISP_ALLOCATION
240{
241 D3DKMT_HANDLE hAllocation;
242 VBOXWDDM_ALLOC_TYPE enmType;
243 UINT iAlloc;
244 struct VBOXWDDMDISP_RESOURCE *pRc;
245 void* pvMem;
246 UINT D3DWidth;
247 /* object type is defined by enmD3DIfType enum */
248 IUnknown *pD3DIf;
249 VBOXDISP_D3DIFTYPE enmD3DIfType;
250 /* list entry used to add allocation to the dirty alloc list */
251 RTLISTNODE DirtyAllocListEntry;
252 BOOLEAN fDirtyWrite;
253 HANDLE hSharedHandle;
254 VBOXWDDMDISP_LOCKINFO LockInfo;
255 VBOXWDDM_DIRTYREGION DirtyRegion; /* <- dirty region to notify host about */
256 VBOXWDDM_SURFACE_DESC SurfDesc;
257 PVBOXWDDMDISP_SWAPCHAIN pSwapchain;
258} VBOXWDDMDISP_ALLOCATION, *PVBOXWDDMDISP_ALLOCATION;
259
260typedef struct VBOXWDDMDISP_RESOURCE
261{
262 HANDLE hResource;
263 D3DKMT_HANDLE hKMResource;
264 PVBOXWDDMDISP_DEVICE pDevice;
265 VBOXWDDMDISP_RESOURCE_FLAGS fFlags;
266 VBOXWDDM_RC_DESC RcDesc;
267 UINT cAllocations;
268 VBOXWDDMDISP_ALLOCATION aAllocations[1];
269} VBOXWDDMDISP_RESOURCE, *PVBOXWDDMDISP_RESOURCE;
270
271typedef struct VBOXWDDMDISP_QUERY
272{
273 D3DDDIQUERYTYPE enmType;
274 D3DDDI_ISSUEQUERYFLAGS fQueryState;
275 union
276 {
277 BOOL bData;
278 UINT u32Data;
279 } data ;
280} VBOXWDDMDISP_QUERY, *PVBOXWDDMDISP_QUERY;
281
282typedef struct VBOXWDDMDISP_TSS_LOOKUP
283{
284 BOOL bSamplerState;
285 DWORD dType;
286} VBOXWDDMDISP_TSS_LOOKUP;
287
288typedef struct VBOXWDDMDISP_OVERLAY
289{
290 D3DKMT_HANDLE hOverlay;
291 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
292 PVBOXWDDMDISP_RESOURCE *pResource;
293} VBOXWDDMDISP_OVERLAY, *PVBOXWDDMDISP_OVERLAY;
294
295#define VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc) (((pRc)->cAllocations)/6)
296#define VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, idx) ((D3DCUBEMAP_FACES)(D3DCUBEMAP_FACE_POSITIVE_X+(idx)%VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc)))
297#define VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, idx) ((idx)%VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc))
298
299#ifdef VBOX_WITH_CRHGSMI
300HRESULT vboxUhgsmiGlobalSetCurrent();
301HRESULT vboxUhgsmiGlobalClearCurrent();
302#endif
303
304DECLINLINE(PVBOXWDDMDISP_SWAPCHAIN) vboxWddmSwapchainForAlloc(PVBOXWDDMDISP_ALLOCATION pAlloc)
305{
306 return pAlloc->pSwapchain;
307}
308
309DECLINLINE(UINT) vboxWddmSwapchainIdxFb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
310{
311 return (pSwapchain->iBB + pSwapchain->cRTs - 1) % pSwapchain->cRTs;
312}
313
314/* if swapchain contains only one surface returns this surface */
315DECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainGetBb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
316{
317 if (pSwapchain->cRTs)
318 {
319 Assert(pSwapchain->iBB < pSwapchain->cRTs);
320 return &pSwapchain->aRTs[pSwapchain->iBB];
321 }
322 return NULL;
323}
324
325DECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainGetFb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
326{
327 if (pSwapchain->cRTs)
328 {
329 UINT iFb = vboxWddmSwapchainIdxFb(pSwapchain);
330 return &pSwapchain->aRTs[iFb];
331 }
332 return NULL;
333}
334
335/* on success increments the surface ref counter,
336 * i.e. one must call pSurf->Release() once the surface is not needed*/
337DECLINLINE(HRESULT) vboxWddmSurfGet(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc, IDirect3DSurface9 **ppSurf)
338{
339 HRESULT hr = S_OK;
340 Assert(pRc->cAllocations > iAlloc);
341 switch (pRc->aAllocations[0].enmD3DIfType)
342 {
343 case VBOXDISP_D3DIFTYPE_SURFACE:
344 {
345 IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pRc->aAllocations[iAlloc].pD3DIf;
346 Assert(pD3DIfSurf);
347 pD3DIfSurf->AddRef();
348 *ppSurf = pD3DIfSurf;
349 break;
350 }
351 case VBOXDISP_D3DIFTYPE_TEXTURE:
352 {
353 Assert(pRc->cAllocations == 1); /* <- vboxWddmSurfGet is typically used in Blt & ColorFill functions
354 * in this case, if texture is used as a destination,
355 * we should update sub-layers as well which is not done currently
356 * so for now check vboxWddmSurfGet is used for one-level textures */
357 IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pRc->aAllocations[0].pD3DIf;
358 IDirect3DSurface9 *pSurfaceLevel;
359 Assert(pD3DIfTex);
360 hr = pD3DIfTex->GetSurfaceLevel(iAlloc, &pSurfaceLevel);
361 Assert(hr == S_OK);
362 if (hr == S_OK)
363 {
364 *ppSurf = pSurfaceLevel;
365 }
366 break;
367 }
368 case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
369 {
370 Assert(0);
371 IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pRc->aAllocations[0].pD3DIf;
372 IDirect3DSurface9 *pSurfaceLevel;
373 Assert(pD3DIfCubeTex);
374 hr = pD3DIfCubeTex->GetCubeMapSurface(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, iAlloc),
375 VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, iAlloc), &pSurfaceLevel);
376 Assert(hr == S_OK);
377 if (hr == S_OK)
378 {
379 *ppSurf = pSurfaceLevel;
380 }
381 break;
382 }
383 default:
384 Assert(0);
385 hr = E_FAIL;
386 break;
387 }
388 return hr;
389}
390
391HRESULT vboxWddmLockRect(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc,
392 D3DLOCKED_RECT * pLockedRect,
393 CONST RECT *pRect,
394 DWORD fLockFlags);
395HRESULT vboxWddmUnlockRect(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc);
396
397#define VBOXDISPMODE_IS_3D(_p) (!!((_p)->pD3D9If))
398#ifdef VBOXDISP_EARLYCREATEDEVICE
399#define VBOXDISP_D3DEV(_p) (_p)->pDevice9If
400#else
401#define VBOXDISP_D3DEV(_p) vboxWddmD3DDeviceGet(_p)
402#endif
403
404#endif /* #ifndef ___VBoxDispD3D_h___ */
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