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