VirtualBox

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

Last change on this file since 94681 was 94401, checked in by vboxsync, 3 years ago

Devices/Graphics: fixed loading a legacy saved state

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