VirtualBox

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

Last change on this file since 78339 was 77114, checked in by vboxsync, 6 years ago

DevVGA-SVGA3d-ogl: remember type of created resource; CopySurface/StretchBlt fixes; vmsvga3dBackSurfaceDMACopyBox support for 3D textures; occlusion query functions should set current context.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 50.8 KB
Line 
1/* $Id: DevVGA-SVGA3d-internal.h 77114 2019-02-01 13:13:31Z vboxsync $ */
2/** @file
3 * DevVMWare - VMWare SVGA device - 3D part, internal header.
4 */
5
6/*
7 * Copyright (C) 2013-2019 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# ifdef VBOX_STRICT
360# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { \
361 Assert((pState)->idActiveContext == (pContext)->id); \
362 (pContext)->lastError = glGetError(); \
363 AssertMsgReturn((pContext)->lastError == GL_NO_ERROR, \
364 ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError), \
365 VERR_INTERNAL_ERROR); \
366 } while (0)
367# else
368# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { } while (0)
369# endif
370
371/** @def VMSVGA3D_CHECK_LAST_ERROR_WARN
372 * Checks that the last OpenGL error code indicates success.
373 *
374 * Will assert in strict builds, otherwise it's a NOOP.
375 *
376 * @parm pState The VMSVGA3d state.
377 * @parm pContext The new context.
378 */
379# ifdef VBOX_STRICT
380# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { \
381 Assert((pState)->idActiveContext == (pContext)->id); \
382 (pContext)->lastError = glGetError(); \
383 AssertMsg((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError)); \
384 } while (0)
385# else
386# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { } while (0)
387# endif
388
389#endif /* VMSVGA3D_OPENGL */
390
391#ifdef VMSVGA3D_DIRECT3D
392/* Enable to use Wine to convert D3D to opengl */
393//#define VBOX_VMSVGA3D_WITH_WINE_OPENGL
394#endif
395
396
397/*********************************************************************************************************************************
398* Structures and Typedefs *
399*********************************************************************************************************************************/
400/**
401 * Mipmap level.
402 */
403typedef struct VMSVGA3DMIPMAPLEVEL
404{
405 /** The mipmap size: width, height and depth. */
406 SVGA3dSize mipmapSize;
407 /** Width in blocks: (width + cxBlock - 1) / cxBlock. SSM: not saved, recalculated on load. */
408 uint32_t cBlocksX;
409 /** Height in blocks: (height + cyBlock - 1) / cyBlock. SSM: not saved, recalculated on load. */
410 uint32_t cBlocksY;
411 /** The scanline/pitch size in bytes: at least cBlocksX * cbBlock. */
412 uint32_t cbSurfacePitch;
413 /** The size (in bytes) of the mipmap plane: cbSurfacePitch * cBlocksY */
414 uint32_t cbSurfacePlane;
415 /** The size (in bytes) of the mipmap data when using the format the surface was
416 * defined with: cbSurfacePlane * mipmapSize.z */
417 uint32_t cbSurface;
418 /** Pointer to the mipmap bytes (cbSurface). Often NULL. If the surface has
419 * been realized in hardware, this may be outdated. */
420 void *pSurfaceData;
421 /** Set if pvSurfaceData contains data not realized in hardware or pushed to the
422 * hardware surface yet. */
423 bool fDirty;
424} VMSVGA3DMIPMAPLEVEL;
425/** Pointer to a mipmap level. */
426typedef VMSVGA3DMIPMAPLEVEL *PVMSVGA3DMIPMAPLEVEL;
427
428
429#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
430/**
431 * SSM descriptor table for the VMSVGA3DMIPMAPLEVEL structure.
432 */
433static SSMFIELD const g_aVMSVGA3DMIPMAPLEVELFields[] =
434{
435 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, mipmapSize),
436 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurface),
437 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurfacePitch),
438 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DMIPMAPLEVEL, pSurfaceData),
439 SSMFIELD_ENTRY_IGNORE( VMSVGA3DMIPMAPLEVEL, fDirty),
440 SSMFIELD_ENTRY_TERM()
441};
442#endif
443
444typedef struct VMSVGATRANSFORMSTATE
445{
446 bool fValid;
447 float matrix[16];
448} VMSVGATRANSFORMSTATE;
449typedef VMSVGATRANSFORMSTATE *PVMSVGATRANSFORMSTATE;
450
451typedef struct VMSVGAMATERIALSTATE
452{
453 bool fValid;
454 SVGA3dMaterial material;
455} VMSVGAMATERIALSTATE;
456typedef VMSVGAMATERIALSTATE *PVMSVGAMATERIALSTATE;
457
458typedef struct VMSVGACLIPPLANESTATE
459{
460 bool fValid;
461 float plane[4];
462} VMSVGACLIPPLANESTATE;
463typedef VMSVGACLIPPLANESTATE *PVMSVGACLIPPLANESTATE;
464
465typedef struct VMSVGALIGHTSTATE
466{
467 bool fEnabled;
468 bool fValidData;
469 SVGA3dLightData data;
470} VMSVGALIGHTSTATE;
471typedef VMSVGALIGHTSTATE *PVMSVGALIGHTSTATE;
472
473typedef struct VMSVGASHADERCONST
474{
475 bool fValid;
476 SVGA3dShaderConstType ctype;
477 uint32_t value[4];
478} VMSVGASHADERCONST;
479typedef VMSVGASHADERCONST *PVMSVGASHADERCONST;
480
481#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
482/**
483 * SSM descriptor table for the VMSVGASHADERCONST structure.
484 */
485static SSMFIELD const g_aVMSVGASHADERCONSTFields[] =
486{
487 SSMFIELD_ENTRY( VMSVGASHADERCONST, fValid),
488 SSMFIELD_ENTRY( VMSVGASHADERCONST, ctype),
489 SSMFIELD_ENTRY( VMSVGASHADERCONST, value),
490 SSMFIELD_ENTRY_TERM()
491};
492#endif
493
494#ifdef VMSVGA3D_DIRECT3D
495
496/* What kind of Direct3D resource has been created for the VMSVGA3D surface. */
497typedef enum VMSVGA3DD3DRESTYPE
498{
499 VMSVGA3D_D3DRESTYPE_NONE = 0,
500 VMSVGA3D_D3DRESTYPE_SURFACE = 1,
501 VMSVGA3D_D3DRESTYPE_TEXTURE = 2,
502 VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE = 3,
503 VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE = 4,
504 VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER = 5,
505 VMSVGA3D_D3DRESTYPE_INDEX_BUFFER = 6
506} VMSVGA3DD3DRESTYPE;
507
508/**
509 *
510 */
511typedef struct
512{
513 /** Key is context id. */
514 AVLU32NODECORE Core;
515 union
516 {
517 IDirect3DSurface9 *pSurface;
518 IDirect3DTexture9 *pTexture;
519 IDirect3DCubeTexture9 *pCubeTexture;
520 IDirect3DVolumeTexture9 *pVolumeTexture;
521 } u;
522} VMSVGA3DSHAREDSURFACE;
523typedef VMSVGA3DSHAREDSURFACE *PVMSVGA3DSHAREDSURFACE;
524#endif /* VMSVGA3D_DIRECT3D */
525
526#ifdef VMSVGA3D_OPENGL
527/* What kind of OpenGL resource has been created for the VMSVGA3D surface. */
528typedef enum VMSVGA3DOGLRESTYPE
529{
530 VMSVGA3D_OGLRESTYPE_NONE = 0,
531 VMSVGA3D_OGLRESTYPE_BUFFER = 1,
532 VMSVGA3D_OGLRESTYPE_TEXTURE = 2,
533 VMSVGA3D_OGLRESTYPE_RENDERBUFFER = 3
534} VMSVGA3DOGLRESTYPE;
535#endif
536
537/**
538 * VMSVGA3d surface.
539 */
540typedef struct VMSVGA3DSURFACE
541{
542 uint32_t id;
543#ifdef VMSVGA3D_OPENGL
544 uint32_t idWeakContextAssociation;
545#else
546 uint32_t idAssociatedContext;
547#endif
548 uint32_t surfaceFlags;
549 SVGA3dSurfaceFormat format;
550#ifdef VMSVGA3D_OPENGL
551 GLint internalFormatGL;
552 GLint formatGL;
553 GLint typeGL;
554 VMSVGA3DOGLRESTYPE enmOGLResType; /* Which resource was created for the surface. */
555 union
556 {
557 GLuint texture;
558 GLuint buffer;
559 GLuint renderbuffer;
560 } oglId;
561 GLenum targetGL; /* GL_TEXTURE_* */
562 GLenum bindingGL; /* GL_TEXTURE_BINDING_* */
563#endif
564 SVGA3dSurfaceFace faces[SVGA3D_MAX_SURFACE_FACES];
565 uint32_t cFaces;
566 uint32_t cMipmapLevels;
567 PVMSVGA3DMIPMAPLEVEL pMipmapLevels;
568 uint32_t multiSampleCount;
569 SVGA3dTextureFilter autogenFilter;
570#ifdef VMSVGA3D_DIRECT3D
571 D3DFORMAT formatD3D;
572 DWORD fUsageD3D;
573 D3DMULTISAMPLE_TYPE multiSampleTypeD3D;
574#endif
575
576 uint32_t cbBlock; /* block/pixel size in bytes */
577 /* Dimensions of the surface block, usually 1x1 except for compressed formats. */
578 uint32_t cxBlock; /* Block width in pixels. SSM: not saved, recalculated on load. */
579 uint32_t cyBlock; /* Block height in pixels. SSM: not saved, recalculated on load. */
580
581 /* Dirty state; surface was manually updated. */
582 bool fDirty;
583
584#ifdef VMSVGA3D_DIRECT3D
585 /* Handle for shared objects (currently only textures & render targets). */
586 HANDLE hSharedObject;
587 /** Event query inserted after each GPU operation that updates or uses this surface. */
588 IDirect3DQuery9 *pQuery;
589 /* The type of actually created D3D resource. */
590 VMSVGA3DD3DRESTYPE enmD3DResType;
591 union
592 {
593 IDirect3DSurface9 *pSurface;
594 IDirect3DTexture9 *pTexture;
595 IDirect3DCubeTexture9 *pCubeTexture;
596 IDirect3DVolumeTexture9 *pVolumeTexture;
597 IDirect3DVertexBuffer9 *pVertexBuffer;
598 IDirect3DIndexBuffer9 *pIndexBuffer;
599 } u;
600 union
601 {
602 IDirect3DTexture9 *pTexture;
603 IDirect3DCubeTexture9 *pCubeTexture;
604 IDirect3DVolumeTexture9 *pVolumeTexture;
605 } bounce;
606 /** AVL tree containing VMSVGA3DSHAREDSURFACE structures. */
607 AVLU32TREE pSharedObjectTree;
608 bool fStencilAsTexture;
609#endif
610} VMSVGA3DSURFACE;
611/** Pointer to a 3d surface. */
612typedef VMSVGA3DSURFACE *PVMSVGA3DSURFACE;
613
614#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
615/**
616 * SSM descriptor table for the VMSVGA3DSURFACE structure.
617 */
618static SSMFIELD const g_aVMSVGA3DSURFACEFields[] =
619{
620 SSMFIELD_ENTRY( VMSVGA3DSURFACE, id),
621# ifdef VMSVGA3D_OPENGL
622 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idWeakContextAssociation),
623# else
624 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext),
625# endif
626 SSMFIELD_ENTRY( VMSVGA3DSURFACE, surfaceFlags),
627 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format),
628# ifdef VMSVGA3D_OPENGL
629 SSMFIELD_ENTRY( VMSVGA3DSURFACE, internalFormatGL),
630 SSMFIELD_ENTRY( VMSVGA3DSURFACE, formatGL),
631 SSMFIELD_ENTRY( VMSVGA3DSURFACE, typeGL),
632 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, id),
633# endif
634 SSMFIELD_ENTRY( VMSVGA3DSURFACE, faces),
635 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cFaces),
636 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, pMipmapLevels),
637 SSMFIELD_ENTRY( VMSVGA3DSURFACE, multiSampleCount),
638 SSMFIELD_ENTRY( VMSVGA3DSURFACE, autogenFilter),
639# ifdef VMSVGA3D_DIRECT3D
640 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format), /** @todo format duplicated. */
641 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, formatD3D),
642 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fUsageD3D),
643 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, multiSampleTypeD3D),
644# endif
645 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cbBlock),
646 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fDirty),
647# ifdef VMSVGA3D_DIRECT3D
648 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, hSharedObject),
649 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, pQuery),
650 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, u.pSurface),
651 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, bounce.pTexture),
652 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, pSharedObjectTree),
653 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fStencilAsTexture),
654# endif
655 SSMFIELD_ENTRY_TERM()
656};
657#endif
658
659/** Mask we frequently apply to VMSVGA3DSURFACE::flags for decing what kind
660 * of surface we're dealing. */
661#define VMSVGA3D_SURFACE_HINT_SWITCH_MASK \
662 ( SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER \
663 | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET \
664 | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP )
665
666/** @def VMSVGA3DSURFACE_HAS_HW_SURFACE
667 * Checks whether the surface has a host hardware/library surface.
668 * @returns true/false
669 * @param a_pSurface The VMSVGA3d surface.
670 */
671#ifdef VMSVGA3D_DIRECT3D
672# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->u.pSurface != NULL)
673#else
674# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->oglId.texture != OPENGL_INVALID_ID)
675#endif
676
677
678
679typedef struct VMSVGA3DSHADER
680{
681 uint32_t id;
682 uint32_t cid;
683 SVGA3dShaderType type;
684 uint32_t cbData;
685 void *pShaderProgram;
686 union
687 {
688#ifdef VMSVGA3D_DIRECT3D
689 IDirect3DVertexShader9 *pVertexShader;
690 IDirect3DPixelShader9 *pPixelShader;
691#else
692 void *pVertexShader;
693 void *pPixelShader;
694#endif
695 void *pv;
696 } u;
697} VMSVGA3DSHADER;
698typedef VMSVGA3DSHADER *PVMSVGA3DSHADER;
699
700#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
701/**
702 * SSM descriptor table for the VMSVGA3DSHADER structure.
703 */
704static SSMFIELD const g_aVMSVGA3DSHADERFields[] =
705{
706 SSMFIELD_ENTRY( VMSVGA3DSHADER, id),
707 SSMFIELD_ENTRY( VMSVGA3DSHADER, cid),
708 SSMFIELD_ENTRY( VMSVGA3DSHADER, type),
709 SSMFIELD_ENTRY( VMSVGA3DSHADER, cbData),
710 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, pShaderProgram),
711 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, u.pv),
712 SSMFIELD_ENTRY_TERM()
713};
714#endif
715
716/** @name VMSVGA3D_UPDATE_XXX - ...
717 * @{ */
718#define VMSVGA3D_UPDATE_SCISSORRECT RT_BIT_32(0)
719#define VMSVGA3D_UPDATE_ZRANGE RT_BIT_32(1)
720#define VMSVGA3D_UPDATE_VIEWPORT RT_BIT_32(2)
721#define VMSVGA3D_UPDATE_VERTEXSHADER RT_BIT_32(3)
722#define VMSVGA3D_UPDATE_PIXELSHADER RT_BIT_32(4)
723#define VMSVGA3D_UPDATE_TRANSFORM RT_BIT_32(5)
724#define VMSVGA3D_UPDATE_MATERIAL RT_BIT_32(6)
725/** @} */
726
727/* Query states. Mostly used for saved state. */
728typedef enum VMSVGA3DQUERYSTATE
729{
730 VMSVGA3DQUERYSTATE_NULL = 0, /* Not created. */
731 VMSVGA3DQUERYSTATE_SIGNALED = 1, /* Result obtained. The guest may or may not read the result yet. */
732 VMSVGA3DQUERYSTATE_BUILDING = 2, /* In process of collecting data. */
733 VMSVGA3DQUERYSTATE_ISSUED = 3, /* Data collected, but result is not yet obtained. */
734 VMSVGA3DQUERYSTATE_32BIT = 0x7fffffff
735} VMSVGA3DQUERYSTATE;
736AssertCompileSize(VMSVGA3DQUERYSTATE, sizeof(uint32_t));
737
738typedef struct VMSVGA3DQUERY
739{
740#ifdef VMSVGA3D_DIRECT3D
741 IDirect3DQuery9 *pQuery;
742#else /* VMSVGA3D_OPENGL */
743 GLuint idQuery;
744#endif
745 VMSVGA3DQUERYSTATE enmQueryState; /* VMSVGA3DQUERYSTATE_*. State is implicitly _NULL if pQuery is NULL. */
746 uint32_t u32QueryResult; /* Generic result. Enough for all VGPU9 queries. */
747} VMSVGA3DQUERY;
748
749#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
750/**
751 * SSM descriptor table for the VMSVGA3DQUERY structure.
752 */
753static SSMFIELD const g_aVMSVGA3DQUERYFields[] =
754{
755#ifdef VMSVGA3D_DIRECT3D
756 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DQUERY, pQuery),
757#else /* VMSVGA3D_OPENGL */
758 SSMFIELD_ENTRY_IGNORE( VMSVGA3DQUERY, idQuery),
759#endif
760 SSMFIELD_ENTRY( VMSVGA3DQUERY, enmQueryState),
761 SSMFIELD_ENTRY( VMSVGA3DQUERY, u32QueryResult),
762 SSMFIELD_ENTRY_TERM()
763};
764#endif
765
766#ifdef VMSVGA3D_DIRECT3D
767#define VMSVGA3DQUERY_EXISTS(p) ((p)->pQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)
768#else
769#define VMSVGA3DQUERY_EXISTS(p) ((p)->idQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)
770#endif
771
772/**
773 * VMSVGA3d context.
774 */
775typedef struct VMSVGA3DCONTEXT
776{
777 uint32_t id;
778#ifdef RT_OS_WINDOWS
779# ifdef VMSVGA3D_DIRECT3D
780# ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
781 IDirect3DDevice9 *pDevice;
782# else
783 IDirect3DDevice9Ex *pDevice;
784# endif
785# else
786 /* Device context of the context window. */
787 HDC hdc;
788 /* OpenGL rendering context handle. */
789 HGLRC hglrc;
790# endif
791 /* Device context window handle. */
792 HWND hwnd;
793#elif defined(RT_OS_DARWIN)
794 /* OpenGL rendering context */
795 NativeNSOpenGLContextRef cocoaContext;
796 NativeNSViewRef cocoaView;
797 bool fOtherProfile;
798#else
799 /** XGL rendering context handle */
800 GLXContext glxContext;
801 /** Device context window handle */
802 Window window;
803#endif
804
805#ifdef VMSVGA3D_OPENGL
806 /* Framebuffer object associated with this context. */
807 GLuint idFramebuffer;
808 /* Read and draw framebuffer objects for various operations. */
809 GLuint idReadFramebuffer;
810 GLuint idDrawFramebuffer;
811 /* Last GL error recorded. */
812 GLenum lastError;
813 void *pShaderContext;
814#endif
815
816 /* Current selected texture surfaces (if any) */
817 uint32_t aSidActiveTextures[SVGA3D_MAX_SAMPLERS];
818 /* Per context pixel and vertex shaders. */
819 uint32_t cPixelShaders;
820 PVMSVGA3DSHADER paPixelShader;
821 uint32_t cVertexShaders;
822 PVMSVGA3DSHADER paVertexShader;
823 /* Keep track of the internal state to be able to recreate the context properly (save/restore, window resize). */
824 struct
825 {
826 /** VMSVGA3D_UPDATE_XXX */
827 uint32_t u32UpdateFlags;
828
829 SVGA3dRenderState aRenderState[SVGA3D_RS_MAX];
830 /* aTextureStates contains both TextureStageStates and SamplerStates, therefore [SVGA3D_MAX_SAMPLERS]. */
831 SVGA3dTextureState aTextureStates[SVGA3D_MAX_SAMPLERS][SVGA3D_TS_MAX];
832 VMSVGATRANSFORMSTATE aTransformState[SVGA3D_TRANSFORM_MAX];
833 VMSVGAMATERIALSTATE aMaterial[SVGA3D_FACE_MAX];
834 VMSVGACLIPPLANESTATE aClipPlane[SVGA3D_CLIPPLANE_MAX];
835 VMSVGALIGHTSTATE aLightData[SVGA3D_MAX_LIGHTS];
836
837 uint32_t aRenderTargets[SVGA3D_RT_MAX];
838 SVGA3dRect RectScissor;
839 SVGA3dRect RectViewPort;
840 SVGA3dZRange zRange;
841 uint32_t shidPixel;
842 uint32_t shidVertex;
843
844 uint32_t cPixelShaderConst;
845 PVMSVGASHADERCONST paPixelShaderConst;
846 uint32_t cVertexShaderConst;
847 PVMSVGASHADERCONST paVertexShaderConst;
848 } state;
849
850 /* Occlusion query. */
851 VMSVGA3DQUERY occlusion;
852
853#ifdef VMSVGA3D_DIRECT3D
854 /* State which is currently applied to the D3D device. It is recreated as needed and not saved.
855 * The purpose is to remember the currently applied state and do not re-apply it if it has not changed.
856 * Unnecessary state changes are very bad for performance.
857 */
858 struct
859 {
860 /* Vertex declaration. */
861 IDirect3DVertexDeclaration9 *pVertexDecl;
862 uint32_t cVertexElements;
863 D3DVERTEXELEMENT9 aVertexElements[SVGA3D_MAX_VERTEX_ARRAYS + 1];
864 } d3dState;
865#endif
866} VMSVGA3DCONTEXT;
867/** Pointer to a VMSVGA3d context. */
868typedef VMSVGA3DCONTEXT *PVMSVGA3DCONTEXT;
869
870#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
871/**
872 * SSM descriptor table for the VMSVGA3DCONTEXT structure.
873 */
874static SSMFIELD const g_aVMSVGA3DCONTEXTFields[] =
875{
876 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, id),
877
878# ifdef RT_OS_WINDOWS
879# ifdef VMSVGA3D_DIRECT3D
880 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pDevice),
881# else
882 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hdc),
883 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hglrc),
884# endif
885 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hwnd),
886# elif defined(RT_OS_DARWIN)
887 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, cocoaContext),
888 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, cocoaView),
889 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, fOtherProfile),
890# else
891 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, glxContext),
892 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, window),
893# endif
894
895#ifdef VMSVGA3D_OPENGL
896 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idFramebuffer),
897 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idReadFramebuffer),
898 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idDrawFramebuffer),
899 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, lastError),
900 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pShaderContext),
901#endif
902
903 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, aSidActiveTextures),
904 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cPixelShaders),
905 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paPixelShader),
906 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cVertexShaders),
907 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paVertexShader),
908 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.u32UpdateFlags),
909
910 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderState),
911 SSMFIELD_ENTRY_OLD( state.aTextureStates,
912 sizeof(SVGA3dTextureState) * /*SVGA3D_MAX_TEXTURE_STAGE=*/ 8 * /*SVGA3D_TS_MAX=*/ 30),
913 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTransformState),
914 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aMaterial),
915 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aClipPlane),
916 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aLightData),
917
918 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderTargets),
919 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectScissor),
920 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectViewPort),
921 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.zRange),
922 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidPixel),
923 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidVertex),
924 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cPixelShaderConst),
925 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paPixelShaderConst),
926 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cVertexShaderConst),
927 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paVertexShaderConst),
928 SSMFIELD_ENTRY_TERM()
929};
930#endif /* VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS */
931
932
933/**
934 * VMSVGA3d state data.
935 *
936 * Allocated on the heap and pointed to by VMSVGAState::p3dState.
937 */
938typedef struct VMSVGA3DSTATE
939{
940 /** The size of papContexts. */
941 uint32_t cContexts;
942 /** The size of papSurfaces. */
943 uint32_t cSurfaces;
944 /** Contexts indexed by ID. Grown as needed. */
945 PVMSVGA3DCONTEXT *papContexts;
946 /** Surfaces indexed by ID. Grown as needed. */
947 PVMSVGA3DSURFACE *papSurfaces;
948
949#ifdef RT_OS_WINDOWS
950# ifdef VMSVGA3D_DIRECT3D
951# ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
952 IDirect3D9 *pD3D9;
953# else
954 IDirect3D9Ex *pD3D9;
955# endif
956 D3DCAPS9 caps;
957 bool fSupportedSurfaceINTZ;
958 bool fSupportedSurfaceNULL;
959# endif
960 /** Window Thread. */
961 R3PTRTYPE(RTTHREAD) pWindowThread;
962 DWORD idWindowThread;
963 HMODULE hInstance;
964 /** Window request semaphore. */
965 RTSEMEVENT WndRequestSem;
966#elif defined(RT_OS_DARWIN)
967#else
968 /* The X display */
969 Display *display;
970 R3PTRTYPE(RTTHREAD) pWindowThread;
971 bool bTerminate;
972#endif
973
974#ifdef VMSVGA3D_OPENGL
975 float rsGLVersion;
976 /* Current active context. */
977 uint32_t idActiveContext;
978
979 struct
980 {
981 PFNGLISRENDERBUFFERPROC glIsRenderbuffer;
982 PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
983 PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
984 PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
985 PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
986 PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv;
987 PFNGLISFRAMEBUFFERPROC glIsFramebuffer;
988 PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
989 PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
990 PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
991 PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
992 PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;
993 PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
994 PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;
995 PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
996 PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv;
997 PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
998 PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
999 PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;
1000 PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer;
1001 PFNGLPOINTPARAMETERFPROC glPointParameterf;
1002#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x102
1003 PFNGLBLENDCOLORPROC glBlendColor;
1004 PFNGLBLENDEQUATIONPROC glBlendEquation;
1005#endif
1006 PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate;
1007 PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
1008 PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate;
1009 PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate;
1010 PFNGLBINDBUFFERPROC glBindBuffer;
1011 PFNGLDELETEBUFFERSPROC glDeleteBuffers;
1012 PFNGLGENBUFFERSPROC glGenBuffers;
1013 PFNGLBUFFERDATAPROC glBufferData;
1014 PFNGLMAPBUFFERPROC glMapBuffer;
1015 PFNGLUNMAPBUFFERPROC glUnmapBuffer;
1016 PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
1017 PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
1018 PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
1019 PFNGLFOGCOORDPOINTERPROC glFogCoordPointer;
1020 PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex;
1021 PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex;
1022 PFNGLACTIVETEXTUREPROC glActiveTexture;
1023#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x103
1024 PFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture;
1025#endif
1026 PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
1027 PFNGLPROVOKINGVERTEXPROC glProvokingVertex;
1028 PFNGLGENQUERIESPROC glGenQueries;
1029 PFNGLDELETEQUERIESPROC glDeleteQueries;
1030 PFNGLBEGINQUERYPROC glBeginQuery;
1031 PFNGLENDQUERYPROC glEndQuery;
1032 PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv;
1033 PFNGLTEXIMAGE3DPROC glTexImage3D;
1034 PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D;
1035 PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor;
1036 PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced;
1037 PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced;
1038 PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D;
1039 PFNGLCOMPRESSEDTEXIMAGE3DPROC glCompressedTexImage3D;
1040 PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D;
1041 PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D;
1042 } ext;
1043
1044 struct
1045 {
1046 GLint maxActiveLights;
1047 GLint maxTextures;
1048 GLint maxClipDistances;
1049 GLint maxColorAttachments;
1050 GLint maxRectangleTextureSize;
1051 GLint maxTextureAnisotropy;
1052 GLint maxVertexShaderInstructions;
1053 GLint maxFragmentShaderInstructions;
1054 GLint maxVertexShaderTemps;
1055 GLint maxFragmentShaderTemps;
1056 GLfloat flPointSize[2];
1057 SVGA3dPixelShaderVersion fragmentShaderVersion;
1058 SVGA3dVertexShaderVersion vertexShaderVersion;
1059 bool fS3TCSupported;
1060 } caps;
1061
1062 /** The GL_EXTENSIONS value (space padded) for the default OpenGL profile.
1063 * Free with RTStrFree. */
1064 R3PTRTYPE(char *) pszExtensions;
1065
1066 /** The GL_EXTENSIONS value (space padded) for the other OpenGL profile.
1067 * Free with RTStrFree.
1068 *
1069 * This is used to detect shader model version since some implementations
1070 * (darwin) hides extensions that have made it into core and probably a
1071 * bunch of others when using a OpenGL core profile instead of a legacy one */
1072 R3PTRTYPE(char *) pszOtherExtensions;
1073 /** The version of the other GL profile. */
1074 float rsOtherGLVersion;
1075
1076 /** Shader talk back interface. */
1077 VBOXVMSVGASHADERIF ShaderIf;
1078
1079# ifdef VMSVGA3D_OPENGL
1080 /** The shared context. */
1081 VMSVGA3DCONTEXT SharedCtx;
1082# endif
1083#endif /* VMSVGA3D_OPENGL */
1084} VMSVGA3DSTATE;
1085
1086#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
1087/**
1088 * SSM descriptor table for the VMSVGA3DSTATE structure.
1089 *
1090 * @remarks This isn't a complete structure markup, only fields with state.
1091 */
1092static SSMFIELD const g_aVMSVGA3DSTATEFields[] =
1093{
1094# ifdef VMSVGA3D_OPENGL
1095 SSMFIELD_ENTRY( VMSVGA3DSTATE, rsGLVersion), /** @todo Why are we saving the GL version?? */
1096# endif
1097 SSMFIELD_ENTRY( VMSVGA3DSTATE, cContexts),
1098 SSMFIELD_ENTRY( VMSVGA3DSTATE, cSurfaces),
1099 SSMFIELD_ENTRY_TERM()
1100};
1101#endif /* VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS */
1102
1103
1104#ifdef VMSVGA3D_DIRECT3D
1105D3DFORMAT vmsvga3dSurfaceFormat2D3D(SVGA3dSurfaceFormat format);
1106D3DMULTISAMPLE_TYPE vmsvga3dMultipeSampleCount2D3D(uint32_t multisampleCount);
1107DECLCALLBACK(int) vmsvga3dSharedSurfaceDestroyTree(PAVLU32NODECORE pNode, void *pvParam);
1108int vmsvga3dSurfaceFlush(PVGASTATE pThis, PVMSVGA3DSURFACE pSurface);
1109#endif /* VMSVGA3D_DIRECT3D */
1110
1111
1112#ifdef VMSVGA3D_OPENGL
1113/** Save and setup everything. */
1114# define VMSVGA3D_PARANOID_TEXTURE_PACKING
1115
1116/**
1117 * Saved texture packing parameters (shared by both pack and unpack).
1118 */
1119typedef struct VMSVGAPACKPARAMS
1120{
1121 GLint iAlignment;
1122 GLint cxRow;
1123# ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
1124 GLint cyImage;
1125 GLboolean fSwapBytes;
1126 GLboolean fLsbFirst;
1127 GLint cSkipRows;
1128 GLint cSkipPixels;
1129 GLint cSkipImages;
1130# endif
1131} VMSVGAPACKPARAMS;
1132/** Pointer to saved texture packing parameters. */
1133typedef VMSVGAPACKPARAMS *PVMSVGAPACKPARAMS;
1134/** Pointer to const saved texture packing parameters. */
1135typedef VMSVGAPACKPARAMS const *PCVMSVGAPACKPARAMS;
1136
1137void vmsvga3dOglSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1138 PVMSVGAPACKPARAMS pSave);
1139void vmsvga3dOglRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1140 PCVMSVGAPACKPARAMS pSave);
1141void vmsvga3dOglSetUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1142 PVMSVGAPACKPARAMS pSave);
1143void vmsvga3dOglRestoreUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1144 PCVMSVGAPACKPARAMS pSave);
1145
1146/** @name VMSVGA3D_DEF_CTX_F_XXX - vmsvga3dContextDefineOgl flags.
1147 * @{ */
1148/** When clear, the context is created using the default OpenGL profile.
1149 * When set, it's created using the alternative profile. The latter is only
1150 * allowed if the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set. */
1151# define VMSVGA3D_DEF_CTX_F_OTHER_PROFILE RT_BIT_32(0)
1152/** Defining the shared context. */
1153# define VMSVGA3D_DEF_CTX_F_SHARED_CTX RT_BIT_32(1)
1154/** Defining the init time context (EMT). */
1155# define VMSVGA3D_DEF_CTX_F_INIT RT_BIT_32(2)
1156/** @} */
1157int vmsvga3dContextDefineOgl(PVGASTATE pThis, uint32_t cid, uint32_t fFlags);
1158void vmsvga3dSurfaceFormat2OGL(PVMSVGA3DSURFACE pSurface, SVGA3dSurfaceFormat format);
1159
1160#endif /* VMSVGA3D_OPENGL */
1161
1162
1163/* DevVGA-SVGA3d-shared.cpp: */
1164int vmsvga3dSaveShaderConst(PVMSVGA3DCONTEXT pContext, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype,
1165 uint32_t val1, uint32_t val2, uint32_t val3, uint32_t val4);
1166
1167
1168
1169/* Command implementation workers. */
1170void vmsvga3dBackSurfaceDestroy(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface);
1171int vmsvga3dBackSurfaceStretchBlt(PVGASTATE pThis, PVMSVGA3DSTATE pState,
1172 PVMSVGA3DSURFACE pDstSurface, uint32_t uDstFace, uint32_t uDstMipmap, SVGA3dBox const *pDstBox,
1173 PVMSVGA3DSURFACE pSrcSurface, uint32_t uSrcFace, uint32_t uSrcMipmap, SVGA3dBox const *pSrcBox,
1174 SVGA3dStretchBltMode enmMode, PVMSVGA3DCONTEXT pContext);
1175int vmsvga3dBackSurfaceDMACopyBox(PVGASTATE pThis, PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface,
1176 PVMSVGA3DMIPMAPLEVEL pMipLevel, uint32_t uHostFace, uint32_t uHostMipmap,
1177 SVGAGuestPtr GuestPtr, uint32_t cbGuestPitch, SVGA3dTransferType transfer,
1178 SVGA3dCopyBox const *pBox, PVMSVGA3DCONTEXT pContext, int rc, int iBox);
1179
1180int vmsvga3dBackCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext,
1181 PVMSVGA3DSURFACE pSurface);
1182
1183DECLINLINE(int) vmsvga3dContextFromCid(PVMSVGA3DSTATE pState, uint32_t cid, PVMSVGA3DCONTEXT *ppContext)
1184{
1185 /** @todo stricter checks for associated context */
1186 if ( cid >= pState->cContexts
1187 || pState->papContexts[cid]->id != cid)
1188 {
1189 Log(("vmsvga3dSurfaceCopy invalid context id!\n"));
1190 return VERR_INVALID_PARAMETER;
1191 }
1192
1193 *ppContext = pState->papContexts[cid];
1194 return VINF_SUCCESS;
1195}
1196
1197DECLINLINE(int) vmsvga3dSurfaceFromSid(PVMSVGA3DSTATE pState, uint32_t sid, PVMSVGA3DSURFACE *ppSurface)
1198{
1199 Assert(sid < SVGA3D_MAX_SURFACE_IDS);
1200 AssertReturn(sid < pState->cSurfaces, VERR_INVALID_PARAMETER);
1201 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
1202 AssertReturn(pSurface && pSurface->id == sid, VERR_INVALID_PARAMETER);
1203 *ppSurface = pSurface;
1204 return VINF_SUCCESS;
1205}
1206
1207DECLINLINE(int) vmsvga3dMipmapLevel(PVMSVGA3DSURFACE pSurface, uint32_t face, uint32_t mipmap,
1208 PVMSVGA3DMIPMAPLEVEL *ppMipmapLevel)
1209{
1210 /* Can use faces[0].numMipLevels, because numMipLevels is the same for all faces. */
1211 const uint32_t numMipLevels = pSurface->faces[0].numMipLevels;
1212
1213 AssertMsgReturn(face < pSurface->cFaces,
1214 ("cFaces %d, face %d\n", pSurface->cFaces, face),
1215 VERR_INVALID_PARAMETER);
1216 AssertMsgReturn(mipmap < numMipLevels,
1217 ("numMipLevels %d, mipmap %d", numMipLevels, mipmap),
1218 VERR_INVALID_PARAMETER);
1219
1220 *ppMipmapLevel = &pSurface->pMipmapLevels[face * numMipLevels + mipmap];
1221 return VINF_SUCCESS;
1222}
1223
1224#ifdef VMSVGA3D_DIRECT3D
1225DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
1226{
1227 D3DCUBEMAP_FACES Face;
1228 switch (iFace)
1229 {
1230 case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break;
1231 case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break;
1232 case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break;
1233 case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break;
1234 case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break;
1235 default:
1236 case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break;
1237 }
1238 return Face;
1239}
1240#else /* VMSVGA3D_OPENGL */
1241DECLINLINE(GLenum) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
1242{
1243 GLint Face;
1244 switch (iFace)
1245 {
1246 case 0: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; break;
1247 case 1: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; break;
1248 case 2: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; break;
1249 case 3: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; break;
1250 case 4: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; break;
1251 default:
1252 case 5: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; break;
1253 }
1254 return Face;
1255}
1256#endif
1257
1258int vmsvga3dOcclusionQueryCreate(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1259int vmsvga3dOcclusionQueryDelete(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1260int vmsvga3dOcclusionQueryBegin(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1261int vmsvga3dOcclusionQueryEnd(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1262int vmsvga3dOcclusionQueryGetData(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t *pu32Pixels);
1263
1264void vmsvga3dInfoSurfaceToBitmap(PCDBGFINFOHLP pHlp, PVMSVGA3DSURFACE pSurface,
1265 const char *pszPath, const char *pszNamePrefix, const char *pszNameSuffix);
1266
1267#endif /* !VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h */
1268
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