VirtualBox

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

Last change on this file since 86809 was 86809, checked in by vboxsync, 4 years ago

Devices/Graphics: move a backend specific structure to the backend source file.

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