VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h@ 39436

Last change on this file since 39436 was 39288, checked in by vboxsync, 13 years ago

CrOpenGL: avoid blocked client polling & extra memcpy (block hgsmi command until completion)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.3 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved.
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#ifndef INCLUDE_CR_SERVER_H
8#define INCLUDE_CR_SERVER_H
9
10#include "cr_spu.h"
11#include "cr_net.h"
12#include "cr_hash.h"
13#include "cr_protocol.h"
14#include "cr_glstate.h"
15#include "spu_dispatch_table.h"
16
17#include "state/cr_currentpointers.h"
18
19#include <iprt/types.h>
20#include <iprt/err.h>
21#include <iprt/string.h>
22
23#include <VBox/vmm/ssm.h>
24
25#ifdef VBOX_WITH_CRHGSMI
26# include <VBox/VBoxVideo.h>
27#endif
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#define SHCROGL_SSM_VERSION 28
34
35#define CR_MAX_WINDOWS 100
36#define CR_MAX_CLIENTS 64
37
38/*@todo must match MaxGuestMonitors from SchemaDefs.h*/
39#define CR_MAX_GUEST_MONITORS 8
40
41typedef DECLCALLBACKPTR(void, PFNCRSERVERPRESENTFBO) (void *data, int32_t screenId, int32_t x, int32_t y, uint32_t w, uint32_t h);
42
43/* Callbacks for output of the rendered frames.
44 *
45 * This allows to pass rendered frames to an external component rather than draw them on screen.
46 *
47 * An external component registers the redirection callbacks using crVBoxServerOutputRedirectSet.
48 *
49 * The list of formats supported by the caller is obtained using CRORContextProperty.
50 * The actual format choosed by the service is passed as a CRORBegin parameter.
51 */
52typedef struct {
53 const void *pvContext; /* Supplied by crVBoxServerOutputRedirectSet. */
54 DECLR3CALLBACKMEMBER(void, CRORBegin, (const void *pvContext, void **ppvInstance,
55 const char *pszFormat));
56 DECLR3CALLBACKMEMBER(void, CRORGeometry, (void *pvInstance,
57 int32_t x, int32_t y, uint32_t w, uint32_t h));
58 DECLR3CALLBACKMEMBER(void, CRORVisibleRegion, (void *pvInstance,
59 uint32_t cRects, RTRECT *paRects));
60 DECLR3CALLBACKMEMBER(void, CRORFrame, (void *pvInstance,
61 void *pvData, uint32_t cbData));
62 DECLR3CALLBACKMEMBER(void, CROREnd, (void *pvInstance));
63 DECLR3CALLBACKMEMBER(int, CRORContextProperty, (const void *pvContext, uint32_t index,
64 void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut));
65} CROutputRedirect;
66
67typedef struct {
68 CRrecti imagewindow; /**< coordinates in mural space */
69 CRrectf bounds; /**< normalized coordinates in [-1,-1] x [1,1] */
70 CRrecti outputwindow; /**< coordinates in server's rendering window */
71 CRrecti clippedImagewindow; /**< imagewindow clipped to current viewport */
72 CRmatrix baseProjection; /**< pre-multiplied onto projection matrix */
73 CRrecti scissorBox; /**< passed to back-end OpenGL */
74 CRrecti viewport; /**< passed to back-end OpenGL */
75 GLuint serialNo; /**< an optimization */
76} CRExtent;
77
78struct BucketingInfo;
79
80/**
81 * Mural info
82 */
83typedef struct {
84 GLuint width, height;
85 GLint gX, gY; /*guest coordinates*/
86 GLint hX, hY; /*host coordinates, screenID related*/
87
88 int spuWindow; /*the SPU's corresponding window ID */
89
90 int screenId;
91
92 GLboolean bVisible; /*guest window is visible*/
93 GLboolean bUseFBO; /*redirect to FBO instead of real host window*/
94
95 GLint cVisibleRects; /*count of visible rects*/
96 GLint *pVisibleRects; /*visible rects left, top, right, bottom*/
97 GLboolean bReceivedRects; /*indicates if guest did any updates for visible regions*/
98
99 GLuint idFBO, idColorTex, idDepthStencilRB;
100 GLuint fboWidth, fboHeight;
101 GLuint idPBO;
102
103 void *pvOutputRedirectInstance;
104} CRMuralInfo;
105
106/**
107 * A client is basically an upstream Cr Node (connected via mothership)
108 */
109typedef struct _crclient {
110 int spu_id; /**< id of the last SPU in the client's SPU chain */
111 CRConnection *conn; /**< network connection from the client */
112 int number; /**< a unique number for each client */
113 uint64_t pid; /*guest pid*/
114 GLint currentContextNumber;
115 CRContext *currentCtx;
116 GLint currentWindow;
117 CRMuralInfo *currentMural;
118 GLint windowList[CR_MAX_WINDOWS];
119 GLint contextList[CR_MAX_CONTEXTS];
120#ifdef VBOXCR_LOGFPS
121 uint64_t timeUsed;
122#endif
123} CRClient;
124
125typedef struct _crclientnode {
126 CRClient *pClient;
127 struct _crclientnode *prev, *next;
128} CRClientNode;
129
130typedef struct CRPoly_t {
131 int npoints;
132 double *points;
133 struct CRPoly_t *next;
134} CRPoly;
135
136/**
137 * There's one of these run queue entries per client
138 * The run queue is a circular, doubly-linked list of these objects.
139 */
140typedef struct RunQueue_t {
141 CRClient *client;
142 int blocked;
143 struct RunQueue_t *next;
144 struct RunQueue_t *prev;
145} RunQueue;
146
147typedef struct {
148 GLint freeWindowID;
149 GLint freeContextID;
150 GLint freeClientID;
151} CRServerFreeIDsPool_t;
152
153typedef struct {
154 int32_t x, y;
155 uint32_t w, h;
156 uint64_t winID;
157} CRScreenInfo;
158
159typedef struct {
160 unsigned short tcpip_port;
161
162 CRScreenInfo screen[CR_MAX_GUEST_MONITORS];
163 int screenCount;
164
165 int numClients;
166 CRClient *clients[CR_MAX_CLIENTS]; /**< array [numClients] */
167 CRClient *curClient;
168 CRClientNode *pCleanupClient; /*list of clients with pending clean up*/
169 CRCurrentStatePointers current;
170
171 GLboolean firstCallCreateContext;
172 GLboolean firstCallMakeCurrent;
173 GLboolean bIsInLoadingState; /* Indicates if we're in process of loading VM snapshot */
174 GLboolean bIsInSavingState; /* Indicates if we're in process of saving VM snapshot */
175 GLint currentWindow;
176 GLint currentNativeWindow;
177
178 CRHashTable *muralTable; /**< hash table where all murals are stored */
179 CRHashTable *pWindowCreateInfoTable; /**< hash table with windows creation info */
180
181 int client_spu_id;
182
183 CRServerFreeIDsPool_t idsPool;
184
185 int mtu;
186 int buffer_size;
187 char protocol[1024];
188
189 SPU *head_spu;
190 SPUDispatchTable dispatch;
191
192 CRNetworkPointer return_ptr;
193 CRNetworkPointer writeback_ptr;
194
195 CRLimitsState limits; /**< GL limits for any contexts we create */
196
197 int SpuContext; /**< Rendering context for the head SPU */
198 int SpuContextVisBits; /**< Context's visual attributes */
199 char *SpuContextDpyName; /**< Context's dpyName */
200
201 CRHashTable *contextTable; /**< hash table for rendering contexts */
202 CRHashTable *pContextCreateInfoTable; /**< hash table with contexts creation info */
203 CRContext *DummyContext; /**< used when no other bound context */
204
205 CRHashTable *programTable; /**< for vertex programs */
206 GLuint currentProgram;
207
208 /** configuration options */
209 /*@{*/
210 int useL2;
211 int ignore_papi;
212 unsigned int maxBarrierCount;
213 unsigned int clearCount;
214 int optimizeBucket;
215 int only_swap_once;
216 int debug_barriers;
217 int sharedDisplayLists;
218 int sharedTextureObjects;
219 int sharedPrograms;
220 int sharedWindows;
221 int uniqueWindows;
222 int localTileSpec;
223 int useDMX;
224 int overlapBlending;
225 int vpProjectionMatrixParameter;
226 const char *vpProjectionMatrixVariable;
227 int stereoView;
228 int vncMode; /* cmd line option */
229 /*@}*/
230 /** view_matrix config */
231 /*@{*/
232 GLboolean viewOverride;
233 CRmatrix viewMatrix[2]; /**< left and right eye */
234 /*@}*/
235 /** projection_matrix config */
236 /*@{*/
237 GLboolean projectionOverride;
238 CRmatrix projectionMatrix[2]; /**< left and right eye */
239 int currentEye;
240 /*@}*/
241
242 /** for warped tiles */
243 /*@{*/
244 GLfloat alignment_matrix[16], unnormalized_alignment_matrix[16];
245 /*@}*/
246
247 /** tile overlap/blending info - this should probably be per-mural */
248 /*@{*/
249 CRPoly **overlap_geom;
250 CRPoly *overlap_knockout;
251 float *overlap_intens;
252 int num_overlap_intens;
253 int num_overlap_levels;
254 /*@}*/
255
256 CRHashTable *barriers, *semaphores;
257
258 RunQueue *run_queue;
259
260 GLuint currentSerialNo;
261
262 PFNCRSERVERPRESENTFBO pfnPresentFBO;
263 GLboolean bForceOffscreenRendering; /*Force server to render 3d data offscreen
264 *using callback above to update vbox framebuffers*/
265 GLboolean bUsePBOForReadback; /*Use PBO's for data readback*/
266
267 GLboolean bUseOutputRedirect; /* Whether the output redirect was set. */
268 CROutputRedirect outputRedirect;
269} CRServer;
270
271
272extern DECLEXPORT(void) crServerInit( int argc, char *argv[] );
273extern DECLEXPORT(int) CRServerMain( int argc, char *argv[] );
274extern DECLEXPORT(void) crServerServiceClients(void);
275extern DECLEXPORT(void) crServerAddNewClient(void);
276extern DECLEXPORT(SPU*) crServerHeadSPU(void);
277extern DECLEXPORT(void) crServerSetPort(int port);
278
279extern DECLEXPORT(GLboolean) crVBoxServerInit(void);
280extern DECLEXPORT(void) crVBoxServerTearDown(void);
281extern DECLEXPORT(int32_t) crVBoxServerAddClient(uint32_t u32ClientID);
282extern DECLEXPORT(void) crVBoxServerRemoveClient(uint32_t u32ClientID);
283extern DECLEXPORT(int32_t) crVBoxServerClientWrite(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t cbBuffer);
284extern DECLEXPORT(int32_t) crVBoxServerClientRead(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t *pcbBuffer);
285extern DECLEXPORT(int32_t) crVBoxServerClientSetVersion(uint32_t u32ClientID, uint32_t vMajor, uint32_t vMinor);
286extern DECLEXPORT(int32_t) crVBoxServerClientSetPID(uint32_t u32ClientID, uint64_t pid);
287
288extern DECLEXPORT(int32_t) crVBoxServerSaveState(PSSMHANDLE pSSM);
289extern DECLEXPORT(int32_t) crVBoxServerLoadState(PSSMHANDLE pSSM, uint32_t version);
290
291extern DECLEXPORT(int32_t) crVBoxServerSetScreenCount(int sCount);
292extern DECLEXPORT(int32_t) crVBoxServerUnmapScreen(int sIndex);
293extern DECLEXPORT(int32_t) crVBoxServerMapScreen(int sIndex, int32_t x, int32_t y, uint32_t w, uint32_t h, uint64_t winID);
294
295extern DECLEXPORT(int32_t) crVBoxServerSetRootVisibleRegion(GLint cRects, GLint *pRects);
296
297extern DECLEXPORT(void) crVBoxServerSetPresentFBOCB(PFNCRSERVERPRESENTFBO pfnPresentFBO);
298
299extern DECLEXPORT(int32_t) crVBoxServerSetOffscreenRendering(GLboolean value);
300
301extern DECLEXPORT(int32_t) crVBoxServerOutputRedirectSet(const CROutputRedirect *pCallbacks);
302
303#ifdef VBOX_WITH_CRHGSMI
304/* We moved all CrHgsmi command processing to crserverlib to keep the logic of dealing with CrHgsmi commands in one place.
305 *
306 * For now we need the notion of CrHgdmi commands in the crserver_lib to be able to complete it asynchronously once it is really processed.
307 * This help avoiding the "blocked-client" issues. The client is blocked if another client is doing begin-end stuff.
308 * For now we eliminated polling that could occur on block, which caused a higher-priority thread (in guest) polling for the blocked command complition
309 * to block the lower-priority thread trying to complete the blocking command.
310 * And removed extra memcpy done on blocked command arrival.
311 *
312 * In the future we will extend CrHgsmi functionality to maintain texture data directly in CrHgsmi allocation to avoid extra memcpy-ing with PBO,
313 * implement command completion and stuff necessary for GPU scheduling to work properly for WDDM Windows guests, etc.
314 *
315 * NOTE: it is ALWAYS responsibility of the crVBoxServerCrHgsmiCmd to complete the command!
316 * */
317extern DECLEXPORT(int32_t) crVBoxServerCrHgsmiCmd(struct VBOXVDMACMD_CHROMIUM_CMD *pCmd);
318extern DECLEXPORT(int32_t) crVBoxServerCrHgsmiCtl(struct VBOXVDMACMD_CHROMIUM_CTL *pCtl);
319#endif
320
321#ifdef __cplusplus
322}
323#endif
324
325#endif
326
Note: See TracBrowser for help on using the repository browser.

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