VirtualBox

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

Last change on this file since 49591 was 49180, checked in by vboxsync, 11 years ago

wddm/3d: ref d3d rt to avoid calling unloaded lib

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
1/* $Id: VBoxDispD3D.h 49180 2013-10-18 12:35:36Z 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#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#ifdef VBOX_WDDMDISP_WITH_PROFILE
29#include <iprt/asm.h>
30extern volatile uint32_t g_u32VBoxDispProfileFunctionLoggerIndex;
31# define VBOXDISPPROFILE_FUNCTION_LOGGER_INDEX_GEN() ASMAtomicIncU32(&g_u32VBoxDispProfileFunctionLoggerIndex);
32# include "VBoxDispProfile.h"
33#endif
34
35#include <iprt/cdefs.h>
36#include <iprt/list.h>
37
38#define VBOXWDDMDISP_MAX_VERTEX_STREAMS 16
39#define VBOXWDDMDISP_MAX_SWAPCHAIN_SIZE 16
40#define VBOXWDDMDISP_MAX_TEX_SAMPLERS 16
41#define VBOXWDDMDISP_TOTAL_SAMPLERS VBOXWDDMDISP_MAX_TEX_SAMPLERS + 5
42#define VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(_i) ((_i) >= D3DDMAPSAMPLER && (_i) <= D3DVERTEXTEXTURESAMPLER3)
43#define VBOXWDDMDISP_SAMPLER_IDX_SPECIAL(_i) (VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(_i) ? (int)((_i) - D3DDMAPSAMPLER + VBOXWDDMDISP_MAX_TEX_SAMPLERS) : (int)-1)
44#define VBOXWDDMDISP_SAMPLER_IDX(_i) (((_i) < VBOXWDDMDISP_MAX_TEX_SAMPLERS) ? (int)(_i) : VBOXWDDMDISP_SAMPLER_IDX_SPECIAL(_i))
45
46
47/* maximum number of direct render targets to be used before
48 * switching to offscreen rendering */
49#ifdef VBOXWDDMDISP_DEBUG
50# define VBOXWDDMDISP_MAX_DIRECT_RTS g_VBoxVDbgCfgMaxDirectRts
51#else
52# define VBOXWDDMDISP_MAX_DIRECT_RTS 3
53#endif
54
55#define VBOXWDDMDISP_IS_TEXTURE(_f) ((_f).Texture || (_f).Value == 0)
56
57#ifdef VBOX_WITH_VIDEOHWACCEL
58typedef struct VBOXDISPVHWA_INFO
59{
60 VBOXVHWA_INFO Settings;
61}VBOXDISPVHWA_INFO;
62
63/* represents settings secific to
64 * display device (head) on the multiple-head graphics card
65 * currently used for 2D (overlay) only since in theory its settings
66 * can differ per each frontend's framebuffer. */
67typedef struct VBOXWDDMDISP_HEAD
68{
69 VBOXDISPVHWA_INFO Vhwa;
70} VBOXWDDMDISP_HEAD;
71#endif
72
73typedef struct VBOXWDDMDISP_ADAPTER
74{
75 HANDLE hAdapter;
76 UINT uIfVersion;
77 UINT uRtVersion;
78 D3DDDI_ADAPTERCALLBACKS RtCallbacks;
79 VBOXWDDMDISP_D3D D3D;
80 VBOXWDDMDISP_FORMATS Formats;
81 uint32_t u32VBox3DCaps;
82#ifdef VBOX_WDDMDISP_WITH_PROFILE
83 VBoxDispProfileFpsCounter ProfileDdiFps;
84 VBoxDispProfileSet ProfileDdiFunc;
85#endif
86#ifdef VBOX_WITH_VIDEOHWACCEL
87 uint32_t cHeads;
88 VBOXWDDMDISP_HEAD aHeads[1];
89#endif
90} VBOXWDDMDISP_ADAPTER, *PVBOXWDDMDISP_ADAPTER;
91
92typedef struct VBOXWDDMDISP_CONTEXT
93{
94 RTLISTNODE ListNode;
95 struct VBOXWDDMDISP_DEVICE *pDevice;
96 D3DDDICB_CREATECONTEXT ContextInfo;
97} VBOXWDDMDISP_CONTEXT, *PVBOXWDDMDISP_CONTEXT;
98
99typedef struct VBOXWDDMDISP_STREAMSOURCEUM
100{
101 CONST VOID* pvBuffer;
102 UINT cbStride;
103} VBOXWDDMDISP_STREAMSOURCEUM, *PVBOXWDDMDISP_STREAMSOURCEUM;
104
105typedef struct VBOXWDDMDISP_INDICIESUM
106{
107 CONST VOID* pvBuffer;
108 UINT cbSize;
109} VBOXWDDMDISP_INDICIESUM, *PVBOXWDDMDISP_INDICIESUM;
110
111struct VBOXWDDMDISP_ALLOCATION;
112
113typedef struct VBOXWDDMDISP_STREAM_SOURCE_INFO
114{
115 UINT uiOffset;
116 UINT uiStride;
117} VBOXWDDMDISP_STREAM_SOURCE_INFO;
118
119typedef struct VBOXWDDMDISP_INDICES_INFO
120{
121 struct VBOXWDDMDISP_ALLOCATION *pIndicesAlloc;
122 const void *pvIndicesUm;
123 UINT uiStride;
124} VBOXWDDMDISP_INDICES_INFO;
125
126typedef struct VBOXWDDMDISP_RENDERTGT_FLAGS
127{
128 union
129 {
130 struct
131 {
132 UINT bAdded : 1;
133 UINT bRemoved : 1;
134 UINT Reserved : 30;
135 };
136 uint32_t Value;
137 };
138}VBOXWDDMDISP_RENDERTGT_FLAGS;
139
140typedef struct VBOXWDDMDISP_RENDERTGT
141{
142 struct VBOXWDDMDISP_ALLOCATION *pAlloc;
143 UINT cNumFlips;
144 VBOXWDDMDISP_RENDERTGT_FLAGS fFlags;
145} VBOXWDDMDISP_RENDERTGT, *PVBOXWDDMDISP_RENDERTGT;
146
147#define VBOXWDDMDISP_INDEX_UNDEFINED (~0)
148typedef struct VBOXWDDMDISP_SWAPCHAIN_FLAGS
149{
150 union
151 {
152 struct
153 {
154 UINT bChanged : 1;
155 UINT bRtReportingPresent : 1; /* use VBox extension method for performing present */
156 UINT bSwitchReportingPresent : 1; /* switch to use VBox extension method for performing present on next present */
157 UINT Reserved : 29;
158 };
159 uint32_t Value;
160 };
161}VBOXWDDMDISP_SWAPCHAIN_FLAGS;
162
163typedef struct VBOXWDDMDISP_SWAPCHAIN
164{
165 RTLISTNODE ListEntry;
166 UINT iBB; /* Backbuffer index */
167 UINT cRTs; /* Number of render targets in the swapchain */
168 VBOXWDDMDISP_SWAPCHAIN_FLAGS fFlags;
169#ifndef VBOXWDDM_WITH_VISIBLE_FB
170 IDirect3DSurface9 *pRenderTargetFbCopy;
171 BOOL bRTFbCopyUpToDate;
172#endif
173 IDirect3DSwapChain9 *pSwapChainIf;
174 /* a read-only hWnd we receive from wine
175 * we use it for visible region notifications only,
176 * it MUST NOT be destroyed on swapchain destruction,
177 * wine will handle that for us */
178 HWND hWnd;
179 VBOXDISP_KMHANDLE hSwapchainKm;
180 VBOXWDDMDISP_RENDERTGT aRTs[VBOXWDDMDISP_MAX_SWAPCHAIN_SIZE];
181} VBOXWDDMDISP_SWAPCHAIN, *PVBOXWDDMDISP_SWAPCHAIN;
182
183typedef struct VBOXWDDMDISP_DEVICE
184{
185 HANDLE hDevice;
186 PVBOXWDDMDISP_ADAPTER pAdapter;
187 IDirect3DDevice9 *pDevice9If;
188 RTLISTANCHOR SwapchainList;
189 UINT u32IfVersion;
190 UINT uRtVersion;
191 D3DDDI_DEVICECALLBACKS RtCallbacks;
192 VOID *pvCmdBuffer;
193 UINT cbCmdBuffer;
194 D3DDDI_CREATEDEVICEFLAGS fFlags;
195 /* number of StreamSources set */
196 UINT cStreamSources;
197 UINT cStreamSourcesUm;
198 VBOXWDDMDISP_STREAMSOURCEUM aStreamSourceUm[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
199 struct VBOXWDDMDISP_ALLOCATION *aStreamSource[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
200 VBOXWDDMDISP_STREAM_SOURCE_INFO StreamSourceInfo[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
201 VBOXWDDMDISP_INDICES_INFO IndiciesInfo;
202 /* need to cache the ViewPort data because IDirect3DDevice9::SetViewport
203 * is split into two calls : SetViewport & SetZRange */
204 D3DVIEWPORT9 ViewPort;
205 VBOXWDDMDISP_CONTEXT DefaultContext;
206 VBOXUHGSMI_PRIVATE_D3D Uhgsmi;
207
208 /* no lock is needed for this since we're guaranteed the per-device calls are not reentrant */
209 RTLISTANCHOR DirtyAllocList;
210
211 UINT cSamplerTextures;
212 struct VBOXWDDMDISP_RESOURCE *aSamplerTextures[VBOXWDDMDISP_TOTAL_SAMPLERS];
213
214 HMODULE hHgsmiTransportModule;
215
216#ifdef VBOX_WDDMDISP_WITH_PROFILE
217 VBoxDispProfileFpsCounter ProfileDdiFps;
218 VBoxDispProfileSet ProfileDdiFunc;
219
220 VBoxDispProfileSet ProfileDdiPresentCb;
221#endif
222
223#ifdef VBOXWDDMDISP_DEBUG_TIMER
224 HANDLE hTimerQueue;
225#endif
226
227 UINT cRTs;
228 struct VBOXWDDMDISP_ALLOCATION * apRTs[1];
229} VBOXWDDMDISP_DEVICE, *PVBOXWDDMDISP_DEVICE;
230
231typedef struct VBOXWDDMDISP_LOCKINFO
232{
233 uint32_t cLocks;
234 union {
235 D3DDDIRANGE Range;
236 RECT Area;
237 D3DDDIBOX Box;
238 };
239 D3DDDI_LOCKFLAGS fFlags;
240 union {
241 D3DLOCKED_RECT LockedRect;
242 D3DLOCKED_BOX LockedBox;
243 };
244#ifdef VBOXWDDMDISP_DEBUG
245 PVOID pvData;
246#endif
247} VBOXWDDMDISP_LOCKINFO;
248
249typedef enum
250{
251 VBOXDISP_D3DIFTYPE_UNDEFINED = 0,
252 VBOXDISP_D3DIFTYPE_SURFACE,
253 VBOXDISP_D3DIFTYPE_TEXTURE,
254 VBOXDISP_D3DIFTYPE_CUBE_TEXTURE,
255 VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE,
256 VBOXDISP_D3DIFTYPE_VERTEXBUFFER,
257 VBOXDISP_D3DIFTYPE_INDEXBUFFER
258} VBOXDISP_D3DIFTYPE;
259
260typedef struct VBOXWDDMDISP_ALLOCATION
261{
262 D3DKMT_HANDLE hAllocation;
263 VBOXWDDM_ALLOC_TYPE enmType;
264 UINT iAlloc;
265 struct VBOXWDDMDISP_RESOURCE *pRc;
266 void* pvMem;
267 /* object type is defined by enmD3DIfType enum */
268 IUnknown *pD3DIf;
269 VBOXDISP_D3DIFTYPE enmD3DIfType;
270 /* list entry used to add allocation to the dirty alloc list */
271 RTLISTNODE DirtyAllocListEntry;
272 BOOLEAN fDirtyWrite;
273 HANDLE hSharedHandle;
274 VBOXWDDMDISP_LOCKINFO LockInfo;
275 VBOXWDDM_DIRTYREGION DirtyRegion; /* <- dirty region to notify host about */
276 VBOXWDDM_SURFACE_DESC SurfDesc;
277 PVBOXWDDMDISP_SWAPCHAIN pSwapchain;
278} VBOXWDDMDISP_ALLOCATION, *PVBOXWDDMDISP_ALLOCATION;
279
280typedef struct VBOXWDDMDISP_RESOURCE
281{
282 HANDLE hResource;
283 D3DKMT_HANDLE hKMResource;
284 PVBOXWDDMDISP_DEVICE pDevice;
285 VBOXWDDMDISP_RESOURCE_FLAGS fFlags;
286 VBOXWDDM_RC_DESC RcDesc;
287 UINT cAllocations;
288 VBOXWDDMDISP_ALLOCATION aAllocations[1];
289} VBOXWDDMDISP_RESOURCE, *PVBOXWDDMDISP_RESOURCE;
290
291typedef struct VBOXWDDMDISP_QUERY
292{
293 D3DDDIQUERYTYPE enmType;
294 D3DDDI_ISSUEQUERYFLAGS fQueryState;
295 IDirect3DQuery9 *pQueryIf;
296} VBOXWDDMDISP_QUERY, *PVBOXWDDMDISP_QUERY;
297
298typedef struct VBOXWDDMDISP_TSS_LOOKUP
299{
300 BOOL bSamplerState;
301 DWORD dType;
302} VBOXWDDMDISP_TSS_LOOKUP;
303
304typedef struct VBOXWDDMDISP_OVERLAY
305{
306 D3DKMT_HANDLE hOverlay;
307 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
308 PVBOXWDDMDISP_RESOURCE *pResource;
309} VBOXWDDMDISP_OVERLAY, *PVBOXWDDMDISP_OVERLAY;
310
311#define VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc) (((pRc)->cAllocations)/6)
312#define VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, idx) ((D3DCUBEMAP_FACES)(D3DCUBEMAP_FACE_POSITIVE_X+(idx)%VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc)))
313#define VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, idx) ((idx)%VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc))
314
315DECLINLINE(PVBOXWDDMDISP_SWAPCHAIN) vboxWddmSwapchainForAlloc(PVBOXWDDMDISP_ALLOCATION pAlloc)
316{
317 return pAlloc->pSwapchain;
318}
319
320DECLINLINE(UINT) vboxWddmSwapchainIdxFb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
321{
322 return (pSwapchain->iBB + pSwapchain->cRTs - 1) % pSwapchain->cRTs;
323}
324
325/* if swapchain contains only one surface returns this surface */
326DECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainGetBb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
327{
328 if (pSwapchain->cRTs)
329 {
330 Assert(pSwapchain->iBB < pSwapchain->cRTs);
331 return &pSwapchain->aRTs[pSwapchain->iBB];
332 }
333 return NULL;
334}
335
336DECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainGetFb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
337{
338 if (pSwapchain->cRTs)
339 {
340 UINT iFb = vboxWddmSwapchainIdxFb(pSwapchain);
341 return &pSwapchain->aRTs[iFb];
342 }
343 return NULL;
344}
345
346void vboxWddmResourceInit(PVBOXWDDMDISP_RESOURCE pRc, UINT cAllocs);
347
348#ifndef IN_VBOXCRHGSMI
349PVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainFindCreate(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pBbAlloc, BOOL *pbNeedPresent);
350HRESULT vboxWddmSwapchainChkCreateIf(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);
351VOID vboxWddmSwapchainDestroy(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);
352
353#endif
354
355#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