VirtualBox

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

Last change on this file since 97697 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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