VirtualBox

Changeset 45201 in vbox


Ignore:
Timestamp:
Mar 27, 2013 10:23:49 AM (12 years ago)
Author:
vboxsync
Message:

crOpenGL: basics for BlitFramebuffer driver bugs work around

Location:
trunk/src/VBox
Files:
7 edited

Legend:

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

    r45132 r45201  
    5454struct CR_BLITTER;
    5555
    56 typedef DECLCALLBACK(int) FNCRBLT_BLITTER(struct CR_BLITTER *pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags);
     56typedef DECLCALLBACK(int) FNCRBLT_BLITTER(struct CR_BLITTER *pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags);
    5757typedef FNCRBLT_BLITTER *PFNCRBLT_BLITTER;
    5858
    59 #define CRBLT_F_LINEAR    0x00000001
    60 #define CRBLT_F_OFFSCREEN 0x00000002
     59#define CRBLT_F_LINEAR            0x00000001
     60#define CRBLT_F_INVERT_SRC_YCOORDS 0x00000002
     61#define CRBLT_F_INVERT_DST_YCOORDS 0x00000004
     62#define CRBLT_F_INVERT_YCOORDS     (CRBLT_F_INVERT_SRC_YCOORDS | CRBLT_F_INVERT_DST_YCOORDS)
     63
     64#define CRBLT_FLAGS_FROM_FILTER(_f) ( ((_f) & GL_LINEAR) ? CRBLT_F_LINEAR : 0)
     65#define CRBLT_FILTER_FROM_FLAGS(_f) (((_f) & CRBLT_F_LINEAR) ? GL_LINEAR : GL_NEAREST)
    6166
    6267typedef struct CR_BLITTER_SPUITEM
     
    8590    CR_BLITTER_BUFFER Indicies;
    8691    RTRECTSIZE CurrentSetSize;
    87     CR_BLITTER_WINDOW *pCurrentMural;
     92    CR_BLITTER_WINDOW CurrentMural;
    8893    CR_BLITTER_CONTEXT CtxInfo;
    89     CR_BLITTER_CONTEXT *pRestoreCtxInfo;
    90     CR_BLITTER_WINDOW *pRestoreMural;
     94    const CR_BLITTER_CONTEXT *pRestoreCtxInfo;
     95    const CR_BLITTER_WINDOW *pRestoreMural;
    9196    int32_t i32MakeCurrentUserData;
    9297    SPUDispatchTable *pDispatch;
    9398} CR_BLITTER, *PCR_BLITTER;
    9499
    95 VBOXBLITTERDECL(int) CrBltInit(PCR_BLITTER pBlitter, CR_BLITTER_CONTEXT *pCtxBase, bool fCreateNewCtx, SPUDispatchTable *pDispatch);
     100DECLINLINE(GLboolean) CrBltIsInitialized(PCR_BLITTER pBlitter)
     101{
     102    return !!pBlitter->pDispatch;
     103}
     104
     105VBOXBLITTERDECL(int) CrBltInit(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pCtxBase, bool fCreateNewCtx, SPUDispatchTable *pDispatch);
    96106VBOXBLITTERDECL(void) CrBltTerm(PCR_BLITTER pBlitter);
    97107
     
    116126}
    117127
    118 VBOXBLITTERDECL(void) CrBltMuralSetCurrent(PCR_BLITTER pBlitter, CR_BLITTER_WINDOW *pMural);
    119 DECLINLINE(CR_BLITTER_WINDOW *) CrBltMuralGetCurrent(PCR_BLITTER pBlitter)
     128VBOXBLITTERDECL(void) CrBltMuralSetCurrent(PCR_BLITTER pBlitter, const CR_BLITTER_WINDOW *pMural);
     129DECLINLINE(const CR_BLITTER_WINDOW *) CrBltMuralGetCurrentInfo(PCR_BLITTER pBlitter)
    120130{
    121     return pBlitter->pCurrentMural;
     131    return &pBlitter->CurrentMural;
    122132}
    123133
    124134VBOXBLITTERDECL(void) CrBltLeave(PCR_BLITTER pBlitter);
    125 VBOXBLITTERDECL(int) CrBltEnter(PCR_BLITTER pBlitter, CR_BLITTER_CONTEXT *pRestoreCtxInfo, CR_BLITTER_WINDOW *pRestoreMural);
    126 VBOXBLITTERDECL(void) CrBltBlitTexMural(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags);
    127 VBOXBLITTERDECL(void) CrBltBlitTexTex(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *pSrcRect, VBOXVR_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags);
     135VBOXBLITTERDECL(int) CrBltEnter(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pRestoreCtxInfo, const CR_BLITTER_WINDOW *pRestoreMural);
     136VBOXBLITTERDECL(void) CrBltBlitTexMural(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags);
     137VBOXBLITTERDECL(void) CrBltBlitTexTex(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *pSrcRect, const VBOXVR_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags);
    128138VBOXBLITTERDECL(void) CrBltPresent(PCR_BLITTER pBlitter);
    129139/* */
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h

    r45148 r45201  
    1414#include "cr_glstate.h"
    1515#include "cr_vreg.h"
     16#include "cr_blitter.h"
    1617#include "spu_dispatch_table.h"
    1718
     
    320321     * we deal with the global RootVr data directly */
    321322    RTPOINT RootVrCurPoint;
     323
     324    CR_BLITTER Blitter;
    322325
    323326    /** configuration options */
  • trunk/src/VBox/GuestHost/OpenGL/util/blitter.cpp

    r45132 r45201  
    2929
    3030
    31 int CrBltInit(PCR_BLITTER pBlitter, CR_BLITTER_CONTEXT *pCtxBase, bool fCreateNewCtx, SPUDispatchTable *pDispatch)
    32 {
    33     memset(pBlitter, 0, sizeof (*pBlitter));
    34 
    35     pBlitter->pDispatch = pDispatch;
    36 
     31int CrBltInit(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pCtxBase, bool fCreateNewCtx, SPUDispatchTable *pDispatch)
     32{
    3733    if (pCtxBase->Base.id == 0 || pCtxBase->Base.id < -1)
    3834    {
     
    4137    }
    4238
     39    memset(pBlitter, 0, sizeof (*pBlitter));
     40
     41    pBlitter->pDispatch = pDispatch;
    4342    pBlitter->CtxInfo = *pCtxBase;
    4443    if (fCreateNewCtx)
     
    4746        if (!pBlitter->CtxInfo.Base.id)
    4847        {
     48            memset(pBlitter, 0, sizeof (*pBlitter));
    4949            crWarning("CreateContext failed!");
    5050            return VERR_GENERAL_FAILURE;
     
    6262}
    6363
    64 void CrBltMuralSetCurrent(PCR_BLITTER pBlitter, CR_BLITTER_WINDOW *pMural)
    65 {
    66     if (pBlitter->pCurrentMural == pMural)
    67         return;
    68 
    69     pBlitter->pCurrentMural = pMural;
     64void CrBltMuralSetCurrent(PCR_BLITTER pBlitter, const CR_BLITTER_WINDOW *pMural)
     65{
     66    if (pMural)
     67    {
     68        if (!memcmp(&pBlitter->CurrentMural, pMural, sizeof (pBlitter->CurrentMural)))
     69            return;
     70        memcpy(&pBlitter->CurrentMural, pMural, sizeof (pBlitter->CurrentMural));
     71    }
     72    else
     73    {
     74        if (!pBlitter->CurrentMural.Base.id)
     75            return;
     76        pBlitter->CurrentMural.Base.id = 0;
     77    }
     78
    7079    pBlitter->Flags.CurrentMuralChanged = 1;
    7180
     
    7988}
    8089
    81 #define CRBLT_FILTER_FROM_FLAGS(_f) (((_f) & CRBLT_F_LINEAR) ? GL_LINEAR : GL_NEAREST)
    82 
    83 static DECLCALLBACK(int) crBltBlitTexBufImplFbo(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags)
     90static DECLCALLBACK(int) crBltBlitTexBufImplFbo(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags)
    8491{
    8592    GLenum filter = CRBLT_FILTER_FROM_FLAGS(fFlags);
     
    9299        const RTRECT * pSrcRect = &paSrcRect[i];
    93100        const RTRECT * pDstRect = &paDstRect[i];
    94         if (CRBLT_F_OFFSCREEN & fFlags)
    95         {
    96             pBlitter->pDispatch->BlitFramebufferEXT(
    97                     pSrcRect->xLeft, pSrcRect->yTop, pSrcRect->xRight, pSrcRect->yBottom,
    98                     pDstRect->xLeft, pDstRect->yTop, pDstRect->xRight, pDstRect->yBottom,
     101        int32_t srcY1;
     102        int32_t srcY2;
     103        int32_t dstY1;
     104        int32_t dstY2;
     105        int32_t srcX1 = pSrcRect->xLeft;
     106        int32_t srcX2 = pSrcRect->xRight;
     107        int32_t dstX1 = pDstRect->xLeft;
     108        int32_t dstX2 = pDstRect->xRight;
     109
     110        if (CRBLT_F_INVERT_SRC_YCOORDS & fFlags)
     111        {
     112            srcY1 = pSrc->height - pSrcRect->yTop;
     113            srcY2 = pSrc->height - pSrcRect->yBottom;
     114        }
     115        else
     116        {
     117            srcY1 = pSrcRect->yTop;
     118            srcY2 = pSrcRect->yBottom;
     119        }
     120
     121        if (CRBLT_F_INVERT_DST_YCOORDS & fFlags)
     122        {
     123            dstY1 = pDstSize->cy - pDstRect->yTop;
     124            dstY2 = pDstSize->cy - pDstRect->yBottom;
     125        }
     126        else
     127        {
     128            dstY1 = pDstRect->yTop;
     129            dstY2 = pDstRect->yBottom;
     130        }
     131
     132        if (srcY1 > srcY2)
     133        {
     134            if (dstY1 > dstY2)
     135            {
     136                /* use srcY1 < srcY2 && dstY1 < dstY2 whenever possible to avoid GPU driver bugs */
     137                int32_t tmp = srcY1;
     138                srcY1 = srcY2;
     139                srcY2 = tmp;
     140                tmp = dstY1;
     141                dstY1 = dstY2;
     142                dstY2 = tmp;
     143            }
     144        }
     145
     146        if (srcX1 > srcX2)
     147        {
     148            if (dstX1 > dstX2)
     149            {
     150                /* use srcX1 < srcX2 && dstX1 < dstX2 whenever possible to avoid GPU driver bugs */
     151                int32_t tmp = srcX1;
     152                srcX1 = srcX2;
     153                srcX2 = tmp;
     154                tmp = dstX1;
     155                dstX1 = dstX2;
     156                dstX2 = tmp;
     157            }
     158        }
     159
     160        pBlitter->pDispatch->BlitFramebufferEXT(srcX1, srcY1, srcX2, srcY2,
     161                    dstX1, dstY1, dstX2, dstY2,
    99162                    GL_COLOR_BUFFER_BIT, filter);
    100         }
    101         else
    102         {
    103             int32_t srcY1 = pSrc->height - pSrcRect->yTop;
    104             int32_t srcY2 = pSrc->height - pSrcRect->yBottom;
    105             int32_t dstY1 = pDstSize->cy - pDstRect->yTop;
    106             int32_t dstY2 = pDstSize->cy - pDstRect->yBottom;
    107             if (srcY1 > srcY2)
    108             {
    109                 if (dstY1 > dstY2)
    110                 {
    111                     /* use srcY1 < srcY2 && dstY1 < dstY2 whenever possible to avoid GPU driver bugs */
    112                     int32_t tmp = srcY1;
    113                     srcY1 = srcY2;
    114                     srcY2 = tmp;
    115                     tmp = dstY1;
    116                     dstY1 = dstY2;
    117                     dstY2 = tmp;
    118                 }
    119             }
    120             pBlitter->pDispatch->BlitFramebufferEXT(
    121                     pSrcRect->xLeft, srcY1, pSrcRect->xRight, srcY2,
    122                     pDstRect->xLeft, dstY1, pDstRect->xRight, dstY2,
    123                     GL_COLOR_BUFFER_BIT, filter);
    124         }
    125163    }
    126164
     
    271309static void crBltCheckSetupViewport(PCR_BLITTER pBlitter, const RTRECTSIZE *pDstSize, bool fFBODraw)
    272310{
    273     if (!pBlitter->Flags.LastWasFBODraw != !fFBODraw
    274             || pBlitter->Flags.CurrentMuralChanged
    275             || pBlitter->CurrentSetSize.cx != pDstSize->cx
     311    bool fUpdateViewport = pBlitter->Flags.CurrentMuralChanged;
     312    if (pBlitter->CurrentSetSize.cx != pDstSize->cx
    276313            || pBlitter->CurrentSetSize.cy != pDstSize->cy)
    277314    {
    278 #if 0
    279         const GLdouble aProjection[] =
    280         {
    281                 2.0 / pDstSize->cx,               0.0,  0.0, 0.0,
    282                               0.0, 2.0 / pDstSize->cy,  0.0, 0.0,
    283                               0.0,               0.0,  2.0, 0.0,
    284                              -1.0,              -1.0, -1.0, 1.0
    285         };
    286         pBlitter->pDispatch->MatrixMode(GL_PROJECTION);
    287         pBlitter->pDispatch->LoadMatrixd(aProjection);
    288         pBlitter->pDispatch->Viewport(0, 0, pDstSize->cx, pDstSize->cy);
    289 #else
     315        pBlitter->CurrentSetSize = *pDstSize;
    290316        pBlitter->pDispatch->MatrixMode(GL_PROJECTION);
    291317        pBlitter->pDispatch->LoadIdentity();
    292         pBlitter->pDispatch->Viewport(0, 0, pDstSize->cx, pDstSize->cy);
    293318        pBlitter->pDispatch->Ortho(0, pDstSize->cx, 0, pDstSize->cy, -1, 1);
    294         pBlitter->pDispatch->MatrixMode(GL_TEXTURE);
    295         pBlitter->pDispatch->LoadIdentity();
    296         pBlitter->pDispatch->MatrixMode(GL_MODELVIEW);
    297         pBlitter->pDispatch->LoadIdentity();
    298 
    299         /* Clear background to transparent */
    300         pBlitter->pDispatch->ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    301 #endif
    302         pBlitter->CurrentSetSize.cx = pDstSize->cx;
    303         pBlitter->CurrentSetSize.cy = pDstSize->cy;
    304         pBlitter->Flags.LastWasFBODraw = fFBODraw;
    305         if (!fFBODraw)
    306             pBlitter->Flags.CurrentMuralChanged = 0;
    307     }
    308 }
    309 
    310 static DECLCALLBACK(int) crBltBlitTexBufImplDraw2D(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags)
     319        fUpdateViewport = true;
     320    }
     321
     322    if (fUpdateViewport)
     323    {
     324        pBlitter->pDispatch->Viewport(0, 0, pBlitter->CurrentSetSize.cx, pBlitter->CurrentSetSize.cy);
     325        pBlitter->Flags.CurrentMuralChanged = 0;
     326    }
     327
     328    pBlitter->Flags.LastWasFBODraw = fFBODraw;
     329}
     330
     331static DECLCALLBACK(int) crBltBlitTexBufImplDraw2D(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags)
    311332{
    312333    GLuint normalX, normalY;
    313     uint32_t height = (fFlags & CRBLT_F_OFFSCREEN) ? 0 : pDstSize->cy;
     334    uint32_t srcHeight = (fFlags & CRBLT_F_INVERT_SRC_YCOORDS) ? pSrc->height : 0;
     335    uint32_t dstHeight = (fFlags & CRBLT_F_INVERT_DST_YCOORDS) ? pDstSize->cy : 0;
     336    Assert(srcHeight == dstHeight);
    314337
    315338    switch (pSrc->target)
     
    343366    {
    344367        /* just optimizatino to draw a single rect with GL_TRIANGLE_FAN */
    345         bool bUseSameVerticies = paSrcRect == paDstRect && normalX == 1 && normalY == 1;
     368        bool bUseSameVerticies = paSrcRect == paDstRect && normalX == 1 && normalY == 1 && srcHeight == dstHeight;
    346369        GLfloat *pVerticies;
    347370        GLfloat *pTexCoords;
     
    350373        {
    351374            pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * sizeof (*pVerticies));
    352             crBltVtRectTFNormalized(paDstRect, normalX, normalY, pVerticies, height);
     375            crBltVtRectTFNormalized(paDstRect, normalX, normalY, pVerticies, dstHeight);
    353376            pTexCoords = pVerticies;
    354377        }
     
    356379        {
    357380            pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * 2 * sizeof (*pVerticies));
    358             pTexCoords = crBltVtRectTFNormalized(paDstRect, 1, 1, pVerticies, height);
    359             crBltVtRectTFNormalized(paSrcRect, normalX, normalY, pTexCoords, height);
     381            pTexCoords = crBltVtRectTFNormalized(paDstRect, 1, 1, pVerticies, dstHeight);
     382            crBltVtRectTFNormalized(paSrcRect, normalX, normalY, pTexCoords, srcHeight);
    360383        }
    361384
     
    377400    else
    378401    {
    379         bool bUseSameVerticies = paSrcRect == paDstRect && normalX == 1 && normalY == 1;
     402        bool bUseSameVerticies = paSrcRect == paDstRect && normalX == 1 && normalY == 1 && srcHeight == dstHeight;
    380403        GLfloat *pVerticies;
    381404        GLfloat *pTexCoords;
     
    387410        {
    388411            pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * sizeof (*pVerticies) + cIndicies * sizeof (*pIndicies));
    389             crBltVtRectsITNormalized(paDstRect, cRects, normalX, normalY, pVerticies, &pIndicies, &iIdxBase, height);
     412            crBltVtRectsITNormalized(paDstRect, cRects, normalX, normalY, pVerticies, &pIndicies, &iIdxBase, dstHeight);
    390413            pTexCoords = pVerticies;
    391414        }
     
    393416        {
    394417            pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * 2 * sizeof (*pVerticies) + cIndicies * sizeof (*pIndicies));
    395             pTexCoords = crBltVtRectsITNormalized(paDstRect, cRects, 1, 1, pVerticies, &pIndicies, &iIdxBase, height);
    396             crBltVtRectsITNormalized(paSrcRect, cRects, normalX, normalY, pTexCoords, NULL, NULL, height);
     418            pTexCoords = crBltVtRectsITNormalized(paDstRect, cRects, 1, 1, pVerticies, &pIndicies, &iIdxBase, dstHeight);
     419            crBltVtRectsITNormalized(paSrcRect, cRects, normalX, normalY, pTexCoords, NULL, NULL, srcHeight);
    397420        }
    398421
     
    441464    }
    442465
     466    /* defaults. but just in case */
     467    pBlitter->pDispatch->MatrixMode(GL_TEXTURE);
     468    pBlitter->pDispatch->LoadIdentity();
     469    pBlitter->pDispatch->MatrixMode(GL_MODELVIEW);
     470    pBlitter->pDispatch->LoadIdentity();
     471
    443472    return VINF_SUCCESS;
    444473}
     
    459488    if (pBlitter->pRestoreCtxInfo != &pBlitter->CtxInfo)
    460489    {
    461 
    462         pBlitter->pDispatch->MakeCurrent(pBlitter->pRestoreMural->Base.id, 0,
    463                 pBlitter->pRestoreCtxInfo->Base.id >= 0
    464                     ? pBlitter->pRestoreCtxInfo->Base.id : pBlitter->pRestoreCtxInfo->Base.id);
     490        pBlitter->pDispatch->MakeCurrent(pBlitter->pRestoreMural->Base.id, 0, pBlitter->pRestoreCtxInfo->Base.id);
    465491    }
    466492    else
     
    472498}
    473499
    474 int CrBltEnter(PCR_BLITTER pBlitter, CR_BLITTER_CONTEXT *pRestoreCtxInfo, CR_BLITTER_WINDOW *pRestoreMural)
    475 {
    476     if (!pBlitter->pCurrentMural)
     500int CrBltEnter(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pRestoreCtxInfo, const CR_BLITTER_WINDOW *pRestoreMural)
     501{
     502    if (!pBlitter->CurrentMural.Base.id)
    477503    {
    478504        crWarning("current mural not initialized!");
     
    498524    }
    499525
    500     pBlitter->pDispatch->MakeCurrent(pBlitter->pCurrentMural->Base.id, pBlitter->i32MakeCurrentUserData, pBlitter->CtxInfo.Base.id);
     526    pBlitter->pDispatch->MakeCurrent(pBlitter->CurrentMural.Base.id, pBlitter->i32MakeCurrentUserData, pBlitter->CtxInfo.Base.id);
    501527
    502528    if (pBlitter->Flags.Initialized)
     
    515541}
    516542
    517 static void crBltBlitTexBuf(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, GLenum enmDstBuff, const RTRECTSIZE *pDstSize, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags)
     543static void crBltBlitTexBuf(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, GLenum enmDstBuff, const RTRECTSIZE *pDstSize, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags)
    518544{
    519545    pBlitter->pDispatch->DrawBuffer(enmDstBuff);
     
    521547    crBltCheckSetupViewport(pBlitter, pDstSize, enmDstBuff == GL_DRAW_FRAMEBUFFER);
    522548
    523     pBlitter->pfnBlt(pBlitter, pSrc, paSrcRects, pDstSize, paDstRects, cRects, fFlags & CRBLT_F_OFFSCREEN);
    524 }
    525 
    526 void CrBltBlitTexMural(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags)
    527 {
    528     RTRECTSIZE DstSize = {pBlitter->pCurrentMural->width, pBlitter->pCurrentMural->height};
     549    pBlitter->pfnBlt(pBlitter, pSrc, paSrcRects, pDstSize, paDstRects, cRects, fFlags);
     550}
     551
     552void CrBltBlitTexMural(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags)
     553{
     554    RTRECTSIZE DstSize = {pBlitter->CurrentMural.width, pBlitter->CurrentMural.height};
    529555
    530556    pBlitter->pDispatch->BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
    531557
    532     crBltBlitTexBuf(pBlitter, pSrc, paSrcRects, GL_BACK, &DstSize, paDstRects, cRects, fFlags & (~CRBLT_F_OFFSCREEN));
    533 }
    534 
    535 void CrBltBlitTexTex(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *pSrcRect, VBOXVR_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags)
     558    crBltBlitTexBuf(pBlitter, pSrc, paSrcRects, GL_BACK, &DstSize, paDstRects, cRects, fFlags);
     559}
     560
     561void CrBltBlitTexTex(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *pSrcRect, const VBOXVR_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags)
    536562{
    537563    RTRECTSIZE DstSize = {(uint32_t)pDst->width, (uint32_t)pDst->height};
     
    552578{
    553579    if (pBlitter->CtxInfo.Base.visualBits & CR_DOUBLE_BIT)
    554         pBlitter->pDispatch->SwapBuffers(pBlitter->pCurrentMural->Base.id, 0);
     580        pBlitter->pDispatch->SwapBuffers(pBlitter->CurrentMural.Base.id, 0);
    555581    else
    556582        pBlitter->pDispatch->Flush();
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c

    r45179 r45201  
    355355    crMemset(&cr_server.RootVrCurPoint, 0, sizeof (cr_server.RootVrCurPoint));
    356356
     357    crMemset(&cr_server.Blitter, 0, sizeof (cr_server.Blitter));
     358
    357359    crServerInitDispatch();
    358360    crStateDiffAPI( &(cr_server.head_spu->dispatch_table) );
     
    443445    VBoxVrListInit(&cr_server.RootVr);
    444446    crMemset(&cr_server.RootVrCurPoint, 0, sizeof (cr_server.RootVrCurPoint));
     447
     448    crMemset(&cr_server.Blitter, 0, sizeof (cr_server.Blitter));
    445449
    446450    crServerSetVBoxConfigurationHGCM();
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_misc.c

    r44196 r45201  
    625625#endif
    626626
     627PCR_BLITTER crServerVBoxBlitterGet()
     628{
     629    if (!CrBltIsInitialized(&cr_server.Blitter))
     630    {
     631        CR_BLITTER_CONTEXT Ctx;
     632        int rc;
     633        CRASSERT(cr_server.MainContextInfo.SpuContext);
     634        Ctx.Base.id = cr_server.MainContextInfo.SpuContext;
     635        Ctx.Base.visualBits = cr_server.MainContextInfo.CreateInfo.visualBits;
     636        rc = CrBltInit(&cr_server.Blitter, &Ctx, true, &cr_server.head_spu->dispatch_table);
     637        if (RT_SUCCESS(rc))
     638        {
     639            CRASSERT(CrBltIsInitialized(&cr_server.Blitter));
     640        }
     641        else
     642        {
     643            crWarning("CrBltInit failed, rc %d", rc);
     644            CRASSERT(!CrBltIsInitialized(&cr_server.Blitter));
     645            return NULL;
     646        }
     647    }
     648    return &cr_server.Blitter;
     649}
     650
     651int crServerVBoxBlitterTexInit(CRContext *ctx, CRMuralInfo *mural, PVBOXVR_TEXTURE pTex, GLboolean fDraw)
     652{
     653    CRTextureObj *tobj;
     654    CRFramebufferObjectState *pBuf = &ctx->framebufferobject;
     655    GLenum enmBuf;
     656    CRFBOAttachmentPoint *pAp;
     657    GLuint idx;
     658    CRTextureLevel *tl;
     659    CRFramebufferObject *pFBO = fDraw ? pBuf->drawFB : pBuf->readFB;
     660
     661    if (!pFBO)
     662    {
     663        GLuint hwid;
     664
     665        if (mural->fUseFBO == CR_SERVER_REDIR_NONE)
     666            return VERR_NOT_IMPLEMENTED;
     667
     668        enmBuf = fDraw ? ctx->buffer.drawBuffer : ctx->buffer.readBuffer;
     669        switch (enmBuf)
     670        {
     671            case GL_BACK:
     672            case GL_BACK_RIGHT:
     673            case GL_BACK_LEFT:
     674                hwid = mural->aidColorTexs[CR_SERVER_FBO_BB_IDX(mural)];
     675                break;
     676            case GL_FRONT:
     677            case GL_FRONT_RIGHT:
     678            case GL_FRONT_LEFT:
     679                hwid = mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)];
     680                break;
     681            default:
     682                crWarning("unsupported enum buf");
     683                return VERR_NOT_IMPLEMENTED;
     684                break;
     685        }
     686
     687        if (!hwid)
     688        {
     689            crWarning("offscreen render tex hwid is null");
     690            return VERR_INVALID_STATE;
     691        }
     692
     693        pTex->width = mural->width;
     694        pTex->height = mural->height;
     695        pTex->target = GL_TEXTURE_2D;
     696        pTex->hwid = hwid;
     697        return VINF_SUCCESS;
     698    }
     699
     700    enmBuf = fDraw ? pFBO->drawbuffer[0] : pFBO->readbuffer;
     701    idx = enmBuf - GL_COLOR_ATTACHMENT0_EXT;
     702    if (idx >= CR_MAX_COLOR_ATTACHMENTS)
     703    {
     704        crWarning("idx is invalid %d, using 0", idx);
     705    }
     706
     707    pAp = &pFBO->color[idx];
     708
     709    if (!pAp->name)
     710    {
     711        crWarning("no collor draw attachment");
     712        return VERR_INVALID_STATE;
     713    }
     714
     715    if (pAp->level)
     716    {
     717        crWarning("non-zero level not implemented");
     718        return VERR_NOT_IMPLEMENTED;
     719    }
     720
     721    tobj = (CRTextureObj*)crHashtableSearch(ctx->shared->textureTable, pAp->name);
     722    if (!tobj)
     723    {
     724        crWarning("no texture object found for name %d", pAp->name);
     725        return VERR_INVALID_STATE;
     726    }
     727
     728    if (tobj->target != GL_TEXTURE_2D && tobj->target != GL_TEXTURE_RECTANGLE_NV)
     729    {
     730        crWarning("non-texture[rect|2d] not implemented");
     731        return VERR_NOT_IMPLEMENTED;
     732    }
     733
     734    CRASSERT(tobj->hwid);
     735
     736    tl = tobj->level[0];
     737    pTex->width = tl->width;
     738    pTex->height = tl->height;
     739    pTex->target = tobj->target;
     740    pTex->hwid = tobj->hwid;
     741
     742    return VINF_SUCCESS;
     743}
     744
     745void crServerVBoxBlitterWinInit(CRMuralInfo *mural, CR_BLITTER_WINDOW *win)
     746{
     747    win->Base.id = mural->spuWindow;
     748    win->Base.visualBits = mural->CreateInfo.visualBits;
     749    win->width = mural->width;
     750    win->height = mural->height;
     751}
     752
     753int crServerVBoxBlitterBlitCurrentCtx(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
     754        GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
     755        GLbitfield mask, GLenum filter)
     756{
     757    PCR_BLITTER pBlitter;
     758    CR_BLITTER_CONTEXT Ctx;
     759    CRMuralInfo *mural;
     760    CRContext *ctx = crStateGetCurrent();
     761    PVBOXVR_TEXTURE pDrawTex, pReadTex;
     762    VBOXVR_TEXTURE DrawTex, ReadTex;
     763    int rc;
     764    GLuint idDrawFBO, idReadFBO;
     765    CR_BLITTER_WINDOW BltInfo;
     766
     767    if (mask != GL_COLOR_BUFFER_BIT)
     768    {
     769        crWarning("not supported blit mask %d", mask);
     770        return VERR_NOT_IMPLEMENTED;
     771    }
     772
     773    if (!cr_server.curClient)
     774    {
     775        crWarning("no current client");
     776        return VERR_INVALID_STATE;
     777    }
     778    mural = cr_server.curClient->currentMural;
     779    if (!mural)
     780    {
     781        crWarning("no current mural");
     782        return VERR_INVALID_STATE;
     783    }
     784
     785    rc = crServerVBoxBlitterTexInit(ctx, mural, &DrawTex, GL_TRUE);
     786    if (RT_SUCCESS(rc))
     787    {
     788        pDrawTex = &DrawTex;
     789    }
     790    else
     791    {
     792        crWarning("crServerVBoxBlitterTexInit failed for draw");
     793        return rc;
     794    }
     795
     796    rc = crServerVBoxBlitterTexInit(ctx, mural, &ReadTex, GL_FALSE);
     797    if (RT_SUCCESS(rc))
     798    {
     799        pReadTex = &ReadTex;
     800    }
     801    else
     802    {
     803//        crWarning("crServerVBoxBlitterTexInit failed for read");
     804        return rc;
     805    }
     806
     807    pBlitter = crServerVBoxBlitterGet();
     808    if (!pBlitter)
     809    {
     810        crWarning("crServerVBoxBlitterGet failed");
     811        return VERR_GENERAL_FAILURE;
     812    }
     813
     814    crServerVBoxBlitterWinInit(mural, &BltInfo);
     815
     816    CrBltMuralSetCurrent(pBlitter, &BltInfo);
     817
     818    Ctx.Base.id = cr_server.curClient->currentCtxInfo->SpuContext;
     819    if (Ctx.Base.id < 0)
     820        Ctx.Base.id = cr_server.MainContextInfo.SpuContext;
     821    Ctx.Base.visualBits = cr_server.curClient->currentCtxInfo->CreateInfo.visualBits;
     822
     823    idDrawFBO = mural->aidFBOs[mural->iCurDrawBuffer];
     824    idReadFBO = mural->aidFBOs[mural->iCurReadBuffer];
     825
     826    crStateSwitchPrepare(NULL, ctx, idDrawFBO, idReadFBO);
     827
     828    rc = CrBltEnter(pBlitter, &Ctx, &BltInfo);
     829    if (RT_SUCCESS(rc))
     830    {
     831        RTRECT ReadRect, DrawRect;
     832        ReadRect.xLeft = srcX0;
     833        ReadRect.yTop = srcY0;
     834        ReadRect.xRight = srcX1;
     835        ReadRect.yBottom = srcY1;
     836        DrawRect.xLeft = dstX0;
     837        DrawRect.yTop = dstY0;
     838        DrawRect.xRight = dstX1;
     839        DrawRect.yBottom = dstY1;
     840        CrBltBlitTexTex(pBlitter, pReadTex, &ReadRect, pDrawTex, &DrawRect, 1, CRBLT_FLAGS_FROM_FILTER(filter));
     841        CrBltLeave(pBlitter);
     842    }
     843    else
     844    {
     845        crWarning("CrBltEnter failed rc %d", rc);
     846    }
     847
     848    crStateSwitchPostprocess(ctx, NULL, idDrawFBO, idReadFBO);
     849
     850    return rc;
     851}
     852
    627853void SERVER_DISPATCH_APIENTRY
    628854crServerDispatchBlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
     
    631857{
    632858    CRContext *ctx = crStateGetCurrent();
     859    bool fTryBlitter = false;
    633860#ifdef CR_CHECK_BLITS
    634861//    {
     
    8401067#endif
    8411068
     1069    if (srcY0 > srcY1)
     1070    {
     1071        if (dstY0 > dstY1)
     1072        {
     1073            /* use srcY1 < srcY2 && dstY1 < dstY2 whenever possible to avoid GPU driver bugs */
     1074            int32_t tmp = srcY0;
     1075            srcY0 = srcY1;
     1076            srcY1 = tmp;
     1077            tmp = dstY0;
     1078            dstY0 = dstY1;
     1079            dstY1 = tmp;
     1080        }
     1081        else
     1082        {
     1083            fTryBlitter = true;
     1084        }
     1085    }
     1086
     1087    if (srcX0 > srcX1)
     1088    {
     1089        if (dstX0 > dstX1)
     1090        {
     1091            /* use srcX1 < srcX2 && dstX1 < dstX2 whenever possible to avoid GPU driver bugs */
     1092            int32_t tmp = srcX0;
     1093            srcX0 = srcX1;
     1094            srcX1 = tmp;
     1095            tmp = dstX0;
     1096            dstX0 = dstX1;
     1097            dstX1 = tmp;
     1098        }
     1099        else
     1100        {
     1101            fTryBlitter = true;
     1102        }
     1103    }
     1104
     1105    /* @todo: enable for problematic platforms */
     1106#if 0
     1107    if (fTryBlitter)
     1108    {
     1109        int rc = crServerVBoxBlitterBlitCurrentCtx(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
     1110        if (RT_SUCCESS(rc))
     1111            goto my_exit;
     1112    }
     1113#endif
     1114
    8421115    if (ctx->viewport.scissorTest)
    8431116        cr_server.head_spu->dispatch_table.Disable(GL_SCISSOR_TEST);
     
    8491122    if (ctx->viewport.scissorTest)
    8501123        cr_server.head_spu->dispatch_table.Enable(GL_SCISSOR_TEST);
     1124
     1125
     1126my_exit:
     1127
    8511128//#ifdef CR_CHECK_BLITS
    8521129//    crDbgDumpTexImage2D("<== src tex:", GL_TEXTURE_2D, rtex, true);
     
    8611138    crFree(img);
    8621139#endif
     1140    return;
    8631141}
    8641142
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_window.c

    r45159 r45201  
    104104    CR_STATE_SHAREDOBJ_USAGE_INIT(mural);
    105105
    106     crServerSetupOutputRedirect(mural);
    107 
    108106    Rect.xLeft = 0;
    109107    Rect.xRight = mural->width;
     
    116114        return -1;
    117115    }
     116
     117    crServerSetupOutputRedirect(mural);
    118118
    119119    if (mural->fRootVrOn)
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c

    r45148 r45201  
    683683                DstRect.xRight = paDstRegions[i].xRight * scaleX;
    684684                DstRect.yBottom = paDstRegions[i].yBottom * scaleY;
    685                 CrBltBlitTexMural(pBlitter, &pEntry->Tex, &paSrcRegions[i], &DstRect, 1, CRBLT_F_LINEAR);
     685                CrBltBlitTexMural(pBlitter, &pEntry->Tex, &paSrcRegions[i], &DstRect, 1, CRBLT_F_LINEAR | CRBLT_F_INVERT_YCOORDS);
    686686            }
    687687        }
     
    705705        if (RT_SUCCESS(rc))
    706706        {
    707             CrBltBlitTexMural(pBlitter, &pEntry->Tex, paSrcRegions, paDstRegions, cRegions, CRBLT_F_LINEAR);
     707            CrBltBlitTexMural(pBlitter, &pEntry->Tex, paSrcRegions, paDstRegions, cRegions, CRBLT_F_LINEAR | CRBLT_F_INVERT_YCOORDS);
    708708        }
    709709        else
     
    721721    if (render_spu.blitterTable)
    722722    {
    723         CR_BLITTER_WINDOW * pBltInfo = CrBltMuralGetCurrent(window->pBlitter);
    724         if (pBltInfo == &window->BltInfo)
     723        const CR_BLITTER_WINDOW * pBltInfo = CrBltMuralGetCurrentInfo(window->pBlitter);
     724        if (pBltInfo->Base.id == window->BltInfo.Base.id)
    725725        {
    726726            CrBltMuralSetCurrent(window->pBlitter, NULL);
     
    729729    else
    730730    {
    731         CRASSERT(CrBltMuralGetCurrent(window->pBlitter) == &window->BltInfo);
     731        CRASSERT(CrBltMuralGetCurrentInfo(window->pBlitter)->Base.id == window->BltInfo.Base.id);
    732732        CrBltMuralSetCurrent(window->pBlitter, NULL);
    733733        CrBltTerm(window->pBlitter);
Note: See TracChangeset for help on using the changeset viewer.

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