VirtualBox

Changeset 44105 in vbox for trunk


Ignore:
Timestamp:
Dec 12, 2012 11:59:06 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82650
Message:

crOpenGL: client state fix, other state fixes

Location:
trunk/src/VBox/GuestHost/OpenGL
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h

    r43980 r44105  
    6060# define CR_STATE_SHAREDOBJ_USAGE_CLEAR(_pObj, _pCtx) (ASMBitClear((_pObj)->ctxUsage, (_pCtx)->id))
    6161# define CR_STATE_SHAREDOBJ_USAGE_IS_USED(_pObj) (ASMBitFirstSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3) >= 0)
     62# define CR_STATE_SHAREDOBJ_USAGE_GET_FIRST_USED_IDX(_pObj) (ASMBitFirstSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3))
     63# define CR_STATE_SHAREDOBJ_USAGE_GET_NEXT_USED_IDX(_pObj, _i) (ASMBitNextSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3, (_i)))
    6264#else
    6365# define CR_STATE_SHAREDOBJ_USAGE_INIT(_pObj) do {} while (0)
     
    6567# define CR_STATE_SHAREDOBJ_USAGE_CLEAR(_pObj, _pCtx) do {} while (0)
    6668# define CR_STATE_SHAREDOBJ_USAGE_IS_USED(_pObj) (GL_FALSE)
    67 #endif
     69# define CR_STATE_SHAREDOBJ_USAGE_GET_FIRST_USED_IDX(_pObj) (-1)
     70# define CR_STATE_SHAREDOBJ_USAGE_GET_NEXT_USED_IDX(_pObj, _i) (-1)
     71#endif
     72# define CR_STATE_SHAREDOBJ_USAGE_FOREACH_USED_IDX(_pObj, _i) for (((int)(_i)) = CR_STATE_SHAREDOBJ_USAGE_GET_FIRST_USED_IDX(_pObj); ((int)(_i)) >= 0; ((int)(_i)) = CR_STATE_SHAREDOBJ_USAGE_GET_NEXT_USED_IDX((_pObj), ((int)(_i))))
    6873
    6974#define CR_MAX_EXTENTS 256
     
    241246typedef FNCRSTATE_CONTEXT_GET *PFNCRSTATE_CONTEXT_GET;
    242247DECLEXPORT(int32_t) crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM, uint32_t u32Version);
    243 DECLEXPORT(void)    crStateFreeShared(CRContext *pContext, CRSharedState *s);
    244248DECLEXPORT(void) crStateFreeShared(CRContext *pContext, CRSharedState *s);
    245249#endif
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_client.h

    r33540 r44105  
    128128DECLEXPORT(void) crStateClientInitBits(CRClientBits *c);
    129129DECLEXPORT(void) crStateClientDestroyBits(CRClientBits *c);
    130 DECLEXPORT(void) crStateClientInit(CRClientState *c);
    131 DECLEXPORT(void) crStateClientDestroy(CRClientState *c);
     130DECLEXPORT(void) crStateClientInit(struct CRContext *g);
     131DECLEXPORT(void) crStateClientDestroy(struct CRContext *g);
    132132
    133133DECLEXPORT(GLboolean) crStateUseServerArrays(void);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state.h

    r44059 r44105  
    4444#endif
    4545
     46extern GLboolean g_bVBoxEnableDiffOnMakeCurrent;
     47
     48extern CRContext *g_pAvailableContexts[CR_MAX_CONTEXTS];
     49
    4650extern void crStateTextureInitTextureObj (CRContext *ctx, CRTextureObj *tobj, GLuint name, GLenum target);
    4751extern void crStateTextureInitTextureFormat( CRTextureLevel *tl, GLenum internalFormat );
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_bufferobject.c

    r44083 r44105  
    115115    b->arrayBuffer = b->nullBuffer;
    116116    b->elementsBuffer = b->nullBuffer;
    117     b->nullBuffer->refCount = 3;
     117    b->nullBuffer->refCount += 2;
    118118#ifdef CR_ARB_pixel_buffer_object
    119119    b->packBuffer = b->nullBuffer;
     
    272272}
    273273
     274static void ctStateBuffersRefsCleanup(CRContext *ctx, CRBufferObject *obj, CRbitvalue *neg_bitid)
     275{
     276    CRBufferObjectState *b = &(ctx->bufferobject);
     277    CRStateBits *sb = GetCurrentBits();
     278    CRBufferObjectBits *bb = &(sb->bufferobject);
     279    int j, k;
     280
     281    if (obj == b->arrayBuffer)
     282    {
     283        b->arrayBuffer = b->nullBuffer;
     284        b->arrayBuffer->refCount++;
     285        DIRTY(bb->dirty, neg_bitid);
     286        DIRTY(bb->arrayBinding, neg_bitid);
     287    }
     288    if (obj == b->elementsBuffer)
     289    {
     290        b->elementsBuffer = b->nullBuffer;
     291        b->elementsBuffer->refCount++;
     292        DIRTY(bb->dirty, neg_bitid);
     293        DIRTY(bb->elementsBinding, neg_bitid);
     294    }
     295#ifdef CR_ARB_pixel_buffer_object
     296    if (obj == b->packBuffer)
     297    {
     298        b->packBuffer = b->nullBuffer;
     299        b->packBuffer->refCount++;
     300        DIRTY(bb->dirty, neg_bitid);
     301        DIRTY(bb->packBinding, neg_bitid);
     302    }
     303    if (obj == b->unpackBuffer)
     304    {
     305        b->unpackBuffer = b->nullBuffer;
     306        b->unpackBuffer->refCount++;
     307        DIRTY(bb->dirty, neg_bitid);
     308        DIRTY(bb->unpackBinding, neg_bitid);
     309    }
     310#endif
     311
     312#ifdef CR_ARB_vertex_buffer_object
     313    for (j=0; j<CRSTATECLIENT_MAX_VERTEXARRAYS; ++j)
     314    {
     315        CRClientPointer *cp = crStateGetClientPointerByIndex(j, &ctx->client.array);
     316        if (obj == cp->buffer)
     317        {
     318            cp->buffer = b->nullBuffer;
     319            ++b->nullBuffer->refCount;
     320        }
     321    }
     322
     323    for (k=0; k<ctx->client.vertexArrayStackDepth; ++k)
     324    {
     325        CRVertexArrays *pArray = &ctx->client.vertexArrayStack[k];
     326        for (j=0; j<CRSTATECLIENT_MAX_VERTEXARRAYS; ++j)
     327        {
     328            CRClientPointer *cp = crStateGetClientPointerByIndex(j, pArray);
     329            if (obj == cp->buffer)
     330            {
     331                cp->buffer = b->nullBuffer;
     332                ++b->nullBuffer->refCount;
     333            }
     334        }
     335    }
     336#endif
     337
     338#ifndef IN_GUEST
     339    CR_STATE_SHAREDOBJ_USAGE_CLEAR(obj, ctx);
     340#endif
     341}
     342
    274343void STATE_APIENTRY
    275344crStateDeleteBuffersARB(GLsizei n, const GLuint *buffers)
    276345{
    277346    CRContext *g = GetCurrentContext();
    278     CRBufferObjectState *b = &(g->bufferobject);
    279     CRStateBits *sb = GetCurrentBits();
    280     CRBufferObjectBits *bb = &(sb->bufferobject);
    281     int i, j, k;
     347    int i;
    282348
    283349    FLUSH();
     
    300366                crHashtableSearch(g->shared->buffersTable, buffers[i]);
    301367            if (obj) {
    302                 if (obj == b->arrayBuffer)
     368                int j;
     369
     370                ctStateBuffersRefsCleanup(g, obj, g->neg_bitid);
     371
     372                CR_STATE_SHAREDOBJ_USAGE_FOREACH_USED_IDX(obj, j)
    303373                {
    304                     b->arrayBuffer = b->nullBuffer;
    305                     b->arrayBuffer->refCount++;
    306                     DIRTY(bb->dirty, g->neg_bitid);
    307                     DIRTY(bb->arrayBinding, g->neg_bitid);
    308                 }
    309                 else if (obj == b->elementsBuffer)
    310                 {
    311                     b->elementsBuffer = b->nullBuffer;
    312                     b->elementsBuffer->refCount++;
    313                     DIRTY(bb->dirty, g->neg_bitid);
    314                     DIRTY(bb->elementsBinding, g->neg_bitid);
     374                    CRContext *ctx = g_pAvailableContexts[j];
     375                    CRASSERT(ctx);
     376                    ctStateBuffersRefsCleanup(ctx, obj, g->neg_bitid); /* <- yes, use g->neg_bitid, i.e. neg_bitid of the current context to ensure others bits get dirtified,
     377                                                                        * but not the current context ones*/
    315378                }
    316 #ifdef CR_ARB_pixel_buffer_object
    317                 else if (obj == b->packBuffer)
    318                 {
    319                     b->packBuffer = b->nullBuffer;
    320                     b->packBuffer->refCount++;
    321                     DIRTY(bb->dirty, g->neg_bitid);
    322                     DIRTY(bb->packBinding, g->neg_bitid);
    323                 }
    324                 else if (obj == b->unpackBuffer)
    325                 {
    326                     b->unpackBuffer = b->nullBuffer;
    327                     b->unpackBuffer->refCount++;
    328                     DIRTY(bb->dirty, g->neg_bitid);
    329                     DIRTY(bb->unpackBinding, g->neg_bitid);
    330                 }
    331 #endif
    332 
    333 #ifdef CR_ARB_vertex_buffer_object
    334                 for (j=0; j<CRSTATECLIENT_MAX_VERTEXARRAYS; ++j)
    335                 {
    336                     CRClientPointer *cp = crStateGetClientPointerByIndex(j, &g->client.array);
    337                     if (obj == cp->buffer)
    338                     {
    339                         cp->buffer = b->nullBuffer;
    340                         ++b->nullBuffer->refCount;
    341                     }
    342                 }
    343 
    344                 for (k=0; k<g->client.vertexArrayStackDepth; ++k)
    345                 {
    346                     CRVertexArrays *pArray = &g->client.vertexArrayStack[k];
    347                     for (j=0; j<CRSTATECLIENT_MAX_VERTEXARRAYS; ++j)
    348                     {
    349                         CRClientPointer *cp = crStateGetClientPointerByIndex(j, pArray);
    350                         if (obj == cp->buffer)
    351                         {
    352                             cp->buffer = b->nullBuffer;
    353                             ++b->nullBuffer->refCount;
    354                         }
    355                     }
    356                 }
    357 #endif
     379
    358380                crHashtableDelete(g->shared->buffersTable, buffers[i], crStateFreeBufferObject);
    359381            }
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_client.c

    r44052 r44105  
    8484}
    8585
    86 void crStateClientDestroy(CRClientState *c)
    87 {
     86void crStateClientDestroy(CRContext *g)
     87{
     88    CRClientState *c = &(g->client);
    8889#ifdef CR_EXT_compiled_vertex_array
    8990    if (c->array.locked)
     
    110111}
    111112
    112 void crStateClientInit(CRClientState *c)
    113 {
    114     CRContext *g = GetCurrentContext();
     113void crStateClientInit(CRContext *g)
     114{
     115    CRClientState *c = &(g->client);
    115116    unsigned int i;
    116117
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c

    r42499 r44105  
    1818
    1919CRStateBits *__currentBits = NULL;
    20 GLboolean g_availableContexts[CR_MAX_CONTEXTS];
     20CRContext *g_pAvailableContexts[CR_MAX_CONTEXTS];
    2121
    2222static CRSharedState *gSharedState=NULL;
     
    2424static CRContext *defaultContext = NULL;
    2525
    26 static GLboolean g_bVBoxEnableDiffOnMakeCurrent = GL_TRUE;
     26GLboolean g_bVBoxEnableDiffOnMakeCurrent = GL_TRUE;
    2727
    2828
     
    219219                                             GLint visBits, CRContext *shareCtx)
    220220{
    221     CRContext *ctx = (CRContext *) crCalloc( sizeof( *ctx ) );
     221    CRContext *ctx;
    222222    int j;
    223223    int node32 = i >> 5;
    224224    int node = i & 0x1f;
    225225
     226    if (g_pAvailableContexts[i] != NULL)
     227    {
     228        crWarning("trying to create context with used id");
     229        return NULL;
     230    }
     231
     232    ctx = (CRContext *) crCalloc( sizeof( *ctx ) );
     233    if (!ctx)
     234    {
     235        crWarning("failed to allocate context");
     236        return NULL;
     237    }
     238    g_pAvailableContexts[i] = ctx;
    226239    ctx->id = i;
    227240#ifdef CHROMIUM_THREADSAFE
     
    253266
    254267    crStateBufferObjectInit( ctx ); /* must precede client state init! */
    255     crStateClientInit( &(ctx->client) );
     268    crStateClientInit( ctx );
    256269
    257270    crStateBufferInit( ctx );
     
    331344crStateFreeContext(CRContext *ctx)
    332345{
    333     crStateClientDestroy( &(ctx->client) );
     346    CRASSERT(g_pAvailableContexts[ctx->id] == ctx);
     347    if (ctx->id || ctx == defaultContext)
     348        g_pAvailableContexts[ctx->id] = NULL;
     349
     350    crStateClientDestroy( ctx );
    334351    crStateLimitsDestroy( &(ctx->limits) );
    335352    crStateBufferObjectDestroy( ctx );
     
    381398
    382399    for (i=0;i<CR_MAX_CONTEXTS;i++)
    383         g_availableContexts[i] = 0;
     400        g_pAvailableContexts[i] = NULL;
    384401
    385402#ifdef CHROMIUM_THREADSAFE
     
    413430
    414431    /* Allocate the default/NULL context */
     432    CRASSERT(g_pAvailableContexts[0] == NULL);
    415433    defaultContext = crStateCreateContextId(0, NULL, CR_RGB_BIT, NULL);
    416     CRASSERT(g_availableContexts[0] == 0);
    417     g_availableContexts[0] = 1; /* in use forever */
     434    g_pAvailableContexts[0] = defaultContext; /* in use forever */
    418435
    419436#ifdef CHROMIUM_THREADSAFE
     
    426443void crStateDestroy(void)
    427444{
     445    int i;
    428446    if (__currentBits)
    429447    {
     
    433451        __currentBits = NULL;
    434452    }
     453
     454    SetCurrentContext(NULL);
     455
     456    for (i = CR_MAX_CONTEXTS-1; i >= 0; i--)
     457    {
     458        if (g_pAvailableContexts[i])
     459        {
     460#ifdef CHROMIUM_THREADSAFE
     461            if (VBoxTlsRefIsFunctional(g_pAvailableContexts[i]))
     462                VBoxTlsRefRelease(g_pAvailableContexts[i]);
     463#else
     464            crStateFreeContext(g_pAvailableContexts[i]);
     465#endif
     466        }
     467    }
     468
     469    /* default context was stored in g_pAvailableContexts[0], so it was destroyed already */
     470    defaultContext = NULL;
     471
    435472
    436473#ifdef CHROMIUM_THREADSAFE
     
    486523crStateCreateContext(const CRLimitsState *limits, GLint visBits, CRContext *share)
    487524{
    488     int i;
    489 
     525    return crStateCreateContextEx(limits, visBits, share, -1);
     526}
     527
     528CRContext *
     529crStateCreateContextEx(const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID)
     530{
    490531    /* Must have created the default context via crStateInit() first */
    491532    CRASSERT(defaultContext);
    492533
    493     for (i = 1 ; i < CR_MAX_CONTEXTS ; i++)
    494     {
    495         if (!g_availableContexts[i])
    496         {
    497             g_availableContexts[i] = 1; /* it's no longer available */
    498             return crStateCreateContextId( i, limits, visBits, share );
    499         }
    500     }
    501     crError( "Out of available contexts in crStateCreateContexts (max %d)",
    502                      CR_MAX_CONTEXTS );
    503     /* never get here */
    504     return NULL;
    505 }
    506 
    507 CRContext *
    508 crStateCreateContextEx(const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID)
    509 {
    510534    if (presetID>0)
    511535    {
    512         CRASSERT(!g_availableContexts[presetID]);
    513         g_availableContexts[presetID] = 1;
    514         return crStateCreateContextId(presetID, limits, visBits, share);
    515     }
    516     else return crStateCreateContext(limits, visBits, share);
     536        if(g_pAvailableContexts[presetID])
     537        {
     538            crWarning("requesting to create context with already allocated id");
     539            return NULL;
     540        }
     541    }
     542    else
     543    {
     544        int i;
     545
     546        for (i = 1 ; i < CR_MAX_CONTEXTS ; i++)
     547        {
     548            if (!g_pAvailableContexts[i])
     549            {
     550                presetID = i;
     551                break;
     552            }
     553        }
     554
     555        if (presetID<=0)
     556        {
     557            crError( "Out of available contexts in crStateCreateContexts (max %d)",
     558                             CR_MAX_CONTEXTS );
     559            /* never get here */
     560            return NULL;
     561        }
     562    }
     563
     564    return crStateCreateContextId(presetID, limits, visBits, share);
    517565}
    518566
     
    536584        crStateMatrixMode(defaultContext->transform.matrixMode);
    537585    }
    538     g_availableContexts[ctx->id] = 0;
    539 
    540 #ifdef CHROMIUM_THREADSAFE
     586
     587#ifdef CHROMIUM_THREADSAFE
     588    VBoxTlsRefMarkDestroy(ctx);
    541589    VBoxTlsRefRelease(ctx);
    542590#else
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texture.c

    r44059 r44105  
    736736    }
    737737
     738    CR_STATE_SHAREDOBJ_USAGE_CLEAR(tObj, g);
    738739}
    739740
     
    769770        if (name && tObj)
    770771        {
     772            GLuint j;
     773
    771774            crStateCleanupTextureRefs(g, tObj);
     775
     776            CR_STATE_SHAREDOBJ_USAGE_FOREACH_USED_IDX(tObj, j)
     777            {
     778                CRContext *ctx = g_pAvailableContexts[j];
     779                crStateCleanupTextureRefs(ctx, tObj);
     780            }
    772781
    773782            /* on the host side, ogl texture object is deleted by a separate cr_server.head_spu->dispatch_table.DeleteTextures(n, newTextures);
     
    875884        CRTextureBits *tb = &(sb->texture);
    876885        CRTextureState *t = &(g->texture);
    877 
    878         CR_STATE_SHAREDOBJ_USAGE_CLEAR(tobj, g);
    879886
    880887        crStateCleanupTextureRefs(g, tobj);
Note: See TracChangeset for help on using the changeset viewer.

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