VirtualBox

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

Last change on this file since 57151 was 57151, checked in by vboxsync, 10 years ago

VMSVGA3d: Started reworking 3d command handling code to avoid duplicating code and ending up with slightly different versions. E.g. the input validation is the same regardless of the backend.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.0 KB
Line 
1/* $Id: DevVGA-SVGA3d-internal.h 57151 2015-08-02 19:46:25Z vboxsync $ */
2/** @file
3 * DevVMWare - VMWare SVGA device - 3D part, internal header.
4 */
5
6/*
7 * Copyright (C) 2013-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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 ___DevVGA_SVGA3d_internal_h
19#define ___DevVGA_SVGA3d_internal_h
20
21/*
22 * Assert sane compilation environment.
23 */
24#ifndef IN_RING3
25# error "VMSVGA3D_INCL_INTERNALS is only for ring-3 code"
26#endif
27#ifdef VMSVGA3D_OPENGL
28# ifdef VMSVGA3D_DIRECT3D
29# error "Both VMSVGA3D_DIRECT3D and VMSVGA3D_OPENGL cannot be defined at the same time."
30# endif
31#elif !defined(VMSVGA3D_DIRECT3D)
32# error "Either VMSVGA3D_OPENGL or VMSVGA3D_DIRECT3D must be defined."
33#endif
34
35
36/*********************************************************************************************************************************
37* Header Files *
38*********************************************************************************************************************************/
39#include "DevVGA-SVGA3d.h"
40
41#ifdef RT_OS_WINDOWS
42# include <Windows.h>
43# ifdef VMSVGA3D_DIRECT3D
44# include <d3d9.h>
45# include <iprt/avl.h>
46# else
47# include <GL/gl.h>
48# include "vmsvga_glext/wglext.h"
49# endif
50
51#elif defined(RT_OS_DARWIN)
52# include <OpenGL/OpenGL.h>
53# include <OpenGL/gl3.h>
54# include <OpenGL/gl3ext.h>
55# define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
56# include <OpenGL/gl.h>
57# include <OpenGL/glext.h>
58# include "DevVGA-SVGA3d-cocoa.h"
59/* work around conflicting definition of GLhandleARB in VMware's glext.h */
60//#define GL_ARB_shader_objects
61// HACK
62typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer);
63typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
64typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params);
65# define GL_RGBA_S3TC 0x83A2
66# define GL_ALPHA8_EXT 0x803c
67# define GL_LUMINANCE8_EXT 0x8040
68# define GL_LUMINANCE16_EXT 0x8042
69# define GL_LUMINANCE4_ALPHA4_EXT 0x8043
70# define GL_LUMINANCE8_ALPHA8_EXT 0x8045
71# define GL_INT_2_10_10_10_REV 0x8D9F
72
73#else
74# include <X11/Xlib.h>
75# include <X11/Xatom.h>
76# include <GL/gl.h>
77# include <GL/glx.h>
78# include <GL/glext.h>
79# define VBOX_VMSVGA3D_GL_HACK_LEVEL 0x103
80#endif
81
82#include "vmsvga/svga3d_shaderdefs.h"
83#ifdef VMSVGA3D_OPENGL
84# include "vmsvga_glext/glext.h"
85# include "shaderlib/shaderlib.h"
86#endif
87
88
89/*********************************************************************************************************************************
90* Defined Constants And Macros *
91*********************************************************************************************************************************/
92/** Experimental: Create a dedicated context for handling surfaces in, thus
93 * avoiding orphaned surfaces after context destruction.
94 *
95 * This cures, for instance, an assertion on fedora 21 that happens in
96 * vmsvga3dSurfaceStretchBlt if the login screen and the desktop has different
97 * sizes. The context of the login screen seems to have just been destroyed
98 * earlier and I believe the driver/X/whoever is attemting to strech the old
99 * screen content onto the new sized screen.
100 *
101 * @remarks This probably comes at a slight preformance expense, as we currently
102 * switches context when setting up the surface the first time. Not sure
103 * if we really need to, but as this is an experiment, I'm playing it safe.
104 */
105#ifdef VMSVGA3D_OPENGL
106# define VMSVGA3D_OGL_WITH_SHARED_CTX
107#endif
108#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
109/** Fake surface ID for the shared context. */
110# define VMSVGA3D_SHARED_CTX_ID UINT32_C(0xffffeeee)
111#endif
112
113#ifdef VMSVGA3D_OPENGL
114
115/** @def VBOX_VMSVGA3D_GL_HACK_LEVEL
116 * Turns out that on Linux gl.h may often define the first 2-4 OpenGL versions
117 * worth of extensions, but missing out on a function pointer of fifteen. This
118 * causes headache for us when we use the function pointers below. This hack
119 * changes the code to call the known problematic functions directly.
120 * The value is ((x)<<16 | (y)) where x and y are taken from the GL_VERSION_x_y.
121 */
122# ifndef VBOX_VMSVGA3D_GL_HACK_LEVEL
123# define VBOX_VMSVGA3D_GL_HACK_LEVEL 0
124# endif
125
126/** Invalid OpenGL ID. */
127# define OPENGL_INVALID_ID 0
128
129# define VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState) \
130 do { (pState)->idActiveContext = OPENGL_INVALID_ID; } while (0)
131
132/** @def VMSVGA3D_SET_CURRENT_CONTEXT
133 * Makes sure the @a pContext is the active OpenGL context.
134 * @parm pState The VMSVGA3d state.
135 * @parm pContext The new context.
136 */
137# ifdef RT_OS_WINDOWS
138# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
139 do { \
140 if ((pState)->idActiveContext != (pContext)->id) \
141 { \
142 BOOL fMakeCurrentRc = wglMakeCurrent((pContext)->hdc, (pContext)->hglrc); \
143 Assert(fMakeCurrentRc == TRUE); \
144 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \
145 (pState)->idActiveContext = (pContext)->id; \
146 } \
147 } while (0)
148
149# elif defined(RT_OS_DARWIN)
150# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
151 do { \
152 if ((pState)->idActiveContext != (pContext)->id) \
153 { \
154 vmsvga3dCocoaViewMakeCurrentContext((pContext)->cocoaView, (pContext)->cocoaContext); \
155 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \
156 (pState)->idActiveContext = (pContext)->id; \
157 } \
158 } while (0)
159# else
160# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
161 do { \
162 if ((pState)->idActiveContext != (pContext)->id) \
163 { \
164 Bool fMakeCurrentRc = glXMakeCurrent((pState)->display, \
165 (pContext)->window, \
166 (pContext)->glxContext); \
167 Assert(fMakeCurrentRc == True); \
168 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \
169 (pState)->idActiveContext = (pContext)->id; \
170 } \
171 } while (0)
172# endif
173
174/** @def VMSVGA3D_CLEAR_GL_ERRORS
175 * Clears all pending OpenGL errors.
176 *
177 * If I understood this correctly, OpenGL maintains a bitmask internally and
178 * glGetError gets the next bit (clearing it) from the bitmap and translates it
179 * into a GL_XXX constant value which it then returns. A single OpenGL call can
180 * set more than one bit, and they stick around across calls, from what I
181 * understand.
182 *
183 * So in order to be able to use glGetError to check whether a function
184 * succeeded, we need to call glGetError until all error bits have been cleared.
185 * This macro does that (in all types of builds).
186 *
187 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS
188 */
189# define VMSVGA3D_CLEAR_GL_ERRORS() \
190 do { \
191 if (RT_UNLIKELY(glGetError() != GL_NO_ERROR)) /* predict no errors pending */ \
192 { \
193 uint32_t iErrorClearingLoopsLeft = 64; \
194 while (glGetError() != GL_NO_ERROR && iErrorClearingLoopsLeft > 0) \
195 iErrorClearingLoopsLeft--; \
196 } \
197 } while (0)
198
199/** @def VMSVGA3D_GET_LAST_GL_ERROR
200 * Gets the last OpenGL error, stores it in a_pContext->lastError and returns
201 * it.
202 *
203 * @returns Same as glGetError.
204 * @param a_pContext The context to store the error in.
205 *
206 * @sa VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
207 */
208# define VMSVGA3D_GET_GL_ERROR(a_pContext) ((a_pContext)->lastError = glGetError())
209
210/** @def VMSVGA3D_GL_SUCCESS
211 * Checks whether VMSVGA3D_GET_LAST_GL_ERROR() return GL_NO_ERROR.
212 *
213 * Will call glGetError() and store the result in a_pContext->lastError.
214 * Will predict GL_NO_ERROR outcome.
215 *
216 * @returns True on success, false on error.
217 * @parm a_pContext The context to store the error in.
218 *
219 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_COMPLAIN
220 */
221# define VMSVGA3D_GL_IS_SUCCESS(a_pContext) RT_LIKELY((((a_pContext)->lastError = glGetError()) == GL_NO_ERROR))
222
223/** @def VMSVGA3D_GL_COMPLAIN
224 * Complains about one or more OpenGL errors (first in a_pContext->lastError).
225 *
226 * Strict builds will trigger an assertion, while other builds will put the
227 * first few occurences in the release log.
228 *
229 * All GL errors will be cleared after invocation. Assumes lastError
230 * is an error, will not check for GL_NO_ERROR.
231 *
232 * @param a_pState The 3D state structure.
233 * @param a_pContext The context that holds the first error.
234 * @param a_LogRelDetails Argument list for LogRel or similar that describes
235 * the operation in greater detail.
236 *
237 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS
238 */
239# ifdef VBOX_STRICT
240# define VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \
241 do { \
242 AssertMsg((a_pState)->idActiveContext == (a_pContext)->id, \
243 ("idActiveContext=%#x id=%x\n", (a_pState)->idActiveContext, (a_pContext)->id)); \
244 RTAssertMsg2Weak a_LogRelDetails; \
245 GLenum iNextError; \
246 while ((iNextError = glGetError()) != GL_NO_ERROR) \
247 RTAssertMsg2Weak("next error: %#x\n", iNextError); \
248 AssertMsgFailed(("first error: %#x (idActiveContext=%#x)\n", (a_pContext)->lastError, (a_pContext)->id)); \
249 } while (0)
250# else
251# define VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \
252 do { \
253 LogRelMax(32, ("VMSVGA3d: OpenGL error %#x (idActiveContext=%#x) on line %u ", (a_pContext)->lastError, (a_pContext)->id)); \
254 GLenum iNextError; \
255 while ((iNextError = glGetError()) != GL_NO_ERROR) \
256 LogRelMax(32, (" - also error %#x ", iNextError)); \
257 LogRelMax(32, a_LogRelDetails); \
258 } while (0)
259# endif
260
261/** @def VMSVGA3D_GL_GET_AND_COMPLAIN
262 * Combination of VMSVGA3D_GET_GL_ERROR and VMSVGA3D_GL_COMPLAIN, assuming that
263 * there is a pending error.
264 *
265 * @param a_pState The 3D state structure.
266 * @param a_pContext The context that holds the first error.
267 * @param a_LogRelDetails Argument list for LogRel or similar that describes
268 * the operation in greater detail.
269 *
270 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
271 */
272# define VMSVGA3D_GL_GET_AND_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \
273 do { \
274 VMSVGA3D_GET_GL_ERROR(a_pContext); \
275 VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \
276 } while (0)
277
278/** @def VMSVGA3D_GL_ASSERT_SUCCESS
279 * Asserts that VMSVGA3D_GL_IS_SUCCESS is true, complains if not.
280 *
281 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
282 * logging in non-strict builds.
283 *
284 * @param a_pState The 3D state structure.
285 * @param a_pContext The context that holds the first error.
286 * @param a_LogRelDetails Argument list for LogRel or similar that describes
287 * the operation in greater detail.
288 *
289 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
290 */
291# define VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails) \
292 if (VMSVGA3D_GL_IS_SUCCESS(a_pContext)) \
293 { /* likely */ } \
294 else do { \
295 VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \
296 } while (0)
297
298/** @def VMSVGA3D_ASSERT_GL_CALL_EX
299 * Executes the specified OpenGL API call and asserts that it succeeded, variant
300 * with extra logging flexibility.
301 *
302 * ASSUMES no GL errors pending prior to invocation - caller should use
303 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
304 *
305 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
306 * logging in non-strict builds.
307 *
308 * @param a_GlCall Expression making an OpenGL call.
309 * @param a_pState The 3D state structure.
310 * @param a_pContext The context that holds the first error.
311 * @param a_LogRelDetails Argument list for LogRel or similar that describes
312 * the operation in greater detail.
313 *
314 * @sa VMSVGA3D_ASSERT_GL_CALL, VMSVGA3D_GL_ASSERT_SUCCESS,
315 * VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
316 */
317# define VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, a_LogRelDetails) \
318 do { \
319 (a_GlCall); \
320 VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails); \
321 } while (0)
322
323/** @def VMSVGA3D_ASSERT_GL_CALL
324 * Executes the specified OpenGL API call and asserts that it succeeded.
325 *
326 * ASSUMES no GL errors pending prior to invocation - caller should use
327 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
328 *
329 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
330 * logging in non-strict builds.
331 *
332 * @param a_GlCall Expression making an OpenGL call.
333 * @param a_pState The 3D state structure.
334 * @param a_pContext The context that holds the first error.
335 *
336 * @sa VMSVGA3D_ASSERT_GL_CALL_EX, VMSVGA3D_GL_ASSERT_SUCCESS,
337 * VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
338 */
339# define VMSVGA3D_ASSERT_GL_CALL(a_GlCall, a_pState, a_pContext) \
340 VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, ("%s\n", #a_GlCall))
341
342
343/** @def VMSVGA3D_CHECK_LAST_ERROR
344 * Checks that the last OpenGL error code indicates success.
345 *
346 * Will assert and return VERR_INTERNAL_ERROR in strict builds, in other
347 * builds it will do nothing and is a NOOP.
348 *
349 * @parm pState The VMSVGA3d state.
350 * @parm pContext The context.
351 *
352 * @todo Replace with proper error handling, it's crazy to return
353 * VERR_INTERNAL_ERROR in strict builds and just barge on ahead in
354 * release builds.
355 */
356# ifdef VBOX_STRICT
357# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { \
358 Assert((pState)->idActiveContext == (pContext)->id); \
359 (pContext)->lastError = glGetError(); \
360 AssertMsgReturn((pContext)->lastError == GL_NO_ERROR, \
361 ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError), \
362 VERR_INTERNAL_ERROR); \
363 } while (0)
364# else
365# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { } while (0)
366# endif
367
368/** @def VMSVGA3D_CHECK_LAST_ERROR_WARN
369 * Checks that the last OpenGL error code indicates success.
370 *
371 * Will assert in strict builds, otherwise it's a NOOP.
372 *
373 * @parm pState The VMSVGA3d state.
374 * @parm pContext The new context.
375 */
376# ifdef VBOX_STRICT
377# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { \
378 Assert((pState)->idActiveContext == (pContext)->id); \
379 (pContext)->lastError = glGetError(); \
380 AssertMsg((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError)); \
381 } while (0)
382# else
383# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { } while (0)
384# endif
385
386#endif /* VMSVGA3D_OPENGL */
387
388#ifdef VMSVGA3D_DIRECT3D
389/* Enable to use Wine to convert D3D to opengl */
390//#define VBOX_VMSVGA3D_WITH_WINE_OPENGL
391#endif
392
393
394/*********************************************************************************************************************************
395* Structures and Typedefs *
396*********************************************************************************************************************************/
397/**
398 * Mipmap level.
399 */
400typedef struct VMSVGA3DMIPMAPLEVEL
401{
402 /** The mipmap size. */
403 SVGA3dSize size;
404 /** The size (in bytes) of the mimap data when using the format the surface was
405 * defined with. */
406 uint32_t cbSurface;
407 /** The scanline/pitch size in bytes. */
408 uint32_t cbSurfacePitch;
409 /** Pointer to the mipmap bytes (cbSurface). Often NULL. If the surface has
410 * been realized in hardware, this may be outdated. */
411 void *pSurfaceData;
412 /** Set if pvSurfaceData contains data not realized in hardware or pushed to the
413 * hardware surface yet. */
414 bool fDirty;
415} VMSVGA3DMIPMAPLEVEL;
416/** Pointer to a mipmap level. */
417typedef VMSVGA3DMIPMAPLEVEL *PVMSVGA3DMIPMAPLEVEL;
418
419
420#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
421/**
422 * SSM descriptor table for the VMSVGA3DMIPMAPLEVEL structure.
423 */
424static SSMFIELD const g_aVMSVGA3DMIPMAPLEVELFields[] =
425{
426 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, size),
427 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurface),
428 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurfacePitch),
429 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DMIPMAPLEVEL, pSurfaceData),
430 SSMFIELD_ENTRY_IGNORE( VMSVGA3DMIPMAPLEVEL, fDirty),
431 SSMFIELD_ENTRY_TERM()
432};
433#endif
434
435typedef struct VMSVGATRANSFORMSTATE
436{
437 bool fValid;
438 float matrix[16];
439} VMSVGATRANSFORMSTATE;
440typedef VMSVGATRANSFORMSTATE *PVMSVGATRANSFORMSTATE;
441
442typedef struct VMSVGAMATERIALSTATE
443{
444 bool fValid;
445 SVGA3dMaterial material;
446} VMSVGAMATERIALSTATE;
447typedef VMSVGAMATERIALSTATE *PVMSVGAMATERIALSTATE;
448
449typedef struct VMSVGACLIPPLANESTATE
450{
451 bool fValid;
452 float plane[4];
453} VMSVGACLIPPLANESTATE;
454typedef VMSVGACLIPPLANESTATE *PVMSVGACLIPPLANESTATE;
455
456typedef struct VMSVGALIGHTSTATE
457{
458 bool fEnabled;
459 bool fValidData;
460 SVGA3dLightData data;
461} VMSVGALIGHTSTATE;
462typedef VMSVGALIGHTSTATE *PVMSVGALIGHTSTATE;
463
464typedef struct VMSVGASHADERCONST
465{
466 bool fValid;
467 SVGA3dShaderConstType ctype;
468 uint32_t value[4];
469} VMSVGASHADERCONST;
470typedef VMSVGASHADERCONST *PVMSVGASHADERCONST;
471
472#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
473/**
474 * SSM descriptor table for the VMSVGASHADERCONST structure.
475 */
476static SSMFIELD const g_aVMSVGASHADERCONSTFields[] =
477{
478 SSMFIELD_ENTRY( VMSVGASHADERCONST, fValid),
479 SSMFIELD_ENTRY( VMSVGASHADERCONST, ctype),
480 SSMFIELD_ENTRY( VMSVGASHADERCONST, value),
481 SSMFIELD_ENTRY_TERM()
482};
483#endif
484
485#ifdef VMSVGA3D_DIRECT3D
486/**
487 *
488 */
489typedef struct
490{
491 /** Key is context id. */
492 AVLU32NODECORE Core;
493 union
494 {
495 IDirect3DSurface9 *pSurface;
496 IDirect3DTexture9 *pTexture;
497 IDirect3DCubeTexture9 *pCubeTexture;
498 } u;
499} VMSVGA3DSHAREDSURFACE;
500typedef VMSVGA3DSHAREDSURFACE *PVMSVGA3DSHAREDSURFACE;
501#endif /* VMSVGA3D_DIRECT3D */
502
503/**
504 * VMSVGA3d surface.
505 */
506typedef struct VMSVGA3DSURFACE
507{
508 uint32_t id;
509#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
510 uint32_t idWeakContextAssociation;
511#else
512 uint32_t idAssociatedContext;
513#endif
514 uint32_t flags;
515 SVGA3dSurfaceFormat format;
516#ifdef VMSVGA3D_OPENGL
517 GLint internalFormatGL;
518 GLint formatGL;
519 GLint typeGL;
520 union
521 {
522 GLuint texture;
523 GLuint buffer;
524 GLuint renderbuffer;
525 } oglId;
526#endif
527 SVGA3dSurfaceFace faces[SVGA3D_MAX_SURFACE_FACES];
528 uint32_t cFaces;
529 PVMSVGA3DMIPMAPLEVEL pMipmapLevels;
530 uint32_t multiSampleCount;
531 SVGA3dTextureFilter autogenFilter;
532#ifdef VMSVGA3D_DIRECT3D
533 D3DFORMAT formatD3D;
534 DWORD fUsageD3D;
535 D3DMULTISAMPLE_TYPE multiSampleTypeD3D;
536#endif
537
538 uint32_t cbBlock; /* block/pixel size in bytes */
539 /* Dirty state; surface was manually updated. */
540 bool fDirty;
541
542#ifdef VMSVGA3D_DIRECT3D
543 /* Handle for shared objects (currently only textures & render targets). */
544 HANDLE hSharedObject;
545 /** Event query inserted after each GPU operation that updates or uses this surface. */
546 IDirect3DQuery9 *pQuery;
547 union
548 {
549 IDirect3DSurface9 *pSurface;
550 IDirect3DCubeTexture9 *pCubeTexture;
551 IDirect3DIndexBuffer9 *pIndexBuffer;
552 IDirect3DTexture9 *pTexture;
553 IDirect3DVertexBuffer9 *pVertexBuffer;
554 } u;
555 union
556 {
557 IDirect3DTexture9 *pTexture;
558 } bounce;
559 /** AVL tree containing VMSVGA3DSHAREDSURFACE structures. */
560 AVLU32TREE pSharedObjectTree;
561 bool fStencilAsTexture;
562#endif
563} VMSVGA3DSURFACE;
564/** Pointer to a 3d surface. */
565typedef VMSVGA3DSURFACE *PVMSVGA3DSURFACE;
566
567#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
568/**
569 * SSM descriptor table for the VMSVGA3DSURFACE structure.
570 */
571static SSMFIELD const g_aVMSVGA3DSURFACEFields[] =
572{
573 SSMFIELD_ENTRY( VMSVGA3DSURFACE, id),
574#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
575 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idWeakContextAssociation),
576# else
577 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext),
578# endif
579 SSMFIELD_ENTRY( VMSVGA3DSURFACE, flags),
580 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format),
581# ifdef VMSVGA3D_OPENGL
582 SSMFIELD_ENTRY( VMSVGA3DSURFACE, internalFormatGL),
583 SSMFIELD_ENTRY( VMSVGA3DSURFACE, formatGL),
584 SSMFIELD_ENTRY( VMSVGA3DSURFACE, typeGL),
585 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, id),
586# endif
587 SSMFIELD_ENTRY( VMSVGA3DSURFACE, faces),
588 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cFaces),
589 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, pMipmapLevels),
590 SSMFIELD_ENTRY( VMSVGA3DSURFACE, multiSampleCount),
591 SSMFIELD_ENTRY( VMSVGA3DSURFACE, autogenFilter),
592# ifdef VMSVGA3D_DIRECT3D
593 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format), /** @todo format duplicated. */
594 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, formatD3D),
595 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fUsageD3D),
596 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, multiSampleTypeD3D),
597# endif
598 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cbBlock),
599 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fDirty),
600# ifdef VMSVGA3D_DIRECT3D
601 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, hSharedObject),
602 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, pQuery),
603 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, u.pSurface),
604 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, bounce.pTexture),
605 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, pSharedObjectTree),
606 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fStencilAsTexture),
607# endif
608 SSMFIELD_ENTRY_TERM()
609};
610#endif
611
612/** Mask we frequently apply to VMSVGA3DSURFACE::flags for decing what kind
613 * of surface we're dealing. */
614#define VMSVGA3D_SURFACE_HINT_SWITCH_MASK \
615 ( SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER \
616 | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET \
617 | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP )
618
619/** @def VMSVGA3DSURFACE_HAS_HW_SURFACE
620 * Checks whether the surface has a host hardware/library surface.
621 * @returns true/false
622 * @param a_pSurface The VMSVGA3d surface.
623 */
624#ifdef VMSVGA3D_DIRECT3D
625# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->u.pSurface != NULL)
626#else
627# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->oglId.texture != OPENGL_INVALID_ID)
628#endif
629
630
631
632typedef struct VMSVGA3DSHADER
633{
634 uint32_t id;
635 uint32_t cid;
636 SVGA3dShaderType type;
637 uint32_t cbData;
638 void *pShaderProgram;
639 union
640 {
641#ifdef VMSVGA3D_DIRECT3D
642 IDirect3DVertexShader9 *pVertexShader;
643 IDirect3DPixelShader9 *pPixelShader;
644#else
645 void *pVertexShader;
646 void *pPixelShader;
647#endif
648 void *pv;
649 } u;
650} VMSVGA3DSHADER;
651typedef VMSVGA3DSHADER *PVMSVGA3DSHADER;
652
653#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
654/**
655 * SSM descriptor table for the VMSVGA3DSHADER structure.
656 */
657static SSMFIELD const g_aVMSVGA3DSHADERFields[] =
658{
659 SSMFIELD_ENTRY( VMSVGA3DSHADER, id),
660 SSMFIELD_ENTRY( VMSVGA3DSHADER, cid),
661 SSMFIELD_ENTRY( VMSVGA3DSHADER, type),
662 SSMFIELD_ENTRY( VMSVGA3DSHADER, cbData),
663 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, pShaderProgram),
664 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, u.pv),
665 SSMFIELD_ENTRY_TERM()
666};
667#endif
668
669/** @name VMSVGA3D_UPDATE_XXX - ...
670 * @{ */
671#define VMSVGA3D_UPDATE_SCISSORRECT RT_BIT_32(0)
672#define VMSVGA3D_UPDATE_ZRANGE RT_BIT_32(1)
673#define VMSVGA3D_UPDATE_VIEWPORT RT_BIT_32(2)
674#define VMSVGA3D_UPDATE_VERTEXSHADER RT_BIT_32(3)
675#define VMSVGA3D_UPDATE_PIXELSHADER RT_BIT_32(4)
676#define VMSVGA3D_UPDATE_TRANSFORM RT_BIT_32(5)
677#define VMSVGA3D_UPDATE_MATERIAL RT_BIT_32(6)
678/** @} */
679
680/**
681 * VMSVGA3d context.
682 */
683typedef struct VMSVGA3DCONTEXT
684{
685 uint32_t id;
686#ifdef RT_OS_WINDOWS
687# ifdef VMSVGA3D_DIRECT3D
688# ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
689 IDirect3DDevice9 *pDevice;
690# else
691 IDirect3DDevice9Ex *pDevice;
692# endif
693# else
694 /* Device context of the context window. */
695 HDC hdc;
696 /* OpenGL rendering context handle. */
697 HGLRC hglrc;
698# endif
699 /* Device context window handle. */
700 HWND hwnd;
701#elif defined(RT_OS_DARWIN)
702 /* OpenGL rendering context */
703 NativeNSOpenGLContextRef cocoaContext;
704 NativeNSViewRef cocoaView;
705 bool fOtherProfile;
706#else
707 /** XGL rendering context handle */
708 GLXContext glxContext;
709 /** Device context window handle */
710 Window window;
711 /** flag whether the window is mapped (=visible) */
712 bool fMapped;
713#endif
714
715#ifdef VMSVGA3D_OPENGL
716 /* Framebuffer object associated with this context. */
717 GLuint idFramebuffer;
718 /* Read and draw framebuffer objects for various operations. */
719 GLuint idReadFramebuffer;
720 GLuint idDrawFramebuffer;
721 /* Last GL error recorded. */
722 GLenum lastError;
723 void *pShaderContext;
724#endif
725
726 /* Current active render target (if any) */
727 uint32_t sidRenderTarget;
728 /* Current selected texture surfaces (if any) */
729 uint32_t aSidActiveTexture[SVGA3D_MAX_TEXTURE_STAGE];
730 /* Per context pixel and vertex shaders. */
731 uint32_t cPixelShaders;
732 PVMSVGA3DSHADER paPixelShader;
733 uint32_t cVertexShaders;
734 PVMSVGA3DSHADER paVertexShader;
735 /* Keep track of the internal state to be able to recreate the context properly (save/restore, window resize). */
736 struct
737 {
738 /** VMSVGA3D_UPDATE_XXX */
739 uint32_t u32UpdateFlags;
740
741 SVGA3dRenderState aRenderState[SVGA3D_RS_MAX];
742 SVGA3dTextureState aTextureState[SVGA3D_MAX_TEXTURE_STAGE][SVGA3D_TS_MAX];
743 VMSVGATRANSFORMSTATE aTransformState[SVGA3D_TRANSFORM_MAX];
744 VMSVGAMATERIALSTATE aMaterial[SVGA3D_FACE_MAX];
745 VMSVGACLIPPLANESTATE aClipPlane[SVGA3D_CLIPPLANE_MAX];
746 VMSVGALIGHTSTATE aLightData[SVGA3D_MAX_LIGHTS];
747
748 uint32_t aRenderTargets[SVGA3D_RT_MAX];
749 SVGA3dRect RectScissor;
750 SVGA3dRect RectViewPort;
751 SVGA3dZRange zRange;
752 uint32_t shidPixel;
753 uint32_t shidVertex;
754
755 uint32_t cPixelShaderConst;
756 PVMSVGASHADERCONST paPixelShaderConst;
757 uint32_t cVertexShaderConst;
758 PVMSVGASHADERCONST paVertexShaderConst;
759 } state;
760} VMSVGA3DCONTEXT;
761/** Pointer to a VMSVGA3d context. */
762typedef VMSVGA3DCONTEXT *PVMSVGA3DCONTEXT;
763
764#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
765/**
766 * SSM descriptor table for the VMSVGA3DCONTEXT structure.
767 */
768static SSMFIELD const g_aVMSVGA3DCONTEXTFields[] =
769{
770 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, id),
771
772# ifdef RT_OS_WINDOWS
773# ifdef VMSVGA3D_DIRECT3D
774 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pDevice),
775# else
776 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hdc),
777 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hglrc),
778# endif
779 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hwnd),
780# elif defined(RT_OS_DARWIN)
781 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, cocoaContext),
782 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, cocoaView),
783 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, fOtherProfile),
784# else
785 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, glxContext),
786 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, window),
787 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, fMapped),
788# endif
789
790#ifdef VMSVGA3D_OPENGL
791 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idFramebuffer),
792 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idReadFramebuffer),
793 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idDrawFramebuffer),
794 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, lastError),
795 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pShaderContext),
796#endif
797
798 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, sidRenderTarget),
799 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, aSidActiveTexture),
800 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cPixelShaders),
801 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paPixelShader),
802 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cVertexShaders),
803 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paVertexShader),
804 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.u32UpdateFlags),
805
806 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderState),
807 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTextureState),
808 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTransformState),
809 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aMaterial),
810 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aClipPlane),
811 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aLightData),
812
813 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderTargets),
814 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectScissor),
815 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectViewPort),
816 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.zRange),
817 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidPixel),
818 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidVertex),
819 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cPixelShaderConst),
820 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paPixelShaderConst),
821 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cVertexShaderConst),
822 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paVertexShaderConst),
823 SSMFIELD_ENTRY_TERM()
824};
825#endif /* VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS */
826
827
828/**
829 * VMSVGA3d state data.
830 *
831 * Allocated on the heap and pointed to by VMSVGAState::p3dState.
832 */
833typedef struct VMSVGA3DSTATE
834{
835 /** The size of papContexts. */
836 uint32_t cContexts;
837 /** The size of papSurfaces. */
838 uint32_t cSurfaces;
839 /** Contexts indexed by ID. Grown as needed. */
840 PVMSVGA3DCONTEXT *papContexts;
841 /** Surfaces indexed by ID. Grown as needed. */
842 PVMSVGA3DSURFACE *papSurfaces;
843
844#ifdef RT_OS_WINDOWS
845# ifdef VMSVGA3D_DIRECT3D
846# ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
847 IDirect3D9 *pD3D9;
848# else
849 IDirect3D9Ex *pD3D9;
850# endif
851 D3DCAPS9 caps;
852 bool fSupportedSurfaceINTZ;
853 bool fSupportedSurfaceNULL;
854# endif
855 /** Window Thread. */
856 R3PTRTYPE(RTTHREAD) pWindowThread;
857 DWORD idWindowThread;
858 HMODULE hInstance;
859 /** Window request semaphore. */
860 RTSEMEVENT WndRequestSem;
861#elif defined(RT_OS_DARWIN)
862#else
863 /* The X display */
864 Display *display;
865 R3PTRTYPE(RTTHREAD) pWindowThread;
866 bool bTerminate;
867#endif
868
869#ifdef VMSVGA3D_OPENGL
870 float fGLVersion;
871 /* Current active context. */
872 uint32_t idActiveContext;
873
874 struct
875 {
876 PFNGLISRENDERBUFFERPROC glIsRenderbuffer;
877 PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
878 PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
879 PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
880 PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
881 PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv;
882 PFNGLISFRAMEBUFFERPROC glIsFramebuffer;
883 PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
884 PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
885 PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
886 PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
887 PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;
888 PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
889 PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;
890 PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
891 PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv;
892 PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
893 PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
894 PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;
895 PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer;
896 PFNGLPOINTPARAMETERFPROC glPointParameterf;
897#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x102
898 PFNGLBLENDCOLORPROC glBlendColor;
899 PFNGLBLENDEQUATIONPROC glBlendEquation;
900#endif
901 PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate;
902 PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
903 PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate;
904 PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate;
905 PFNGLBINDBUFFERPROC glBindBuffer;
906 PFNGLDELETEBUFFERSPROC glDeleteBuffers;
907 PFNGLGENBUFFERSPROC glGenBuffers;
908 PFNGLBUFFERDATAPROC glBufferData;
909 PFNGLMAPBUFFERPROC glMapBuffer;
910 PFNGLUNMAPBUFFERPROC glUnmapBuffer;
911 PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
912 PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
913 PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
914 PFNGLFOGCOORDPOINTERPROC glFogCoordPointer;
915 PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex;
916 PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex;
917 PFNGLACTIVETEXTUREPROC glActiveTexture;
918#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x103
919 PFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture;
920#endif
921 PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
922 PFNGLPROVOKINGVERTEXPROC glProvokingVertex;
923 bool fEXT_stencil_two_side;
924 } ext;
925
926 struct
927 {
928 GLint maxActiveLights;
929 GLint maxTextureBufferSize;
930 GLint maxTextures;
931 GLint maxClipDistances;
932 GLint maxColorAttachments;
933 GLint maxRectangleTextureSize;
934 GLint maxTextureAnisotropy;
935 GLint maxVertexShaderInstructions;
936 GLint maxFragmentShaderInstructions;
937 GLint maxVertexShaderTemps;
938 GLint maxFragmentShaderTemps;
939 GLfloat flPointSize[2];
940 SVGA3dPixelShaderVersion fragmentShaderVersion;
941 SVGA3dVertexShaderVersion vertexShaderVersion;
942 bool fS3TCSupported;
943 } caps;
944
945 /** The GL_EXTENSIONS value (space padded) for the default OpenGL profile.
946 * Free with RTStrFree. */
947 R3PTRTYPE(char *) pszExtensions;
948
949 /** The GL_EXTENSIONS value (space padded) for the other OpenGL profile.
950 * Free with RTStrFree.
951 *
952 * This is used to detect shader model version since some implementations
953 * (darwin) hides extensions that have made it into core and probably a
954 * bunch of others when using a OpenGL core profile instead of a legacy one */
955 R3PTRTYPE(char *) pszOtherExtensions;
956 /** The version of the other GL profile. */
957 float fOtherGLVersion;
958
959 /** Shader talk back interface. */
960 VBOXVMSVGASHADERIF ShaderIf;
961
962# ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
963 /** The shared context. */
964 VMSVGA3DCONTEXT SharedCtx;
965# endif
966#endif /* VMSVGA3D_OPENGL */
967} VMSVGA3DSTATE;
968
969#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
970/**
971 * SSM descriptor table for the VMSVGA3DSTATE structure.
972 *
973 * @remarks This isn't a complete structure markup, only fields with state.
974 */
975static SSMFIELD const g_aVMSVGA3DSTATEFields[] =
976{
977# ifdef VMSVGA3D_OPENGL
978 SSMFIELD_ENTRY( VMSVGA3DSTATE, fGLVersion), /** @todo Why are we saving the GL version?? */
979# endif
980 SSMFIELD_ENTRY( VMSVGA3DSTATE, cContexts),
981 SSMFIELD_ENTRY( VMSVGA3DSTATE, cSurfaces),
982 SSMFIELD_ENTRY_TERM()
983};
984#endif /* VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS */
985
986
987#ifdef VMSVGA3D_DIRECT3D
988D3DFORMAT vmsvga3dSurfaceFormat2D3D(SVGA3dSurfaceFormat format);
989D3DMULTISAMPLE_TYPE vmsvga3dMultipeSampleCount2D3D(uint32_t multisampleCount);
990DECLCALLBACK(int) vmsvga3dSharedSurfaceDestroyTree(PAVLU32NODECORE pNode, void *pvParam);
991int vmsvga3dSurfaceFlush(PVGASTATE pThis, PVMSVGA3DSURFACE pSurface);
992#endif /* VMSVGA3D_DIRECT3D */
993
994
995#ifdef VMSVGA3D_OPENGL
996/** Save and setup everything. */
997# define VMSVGA3D_PARANOID_TEXTURE_PACKING
998
999/**
1000 * Saved texture packing parameters (shared by both pack and unpack).
1001 */
1002typedef struct VMSVGAPACKPARAMS
1003{
1004 GLint iAlignment;
1005 GLint cxRow;
1006# ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
1007 GLint cyImage;
1008 GLboolean fSwapBytes;
1009 GLboolean fLsbFirst;
1010 GLint cSkipRows;
1011 GLint cSkipPixels;
1012 GLint cSkipImages;
1013# endif
1014} VMSVGAPACKPARAMS;
1015/** Pointer to saved texture packing parameters. */
1016typedef VMSVGAPACKPARAMS *PVMSVGAPACKPARAMS;
1017/** Pointer to const saved texture packing parameters. */
1018typedef VMSVGAPACKPARAMS const *PCVMSVGAPACKPARAMS;
1019
1020void vmsvga3dOglSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1021 PVMSVGAPACKPARAMS pSave);
1022void vmsvga3dOglRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1023 PCVMSVGAPACKPARAMS pSave);
1024void vmsvga3dOglSetUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1025 PVMSVGAPACKPARAMS pSave);
1026void vmsvga3dOglRestoreUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1027 PCVMSVGAPACKPARAMS pSave);
1028
1029/** @name VMSVGA3D_DEF_CTX_F_XXX - vmsvga3dContextDefineOgl flags.
1030 * @{ */
1031/** When clear, the context is created using the default OpenGL profile.
1032 * When set, it's created using the alternative profile. The latter is only
1033 * allowed if the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set. */
1034# define VMSVGA3D_DEF_CTX_F_OTHER_PROFILE RT_BIT_32(0)
1035/** Defining the shared context. */
1036# define VMSVGA3D_DEF_CTX_F_SHARED_CTX RT_BIT_32(1)
1037/** Defining the init time context (EMT). */
1038# define VMSVGA3D_DEF_CTX_F_INIT RT_BIT_32(2)
1039/** @} */
1040int vmsvga3dContextDefineOgl(PVGASTATE pThis, uint32_t cid, uint32_t fFlags);
1041void vmsvga3dSurfaceFormat2OGL(PVMSVGA3DSURFACE pSurface, SVGA3dSurfaceFormat format);
1042
1043#endif /* VMSVGA3D_OPENGL */
1044
1045
1046/* DevVGA-SVGA3d-shared.cpp: */
1047uint32_t vmsvga3dSaveShaderConst(PVMSVGA3DCONTEXT pContext, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype,
1048 uint32_t val1, uint32_t val2, uint32_t val3, uint32_t val4);
1049
1050
1051
1052/* Command implementation workers. */
1053void vmsvga3dBackSurfaceDestroy(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface);
1054int vmsvga3dBackSurfaceStretchBlt(PVGASTATE pThis, PVMSVGA3DSTATE pState,
1055 PVMSVGA3DSURFACE pDstSurface, uint32_t uDstMipmap, SVGA3dBox const *pDstBox,
1056 PVMSVGA3DSURFACE pSrcSurface, uint32_t uSrcMipmap, SVGA3dBox const *pSrcBox,
1057 SVGA3dStretchBltMode enmMode, PVMSVGA3DCONTEXT pContext);
1058int vmsvga3dBackSurfaceDMACopyBox(PVGASTATE pThis, PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface, uint32_t uHostMimap,
1059 SVGAGuestPtr GuestPtr, uint32_t cbSrcPitch, SVGA3dTransferType transfer,
1060 SVGA3dCopyBox const *pBox, PVMSVGA3DCONTEXT pContext, int rc, int iBox);
1061
1062int vmsvga3dBackCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext,
1063 PVMSVGA3DSURFACE pSurface);
1064
1065#endif
1066
Note: See TracBrowser for help on using the repository browser.

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