VirtualBox

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

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

Devices/Graphics: use glVertexAttrib to set a constant value of a generic vertex attribute

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 57.0 KB
Line 
1/* $Id: DevVGA-SVGA3d-internal.h 82586 2019-12-16 15:23:17Z vboxsync $ */
2/** @file
3 * DevVMWare - VMWare SVGA device - 3D part, internal header.
4 */
5
6/*
7 * Copyright (C) 2013-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h
19#define VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/*
25 * Assert sane compilation environment.
26 */
27#ifndef IN_RING3
28# error "VMSVGA3D_INCL_INTERNALS is only for ring-3 code"
29#endif
30#ifdef VMSVGA3D_OPENGL
31# ifdef VMSVGA3D_DIRECT3D
32# error "Both VMSVGA3D_DIRECT3D and VMSVGA3D_OPENGL cannot be defined at the same time."
33# endif
34#elif !defined(VMSVGA3D_DIRECT3D)
35# error "Either VMSVGA3D_OPENGL or VMSVGA3D_DIRECT3D must be defined."
36#endif
37
38
39/*********************************************************************************************************************************
40* Header Files *
41*********************************************************************************************************************************/
42#include "DevVGA-SVGA3d.h"
43
44#if defined(VMSVGA3D_DYNAMIC_LOAD) && defined(VMSVGA3D_OPENGL)
45# include "DevVGA-SVGA3d-glLdr.h"
46#endif
47
48#ifdef RT_OS_WINDOWS
49# include <iprt/win/windows.h>
50# ifdef VMSVGA3D_DIRECT3D
51# include <d3d9.h>
52# include <iprt/avl.h>
53# else
54# include <GL/gl.h>
55# include "vmsvga_glext/wglext.h"
56# endif
57
58#elif defined(RT_OS_DARWIN)
59# include <OpenGL/OpenGL.h>
60# include <OpenGL/gl3.h>
61# include <OpenGL/gl3ext.h>
62# define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
63# include <OpenGL/gl.h>
64# include <OpenGL/glext.h>
65# include "DevVGA-SVGA3d-cocoa.h"
66/* work around conflicting definition of GLhandleARB in VMware's glext.h */
67//#define GL_ARB_shader_objects
68// HACK
69typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer);
70typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
71typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params);
72# define GL_RGBA_S3TC 0x83A2
73# define GL_ALPHA8_EXT 0x803c
74# define GL_LUMINANCE8_EXT 0x8040
75# define GL_LUMINANCE16_EXT 0x8042
76# define GL_LUMINANCE4_ALPHA4_EXT 0x8043
77# define GL_LUMINANCE8_ALPHA8_EXT 0x8045
78# define GL_INT_2_10_10_10_REV 0x8D9F
79
80#else
81# include <X11/Xlib.h>
82# include <X11/Xatom.h>
83# include <GL/gl.h>
84# include <GL/glx.h>
85# include <GL/glext.h>
86# define VBOX_VMSVGA3D_GL_HACK_LEVEL 0x103
87#endif
88
89#include "vmsvga/svga3d_shaderdefs.h"
90#ifdef VMSVGA3D_OPENGL
91# include "vmsvga_glext/glext.h"
92# include "shaderlib/shaderlib.h"
93#endif
94
95
96/*********************************************************************************************************************************
97* Defined Constants And Macros *
98*********************************************************************************************************************************/
99#ifdef VMSVGA3D_OPENGL
100/** OpenGL: Create a dedicated context for handling surfaces in, thus
101 * avoiding orphaned surfaces after context destruction.
102 *
103 * This cures, for instance, an assertion on fedora 21 that happens in
104 * vmsvga3dSurfaceStretchBlt if the login screen and the desktop has different
105 * sizes. The context of the login screen seems to have just been destroyed
106 * earlier and I believe the driver/X/whoever is attemting to strech the old
107 * screen content onto the new sized screen.
108 *
109 * @remarks This probably comes at a slight preformance expense, as we currently
110 * switches context when setting up the surface the first time. Not sure
111 * if we really need to, but as this is an experiment, I'm playing it safe.
112 * @remarks The define has been made default, thus should no longer be used.
113 */
114# define VMSVGA3D_OGL_WITH_SHARED_CTX
115/** Fake surface ID for the shared context. */
116# define VMSVGA3D_SHARED_CTX_ID UINT32_C(0xffffeeee)
117
118/** @def VBOX_VMSVGA3D_GL_HACK_LEVEL
119 * Turns out that on Linux gl.h may often define the first 2-4 OpenGL versions
120 * worth of extensions, but missing out on a function pointer of fifteen. This
121 * causes headache for us when we use the function pointers below. This hack
122 * changes the code to call the known problematic functions directly.
123 * The value is ((x)<<16 | (y)) where x and y are taken from the GL_VERSION_x_y.
124 */
125# ifndef VBOX_VMSVGA3D_GL_HACK_LEVEL
126# define VBOX_VMSVGA3D_GL_HACK_LEVEL 0
127# endif
128
129/** Invalid OpenGL ID. */
130# define OPENGL_INVALID_ID 0
131
132# define VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState) \
133 do { (pState)->idActiveContext = OPENGL_INVALID_ID; } while (0)
134
135/** @def VMSVGA3D_SET_CURRENT_CONTEXT
136 * Makes sure the @a pContext is the active OpenGL context.
137 * @parm pState The VMSVGA3d state.
138 * @parm pContext The new context.
139 */
140# ifdef RT_OS_WINDOWS
141# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
142 do { \
143 if ((pState)->idActiveContext != (pContext)->id) \
144 { \
145 BOOL fMakeCurrentRc = wglMakeCurrent((pContext)->hdc, (pContext)->hglrc); \
146 Assert(fMakeCurrentRc == TRUE); RT_NOREF_PV(fMakeCurrentRc); \
147 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \
148 (pState)->idActiveContext = (pContext)->id; \
149 } \
150 } while (0)
151
152# elif defined(RT_OS_DARWIN)
153# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
154 do { \
155 if ((pState)->idActiveContext != (pContext)->id) \
156 { \
157 vmsvga3dCocoaViewMakeCurrentContext((pContext)->cocoaView, (pContext)->cocoaContext); \
158 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \
159 (pState)->idActiveContext = (pContext)->id; \
160 } \
161 } while (0)
162# else
163# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
164 do { \
165 if ((pState)->idActiveContext != (pContext)->id) \
166 { \
167 Bool fMakeCurrentRc = glXMakeCurrent((pState)->display, \
168 (pContext)->window, \
169 (pContext)->glxContext); \
170 Assert(fMakeCurrentRc == True); RT_NOREF_PV(fMakeCurrentRc); \
171 LogFlowFunc(("Changing context: %#x -> %#x\n", (pState)->idActiveContext, (pContext)->id)); \
172 (pState)->idActiveContext = (pContext)->id; \
173 } \
174 } while (0)
175# endif
176
177/** @def VMSVGA3D_CLEAR_GL_ERRORS
178 * Clears all pending OpenGL errors.
179 *
180 * If I understood this correctly, OpenGL maintains a bitmask internally and
181 * glGetError gets the next bit (clearing it) from the bitmap and translates it
182 * into a GL_XXX constant value which it then returns. A single OpenGL call can
183 * set more than one bit, and they stick around across calls, from what I
184 * understand.
185 *
186 * So in order to be able to use glGetError to check whether a function
187 * succeeded, we need to call glGetError until all error bits have been cleared.
188 * This macro does that (in all types of builds).
189 *
190 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS
191 */
192# define VMSVGA3D_CLEAR_GL_ERRORS() \
193 do { \
194 if (RT_UNLIKELY(glGetError() != GL_NO_ERROR)) /* predict no errors pending */ \
195 { \
196 uint32_t iErrorClearingLoopsLeft = 64; \
197 while (glGetError() != GL_NO_ERROR && iErrorClearingLoopsLeft > 0) \
198 iErrorClearingLoopsLeft--; \
199 } \
200 } while (0)
201
202/** @def VMSVGA3D_GET_LAST_GL_ERROR
203 * Gets the last OpenGL error, stores it in a_pContext->lastError and returns
204 * it.
205 *
206 * @returns Same as glGetError.
207 * @param a_pContext The context to store the error in.
208 *
209 * @sa VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
210 */
211# define VMSVGA3D_GET_GL_ERROR(a_pContext) ((a_pContext)->lastError = glGetError())
212
213/** @def VMSVGA3D_GL_SUCCESS
214 * Checks whether VMSVGA3D_GET_LAST_GL_ERROR() return GL_NO_ERROR.
215 *
216 * Will call glGetError() and store the result in a_pContext->lastError.
217 * Will predict GL_NO_ERROR outcome.
218 *
219 * @returns True on success, false on error.
220 * @parm a_pContext The context to store the error in.
221 *
222 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_COMPLAIN
223 */
224# define VMSVGA3D_GL_IS_SUCCESS(a_pContext) RT_LIKELY((((a_pContext)->lastError = glGetError()) == GL_NO_ERROR))
225
226/** @def VMSVGA3D_GL_COMPLAIN
227 * Complains about one or more OpenGL errors (first in a_pContext->lastError).
228 *
229 * Strict builds will trigger an assertion, while other builds will put the
230 * first few occurences in the release log.
231 *
232 * All GL errors will be cleared after invocation. Assumes lastError
233 * is an error, will not check for GL_NO_ERROR.
234 *
235 * @param a_pState The 3D state structure.
236 * @param a_pContext The context that holds the first error.
237 * @param a_LogRelDetails Argument list for LogRel or similar that describes
238 * the operation in greater detail.
239 *
240 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS
241 */
242# ifdef VBOX_STRICT
243# define VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \
244 do { \
245 AssertMsg((a_pState)->idActiveContext == (a_pContext)->id, \
246 ("idActiveContext=%#x id=%x\n", (a_pState)->idActiveContext, (a_pContext)->id)); \
247 RTAssertMsg2Weak a_LogRelDetails; \
248 GLenum iNextError; \
249 while ((iNextError = glGetError()) != GL_NO_ERROR) \
250 RTAssertMsg2Weak("next error: %#x\n", iNextError); \
251 AssertMsgFailed(("first error: %#x (idActiveContext=%#x)\n", (a_pContext)->lastError, (a_pContext)->id)); \
252 } while (0)
253# else
254# define VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \
255 do { \
256 LogRelMax(32, ("VMSVGA3d: OpenGL error %#x (idActiveContext=%#x) on line %u ", (a_pContext)->lastError, (a_pContext)->id, __LINE__)); \
257 GLenum iNextError; \
258 while ((iNextError = glGetError()) != GL_NO_ERROR) \
259 LogRelMax(32, (" - also error %#x ", iNextError)); \
260 LogRelMax(32, a_LogRelDetails); \
261 } while (0)
262# endif
263
264/** @def VMSVGA3D_GL_GET_AND_COMPLAIN
265 * Combination of VMSVGA3D_GET_GL_ERROR and VMSVGA3D_GL_COMPLAIN, assuming that
266 * there is a pending error.
267 *
268 * @param a_pState The 3D state structure.
269 * @param a_pContext The context that holds the first error.
270 * @param a_LogRelDetails Argument list for LogRel or similar that describes
271 * the operation in greater detail.
272 *
273 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
274 */
275# define VMSVGA3D_GL_GET_AND_COMPLAIN(a_pState, a_pContext, a_LogRelDetails) \
276 do { \
277 VMSVGA3D_GET_GL_ERROR(a_pContext); \
278 VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \
279 } while (0)
280
281/** @def VMSVGA3D_GL_ASSERT_SUCCESS
282 * Asserts that VMSVGA3D_GL_IS_SUCCESS is true, complains if not.
283 *
284 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
285 * logging in non-strict builds.
286 *
287 * @param a_pState The 3D state structure.
288 * @param a_pContext The context that holds the first error.
289 * @param a_LogRelDetails Argument list for LogRel or similar that describes
290 * the operation in greater detail.
291 *
292 * @sa VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
293 */
294# define VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails) \
295 if (VMSVGA3D_GL_IS_SUCCESS(a_pContext)) \
296 { /* likely */ } \
297 else do { \
298 VMSVGA3D_GL_COMPLAIN(a_pState, a_pContext, a_LogRelDetails); \
299 } while (0)
300
301/** @def VMSVGA3D_ASSERT_GL_CALL_EX
302 * Executes the specified OpenGL API call and asserts that it succeeded, variant
303 * with extra logging flexibility.
304 *
305 * ASSUMES no GL errors pending prior to invocation - caller should use
306 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
307 *
308 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
309 * logging in non-strict builds.
310 *
311 * @param a_GlCall Expression making an OpenGL call.
312 * @param a_pState The 3D state structure.
313 * @param a_pContext The context that holds the first error.
314 * @param a_LogRelDetails Argument list for LogRel or similar that describes
315 * the operation in greater detail.
316 *
317 * @sa VMSVGA3D_ASSERT_GL_CALL, VMSVGA3D_GL_ASSERT_SUCCESS,
318 * VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
319 */
320# define VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, a_LogRelDetails) \
321 do { \
322 (a_GlCall); \
323 VMSVGA3D_GL_ASSERT_SUCCESS(a_pState, a_pContext, a_LogRelDetails); \
324 } while (0)
325
326/** @def VMSVGA3D_ASSERT_GL_CALL
327 * Executes the specified OpenGL API call and asserts that it succeeded.
328 *
329 * ASSUMES no GL errors pending prior to invocation - caller should use
330 * VMSVGA3D_CLEAR_GL_ERRORS if uncertain.
331 *
332 * Uses VMSVGA3D_GL_COMPLAIN for complaining, so check it out wrt to release
333 * logging in non-strict builds.
334 *
335 * @param a_GlCall Expression making an OpenGL call.
336 * @param a_pState The 3D state structure.
337 * @param a_pContext The context that holds the first error.
338 *
339 * @sa VMSVGA3D_ASSERT_GL_CALL_EX, VMSVGA3D_GL_ASSERT_SUCCESS,
340 * VMSVGA3D_GET_GL_ERROR, VMSVGA3D_GL_IS_SUCCESS, VMSVGA3D_GL_COMPLAIN
341 */
342# define VMSVGA3D_ASSERT_GL_CALL(a_GlCall, a_pState, a_pContext) \
343 VMSVGA3D_ASSERT_GL_CALL_EX(a_GlCall, a_pState, a_pContext, ("%s\n", #a_GlCall))
344
345
346/** @def VMSVGA3D_CHECK_LAST_ERROR
347 * Checks that the last OpenGL error code indicates success.
348 *
349 * Will assert and return VERR_INTERNAL_ERROR in strict builds, in other
350 * builds it will do nothing and is a NOOP.
351 *
352 * @parm pState The VMSVGA3d state.
353 * @parm pContext The context.
354 *
355 * @todo Replace with proper error handling, it's crazy to return
356 * VERR_INTERNAL_ERROR in strict builds and just barge on ahead in
357 * release builds.
358 */
359/** @todo Rename to VMSVGA3D_CHECK_LAST_ERROR_RETURN */
360# ifdef VBOX_STRICT
361# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { \
362 Assert((pState)->idActiveContext == (pContext)->id); \
363 (pContext)->lastError = glGetError(); \
364 AssertMsgReturn((pContext)->lastError == GL_NO_ERROR, \
365 ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError), \
366 VERR_INTERNAL_ERROR); \
367 } while (0)
368# else
369# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do { } while (0)
370# endif
371
372/** @def VMSVGA3D_CHECK_LAST_ERROR_WARN
373 * Checks that the last OpenGL error code indicates success.
374 *
375 * Will assert in strict builds, otherwise it's a NOOP.
376 *
377 * @parm pState The VMSVGA3d state.
378 * @parm pContext The new context.
379 */
380# ifdef VBOX_STRICT
381# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { \
382 Assert((pState)->idActiveContext == (pContext)->id); \
383 (pContext)->lastError = glGetError(); \
384 AssertMsg((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError)); \
385 } while (0)
386# else
387# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do { } while (0)
388# endif
389
390#endif /* VMSVGA3D_OPENGL */
391
392#ifdef VMSVGA3D_DIRECT3D
393/* Enable to use Wine to convert D3D to opengl */
394//#define VBOX_VMSVGA3D_WITH_WINE_OPENGL
395#endif
396
397
398/*********************************************************************************************************************************
399* Structures and Typedefs *
400*********************************************************************************************************************************/
401/**
402 * Mipmap level.
403 */
404typedef struct VMSVGA3DMIPMAPLEVEL
405{
406 /** The mipmap size: width, height and depth. */
407 SVGA3dSize mipmapSize;
408 /** Width in blocks: (width + cxBlock - 1) / cxBlock. SSM: not saved, recalculated on load. */
409 uint32_t cBlocksX;
410 /** Height in blocks: (height + cyBlock - 1) / cyBlock. SSM: not saved, recalculated on load. */
411 uint32_t cBlocksY;
412 /** Number of blocks: cBlocksX * cBlocksY * mipmapSize.depth. SSM: not saved, recalculated on load. */
413 uint32_t cBlocks;
414 /** The scanline/pitch size in bytes: at least cBlocksX * cbBlock. */
415 uint32_t cbSurfacePitch;
416 /** The size (in bytes) of the mipmap plane: cbSurfacePitch * cBlocksY */
417 uint32_t cbSurfacePlane;
418 /** The size (in bytes) of the mipmap data when using the format the surface was
419 * defined with: cbSurfacePlane * mipmapSize.z */
420 uint32_t cbSurface;
421 /** Pointer to the mipmap bytes (cbSurface). Often NULL. If the surface has
422 * been realized in hardware, this may be outdated. */
423 void *pSurfaceData;
424 /** Set if pvSurfaceData contains data not realized in hardware or pushed to the
425 * hardware surface yet. */
426 bool fDirty;
427} VMSVGA3DMIPMAPLEVEL;
428/** Pointer to a mipmap level. */
429typedef VMSVGA3DMIPMAPLEVEL *PVMSVGA3DMIPMAPLEVEL;
430
431
432#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
433/**
434 * SSM descriptor table for the VMSVGA3DMIPMAPLEVEL structure.
435 */
436static SSMFIELD const g_aVMSVGA3DMIPMAPLEVELFields[] =
437{
438 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, mipmapSize),
439 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurface),
440 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurfacePitch),
441 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DMIPMAPLEVEL, pSurfaceData),
442 SSMFIELD_ENTRY_IGNORE( VMSVGA3DMIPMAPLEVEL, fDirty),
443 SSMFIELD_ENTRY_TERM()
444};
445#endif
446
447typedef struct VMSVGATRANSFORMSTATE
448{
449 bool fValid;
450 float matrix[16];
451} VMSVGATRANSFORMSTATE;
452typedef VMSVGATRANSFORMSTATE *PVMSVGATRANSFORMSTATE;
453
454typedef struct VMSVGAMATERIALSTATE
455{
456 bool fValid;
457 SVGA3dMaterial material;
458} VMSVGAMATERIALSTATE;
459typedef VMSVGAMATERIALSTATE *PVMSVGAMATERIALSTATE;
460
461typedef struct VMSVGACLIPPLANESTATE
462{
463 bool fValid;
464 float plane[4];
465} VMSVGACLIPPLANESTATE;
466typedef VMSVGACLIPPLANESTATE *PVMSVGACLIPPLANESTATE;
467
468typedef struct VMSVGALIGHTSTATE
469{
470 bool fEnabled;
471 bool fValidData;
472 SVGA3dLightData data;
473} VMSVGALIGHTSTATE;
474typedef VMSVGALIGHTSTATE *PVMSVGALIGHTSTATE;
475
476typedef struct VMSVGASHADERCONST
477{
478 bool fValid;
479 SVGA3dShaderConstType ctype;
480 uint32_t value[4];
481} VMSVGASHADERCONST;
482typedef VMSVGASHADERCONST *PVMSVGASHADERCONST;
483
484#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
485/**
486 * SSM descriptor table for the VMSVGASHADERCONST structure.
487 */
488static SSMFIELD const g_aVMSVGASHADERCONSTFields[] =
489{
490 SSMFIELD_ENTRY( VMSVGASHADERCONST, fValid),
491 SSMFIELD_ENTRY( VMSVGASHADERCONST, ctype),
492 SSMFIELD_ENTRY( VMSVGASHADERCONST, value),
493 SSMFIELD_ENTRY_TERM()
494};
495#endif
496
497#ifdef VMSVGA3D_DIRECT3D
498
499/* What kind of Direct3D resource has been created for the VMSVGA3D surface. */
500typedef enum VMSVGA3DD3DRESTYPE
501{
502 VMSVGA3D_D3DRESTYPE_NONE = 0,
503 VMSVGA3D_D3DRESTYPE_SURFACE = 1,
504 VMSVGA3D_D3DRESTYPE_TEXTURE = 2,
505 VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE = 3,
506 VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE = 4,
507 VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER = 5,
508 VMSVGA3D_D3DRESTYPE_INDEX_BUFFER = 6
509} VMSVGA3DD3DRESTYPE;
510
511/**
512 *
513 */
514typedef struct
515{
516 /** Key is context id. */
517 AVLU32NODECORE Core;
518 union
519 {
520 IDirect3DSurface9 *pSurface;
521 IDirect3DTexture9 *pTexture;
522 IDirect3DCubeTexture9 *pCubeTexture;
523 IDirect3DVolumeTexture9 *pVolumeTexture;
524 } u;
525} VMSVGA3DSHAREDSURFACE;
526typedef VMSVGA3DSHAREDSURFACE *PVMSVGA3DSHAREDSURFACE;
527#endif /* VMSVGA3D_DIRECT3D */
528
529#ifdef VMSVGA3D_OPENGL
530/* What kind of OpenGL resource has been created for the VMSVGA3D surface. */
531typedef enum VMSVGA3DOGLRESTYPE
532{
533 VMSVGA3D_OGLRESTYPE_NONE = 0,
534 VMSVGA3D_OGLRESTYPE_BUFFER = 1,
535 VMSVGA3D_OGLRESTYPE_TEXTURE = 2,
536 VMSVGA3D_OGLRESTYPE_RENDERBUFFER = 3
537} VMSVGA3DOGLRESTYPE;
538#endif
539
540/**
541 * VMSVGA3d surface.
542 */
543typedef struct VMSVGA3DSURFACE
544{
545 uint32_t id;
546#ifdef VMSVGA3D_OPENGL
547 uint32_t idWeakContextAssociation;
548#else
549 uint32_t idAssociatedContext;
550#endif
551 uint32_t surfaceFlags;
552 SVGA3dSurfaceFormat format;
553#ifdef VMSVGA3D_OPENGL
554 GLint internalFormatGL;
555 GLint formatGL;
556 GLint typeGL;
557 VMSVGA3DOGLRESTYPE enmOGLResType; /* Which resource was created for the surface. */
558 union
559 {
560 GLuint texture;
561 GLuint buffer;
562 GLuint renderbuffer;
563 } oglId;
564 GLenum targetGL; /* GL_TEXTURE_* */
565 GLenum bindingGL; /* GL_TEXTURE_BINDING_* */
566 /* Emulated formats */
567 bool fEmulated; /* Whether the texture format is emulated. */
568 GLuint idEmulated; /* GL name of the intermediate texture. */
569#endif
570 SVGA3dSurfaceFace faces[SVGA3D_MAX_SURFACE_FACES];
571 uint32_t cFaces;
572 uint32_t cMipmapLevels;
573 PVMSVGA3DMIPMAPLEVEL paMipmapLevels;
574 uint32_t multiSampleCount;
575 SVGA3dTextureFilter autogenFilter;
576#ifdef VMSVGA3D_DIRECT3D
577 D3DFORMAT formatD3D;
578 DWORD fUsageD3D;
579 D3DMULTISAMPLE_TYPE multiSampleTypeD3D;
580#endif
581
582 uint32_t cbBlock; /* block/pixel size in bytes */
583 /* Dimensions of the surface block, usually 1x1 except for compressed formats. */
584 uint32_t cxBlock; /* Block width in pixels. SSM: not saved, recalculated on load. */
585 uint32_t cyBlock; /* Block height in pixels. SSM: not saved, recalculated on load. */
586#ifdef VMSVGA3D_OPENGL
587 uint32_t cbBlockGL; /* Block size of the OpenGL texture, same as cbBlock for not-emulated formats. */
588#endif
589
590 /* Dirty state; surface was manually updated. */
591 bool fDirty;
592
593#ifdef VMSVGA3D_DIRECT3D
594 /* Handle for shared objects (currently only textures & render targets). */
595 HANDLE hSharedObject;
596 /** Event query inserted after each GPU operation that updates or uses this surface. */
597 IDirect3DQuery9 *pQuery;
598 /** The context id where the query has been created. */
599 uint32_t idQueryContext;
600 /** The type of actually created D3D resource. */
601 VMSVGA3DD3DRESTYPE enmD3DResType;
602 union
603 {
604 IDirect3DSurface9 *pSurface;
605 IDirect3DTexture9 *pTexture;
606 IDirect3DCubeTexture9 *pCubeTexture;
607 IDirect3DVolumeTexture9 *pVolumeTexture;
608 IDirect3DVertexBuffer9 *pVertexBuffer;
609 IDirect3DIndexBuffer9 *pIndexBuffer;
610 } u;
611 union
612 {
613 IDirect3DTexture9 *pTexture;
614 IDirect3DCubeTexture9 *pCubeTexture;
615 IDirect3DVolumeTexture9 *pVolumeTexture;
616 } bounce;
617 /** AVL tree containing VMSVGA3DSHAREDSURFACE structures. */
618 AVLU32TREE pSharedObjectTree;
619 bool fStencilAsTexture;
620 D3DFORMAT d3dfmtRequested;
621 union
622 {
623 IDirect3DTexture9 *pTexture;
624 IDirect3DCubeTexture9 *pCubeTexture;
625 IDirect3DVolumeTexture9 *pVolumeTexture;
626 } emulated;
627#endif
628} VMSVGA3DSURFACE;
629/** Pointer to a 3d surface. */
630typedef VMSVGA3DSURFACE *PVMSVGA3DSURFACE;
631
632#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
633/**
634 * SSM descriptor table for the VMSVGA3DSURFACE structure.
635 */
636static SSMFIELD const g_aVMSVGA3DSURFACEFields[] =
637{
638 SSMFIELD_ENTRY( VMSVGA3DSURFACE, id),
639# ifdef VMSVGA3D_OPENGL
640 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idWeakContextAssociation),
641# else
642 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext),
643# endif
644 SSMFIELD_ENTRY( VMSVGA3DSURFACE, surfaceFlags),
645 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format),
646# ifdef VMSVGA3D_OPENGL
647 SSMFIELD_ENTRY( VMSVGA3DSURFACE, internalFormatGL),
648 SSMFIELD_ENTRY( VMSVGA3DSURFACE, formatGL),
649 SSMFIELD_ENTRY( VMSVGA3DSURFACE, typeGL),
650 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, id),
651# endif
652 SSMFIELD_ENTRY( VMSVGA3DSURFACE, faces),
653 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cFaces),
654 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, paMipmapLevels),
655 SSMFIELD_ENTRY( VMSVGA3DSURFACE, multiSampleCount),
656 SSMFIELD_ENTRY( VMSVGA3DSURFACE, autogenFilter),
657# ifdef VMSVGA3D_DIRECT3D
658 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format), /** @todo format duplicated. */
659 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, formatD3D),
660 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fUsageD3D),
661 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, multiSampleTypeD3D),
662# endif
663 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cbBlock),
664 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fDirty),
665# ifdef VMSVGA3D_DIRECT3D
666 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, hSharedObject),
667 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, pQuery),
668 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, u.pSurface),
669 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSURFACE, bounce.pTexture),
670 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, pSharedObjectTree),
671 SSMFIELD_ENTRY_IGNORE( VMSVGA3DSURFACE, fStencilAsTexture),
672# endif
673 SSMFIELD_ENTRY_TERM()
674};
675#endif
676
677/** Mask we frequently apply to VMSVGA3DSURFACE::flags for decing what kind
678 * of surface we're dealing. */
679#define VMSVGA3D_SURFACE_HINT_SWITCH_MASK \
680 ( SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER \
681 | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET \
682 | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP )
683
684/** @def VMSVGA3DSURFACE_HAS_HW_SURFACE
685 * Checks whether the surface has a host hardware/library surface.
686 * @returns true/false
687 * @param a_pSurface The VMSVGA3d surface.
688 */
689#ifdef VMSVGA3D_DIRECT3D
690# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->u.pSurface != NULL)
691#else
692# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->oglId.texture != OPENGL_INVALID_ID)
693#endif
694
695/** @def VMSVGA3DSURFACE_NEEDS_DATA
696 * Checks whether SurfaceDMA transfers must always update pSurfaceData,
697 * even if the surface has a host hardware resource.
698 * @returns true/false
699 * @param a_pSurface The VMSVGA3d surface.
700 */
701#ifdef VMSVGA3D_DIRECT3D
702# define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) \
703 ( (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER \
704 || (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_INDEX_BUFFER)
705#else
706# define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) \
707 ((a_pSurface)->enmOGLResType == VMSVGA3D_OGLRESTYPE_BUFFER)
708#endif
709
710
711typedef struct VMSVGA3DSHADER
712{
713 uint32_t id;
714 uint32_t cid;
715 SVGA3dShaderType type;
716 uint32_t cbData;
717 void *pShaderProgram;
718 union
719 {
720#ifdef VMSVGA3D_DIRECT3D
721 IDirect3DVertexShader9 *pVertexShader;
722 IDirect3DPixelShader9 *pPixelShader;
723#else
724 void *pVertexShader;
725 void *pPixelShader;
726#endif
727 void *pv;
728 } u;
729} VMSVGA3DSHADER;
730typedef VMSVGA3DSHADER *PVMSVGA3DSHADER;
731
732#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
733/**
734 * SSM descriptor table for the VMSVGA3DSHADER structure.
735 */
736static SSMFIELD const g_aVMSVGA3DSHADERFields[] =
737{
738 SSMFIELD_ENTRY( VMSVGA3DSHADER, id),
739 SSMFIELD_ENTRY( VMSVGA3DSHADER, cid),
740 SSMFIELD_ENTRY( VMSVGA3DSHADER, type),
741 SSMFIELD_ENTRY( VMSVGA3DSHADER, cbData),
742 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, pShaderProgram),
743 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, u.pv),
744 SSMFIELD_ENTRY_TERM()
745};
746#endif
747
748/** @name VMSVGA3D_UPDATE_XXX - ...
749 * @{ */
750#define VMSVGA3D_UPDATE_SCISSORRECT RT_BIT_32(0)
751#define VMSVGA3D_UPDATE_ZRANGE RT_BIT_32(1)
752#define VMSVGA3D_UPDATE_VIEWPORT RT_BIT_32(2)
753#define VMSVGA3D_UPDATE_VERTEXSHADER RT_BIT_32(3)
754#define VMSVGA3D_UPDATE_PIXELSHADER RT_BIT_32(4)
755#define VMSVGA3D_UPDATE_TRANSFORM RT_BIT_32(5)
756#define VMSVGA3D_UPDATE_MATERIAL RT_BIT_32(6)
757/** @} */
758
759/* Query states. Mostly used for saved state. */
760typedef enum VMSVGA3DQUERYSTATE
761{
762 VMSVGA3DQUERYSTATE_NULL = 0, /* Not created. */
763 VMSVGA3DQUERYSTATE_SIGNALED = 1, /* Result obtained. The guest may or may not read the result yet. */
764 VMSVGA3DQUERYSTATE_BUILDING = 2, /* In process of collecting data. */
765 VMSVGA3DQUERYSTATE_ISSUED = 3, /* Data collected, but result is not yet obtained. */
766 VMSVGA3DQUERYSTATE_32BIT = 0x7fffffff
767} VMSVGA3DQUERYSTATE;
768AssertCompileSize(VMSVGA3DQUERYSTATE, sizeof(uint32_t));
769
770typedef struct VMSVGA3DQUERY
771{
772#ifdef VMSVGA3D_DIRECT3D
773 IDirect3DQuery9 *pQuery;
774#else /* VMSVGA3D_OPENGL */
775 GLuint idQuery;
776#endif
777 VMSVGA3DQUERYSTATE enmQueryState; /* VMSVGA3DQUERYSTATE_*. State is implicitly _NULL if pQuery is NULL. */
778 uint32_t u32QueryResult; /* Generic result. Enough for all VGPU9 queries. */
779} VMSVGA3DQUERY;
780
781#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
782/**
783 * SSM descriptor table for the VMSVGA3DQUERY structure.
784 */
785static SSMFIELD const g_aVMSVGA3DQUERYFields[] =
786{
787#ifdef VMSVGA3D_DIRECT3D
788 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DQUERY, pQuery),
789#else /* VMSVGA3D_OPENGL */
790 SSMFIELD_ENTRY_IGNORE( VMSVGA3DQUERY, idQuery),
791#endif
792 SSMFIELD_ENTRY( VMSVGA3DQUERY, enmQueryState),
793 SSMFIELD_ENTRY( VMSVGA3DQUERY, u32QueryResult),
794 SSMFIELD_ENTRY_TERM()
795};
796#endif
797
798#ifdef VMSVGA3D_DIRECT3D
799#define VMSVGA3DQUERY_EXISTS(p) ((p)->pQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)
800#else
801#define VMSVGA3DQUERY_EXISTS(p) ((p)->idQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)
802#endif
803
804/**
805 * VMSVGA3d context.
806 */
807typedef struct VMSVGA3DCONTEXT
808{
809 uint32_t id;
810#ifdef RT_OS_WINDOWS
811# ifdef VMSVGA3D_DIRECT3D
812# ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
813 IDirect3DDevice9 *pDevice;
814# else
815 IDirect3DDevice9Ex *pDevice;
816# endif
817# else
818 /* Device context of the context window. */
819 HDC hdc;
820 /* OpenGL rendering context handle. */
821 HGLRC hglrc;
822# endif
823 /* Device context window handle. */
824 HWND hwnd;
825#elif defined(RT_OS_DARWIN)
826 /* OpenGL rendering context */
827 NativeNSOpenGLContextRef cocoaContext;
828 NativeNSViewRef cocoaView;
829 bool fOtherProfile;
830#else
831 /** XGL rendering context handle */
832 GLXContext glxContext;
833 /** Device context window handle */
834 Window window;
835#endif
836
837#ifdef VMSVGA3D_OPENGL
838 /* Framebuffer object associated with this context. */
839 GLuint idFramebuffer;
840 /* Read and draw framebuffer objects for various operations. */
841 GLuint idReadFramebuffer;
842 GLuint idDrawFramebuffer;
843 /* Last GL error recorded. */
844 GLenum lastError;
845 void *pShaderContext;
846#endif
847
848 /* Current selected texture surfaces (if any) */
849 uint32_t aSidActiveTextures[SVGA3D_MAX_SAMPLERS];
850 /* Per context pixel and vertex shaders. */
851 uint32_t cPixelShaders;
852 PVMSVGA3DSHADER paPixelShader;
853 uint32_t cVertexShaders;
854 PVMSVGA3DSHADER paVertexShader;
855 /* Keep track of the internal state to be able to recreate the context properly (save/restore, window resize). */
856 struct
857 {
858 /** VMSVGA3D_UPDATE_XXX */
859 uint32_t u32UpdateFlags;
860
861 SVGA3dRenderState aRenderState[SVGA3D_RS_MAX];
862 /* aTextureStates contains both TextureStageStates and SamplerStates, therefore [SVGA3D_MAX_SAMPLERS]. */
863 SVGA3dTextureState aTextureStates[SVGA3D_MAX_SAMPLERS][SVGA3D_TS_MAX];
864 VMSVGATRANSFORMSTATE aTransformState[SVGA3D_TRANSFORM_MAX];
865 VMSVGAMATERIALSTATE aMaterial[SVGA3D_FACE_MAX];
866 VMSVGACLIPPLANESTATE aClipPlane[SVGA3D_CLIPPLANE_MAX];
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
1171
1172#ifdef VMSVGA3D_DIRECT3D
1173D3DFORMAT vmsvga3dSurfaceFormat2D3D(SVGA3dSurfaceFormat format);
1174D3DMULTISAMPLE_TYPE vmsvga3dMultipeSampleCount2D3D(uint32_t multisampleCount);
1175DECLCALLBACK(int) vmsvga3dSharedSurfaceDestroyTree(PAVLU32NODECORE pNode, void *pvParam);
1176int vmsvga3dSurfaceFlush(PVMSVGA3DSURFACE pSurface);
1177#endif /* VMSVGA3D_DIRECT3D */
1178
1179
1180#ifdef VMSVGA3D_OPENGL
1181/** Save and setup everything. */
1182# define VMSVGA3D_PARANOID_TEXTURE_PACKING
1183
1184/** @name VMSVGAPACKPARAMS_* - which packing parameters were set.
1185 * @{ */
1186# define VMSVGAPACKPARAMS_ALIGNMENT RT_BIT_32(0)
1187# define VMSVGAPACKPARAMS_ROW_LENGTH RT_BIT_32(1)
1188# define VMSVGAPACKPARAMS_IMAGE_HEIGHT RT_BIT_32(2)
1189# define VMSVGAPACKPARAMS_SWAP_BYTES RT_BIT_32(3)
1190# define VMSVGAPACKPARAMS_LSB_FIRST RT_BIT_32(4)
1191# define VMSVGAPACKPARAMS_SKIP_ROWS RT_BIT_32(5)
1192# define VMSVGAPACKPARAMS_SKIP_PIXELS RT_BIT_32(6)
1193# define VMSVGAPACKPARAMS_SKIP_IMAGES RT_BIT_32(7)
1194/** @} */
1195
1196/**
1197 * Saved texture packing parameters (shared by both pack and unpack).
1198 */
1199typedef struct VMSVGAPACKPARAMS
1200{
1201 uint32_t fChanged;
1202 GLint iAlignment;
1203 GLint cxRow;
1204 GLint cyImage;
1205# ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
1206 GLboolean fSwapBytes;
1207 GLboolean fLsbFirst;
1208 GLint cSkipRows;
1209 GLint cSkipPixels;
1210 GLint cSkipImages;
1211# endif
1212} VMSVGAPACKPARAMS;
1213/** Pointer to saved texture packing parameters. */
1214typedef VMSVGAPACKPARAMS *PVMSVGAPACKPARAMS;
1215/** Pointer to const saved texture packing parameters. */
1216typedef VMSVGAPACKPARAMS const *PCVMSVGAPACKPARAMS;
1217
1218void vmsvga3dOglSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1219 PVMSVGAPACKPARAMS pSave);
1220void vmsvga3dOglRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1221 PCVMSVGAPACKPARAMS pSave);
1222void vmsvga3dOglSetUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, GLint cxRow, GLint cyImage,
1223 PVMSVGAPACKPARAMS pSave);
1224void vmsvga3dOglRestoreUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext,
1225 PCVMSVGAPACKPARAMS pSave);
1226
1227/** @name VMSVGA3D_DEF_CTX_F_XXX - vmsvga3dContextDefineOgl flags.
1228 * @{ */
1229/** When clear, the context is created using the default OpenGL profile.
1230 * When set, it's created using the alternative profile. The latter is only
1231 * allowed if the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set. */
1232# define VMSVGA3D_DEF_CTX_F_OTHER_PROFILE RT_BIT_32(0)
1233/** Defining the shared context. */
1234# define VMSVGA3D_DEF_CTX_F_SHARED_CTX RT_BIT_32(1)
1235/** Defining the init time context (EMT). */
1236# define VMSVGA3D_DEF_CTX_F_INIT RT_BIT_32(2)
1237/** @} */
1238int vmsvga3dContextDefineOgl(PVGASTATECC pThisCC, uint32_t cid, uint32_t fFlags);
1239void vmsvga3dSurfaceFormat2OGL(PVMSVGA3DSURFACE pSurface, SVGA3dSurfaceFormat format);
1240
1241#endif /* VMSVGA3D_OPENGL */
1242
1243
1244/* DevVGA-SVGA3d-shared.cpp: */
1245int vmsvga3dSaveShaderConst(PVMSVGA3DCONTEXT pContext, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype,
1246 uint32_t val1, uint32_t val2, uint32_t val3, uint32_t val4);
1247
1248
1249
1250/* Command implementation workers. */
1251void vmsvga3dBackSurfaceDestroy(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface);
1252int vmsvga3dBackSurfaceStretchBlt(PVGASTATE pThis, PVMSVGA3DSTATE pState,
1253 PVMSVGA3DSURFACE pDstSurface, uint32_t uDstFace, uint32_t uDstMipmap, SVGA3dBox const *pDstBox,
1254 PVMSVGA3DSURFACE pSrcSurface, uint32_t uSrcFace, uint32_t uSrcMipmap, SVGA3dBox const *pSrcBox,
1255 SVGA3dStretchBltMode enmMode, PVMSVGA3DCONTEXT pContext);
1256int vmsvga3dBackSurfaceDMACopyBox(PVGASTATE pThis, PVGASTATECC pThisCC, PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface,
1257 PVMSVGA3DMIPMAPLEVEL pMipLevel, uint32_t uHostFace, uint32_t uHostMipmap,
1258 SVGAGuestPtr GuestPtr, uint32_t cbGuestPitch, SVGA3dTransferType transfer,
1259 SVGA3dCopyBox const *pBox, PVMSVGA3DCONTEXT pContext, int rc, int iBox);
1260
1261int vmsvga3dBackCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext,
1262 PVMSVGA3DSURFACE pSurface);
1263
1264DECLINLINE(int) vmsvga3dContextFromCid(PVMSVGA3DSTATE pState, uint32_t cid, PVMSVGA3DCONTEXT *ppContext)
1265{
1266 AssertReturn(cid < pState->cContexts, VERR_INVALID_PARAMETER);
1267 PVMSVGA3DCONTEXT const pContext = pState->papContexts[cid];
1268 if (RT_LIKELY(pContext && pContext->id == cid))
1269 {
1270 *ppContext = pContext;
1271 return VINF_SUCCESS;
1272 }
1273 LogRelMax(64, ("VMSVGA: unknown cid=%u (%s cid=%u)\n", cid, pContext ? "expected" : "null", pContext ? pContext->id : -1));
1274 return VERR_INVALID_PARAMETER;
1275}
1276
1277DECLINLINE(int) vmsvga3dSurfaceFromSid(PVMSVGA3DSTATE pState, uint32_t sid, PVMSVGA3DSURFACE *ppSurface)
1278{
1279 AssertReturn(sid < pState->cSurfaces, VERR_INVALID_PARAMETER);
1280 PVMSVGA3DSURFACE const pSurface = pState->papSurfaces[sid];
1281 if (RT_LIKELY(pSurface && pSurface->id == sid))
1282 {
1283 *ppSurface = pSurface;
1284 return VINF_SUCCESS;
1285 }
1286 LogRelMax(64, ("VMSVGA: unknown sid=%u (%s sid=%u)\n", sid, pSurface ? "expected" : "null", pSurface ? pSurface->id : -1));
1287 return VERR_INVALID_PARAMETER;
1288}
1289
1290DECLINLINE(int) vmsvga3dMipmapLevel(PVMSVGA3DSURFACE pSurface, uint32_t face, uint32_t mipmap,
1291 PVMSVGA3DMIPMAPLEVEL *ppMipmapLevel)
1292{
1293 /* Can use faces[0].numMipLevels, because numMipLevels is the same for all faces. */
1294 const uint32_t numMipLevels = pSurface->faces[0].numMipLevels;
1295
1296 AssertMsgReturn(face < pSurface->cFaces,
1297 ("cFaces %d, face %d\n", pSurface->cFaces, face),
1298 VERR_INVALID_PARAMETER);
1299 AssertMsgReturn(mipmap < numMipLevels,
1300 ("numMipLevels %d, mipmap %d", numMipLevels, mipmap),
1301 VERR_INVALID_PARAMETER);
1302
1303 *ppMipmapLevel = &pSurface->paMipmapLevels[face * numMipLevels + mipmap];
1304 return VINF_SUCCESS;
1305}
1306
1307#ifdef VMSVGA3D_DIRECT3D
1308DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
1309{
1310 D3DCUBEMAP_FACES Face;
1311 switch (iFace)
1312 {
1313 case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break;
1314 case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break;
1315 case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break;
1316 case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break;
1317 case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break;
1318 default:
1319 case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break;
1320 }
1321 return Face;
1322}
1323#else /* VMSVGA3D_OPENGL */
1324DECLINLINE(GLenum) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
1325{
1326 GLint Face;
1327 switch (iFace)
1328 {
1329 case 0: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; break;
1330 case 1: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; break;
1331 case 2: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; break;
1332 case 3: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; break;
1333 case 4: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; break;
1334 default:
1335 case 5: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; break;
1336 }
1337 return Face;
1338}
1339#endif
1340
1341int vmsvga3dOcclusionQueryCreate(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1342int vmsvga3dOcclusionQueryDelete(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1343int vmsvga3dOcclusionQueryBegin(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1344int vmsvga3dOcclusionQueryEnd(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext);
1345int vmsvga3dOcclusionQueryGetData(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t *pu32Pixels);
1346
1347void vmsvga3dInfoSurfaceToBitmap(PCDBGFINFOHLP pHlp, PVMSVGA3DSURFACE pSurface,
1348 const char *pszPath, const char *pszNamePrefix, const char *pszNameSuffix);
1349
1350#ifdef VMSVGA3D_DIRECT3D
1351#define D3D_RELEASE(ptr) do { \
1352 if (ptr) \
1353 { \
1354 (ptr)->Release(); \
1355 (ptr) = 0; \
1356 } \
1357} while (0)
1358
1359HRESULT D3D9UpdateTexture(PVMSVGA3DCONTEXT pContext,
1360 PVMSVGA3DSURFACE pSurface);
1361HRESULT D3D9GetRenderTargetData(PVMSVGA3DCONTEXT pContext,
1362 PVMSVGA3DSURFACE pSurface,
1363 uint32_t uFace,
1364 uint32_t uMipmap);
1365HRESULT D3D9GetSurfaceLevel(PVMSVGA3DSURFACE pSurface,
1366 uint32_t uFace,
1367 uint32_t uMipmap,
1368 bool fBounce,
1369 IDirect3DSurface9 **ppD3DSurface);
1370D3DFORMAT D3D9GetActualFormat(PVMSVGA3DSTATE pState,
1371 D3DFORMAT d3dfmt);
1372bool D3D9CheckDeviceFormat(IDirect3D9 *pD3D9,
1373 DWORD Usage,
1374 D3DRESOURCETYPE RType,
1375 D3DFORMAT CheckFormat);
1376#endif
1377
1378#ifdef VMSVGA3D_OPENGL
1379void vmsvga3dOnSharedContextDefine(PVMSVGA3DSTATE pState);
1380void vmsvga3dOnSharedContextDestroy(PVMSVGA3DSTATE pState);
1381
1382DECLINLINE(GLuint) GLTextureId(PVMSVGA3DSURFACE pSurface)
1383{
1384 return pSurface->fEmulated ? pSurface->idEmulated : pSurface->oglId.texture;
1385}
1386
1387void FormatConvUpdateTexture(PVMSVGA3DSTATE pState,
1388 PVMSVGA3DCONTEXT pCurrentContext,
1389 PVMSVGA3DSURFACE pSurface,
1390 uint32_t iMipmap);
1391void FormatConvReadTexture(PVMSVGA3DSTATE pState,
1392 PVMSVGA3DCONTEXT pCurrentContext,
1393 PVMSVGA3DSURFACE pSurface,
1394 uint32_t iMipmap);
1395#endif
1396
1397#endif /* !VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h */
1398
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use