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