VirtualBox

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

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

Devices/Graphics: Build new and old 3D backend. bugref:9830

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 57.7 KB
Line 
1/* $Id: DevVGA-SVGA3d-internal.h 89163 2021-05-19 13:12:44Z vboxsync $ */
2/** @file
3 * DevVMWare - VMWare SVGA device - 3D part, internal header.
4 */
5
6/*
7 * Copyright (C) 2013-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h
19#define VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/*
25 * Assert sane compilation environment.
26 */
27#ifndef IN_RING3
28# error "VMSVGA3D_INCL_INTERNALS is only for ring-3 code"
29#endif
30#ifdef VMSVGA3D_OPENGL
31# 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#ifdef VMSVGA3D_DIRECT3D
396/* Enable to use Wine to convert D3D to opengl */
397//#define VBOX_VMSVGA3D_WITH_WINE_OPENGL
398#endif
399
400
401/*********************************************************************************************************************************
402* Structures and Typedefs *
403*********************************************************************************************************************************/
404/**
405 * Mipmap level.
406 */
407typedef struct VMSVGA3DMIPMAPLEVEL
408{
409 /** The mipmap size: width, height and depth. */
410 SVGA3dSize mipmapSize;
411 /** Width in blocks: (width + cxBlock - 1) / cxBlock. SSM: not saved, recalculated on load. */
412 uint32_t cBlocksX;
413 /** Height in blocks: (height + cyBlock - 1) / cyBlock. SSM: not saved, recalculated on load. */
414 uint32_t cBlocksY;
415 /** Number of blocks: cBlocksX * cBlocksY * mipmapSize.depth. SSM: not saved, recalculated on load. */
416 uint32_t cBlocks;
417 /** The scanline/pitch size in bytes: at least cBlocksX * cbBlock. */
418 uint32_t cbSurfacePitch;
419 /** The size (in bytes) of the mipmap plane: cbSurfacePitch * cBlocksY */
420 uint32_t cbSurfacePlane;
421 /** The size (in bytes) of the mipmap data when using the format the surface was
422 * defined with: cbSurfacePlane * mipmapSize.z */
423 uint32_t cbSurface;
424 /** Pointer to the mipmap bytes (cbSurface). Often NULL. If the surface has
425 * been realized in hardware, this may be outdated. */
426 void *pSurfaceData;
427 /** Set if pvSurfaceData contains data not realized in hardware or pushed to the
428 * hardware surface yet. */
429 bool fDirty;
430} VMSVGA3DMIPMAPLEVEL;
431/** Pointer to a mipmap level. */
432typedef VMSVGA3DMIPMAPLEVEL *PVMSVGA3DMIPMAPLEVEL;
433
434
435#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
436/**
437 * SSM descriptor table for the VMSVGA3DMIPMAPLEVEL structure.
438 */
439static SSMFIELD const g_aVMSVGA3DMIPMAPLEVELFields[] =
440{
441 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, mipmapSize),
442 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurface),
443 SSMFIELD_ENTRY( VMSVGA3DMIPMAPLEVEL, cbSurfacePitch),
444 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DMIPMAPLEVEL, pSurfaceData),
445 SSMFIELD_ENTRY_IGNORE( VMSVGA3DMIPMAPLEVEL, fDirty),
446 SSMFIELD_ENTRY_TERM()
447};
448#endif
449
450typedef struct VMSVGATRANSFORMSTATE
451{
452 bool fValid;
453 float matrix[16];
454} VMSVGATRANSFORMSTATE;
455typedef VMSVGATRANSFORMSTATE *PVMSVGATRANSFORMSTATE;
456
457typedef struct VMSVGAMATERIALSTATE
458{
459 bool fValid;
460 SVGA3dMaterial material;
461} VMSVGAMATERIALSTATE;
462typedef VMSVGAMATERIALSTATE *PVMSVGAMATERIALSTATE;
463
464typedef struct VMSVGACLIPPLANESTATE
465{
466 bool fValid;
467 float plane[4];
468} VMSVGACLIPPLANESTATE;
469typedef VMSVGACLIPPLANESTATE *PVMSVGACLIPPLANESTATE;
470
471typedef struct VMSVGALIGHTSTATE
472{
473 bool fEnabled;
474 bool fValidData;
475 SVGA3dLightData data;
476} VMSVGALIGHTSTATE;
477typedef VMSVGALIGHTSTATE *PVMSVGALIGHTSTATE;
478
479typedef struct VMSVGASHADERCONST
480{
481 bool fValid;
482 SVGA3dShaderConstType ctype;
483 uint32_t value[4];
484} VMSVGASHADERCONST;
485typedef VMSVGASHADERCONST *PVMSVGASHADERCONST;
486
487#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
488/**
489 * SSM descriptor table for the VMSVGASHADERCONST structure.
490 */
491static SSMFIELD const g_aVMSVGASHADERCONSTFields[] =
492{
493 SSMFIELD_ENTRY( VMSVGASHADERCONST, fValid),
494 SSMFIELD_ENTRY( VMSVGASHADERCONST, ctype),
495 SSMFIELD_ENTRY( VMSVGASHADERCONST, value),
496 SSMFIELD_ENTRY_TERM()
497};
498#endif
499
500#ifdef VMSVGA3D_DIRECT3D
501
502/* What kind of Direct3D resource has been created for the VMSVGA3D surface. */
503typedef enum VMSVGA3DD3DRESTYPE
504{
505 VMSVGA3D_D3DRESTYPE_NONE = 0,
506 VMSVGA3D_D3DRESTYPE_SURFACE = 1,
507 VMSVGA3D_D3DRESTYPE_TEXTURE = 2,
508 VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE = 3,
509 VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE = 4,
510 VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER = 5,
511 VMSVGA3D_D3DRESTYPE_INDEX_BUFFER = 6
512} VMSVGA3DD3DRESTYPE;
513
514/**
515 *
516 */
517typedef struct
518{
519 /** Key is context id. */
520 AVLU32NODECORE Core;
521 union
522 {
523 IDirect3DTexture9 *pTexture;
524 IDirect3DCubeTexture9 *pCubeTexture;
525 IDirect3DVolumeTexture9 *pVolumeTexture;
526 } u;
527} VMSVGA3DSHAREDSURFACE;
528typedef VMSVGA3DSHAREDSURFACE *PVMSVGA3DSHAREDSURFACE;
529#endif /* VMSVGA3D_DIRECT3D */
530
531#ifdef VMSVGA3D_OPENGL
532/* What kind of OpenGL resource has been created for the VMSVGA3D surface. */
533typedef enum VMSVGA3DOGLRESTYPE
534{
535 VMSVGA3D_OGLRESTYPE_NONE = 0,
536 VMSVGA3D_OGLRESTYPE_BUFFER = 1,
537 VMSVGA3D_OGLRESTYPE_TEXTURE = 2,
538 VMSVGA3D_OGLRESTYPE_RENDERBUFFER = 3
539} VMSVGA3DOGLRESTYPE;
540#endif
541
542/* The 3D backend surface. The actual structure is 3D API specific. */
543typedef struct VMSVGA3DBACKENDSURFACE *PVMSVGA3DBACKENDSURFACE;
544
545/**
546 * VMSVGA3d surface.
547 */
548typedef struct VMSVGA3DSURFACE
549{
550 PVMSVGA3DBACKENDSURFACE pBackendSurface;
551
552 uint32_t id; /** @todo sid */
553 /* Which context created the corresponding resource.
554 * SVGA_ID_INVALID means that resource has not been created yet, or has been created by the shared context.
555 * A resource has been created if VMSVGA3DSURFACE_HAS_HW_SURFACE is true.
556 *
557 */
558 uint32_t idAssociatedContext;
559
560 SVGA3dSurface1Flags surfaceFlags; /** @todo SVGA3dSurfaceAllFlags as an union. */
561 SVGA3dSurfaceFormat format;
562#ifdef VMSVGA3D_OPENGL
563 GLint internalFormatGL;
564 GLint formatGL;
565 GLint typeGL;
566 VMSVGA3DOGLRESTYPE enmOGLResType; /* Which resource was created for the surface. */
567 union
568 {
569 GLuint texture;
570 GLuint buffer;
571 GLuint renderbuffer;
572 } oglId;
573 GLenum targetGL; /* GL_TEXTURE_* */
574 GLenum bindingGL; /* GL_TEXTURE_BINDING_* */
575 /* Emulated formats */
576 bool fEmulated; /* Whether the texture format is emulated. */
577 GLuint idEmulated; /* GL name of the intermediate texture. */
578#endif
579 uint32_t cFaces; /* Number of faces: 6 for cubemaps, 1 for everything else. */
580 uint32_t cLevels; /* Number of mipmap levels per face. */
581 PVMSVGA3DMIPMAPLEVEL paMipmapLevels; /* cFaces * cLevels elements. */
582 uint32_t multiSampleCount;
583 SVGA3dTextureFilter autogenFilter;
584#ifdef VMSVGA3D_DIRECT3D
585 D3DFORMAT formatD3D;
586 DWORD fUsageD3D;
587 D3DMULTISAMPLE_TYPE multiSampleTypeD3D;
588#endif
589
590 uint32_t cbBlock; /* block/pixel size in bytes */
591 /* Dimensions of the surface block, usually 1x1 except for compressed formats. */
592 uint32_t cxBlock; /* Block width in pixels. SSM: not saved, recalculated on load. */
593 uint32_t cyBlock; /* Block height in pixels. SSM: not saved, recalculated on load. */
594#ifdef VMSVGA3D_OPENGL
595 uint32_t cbBlockGL; /* Block size of the OpenGL texture, same as cbBlock for not-emulated formats. */
596#endif
597
598 /* Dirty state; surface was manually updated. */
599 bool fDirty;
600
601#ifdef VMSVGA3D_DIRECT3D
602 /* Handle for shared objects (currently only textures & render targets). */
603 HANDLE hSharedObject;
604 /** Event query inserted after each GPU operation that updates or uses this surface. */
605 IDirect3DQuery9 *pQuery;
606 /** The context id where the query has been created. */
607 uint32_t idQueryContext;
608 /** The type of actually created D3D resource. */
609 VMSVGA3DD3DRESTYPE enmD3DResType;
610 union
611 {
612 IDirect3DSurface9 *pSurface;
613 IDirect3DTexture9 *pTexture;
614 IDirect3DCubeTexture9 *pCubeTexture;
615 IDirect3DVolumeTexture9 *pVolumeTexture;
616 IDirect3DVertexBuffer9 *pVertexBuffer;
617 IDirect3DIndexBuffer9 *pIndexBuffer;
618 } u;
619 union
620 {
621 IDirect3DTexture9 *pTexture;
622 IDirect3DCubeTexture9 *pCubeTexture;
623 IDirect3DVolumeTexture9 *pVolumeTexture;
624 } bounce;
625 /** AVL tree containing VMSVGA3DSHAREDSURFACE structures. */
626 AVLU32TREE pSharedObjectTree;
627 bool fStencilAsTexture;
628 D3DFORMAT d3dfmtRequested;
629 union
630 {
631 IDirect3DTexture9 *pTexture;
632 IDirect3DCubeTexture9 *pCubeTexture;
633 IDirect3DVolumeTexture9 *pVolumeTexture;
634 } emulated;
635#endif
636} VMSVGA3DSURFACE;
637/** Pointer to a 3d surface. */
638typedef VMSVGA3DSURFACE *PVMSVGA3DSURFACE;
639
640#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
641/**
642 * SSM descriptor table for the VMSVGA3DSURFACE structure.
643 */
644static SSMFIELD const g_aVMSVGA3DSURFACEFields[] =
645{
646 SSMFIELD_ENTRY( VMSVGA3DSURFACE, id),
647 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext),
648 SSMFIELD_ENTRY( VMSVGA3DSURFACE, surfaceFlags),
649 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format),
650# ifdef VMSVGA3D_OPENGL
651 SSMFIELD_ENTRY( VMSVGA3DSURFACE, internalFormatGL),
652 SSMFIELD_ENTRY( VMSVGA3DSURFACE, formatGL),
653 SSMFIELD_ENTRY( VMSVGA3DSURFACE, typeGL),
654# endif
655 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cFaces),
656 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cLevels),
657 SSMFIELD_ENTRY( VMSVGA3DSURFACE, multiSampleCount),
658 SSMFIELD_ENTRY( VMSVGA3DSURFACE, autogenFilter),
659 SSMFIELD_ENTRY( VMSVGA3DSURFACE, cbBlock),
660 SSMFIELD_ENTRY_TERM()
661};
662#endif
663
664/** Mask we frequently apply to VMSVGA3DSURFACE::flags for decing what kind
665 * of surface we're dealing. */
666#define VMSVGA3D_SURFACE_HINT_SWITCH_MASK \
667 ( SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER \
668 | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET \
669 | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP )
670
671/** @def VMSVGA3DSURFACE_HAS_HW_SURFACE
672 * Checks whether the surface has a host hardware/library surface.
673 * @returns true/false
674 * @param a_pSurface The VMSVGA3d surface.
675 */
676#ifdef VMSVGA3D_DIRECT3D
677# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->pBackendSurface != NULL || (a_pSurface)->u.pSurface != NULL)
678#else
679# define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->pBackendSurface != NULL || (a_pSurface)->oglId.texture != OPENGL_INVALID_ID)
680#endif
681
682/** @def VMSVGA3DSURFACE_NEEDS_DATA
683 * Checks whether SurfaceDMA transfers must always update pSurfaceData,
684 * even if the surface has a host hardware resource.
685 * @returns true/false
686 * @param a_pSurface The VMSVGA3d surface.
687 */
688#ifdef VMSVGA3D_DIRECT3D
689# define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) \
690 ( (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER \
691 || (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_INDEX_BUFFER)
692#else
693# define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) \
694 ((a_pSurface)->enmOGLResType == VMSVGA3D_OGLRESTYPE_BUFFER)
695#endif
696
697
698typedef struct VMSVGA3DSHADER
699{
700 uint32_t id; /** @todo Rename to shid. */
701 uint32_t cid;
702 SVGA3dShaderType type;
703 uint32_t cbData;
704 void *pShaderProgram;
705 union
706 {
707#ifdef VMSVGA3D_DIRECT3D
708 IDirect3DVertexShader9 *pVertexShader;
709 IDirect3DPixelShader9 *pPixelShader;
710#else
711 void *pVertexShader;
712 void *pPixelShader;
713#endif
714 void *pvBackendShader;
715 } u;
716#ifdef VMSVGA3D_DX
717 DXShaderInfo shaderInfo;
718#endif
719} VMSVGA3DSHADER;
720typedef VMSVGA3DSHADER *PVMSVGA3DSHADER;
721
722#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
723/**
724 * SSM descriptor table for the VMSVGA3DSHADER structure.
725 */
726static SSMFIELD const g_aVMSVGA3DSHADERFields[] =
727{
728 SSMFIELD_ENTRY( VMSVGA3DSHADER, id),
729 SSMFIELD_ENTRY( VMSVGA3DSHADER, cid),
730 SSMFIELD_ENTRY( VMSVGA3DSHADER, type),
731 SSMFIELD_ENTRY( VMSVGA3DSHADER, cbData),
732 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, pShaderProgram),
733 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, u.pvBackendShader),
734 SSMFIELD_ENTRY_TERM()
735};
736#endif
737
738/** @name VMSVGA3D_UPDATE_XXX - ...
739 * @{ */
740#define VMSVGA3D_UPDATE_SCISSORRECT RT_BIT_32(0)
741#define VMSVGA3D_UPDATE_ZRANGE RT_BIT_32(1)
742#define VMSVGA3D_UPDATE_VIEWPORT RT_BIT_32(2)
743#define VMSVGA3D_UPDATE_VERTEXSHADER RT_BIT_32(3)
744#define VMSVGA3D_UPDATE_PIXELSHADER RT_BIT_32(4)
745#define VMSVGA3D_UPDATE_TRANSFORM RT_BIT_32(5)
746#define VMSVGA3D_UPDATE_MATERIAL RT_BIT_32(6)
747/** @} */
748
749/* Query states. Mostly used for saved state. */
750typedef enum VMSVGA3DQUERYSTATE
751{
752 VMSVGA3DQUERYSTATE_NULL = 0, /* Not created. */
753 VMSVGA3DQUERYSTATE_SIGNALED = 1, /* Result obtained. The guest may or may not read the result yet. */
754 VMSVGA3DQUERYSTATE_BUILDING = 2, /* In process of collecting data. */
755 VMSVGA3DQUERYSTATE_ISSUED = 3, /* Data collected, but result is not yet obtained. */
756 VMSVGA3DQUERYSTATE_32BIT = 0x7fffffff
757} VMSVGA3DQUERYSTATE;
758AssertCompileSize(VMSVGA3DQUERYSTATE, sizeof(uint32_t));
759
760typedef struct VMSVGA3DQUERY
761{
762#ifdef VMSVGA3D_DIRECT3D
763 IDirect3DQuery9 *pQuery;
764#else /* VMSVGA3D_OPENGL */
765 GLuint idQuery;
766#endif
767 VMSVGA3DQUERYSTATE enmQueryState; /* VMSVGA3DQUERYSTATE_*. State is implicitly _NULL if pQuery is NULL. */
768 uint32_t u32QueryResult; /* Generic result. Enough for all VGPU9 queries. */
769} VMSVGA3DQUERY;
770
771#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
772/**
773 * SSM descriptor table for the VMSVGA3DQUERY structure.
774 */
775static SSMFIELD const g_aVMSVGA3DQUERYFields[] =
776{
777#ifdef VMSVGA3D_DIRECT3D
778 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DQUERY, pQuery),
779#else /* VMSVGA3D_OPENGL */
780 SSMFIELD_ENTRY_IGNORE( VMSVGA3DQUERY, idQuery),
781#endif
782 SSMFIELD_ENTRY( VMSVGA3DQUERY, enmQueryState),
783 SSMFIELD_ENTRY( VMSVGA3DQUERY, u32QueryResult),
784 SSMFIELD_ENTRY_TERM()
785};
786#endif
787
788#ifdef VMSVGA3D_DIRECT3D
789#define VMSVGA3DQUERY_EXISTS(p) ((p)->pQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)
790#else
791#define VMSVGA3DQUERY_EXISTS(p) ((p)->idQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)
792#endif
793
794/**
795 * VMSVGA3d context.
796 */
797typedef struct VMSVGA3DCONTEXT
798{
799 /** @todo Legacy contexts with DX backend. */
800
801 uint32_t id;
802#ifdef RT_OS_WINDOWS
803# ifdef VMSVGA3D_DIRECT3D
804# ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
805 IDirect3DDevice9 *pDevice;
806# else
807 IDirect3DDevice9Ex *pDevice;
808# endif
809# else
810 /* Device context of the context window. */
811 HDC hdc;
812 /* OpenGL rendering context handle. */
813 HGLRC hglrc;
814# endif
815 /* Device context window handle. */
816 HWND hwnd;
817#elif defined(RT_OS_DARWIN)
818 /* OpenGL rendering context */
819 NativeNSOpenGLContextRef cocoaContext;
820 NativeNSViewRef cocoaView;
821 bool fOtherProfile;
822#else
823 /** XGL rendering context handle */
824 GLXContext glxContext;
825 /** Device context window handle */
826 Window window;
827#endif
828
829#ifdef VMSVGA3D_OPENGL
830 /* Framebuffer object associated with this context. */
831 GLuint idFramebuffer;
832 /* Read and draw framebuffer objects for various operations. */
833 GLuint idReadFramebuffer;
834 GLuint idDrawFramebuffer;
835 /* Last GL error recorded. */
836 GLenum lastError;
837 void *pShaderContext;
838#endif
839
840 /* Current selected texture surfaces (if any) */
841 uint32_t aSidActiveTextures[SVGA3D_MAX_SAMPLERS];
842 /* Per context pixel and vertex shaders. */
843 uint32_t cPixelShaders;
844 PVMSVGA3DSHADER paPixelShader;
845 uint32_t cVertexShaders;
846 PVMSVGA3DSHADER paVertexShader;
847 /* Keep track of the internal state to be able to recreate the context properly (save/restore, window resize). */
848 struct
849 {
850 /** VMSVGA3D_UPDATE_XXX */
851 uint32_t u32UpdateFlags;
852
853 SVGA3dRenderState aRenderState[SVGA3D_RS_MAX];
854 /* aTextureStates contains both TextureStageStates and SamplerStates, therefore [SVGA3D_MAX_SAMPLERS]. */
855 SVGA3dTextureState aTextureStates[SVGA3D_MAX_SAMPLERS][SVGA3D_TS_MAX];
856 VMSVGATRANSFORMSTATE aTransformState[SVGA3D_TRANSFORM_MAX];
857 VMSVGAMATERIALSTATE aMaterial[SVGA3D_FACE_MAX];
858 /* The aClipPlane array has a wrong (greater) size. Keep it for now because the array is a part of the saved state. */
859 /** @todo Replace SVGA3D_CLIPPLANE_5 with SVGA3D_NUM_CLIPPLANES and increase the saved state version. */
860 VMSVGACLIPPLANESTATE aClipPlane[SVGA3D_CLIPPLANE_5];
861 VMSVGALIGHTSTATE aLightData[SVGA3D_MAX_LIGHTS];
862
863 uint32_t aRenderTargets[SVGA3D_RT_MAX];
864 SVGA3dRect RectScissor;
865 SVGA3dRect RectViewPort;
866 SVGA3dZRange zRange;
867 uint32_t shidPixel;
868 uint32_t shidVertex;
869
870 uint32_t cPixelShaderConst;
871 PVMSVGASHADERCONST paPixelShaderConst;
872 uint32_t cVertexShaderConst;
873 PVMSVGASHADERCONST paVertexShaderConst;
874 } state;
875
876 /* Occlusion query. */
877 VMSVGA3DQUERY occlusion;
878
879#ifdef VMSVGA3D_DIRECT3D
880 /* State which is currently applied to the D3D device. It is recreated as needed and not saved.
881 * The purpose is to remember the currently applied state and do not re-apply it if it has not changed.
882 * Unnecessary state changes are very bad for performance.
883 */
884 struct
885 {
886 /* Vertex declaration. */
887 IDirect3DVertexDeclaration9 *pVertexDecl;
888 uint32_t cVertexElements;
889 D3DVERTEXELEMENT9 aVertexElements[SVGA3D_MAX_VERTEX_ARRAYS + 1];
890 } d3dState;
891#endif
892} VMSVGA3DCONTEXT;
893/** Pointer to a VMSVGA3d context. */
894typedef VMSVGA3DCONTEXT *PVMSVGA3DCONTEXT;
895
896#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
897/**
898 * SSM descriptor table for the VMSVGA3DCONTEXT structure.
899 */
900static SSMFIELD const g_aVMSVGA3DCONTEXTFields[] =
901{
902 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, id),
903
904# ifdef RT_OS_WINDOWS
905# ifdef VMSVGA3D_DIRECT3D
906 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pDevice),
907# else
908 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hdc),
909 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hglrc),
910# endif
911 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hwnd),
912# elif defined(RT_OS_DARWIN)
913 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, cocoaContext),
914 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, cocoaView),
915 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, fOtherProfile),
916# else
917 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, glxContext),
918 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, window),
919# endif
920
921#ifdef VMSVGA3D_OPENGL
922 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idFramebuffer),
923 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idReadFramebuffer),
924 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, idDrawFramebuffer),
925 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, lastError),
926 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pShaderContext),
927#endif
928
929 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, aSidActiveTextures),
930 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cPixelShaders),
931 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paPixelShader),
932 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, cVertexShaders),
933 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, paVertexShader),
934 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.u32UpdateFlags),
935
936 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderState),
937 SSMFIELD_ENTRY_OLD( state.aTextureStates,
938 sizeof(SVGA3dTextureState) * /*SVGA3D_MAX_TEXTURE_STAGE=*/ 8 * /*SVGA3D_TS_MAX=*/ 30),
939 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aTransformState),
940 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aMaterial),
941 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aClipPlane),
942 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aLightData),
943
944 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.aRenderTargets),
945 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectScissor),
946 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.RectViewPort),
947 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.zRange),
948 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidPixel),
949 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.shidVertex),
950 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cPixelShaderConst),
951 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paPixelShaderConst),
952 SSMFIELD_ENTRY( VMSVGA3DCONTEXT, state.cVertexShaderConst),
953 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, state.paVertexShaderConst),
954 SSMFIELD_ENTRY_TERM()
955};
956#endif /* VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS */
957
958
959#ifdef VMSVGA3D_DX
960/* The 3D backend DX context. The actual structure is 3D API specific. */
961typedef struct VMSVGA3DBACKENDDXCONTEXT *PVMSVGA3DBACKENDDXCONTEXT;
962
963/**
964 * VMSVGA3D DX context (VGPU10+). DX contexts ids are a separate namespace from legacy context ids.
965 */
966typedef struct VMSVGA3DDXCONTEXT
967{
968 /** The DX context id. */
969 uint32_t cid;
970 /** . */
971 uint32_t u32Reserved;
972 /** Backend specific data. */
973 PVMSVGA3DBACKENDDXCONTEXT pBackendDXContext;
974 /** Copy of the guest memory for this context. The guest will be updated on unbind. */
975 SVGADXContextMobFormat svgaDXContext;
976 /* Context-Object Tables bound to this context. */
977 PVMSVGAMOB aCOTMobs[SVGA_COTABLE_MAX];
978 struct
979 {
980 SVGACOTableDXRTViewEntry *paRTView;
981 SVGACOTableDXDSViewEntry *paDSView;
982 SVGACOTableDXSRViewEntry *paSRView;
983 SVGACOTableDXElementLayoutEntry *paElementLayout;
984 SVGACOTableDXBlendStateEntry *paBlendState;
985 SVGACOTableDXDepthStencilEntry *paDepthStencil;
986 SVGACOTableDXRasterizerStateEntry *paRasterizerState;
987 SVGACOTableDXSamplerEntry *paSampler;
988 SVGACOTableDXStreamOutputEntry *paStreamOutput;
989 SVGACOTableDXQueryEntry *paQuery;
990 SVGACOTableDXShaderEntry *paShader;
991 SVGACOTableDXUAViewEntry *paUAView;
992 uint32_t cRTView;
993 uint32_t cDSView;
994 uint32_t cSRView;
995 uint32_t cElementLayout;
996 uint32_t cBlendState;
997 uint32_t cDepthStencil;
998 uint32_t cRasterizerState;
999 uint32_t cSampler;
1000 uint32_t cStreamOutput;
1001 uint32_t cQuery;
1002 uint32_t cShader;
1003 uint32_t cUAView;
1004 } cot;
1005 /* Shader information. The array has cot.cShader elements. Some data is dublicated in cot.paShader. */
1006 PVMSVGA3DSHADER paShader;
1007} VMSVGA3DDXCONTEXT;
1008/** Pointer to a VMSVGA3D DX context. */
1009typedef VMSVGA3DDXCONTEXT *PVMSVGA3DDXCONTEXT;
1010#endif /* VMSVGA3D_DX */
1011
1012
1013#ifdef VMSVGA3D_OPENGL
1014typedef struct VMSVGA3DFORMATCONVERTER *PVMSVGA3DFORMATCONVERTER;
1015#endif
1016
1017/* The 3D backend. The actual structure is 3D API specific. */
1018typedef struct VMSVGA3DBACKEND *PVMSVGA3DBACKEND;
1019
1020/**
1021 * VMSVGA3d state data.
1022 *
1023 * Allocated on the heap and pointed to by VMSVGAState::p3dState.
1024 */
1025typedef struct VMSVGA3DSTATE
1026{
1027 /** Backend specific data. */
1028 PVMSVGA3DBACKEND pBackend;
1029
1030 /** The size of papContexts. */
1031 uint32_t cContexts;
1032 /** The size of papSurfaces. */
1033 uint32_t cSurfaces;
1034#ifdef VMSVGA3D_DX
1035 /** The size of papDXContexts. */
1036 uint32_t cDXContexts;
1037 /** Reserved. */
1038 uint32_t u32Reserved;
1039#endif
1040 /** Contexts indexed by ID. Grown as needed. */
1041 PVMSVGA3DCONTEXT *papContexts;
1042 /** Surfaces indexed by ID. Grown as needed. */
1043 PVMSVGA3DSURFACE *papSurfaces;
1044#ifdef VMSVGA3D_DX
1045 /** DX contexts indexed by ID. Grown as needed. */
1046 PVMSVGA3DDXCONTEXT *papDXContexts;
1047#endif
1048
1049#ifdef RT_OS_WINDOWS
1050# ifdef VMSVGA3D_DIRECT3D
1051# ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
1052 IDirect3D9 *pD3D9;
1053# else
1054 IDirect3D9Ex *pD3D9;
1055# endif
1056 D3DCAPS9 caps;
1057 bool fSupportedSurfaceINTZ;
1058 bool fSupportedSurfaceNULL;
1059 bool fSupportedFormatUYVY : 1;
1060 bool fSupportedFormatYUY2 : 1;
1061 bool fSupportedFormatA8B8G8R8 : 1;
1062# endif
1063 /** Window Thread. */
1064 R3PTRTYPE(RTTHREAD) pWindowThread;
1065 DWORD idWindowThread;
1066 HMODULE hInstance;
1067 /** Window request semaphore. */
1068 RTSEMEVENT WndRequestSem;
1069#elif defined(RT_OS_DARWIN)
1070#else
1071 /* The X display */
1072 Display *display;
1073 R3PTRTYPE(RTTHREAD) pWindowThread;
1074 bool bTerminate;
1075#endif
1076
1077#ifdef VMSVGA3D_OPENGL
1078 float rsGLVersion;
1079 /* Current active context. */
1080 uint32_t idActiveContext;
1081
1082 struct
1083 {
1084 PFNGLISRENDERBUFFERPROC glIsRenderbuffer;
1085 PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
1086 PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
1087 PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
1088 PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
1089 PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv;
1090 PFNGLISFRAMEBUFFERPROC glIsFramebuffer;
1091 PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
1092 PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
1093 PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
1094 PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
1095 PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;
1096 PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
1097 PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;
1098 PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
1099 PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv;
1100 PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
1101 PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
1102 PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;
1103 PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer;
1104 PFNGLPOINTPARAMETERFPROC glPointParameterf;
1105#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x102
1106 PFNGLBLENDCOLORPROC glBlendColor;
1107 PFNGLBLENDEQUATIONPROC glBlendEquation;
1108#endif
1109 PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate;
1110 PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
1111 PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate;
1112 PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate;
1113 PFNGLBINDBUFFERPROC glBindBuffer;
1114 PFNGLDELETEBUFFERSPROC glDeleteBuffers;
1115 PFNGLGENBUFFERSPROC glGenBuffers;
1116 PFNGLBUFFERDATAPROC glBufferData;
1117 PFNGLMAPBUFFERPROC glMapBuffer;
1118 PFNGLUNMAPBUFFERPROC glUnmapBuffer;
1119 PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
1120 PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
1121 PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
1122 PFNGLFOGCOORDPOINTERPROC glFogCoordPointer;
1123 PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex;
1124 PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex;
1125 PFNGLACTIVETEXTUREPROC glActiveTexture;
1126#if VBOX_VMSVGA3D_GL_HACK_LEVEL < 0x103
1127 PFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture;
1128#endif
1129 PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
1130 PFNGLPROVOKINGVERTEXPROC glProvokingVertex;
1131 PFNGLGENQUERIESPROC glGenQueries;
1132 PFNGLDELETEQUERIESPROC glDeleteQueries;
1133 PFNGLBEGINQUERYPROC glBeginQuery;
1134 PFNGLENDQUERYPROC glEndQuery;
1135 PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv;
1136 PFNGLTEXIMAGE3DPROC glTexImage3D;
1137 PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D;
1138 PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor;
1139 PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced;
1140 PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced;
1141 PFNGLGETCOMPRESSEDTEXIMAGEPROC glGetCompressedTexImage;
1142 PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D;
1143 PFNGLCOMPRESSEDTEXIMAGE3DPROC glCompressedTexImage3D;
1144 PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D;
1145 PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D;
1146 PFNGLDRAWBUFFERSPROC glDrawBuffers;
1147 PFNGLCREATESHADERPROC glCreateShader;
1148 PFNGLSHADERSOURCEPROC glShaderSource;
1149 PFNGLCOMPILESHADERPROC glCompileShader;
1150 PFNGLGETSHADERIVPROC glGetShaderiv;
1151 PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
1152 PFNGLCREATEPROGRAMPROC glCreateProgram;
1153 PFNGLATTACHSHADERPROC glAttachShader;
1154 PFNGLLINKPROGRAMPROC glLinkProgram;
1155 PFNGLGETPROGRAMIVPROC glGetProgramiv;
1156 PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
1157 PFNGLUSEPROGRAMPROC glUseProgram;
1158 PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
1159 PFNGLUNIFORM1IPROC glUniform1i;
1160 PFNGLUNIFORM4FVPROC glUniform4fv;
1161 PFNGLDETACHSHADERPROC glDetachShader;
1162 PFNGLDELETESHADERPROC glDeleteShader;
1163 PFNGLDELETEPROGRAMPROC glDeleteProgram;
1164 PFNGLVERTEXATTRIB4FVPROC glVertexAttrib4fv;
1165 PFNGLVERTEXATTRIB4UBVPROC glVertexAttrib4ubv;
1166 PFNGLVERTEXATTRIB4NUBVPROC glVertexAttrib4Nubv;
1167 PFNGLVERTEXATTRIB4SVPROC glVertexAttrib4sv;
1168 PFNGLVERTEXATTRIB4NSVPROC glVertexAttrib4Nsv;
1169 PFNGLVERTEXATTRIB4NUSVPROC glVertexAttrib4Nusv;
1170 } ext;
1171
1172 struct
1173 {
1174 bool fS3TCSupported : 1;
1175 bool fTextureFilterAnisotropicSupported : 1;
1176 GLint maxActiveLights;
1177 GLint maxTextures;
1178 GLint maxClipDistances;
1179 GLint maxColorAttachments;
1180 GLint maxRectangleTextureSize;
1181 GLint maxTextureAnisotropy;
1182 GLint maxVertexShaderInstructions;
1183 GLint maxFragmentShaderInstructions;
1184 GLint maxVertexShaderTemps;
1185 GLint maxFragmentShaderTemps;
1186 GLfloat flPointSize[2];
1187 SVGA3dPixelShaderVersion fragmentShaderVersion;
1188 SVGA3dVertexShaderVersion vertexShaderVersion;
1189 } caps;
1190
1191 /** The GL_EXTENSIONS value (space padded) for the default OpenGL profile.
1192 * Free with RTStrFree. */
1193 R3PTRTYPE(char *) pszExtensions;
1194
1195 /** The GL_EXTENSIONS value (space padded) for the other OpenGL profile.
1196 * Free with RTStrFree.
1197 *
1198 * This is used to detect shader model version since some implementations
1199 * (darwin) hides extensions that have made it into core and probably a
1200 * bunch of others when using a OpenGL core profile instead of a legacy one */
1201 R3PTRTYPE(char *) pszOtherExtensions;
1202 /** The version of the other GL profile. */
1203 float rsOtherGLVersion;
1204
1205 /** Shader talk back interface. */
1206 VBOXVMSVGASHADERIF ShaderIf;
1207
1208# ifdef VMSVGA3D_OPENGL
1209 /** The shared context. */
1210 VMSVGA3DCONTEXT SharedCtx;
1211
1212 /** Conversion of emulated formats. Resources are created on the SharedCtx. */
1213 PVMSVGA3DFORMATCONVERTER pConv;
1214# endif
1215#endif /* VMSVGA3D_OPENGL */
1216} VMSVGA3DSTATE;
1217
1218#ifdef VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
1219/**
1220 * SSM descriptor table for the VMSVGA3DSTATE structure.
1221 *
1222 * @remarks This isn't a complete structure markup, only fields with state.
1223 */
1224static SSMFIELD const g_aVMSVGA3DSTATEFields[] =
1225{
1226# ifdef VMSVGA3D_OPENGL
1227 SSMFIELD_ENTRY( VMSVGA3DSTATE, rsGLVersion), /** @todo Why are we saving the GL version?? */
1228# endif
1229 SSMFIELD_ENTRY( VMSVGA3DSTATE, cContexts),
1230 SSMFIELD_ENTRY( VMSVGA3DSTATE, cSurfaces),
1231 SSMFIELD_ENTRY_TERM()
1232};
1233#endif /* VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS */
1234
1235
1236#ifdef VMSVGA3D_DIRECT3D
1237D3DFORMAT vmsvga3dSurfaceFormat2D3D(SVGA3dSurfaceFormat format);
1238D3DMULTISAMPLE_TYPE vmsvga3dMultipeSampleCount2D3D(uint32_t multisampleCount);
1239DECLCALLBACK(int) vmsvga3dSharedSurfaceDestroyTree(PAVLU32NODECORE pNode, void *pvParam);
1240int vmsvga3dSurfaceFlush(PVMSVGA3DSURFACE pSurface);
1241#endif /* VMSVGA3D_DIRECT3D */
1242
1243
1244#ifdef VMSVGA3D_OPENGL
1245/** Save and setup everything. */
1246# define VMSVGA3D_PARANOID_TEXTURE_PACKING
1247
1248/** @name VMSVGAPACKPARAMS_* - which packing parameters were set.
1249 * @{ */
1250# define VMSVGAPACKPARAMS_ALIGNMENT RT_BIT_32(0)
1251# define VMSVGAPACKPARAMS_ROW_LENGTH RT_BIT_32(1)
1252# define VMSVGAPACKPARAMS_IMAGE_HEIGHT RT_BIT_32(2)
1253# define VMSVGAPACKPARAMS_SWAP_BYTES RT_BIT_32(3)
1254# define VMSVGAPACKPARAMS_LSB_FIRST RT_BIT_32(4)
1255# define VMSVGAPACKPARAMS_SKIP_ROWS RT_BIT_32(5)
1256# define VMSVGAPACKPARAMS_SKIP_PIXELS RT_BIT_32(6)
1257# define VMSVGAPACKPARAMS_SKIP_IMAGES RT_BIT_32(7)
1258/** @} */
1259
1260/**
1261 * Saved texture packing parameters (shared by both pack and unpack).
1262 */
1263typedef struct VMSVGAPACKPARAMS
1264{
1265 uint32_t fChanged;
1266 GLint iAlignment;
1267 GLint cxRow;
1268 GLint cyImage;
1269# ifdef VMSVGA3D_PARANOID_TEXTURE_PACKING
1270 GLboolean fSwapBytes;
1271 GLboolean fLsbFirst;
1272 GLint cSkipRows;
1273 GLint cSkipPixels;
1274 GLint cSkipImages;
1275# endif
1276} VMSVGAPACKPARAMS;
1277/** Pointer to saved texture packing parameters. */
1278typedef VMSVGAPACKPARAMS *PVMSVGAPACKPARAMS;
1279/** Pointer to const saved texture packing parameters. */
1280typedef VMSVGAPACKPARAMS const *PCVMSVGAPACKPARAMS;
1281
1282void vmsvga3dOglSetPackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1283 PVMSVGAPACKPARAMS pSave);
1284void vmsvga3dOglRestorePackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface,
1285 PCVMSVGAPACKPARAMS pSave);
1286void vmsvga3dOglSetUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, GLint cxRow, GLint cyImage,
1287 PVMSVGAPACKPARAMS pSave);
1288void vmsvga3dOglRestoreUnpackParams(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext,
1289 PCVMSVGAPACKPARAMS pSave);
1290
1291/** @name VMSVGA3D_DEF_CTX_F_XXX - vmsvga3dContextDefineOgl flags.
1292 * @{ */
1293/** When clear, the context is created using the default OpenGL profile.
1294 * When set, it's created using the alternative profile. The latter is only
1295 * allowed if the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set. */
1296# define VMSVGA3D_DEF_CTX_F_OTHER_PROFILE RT_BIT_32(0)
1297/** Defining the shared context. */
1298# define VMSVGA3D_DEF_CTX_F_SHARED_CTX RT_BIT_32(1)
1299/** Defining the init time context (EMT). */
1300# define VMSVGA3D_DEF_CTX_F_INIT RT_BIT_32(2)
1301/** @} */
1302int vmsvga3dContextDefineOgl(PVGASTATECC pThisCC, uint32_t cid, uint32_t fFlags);
1303void vmsvga3dSurfaceFormat2OGL(PVMSVGA3DSURFACE pSurface, SVGA3dSurfaceFormat format);
1304
1305#endif /* VMSVGA3D_OPENGL */
1306
1307
1308/* DevVGA-SVGA3d-shared.cpp: */
1309int vmsvga3dSaveShaderConst(PVMSVGA3DCONTEXT pContext, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype,
1310 uint32_t val1, uint32_t val2, uint32_t val3, uint32_t val4);
1311
1312
1313DECLINLINE(int) vmsvga3dContextFromCid(PVMSVGA3DSTATE pState, uint32_t cid, PVMSVGA3DCONTEXT *ppContext)
1314{
1315 AssertReturn(cid < pState->cContexts, VERR_INVALID_PARAMETER);
1316 PVMSVGA3DCONTEXT const pContext = pState->papContexts[cid];
1317 if (RT_LIKELY(pContext && pContext->id == cid))
1318 {
1319 *ppContext = pContext;
1320 return VINF_SUCCESS;
1321 }
1322 LogRelMax(64, ("VMSVGA: unknown cid=%u (%s cid=%u)\n", cid, pContext ? "expected" : "null", pContext ? pContext->id : -1));
1323 return VERR_INVALID_PARAMETER;
1324}
1325
1326#ifdef VMSVGA3D_DX
1327DECLINLINE(int) vmsvga3dDXContextFromCid(PVMSVGA3DSTATE pState, uint32_t cid, PVMSVGA3DDXCONTEXT *ppDXContext)
1328{
1329 *ppDXContext = NULL;
1330 if (cid == SVGA_ID_INVALID)
1331 return VERR_INVALID_STATE;
1332 AssertReturn(cid < pState->cDXContexts, VERR_INVALID_PARAMETER);
1333 PVMSVGA3DDXCONTEXT const pDXContext = pState->papDXContexts[cid];
1334 if (RT_LIKELY(pDXContext && pDXContext->cid == cid))
1335 {
1336 *ppDXContext = pDXContext;
1337 return VINF_SUCCESS;
1338 }
1339 LogRelMax(64, ("VMSVGA: unknown DX cid=%u (%s cid=%u)\n", cid, pDXContext ? "expected" : "null", pDXContext ? pDXContext->cid : -1));
1340 return VERR_INVALID_PARAMETER;
1341}
1342#endif
1343
1344DECLINLINE(int) vmsvga3dSurfaceFromSid(PVMSVGA3DSTATE pState, uint32_t sid, PVMSVGA3DSURFACE *ppSurface)
1345{
1346 AssertReturn(sid < pState->cSurfaces, VERR_INVALID_PARAMETER);
1347 PVMSVGA3DSURFACE const pSurface = pState->papSurfaces[sid];
1348 if (RT_LIKELY(pSurface && pSurface->id == sid))
1349 {
1350 *ppSurface = pSurface;
1351 return VINF_SUCCESS;
1352 }
1353 LogRelMax(64, ("VMSVGA: unknown sid=%u (%s sid=%u)\n", sid, pSurface ? "expected" : "null", pSurface ? pSurface->id : -1));
1354 return VERR_INVALID_PARAMETER;
1355}
1356
1357DECLINLINE(int) vmsvga3dMipmapLevel(PVMSVGA3DSURFACE pSurface, uint32_t face, uint32_t mipmap,
1358 PVMSVGA3DMIPMAPLEVEL *ppMipmapLevel)
1359{
1360 AssertMsgReturn(face < pSurface->cFaces,
1361 ("cFaces %d, face %d\n", pSurface->cFaces, face),
1362 VERR_INVALID_PARAMETER);
1363 AssertMsgReturn(mipmap < pSurface->cLevels,
1364 ("numMipLevels %d, mipmap %d", pSurface->cLevels, mipmap),
1365 VERR_INVALID_PARAMETER);
1366
1367 *ppMipmapLevel = &pSurface->paMipmapLevels[face * pSurface->cLevels + mipmap];
1368 return VINF_SUCCESS;
1369}
1370
1371void vmsvga3dInfoSurfaceToBitmap(PCDBGFINFOHLP pHlp, PVMSVGA3DSURFACE pSurface,
1372 const char *pszPath, const char *pszNamePrefix, const char *pszNameSuffix);
1373
1374#if defined(RT_OS_WINDOWS)
1375#define D3D_RELEASE(ptr) do { \
1376 if (ptr) \
1377 { \
1378 (ptr)->Release(); \
1379 (ptr) = 0; \
1380 } \
1381} while (0)
1382#endif
1383
1384#if defined(VMSVGA3D_DIRECT3D)
1385HRESULT D3D9UpdateTexture(PVMSVGA3DCONTEXT pContext,
1386 PVMSVGA3DSURFACE pSurface);
1387HRESULT D3D9GetRenderTargetData(PVMSVGA3DCONTEXT pContext,
1388 PVMSVGA3DSURFACE pSurface,
1389 uint32_t uFace,
1390 uint32_t uMipmap);
1391HRESULT D3D9GetSurfaceLevel(PVMSVGA3DSURFACE pSurface,
1392 uint32_t uFace,
1393 uint32_t uMipmap,
1394 bool fBounce,
1395 IDirect3DSurface9 **ppD3DSurface);
1396D3DFORMAT D3D9GetActualFormat(PVMSVGA3DSTATE pState,
1397 D3DFORMAT d3dfmt);
1398bool D3D9CheckDeviceFormat(IDirect3D9 *pD3D9,
1399 DWORD Usage,
1400 D3DRESOURCETYPE RType,
1401 D3DFORMAT CheckFormat);
1402#endif
1403
1404#ifdef VMSVGA3D_OPENGL
1405void vmsvga3dOnSharedContextDefine(PVMSVGA3DSTATE pState);
1406void vmsvga3dOnSharedContextDestroy(PVMSVGA3DSTATE pState);
1407
1408DECLINLINE(GLuint) GLTextureId(PVMSVGA3DSURFACE pSurface)
1409{
1410 return pSurface->fEmulated ? pSurface->idEmulated : pSurface->oglId.texture;
1411}
1412
1413void FormatConvUpdateTexture(PVMSVGA3DSTATE pState,
1414 PVMSVGA3DCONTEXT pCurrentContext,
1415 PVMSVGA3DSURFACE pSurface,
1416 uint32_t iMipmap);
1417void FormatConvReadTexture(PVMSVGA3DSTATE pState,
1418 PVMSVGA3DCONTEXT pCurrentContext,
1419 PVMSVGA3DSURFACE pSurface,
1420 uint32_t iMipmap);
1421#endif
1422
1423int vmsvga3dShaderParse(SVGA3dShaderType type, uint32_t cbShaderData, uint32_t const *pShaderData);
1424void vmsvga3dShaderLogRel(char const *pszMsg, SVGA3dShaderType type, uint32_t cbShaderData, uint32_t const *pShaderData);
1425
1426#endif /* !VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h */
1427
Note: See TracBrowser for help on using the repository browser.

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