VirtualBox

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

Last change on this file since 69498 was 69498, checked in by vboxsync, 7 years ago

backed out r118835 as it incorrectly updated the 'This file is based on' file headers.

  • 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 69498 2017-10-28 15:07:25Z vboxsync $ */
2/** @file
3 * VBoxVideo Display D3D User mode dll
4 */
5
6/*
7 * Copyright (C) 2011-2016 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#ifndef ___VBoxDispD3D_h___
19#define ___VBoxDispD3D_h___
20
21#include "VBoxDispD3DIf.h"
22#include "../../common/wddm/VBoxMPIf.h"
23#ifdef VBOX_WITH_CRHGSMI
24#include "VBoxUhgsmiDisp.h"
25#endif
26
27#ifdef VBOX_WDDMDISP_WITH_PROFILE
28#include <iprt/asm.h>
29extern volatile uint32_t g_u32VBoxDispProfileFunctionLoggerIndex;
30# define VBOXDISPPROFILE_FUNCTION_LOGGER_INDEX_GEN() ASMAtomicIncU32(&g_u32VBoxDispProfileFunctionLoggerIndex);
31# include "VBoxDispProfile.h"
32#endif
33
34#include <iprt/cdefs.h>
35#include <iprt/list.h>
36
37#define VBOXWDDMDISP_MAX_VERTEX_STREAMS 16
38#define VBOXWDDMDISP_MAX_SWAPCHAIN_SIZE 16
39#define VBOXWDDMDISP_MAX_TEX_SAMPLERS 16
40#define VBOXWDDMDISP_TOTAL_SAMPLERS VBOXWDDMDISP_MAX_TEX_SAMPLERS + 5
41#define VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(_i) ((_i) >= D3DDMAPSAMPLER && (_i) <= D3DVERTEXTEXTURESAMPLER3)
42#define VBOXWDDMDISP_SAMPLER_IDX_SPECIAL(_i) (VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(_i) ? (int)((_i) - D3DDMAPSAMPLER + VBOXWDDMDISP_MAX_TEX_SAMPLERS) : (int)-1)
43#define VBOXWDDMDISP_SAMPLER_IDX(_i) (((_i) < VBOXWDDMDISP_MAX_TEX_SAMPLERS) ? (int)(_i) : VBOXWDDMDISP_SAMPLER_IDX_SPECIAL(_i))
44
45
46/* maximum number of direct render targets to be used before
47 * switching to offscreen rendering */
48#ifdef VBOXWDDMDISP_DEBUG
49# define VBOXWDDMDISP_MAX_DIRECT_RTS g_VBoxVDbgCfgMaxDirectRts
50#else
51# define VBOXWDDMDISP_MAX_DIRECT_RTS 3
52#endif
53
54#define VBOXWDDMDISP_IS_TEXTURE(_f) ((_f).Texture || (_f).Value == 0)
55
56#ifdef VBOX_WITH_VIDEOHWACCEL
57typedef struct VBOXDISPVHWA_INFO
58{
59 VBOXVHWA_INFO Settings;
60}VBOXDISPVHWA_INFO;
61
62/* represents settings secific to
63 * display device (head) on the multiple-head graphics card
64 * currently used for 2D (overlay) only since in theory its settings
65 * can differ per each frontend's framebuffer. */
66typedef struct VBOXWDDMDISP_HEAD
67{
68 VBOXDISPVHWA_INFO Vhwa;
69} VBOXWDDMDISP_HEAD;
70#endif
71
72typedef struct VBOXWDDMDISP_ADAPTER
73{
74 HANDLE hAdapter;
75 UINT uIfVersion;
76 UINT uRtVersion;
77 D3DDDI_ADAPTERCALLBACKS RtCallbacks;
78 VBOXWDDMDISP_D3D D3D;
79 VBOXWDDMDISP_FORMATS Formats;
80 uint32_t u32VBox3DCaps;
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 (~0U)
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#ifdef VBOX_WITH_CRHGSMI
206 VBOXUHGSMI_PRIVATE_D3D Uhgsmi;
207#endif
208
209 /* no lock is needed for this since we're guaranteed the per-device calls are not reentrant */
210 RTLISTANCHOR DirtyAllocList;
211
212 UINT cSamplerTextures;
213 struct VBOXWDDMDISP_RESOURCE *aSamplerTextures[VBOXWDDMDISP_TOTAL_SAMPLERS];
214
215 struct VBOXWDDMDISP_RESOURCE *pDepthStencilRc;
216
217 HMODULE hHgsmiTransportModule;
218
219#ifdef VBOX_WDDMDISP_WITH_PROFILE
220 VBoxDispProfileFpsCounter ProfileDdiFps;
221 VBoxDispProfileSet ProfileDdiFunc;
222
223 VBoxDispProfileSet ProfileDdiPresentCb;
224#endif
225
226#ifdef VBOXWDDMDISP_DEBUG_TIMER
227 HANDLE hTimerQueue;
228#endif
229
230 UINT cRTs;
231 struct VBOXWDDMDISP_ALLOCATION * apRTs[1];
232} VBOXWDDMDISP_DEVICE, *PVBOXWDDMDISP_DEVICE;
233
234typedef struct VBOXWDDMDISP_LOCKINFO
235{
236 uint32_t cLocks;
237 union {
238 D3DDDIRANGE Range;
239 RECT Area;
240 D3DDDIBOX Box;
241 };
242 D3DDDI_LOCKFLAGS fFlags;
243 union {
244 D3DLOCKED_RECT LockedRect;
245 D3DLOCKED_BOX LockedBox;
246 };
247#ifdef VBOXWDDMDISP_DEBUG
248 PVOID pvData;
249#endif
250} VBOXWDDMDISP_LOCKINFO;
251
252typedef enum
253{
254 VBOXDISP_D3DIFTYPE_UNDEFINED = 0,
255 VBOXDISP_D3DIFTYPE_SURFACE,
256 VBOXDISP_D3DIFTYPE_TEXTURE,
257 VBOXDISP_D3DIFTYPE_CUBE_TEXTURE,
258 VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE,
259 VBOXDISP_D3DIFTYPE_VERTEXBUFFER,
260 VBOXDISP_D3DIFTYPE_INDEXBUFFER
261} VBOXDISP_D3DIFTYPE;
262
263typedef struct VBOXWDDMDISP_ALLOCATION
264{
265 D3DKMT_HANDLE hAllocation;
266 VBOXWDDM_ALLOC_TYPE enmType;
267 UINT iAlloc;
268 struct VBOXWDDMDISP_RESOURCE *pRc;
269 void* pvMem;
270 /* object type is defined by enmD3DIfType enum */
271 IUnknown *pD3DIf;
272 VBOXDISP_D3DIFTYPE enmD3DIfType;
273 /* list entry used to add allocation to the dirty alloc list */
274 RTLISTNODE DirtyAllocListEntry;
275 BOOLEAN fEverWritten;
276 BOOLEAN fDirtyWrite;
277 BOOLEAN fAllocLocked;
278 HANDLE hSharedHandle;
279 VBOXWDDMDISP_LOCKINFO LockInfo;
280 VBOXWDDM_DIRTYREGION DirtyRegion; /* <- dirty region to notify host about */
281 VBOXWDDM_SURFACE_DESC SurfDesc;
282 PVBOXWDDMDISP_SWAPCHAIN pSwapchain;
283} VBOXWDDMDISP_ALLOCATION, *PVBOXWDDMDISP_ALLOCATION;
284
285typedef struct VBOXWDDMDISP_RESOURCE
286{
287 HANDLE hResource;
288 D3DKMT_HANDLE hKMResource;
289 PVBOXWDDMDISP_DEVICE pDevice;
290 VBOXWDDMDISP_RESOURCE_FLAGS fFlags;
291 VBOXWDDM_RC_DESC RcDesc;
292 UINT cAllocations;
293 VBOXWDDMDISP_ALLOCATION aAllocations[1];
294} VBOXWDDMDISP_RESOURCE, *PVBOXWDDMDISP_RESOURCE;
295
296typedef struct VBOXWDDMDISP_QUERY
297{
298 D3DDDIQUERYTYPE enmType;
299 D3DDDI_ISSUEQUERYFLAGS fQueryState;
300 IDirect3DQuery9 *pQueryIf;
301} VBOXWDDMDISP_QUERY, *PVBOXWDDMDISP_QUERY;
302
303typedef struct VBOXWDDMDISP_TSS_LOOKUP
304{
305 BOOL bSamplerState;
306 DWORD dType;
307} VBOXWDDMDISP_TSS_LOOKUP;
308
309typedef struct VBOXWDDMDISP_OVERLAY
310{
311 D3DKMT_HANDLE hOverlay;
312 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
313 PVBOXWDDMDISP_RESOURCE *pResource;
314} VBOXWDDMDISP_OVERLAY, *PVBOXWDDMDISP_OVERLAY;
315
316#define VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc) (((pRc)->cAllocations)/6)
317#define VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, idx) ((D3DCUBEMAP_FACES)(D3DCUBEMAP_FACE_POSITIVE_X+(idx)/VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc)))
318#define VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, idx) ((idx)%VBOXDISP_CUBEMAP_LEVELS_COUNT(pRc))
319
320DECLINLINE(PVBOXWDDMDISP_SWAPCHAIN) vboxWddmSwapchainForAlloc(PVBOXWDDMDISP_ALLOCATION pAlloc)
321{
322 return pAlloc->pSwapchain;
323}
324
325DECLINLINE(UINT) vboxWddmSwapchainIdxFb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
326{
327 return (pSwapchain->iBB + pSwapchain->cRTs - 1) % pSwapchain->cRTs;
328}
329
330/* if swapchain contains only one surface returns this surface */
331DECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainGetBb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
332{
333 if (pSwapchain->cRTs)
334 {
335 Assert(pSwapchain->iBB < pSwapchain->cRTs);
336 return &pSwapchain->aRTs[pSwapchain->iBB];
337 }
338 return NULL;
339}
340
341DECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainGetFb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
342{
343 if (pSwapchain->cRTs)
344 {
345 UINT iFb = vboxWddmSwapchainIdxFb(pSwapchain);
346 return &pSwapchain->aRTs[iFb];
347 }
348 return NULL;
349}
350
351void vboxWddmResourceInit(PVBOXWDDMDISP_RESOURCE pRc, UINT cAllocs);
352
353#ifndef IN_VBOXCRHGSMI
354PVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainFindCreate(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pBbAlloc, BOOL *pbNeedPresent);
355HRESULT vboxWddmSwapchainChkCreateIf(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);
356VOID vboxWddmSwapchainDestroy(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);
357
358#endif
359
360#endif /* #ifndef ___VBoxDispD3D_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette