VirtualBox

Changeset 54659 in vbox


Ignore:
Timestamp:
Mar 5, 2015 9:32:14 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
98807
Message:

DevVGA-SVGA3d-ogl.cpp: Attempt to deal with annoying assertions in for example vmsvga3dSurfaceStretchBlt after surfaces have been ophaned by vmsvga3dContextDestroy.

Location:
trunk/src/VBox/Devices/Graphics
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA.cpp

    r54641 r54659  
    29302930                        VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
    29312931
    2932                         rc = vmsvga3dContextDefine(pThis, pCmd->cid, false /*fOtherProfile*/);
     2932                        rc = vmsvga3dContextDefine(pThis, pCmd->cid);
    29332933                        break;
    29342934                    }
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp

    r54658 r54659  
    9191
    9292
    93 /* Generated by VBoxDef2LazyLoad from the VBoxSVGA3D.def and VBoxSVGA3DObjC.def files. */
    94 extern "C" int ExplicitlyLoadVBoxSVGA3D(bool fResolveAllImports, PRTERRINFO pErrInfo);
    95 #ifdef RT_OS_DARWIN
    96 extern "C" int ExplicitlyLoadVBoxSVGA3DObjC(bool fResolveAllImports, PRTERRINFO pErrInfo);
    97 #endif
    98 
    99 
    10093/*******************************************************************************
    10194*   Defined Constants And Macros                                               *
    10295*******************************************************************************/
     96/** Experimental: Create a dedicated context for handling surfaces in, thus
     97 * avoiding orphaned surfaces after context destruction.
     98 *
     99 * This cures, for instance, an assertion on fedora 21 that happens in
     100 * vmsvga3dSurfaceStretchBlt if the login screen and the desktop has different
     101 * sizes.  The context of the login screen seems to have just been destroyed
     102 * earlier and I believe the driver/X/whoever is attemting to strech the old
     103 * screen content onto the new sized screen.
     104 *
     105 * @remarks This probably comes at a slight preformance expense, as we currently
     106 *          switches context when setting up the surface the first time.  Not sure
     107 *          if we really need to, but as this is an experiment, I'm playing it safe.
     108 */
     109#define VMSVGA3D_OGL_WITH_SHARED_CTX
     110#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     111/** Fake surface ID for the shared context. */
     112# define VMSVGA3D_SHARED_CTX_ID     UINT32_C(0xffffeeee)
     113#endif
     114
    103115/** @def VBOX_VMSVGA3D_GL_HACK_LEVEL
    104116 * Turns out that on Linux gl.h may often define the first 2-4 OpenGL versions
     
    146158//#define DEBUG_GFX_WINDOW
    147159
     160
     161/** @name VMSVGA3D_DEF_CTX_F_XXX - vmsvga3dContextDefineOgl flags.
     162 * @{ */
     163/** When clear, the  context is created using the default OpenGL profile.
     164 * When set, it's created using the alternative profile.  The latter is only
     165 * allowed if the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set.  */
     166#define VMSVGA3D_DEF_CTX_F_OTHER_PROFILE    RT_BIT_32(0)
     167/** Defining the shared context.  */
     168#define VMSVGA3D_DEF_CTX_F_SHARED_CTX       RT_BIT_32(1)
     169/** Defining the init time context (EMT).  */
     170#define VMSVGA3D_DEF_CTX_F_INIT             RT_BIT_32(2)
     171/** @} */
     172
     173
    148174#define VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState)                          \
    149175    do { (pState)->idActiveContext = OPENGL_INVALID_ID; } while (0)
     
    156182#ifdef RT_OS_WINDOWS
    157183# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
    158     if ((pState)->idActiveContext != pContext->id) \
     184    if ((pState)->idActiveContext != (pContext)->id) \
    159185    { \
    160186        BOOL fMakeCurrentRc = wglMakeCurrent((pContext)->hdc, (pContext)->hglrc); \
     
    470496{
    471497    uint32_t                id;
     498#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     499    uint32_t                idAssociatedContextUnused;
     500#else
    472501    uint32_t                idAssociatedContext;
     502#endif
    473503    uint32_t                flags;
    474504    SVGA3dSurfaceFormat     format;
     
    498528{
    499529    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, id),
     530#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     531    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, idAssociatedContextUnused),
     532#else
    500533    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, idAssociatedContext),
     534#endif
    501535    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, flags),
    502536    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, format),
     
    826860    /** Shader talk back interface. */
    827861    VBOXVMSVGASHADERIF      ShaderIf;
     862
     863#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     864    /** The shared context. */
     865    VMSVGA3DCONTEXT         SharedCtx;
     866#endif
    828867} VMSVGA3DSTATE;
    829868/** Pointer to the VMSVGA3d state. */
     
    909948*   Internal Functions                                                         *
    910949*******************************************************************************/
    911 RT_C_DECLS_BEGIN
    912 static int vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface);
     950static int  vmsvga3dCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface);
     951static int  vmsvga3dContextDefineOgl(PVGASTATE pThis, uint32_t cid, uint32_t fFlags);
    913952static void vmsvgaColor2GLFloatArray(uint32_t color, GLfloat *pRed, GLfloat *pGreen, GLfloat *pBlue, GLfloat *pAlpha);
    914 RT_C_DECLS_END
     953
     954/* Generated by VBoxDef2LazyLoad from the VBoxSVGA3D.def and VBoxSVGA3DObjC.def files. */
     955extern "C" int ExplicitlyLoadVBoxSVGA3D(bool fResolveAllImports, PRTERRINFO pErrInfo);
     956#ifdef RT_OS_DARWIN
     957extern "C" int ExplicitlyLoadVBoxSVGA3DObjC(bool fResolveAllImports, PRTERRINFO pErrInfo);
     958#endif
    915959
    916960
     
    13861430     * OpenGL function calls aren't possible without a valid current context, so create a fake one here.
    13871431     */
    1388     rc = vmsvga3dContextDefine(pThis, 1, false /*fOtherProfile*/);
     1432    rc = vmsvga3dContextDefineOgl(pThis, 1, VMSVGA3D_DEF_CTX_F_INIT);
    13891433    AssertRCReturn(rc, rc);
    13901434
     
    14111455     * figure out the shader model and stuff.
    14121456     */
    1413     rc = vmsvga3dContextDefine(pThis, 2, true /*fOtherProfile*/);
     1457    rc = vmsvga3dContextDefineOgl(pThis, 2, VMSVGA3D_DEF_CTX_F_INIT | VMSVGA3D_DEF_CTX_F_OTHER_PROFILE);
    14141458    AssertLogRelRCReturn(rc, rc);
    14151459    pContext = &pState->paContext[1]; /* Array may have been reallocated. */
     
    25872631    memset(pSurface, 0, sizeof(*pSurface));
    25882632    pSurface->id                    = sid;
     2633#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     2634    pSurface->idAssociatedContextUnused = SVGA3D_INVALID_ID;
     2635#else
    25892636    pSurface->idAssociatedContext   = SVGA3D_INVALID_ID;
     2637#endif
    25902638    vmsvga3dSurfaceFormat2OGL(pSurface, format);
    25912639
     
    27672815#endif
    27682816
     2817#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     2818        pContext = &pState->SharedCtx;
     2819        VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     2820#else
    27692821        /* @todo stricter checks for associated context */
    27702822        uint32_t cid = pSurface->idAssociatedContext;
     
    27902842            AssertReturn(pContext, VERR_INTERNAL_ERROR); /* otherwise crashes/fails; create temp context if this ever triggers! */
    27912843        }
     2844#endif
    27922845
    27932846        switch (pSurface->flags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP))
     
    30043057{
    30053058    GLint activeTexture = 0;
     3059#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     3060    uint32_t idPrevCtx = pState->idActiveContext;
     3061    pContext = &pState->SharedCtx;
     3062    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     3063#endif
    30063064
    30073065    glGenTextures(1, &pSurface->oglId.texture);
     
    30683126    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    30693127
     3128    pSurface->flags              |= SVGA3D_SURFACE_HINT_TEXTURE;
     3129#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    30703130    LogFlow(("vmsvga3dCreateTexture: sid=%x idAssociatedContext %#x -> %#x; oglId.texture=%#x\n",
    30713131             pSurface->id, pSurface->idAssociatedContext, idAssociatedContext, pSurface->oglId.texture));
    3072     pSurface->flags              |= SVGA3D_SURFACE_HINT_TEXTURE;
    30733132    pSurface->idAssociatedContext = idAssociatedContext;
     3133#endif
     3134
     3135#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     3136    if (idPrevCtx < pState->cContexts && pState->paContext[idPrevCtx].id == idPrevCtx)
     3137        VMSVGA3D_SET_CURRENT_CONTEXT(pState, &pState->paContext[idPrevCtx]);
     3138#endif
    30743139    return VINF_SUCCESS;
    30753140}
     
    30983163    AssertReturn(pSurfaceDest->faces[0].numMipLevels > dest.mipmap, VERR_INVALID_PARAMETER);
    30993164
     3165#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     3166    Log(("vmsvga3dSurfaceStretchBlt: src sid=%x (%d,%d)(%d,%d) dest sid=%x (%d,%d)(%d,%d) mode=%x\n",
     3167         src.sid, srcBox.x, srcBox.y, srcBox.x + srcBox.w, srcBox.y + srcBox.h,
     3168         dest.sid, destBox.x, destBox.y, destBox.x + destBox.w, destBox.y + destBox.h, mode));
     3169    cid = SVGA3D_INVALID_ID;
     3170    pContext = &pState->SharedCtx;
     3171    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     3172#else
    31003173    Log(("vmsvga3dSurfaceStretchBlt: src sid=%x cid=%x (%d,%d)(%d,%d) dest sid=%x cid=%x (%d,%d)(%d,%d) mode=%x\n",
    31013174         src.sid, pSurfaceSrc->idAssociatedContext, srcBox.x, srcBox.y, srcBox.x + srcBox.w, srcBox.y + srcBox.h,
     
    31153188    pContext = &pState->paContext[cid];
    31163189    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     3190#endif
    31173191
    31183192    if (pSurfaceSrc->oglId.texture == OPENGL_INVALID_ID)
     
    33813455    else
    33823456    {
     3457#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     3458        PVMSVGA3DCONTEXT pContext = &pState->SharedCtx;
     3459#else
    33833460        /* @todo stricter checks for associated context */
    33843461        uint32_t cid = pSurface->idAssociatedContext;
     
    33903467        }
    33913468        PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
     3469#endif
    33923470        VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
    33933471
     
    37133791
    37143792    pSurface = &pState->paSurface[sid];
     3793#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    37153794    AssertReturn(pSurface->idAssociatedContext != SVGA3D_INVALID_ID, VERR_INTERNAL_ERROR);
     3795#endif
    37163796
    37173797    Assert(filter != SVGA3D_TEX_FILTER_FLATCUBIC);
     
    37213801    Log(("vmsvga3dGenerateMipmaps: sid=%x filter=%d\n", sid, filter));
    37223802
     3803#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     3804    cid = SVGA3D_INVALID_ID;
     3805    pContext = &pState->SharedCtx;
     3806    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     3807#else
    37233808    /* @todo stricter checks for associated context */
    37243809    cid = pSurface->idAssociatedContext;
     
    37323817    pContext = &pState->paContext[cid];
    37333818    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     3819#endif
    37343820
    37353821    if (pSurface->oglId.texture == OPENGL_INVALID_ID)
     
    37843870
    37853871    pSurface = &pState->paSurface[sid];
     3872#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    37863873    AssertReturn(pSurface->idAssociatedContext != SVGA3D_INVALID_ID, VERR_INTERNAL_ERROR);
    3787 
     3874#endif
     3875
     3876#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     3877    /* @todo stricter checks for associated context */
     3878    Log(("vmsvga3dCommandPresent: sid=%x cRects=%d\n", sid, cRects));
     3879    for (uint32_t i=0; i < cRects; i++)
     3880        Log(("vmsvga3dCommandPresent: rectangle %d src=(%d,%d) (%d,%d)(%d,%d)\n", i, pRect[i].srcx, pRect[i].srcy, pRect[i].x, pRect[i].y, pRect[i].x + pRect[i].w, pRect[i].y + pRect[i].h));
     3881
     3882    cid = SVGA3D_INVALID_ID;
     3883    pContext = &pState->SharedCtx;
     3884    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     3885#else
    37883886    /* @todo stricter checks for associated context */
    37893887    cid = pSurface->idAssociatedContext;
     
    38023900    pContext = &pState->paContext[cid];
    38033901    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     3902#endif
    38043903
    38053904    /* Source surface different size? */
     
    40834182 * @param   pThis           VGA device instance data.
    40844183 * @param   cid             Context id
    4085  * @param   fOtherProfile   When clear, the context is created using the default
    4086  *                          OpenGL profile.  When set, it's created using the
    4087  *                          alternative profile.  The latter is only allowed if
    4088  *                          the VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE is set.
     4184 * @param   fFlags          VMSVGA3D_DEF_CTX_F_XXX.
    40894185 */
    4090 int vmsvga3dContextDefine(PVGASTATE pThis, uint32_t cid, bool fOtherProfile)
     4186static int vmsvga3dContextDefineOgl(PVGASTATE pThis, uint32_t cid, uint32_t fFlags)
    40914187{
    40924188    int                     rc;
     
    40954191
    40964192    AssertReturn(pState, VERR_NO_MEMORY);
     4193#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     4194    AssertReturn(   cid < SVGA3D_MAX_CONTEXT_IDS
     4195                 || (cid == VMSVGA3D_SHARED_CTX_ID && (fFlags & VMSVGA3D_DEF_CTX_F_SHARED_CTX)), VERR_INVALID_PARAMETER);
     4196#else
    40974197    AssertReturn(cid < SVGA3D_MAX_CONTEXT_IDS, VERR_INVALID_PARAMETER);
     4198#endif
    40984199#if !defined(VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE) || !(defined(RT_OS_DARWIN))
    4099     AssertReturn(!fOtherProfile, VERR_INTERNAL_ERROR_3);
     4200    AssertReturn(!(fFlags & VMSVGA3D_DEF_CTX_F_OTHER_PROFILE), VERR_INTERNAL_ERROR_3);
    41004201#endif
    41014202
     
    41054206    {
    41064207        pState->idTestContext = 207;
    4107         rc = vmsvga3dContextDefine(pThis, pState->idTestContext, false /*fOtherProfile*/);
     4208        rc = vmsvga3dContextDefine(pThis, pState->idTestContext);
    41084209        AssertRCReturn(rc, rc);
    41094210    }
    41104211#endif
    41114212
    4112     if (cid >= pState->cContexts)
    4113     {
    4114         pState->paContext = (PVMSVGA3DCONTEXT)RTMemRealloc(pState->paContext, sizeof(VMSVGA3DCONTEXT) * (cid + 1));
    4115         AssertReturn(pState->paContext, VERR_NO_MEMORY);
    4116         memset(&pState->paContext[pState->cContexts], 0, sizeof(VMSVGA3DCONTEXT) * (cid + 1 - pState->cContexts));
    4117         for (uint32_t i = pState->cContexts; i < cid + 1; i++)
    4118             pState->paContext[i].id = SVGA3D_INVALID_ID;
    4119 
    4120         pState->cContexts = cid + 1;
    4121     }
    4122     /* If one already exists with this id, then destroy it now. */
    4123     if (pState->paContext[cid].id != SVGA3D_INVALID_ID)
    4124         vmsvga3dContextDestroy(pThis, cid);
    4125 
    4126     pContext = &pState->paContext[cid];
     4213#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     4214    if (cid == VMSVGA3D_SHARED_CTX_ID)
     4215        pContext = &pState->SharedCtx;
     4216    else
     4217#endif
     4218    {
     4219        if (cid >= pState->cContexts)
     4220        {
     4221            pState->paContext = (PVMSVGA3DCONTEXT)RTMemRealloc(pState->paContext, sizeof(VMSVGA3DCONTEXT) * (cid + 1));
     4222            AssertReturn(pState->paContext, VERR_NO_MEMORY);
     4223            memset(&pState->paContext[pState->cContexts], 0, sizeof(VMSVGA3DCONTEXT) * (cid + 1 - pState->cContexts));
     4224            for (uint32_t i = pState->cContexts; i < cid + 1; i++)
     4225                pState->paContext[i].id = SVGA3D_INVALID_ID;
     4226
     4227            pState->cContexts = cid + 1;
     4228        }
     4229        /* If one already exists with this id, then destroy it now. */
     4230        if (pState->paContext[cid].id != SVGA3D_INVALID_ID)
     4231            vmsvga3dContextDestroy(pThis, cid);
     4232
     4233        pContext = &pState->paContext[cid];
     4234    }
     4235
     4236    /*
     4237     * Find the shared context (necessary for sharing e.g. textures between contexts).
     4238     */
     4239#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     4240    PVMSVGA3DCONTEXT pSharedCtx = NULL;
     4241    if (!(fFlags & (VMSVGA3D_DEF_CTX_F_INIT | VMSVGA3D_DEF_CTX_F_SHARED_CTX)))
     4242    {
     4243        pSharedCtx = &pState->SharedCtx;
     4244        if (pSharedCtx->id != VMSVGA3D_SHARED_CTX_ID)
     4245        {
     4246            rc = vmsvga3dContextDefineOgl(pThis, VMSVGA3D_SHARED_CTX_ID, VMSVGA3D_DEF_CTX_F_SHARED_CTX);
     4247            AssertLogRelRCReturn(rc, rc);
     4248        }
     4249    }
     4250#else
     4251    // TODO isn't this default on Linux since OpenGL 1.1?
     4252    /* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
     4253    PVMSVGA3DCONTEXT pSharedCtx = NULL;
     4254    for (uint32_t i = 0; i < pState->cContexts; i++)
     4255        if (   pState->paContext[i].id != SVGA3D_INVALID_ID
     4256            && i != cid
     4257# ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE
     4258            && pState->paContext[i].fOtherProfile == RT_BOOL(fFlags & VMSVGA3D_DEF_CTX_F_OTHER_PROFILE)
     4259# endif
     4260           )
     4261        {
     4262            Log(("Sharing display lists between cid=%d and cid=%d\n", pContext->id, i));
     4263            pSharedCtx = &pState->paContext[i];
     4264            break;
     4265        }
     4266#endif
     4267
     4268    /*
     4269     * Initialize the context.
     4270     */
    41274271    memset(pContext, 0, sizeof(*pContext));
    41284272    pContext->id                = cid;
     
    42104354    AssertMsgReturn(pContext->hglrc, ("wglCreateContext %x failed with %d\n", pContext->hdc, GetLastError()), VERR_INTERNAL_ERROR);
    42114355
    4212     // TODO isn't this default on Linux since OpenGL 1.1?
    4213     /* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
    4214     for (uint32_t i = 0; i < pState->cContexts; i++)
    4215     {
    4216         if (    pState->paContext[i].id != SVGA3D_INVALID_ID
    4217             &&  i != pContext->id)
    4218         {
    4219             Log(("Sharing display lists between cid=%d and cid=%d\n", pContext->id, i));
    4220             ret = wglShareLists(pState->paContext[i].hglrc, pContext->hglrc);
    4221             Assert(ret == TRUE);
    4222             break;
    4223         }
     4356    if (pSharedCtx)
     4357    {
     4358        ret = wglShareLists(pSharedCtx->hglrc, pContext->hglrc);
     4359        AssertMsg(ret == TRUE, ("wglShareLists(%p, %p) failed with %d\n", pSharedCtx->hglrc, pContext->hglrc, GetLastError()));
    42244360    }
    42254361
    42264362#elif defined(RT_OS_DARWIN)
    4227     pContext->fOtherProfile = fOtherProfile;
    4228 
    4229     /* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
    4230     NativeNSOpenGLContextRef shareContext = NULL;
    4231     for (uint32_t i = 0; i < pState->cContexts; i++)
    4232     {
    4233         if (    pState->paContext[i].id != SVGA3D_INVALID_ID
    4234             &&  i != pContext->id
    4235             &&  pState->paContext[i].fOtherProfile == fOtherProfile)
    4236         {
    4237             Log(("Sharing display lists between cid=%d and cid=%d\n", pContext->id, i));
    4238             shareContext = pState->paContext[i].cocoaContext;
    4239             break;
    4240         }
    4241     }
    4242     vmsvga3dCocoaCreateContext(&pContext->cocoaContext, shareContext, fOtherProfile);
     4363    pContext->fOtherProfile = RT_BOOL(fFlags & VMSVGA3D_DEF_CTX_F_OTHER_PROFILE);
     4364
     4365    NativeNSOpenGLContextRef shareContext = pSharedCtx ? pSharedCtx->cocoaContext : NULL;
     4366    vmsvga3dCocoaCreateContext(&pContext->cocoaContext, shareContext, pContext->fOtherProfile);
    42434367    NativeNSViewRef pHostView = (NativeNSViewRef)pThis->svga.u64HostWindowId;
    42444368    vmsvga3dCocoaCreateView(&pContext->cocoaView, pHostView);
     
    42894413    /* the window is hidden by default and only mapped when CommandPresent is executed on it */
    42904414
    4291     /* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
    4292     GLXContext shareContext = NULL;
    4293     for (uint32_t i = 0; i < pState->cContexts; i++)
    4294     {
    4295         if (    pState->paContext[i].id != SVGA3D_INVALID_ID
    4296             &&  i != pContext->id)
    4297         {
    4298             Log(("Sharing display lists between cid=%d and cid=%d\n", pContext->id, i));
    4299             shareContext = pState->paContext[i].glxContext;
    4300             break;
    4301         }
    4302     }
    4303 
     4415    GLXContext shareContext = pSharedCtx ? pSharedCtx->glxContext : NULL;
    43044416    pContext->glxContext = glXCreateContext(pState->display, vi, shareContext, GL_TRUE);
    43054417    AssertMsgReturn(pContext->glxContext, ("glXCreateContext failed"), VERR_INTERNAL_ERROR);
     
    43464458}
    43474459
     4460
     4461/**
     4462 * Create a new 3d context
     4463 *
     4464 * @returns VBox status code.
     4465 * @param   pThis           VGA device instance data.
     4466 * @param   cid             Context id
     4467 */
     4468int vmsvga3dContextDefine(PVGASTATE pThis, uint32_t cid)
     4469{
     4470    return vmsvga3dContextDefineOgl(pThis, cid, 0/*fFlags*/);
     4471}
     4472
     4473
    43484474/**
    43494475 * Destroy an existing 3d context
     
    43984524        }
    43994525
    4400 #if 1 /* This is done on windows - prevents various assertions at runtime, as well as shutdown & reset assertions when destroying surfaces. */
     4526#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX /* This is done on windows - prevents various assertions at runtime, as well as shutdown & reset assertions when destroying surfaces. */
    44014527        /* Check for all surfaces that are associated with this context to remove all dependencies */
    44024528        for (uint32_t sid = 0; sid < pState->cSurfaces; sid++)
     
    56725798        {
    56735799            Log(("vmsvga3dSetRenderTarget: create renderbuffer to be used as render target; surface id=%x type=%d format=%d\n", target.sid, pRenderTarget->flags, pRenderTarget->internalFormatGL));
     5800#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     5801            pContext = &pState->SharedCtx;
     5802            VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     5803#endif
    56745804            pState->ext.glGenRenderbuffers(1, &pRenderTarget->oglId.renderbuffer);
    56755805            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     
    56845814            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    56855815
     5816#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     5817            pState->ext.glBindRenderbuffer(GL_RENDERBUFFER, OPENGL_INVALID_ID);
     5818            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     5819
     5820            pContext = &pState->paContext[cid];
     5821            VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     5822#else
    56865823            LogFlow(("vmsvga3dSetRenderTarget: sid=%x idAssociatedContext %#x -> %#x\n", pRenderTarget->id, pRenderTarget->idAssociatedContext, cid));
    56875824            pRenderTarget->idAssociatedContext = cid;
    5688         }
     5825#endif
     5826        }
     5827#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    56895828        else
     5829#endif
    56905830        {
    56915831            pState->ext.glBindRenderbuffer(GL_RENDERBUFFER, pRenderTarget->oglId.renderbuffer);
    56925832            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    56935833        }
     5834#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    56945835        Assert(pRenderTarget->idAssociatedContext == cid);
     5836#endif
    56955837        Assert(!pRenderTarget->fDirty);
    56965838        AssertReturn(pRenderTarget->oglId.texture != OPENGL_INVALID_ID, VERR_INVALID_PARAMETER);
     
    60206162                if (pSurface->oglId.texture == OPENGL_INVALID_ID)
    60216163                {
     6164#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    60226165                    Assert(pSurface->idAssociatedContext == SVGA3D_INVALID_ID);
     6166#endif
    60236167                    Log(("CreateTexture (%d,%d) level=%d\n", pSurface->pMipmapLevels[0].size.width, pSurface->pMipmapLevels[0].size.height, pSurface->faces[0].numMipLevels));
    60246168                    int rc = vmsvga3dCreateTexture(pState, pContext, cid, pSurface);
     
    67516895    {
    67526896        Log(("vmsvga3dDrawPrimitives: create vertex buffer fDirty=%d size=%x bytes\n", pVertexSurface->fDirty, pVertexSurface->pMipmapLevels[0].cbSurface));
     6897#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     6898        PVMSVGA3DCONTEXT pSavedCtx = pContext;
     6899        pContext = &pState->SharedCtx;
     6900        VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     6901#endif
     6902
    67536903        pState->ext.glGenBuffers(1, &pVertexSurface->oglId.buffer);
    67546904        VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     
    67666916
    67676917        pVertexSurface->flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
    6768     }
     6918
     6919#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     6920        pState->ext.glBindBuffer(GL_ARRAY_BUFFER, OPENGL_INVALID_ID);
     6921        VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     6922
     6923        pContext = pSavedCtx;
     6924        VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     6925#endif
     6926    }
     6927#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    67696928    else
     6929#endif
    67706930    {
    67716931        Assert(pVertexSurface->fDirty == false);
     
    67736933        VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    67746934    }
     6935#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    67756936    pVertexSurface->idAssociatedContext = pContext->id;
    67766937    LogFlow(("vmsvga3dDrawPrimitivesProcessVertexDecls: sid=%x idAssociatedContext %#x -> %#x\n", pVertexSurface->id, pVertexSurface->idAssociatedContext, pContext->id));
     6938#endif
    67776939
    67786940    /* Setup the vertex declarations. */
     
    70517213            {
    70527214                Log(("vmsvga3dDrawPrimitives: create index buffer fDirty=%d size=%x bytes\n", pIndexSurface->fDirty, pIndexSurface->pMipmapLevels[0].cbSurface));
     7215#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     7216                pContext = &pState->SharedCtx;
     7217                VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     7218#endif
    70537219
    70547220                pState->ext.glGenBuffers(1, &pIndexSurface->oglId.buffer);
     
    70687234
    70697235                pIndexSurface->flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
     7236
     7237#ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     7238                pState->ext.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OPENGL_INVALID_ID);
     7239                VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     7240
     7241                pContext = &pState->paContext[cid];
     7242                VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     7243#endif
    70707244            }
     7245#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    70717246            else
     7247#endif
    70727248            {
    70737249                Assert(pIndexSurface->fDirty == false);
     
    70767252                VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    70777253            }
     7254#ifndef VMSVGA3D_OGL_WITH_SHARED_CTX
    70787255            LogFlow(("vmsvga3dDrawPrimitives: sid=%x idAssociatedContext %#x -> %#x\n", pIndexSurface->id, pIndexSurface->idAssociatedContext, pContext->id));
    70797256            pIndexSurface->idAssociatedContext = pContext->id;
     7257#endif
    70807258        }
    70817259
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-shared.h

    r53755 r54659  
    4949            uint32_t cPixelShaderConst, cVertexShaderConst, cPixelShaders, cVertexShaders;
    5050
    51             rc = vmsvga3dContextDefine(pThis, cid, false /*fOtherProfile*/);
     51            rc = vmsvga3dContextDefine(pThis, cid);
    5252            AssertRCReturn(rc, rc);
    5353
     
    648648                        void *pData = NULL;
    649649
     650# ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
     651                        PVMSVGA3DCONTEXT pContext = &pState->SharedCtx;
     652                        VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     653# else
    650654                        /* @todo stricter checks for associated context */
    651655                        uint32_t cid = pSurface->idAssociatedContext;
     
    658662                        PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
    659663                        VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     664# endif
    660665
    661666                        Assert(pMipmapLevel->cbSurface);
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp

    r53780 r54659  
    29032903 * @param   pThis           VGA device instance data.
    29042904 * @param   cid             Context id
    2905  * @param   fOtherProfile   OpenGL(+darwin) specific argument, ignored.
    29062905 */
    2907 int vmsvga3dContextDefine(PVGASTATE pThis, uint32_t cid, bool fOtherProfile)
     2906int vmsvga3dContextDefine(PVGASTATE pThis, uint32_t cid)
    29082907{
    29092908    int                     rc;
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.h

    r53756 r54659  
    6363int vmsvga3dSurfaceBlitToScreen(PVGASTATE pThis, uint32_t dest, SVGASignedRect destRect, SVGA3dSurfaceImageId src, SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *pRect);
    6464
    65 int vmsvga3dContextDefine(PVGASTATE pThis, uint32_t cid, bool fOtherProfile);
     65int vmsvga3dContextDefine(PVGASTATE pThis, uint32_t cid);
    6666int vmsvga3dContextDestroy(PVGASTATE pThis, uint32_t cid);
    6767
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