VirtualBox

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

Last change on this file since 62522 was 62522, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 KB
Line 
1/* $Id: VBoxDispD3D.h 62522 2016-07-22 19:17:25Z vboxsync $ */
2
3/** @file
4 * VBoxVideo Display D3D User mode dll
5 */
6
7/*
8 * Copyright (C) 2011-2016 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#ifdef VBOX_WITH_CRHGSMI
207 VBOXUHGSMI_PRIVATE_D3D Uhgsmi;
208#endif
209
210 /* no lock is needed for this since we're guaranteed the per-device calls are not reentrant */
211 RTLISTANCHOR DirtyAllocList;
212
213 UINT cSamplerTextures;
214 struct VBOXWDDMDISP_RESOURCE *aSamplerTextures[VBOXWDDMDISP_TOTAL_SAMPLERS];
215
216 struct VBOXWDDMDISP_RESOURCE *pDepthStencilRc;
217
218 HMODULE hHgsmiTransportModule;
219
220#ifdef VBOX_WDDMDISP_WITH_PROFILE
221 VBoxDispProfileFpsCounter ProfileDdiFps;
222 VBoxDispProfileSet ProfileDdiFunc;
223
224 VBoxDispProfileSet ProfileDdiPresentCb;
225#endif
226
227#ifdef VBOXWDDMDISP_DEBUG_TIMER
228 HANDLE hTimerQueue;
229#endif
230
231 UINT cRTs;
232 struct VBOXWDDMDISP_ALLOCATION * apRTs[1];
233} VBOXWDDMDISP_DEVICE, *PVBOXWDDMDISP_DEVICE;
234
235typedef struct VBOXWDDMDISP_LOCKINFO
236{
237 uint32_t cLocks;
238 union {
239 D3DDDIRANGE Range;
240 RECT Area;
241 D3DDDIBOX Box;
242 };
243 D3DDDI_LOCKFLAGS fFlags;
244 union {
245 D3DLOCKED_RECT LockedRect;
246 D3DLOCKED_BOX LockedBox;
247 };
248#ifdef VBOXWDDMDISP_DEBUG
249 PVOID pvData;
250#endif
251} VBOXWDDMDISP_LOCKINFO;
252
253typedef enum
254{
255 VBOXDISP_D3DIFTYPE_UNDEFINED = 0,
256 VBOXDISP_D3DIFTYPE_SURFACE,
257 VBOXDISP_D3DIFTYPE_TEXTURE,
258 VBOXDISP_D3DIFTYPE_CUBE_TEXTURE,
259 VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE,
260 VBOXDISP_D3DIFTYPE_VERTEXBUFFER,
261 VBOXDISP_D3DIFTYPE_INDEXBUFFER
262} VBOXDISP_D3DIFTYPE;
263
264typedef struct VBOXWDDMDISP_ALLOCATION
265{
266 D3DKMT_HANDLE hAllocation;
267 VBOXWDDM_ALLOC_TYPE enmType;
268 UINT iAlloc;
269 struct VBOXWDDMDISP_RESOURCE *pRc;
270 void* pvMem;
271 /* object type is defined by enmD3DIfType enum */
272 IUnknown *pD3DIf;
273 VBOXDISP_D3DIFTYPE enmD3DIfType;
274 /* list entry used to add allocation to the dirty alloc list */
275 RTLISTNODE DirtyAllocListEntry;
276 BOOLEAN fEverWritten;
277 BOOLEAN fDirtyWrite;
278 BOOLEAN fAllocLocked;
279 HANDLE hSharedHandle;
280 VBOXWDDMDISP_LOCKINFO LockInfo;
281 VBOXWDDM_DIRTYREGION DirtyRegion; /* <- dirty region to notify host about */
282 VBOXWDDM_SURFACE_DESC SurfDesc;
283 PVBOXWDDMDISP_SWAPCHAIN pSwapchain;
284} VBOXWDDMDISP_ALLOCATION, *PVBOXWDDMDISP_ALLOCATION;
285
286typedef struct VBOXWDDMDISP_RESOURCE
287{
288 HANDLE hResource;
289 D3DKMT_HANDLE hKMResource;
290 PVBOXWDDMDISP_DEVICE pDevice;
291 VBOXWDDMDISP_RESOURCE_FLAGS fFlags;
292 VBOXWDDM_RC_DESC RcDesc;
293 UINT cAllocations;
294 VBOXWDDMDISP_ALLOCATION aAllocations[1];
295} VBOXWDDMDISP_RESOURCE, *PVBOXWDDMDISP_RESOURCE;
296
297typedef struct VBOXWDDMDISP_QUERY
298{
299 D3DDDIQUERYTYPE enmType;
300 D3DDDI_ISSUEQUERYFLAGS fQueryState;
301 IDirect3DQuery9 *pQueryIf;
302} VBOXWDDMDISP_QUERY, *PVBOXWDDMDISP_QUERY;
303
304typedef struct VBOXWDDMDISP_TSS_LOOKUP
305{
306 BOOL bSamplerState;
307 DWORD dType;
308} VBOXWDDMDISP_TSS_LOOKUP;
309
310typedef struct VBOXWDDMDISP_OVERLAY
311{
312 D3DKMT_HANDLE hOverlay;
313 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
314 PVBOXWDDMDISP_RESOURCE *pResource;
315} VBOXWDDMDISP_OVERLAY, *PVBOXWDDMDISP_OVERLAY;
316
317#define VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc) (((pRc)->cAllocations)/6)
318#define VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, idx) ((D3DCUBEMAP_FACES)(D3DCUBEMAP_FACE_POSITIVE_X+(idx)%VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc)))
319#define VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, idx) ((idx)%VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc))
320
321DECLINLINE(PVBOXWDDMDISP_SWAPCHAIN) vboxWddmSwapchainForAlloc(PVBOXWDDMDISP_ALLOCATION pAlloc)
322{
323 return pAlloc->pSwapchain;
324}
325
326DECLINLINE(UINT) vboxWddmSwapchainIdxFb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
327{
328 return (pSwapchain->iBB + pSwapchain->cRTs - 1) % pSwapchain->cRTs;
329}
330
331/* if swapchain contains only one surface returns this surface */
332DECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainGetBb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
333{
334 if (pSwapchain->cRTs)
335 {
336 Assert(pSwapchain->iBB < pSwapchain->cRTs);
337 return &pSwapchain->aRTs[pSwapchain->iBB];
338 }
339 return NULL;
340}
341
342DECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainGetFb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
343{
344 if (pSwapchain->cRTs)
345 {
346 UINT iFb = vboxWddmSwapchainIdxFb(pSwapchain);
347 return &pSwapchain->aRTs[iFb];
348 }
349 return NULL;
350}
351
352void vboxWddmResourceInit(PVBOXWDDMDISP_RESOURCE pRc, UINT cAllocs);
353
354#ifndef IN_VBOXCRHGSMI
355PVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainFindCreate(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pBbAlloc, BOOL *pbNeedPresent);
356HRESULT vboxWddmSwapchainChkCreateIf(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);
357VOID vboxWddmSwapchainDestroy(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);
358
359#endif
360
361#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