cr_server.h revision 022e56bff837db399121bc76e4f404a6cd959d6e
/* Copyright (c) 2001, Stanford University
* All rights reserved.
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#ifndef INCLUDE_CR_SERVER_H
#define INCLUDE_CR_SERVER_H
#include "cr_spu.h"
#include "cr_net.h"
#include "cr_hash.h"
#include "cr_protocol.h"
#include "cr_glstate.h"
#include "cr_vreg.h"
#include "cr_blitter.h"
#include "cr_htable.h"
#include "spu_dispatch_table.h"
#include "cr_dump.h"
#include "state/cr_currentpointers.h"
#include <iprt/critsect.h>
#include <iprt/semaphore.h>
#include <iprt/memcache.h>
#include <VBox/VBoxVideo.h>
#include <VBox/VBoxVideo3D.h>
#include <VBox/VBoxVideoHost3D.h>
#ifdef __cplusplus
extern "C" {
#endif
#define CR_MAX_WINDOWS 100
#define CR_MAX_CLIENTS 64
/*@todo must match MaxGuestMonitors from SchemaDefs.h*/
typedef DECLCALLBACKPTR(void, PFNCRSERVERPRESENTFBO) (void *data, int32_t screenId, int32_t x, int32_t y, uint32_t w, uint32_t h);
/* Callbacks for output of the rendered frames.
*
* This allows to pass rendered frames to an external component rather than draw them on screen.
*
* An external component registers the redirection callbacks using crVBoxServerOutputRedirectSet.
*
* The list of formats supported by the caller is obtained using CRORContextProperty.
* The actual format choosed by the service is passed as a CRORBegin parameter.
*/
typedef struct {
const void *pvContext; /* Supplied by crVBoxServerOutputRedirectSet. */
const char *pszFormat));
typedef struct {
} CRExtent;
struct BucketingInfo;
typedef struct {
char *pszDpyName;
typedef struct {
char *pszDpyName;
/* VRAM->RAM worker thread */
typedef enum
{
/* worker control command */
typedef enum
{
struct CR_SERVER_RPW_ENTRY;
typedef struct CR_SERVER_RPW_CTL {
int rc;
/* valid for *_WAIT_COMPLETE and *_CANCEL */
struct CR_SERVER_RPW_ENTRY *pEntry;
struct CR_SERVER_RPW_ENTRY;
typedef DECLCALLBACKPTR(void, PFNCR_SERVER_RPW_DATA) (const struct CR_SERVER_RPW_ENTRY* pEntry, void *pvEntryTexData);
typedef DECLCALLBACKPTR(void, PFNCRSERVERNOTIFYEVENT) (int32_t screenId, uint32_t uEvent, void* pvData, uint32_t cbData);
typedef struct CR_SERVER_RPW_ENTRY
{
/* We have to use 4 textures here.
*
* 1. iDrawTex - the texture clients can draw to and then submit it for contents acquisition via crServerRpwEntrySubmit
* 2. iSubmittedTex - the texture submitted to the worker for processing and, whose processing has not start yet,
* 3. iWorkerTex - the texture being prepared & passed by the worker to the GPU (stage 1 of a worker contents acquisition process)
* 4. iGpuTex - the texture passed/processed to/by the GPU, whose data is then acquired by the server (stage 2 of a worker contents acquisition process)
*
* - There can be valid distinct iGpuTex, iWorkerTex, iSubmittedTex and iDrawTex present simultaneously.
* - Either or both of iSubmittedTex and iFreeTex are always valid
*
* Detail:
*
* - iSubmittedTex and iFreeTex modifications are performed under CR_SERVER_RPW::CritSect lock.
*
* - iDrawTex can only be changed by client side (i.e. the crServerRpwEntrySubmit caller), this is why client thread can access it w/o a lock
* - iSubmittedTex and iFreeTex can be modified by both client and worker, so lock is always required
*
* - iDrawTex can be accessed by client code only
* - iWorkerTex and iGpuTex can be accessed by worker code only
* - iSubmittedTex and iFreeTex can be accessed under CR_SERVER_RPW::CritSect lock only
* - either or both of iSubmittedTex and iFreeTex are always valid (see below for more explanation),
* this is why client can easily determine the new iDrawTex value on Submit, i.e. :
*
* (if initial iSubmittedTex was valid)
* ---------------
* | ^
* > |
* Submit-> iDrawTex -> iSubmittedTex
* ^
* | (if initial iSubmittedTex was NOT valid)
* iFreeTex
*
* - The worker can invalidate the iSubmittedTex (i.e. do iSubmittedTex -> iWorkerTex) only after it is done
* with the last iWorkerTex -> iGpuTex transformation freeing the previously used iGpuTex to iFreeTex.
*
* - A simplified worker iXxxTex transformation logic is:
* 1. iFreeTex is initially valid
* 2. iSubmittedTex -> iWorkerTex;
* 3. submit iWorkerTex acquire request to the GPU
* 4. complete current iGpuTex
* 5. iGpuTex -> iFreeTex
* 6. iWorkerTex -> iGpuTex
* 7. goto 1
*
* */
typedef struct CR_SERVER_RPW {
/* only one outstanding command is supported,
* and ctl requests must be cynchronized, hold it right here */
int ctxId;
/* */
/* FRAMEBUFFER */
typedef struct CR_FRAMEBUFFER *HCR_FRAMEBUFFER;
typedef struct CR_FRAMEBUFFER_ENTRY *HCR_FRAMEBUFFER_ENTRY;
/* */
typedef struct CR_FBDATA
{
} CR_FBDATA;
/**
* Mural info
*/
typedef struct {
int spuWindow; /*the SPU's corresponding window ID */
int screenId;
void *pvReserved;
/* to avoid saved state breakage we need to keep RT_OFFSETOF(CRMuralInfo, CreateInfo) intact
* this is why we place some FBO stuff to the tail
* @todo: once we need to increment a saved state version, we could refactor this structure */
/* bitfield representing contexts the mural has been ever current with
* we just reuse CR_STATE_SHAREDOBJ_USAGE_XXX API here for simplicity */
} CRMuralInfo;
typedef struct {
int SpuContext;
/**
* A client is basically an upstream Cr Node (connected via mothership)
*/
typedef struct _crclient {
int spu_id; /**< id of the last SPU in the client's SPU chain */
int number; /**< a unique number for each client */
#ifdef VBOXCR_LOGFPS
#endif
} CRClient;
typedef struct _crclientnode {
} CRClientNode;
typedef struct CRPoly_t {
int npoints;
double *points;
} CRPoly;
/**
* There's one of these run queue entries per client
* The run queue is a circular, doubly-linked list of these objects.
*/
typedef struct RunQueue_t {
int blocked;
struct RunQueue_t *next;
struct RunQueue_t *prev;
} RunQueue;
typedef struct {
typedef struct {
int32_t x, y;
uint32_t w, h;
} CRScreenInfo;
typedef struct {
/* BFB (BlitFramebuffer Blitter) flags
* so far only CR_SERVER_BFB_ON_ALWAIS is supported and is alwais used if any flag is set */
#define CR_SERVER_BFB_DISABLED 0
#define CR_SERVER_BFB_ON_INVERTED_BLIT 1
#define CR_SERVER_BFB_ON_STRAIGHT_BLIT 2
typedef struct {
unsigned short tcpip_port;
int screenCount;
int numClients;
int client_spu_id;
int mtu;
int buffer_size;
char protocol[1024];
/* visBits -> dummy mural association */
/* we need to translate Root Vr to each window coords, this one cpecifies the current translation point
* note that since window attributes modifications is performed in HGCM thread only and thus is serialized,
* we deal with the global RootVr data directly */
/* blitter so far used for working around host drivers BlitFramebuffer bugs
* by implementing */
/** configuration options */
/*@{*/
int useL2;
int ignore_papi;
unsigned int maxBarrierCount;
unsigned int clearCount;
int optimizeBucket;
int only_swap_once;
int debug_barriers;
int sharedDisplayLists;
int sharedTextureObjects;
int sharedPrograms;
int sharedWindows;
int uniqueWindows;
int localTileSpec;
int useDMX;
int overlapBlending;
const char *vpProjectionMatrixVariable;
int stereoView;
int vncMode; /* cmd line option */
/*@}*/
/** view_matrix config */
/*@{*/
/*@}*/
/** projection_matrix config */
/*@{*/
int currentEye;
/*@}*/
/** for warped tiles */
/*@{*/
/*@}*/
/*@{*/
float *overlap_intens;
int num_overlap_intens;
int num_overlap_levels;
/*@}*/
/* OR-ed CR_VBOX_CAP_XXX cap values
* describing VBox Chromium functionality caps visible to guest
* Currently can have only CR_VBOX_CAP_TEX_PRESENT cap to notify
* that the TexPresent mechanism is available and enabled */
#ifdef VBOX_WITH_CRSERVER_DUMPER
#endif
int RcToGuest;
int RcToGuestOnce;
} CRServer;
extern DECLEXPORT(void) crServerServiceClients(void);
extern DECLEXPORT(void) crServerAddNewClient(void);
extern DECLEXPORT(void) crVBoxServerTearDown(void);
extern DECLEXPORT(int32_t) crVBoxServerClientWrite(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t cbBuffer);
extern DECLEXPORT(int32_t) crVBoxServerClientRead(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t *pcbBuffer);
extern DECLEXPORT(int32_t) crVBoxServerClientSetVersion(uint32_t u32ClientID, uint32_t vMajor, uint32_t vMinor);
extern DECLEXPORT(int32_t) crVBoxServerClientGetCapsLegacy(uint32_t u32ClientID, uint32_t *pu32Caps);
typedef struct
{
extern DECLEXPORT(int) crServerVBoxScreenshotGet(uint32_t u32Screen, uint32_t width, uint32_t height, uint32_t pitch, void *pvBuffer, CR_SCREENSHOT *pScreenshot);
extern DECLEXPORT(int32_t) crVBoxServerMapScreen(int sIndex, int32_t x, int32_t y, uint32_t w, uint32_t h, uint64_t winID);
struct VBVAINFOSCREEN;
extern DECLEXPORT(int) crVBoxServerNotifyResize(const struct VBVAINFOSCREEN *pScreen, void *pvVRAM);
extern DECLEXPORT(int32_t) crVBoxServerSetScreenViewport(int sIndex, int32_t x, int32_t y, uint32_t w, uint32_t h);
#ifdef VBOX_WITH_CRHGSMI
/* We moved all CrHgsmi command processing to crserverlib to keep the logic of dealing with CrHgsmi commands in one place.
*
* 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.
* This help avoiding the "blocked-client" issues. The client is blocked if another client is doing begin-end stuff.
* For now we eliminated polling that could occur on block, which caused a higher-priority thread (in guest) polling for the blocked command complition
* to block the lower-priority thread trying to complete the blocking command.
* And removed extra memcpy done on blocked command arrival.
*
* In the future we will extend CrHgsmi functionality to maintain texture data directly in CrHgsmi allocation to avoid extra memcpy-ing with PBO,
* implement command completion and stuff necessary for GPU scheduling to work properly for WDDM Windows guests, etc.
*
* NOTE: it is ALWAYS responsibility of the crVBoxServerCrHgsmiCmd to complete the command!
* */
extern DECLEXPORT(int32_t) crVBoxServerCrHgsmiCmd(struct VBOXVDMACMD_CHROMIUM_CMD *pCmd, uint32_t cbCmd);
extern DECLEXPORT(int32_t) crVBoxServerCrHgsmiCtl(struct VBOXVDMACMD_CHROMIUM_CTL *pCtl, uint32_t cbCtl);
#endif
#ifdef __cplusplus
}
#endif
#endif