VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h@ 84909

Last change on this file since 84909 was 84742, checked in by vboxsync, 5 years ago

Devices/Graphics: experimental GLX graphics output

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 57.9 KB
Line 
1/* $Id: DevVGA-SVGA3d-internal.h 84742 2020-06-09 17:49:09Z vboxsync $ */
2/** @file
3 * DevVMWare - VMWare SVGA device - 3D part, internal header.
4 */
5
6/*
7 * Copyright (C) 2013-2020 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 VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h
19#define VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/*
25 * Assert sane compilation environment.
26 */
27#ifndef IN_RING3
28# error "VMSVGA3D_INCL_INTERNALS is only for ring-3 code"
29#endif
30#ifdef VMSVGA3D_OPENGL
31# ifdef VMSVGA3D_DIRECT3D
32# error "Both VMSVGA3D_DIRECT3D and VMSVGA3D_OPENGL cannot be defined at the same time."
33# endif
34#elif !defined(VMSVGA3D_DIRECT3D)
35# error "Either VMSVGA3D_OPENGL or VMSVGA3D_DIRECT3D must be defined."
36#endif
37
38
39/*********************************************************************************************************************************
40* Header Files *
41*********************************************************************************************************************************/
42#include "DevVGA-SVGA3d.h"
43
44#if defined(VMSVGA3D_DYNAMIC_LOAD) && defined(VMSVGA3D_OPENGL)
45# include "DevVGA-SVGA3d-glLdr.h"
46#endif
47
48#ifdef RT_OS_WINDOWS
49# include <iprt/win/windows.h>
50# ifdef VMSVGA3D_DIRECT3D
51# include <d3d9.h>
52# include <iprt/avl.h>
53# else
54# include <GL/gl.h>
55# include "vmsvga_glext/wglext.h"
56# endif
57
58#elif defined(RT_OS_DARWIN)
59# include <OpenGL/OpenGL.h>
60# include <OpenGL/gl3.h>
61# include <OpenGL/gl3ext.h>
62# define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
63# include <OpenGL/gl.h>
64# include <OpenGL/glext.h>
65# include "DevVGA-SVGA3d-cocoa.h"
66/* work around conflicting definition of GLhandleARB in VMware's glext.h */
67//#define GL_ARB_shader_objects
68// HACK
69typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer);
70typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
71typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params);
72# define GL_RGBA_S3TC 0x83A2
73# define GL_ALPHA8_EXT 0x803c
74# define GL_LUMINANCE8_EXT 0x8040
75# define GL_LUMINANCE16_EXT 0x8042
76# define GL_LUMINANCE4_ALPHA4_EXT 0x8043
77# define GL_LUMINANCE8_ALPHA8_EXT 0x8045
78# define GL_INT_2_10_10_10_REV 0x8D9F
79
80#else
81# include <X11/Xlib.h>
82# include <X11/Xatom.h>
83# include <GL/gl.h>
84# include <GL/glx.h>
85# include <GL/glext.h>
86# define VBOX_VMSVGA3D_GL_HACK_LEVEL 0x103
87#endif
88
89#include "vmsvga/svga3d_shaderdefs.h"
90#ifdef VMSVGA3D_OPENGL
91# include "vmsvga_glext/glext.h"
92# include "shaderlib/shaderlib.h"
93#endif
94
95
96/*********************************************************************************************************************************
97* Defined Constants And Macros *
98*********************************************************************************************************************************/
99#ifdef VMSVGA3D_OPENGL
100/** OpenGL: Create a dedicated context for handling surfaces in, thus
101 * avoiding orphaned surfaces after context destruction.
102 *
103 * This cures, for instance, an assertion on fedora 21 that happens in
104 * vmsvga3dSurfaceStretchBlt if the login screen and the desktop has different
105 * sizes. The context of the login screen seems to have just been destroyed
106 * earlier and I believe the driver/X/whoever is attemting to strech the old
107 * screen content onto the new sized screen.
108 *
109 * @remarks This probably comes at a slight preformance expense, as we currently
110 * switches context when setting up the surface the first time. Not sure
111 * if we really need to, but as this is an experiment, I'm playing it safe.
112 * @remarks The define has been made default, thus should no longer be used.
113 */
114# define VMSVGA3D_OGL_WITH_SHARED_CTX
115/** Fake surface ID for the shared context. */
116# define VMSVGA3D_SHARED_CTX_ID UINT32_C(0xffffeeee)
117
118/** @def VBOX_VMSVGA3D_GL_HACK_LEVEL
119 * Turns out that on Linux gl.h may often define the first 2-4 OpenGL versions
120 * worth of extensions, but missing out on a function pointer of fifteen. This
121 * causes headache for us when we use the function pointers below. This hack
122 * changes the code to call the known problematic functions directly.
123 * The value is ((x)<<16 | (y)) where x and y are taken from the GL_VERSION_x_y.
124 */
125# ifndef VBOX_VMSVGA3D_GL_HACK_LEVEL
126# define VBOX_VMSVGA3D_GL_HACK_LEVEL 0
127# endif
128
129/** Invalid OpenGL ID. */
130# define OPENGL_INVALID_ID 0
131
132# define VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState) \
133 do { (pState)->idActiveContext = OPENGL_INVALID_ID; } while (0)
134
135/** @def VMSVGA3D_SET_CURRENT_CONTEXT
136 * Makes sure the @a pContext is the active OpenGL context.
137 * @parm pState The VMSVGA3d state.
138 * @parm pContext The new context.
139 */
140# ifdef RT_OS_WINDOWS
141# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
142 do { \
143 if ((pState)->idActiveContext != (pContext)->id) \
144 { \
145 BOOL fMakeCurrentRc = wglMakeCurrent((pContext)->hdc, (pContext)->hglrc); \
146 Assert(fMakeCurrentRc == TRUE); RT_NOREF_PV(fMakeCurrentRc); \
147 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \
148 (pState)->idActiveContext = (pContext)->id; \
149 } \
150 } while (0)
151
152# elif defined(RT_OS_DARWIN)
153# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
154 do { \
155 if ((pState)->idActiveContext != (pContext)->id) \
156 { \
157 vmsvga3dCocoaViewMakeCurrentContext((pContext)->cocoaView, (pContext)->cocoaContext); \
158 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \
159 (pState)->idActiveContext = (pContext)->id; \
160 } \
161 } while (0)
162# else
163# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
164 do { \
165 if ((pState)->idActiveContext != (pContext)->id) \
166 { \
167 Bool fMakeCurrentRc = glXMakeCurrent((pState)->display, \
168 (pContext)->window, \
169 (pContext)->glxContext); \
170 Assert(fMakeCurrentRc == True); RT_NOREF_PV(fMakeCurrentRc); \
171 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \
172 (pState)->idActiveContext = (pContext)->id; \
173 } \
174 } while (0)
175# endif
176
177/** @def VMSVGA3D_CLEAR_GL_ERRORS
178 * Clears all pending OpenGL errors.
179 *
180 * If I understood this correctly, OpenGL maintains a bitmask internally and
181 * glGetError gets the next bit (clearing it) from the bitmap and translates it
182 * into a GL_XXX constant value which it then returns. A single OpenGL call can
183 * set more than one bit, and they stick around across calls, from what I
184 * understand.
185 *
186 * So in order to be able to use glGetError to check whether a function
187 * succeeded, we need to call glGetError until all error bits have been cleared.
188 * This macro does that (in all types of builds).
189 *
190 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS
191 */
192# define VMSVGA3D_CLEAR_GL_ERRORS() \
193 do { \
194 if (RT_UNLIKELY(glGetError() != GL_NO_ERROR)) /* predict no errors pending */ \
195 { \
196 uint32_t iErrorClearingLoopsLeft = 64; \
197 while (glGetError() != GL_NO_ERROR && iErrorClearingLoopsLeft > 0) \
198 iErrorClearingLoopsLeft--; \
199 } \
200 } while (0)
201
202/** @def VMSVGA3D_GET_LAST_GL_ERROR
203 * Gets the last OpenGL error, stores it in a_pContext->lastError and returns
204 * it.
205 *
206 * @returns Same as glGetError.
207 * @param a_pContext The context to store the error in.
208 *
209 * @sa VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
210 */
211# define VMSVGA3D_GET_GL_ERROR(a_pContext) ((a_pContext)->lastError = glGetError())
212
213/** @def VMSVGA3D_GL_SUCCESS
214 * Checks whether VMSVGA3D_GET_LAST_GL_ERROR() return GL_NO_ERROR.
215 *
216 * Will call glGetError() and store the result in a_pContext->lastError.
217 * Will predict GL_NO_ERROR outcome.
218 *
219 * @returns True on success, false on error.
220 * @parm a_pContext The context to store the error in.
221 *
222 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_COMPLAIN
223 */
224# define VMSVGA3D_GL_IS_SUCCESS(a_pContext) RT_LIKELY((((a_pContext)->lastError = glGetError()) == GL_NO_ERROR))
225
226/** @def VMSVGA3D_GL_COMPLAIN
227 * Complains about one or more OpenGL errors (first in a_pContext->lastError).
228 *
229 * Strict builds will trigger an assertion, while other builds will put the
230 * first few occurences in the release log.
231 *
232 * All GL errors will be cleared after invocation. Assumes lastError
233 * is an error, will not check for GL_NO_ERROR.
234 *
235 * @param a_pState The 3D state structure.
236 * @param a_pContext The context that holds the first error.
237 * @param a_LogRelDetails Argument list for LogRel or similar that describes
238 * the operation in greater detail.
239 *
240 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS
241 */
242# ifdef VBOX_STRICT
243# define VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \
244 do { \
245 AssertMsg((a_pState)->idActiveContext == (a_pContext)->id, \
246 ("idActiveContext=%#x id=%x\n", (a_pState)->idActiveContext, (a_pContext)->id)); \
247 RTAssertMsg2Weak a_LogRelDetails; \
248 GLenum iNextError; \
249 while ((iNextError = glGetError()) != GL_NO_ERROR) \
250 RTAssertMsg2Weak("next error: %#x\n", iNextError); \
251 AssertMsgFailed(("first error: %#x (idActiveContext=%#x)\n", (a_pContext)->lastError, (a_pContext)->id)); \
252 } while (0)
253# else
254# define VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \
255 do { \
256 LogRelMax(32, ("VMSVGA3d: OpenGL error %#x (idActiveContext=%#x) on line %u ", (a_pContext)->lastError, (a_pContext)->id, __LINE__)); \
257 GLenum iNextError; \
258 while ((iNextError = glGetError()) != GL_NO_ERROR) \
259 LogRelMax(32, (" - also error %#x ", iNextError)); \
260 LogRelMax(32, a_LogRelDetails); \
261 } while (0)
262# endif
263
264/** @def VMSVGA3D_GL_GET_AND_COMPLAIN
265 * Combination of VMSVGA3D_GET_GL_ERROR and VMSVGA3D_GL_COMPLAIN, assuming that
266 * there is a pending error.
267 *
268 * @param a_pState The 3D state structure.
269 * @param a_pContext The context that holds the first error.
270 * @param a_LogRelDetails Argument list for LogRel or similar that describes
271 * the operation in greater detail.
272 *
273 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
274 */
275# define VMSVGA3D_GL_GET_AND_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \
276 do { \
277 VMSVGA3D_GET_GL_ERROR(a_pContext); \
278 VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \
279 } while (0)
280
281/** @def VMSVGA3D_GL_ASSERT_SUCCESS
282 * Asserts that VMSVGA3D_GL_IS_SUCCESS is true, complains if not.
283 *
284 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
285 * logging in non-strict builds.
286 *
287 * @param a_pState The 3D state structure.
288 * @param a_pContext The context that holds the first error.
289 * @param a_LogRelDetails Argument list for LogRel or similar that describes
290 * the operation in greater detail.
291 *
292 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
293 */
294# define VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails) \
295 if (VMSVGA3D_GL_IS_SUCCESS(a_pContext)) \
296 { /* likely */ } \
297 else do { \
298 VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \
299 } while (0)
300
301/** @def VMSVGA3D_ASSERT_GL_CALL_EX
302 * Executes the specified OpenGL API call and asserts that it succeeded, variant
303 * with extra logging flexibility.
304 *
305 * ASSUMES no GL errors pending prior to invocation - caller should use
306 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
307 *
308 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
309 * logging in non-strict builds.
310 *
311 * @param a_GlCall Expression making an OpenGL call.
312 * @param a_pState The 3D state structure.
313 * @param a_pContext The context that holds the first error.
314 * @param a_LogRelDetails Argument list for LogRel or similar that describes
315 * the operation in greater detail.
316 *
317 * @sa VMSVGA3D_ASSERT_GL_CALL, VMSVGA3D_GL_ASSERT_SUCCESS,
318 * VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
319 */
320# define VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, a_LogRelDetails) \
321 do { \
322 (a_GlCall); \
323 VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails); \
324 } while (0)
325
326/** @def VMSVGA3D_ASSERT_GL_CALL
327 * Executes the specified OpenGL API call and asserts that it succeeded.
328 *
329 * ASSUMES no GL errors pending prior to invocation - caller should use
330 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
331 *
332 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
333 * logging in non-strict builds.
334 *
335 * @param a_GlCall Expression making an OpenGL call.
336 * @param a_pState The 3D state structure.
337 * @param a_pContext The context that holds the first error.
338 *
339 * @sa VMSVGA3D_ASSERT_GL_CALL_EX, VMSVGA3D_GL_ASSERT_SUCCESS,
340 * VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
341 */
342# define VMSVGA3D_ASSERT_GL_CALL(a_GlCall, a_pState, a_pContext) \
343 VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, ("%s\n", #a_GlCall))
344
345
346/** @def VMSVGA3D_CHECK_LAST_ERROR
347 * Checks that the last OpenGL error code indicates success.
348 *
349 * Will assert and return VERR_INTERNAL_ERROR in strict builds, in other
350 * builds it will do nothing and is a NOOP.
351 *
352 * @parm pState The VMSVGA3d state.
353 * @parm pContext The context.
354 *
355 * @todo Replace with proper error handling, it's crazy to return
356 * VERR_INTERNAL_ERROR in strict builds and just barge on ahead in
357 * release builds.
358 */
359/** @todo Rename to VMSVGA3D_CHECK_LAST_ERROR_RETURN */
360# ifdef VBOX_STRICT
361# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { \
362 Assert((pState)->idActiveContext == (pContext)->id); \
363 (pContext)->lastError = glGetError(); \
364 AssertMsgReturn((pContext)->lastError == GL_NO_ERROR, \
365 ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError), \
366 VERR_INTERNAL_ERROR); \
367 } while (0)
368# else
369# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { } while (0)
370# endif
371
372/** @def VMSVGA3D_CHECK_LAST_ERROR_WARN
373 * Checks that the last OpenGL error code indicates success.
374 *
375 * Will assert in strict builds, otherwise it's a NOOP.
376 *
377 * @parm pState The VMSVGA3d state.
378 * @parm pContext The new context.
379 */
380# ifdef VBOX_STRICT
381# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { \
382 Assert((pState)->idActiveContext == (pContext)->id); \
383 (pContext)->lastError = glGetError(); \
384 AssertMsg((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError)); \
385 } while (0)
386# else
387# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { } while (0)
388# endif
389
390#endif /* VMSVGA3D_OPENGL */
391
392#ifdef VMSVGA3D_DIRECT3D
393/* Enable to use Wine to convert D3D to opengl */
394//#define VBOX_VMSVGA3D_WITH_WINE_OPENGL
395#endif
396
397
398/*********************************************************************************************************************************
399* Structures and Typedefs *
400*********************************************************************************************************************************/
401/**
402 * Mipmap level.
403 */
404typedef struct VMSVGA3DMIPMAPLEVEL
405{
406 /** The mipmap size: width, height and depth. */
407 SVGA3dSize mipmapSize;
408 /** Width in blocks: (width + cxBlock - 1) / cxBlock. SSM: not saved, recalculated on load. */
409 uint32_t cBlocksX;
410 /** Height in blocks: (height + cyBlock - 1) / cyBlock. SSM: not saved, recalculated on load. */
411 uint32_t cBlocksY;
412 /** Number of blocks: cBlocksX * cBlocksY * mipmapSize.depth. SSM: not saved, recalculated on load. */
413 uint32_t cBlocks;
414 /** The scanline/pitch size in bytes: at least cBlocksX * cbBlock. */
415 uint32_t cbSurfacePitch;
416 /** The size (in bytes) of the mipmap plane: cbSurfacePitch * cBlocksY */
417 uint32_t cbSurfacePlane;
418 /** The size (in bytes) of the mipmap data when using the format the surface was
419 * defined with: cbSurfacePlane * mipmapSize.z */
420 uint32_t cbSurface;
421 /** Pointer to the mipmap bytes (cbSurface). Often NULL. If the surface has
422 * been realized in hardware, this may be outdated. */
423 void *pSurfaceData;
424 /** Set if pvSurfaceData contains data not realized in hardware or pushed to the
425 * hardware surface yet. */
426 bool fDirty;
427} VMSVGA3DMIPMAPLEVEL;
428/** Pointer to a mipmap level. */
429typedef VMSVGA3DMIPMAPLEVEL *PVMSVGA3DMIPMAPLEVEL;
430
431
432#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
433/**
434 * SSM descriptor table for the VMSVGA3DMIPMAPLEVEL structure.
435 */
436static SSMFIELD const g_aVMSVGA3DMIPMAPLEVELFields[] =
437{
438 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, mipmapSize),
439 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurface),
440 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurfacePitch),
441 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DMIPMAPLEVEL, pSurfaceData),
442 SSMFIELD_ENTRY_IGNORE( VMSVGA3DMIPMAPLEVEL, fDirty),
443 SSMFIELD_ENTRY_TERM()
444};
445#endif
446
447typedef struct VMSVGATRANSFORMSTATE
448{
449 bool fValid;
450 float matrix[16];
451} VMSVGATRANSFORMSTATE;
452typedef VMSVGATRANSFORMSTATE *PVMSVGATRANSFORMSTATE;
453
454typedef struct VMSVGAMATERIALSTATE
455{
456 bool fValid;
457 SVGA3dMaterial material;
458} VMSVGAMATERIALSTATE;
459typedef VMSVGAMATERIALSTATE *PVMSVGAMATERIALSTATE;
460
461typedef struct VMSVGACLIPPLANESTATE
462{
463 bool fValid;
464 float plane[4];
465} VMSVGACLIPPLANESTATE;
466typedef VMSVGACLIPPLANESTATE *PVMSVGACLIPPLANESTATE;
467
468typedef struct VMSVGALIGHTSTATE
469{
470 bool fEnabled;
471 bool fValidData;
472 SVGA3dLightData data;
473} VMSVGALIGHTSTATE;
474typedef VMSVGALIGHTSTATE *PVMSVGALIGHTSTATE;
475
476typedef struct VMSVGASHADERCONST
477{
478 bool fValid;
479 SVGA3dShaderConstType ctype;
480 uint32_t value[4];
481} VMSVGASHADERCONST;
482typedef VMSVGASHADERCONST *PVMSVGASHADERCONST;
483
484#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
485/**
486 * SSM descriptor table for the VMSVGASHADERCONST structure.
487 */
488static SSMFIELD const g_aVMSVGASHADERCONSTFields[] =
489{
490 SSMFIELD_ENTRY( VMSVGASHADERCONST, fValid),
491 SSMFIELD_ENTRY( VMSVGASHADERCONST, ctype),
492 SSMFIELD_ENTRY( VMSVGASHADERCONST, value),
493 SSMFIELD_ENTRY_TERM()
494};
495#endif
496
497#ifdef VMSVGA3D_DIRECT3D
498
499/* What kind of Direct3D resource has been created for the VMSVGA3D surface. */
500typedef enum VMSVGA3DD3DRESTYPE
501{
502 VMSVGA3D_D3DRESTYPE_NONE = 0,
503 VMSVGA3D_D3DRESTYPE_SURFACE = 1,
504 VMSVGA3D_D3DRESTYPE_TEXTURE = 2,
505 VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE = 3,
506 VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE = 4,
507 VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER = 5,
508 VMSVGA3D_D3DRESTYPE_INDEX_BUFFER = 6
509} VMSVGA3DD3DRESTYPE;
510
511/**
512 *
513 */
514typedef struct
515{
516 /** Key is context id. */
517 AVLU32NODECORE Core;
518 union
519 {
520 IDirect3DTexture9 *pTexture;
521 IDirect3DCubeTexture9 *pCubeTexture;
522 IDirect3DVolumeTexture9 *pVolumeTexture;
523 } u;
524} VMSVGA3DSHAREDSURFACE;
525typedef VMSVGA3DSHAREDSURFACE *PVMSVGA3DSHAREDSURFACE;
526#endif /* VMSVGA3D_DIRECT3D */
527
528#ifdef VMSVGA3D_OPENGL
529/* What kind of OpenGL resource has been created for the VMSVGA3D surface. */
530typedef enum VMSVGA3DOGLRESTYPE
531{
532 VMSVGA3D_OGLRESTYPE_NONE = 0,
533 VMSVGA3D_OGLRESTYPE_BUFFER = 1,
534 VMSVGA3D_OGLRESTYPE_TEXTURE = 2,
535 VMSVGA3D_OGLRESTYPE_RENDERBUFFER = 3
536} VMSVGA3DOGLRESTYPE;
537#endif
538
539/**
540 * VMSVGA3d surface.
541 */
542typedef struct VMSVGA3DSURFACE
543{
544 uint32_t id;
545#ifdef VMSVGA3D_OPENGL
546 uint32_t idWeakContextAssociation;
547#else
548 uint32_t idAssociatedContext;
549#endif
550 uint32_t surfaceFlags;
551 SVGA3dSurfaceFormat format;
552#ifdef VMSVGA3D_OPENGL
553 GLint internalFormatGL;
554 GLint formatGL;
555 GLint typeGL;
556 VMSVGA3DOGLRESTYPE enmOGLResType; /* Which resource was created for the surface. */
557 union
558 {
559 GLuint texture;
560 GLuint buffer;
561 GLuint renderbuffer;
562 } oglId;
563 GLenum targetGL; /* GL_TEXTURE_* */
564 GLenum bindingGL; /* GL_TEXTURE_BINDING_* */
565 /* Emulated formats */
566 bool fEmulated; /* Whether the texture format is emulated. */
567 GLuint idEmulated; /* GL name of the intermediate texture. */
568#endif
569 SVGA3dSurfaceFace faces[SVGA3D_MAX_SURFACE_FACES];
570 uint32_t cFaces;
571 uint32_t cMipmapLevels;
572 PVMSVGA3DMIPMAPLEVEL paMipmapLevels;
573 uint32_t multiSampleCount;
574 SVGA3dTextureFilter autogenFilter;
575#ifdef VMSVGA3D_DIRECT3D
576 D3DFORMAT formatD3D;
577 DWORD fUsageD3D;
578 D3DMULTISAMPLE_TYPE multiSampleTypeD3D;
579#endif
580
581 uint32_t cbBlock; /* block/pixel size in bytes */
582 /* Dimensions of the surface block, usually 1x1 except for compressed formats. */
583 uint32_t cxBlock; /* Block width in pixels. SSM: not saved, recalculated on load. */
584 uint32_t cyBlock; /* Block height in pixels. SSM: not saved, recalculated on load. */
585#ifdef VMSVGA3D_OPENGL
586 uint32_t cbBlockGL; /* Block size of the OpenGL texture, same as cbBlock for not-emulated formats. */
587#endif
588
589 /* Dirty state; surface was manually updated. */
590 bool fDirty;
591
592#ifdef VMSVGA3D_DIRECT3D
593 /* Handle for shared objects (currently only textures & render targets). */
594 HANDLE hSharedObject;
595 /** Event query inserted after each GPU operation that updates or uses this surface. */
596 IDirect3DQuery9 *pQuery;
597 /** The context id where the query has been created. */
598 uint32_t idQueryContext;
599 /** The type of actually created D3D resource. */
600 VMSVGA3DD3DRESTYPE enmD3DResType;
601 union
602 {
603 IDirect3DSurface9 *pSurface;
604 IDirect3DTexture9 *pTexture;
605 IDirect3DCubeTexture9 *pCubeTexture;
606 IDirect3DVolumeTexture9 *pVolumeTexture;
607 IDirect3DVertexBuffer9 *pVertexBuffer;
608 IDirect3DIndexBuffer9 *pIndexBuffer;
609 } u;
610 union
611 {
612 IDirect3DTexture9 *pTexture;
613 IDirect3DCubeTexture9 *pCubeTexture;
614 IDirect3DVolumeTexture9 *pVolumeTexture;
615 } bounce;
616 /** AVL tree containing VMSVGA3DSHAREDSURFACE structures. */
617 AVLU32TREE pSharedObjectTree;
618 bool fStencilAsTexture;
619 D3DFORMAT d3dfmtRequested;
620 union
621 {
622 IDirect3DTexture9 *pTexture;
623 IDirect3DCubeTexture9 *pCubeTexture;
624 IDirect3DVolumeTexture9 *pVolumeTexture;
625 } emulated;
626#endif
627} VMSVGA3DSURFACE;
628/** Pointer to a 3d surface. */
629typedef VMSVGA3DSURFACE *PVMSVGA3DSURFACE;
630
631#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
632/**
633 * SSM descriptor table for the VMSVGA3DSURFACE structure.
634 */
635static SSMFIELD const g_aVMSVGA3DSURFACEFields[] =
636{
637 SSMFIELD_ENTRY( VMSVGA3DSURFACE, id),
638# ifdef VMSVGA3D_OPENGL
639 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idWeakContextAssociation),
640# else
641 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext),
642# endif
643 SSMFIELD_ENTRY( VMSVGA3DSURFACE, surfaceFlags),
644 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format),
645# ifdef VMSVGA3D_OPENGL
646 SSMFIELD_ENTRY( VMSVGA3DSURFACE, internalFormatGL),
647 SSMFIELD_ENTRY( VMSVGA3DSURFACE, formatGL),
648 SSMFIELD_ENTRY( VMSVGA3DSURFACE, typeGL),
649 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, id),
650# endif
651 SSMFIELD_ENTRY( VMSVGA3DSURFACE, faces),
652 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cFaces),
653 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, paMipmapLevels),
654 SSMFIELD_ENTRY( VMSVGA3DSURFACE, multiSampleCount),
655 SSMFIELD_ENTRY( VMSVGA3DSURFACE, autogenFilter),
656# ifdef VMSVGA3D_DIRECT3D
657 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format), /** @todo format duplicated. */
658 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, formatD3D),
659 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fUsageD3D),
660 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, multiSampleTypeD3D),
661# endif
662 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cbBlock),
663 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fDirty),
664# ifdef VMSVGA3D_DIRECT3D
665 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, hSharedObject),
666 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, pQuery),
667 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, u.pSurface),
668 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, bounce.pTexture),
669 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, pSharedObjectTree),
670 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fStencilAsTexture),
671# endif
672 SSMFIELD_ENTRY_TERM()
673};
674#endif
675
676/** Mask we frequently apply to VMSVGA3DSURFACE::flags for decing what kind
677 * of surface we're dealing. */
678#define VMSVGA3D_SURFACE_HINT_SWITCH_MASK \
679 ( SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER \
680 | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET \
681 | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP )
682
683/** @def VMSVGA3DSURFACE_HAS_HW_SURFACE
684 * Checks whether the surface has a host hardware/library surface.
685 * @returns true/false
686 * @param a_pSurface The VMSVGA3d surface.
687 */
688#ifdef VMSVGA3D_DIRECT3D
689# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->u.pSurface != NULL)
690#else
691# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->oglId.texture != OPENGL_INVALID_ID)
692#endif
693
694/** @def VMSVGA3DSURFACE_NEEDS_DATA
695 * Checks whether SurfaceDMA transfers must always update pSurfaceData,
696 * even if the surface has a host hardware resource.
697 * @returns true/false
698 * @param a_pSurface The VMSVGA3d surface.
699 */
700#ifdef VMSVGA3D_DIRECT3D
701# define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) \
702 ( (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER \
703 || (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_INDEX_BUFFER)
704#else
705# define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) \
706 ((a_pSurface)->enmOGLResType == VMSVGA3D_OGLRESTYPE_BUFFER)
707#endif
708
709
710typedef struct VMSVGA3DSHADER
711{
712 uint32_t id;
713 uint32_t cid;
714 SVGA3dShaderType type;
715 uint32_t cbData;
716 void *pShaderProgram;
717 union
718 {
719#ifdef VMSVGA3D_DIRECT3D
720 IDirect3DVertexShader9 *pVertexShader;
721 IDirect3DPixelShader9 *pPixelShader;
722#else
723 void *pVertexShader;
724 void *pPixelShader;
725#endif
726 void *pv;
727 } u;
728} VMSVGA3DSHADER;
729typedef VMSVGA3DSHADER *PVMSVGA3DSHADER;
730
731#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
732/**
733 * SSM descriptor table for the VMSVGA3DSHADER structure.
734 */
735static SSMFIELD const g_aVMSVGA3DSHADERFields[] =
736{
737 SSMFIELD_ENTRY( VMSVGA3DSHADER, id),
738 SSMFIELD_ENTRY( VMSVGA3DSHADER, cid),
739 SSMFIELD_ENTRY( VMSVGA3DSHADER, type),
740 SSMFIELD_ENTRY( VMSVGA3DSHADER, cbData),
741 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, pShaderProgram),
742 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, u.pv),
743 SSMFIELD_ENTRY_TERM()
744};
745#endif
746
747/** @name VMSVGA3D_UPDATE_XXX - ...
748 * @{ */
749#define VMSVGA3D_UPDATE_SCISSORRECT RT_BIT_32(0)
750#define VMSVGA3D_UPDATE_ZRANGE RT_BIT_32(1)
751#define VMSVGA3D_UPDATE_VIEWPORT RT_BIT_32(2)
752#define VMSVGA3D_UPDATE_VERTEXSHADER RT_BIT_32(3)
753#define VMSVGA3D_UPDATE_PIXELSHADER RT_BIT_32(4)
754#define VMSVGA3D_UPDATE_TRANSFORM RT_BIT_32(5)
755#define VMSVGA3D_UPDATE_MATERIAL RT_BIT_32(6)
756/** @} */
757
758/* Query states. Mostly used for saved state. */
759typedef enum VMSVGA3DQUERYSTATE
760{
761 VMSVGA3DQUERYSTATE_NULL = 0, /* Not created. */
762 VMSVGA3DQUERYSTATE_SIGNALED = 1, /* Result obtained. The guest may or may not read the result yet. */
763 VMSVGA3DQUERYSTATE_BUILDING = 2, /* In process of collecting data. */
764 VMSVGA3DQUERYSTATE_ISSUED = 3, /* Data collected, but result is not yet obtained. */
765 VMSVGA3DQUERYSTATE_32BIT = 0x7fffffff
766} VMSVGA3DQUERYSTATE;
767AssertCompileSize(VMSVGA3DQUERYSTATE, sizeof(uint32_t));
768
769typedef struct VMSVGA3DQUERY
770{
771#ifdef VMSVGA3D_DIRECT3D
772 IDirect3DQuery9 *pQuery;
773#else /* VMSVGA3D_OPENGL */
774 GLuint idQuery;
775#endif
776 VMSVGA3DQUERYSTATE enmQueryState; /* VMSVGA3DQUERYSTATE_*. State is implicitly _NULL if pQuery is NULL. */
777 uint32_t u32QueryResult; /* Generic result. Enough for all VGPU9 queries. */
778} VMSVGA3DQUERY;
779
780#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
781/**
782 * SSM descriptor table for the VMSVGA3DQUERY structure.
783 */
784static SSMFIELD const g_aVMSVGA3DQUERYFields[] =
785{
786#ifdef VMSVGA3D_DIRECT3D
787 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DQUERY, pQuery),
788#else /* VMSVGA3D_OPENGL */
789 SSMFIELD_ENTRY_IGNORE( VMSVGA3DQUERY, idQuery),
790#endif
791 SSMFIELD_ENTRY( VMSVGA3DQUERY, enmQueryState),
792 SSMFIELD_ENTRY( VMSVGA3DQUERY, u32QueryResult),
793 SSMFIELD_ENTRY_TERM()
794};
795#endif
796
797#ifdef VMSVGA3D_DIRECT3D
798#define VMSVGA3DQUERY_EXISTS(p) ((p)->pQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)
799#else
800#define VMSVGA3DQUERY_EXISTS(p) ((p)->idQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)
801#endif
802
803/**
804 * VMSVGA3d context.
805 */
806typedef struct VMSVGA3DCONTEXT
807{
808 uint32_t id;
809#ifdef RT_OS_WINDOWS
810# ifdef VMSVGA3D_DIRECT3D
811# ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
812 IDirect3DDevice9 *pDevice;
813# else
814 IDirect3DDevice9Ex *pDevice;
815# endif
816# else
817 /* Device context of the context window. */
818 HDC hdc;
819 /* OpenGL rendering context handle. */
820 HGLRC hglrc;
821# endif
822 /* Device context window handle. */
823 HWND hwnd;
824#elif defined(RT_OS_DARWIN)
825 /* OpenGL rendering context */
826 NativeNSOpenGLContextRef cocoaContext;
827 NativeNSViewRef cocoaView;
828 bool fOtherProfile;
829#else
830 /** XGL rendering context handle */
831 GLXContext glxContext;
832 /** Device context window handle */
833 Window window;
834#endif
835
836#ifdef VMSVGA3D_OPENGL
837 /* Framebuffer object associated with this context. */
838 GLuint idFramebuffer;
839 /* Read and draw framebuffer objects for various operations. */
840 GLuint idReadFramebuffer;
841 GLuint idDrawFramebuffer;
842 /* Last GL error recorded. */
843 GLenum lastError;
844 void *pShaderContext;
845#endif
846
847 /* Current selected texture surfaces (if any) */
848 uint32_t aSidActiveTextures[SVGA3D_MAX_SAMPLERS];
849 /* Per context pixel and vertex shaders. */
850 uint32_t cPixelShaders;
851 PVMSVGA3DSHADER paPixelShader;
852 uint32_t cVertexShaders;
853 PVMSVGA3DSHADER paVertexShader;
854 /* Keep track of the internal state to be able to recreate the context properly (save/restore, window resize). */
855 struct
856 {
857 /** VMSVGA3D_UPDATE_XXX */
858 uint32_t u32UpdateFlags;
859
860 SVGA3dRenderState aRenderState[SVGA3D_RS_MAX];
861 /* aTextureStates contains both TextureStageStates and SamplerStates, therefore [SVGA3D_MAX_SAMPLERS]. */
862 SVGA3dTextureState aTextureStates[SVGA3D_MAX_SAMPLERS][SVGA3D_TS_MAX];
863 VMSVGATRANSFORMSTATE aTransformState[SVGA3D_TRANSFORM_MAX];
864 VMSVGAMATERIALSTATE aMaterial[SVGA3D_FACE_MAX];
865 VMSVGACLIPPLANESTATE aClipPlane[SVGA3D_CLIPPLANE_MAX];
866 VMSVGALIGHTSTATE aLightData[SVGA3D_MAX_LIGHTS];
867
868 uint32_t aRenderTargets[SVGA3D_RT_MAX];
869 SVGA3dRect RectScissor;
870 SVGA3dRect RectViewPort;
871 SVGA3dZRange zRange;
872 uint32_t shidPixel;
873 uint32_t shidVertex;
874
875 uint32_t cPixelShaderConst;
876 PVMSVGASHADERCONST paPixelShaderConst;
877 uint32_t cVertexShaderConst;
878 PVMSVGASHADERCONST paVertexShaderConst;
879 } state;
880
881 /* Occlusion query. */
882 VMSVGA3DQUERY occlusion;
883
884#ifdef VMSVGA3D_DIRECT3D
885 /* State which is currently applied to the D3D device. It is recreated as needed and not saved.
886 * The purpose is to remember the currently applied state and do not re-apply it if it has not changed.
887 * Unnecessary state changes are very bad for performance.
888 */
889 struct
890 {
891 /* Vertex declaration. */
892 IDirect3DVertexDeclaration9 *pVertexDecl;
893 uint32_t cVertexElements;
894 D3DVERTEXELEMENT9 aVertexElements[SVGA3D_MAX_VERTEX_ARRAYS + 1];
895 } d3dState;
896#endif
897} VMSVGA3DCONTEXT;
898/** Pointer to a VMSVGA3d context. */
899typedef VMSVGA3DCONTEXT *PVMSVGA3DCONTEXT;
900
901#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
902/**
903 * SSM descriptor table for the VMSVGA3DCONTEXT structure.
904 */
905static SSMFIELD const g_aVMSVGA3DCONTEXTFields[] =
906{
907 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, id),
908
909# ifdef RT_OS_WINDOWS
910# ifdef VMSVGA3D_DIRECT3D
911 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pDevice),
912# else
913 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hdc),
914 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hglrc),
915# endif
916 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hwnd),
917# elif defined(RT_OS_DARWIN)
918 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, cocoaContext),
919 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, cocoaView),
920 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, fOtherProfile),
921# else
922 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, glxContext),
923 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, window),
924# endif
925
926#ifdef VMSVGA3D_OPENGL
927 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idFramebuffer),
928 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idReadFramebuffer),
929 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idDrawFramebuffer),
930 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, lastError),
931 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pShaderContext),
932#endif
933
934 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, aSidActiveTextures),
935 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cPixelShaders),
936 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paPixelShader),
937 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cVertexShaders),
938 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paVertexShader),
939 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.u32UpdateFlags),
940
941 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderState),
942 SSMFIELD_ENTRY_OLD( state.aTextureStates,
943 sizeof(SVGA3dTextureState) * /*SVGA3D_MAX_TEXTURE_STAGE=*/ 8 * /*SVGA3D_TS_MAX=*/ 30),
944 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTransformState),
945 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aMaterial),
946 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aClipPlane),
947 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aLightData),
948
949 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderTargets),
950 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectScissor),
951 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectViewPort),
952 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.zRange),
953 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidPixel),
954 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidVertex),
955 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cPixelShaderConst),
956 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paPixelShaderConst),
957 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cVertexShaderConst),
958 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paVertexShaderConst),
959 SSMFIELD_ENTRY_TERM()
960};
961#endif /* VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS */
962
963
964#ifdef VMSVGA3D_OPENGL
965typedef struct VMSVGA3DFORMATCONVERTER *PVMSVGA3DFORMATCONVERTER;
966#endif
967
968/**
969 * VMSVGA3d state data.
970 *
971 * Allocated on the heap and pointed to by VMSVGAState::p3dState.
972 */
973typedef struct VMSVGA3DSTATE
974{
975 /** The size of papContexts. */
976 uint32_t cContexts;
977 /** The size of papSurfaces. */
978 uint32_t cSurfaces;
979 /** Contexts indexed by ID. Grown as needed. */
980 PVMSVGA3DCONTEXT *papContexts;
981 /** Surfaces indexed by ID. Grown as needed. */
982 PVMSVGA3DSURFACE *papSurfaces;
983
984#ifdef RT_OS_WINDOWS
985# ifdef VMSVGA3D_DIRECT3D
986# ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
987 IDirect3D9 *pD3D9;
988# else
989 IDirect3D9Ex *pD3D9;
990# endif
991 D3DCAPS9 caps;
992 bool fSupportedSurfaceINTZ;
993 bool fSupportedSurfaceNULL;
994 bool fSupportedFormatUYVY : 1;
995 bool fSupportedFormatYUY2 : 1;
996 bool fSupportedFormatA8B8G8R8 : 1;
997# endif
998 /** Window Thread. */
999 R3PTRTYPE(RTTHREAD) pWindowThread;
1000 DWORD idWindowThread;
1001 HMODULE hInstance;
1002 /** Window request semaphore. */
1003 RTSEMEVENT WndRequestSem;
1004#elif defined(RT_OS_DARWIN)
1005#else
1006 /* The X display */
1007 Display *display;
1008 R3PTRTYPE(RTTHREAD) pWindowThread;
1009 bool bTerminate;
1010#endif
1011
1012#ifdef VMSVGA3D_OPENGL
1013 float rsGLVersion;
1014 /* Current active context. */
1015 uint32_t idActiveContext;
1016
1017 struct
1018 {
1019 PFNGLISRENDERBUFFERPROC glIsRenderbuffer;
1020 PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
1021 PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
1022 PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
1023 PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
1024 PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv;
1025 PFNGLISFRAMEBUFFERPROC glIsFramebuffer;
1026 PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
1027 PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
1028 PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
1029 PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
1030 PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;
1031 PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
1032 PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;
1033 PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
1034 PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv;
1035 PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
1036 PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
1037 PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;
1038 PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer;
1039 PFNGLPOINTPARAMETERFPROC glPointParameterf;
1040#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x102
1041 PFNGLBLENDCOLORPROC glBlendColor;
1042 PFNGLBLENDEQUATIONPROC glBlendEquation;
1043#endif
1044 PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate;
1045 PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
1046 PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate;
1047 PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate;
1048 PFNGLBINDBUFFERPROC glBindBuffer;
1049 PFNGLDELETEBUFFERSPROC glDeleteBuffers;
1050 PFNGLGENBUFFERSPROC glGenBuffers;
1051 PFNGLBUFFERDATAPROC glBufferData;
1052 PFNGLMAPBUFFERPROC glMapBuffer;
1053 PFNGLUNMAPBUFFERPROC glUnmapBuffer;
1054 PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
1055 PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
1056 PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
1057 PFNGLFOGCOORDPOINTERPROC glFogCoordPointer;
1058 PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex;
1059 PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex;
1060 PFNGLACTIVETEXTUREPROC glActiveTexture;
1061#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x103
1062 PFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture;
1063#endif
1064 PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
1065 PFNGLPROVOKINGVERTEXPROC glProvokingVertex;
1066 PFNGLGENQUERIESPROC glGenQueries;
1067 PFNGLDELETEQUERIESPROC glDeleteQueries;
1068 PFNGLBEGINQUERYPROC glBeginQuery;
1069 PFNGLENDQUERYPROC glEndQuery;
1070 PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv;
1071 PFNGLTEXIMAGE3DPROC glTexImage3D;
1072 PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D;
1073 PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor;
1074 PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced;
1075 PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced;
1076 PFNGLGETCOMPRESSEDTEXIMAGEPROC glGetCompressedTexImage;
1077 PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D;
1078 PFNGLCOMPRESSEDTEXIMAGE3DPROC glCompressedTexImage3D;
1079 PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D;
1080 PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D;
1081 PFNGLDRAWBUFFERSPROC glDrawBuffers;
1082 PFNGLCREATESHADERPROC glCreateShader;
1083 PFNGLSHADERSOURCEPROC glShaderSource;
1084 PFNGLCOMPILESHADERPROC glCompileShader;
1085 PFNGLGETSHADERIVPROC glGetShaderiv;
1086 PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
1087 PFNGLCREATEPROGRAMPROC glCreateProgram;
1088 PFNGLATTACHSHADERPROC glAttachShader;
1089 PFNGLLINKPROGRAMPROC glLinkProgram;
1090 PFNGLGETPROGRAMIVPROC glGetProgramiv;
1091 PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
1092 PFNGLUSEPROGRAMPROC glUseProgram;
1093 PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
1094 PFNGLUNIFORM1IPROC glUniform1i;
1095 PFNGLUNIFORM4FVPROC glUniform4fv;
1096 PFNGLDETACHSHADERPROC glDetachShader;
1097 PFNGLDELETESHADERPROC glDeleteShader;
1098 PFNGLDELETEPROGRAMPROC glDeleteProgram;
1099 PFNGLVERTEXATTRIB4FVPROC glVertexAttrib4fv;
1100 PFNGLVERTEXATTRIB4UBVPROC glVertexAttrib4ubv;
1101 PFNGLVERTEXATTRIB4NUBVPROC glVertexAttrib4Nubv;
1102 PFNGLVERTEXATTRIB4SVPROC glVertexAttrib4sv;
1103 PFNGLVERTEXATTRIB4NSVPROC glVertexAttrib4Nsv;
1104 PFNGLVERTEXATTRIB4NUSVPROC glVertexAttrib4Nusv;
1105 } ext;
1106
1107 struct
1108 {
1109 bool fS3TCSupported : 1;
1110 bool fTextureFilterAnisotropicSupported : 1;
1111 GLint maxActiveLights;
1112 GLint maxTextures;
1113 GLint maxClipDistances;
1114 GLint maxColorAttachments;
1115 GLint maxRectangleTextureSize;
1116 GLint maxTextureAnisotropy;
1117 GLint maxVertexShaderInstructions;
1118 GLint maxFragmentShaderInstructions;
1119 GLint maxVertexShaderTemps;
1120 GLint maxFragmentShaderTemps;
1121 GLfloat flPointSize[2];
1122 SVGA3dPixelShaderVersion fragmentShaderVersion;
1123 SVGA3dVertexShaderVersion vertexShaderVersion;
1124 } caps;
1125
1126 /** The GL_EXTENSIONS value (space padded) for the default OpenGL profile.
1127 * Free with RTStrFree. */
1128 R3PTRTYPE(char *) pszExtensions;
1129
1130 /** The GL_EXTENSIONS value (space padded) for the other OpenGL profile.
1131 * Free with RTStrFree.
1132 *
1133 * This is used to detect shader model version since some implementations
1134 * (darwin) hides extensions that have made it into core and probably a
1135 * bunch of others when using a OpenGL core profile instead of a legacy one */
1136 R3PTRTYPE(char *) pszOtherExtensions;
1137 /** The version of the other GL profile. */
1138 float rsOtherGLVersion;
1139
1140 /** Shader talk back interface. */
1141 VBOXVMSVGASHADERIF ShaderIf;
1142
1143# ifdef VMSVGA3D_OPENGL
1144 /** The shared context. */
1145 VMSVGA3DCONTEXT SharedCtx;
1146
1147 /** Conversion of emulated formats. Resources are created on the SharedCtx. */
1148 PVMSVGA3DFORMATCONVERTER pConv;
1149# endif
1150#endif /* VMSVGA3D_OPENGL */
1151} VMSVGA3DSTATE;
1152
1153#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
1154/**
1155 * SSM descriptor table for the VMSVGA3DSTATE structure.
1156 *
1157 * @remarks This isn't a complete structure markup, only fields with state.
1158 */
1159static SSMFIELD const g_aVMSVGA3DSTATEFields[] =
1160{
1161# ifdef VMSVGA3D_OPENGL
1162 SSMFIELD_ENTRY( VMSVGA3DSTATE, rsGLVersion), /** @todo Why are we saving the GL version?? */
1163# endif
1164 SSMFIELD_ENTRY( VMSVGA3DSTATE, cContexts),
1165 SSMFIELD_ENTRY( VMSVGA3DSTATE, cSurfaces),
1166 SSMFIELD_ENTRY_TERM()
1167};
1168#endif /* VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS */
1169
1170/**
1171 * VMSVGA3d screen data.
1172 *
1173 * Allocated on the heap and pointed to by VMSVGASCREENOBJECT::pHwScreen.
1174 */
1175typedef struct VMSVGAHWSCREEN
1176{
1177 uint32_t u32Reserved0;
1178#if defined(RT_OS_LINUX)
1179 VisualID visualid;
1180 Pixmap pixmap;
1181 GLXPixmap glxpixmap;
1182 GLXContext glxctx;
1183 bool fYInverted;
1184 bool fMipmap;
1185#endif
1186} VMSVGAHWSCREEN;
1187
1188int vmsvga3dBackDefineScreen(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen);
1189int vmsvga3dBackDestroyScreen(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen);
1190
1191int vmsvga3dBackSurfaceBlitToScreen(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen,
1192 SVGASignedRect destRect, SVGA3dSurfaceImageId srcImage,
1193 SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *paRects);
1194
1195#ifdef VMSVGA3D_DIRECT3D
1196D3DFORMAT vmsvga3dSurfaceFormat2D3D(SVGA3dSurfaceFormat format);
1197D3DMULTISAMPLE_TYPE vmsvga3dMultipeSampleCount2D3D(uint32_t multisampleCount);
1198DECLCALLBACK(int) vmsvga3dSharedSurfaceDestroyTree(PAVLU32NODECORE pNode, void *pvParam);
1199int vmsvga3dSurfaceFlush(PVMSVGA3DSURFACE pSurface);
1200#endif /* VMSVGA3D_DIRECT3D */
1201
1202
1203#ifdef VMSVGA3D_OPENGL
1204/** Save and setup everything. */
1205# define VMSVGA3D_PARANOID_TEXTURE_PACKING
1206
1207/** @name VMSVGAPACKPARAMS_* - which packing parameters were set.
1208 * @{ */
1209# define VMSVGAPACKPARAMS_ALIGNMENT RT_BIT_32(0)
1210# define VMSVGAPACKPARAMS_ROW_LENGTH RT_BIT_32(1)
1211# define VMSVGAPACKPARAMS_IMAGE_HEIGHT RT_BIT_32(2)
1212# define VMSVGAPACKPARAMS_SWAP_BYTES RT_BIT_32(3)
1213# define VMSVGAPACKPARAMS_LSB_FIRST RT_BIT_32(4)
1214# define VMSVGAPACKPARAMS_SKIP_ROWS RT_BIT_32(5)
1215# define VMSVGAPACKPARAMS_SKIP_PIXELS RT_BIT_32(6)
1216# define VMSVGAPACKPARAMS_SKIP_IMAGES RT_BIT_32(7)
1217/** @} */
1218
1219/**
1220 * Saved texture packing parameters (shared by both pack and unpack).
1221 */
1222typedef struct VMSVGAPACKPARAMS
1223{
1224 uint32_t fChanged;
1225 GLint iAlignment;
1226 GLint cxRow;
1227 GLint cyImage;
1228# ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
1229 GLboolean fSwapBytes;
1230 GLboolean fLsbFirst;
1231 GLint cSkipRows;
1232 GLint cSkipPixels;
1233 GLint cSkipImages;
1234# endif
1235} VMSVGAPACKPARAMS;
1236/** Pointer to saved texture packing parameters. */
1237typedef VMSVGAPACKPARAMS *PVMSVGAPACKPARAMS;
1238/** Pointer to const saved texture packing parameters. */
1239typedef VMSVGAPACKPARAMS const *PCVMSVGAPACKPARAMS;
1240
1241void vmsvga3dOglSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1242 PVMSVGAPACKPARAMS pSave);
1243void vmsvga3dOglRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1244 PCVMSVGAPACKPARAMS pSave);
1245void vmsvga3dOglSetUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, GLint cxRow, GLint cyImage,
1246 PVMSVGAPACKPARAMS pSave);
1247void vmsvga3dOglRestoreUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext,
1248 PCVMSVGAPACKPARAMS pSave);
1249
1250/** @name VMSVGA3D_DEF_CTX_F_XXX - vmsvga3dContextDefineOgl flags.
1251 * @{ */
1252/** When clear, the context is created using the default OpenGL profile.
1253 * When set, it's created using the alternative profile. The latter is only
1254 * allowed if the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set. */
1255# define VMSVGA3D_DEF_CTX_F_OTHER_PROFILE RT_BIT_32(0)
1256/** Defining the shared context. */
1257# define VMSVGA3D_DEF_CTX_F_SHARED_CTX RT_BIT_32(1)
1258/** Defining the init time context (EMT). */
1259# define VMSVGA3D_DEF_CTX_F_INIT RT_BIT_32(2)
1260/** @} */
1261int vmsvga3dContextDefineOgl(PVGASTATECC pThisCC, uint32_t cid, uint32_t fFlags);
1262void vmsvga3dSurfaceFormat2OGL(PVMSVGA3DSURFACE pSurface, SVGA3dSurfaceFormat format);
1263
1264#endif /* VMSVGA3D_OPENGL */
1265
1266
1267/* DevVGA-SVGA3d-shared.cpp: */
1268int vmsvga3dSaveShaderConst(PVMSVGA3DCONTEXT pContext, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype,
1269 uint32_t val1, uint32_t val2, uint32_t val3, uint32_t val4);
1270
1271
1272
1273/* Command implementation workers. */
1274void vmsvga3dBackSurfaceDestroy(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface);
1275int vmsvga3dBackSurfaceStretchBlt(PVGASTATE pThis, PVMSVGA3DSTATE pState,
1276 PVMSVGA3DSURFACE pDstSurface, uint32_t uDstFace, uint32_t uDstMipmap, SVGA3dBox const *pDstBox,
1277 PVMSVGA3DSURFACE pSrcSurface, uint32_t uSrcFace, uint32_t uSrcMipmap, SVGA3dBox const *pSrcBox,
1278 SVGA3dStretchBltMode enmMode, PVMSVGA3DCONTEXT pContext);
1279int vmsvga3dBackSurfaceDMACopyBox(PVGASTATE pThis, PVGASTATECC pThisCC, PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface,
1280 PVMSVGA3DMIPMAPLEVEL pMipLevel, uint32_t uHostFace, uint32_t uHostMipmap,
1281 SVGAGuestPtr GuestPtr, uint32_t cbGuestPitch, SVGA3dTransferType transfer,
1282 SVGA3dCopyBox const *pBox, PVMSVGA3DCONTEXT pContext, int rc, int iBox);
1283
1284int vmsvga3dBackCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext,
1285 PVMSVGA3DSURFACE pSurface);
1286
1287DECLINLINE(int) vmsvga3dContextFromCid(PVMSVGA3DSTATE pState, uint32_t cid, PVMSVGA3DCONTEXT *ppContext)
1288{
1289 AssertReturn(cid < pState->cContexts, VERR_INVALID_PARAMETER);
1290 PVMSVGA3DCONTEXT const pContext = pState->papContexts[cid];
1291 if (RT_LIKELY(pContext && pContext->id == cid))
1292 {
1293 *ppContext = pContext;
1294 return VINF_SUCCESS;
1295 }
1296 LogRelMax(64, ("VMSVGA: unknown cid=%u (%s cid=%u)\n", cid, pContext ? "expected" : "null", pContext ? pContext->id : -1));
1297 return VERR_INVALID_PARAMETER;
1298}
1299
1300DECLINLINE(int) vmsvga3dSurfaceFromSid(PVMSVGA3DSTATE pState, uint32_t sid, PVMSVGA3DSURFACE *ppSurface)
1301{
1302 AssertReturn(sid < pState->cSurfaces, VERR_INVALID_PARAMETER);
1303 PVMSVGA3DSURFACE const pSurface = pState->papSurfaces[sid];
1304 if (RT_LIKELY(pSurface && pSurface->id == sid))
1305 {
1306 *ppSurface = pSurface;
1307 return VINF_SUCCESS;
1308 }
1309 LogRelMax(64, ("VMSVGA: unknown sid=%u (%s sid=%u)\n", sid, pSurface ? "expected" : "null", pSurface ? pSurface->id : -1));
1310 return VERR_INVALID_PARAMETER;
1311}
1312
1313DECLINLINE(int) vmsvga3dMipmapLevel(PVMSVGA3DSURFACE pSurface, uint32_t face, uint32_t mipmap,
1314 PVMSVGA3DMIPMAPLEVEL *ppMipmapLevel)
1315{
1316 /* Can use faces[0].numMipLevels, because numMipLevels is the same for all faces. */
1317 const uint32_t numMipLevels = pSurface->faces[0].numMipLevels;
1318
1319 AssertMsgReturn(face < pSurface->cFaces,
1320 ("cFaces %d, face %d\n", pSurface->cFaces, face),
1321 VERR_INVALID_PARAMETER);
1322 AssertMsgReturn(mipmap < numMipLevels,
1323 ("numMipLevels %d, mipmap %d", numMipLevels, mipmap),
1324 VERR_INVALID_PARAMETER);
1325
1326 *ppMipmapLevel = &pSurface->paMipmapLevels[face * numMipLevels + mipmap];
1327 return VINF_SUCCESS;
1328}
1329
1330#ifdef VMSVGA3D_DIRECT3D
1331DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
1332{
1333 D3DCUBEMAP_FACES Face;
1334 switch (iFace)
1335 {
1336 case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break;
1337 case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break;
1338 case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break;
1339 case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break;
1340 case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break;
1341 default:
1342 case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break;
1343 }
1344 return Face;
1345}
1346#else /* VMSVGA3D_OPENGL */
1347DECLINLINE(GLenum) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
1348{
1349 GLint Face;
1350 switch (iFace)
1351 {
1352 case 0: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; break;
1353 case 1: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; break;
1354 case 2: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; break;
1355 case 3: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; break;
1356 case 4: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; break;
1357 default:
1358 case 5: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; break;
1359 }
1360 return Face;
1361}
1362#endif
1363
1364int vmsvga3dOcclusionQueryCreate(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1365int vmsvga3dOcclusionQueryDelete(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1366int vmsvga3dOcclusionQueryBegin(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1367int vmsvga3dOcclusionQueryEnd(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1368int vmsvga3dOcclusionQueryGetData(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t *pu32Pixels);
1369
1370void vmsvga3dInfoSurfaceToBitmap(PCDBGFINFOHLP pHlp, PVMSVGA3DSURFACE pSurface,
1371 const char *pszPath, const char *pszNamePrefix, const char *pszNameSuffix);
1372
1373#ifdef VMSVGA3D_DIRECT3D
1374#define D3D_RELEASE(ptr) do { \
1375 if (ptr) \
1376 { \
1377 (ptr)->Release(); \
1378 (ptr) = 0; \
1379 } \
1380} while (0)
1381
1382HRESULT D3D9UpdateTexture(PVMSVGA3DCONTEXT pContext,
1383 PVMSVGA3DSURFACE pSurface);
1384HRESULT D3D9GetRenderTargetData(PVMSVGA3DCONTEXT pContext,
1385 PVMSVGA3DSURFACE pSurface,
1386 uint32_t uFace,
1387 uint32_t uMipmap);
1388HRESULT D3D9GetSurfaceLevel(PVMSVGA3DSURFACE pSurface,
1389 uint32_t uFace,
1390 uint32_t uMipmap,
1391 bool fBounce,
1392 IDirect3DSurface9 **ppD3DSurface);
1393D3DFORMAT D3D9GetActualFormat(PVMSVGA3DSTATE pState,
1394 D3DFORMAT d3dfmt);
1395bool D3D9CheckDeviceFormat(IDirect3D9 *pD3D9,
1396 DWORD Usage,
1397 D3DRESOURCETYPE RType,
1398 D3DFORMAT CheckFormat);
1399#endif
1400
1401#ifdef VMSVGA3D_OPENGL
1402void vmsvga3dOnSharedContextDefine(PVMSVGA3DSTATE pState);
1403void vmsvga3dOnSharedContextDestroy(PVMSVGA3DSTATE pState);
1404
1405DECLINLINE(GLuint) GLTextureId(PVMSVGA3DSURFACE pSurface)
1406{
1407 return pSurface->fEmulated ? pSurface->idEmulated : pSurface->oglId.texture;
1408}
1409
1410void FormatConvUpdateTexture(PVMSVGA3DSTATE pState,
1411 PVMSVGA3DCONTEXT pCurrentContext,
1412 PVMSVGA3DSURFACE pSurface,
1413 uint32_t iMipmap);
1414void FormatConvReadTexture(PVMSVGA3DSTATE pState,
1415 PVMSVGA3DCONTEXT pCurrentContext,
1416 PVMSVGA3DSURFACE pSurface,
1417 uint32_t iMipmap);
1418#endif
1419
1420int vmsvga3dShaderParse(uint32_t cbShaderData, uint32_t const *pShaderData);
1421void vmsvga3dShaderLogRel(char const *pszMsg, SVGA3dShaderType type, uint32_t cbShaderData, uint32_t const *pShaderData);
1422
1423#endif /* !VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h */
1424
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