VirtualBox

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

Last change on this file since 43621 was 43607, checked in by vboxsync, 12 years ago

wddm/3d: d3d width in SurfDesc to make it properly propagated to OpenResource

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