VirtualBox

Changeset 73194 in vbox


Ignore:
Timestamp:
Jul 18, 2018 7:14:24 AM (7 years ago)
Author:
vboxsync
Message:

DevVGA-SVGA: added new parameters for vmsvgaGMRTransfer in order to reduce code duplication, adjusted callers accordingly

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

Legend:

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

    r73004 r73194  
    37603760                STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdBlitGmrFbToScreen);
    37613761
    3762                 Log(("vmsvgaFIFOLoop: SVGA_CMD_BLIT_GMRFB_TO_SCREEN src=(%d,%d) dest id=%d (%d,%d)(%d,%d)\n", pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->destScreenId, pCmd->destRect.left, pCmd->destRect.top, pCmd->destRect.right, pCmd->destRect.bottom));
     3762                LogFunc(("SVGA_CMD_BLIT_GMRFB_TO_SCREEN src=(%d,%d) dest id=%d (%d,%d)(%d,%d)\n",
     3763                         pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->destScreenId, pCmd->destRect.left, pCmd->destRect.top, pCmd->destRect.right, pCmd->destRect.bottom));
    37633764
    37643765                /** @todo Support GMRFB.format.s.bitsPerPixel != pThis->svga.uBpp   */
    37653766                AssertBreak(pSVGAState->GMRFB.format.s.bitsPerPixel == pThis->svga.uBpp);
     3767                /** @todo Multimonitor. */
    37663768                AssertBreak(pCmd->destScreenId == 0);
    37673769
    3768                 if (pCmd->destRect.left < 0)
    3769                     pCmd->destRect.left = 0;
    3770                 if (pCmd->destRect.top < 0)
    3771                     pCmd->destRect.top = 0;
    3772                 if (pCmd->destRect.right < 0)
    3773                     pCmd->destRect.right = 0;
    3774                 if (pCmd->destRect.bottom < 0)
    3775                     pCmd->destRect.bottom = 0;
    3776 
    3777                 width  = pCmd->destRect.right - pCmd->destRect.left;
    3778                 height = pCmd->destRect.bottom - pCmd->destRect.top;
    3779 
    3780                 if (    width == 0
    3781                     ||  height == 0)
     3770                /* Clip destRect to the screen dimensions. */
     3771                SVGASignedRect screenRect;
     3772                screenRect.left  = 0;
     3773                screenRect.top   = 0;
     3774                screenRect.right = pThis->svga.uWidth;
     3775                screenRect.top   = pThis->svga.uHeight;
     3776                SVGASignedRect clipRect = pCmd->destRect;
     3777                vmsvgaClipRect(&screenRect, &clipRect);
     3778                RT_UNTRUSTED_VALIDATED_FENCE();
     3779
     3780                width  = clipRect.right - clipRect.left;
     3781                height = clipRect.bottom - clipRect.top;
     3782
     3783                if (   width == 0
     3784                    || height == 0)
    37823785                    break;  /* Nothing to do. */
    37833786
    3784                 /* Clip to screen dimensions. */
    3785                 if (width > pThis->svga.uWidth)
    3786                     width = pThis->svga.uWidth;
    3787                 if (height > pThis->svga.uHeight)
    3788                     height = pThis->svga.uHeight;
    3789 
    3790                 /* srcOrigin */
    3791                 AssertBreak(pSVGAState->GMRFB.bytesPerLine != 0);
    3792                 AssertBreak(pSVGAState->GMRFB.format.s.bitsPerPixel != 0);
    3793 
     3787                int32_t const srcx = pCmd->srcOrigin.x + (clipRect.left - pCmd->destRect.left);
     3788                int32_t const srcy = pCmd->srcOrigin.y + (clipRect.top - pCmd->destRect.top);
     3789
     3790                /* Copy the defined by GMRFB image to the screen 0 VRAM area.
     3791                 * Prepare parameters for vmsvgaGMRTransfer.
     3792                 */
    37943793                AssertBreak(pThis->svga.uScreenOffset < pThis->vram_size); /* Paranoia. Ensured by SVGA_CMD_DEFINE_SCREEN. */
    3795                 const uint32_t cbVram = pThis->vram_size - pThis->svga.uScreenOffset;
    3796 
    3797                 const uint32_t cScanlines = cbVram / pSVGAState->GMRFB.bytesPerLine;
    3798                 AssertBreak(pCmd->srcOrigin.y < (int32_t)cScanlines);
    3799 
    3800                 AssertBreak(pCmd->srcOrigin.x < (int32_t)(pSVGAState->GMRFB.bytesPerLine / ((pSVGAState->GMRFB.format.s.bitsPerPixel + 7) / 8)));
    3801 
    3802                 unsigned offsetSource = (pCmd->srcOrigin.x * pSVGAState->GMRFB.format.s.bitsPerPixel) / 8 + pSVGAState->GMRFB.bytesPerLine * pCmd->srcOrigin.y;
    3803                 unsigned offsetDest   = (pCmd->destRect.left * RT_ALIGN(pThis->svga.uBpp, 8)) / 8 + pThis->svga.cbScanline * pCmd->destRect.top;
    3804                 unsigned cbCopyWidth  = (width * RT_ALIGN(pThis->svga.uBpp, 8)) / 8;
    3805 
    3806                 AssertBreak(offsetDest < cbVram);
    3807                 offsetDest += pThis->svga.uScreenOffset;
    3808 
    3809                 RT_UNTRUSTED_VALIDATED_FENCE();
    3810 
    3811                 rc = vmsvgaGMRTransfer(pThis, SVGA3D_WRITE_HOST_VRAM, pThis->CTX_SUFF(vram_ptr) + offsetDest, pThis->svga.cbScanline, pSVGAState->GMRFB.ptr, offsetSource, pSVGAState->GMRFB.bytesPerLine, cbCopyWidth, height);
     3794
     3795                /* Destination: host buffer which describes the screen 0 VRAM.
     3796                 * Important are pbHstBuf and cbHstBuf. offHst and cbHstPitch are verified by vmsvgaGMRTransfer.
     3797                 */
     3798                uint8_t * const pbHstBuf = (uint8_t *)pThis->CTX_SUFF(vram_ptr) + pThis->svga.uScreenOffset;
     3799                uint32_t cbHstBuf = pThis->svga.cbScanline * pThis->svga.uHeight;
     3800                if (cbHstBuf > pThis->vram_size - pThis->svga.uScreenOffset)
     3801                   cbHstBuf = pThis->vram_size - pThis->svga.uScreenOffset; /* Paranoia. */
     3802                uint32_t const offHst =   (clipRect.left * RT_ALIGN(pThis->svga.uBpp, 8)) / 8
     3803                                        + pThis->svga.cbScanline * clipRect.top;
     3804                int32_t const cbHstPitch = pThis->svga.cbScanline;
     3805
     3806                /* Source: GMRFB. vmsvgaGMRTransfer ensures that no memory outside the GMR is read. */
     3807                SVGAGuestPtr const gstPtr = pSVGAState->GMRFB.ptr;
     3808                uint32_t const offGst =  (srcx * RT_ALIGN(pSVGAState->GMRFB.format.s.bitsPerPixel, 8)) / 8
     3809                                       + pSVGAState->GMRFB.bytesPerLine * srcy;
     3810                int32_t const cbGstPitch = pSVGAState->GMRFB.bytesPerLine;
     3811
     3812                rc = vmsvgaGMRTransfer(pThis, SVGA3D_WRITE_HOST_VRAM,
     3813                                       pbHstBuf, cbHstBuf, offHst, cbHstPitch,
     3814                                       gstPtr, offGst, cbGstPitch,
     3815                                       (width * RT_ALIGN(pThis->svga.uBpp, 8)) / 8, height);
    38123816                AssertRC(rc);
    3813                 vgaR3UpdateDisplay(pThis, pCmd->destRect.left, pCmd->destRect.top, pCmd->destRect.right - pCmd->destRect.left, pCmd->destRect.bottom - pCmd->destRect.top);
     3817                vgaR3UpdateDisplay(pThis, clipRect.left, clipRect.top, width, height);
    38143818                break;
    38153819            }
     
    43524356 * @param   pThis           VGA device instance data.
    43534357 * @param   enmTransferType Transfer type (read/write)
    4354  * @param   pbHst           Host destination pointer
     4358 * @param   pbHstBuf        Host buffer pointer (valid)
     4359 * @param   cbHstBuf        Size of host buffer (valid)
     4360 * @param   offHst          Host buffer offset of the first scanline
    43554361 * @param   cbHstPitch      Destination buffer pitch
    43564362 * @param   gstPtr          GMR description
    4357  * @param   offGst          Guest buffer offset
     4363 * @param   offGst          Guest buffer offset of the first scanline
    43584364 * @param   cbGstPitch      Guest buffer pitch
    43594365 * @param   cbWidth         Width in bytes to copy
    43604366 * @param   cHeight         Number of scanllines to copy
    43614367 */
    4362 int vmsvgaGMRTransfer(PVGASTATE pThis, const SVGA3dTransferType enmTransferType, uint8_t *pbHst, int32_t cbHstPitch,
    4363                       SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch, uint32_t cbWidth, uint32_t cHeight)
     4368int vmsvgaGMRTransfer(PVGASTATE pThis, const SVGA3dTransferType enmTransferType,
     4369                      uint8_t *pbHstBuf, uint32_t cbHstBuf, uint32_t offHst, int32_t cbHstPitch,
     4370                      SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch,
     4371                      uint32_t cbWidth, uint32_t cHeight)
    43644372{
    43654373    PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
    43664374    int            rc;
    43674375
    4368     LogFunc(("%s host %p pitch=%d; guest gmr=%#x:%#x offset=%d pitch=%d cbWidth=%d cHeight=%d\n",
    4369              enmTransferType == SVGA3D_READ_HOST_VRAM ? "READ" : "WRITE", pbHst, cbHstPitch,
     4376    LogFunc(("%s host %p size=%d offset %d pitch=%d; guest gmr=%#x:%#x offset=%d pitch=%d cbWidth=%d cHeight=%d\n",
     4377             enmTransferType == SVGA3D_READ_HOST_VRAM ? "READ" : "WRITE",
     4378             pbHstBuf, cbHstBuf, offHst, cbHstPitch,
    43704379             gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cbWidth, cHeight));
    43714380    AssertReturn(cbWidth && cHeight, VERR_INVALID_PARAMETER);
    43724381
    43734382    PGMR pGMR;
    4374     uint32_t cbGmrTotal; /* The GMR size in bytes. */
     4383    uint32_t cbGmr; /* The GMR size in bytes. */
    43754384    if (gstPtr.gmrId == SVGA_GMR_FRAMEBUFFER)
    43764385    {
    43774386        pGMR = NULL;
    4378         cbGmrTotal = pThis->vram_size;
     4387        cbGmr = pThis->vram_size;
    43794388    }
    43804389    else
     
    43834392        RT_UNTRUSTED_VALIDATED_FENCE();
    43844393        pGMR = &pSVGAState->paGMR[gstPtr.gmrId];
    4385         cbGmrTotal = pGMR->cbTotal;
    4386     }
    4387 
     4394        cbGmr = pGMR->cbTotal;
     4395    }
     4396
     4397    /*
     4398     * GMR
     4399     */
    43884400    /* Calculate GMR offset of the data to be copied. */
    4389     AssertMsgReturn(gstPtr.offset < cbGmrTotal,
    4390                     ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmrTotal=%#x\n",
    4391                      gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmrTotal),
     4401    AssertMsgReturn(gstPtr.offset < cbGmr,
     4402                    ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
     4403                     gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
    43924404                    VERR_INVALID_PARAMETER);
    43934405    RT_UNTRUSTED_VALIDATED_FENCE();
    4394     AssertMsgReturn(offGst < cbGmrTotal - gstPtr.offset,
    4395                     ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmrTotal=%#x\n",
    4396                      gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmrTotal),
     4406    AssertMsgReturn(offGst < cbGmr - gstPtr.offset,
     4407                    ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
     4408                     gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
    43974409                    VERR_INVALID_PARAMETER);
    43984410    RT_UNTRUSTED_VALIDATED_FENCE();
    43994411    uint32_t const offGmr = offGst + gstPtr.offset; /* Offset in the GMR, where the first scanline is located. */
    44004412
    4401     /* Verify that cbWidth is less that scanline and fits into the GMR. */
     4413    /* Verify that cbWidth is less than scanline and fits into the GMR. */
    44024414    uint32_t const cbGmrScanline = cbGstPitch > 0 ? cbGstPitch : -cbGstPitch;
    44034415    AssertMsgReturn(cbGmrScanline != 0,
    4404                     ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmrTotal=%#x\n",
    4405                      gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmrTotal),
     4416                    ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
     4417                     gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
    44064418                    VERR_INVALID_PARAMETER);
    44074419    RT_UNTRUSTED_VALIDATED_FENCE();
    44084420    AssertMsgReturn(cbWidth <= cbGmrScanline,
    4409                     ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmrTotal=%#x\n",
    4410                      gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmrTotal),
     4421                    ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
     4422                     gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
    44114423                    VERR_INVALID_PARAMETER);
    4412     AssertMsgReturn(cbWidth <= cbGmrTotal - offGmr,
    4413                     ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmrTotal=%#x\n",
    4414                      gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmrTotal),
     4424    AssertMsgReturn(cbWidth <= cbGmr - offGmr,
     4425                    ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
     4426                     gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
    44154427                    VERR_INVALID_PARAMETER);
    44164428    RT_UNTRUSTED_VALIDATED_FENCE();
    44174429
    44184430    /* How many bytes are available for the data in the GMR. */
    4419     uint32_t const cbGmrLeft = cbGstPitch > 0 ? cbGmrTotal - offGmr : offGmr + cbWidth;
     4431    uint32_t const cbGmrLeft = cbGstPitch > 0 ? cbGmr - offGmr : offGmr + cbWidth;
    44204432
    44214433    /* How many scanlines would fit into the available data. */
    44224434    uint32_t cGmrScanlines = cbGmrLeft / cbGmrScanline;
    4423     uint32_t const cbLastScanline = cbGmrLeft - cGmrScanlines * cbGmrScanline; /* Slack space. */
    4424     if (cbWidth <= cbLastScanline)
     4435    uint32_t const cbGmrLastScanline = cbGmrLeft - cGmrScanlines * cbGmrScanline; /* Slack space. */
     4436    if (cbWidth <= cbGmrLastScanline)
    44254437        ++cGmrScanlines;
    44264438
     
    44294441
    44304442    AssertMsgReturn(cHeight > 0,
    4431                     ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmrTotal=%#x\n",
    4432                      gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmrTotal),
     4443                    ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
     4444                     gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
    44334445                    VERR_INVALID_PARAMETER);
    44344446    RT_UNTRUSTED_VALIDATED_FENCE();
     4447
     4448    /*
     4449     * Host buffer.
     4450     */
     4451    AssertMsgReturn(offHst < cbHstBuf,
     4452                    ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
     4453                     pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
     4454                    VERR_INVALID_PARAMETER);
     4455
     4456    /* Verify that cbWidth is less than scanline and fits into the buffer. */
     4457    uint32_t const cbHstScanline = cbHstPitch > 0 ? cbHstPitch : -cbHstPitch;
     4458    AssertMsgReturn(cbHstScanline != 0,
     4459                    ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
     4460                     pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
     4461                    VERR_INVALID_PARAMETER);
     4462    AssertMsgReturn(cbWidth <= cbHstScanline,
     4463                    ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
     4464                     pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
     4465                    VERR_INVALID_PARAMETER);
     4466    AssertMsgReturn(cbWidth <= cbHstBuf - offHst,
     4467                    ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
     4468                     pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
     4469                    VERR_INVALID_PARAMETER);
     4470
     4471    /* How many bytes are available for the data in the buffer. */
     4472    uint32_t const cbHstLeft = cbHstPitch > 0 ? cbHstBuf - offHst : offHst + cbWidth;
     4473
     4474    /* How many scanlines would fit into the available data. */
     4475    uint32_t cHstScanlines = cbHstLeft / cbHstScanline;
     4476    uint32_t const cbHstLastScanline = cbHstLeft - cHstScanlines * cbHstScanline; /* Slack space. */
     4477    if (cbWidth <= cbHstLastScanline)
     4478        ++cHstScanlines;
     4479
     4480    if (cHeight > cHstScanlines)
     4481        cHeight = cHstScanlines;
     4482
     4483    AssertMsgReturn(cHeight > 0,
     4484                    ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
     4485                     pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
     4486                    VERR_INVALID_PARAMETER);
     4487
     4488    uint8_t *pbHst = pbHstBuf + offHst;
    44354489
    44364490    /* Shortcut for the framebuffer. */
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp

    r71686 r73194  
    23492349 * @param   cbGuestPitch        The guest pitch.
    23502350 * @param   transfer            The transfer direction.
    2351  * @param   pBox                The box to copy.
     2351 * @param   pBox                The box to copy (clipped, valid, except for guest's srcx, srcy, srcz).
    23522352 * @param   pContext            The context (for OpenGL).
    23532353 * @param   rc                  The current rc for all boxes.
     
    23692369    {
    23702370        uint32_t cbSurfacePitch;
    2371         uint8_t *pDoubleBuffer, *pBufferStart;
    2372         unsigned uDestOffset = 0;
     2371        uint8_t *pDoubleBuffer;
     2372        uint32_t offHst;
    23732373
    23742374        pDoubleBuffer = (uint8_t *)RTMemAlloc(pMipLevel->cbSurface);
     
    24032403            VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    24042404
    2405             uDestOffset = pBox->x * pSurface->cbBlock + pBox->y * pMipLevel->cbSurfacePitch;
    2406             AssertReturnStmt(   uDestOffset + pBox->w * pSurface->cbBlock + (pBox->h - 1) * pMipLevel->cbSurfacePitch
    2407                              <= pMipLevel->cbSurface,
    2408                              RTMemFree(pDoubleBuffer),
    2409                              VERR_INTERNAL_ERROR);
    2410 
     2405            offHst = pBox->x * pSurface->cbBlock + pBox->y * pMipLevel->cbSurfacePitch;
    24112406            cbSurfacePitch = pMipLevel->cbSurfacePitch;
    24122407
     
    24172412                           - cbSurfacePitch;      /* flip image during copy */
    24182413#else
    2419             pBufferStart = pDoubleBuffer + uDestOffset;
    24202414#endif
    24212415        }
    24222416        else
    24232417        {
     2418            /* The buffer will contain only the copied rectangle. */
     2419            offHst = 0;
    24242420            cbSurfacePitch = pBox->w * pSurface->cbBlock;
    24252421#ifdef MANUAL_FLIP_SURFACE_DATA
    24262422            pBufferStart = pDoubleBuffer + cbSurfacePitch * pBox->h - cbSurfacePitch;      /* flip image during copy */
    24272423#else
    2428             pBufferStart = pDoubleBuffer;
    2429 #endif
    2430         }
     2424#endif
     2425        }
     2426
     2427        uint32_t const offGst = pBox->srcx * pSurface->cbBlock + pBox->srcy * cbGuestPitch; /// @todo compressed fmts
    24312428
    24322429        rc = vmsvgaGMRTransfer(pThis,
    24332430                               transfer,
    2434                                pBufferStart,
     2431                               pDoubleBuffer,
     2432                               pMipLevel->cbSurface,
     2433                               offHst,
    24352434#ifdef MANUAL_FLIP_SURFACE_DATA
    24362435                               -(int32_t)cbSurfacePitch,
    24372436#else
    2438                                (int32_t)cbSurfacePitch,
     2437                               cbSurfacePitch,
    24392438#endif
    24402439                               GuestPtr,
    2441                                pBox->srcx * pSurface->cbBlock + pBox->srcy * cbGuestPitch, /// @todo compressed fmts
     2440                               offGst,
    24422441                               cbGuestPitch,
    24432442                               pBox->w * pSurface->cbBlock,
     
    24982497    case SVGA3D_SURFACE_HINT_INDEXBUFFER:
    24992498    {
    2500         Assert(pBox->h == 1);
     2499        /* Caller already clipped pBox and buffers are 1-dimensional. */
     2500        Assert(pBox->y == 0 && pBox->h == 1 && pBox->z == 0 && pBox->d == 1);
    25012501
    25022502        VMSVGA3D_CLEAR_GL_ERRORS();
     
    25152515                          ("cbStrictBufSize=%#x cbSurface=%#x pContext->id=%#x\n", (uint32_t)cbStrictBufSize, pMipLevel->cbSurface, pContext->id));
    25162516#endif
    2517 
    2518                 unsigned offDst = pBox->x * pSurface->cbBlock + pBox->y * pMipLevel->cbSurfacePitch;
    2519                 if (RT_LIKELY(   offDst + pBox->w * pSurface->cbBlock  + (pBox->h - 1) * pMipLevel->cbSurfacePitch
    2520                               <= pMipLevel->cbSurface))
    2521                 {
    2522                     Log(("Lock %s memory for rectangle (%d,%d)(%d,%d)\n",
    2523                          (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_VERTEXBUFFER ? "vertex" :
    2524                            (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_INDEXBUFFER ? "index" : "buffer",
    2525                          pBox->x, pBox->y, pBox->x + pBox->w, pBox->y + pBox->h));
    2526 
    2527                     rc = vmsvgaGMRTransfer(pThis,
    2528                                            transfer,
    2529                                            pbData + offDst,
    2530                                            pMipLevel->cbSurfacePitch,
    2531                                            GuestPtr,
    2532                                            pBox->srcx * pSurface->cbBlock + pBox->srcy * cbGuestPitch,
    2533                                            cbGuestPitch,
    2534                                            pBox->w * pSurface->cbBlock,
    2535                                            pBox->h);
    2536                     AssertRC(rc);
    2537 
    2538                     Log4(("first line:\n%.*Rhxd\n", cbGuestPitch, pbData + offDst));
    2539                 }
    2540                 else
    2541                 {
    2542                     AssertFailed();
    2543                     rc = VERR_INTERNAL_ERROR;
    2544                 }
     2517                Log(("Lock %s memory for rectangle (%d,%d)(%d,%d)\n",
     2518                     (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_VERTEXBUFFER ? "vertex" :
     2519                       (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_INDEXBUFFER ? "index" : "buffer",
     2520                     pBox->x, pBox->y, pBox->x + pBox->w, pBox->y + pBox->h));
     2521
     2522                uint32_t const offHst = pBox->x * pSurface->cbBlock;
     2523
     2524                rc = vmsvgaGMRTransfer(pThis,
     2525                                       transfer,
     2526                                       pbData,
     2527                                       pMipLevel->cbSurface,
     2528                                       offHst,
     2529                                       pMipLevel->cbSurfacePitch,
     2530                                       GuestPtr,
     2531                                       pBox->srcx * pSurface->cbBlock,
     2532                                       cbGuestPitch,
     2533                                       pBox->w * pSurface->cbBlock,
     2534                                       pBox->h);
     2535                AssertRC(rc);
     2536
     2537                Log4(("first line:\n%.*Rhxd\n", cbGuestPitch, pbData + offHst));
    25452538
    25462539                pState->ext.glUnmapBuffer(GL_ARRAY_BUFFER);
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-shared.cpp

    r69852 r73194  
    11901190        pBox->d = pSize->depth - pBox->z;
    11911191}
     1192
     1193/** Clip.
     1194 *
     1195 * @param pBound    Bounding rectangle.
     1196 * @param pRect     Rectangle to be clipped.
     1197 */
     1198void vmsvgaClipRect(SVGASignedRect const *pBound,
     1199                    SVGASignedRect *pRect)
     1200{
     1201    int32_t left;
     1202    int32_t top;
     1203    int32_t right;
     1204    int32_t bottom;
     1205
     1206    /* Right order. */
     1207    Assert(pBound->left <= pBound->right && pBound->top <= pBound->bottom);
     1208    if (pRect->left < pRect->right)
     1209    {
     1210        left = pRect->left;
     1211        right = pRect->right;
     1212    }
     1213    else
     1214    {
     1215        left = pRect->right;
     1216        right = pRect->left;
     1217    }
     1218    if (pRect->top < pRect->bottom)
     1219    {
     1220        top = pRect->top;
     1221        bottom = pRect->bottom;
     1222    }
     1223    else
     1224    {
     1225        top = pRect->bottom;
     1226        bottom = pRect->top;
     1227    }
     1228
     1229    if (left < pBound->left)
     1230        left = pBound->left;
     1231    if (right < pBound->left)
     1232        right = pBound->left;
     1233
     1234    if (left > pBound->right)
     1235        left = pBound->right;
     1236    if (right > pBound->right)
     1237        right = pBound->right;
     1238
     1239    if (top < pBound->top)
     1240        top = pBound->top;
     1241    if (bottom < pBound->top)
     1242        bottom = pBound->top;
     1243
     1244    if (top > pBound->bottom)
     1245        top = pBound->bottom;
     1246    if (bottom > pBound->bottom)
     1247        bottom = pBound->bottom;
     1248
     1249    pRect->left = left;
     1250    pRect->right = right;
     1251    pRect->top = top;
     1252    pRect->bottom = bottom;
     1253}
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp

    r72241 r73194  
    21882188 * @param   cbGuestPitch        The guest pitch.
    21892189 * @param   transfer            The transfer direction.
    2190  * @param   pBox                The box to copy (clipped, valid).
     2190 * @param   pBox                The box to copy (clipped, valid, except for guest's srcx, srcy, srcz).
    21912191 * @param   pContext            The context (for OpenGL).
    21922192 * @param   rc                  The current rc for all boxes.
     
    22442244        }
    22452245
     2246        uint32_t const u32GuestBlockX = pBox->srcx / pSurface->cxBlock;
     2247        uint32_t const u32GuestBlockY = pBox->srcy / pSurface->cyBlock;
     2248        Assert(u32GuestBlockX * pSurface->cxBlock == pBox->srcx);
     2249        Assert(u32GuestBlockY * pSurface->cyBlock == pBox->srcy);
     2250        uint32_t const cBlocksX = (pBox->w + pSurface->cxBlock - 1) / pSurface->cxBlock;
     2251        uint32_t const cBlocksY = (pBox->h + pSurface->cyBlock - 1) / pSurface->cyBlock;
     2252        AssertMsgReturn(cBlocksX && cBlocksY, ("Empty box %dx%d\n", pBox->w, pBox->h), VERR_INTERNAL_ERROR);
     2253
     2254        /* vmsvgaGMRTransfer verifies uGuestOffset.
     2255         * srcx(u32GuestBlockX) and srcy(u32GuestBlockY) have been verified in vmsvga3dSurfaceDMA
     2256         * to not cause 32 bit overflow when multiplied by cbBlock and cbGuestPitch.
     2257         */
     2258        uint64_t const uGuestOffset = u32GuestBlockX * pSurface->cbBlock + u32GuestBlockY * cbGuestPitch;
     2259        AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER);
     2260
    22462261        RECT Rect;
    22472262        Rect.left   = pBox->x;
     
    22582273                 Rect.left, Rect.top, Rect.right, Rect.bottom));
    22592274
    2260         uint32_t u32BlockX = pBox->srcx / pSurface->cxBlock;
    2261         uint32_t u32BlockY = pBox->srcy / pSurface->cyBlock;
    2262         Assert(u32BlockX * pSurface->cxBlock == pBox->srcx);
    2263         Assert(u32BlockY * pSurface->cyBlock == pBox->srcy);
    2264         uint32_t cBlocksX = (pBox->w + pSurface->cxBlock - 1) / pSurface->cxBlock;
    2265         uint32_t cBlocksY = (pBox->h + pSurface->cyBlock - 1) / pSurface->cyBlock;
     2275        /* Prepare parameters for vmsvgaGMRTransfer, which needs the host buffer address, size
     2276         * and offset of the first scanline.
     2277         */
     2278        uint32_t const cbLockedBuf = RT_ABS(LockedRect.Pitch) * cBlocksY;
     2279        uint8_t *pu8LockedBuf = (uint8_t *)LockedRect.pBits;
     2280        if (LockedRect.Pitch < 0)
     2281            pu8LockedBuf -= cbLockedBuf + LockedRect.Pitch;
     2282        uint32_t const offLockedBuf = (uint32_t)((uintptr_t)LockedRect.pBits - (uintptr_t)pu8LockedBuf);
    22662283
    22672284        rc = vmsvgaGMRTransfer(pThis,
    22682285                               transfer,
    2269                                (uint8_t *)LockedRect.pBits,
     2286                               pu8LockedBuf,
     2287                               cbLockedBuf,
     2288                               offLockedBuf,
    22702289                               LockedRect.Pitch,
    22712290                               GuestPtr,
    2272                                u32BlockX * pSurface->cbBlock + u32BlockY * cbGuestPitch,
     2291                               (uint32_t)uGuestOffset,
    22732292                               cbGuestPitch,
    22742293                               cBlocksX * pSurface->cbBlock,
     
    23252344        Assert(pBox->y == 0 && pBox->h == 1 && pBox->z == 0 && pBox->d == 1);
    23262345
    2327         const uint32_t uHostOffset = pBox->x * pSurface->cbBlock;
    2328         const uint32_t cbWidth = pBox->w * pSurface->cbBlock;
    2329 
    2330         AssertReturn(uHostOffset < pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
    2331         AssertReturn(cbWidth <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
    2332         AssertReturn(uHostOffset <= pMipLevel->cbSurface - cbWidth, VERR_INTERNAL_ERROR);
    2333 
    2334         uint8_t *pu8HostData = (uint8_t *)pMipLevel->pSurfaceData + uHostOffset;
    2335 
    2336         const uint32_t uGuestOffset = pBox->srcx * pSurface->cbBlock;
     2346        /* vmsvgaGMRTransfer verifies input parameters except for the host buffer addres and size.
     2347         * srcx has been verified in vmsvga3dSurfaceDMA to not cause 32 bit overflow when multiplied by cbBlock.
     2348         */
     2349        uint32_t const offHst = pBox->x * pSurface->cbBlock;
     2350        uint32_t const cbWidth = pBox->w * pSurface->cbBlock;
     2351
     2352        uint32_t const offGst = pBox->srcx * pSurface->cbBlock;
    23372353
    23382354        /* Copy data between the guest and the host buffer. */
    23392355        rc = vmsvgaGMRTransfer(pThis,
    23402356                               transfer,
    2341                                pu8HostData,
     2357                               (uint8_t *)pMipLevel->pSurfaceData,
     2358                               pMipLevel->cbSurface,
     2359                               offHst,
    23422360                               pMipLevel->cbSurfacePitch,
    23432361                               GuestPtr,
    2344                                uGuestOffset,
     2362                               offGst,
    23452363                               cbGuestPitch,
    23462364                               cbWidth,
     
    23482366        AssertRC(rc);
    23492367
    2350         Log4(("Buffer first line:\n%.*Rhxd\n", cbWidth, pu8HostData));
     2368        Log4(("Buffer first line:\n%.*Rhxd\n", cbWidth, (uint8_t *)pMipLevel->pSurfaceData + uHostOffset));
    23512369
    23522370        /* Do not bother to copy the data to the D3D resource now. vmsvga3dDrawPrimitives will do that.
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp

    r69859 r73194  
    494494    AssertRCReturn(rc, rc);
    495495
     496    PVMSVGA3DCONTEXT pContext = NULL;
    496497    if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
    497498    {
     
    501502         */
    502503        AssertReturn(pMipLevel->pSurfaceData, VERR_INTERNAL_ERROR);
    503 
    504         for (uint32_t i = 0; i < cCopyBoxes; ++i)
    505         {
    506             Log(("Copy box (mem) %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n",
    507                   i, paBoxes[i].srcx, paBoxes[i].srcy, paBoxes[i].srcz, paBoxes[i].w, paBoxes[i].h, paBoxes[i].d, paBoxes[i].x, paBoxes[i].y));
    508 
    509             /* Apparently we're supposed to clip it (gmr test sample) */
    510             SVGA3dCopyBox clipBox = paBoxes[i];
    511             vmsvgaClipCopyBox(&pMipLevel->mipmapSize, &pMipLevel->mipmapSize, &clipBox);
    512             if (   !clipBox.w
    513                 || !clipBox.h
    514                 || !clipBox.d)
    515             {
    516                 Log(("Skip empty box\n"));
    517                 continue;
    518             }
    519 
    520             /* Calculate memory addresses of the image blocks for the transfer. */
    521             uint32_t u32HostBlockX;
    522             uint32_t u32HostBlockY;
    523             uint32_t u32GuestBlockX;
    524             uint32_t u32GuestBlockY;
    525             uint32_t cBlocksX;
    526             uint32_t cBlocksY;
    527             if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
    528             {
    529                 u32HostBlockX = clipBox.x;
    530                 u32HostBlockY = clipBox.y;
    531 
    532                 u32GuestBlockX = clipBox.srcx;
    533                 u32GuestBlockY = clipBox.srcy;
    534 
    535                 cBlocksX = clipBox.w;
    536                 cBlocksY = clipBox.h;
    537             }
    538             else
    539             {
    540                 /* Pixels to blocks. */
    541                 u32HostBlockX = clipBox.x / pSurface->cxBlock;
    542                 u32HostBlockY = clipBox.y / pSurface->cyBlock;
    543                 Assert(u32HostBlockX * pSurface->cxBlock == clipBox.x);
    544                 Assert(u32HostBlockY * pSurface->cyBlock == clipBox.y);
    545 
    546                 u32GuestBlockX = clipBox.srcx / pSurface->cxBlock;
    547                 u32GuestBlockY = clipBox.srcy / pSurface->cyBlock;
    548                 Assert(u32GuestBlockX * pSurface->cxBlock == clipBox.srcx);
    549                 Assert(u32GuestBlockY * pSurface->cyBlock == clipBox.srcy);
    550 
    551                 cBlocksX = (clipBox.w + pSurface->cxBlock - 1) / pSurface->cxBlock;
    552                 cBlocksY = (clipBox.h + pSurface->cyBlock - 1) / pSurface->cyBlock;
    553             }
    554 
    555             uint32_t cbGuestPitch;
    556             if (guest.pitch == 0)
    557                 cbGuestPitch = cBlocksX * pSurface->cbBlock;
    558             else
    559             {
    560                 cbGuestPitch = guest.pitch; /* vmsvgaGMRTransfer will verify the value. */
    561                 AssertReturn(cbGuestPitch <= SVGA3D_MAX_SURFACE_MEM_SIZE, VERR_INVALID_PARAMETER);
    562             }
    563 
     504    }
     505    else
     506    {
     507#ifdef VMSVGA3D_DIRECT3D
     508        /* Flush the drawing pipeline for this surface as it could be used in a shared context. */
     509        vmsvga3dSurfaceFlush(pThis, pSurface);
     510
     511#else /* VMSVGA3D_OPENGL */
     512        pContext = &pState->SharedCtx;
     513        VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     514#endif
     515    }
     516
     517    /* SVGA_3D_CMD_SURFACE_DMA:
     518     * "define the 'source' in each copyBox as the guest image and the
     519     * 'destination' as the host image, regardless of transfer direction."
     520     */
     521    for (uint32_t i = 0; i < cCopyBoxes; ++i)
     522    {
     523        Log(("Copy box (%s) %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n",
     524             VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface) ? "hw" : "mem",
     525             i, paBoxes[i].srcx, paBoxes[i].srcy, paBoxes[i].srcz, paBoxes[i].w, paBoxes[i].h, paBoxes[i].d, paBoxes[i].x, paBoxes[i].y));
     526
     527        /* Apparently we're supposed to clip it (gmr test sample) */
     528
     529        /* The copybox's "dest" is coords in the host surface. Verify them against the surface's mipmap size. */
     530        SVGA3dBox hostBox;
     531        hostBox.x = paBoxes[i].x;
     532        hostBox.y = paBoxes[i].y;
     533        hostBox.z = paBoxes[i].z;
     534        hostBox.w = paBoxes[i].w;
     535        hostBox.h = paBoxes[i].h;
     536        hostBox.d = paBoxes[i].d;
     537        vmsvgaClipBox(&pMipLevel->mipmapSize, &hostBox);
     538
     539        if (   !hostBox.w
     540            || !hostBox.h
     541            || !hostBox.d)
     542        {
     543            Log(("Skip empty box\n"));
     544            continue;
     545        }
     546        RT_UNTRUSTED_VALIDATED_FENCE();
     547
     548        /* Adjust the guest, i.e. "src", point.
     549         * Do not try to verify them here because vmsvgaGMRTransfer takes care of this.
     550         */
     551        uint32_t const srcx = paBoxes[i].srcx + (hostBox.x - paBoxes[i].x);
     552        uint32_t const srcy = paBoxes[i].srcy + (hostBox.y - paBoxes[i].y);
     553        uint32_t const srcz = paBoxes[i].srcz + (hostBox.z - paBoxes[i].z);
     554
     555        /* Calculate offsets of the image blocks for the transfer. */
     556        uint32_t u32HostBlockX;
     557        uint32_t u32HostBlockY;
     558        uint32_t u32GuestBlockX;
     559        uint32_t u32GuestBlockY;
     560        uint32_t cBlocksX;
     561        uint32_t cBlocksY;
     562        if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
     563        {
     564            u32HostBlockX = hostBox.x;
     565            u32HostBlockY = hostBox.y;
     566
     567            u32GuestBlockX = srcx;
     568            u32GuestBlockY = srcy;
     569
     570            cBlocksX = hostBox.w;
     571            cBlocksY = hostBox.h;
     572        }
     573        else
     574        {
     575            /* Pixels to blocks. */
     576            u32HostBlockX = hostBox.x / pSurface->cxBlock;
     577            u32HostBlockY = hostBox.y / pSurface->cyBlock;
     578            Assert(u32HostBlockX * pSurface->cxBlock == hostBox.x);
     579            Assert(u32HostBlockY * pSurface->cyBlock == hostBox.y);
     580
     581            u32GuestBlockX = srcx / pSurface->cxBlock;
     582            u32GuestBlockY = srcy / pSurface->cyBlock;
     583            Assert(u32GuestBlockX * pSurface->cxBlock == srcx);
     584            Assert(u32GuestBlockY * pSurface->cyBlock == srcy);
     585
     586            cBlocksX = (hostBox.w + pSurface->cxBlock - 1) / pSurface->cxBlock;
     587            cBlocksY = (hostBox.h + pSurface->cyBlock - 1) / pSurface->cyBlock;
     588        }
     589
     590        uint32_t cbGuestPitch = guest.pitch;
     591        if (cbGuestPitch == 0)
     592            cbGuestPitch = cBlocksX * pSurface->cbBlock; /* Have to calculate. */
     593        else
     594        {
     595            /* vmsvgaGMRTransfer will verify the value, just check it is sane. */
     596            AssertReturn(cbGuestPitch <= SVGA3D_MAX_SURFACE_MEM_SIZE, VERR_INVALID_PARAMETER);
     597            RT_UNTRUSTED_VALIDATED_FENCE();
     598        }
     599
     600        /* srcx, srcy and srcz values are used to calculate the guest offset.
     601         * The offset will be verified by vmsvgaGMRTransfer, so just check for overflows here.
     602         */
     603        AssertReturn(srcz < UINT32_MAX / pMipLevel->mipmapSize.height / cbGuestPitch, VERR_INVALID_PARAMETER);
     604        AssertReturn(u32GuestBlockY < UINT32_MAX / cbGuestPitch, VERR_INVALID_PARAMETER);
     605        AssertReturn(u32GuestBlockX < UINT32_MAX / pSurface->cbBlock, VERR_INVALID_PARAMETER);
     606        RT_UNTRUSTED_VALIDATED_FENCE();
     607
     608        if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
     609        {
    564610            uint64_t uGuestOffset = u32GuestBlockX * pSurface->cbBlock +
    565611                                    u32GuestBlockY * cbGuestPitch +
    566                                     clipBox.srcz * pMipLevel->mipmapSize.height * cbGuestPitch;
     612                                    srcz * pMipLevel->mipmapSize.height * cbGuestPitch;
    567613            AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER);
    568614
     
    570616            uint32_t uHostOffset = u32HostBlockX * pSurface->cbBlock +
    571617                                   u32HostBlockY * pMipLevel->cbSurfacePitch +
    572                                    clipBox.z * pMipLevel->cbSurfacePlane;
     618                                   hostBox.z * pMipLevel->cbSurfacePlane;
    573619            AssertReturn(uHostOffset < pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
    574620
    575             for (uint32_t z = 0; z < clipBox.d; ++z)
     621            for (uint32_t z = 0; z < hostBox.d; ++z)
    576622            {
    577623                rc = vmsvgaGMRTransfer(pThis,
    578624                                       transfer,
    579                                        (uint8_t *)pMipLevel->pSurfaceData + uHostOffset,
     625                                       (uint8_t *)pMipLevel->pSurfaceData,
     626                                       pMipLevel->cbSurface,
     627                                       uHostOffset,
    580628                                       (int32_t)pMipLevel->cbSurfacePitch,
    581629                                       guest.ptr,
     
    591639                uHostOffset += pMipLevel->cbSurfacePlane;
    592640                uGuestOffset += pMipLevel->mipmapSize.height * cbGuestPitch;
     641                AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER);
    593642            }
    594643        }
    595 
    596         pMipLevel->fDirty = true;
    597         pSurface->fDirty = true;
    598     }
    599     else
    600     {
    601         /*
    602          * Because of the clipping below, we're doing a little more
    603          * here before calling the backend specific code.
    604          */
    605 #ifdef VMSVGA3D_DIRECT3D
    606         /* Flush the drawing pipeline for this surface as it could be used in a shared context. */
    607         vmsvga3dSurfaceFlush(pThis, pSurface);
    608         PVMSVGA3DCONTEXT pContext = NULL;
    609 
    610 #else /* VMSVGA3D_OPENGL */
    611         PVMSVGA3DCONTEXT pContext = &pState->SharedCtx;
    612         VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
    613 #endif
    614 
    615         for (uint32_t i = 0; i < cCopyBoxes; ++i)
    616         {
    617             /** @todo Identical code to the above no-hw branch. Think about merging. */
    618             Log(("Copy box (hw) %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n",
    619                   i, paBoxes[i].srcx, paBoxes[i].srcy, paBoxes[i].srcz, paBoxes[i].w, paBoxes[i].h, paBoxes[i].d, paBoxes[i].x, paBoxes[i].y));
    620 
    621             /* Apparently we're supposed to clip it (gmr test sample) */
    622             SVGA3dCopyBox clipBox = paBoxes[i];
    623             vmsvgaClipCopyBox(&pMipLevel->mipmapSize, &pMipLevel->mipmapSize, &clipBox);
    624             if (   !clipBox.w
    625                 || !clipBox.h
    626                 || !clipBox.d)
    627             {
    628                 Log(("Skip empty box\n"));
    629                 continue;
    630             }
    631 
    632             /* Calculate memory addresses of the image blocks for the transfer. */
    633             uint32_t u32HostBlockX;
    634             uint32_t u32HostBlockY;
    635             uint32_t u32GuestBlockX;
    636             uint32_t u32GuestBlockY;
    637             uint32_t cBlocksX;
    638             uint32_t cBlocksY;
    639             if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
    640             {
    641                 u32HostBlockX = clipBox.x;
    642                 u32HostBlockY = clipBox.y;
    643 
    644                 u32GuestBlockX = clipBox.srcx;
    645                 u32GuestBlockY = clipBox.srcy;
    646 
    647                 cBlocksX = clipBox.w;
    648                 cBlocksY = clipBox.h;
    649             }
    650             else
    651             {
    652                 /* Pixels to blocks. */
    653                 u32HostBlockX = clipBox.x / pSurface->cxBlock;
    654                 u32HostBlockY = clipBox.y / pSurface->cyBlock;
    655                 Assert(u32HostBlockX * pSurface->cxBlock == clipBox.x);
    656                 Assert(u32HostBlockY * pSurface->cyBlock == clipBox.y);
    657 
    658                 u32GuestBlockX = clipBox.srcx / pSurface->cxBlock;
    659                 u32GuestBlockY = clipBox.srcy / pSurface->cyBlock;
    660                 Assert(u32GuestBlockX * pSurface->cxBlock == clipBox.srcx);
    661                 Assert(u32GuestBlockY * pSurface->cyBlock == clipBox.srcy);
    662 
    663                 cBlocksX = (clipBox.w + pSurface->cxBlock - 1) / pSurface->cxBlock;
    664                 cBlocksY = (clipBox.h + pSurface->cyBlock - 1) / pSurface->cyBlock;
    665             }
    666 
    667             uint32_t cbGuestPitch;
    668             if (guest.pitch == 0)
    669                 cbGuestPitch = cBlocksX * pSurface->cbBlock;
    670             else
    671             {
    672                 cbGuestPitch = guest.pitch; /* vmsvgaGMRTransfer will verify the value. */
    673                 AssertReturn(cbGuestPitch <= SVGA3D_MAX_SURFACE_MEM_SIZE, VERR_INVALID_PARAMETER);
    674             }
    675 
     644        else
     645        {
     646            SVGA3dCopyBox clipBox;
     647            clipBox.x = hostBox.x;
     648            clipBox.y = hostBox.y;
     649            clipBox.z = hostBox.z;
     650            clipBox.w = hostBox.w;
     651            clipBox.h = hostBox.h;
     652            clipBox.d = hostBox.d;
     653            clipBox.srcx = srcx;
     654            clipBox.srcy = srcy;
     655            clipBox.srcz = srcz;
    676656            rc = vmsvga3dBackSurfaceDMACopyBox(pThis, pState, pSurface, pMipLevel, host.face, host.mipmap,
    677657                                               guest.ptr, cbGuestPitch, transfer,
     
    679659            AssertRC(rc);
    680660        }
     661    }
     662
     663    if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
     664    {
     665        pMipLevel->fDirty = true;
     666        pSurface->fDirty = true;
    681667    }
    682668
     
    691677    queryResult.result32 = u32Result;
    692678
    693     int rc = vmsvgaGMRTransfer(pThis, SVGA3D_READ_HOST_VRAM, (uint8_t *)&queryResult, sizeof(queryResult),
     679    int rc = vmsvgaGMRTransfer(pThis, SVGA3D_READ_HOST_VRAM,
     680                               (uint8_t *)&queryResult, sizeof(queryResult), 0, sizeof(queryResult),
    694681                               guestResult, 0, sizeof(queryResult), sizeof(queryResult), 1);
    695682    AssertRC(rc);
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.h

    r73004 r73194  
    5151/* DevVGA-SVGA.cpp: */
    5252void vmsvgaGMRFree(PVGASTATE pThis, uint32_t idGMR);
    53 int vmsvgaGMRTransfer(PVGASTATE pThis, const SVGA3dTransferType enmTransferType, uint8_t *pbHst, int32_t cbHstPitch,
    54                       SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch, uint32_t cbWidth, uint32_t cHeight);
     53int vmsvgaGMRTransfer(PVGASTATE pThis, const SVGA3dTransferType enmTransferType,
     54                      uint8_t *pbHstBuf, uint32_t cbHstBuf, uint32_t offHst, int32_t cbHstPitch,
     55                      SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch,
     56                      uint32_t cbWidth, uint32_t cHeight);
    5557void vmsvga3dSurfaceUpdateHeapBuffersOnFifoThread(PVGASTATE pThis, uint32_t sid);
    5658
     
    123125void vmsvga3dInfoSurfaceWorker(PVGASTATE pThis, PCDBGFINFOHLP pHlp, uint32_t sid, bool fVerbose, uint32_t cxAscii, bool fInvY, const char *pszBitmapPath);
    124126
     127void vmsvgaClipRect(SVGASignedRect const *pBound,
     128                    SVGASignedRect *pRect);
    125129
    126130/* DevVGA-SVGA3d-shared.cpp: */
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