VirtualBox

Changeset 33306 in vbox


Ignore:
Timestamp:
Oct 21, 2010 12:52:37 PM (14 years ago)
Author:
vboxsync
Message:

wddm/3d: scrolling with aero 8x speedup, bugfixing + profiling

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxCrHgsmi.h

    r33119 r33306  
    4848VBOXCRHGSMI_DECL(HVBOXCRHGSMI_CLIENT) VBoxCrHgsmiQueryClient();
    4949
     50VBOXCRHGSMI_DECL(void) VBoxCrHgsmiLog(char * szString);
     51
    5052RT_C_DECLS_END
    5153
  • trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxCrHgsmi.cpp

    r33241 r33306  
    88static uint32_t g_cVBoxCrHgsmiProvider = 0;
    99
     10static VBOXDISPKMT_CALLBACKS g_VBoxCrHgsmiKmtCallbacks;
     11
    1012typedef VBOXWDDMDISP_DECL(int) FNVBOXDISPCRHGSMI_INIT(PVBOXCRHGSMI_CALLBACKS pCallbacks);
    1113typedef FNVBOXDISPCRHGSMI_INIT *PFNVBOXDISPCRHGSMI_INIT;
     
    2325VBOXCRHGSMI_DECL(int) VBoxCrHgsmiInit(PVBOXCRHGSMI_CALLBACKS pCallbacks)
    2426{
     27    static int bKmtCallbacksInited = 0;
     28    if (!bKmtCallbacksInited)
     29    {
     30        HRESULT hr = vboxDispKmtCallbacksInit(&g_VBoxCrHgsmiKmtCallbacks);
     31        Assert(hr == S_OK);
     32        if (hr == S_OK)
     33            bKmtCallbacksInited = 1;
     34        else
     35            bKmtCallbacksInited = -1;
     36    }
     37
     38    Assert(bKmtCallbacksInited);
     39    if (bKmtCallbacksInited < 0)
     40    {
     41        Assert(0);
     42        return VERR_NOT_SUPPORTED;
     43    }
     44
    2545    g_VBoxCrHgsmiCallbacks = *pCallbacks;
    2646    if (!g_hVBoxCrHgsmiProvider)
     
    7797    {
    7898        hClient = g_pfnVBoxDispCrHgsmiQueryClient();
    79 #ifdef DEBUG_misha
    80         Assert(hClient);
    81 #endif
     99//#ifdef DEBUG_misha
     100//        Assert(hClient);
     101//#endif
    82102        if (hClient)
    83103            return hClient;
     
    125145}
    126146
     147VBOXCRHGSMI_DECL(void) VBoxCrHgsmiLog(char * szString)
     148{
     149    VBOXDISPKMT_ADAPTER Adapter;
     150    HRESULT hr = vboxDispKmtOpenAdapter(&g_VBoxCrHgsmiKmtCallbacks, &Adapter);
     151    Assert(hr == S_OK);
     152    if (hr == S_OK)
     153    {
     154        uint32_t cbString = (uint32_t)strlen(szString) + 1;
     155        uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGPRINT, aStringBuf[cbString]);
     156        PVBOXDISPIFESCAPE_DBGPRINT pCmd = (PVBOXDISPIFESCAPE_DBGPRINT)RTMemAllocZ(cbCmd);
     157        Assert(pCmd);
     158        if (pCmd)
     159        {
     160            pCmd->EscapeHdr.escapeCode = VBOXESC_DBGPRINT;
     161            memcpy(pCmd->aStringBuf, szString, cbString);
     162
     163            D3DKMT_ESCAPE EscapeData = {0};
     164            EscapeData.hAdapter = Adapter.hAdapter;
     165            //EscapeData.hDevice = NULL;
     166            EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
     167    //        EscapeData.Flags.HardwareAccess = 1;
     168            EscapeData.pPrivateDriverData = pCmd;
     169            EscapeData.PrivateDriverDataSize = cbCmd;
     170            //EscapeData.hContext = NULL;
     171
     172            int Status = g_VBoxCrHgsmiKmtCallbacks.pfnD3DKMTEscape(&EscapeData);
     173            Assert(!Status);
     174
     175            RTMemFree(pCmd);
     176        }
     177        hr = vboxDispKmtCloseAdapter(&Adapter);
     178        Assert(hr == S_OK);
     179    }
     180}
    127181
    128182///* to be used by injection thread and by ogl ICD driver for hgsmi initialization*/
  • trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp

    r33281 r33306  
    16991699        pSwapchain->pRenderTargetFbCopy->Release();
    17001700        pSwapchain->pRenderTargetFbCopy = NULL;
     1701        pSwapchain->bRTFbCopyUpToDate = FALSE;
    17011702#endif
    17021703        pSwapchain->pSwapChainIf->Release();
     
    23582359        pSwapchain->pSwapChainIf = pNewIf;
    23592360#ifndef VBOXWDDM_WITH_VISIBLE_FB
     2361        pSwapchain->bRTFbCopyUpToDate = FALSE;
    23602362        if (!pSwapchain->pRenderTargetFbCopy)
    23612363        {
     
    24622464    if (hr == S_OK)
    24632465    {
     2466        pSwapchain->bRTFbCopyUpToDate = FALSE;
    24642467        vboxWddmSwapchainFlip(pSwapchain);
    24652468        Assert(pSwapchain->fFlags.Value == 0);
     
    63556358                    pSrcSurfIf = pSrcSwapchain->pRenderTargetFbCopy;
    63566359                    Assert(pSrcSurfIf);
    6357                     hr = pSrcSwapchain->pSwapChainIf->GetFrontBufferData(pSrcSurfIf);
    6358                     Assert(hr == S_OK);
    6359                     if (hr == S_OK)
     6360                    if (!pSrcSwapchain->bRTFbCopyUpToDate)
    63606361                    {
    6361                         /* do pSrcSurfIf->AddRef since we do a Release in the following if (hr == S_OK) branch */
     6362                        hr = pSrcSwapchain->pSwapChainIf->GetFrontBufferData(pSrcSurfIf);
     6363                        Assert(hr == S_OK);
     6364                        if (hr == S_OK)
     6365                        {
     6366                            /* do pSrcSurfIf->AddRef since we do a Release in the following if (hr == S_OK) branch */
     6367                            pSrcSwapchain->bRTFbCopyUpToDate = TRUE;
     6368                            pSrcSurfIf->AddRef();
     6369                        }
     6370                    }
     6371                    else
     6372                    {
    63626373                        pSrcSurfIf->AddRef();
    63636374                    }
  • trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h

    r33171 r33306  
    139139#ifndef VBOXWDDM_WITH_VISIBLE_FB
    140140    IDirect3DSurface9 *pRenderTargetFbCopy;
     141    BOOL bRTFbCopyUpToDate;
    141142#endif
    142143    IDirect3DSwapChain9 *pSwapChainIf;
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp

    r33252 r33306  
    983983    Assert(Status == STATUS_SUCCESS);
    984984
     985    if (context.data.bNotifyDpc)
     986        pDevExt->u.primary.DxgkInterface.DxgkCbNotifyDpc(pDevExt->u.primary.DxgkInterface.DeviceHandle);
     987
    985988    if (!vboxSHGSMIListIsEmpty(&context.data.CtlList))
    986989    {
     
    10031006
    10041007    vboxVdmaDdiCmdHandleCompletedList(pDevExt, &pDevExt->DdiCmdQueue, &context.data.CompletedDdiCmdQueue);
    1005 
    1006     if (context.data.bNotifyDpc)
    1007         pDevExt->u.primary.DxgkInterface.DxgkCbNotifyDpc(pDevExt->u.primary.DxgkInterface.DeviceHandle);
    10081008
    10091009//    dfprintf(("<== "__FUNCTION__ ", context(0x%p)\n", MiniportDeviceContext));
     
    42454245    DXGKARG_RENDER  *pRender)
    42464246{
    4247     drprintf(("==> "__FUNCTION__ ", hContext(0x%x)\n", hContext));
     4247//    drprintf(("==> "__FUNCTION__ ", hContext(0x%x)\n", hContext));
    42484248
    42494249    Assert(pRender->DmaBufferPrivateDataSize >= sizeof (VBOXWDDM_DMA_PRIVATEDATA_BASEHDR));
     
    43474347    }
    43484348
    4349     drprintf(("<== "__FUNCTION__ ", hContext(0x%x)\n", hContext));
     4349//    drprintf(("<== "__FUNCTION__ ", hContext(0x%x)\n", hContext));
    43504350
    43514351    return Status;
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c

    r33282 r33306  
    854854}
    855855
     856#ifdef VBOX_WITH_WDDM
     857static void surface_upload_data_rect(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
     858        const struct wined3d_format_desc *format_desc, BOOL srgb, const GLvoid *data, RECT *pRect)
     859{
     860    GLsizei width = pRect->right - pRect->left;
     861    GLsizei height = pRect->bottom - pRect->top;
     862    GLenum internal;
     863
     864    if (srgb)
     865    {
     866        internal = format_desc->glGammaInternal;
     867    }
     868    else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET
     869            && surface_is_offscreen((IWineD3DSurface *)This))
     870    {
     871        internal = format_desc->rtInternal;
     872    }
     873    else
     874    {
     875        internal = format_desc->glInternal;
     876    }
     877
     878    TRACE("This %p, internal %#x, width %d, height %d, format %#x, type %#x, data %p.\n",
     879            This, internal, width, height, format_desc->glFormat, format_desc->glType, data);
     880    TRACE("target %#x, level %u, resource size %u.\n",
     881            This->texture_target, This->texture_level, This->resource.size);
     882
     883    if (format_desc->heightscale != 1.0f && format_desc->heightscale != 0.0f) height *= format_desc->heightscale;
     884
     885    ENTER_GL();
     886
     887    if (This->Flags & SFLAG_PBO)
     888    {
     889        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
     890        checkGLcall("glBindBufferARB");
     891
     892        TRACE("(%p) pbo: %#x, data: %p.\n", This, This->pbo, data);
     893        data = NULL;
     894    }
     895
     896    if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
     897    {
     898        TRACE("Calling glCompressedTexSubImage2DARB.\n");
     899
     900        GL_EXTCALL(glCompressedTexSubImage2DARB(This->texture_target, This->texture_level,
     901                pRect->left, pRect->top, width, height, internal, This->resource.size, data));
     902        checkGLcall("glCompressedTexSubImage2DARB");
     903    }
     904    else
     905    {
     906        TRACE("Calling glTexSubImage2D.\n");
     907
     908        glTexSubImage2D(This->texture_target, This->texture_level,
     909                pRect->left, pRect->top, width, height, format_desc->glFormat, format_desc->glType, data);
     910        checkGLcall("glTexSubImage2D");
     911    }
     912
     913    if (This->Flags & SFLAG_PBO)
     914    {
     915        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
     916        checkGLcall("glBindBufferARB");
     917    }
     918
     919    LEAVE_GL();
     920
     921    if (gl_info->quirks & WINED3D_QUIRK_FBO_TEX_UPDATE)
     922    {
     923        IWineD3DDeviceImpl *device = This->resource.device;
     924        unsigned int i;
     925
     926        for (i = 0; i < device->numContexts; ++i)
     927        {
     928            context_surface_update(device->contexts[i], This);
     929        }
     930    }
     931}
     932#endif
     933
    856934/* This call just allocates the texture, the caller is responsible for binding
    857935 * the correct texture. */
     
    38993977}
    39003978
     3979#ifdef VBOX_WITH_WDDM
     3980/* Not called from the VTable */
     3981static HRESULT IWineD3DSurfaceImpl_BltSys2Vram(IWineD3DSurfaceImpl *This, const RECT *DestRect,
     3982        IWineD3DSurface *SrcSurface, const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx,
     3983        WINED3DTEXTUREFILTERTYPE Filter)
     3984{
     3985    IWineD3DDeviceImpl *myDevice = This->resource.device;
     3986    const struct wined3d_gl_info *gl_info = &myDevice->adapter->gl_info;
     3987    IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
     3988    RECT dst_rect, src_rect;
     3989    struct wined3d_format_desc desc;
     3990    CONVERT_TYPES convert;
     3991    struct wined3d_context *context = NULL;
     3992    BYTE *mem;
     3993    BYTE *updateMem;
     3994    BOOL srgb;
     3995    int srcWidth, srcPitch;
     3996
     3997    TRACE("(%p)->(%p,%p,%p,%08x,%p)\n", This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx);
     3998
     3999    if(This->Flags & SFLAG_INSYSMEM) {
     4000        WARN("Destination has a SYSMEM location valid, rejecting gl blt\n");
     4001        return WINED3DERR_INVALIDCALL;
     4002    }
     4003
     4004    if(!(This->Flags & SFLAG_INTEXTURE)
     4005            && !(This->Flags & SFLAG_INSRGBTEX)) {
     4006        WARN("Destination does NOT have a TEXTURE location valid, rejecting gl blt\n");
     4007        return WINED3DERR_INVALIDCALL;
     4008    }
     4009
     4010    srgb = !(This->Flags & SFLAG_INTEXTURE);
     4011
     4012    if(!(Src->Flags & SFLAG_INSYSMEM)) {
     4013        WARN("Source does NOT have a SYSMEM location valid, rejecting gl blt\n");
     4014        return WINED3DERR_INVALIDCALL;
     4015    }
     4016
     4017    if(This->resource.format_desc != Src->resource.format_desc) {
     4018        WARN("Src and Dest Formats NOT equal, rejecting gl blt\n");
     4019        return WINED3DERR_INVALIDCALL;
     4020    }
     4021
     4022    /* No destination color keying supported */
     4023    if(Flags & (WINEDDBLT_KEYDEST | WINEDDBLT_KEYDESTOVERRIDE)) {
     4024        /* Can we support that with glBlendFunc if blitting to the frame buffer? */
     4025        TRACE("Destination color key not supported in accelerated Blit, falling back to software\n");
     4026        return WINED3DERR_INVALIDCALL;
     4027    }
     4028
     4029    surface_get_rect(This, DestRect, &dst_rect);
     4030    surface_get_rect(Src, SrcRect, &src_rect);
     4031
     4032    if (src_rect.right - src_rect.left != dst_rect.right - dst_rect.left
     4033            || src_rect.bottom - src_rect.top != dst_rect.bottom - dst_rect.top)
     4034    {
     4035        WARN("Stretching requested, rejecting gl blt\n");
     4036        return WINED3DERR_INVALIDCALL;
     4037    }
     4038
     4039    d3dfmt_get_conv(Src, TRUE /* We need color keying */, TRUE /* We will use textures */,
     4040            &desc, &convert);
     4041
     4042    if  (desc.convert || convert != NO_CONVERSION)
     4043    {
     4044        WARN("TODO: test if conversion works, rejecting gl blt\n");
     4045        return WINED3DERR_INVALIDCALL;
     4046    }
     4047
     4048    if (!myDevice->isInDraw) context = context_acquire(myDevice, NULL, CTXUSAGE_RESOURCELOAD);
     4049
     4050    surface_bind_and_dirtify(This, srgb);
     4051
     4052    if(This->CKeyFlags & WINEDDSD_CKSRCBLT) {
     4053        This->Flags |= SFLAG_GLCKEY;
     4054        This->glCKey = This->SrcBltCKey;
     4055    }
     4056    else This->Flags &= ~SFLAG_GLCKEY;
     4057
     4058//    /* The width is in 'length' not in bytes */
     4059    srcWidth = Src->currentDesc.Width;
     4060    srcPitch = IWineD3DSurface_GetPitch(SrcSurface);
     4061
     4062    /* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED
     4063     * but it isn't set (yet) in all cases it is getting called. */
     4064    if((convert != NO_CONVERSION) && (This->Flags & SFLAG_PBO)) {
     4065        TRACE("Removing the pbo attached to surface %p\n", This);
     4066        surface_remove_pbo(This, gl_info);
     4067    }
     4068
     4069    if(desc.convert) {
     4070        /* This code is entered for texture formats which need a fixup. */
     4071        int srcHeight = Src->currentDesc.Height;
     4072//        int width = Src->currentDesc.Width;
     4073//        int pitch = IWineD3DSurface_GetPitch(SrcSurface);
     4074
     4075        /* Stick to the alignment for the converted surface too, makes it easier to load the surface */
     4076        int outpitch = srcWidth * desc.conv_byte_count;
     4077        outpitch = (outpitch + myDevice->surface_alignment - 1) & ~(myDevice->surface_alignment - 1);
     4078
     4079        mem = HeapAlloc(GetProcessHeap(), 0, outpitch * srcHeight);
     4080        if(!mem) {
     4081            ERR("Out of memory %d, %d!\n", outpitch, srcHeight);
     4082            if (context) context_release(context);
     4083            return WINED3DERR_OUTOFVIDEOMEMORY;
     4084        }
     4085        desc.convert(Src->resource.allocatedMemory, mem, srcPitch, srcWidth, srcHeight);
     4086    } else if((convert != NO_CONVERSION) && Src->resource.allocatedMemory) {
     4087        /* This code is only entered for color keying fixups */
     4088        int srcHeight = Src->currentDesc.Height;
     4089        int outpitch;
     4090//        int width = Src->currentDesc.Width;
     4091//        int pitch = IWineD3DSurface_GetPitch(SrcSurface);
     4092
     4093        /* Stick to the alignment for the converted surface too, makes it easier to load the surface */
     4094        outpitch = srcWidth * desc.conv_byte_count;
     4095        outpitch = (outpitch + myDevice->surface_alignment - 1) & ~(myDevice->surface_alignment - 1);
     4096
     4097        mem = HeapAlloc(GetProcessHeap(), 0, outpitch * srcHeight);
     4098        if(!mem) {
     4099            ERR("Out of memory %d, %d!\n", outpitch, srcHeight);
     4100            if (context) context_release(context);
     4101            return WINED3DERR_OUTOFVIDEOMEMORY;
     4102        }
     4103        d3dfmt_convert_surface(Src->resource.allocatedMemory, mem, srcPitch, srcWidth, srcHeight, outpitch, convert, Src);
     4104    } else {
     4105        mem = Src->resource.allocatedMemory;
     4106    }
     4107
     4108    updateMem = mem + srcPitch * src_rect.top;
     4109
     4110    /* Make sure the correct pitch is used */
     4111    ENTER_GL();
     4112    glPixelStorei(GL_UNPACK_ROW_LENGTH, Src->currentDesc.Width);
     4113    glPixelStorei(GL_UNPACK_SKIP_PIXELS, src_rect.left);
     4114    LEAVE_GL();
     4115
     4116    if (mem || (This->Flags & SFLAG_PBO))
     4117        surface_upload_data_rect(This, gl_info, &desc, srgb, updateMem, &dst_rect);
     4118
     4119    /* Restore the default pitch */
     4120    ENTER_GL();
     4121    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
     4122    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
     4123    LEAVE_GL();
     4124
     4125    if (context) context_release(context);
     4126
     4127    /* Don't delete PBO memory */
     4128    if((mem != Src->resource.allocatedMemory) && !(This->Flags & SFLAG_PBO))
     4129        HeapFree(GetProcessHeap(), 0, mem);
     4130    ////
     4131
     4132    IWineD3DSurface_ModifyLocation((IWineD3DSurface *)This, srgb ? SFLAG_INSRGBTEX : SFLAG_INTEXTURE, TRUE);
     4133
     4134    return WINED3D_OK;
     4135}
     4136#endif
     4137
    39014138static HRESULT WINAPI IWineD3DSurfaceImpl_Blt(IWineD3DSurface *iface, const RECT *DestRect, IWineD3DSurface *SrcSurface,
    39024139        const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter) {
     
    39324169        if(IWineD3DSurfaceImpl_BltOverride(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx, Filter) == WINED3D_OK) return WINED3D_OK;
    39334170    }
     4171
     4172#ifdef VBOX_WITH_WDDM
     4173    if (IWineD3DSurfaceImpl_BltSys2Vram(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx, Filter) == WINED3D_OK) return WINED3D_OK;
     4174#endif
    39344175
    39354176    /* For the rest call the X11 surface implementation.
  • trunk/src/VBox/Devices/Graphics/DevVGA_VDMA.cpp

    r33216 r33306  
    524524    void * pvDst;
    525525    int rc = VINF_SUCCESS;
     526    uint32_t cbTransfer = pTransfer->cbTransferSize;
     527    uint32_t cbTransfered = 0;
    526528    bool bSrcLocked = false;
    527529    bool bDstLocked = false;
    528     if (pTransfer->fFlags & VBOXVDMACMD_DMA_BPB_TRANSFER_F_SRC_VRAMOFFSET)
    529     {
    530         pvSrc = pvRam + pTransfer->Src.offVramBuf;
    531     }
    532     else
    533     {
    534         RTGCPHYS phPage = pTransfer->Src.phBuf;
    535         rc = PDMDevHlpPhysGCPhys2CCPtrReadOnly(pDevIns, phPage, 0, &pvSrc, &SrcLock);
    536         AssertRC(rc);
     530    do
     531    {
     532        uint32_t cbSubTransfer = cbTransfer;
     533        if (pTransfer->fFlags & VBOXVDMACMD_DMA_BPB_TRANSFER_F_SRC_VRAMOFFSET)
     534        {
     535            pvSrc  = pvRam + pTransfer->Src.offVramBuf + cbTransfered;
     536        }
     537        else
     538        {
     539            RTGCPHYS phPage = pTransfer->Src.phBuf;
     540            phPage += cbTransfered;
     541            rc = PDMDevHlpPhysGCPhys2CCPtrReadOnly(pDevIns, phPage, 0, &pvSrc, &SrcLock);
     542            AssertRC(rc);
     543            if (RT_SUCCESS(rc))
     544            {
     545                bSrcLocked = true;
     546                cbSubTransfer = RT_MIN(cbSubTransfer, 0x1000);
     547            }
     548            else
     549            {
     550                break;
     551            }
     552        }
     553
     554        if (pTransfer->fFlags & VBOXVDMACMD_DMA_BPB_TRANSFER_F_DST_VRAMOFFSET)
     555        {
     556            pvDst  = pvRam + pTransfer->Dst.offVramBuf + cbTransfered;
     557        }
     558        else
     559        {
     560            RTGCPHYS phPage = pTransfer->Dst.phBuf;
     561            phPage += cbTransfered;
     562            rc = PDMDevHlpPhysGCPhys2CCPtr(pDevIns, phPage, 0, &pvDst, &DstLock);
     563            AssertRC(rc);
     564            if (RT_SUCCESS(rc))
     565            {
     566                bDstLocked = true;
     567                cbSubTransfer = RT_MIN(cbSubTransfer, 0x1000);
     568            }
     569            else
     570            {
     571                break;
     572            }
     573        }
     574
    537575        if (RT_SUCCESS(rc))
    538576        {
    539             bSrcLocked = true;
    540         }
    541     }
    542 
    543     if (pTransfer->fFlags & VBOXVDMACMD_DMA_BPB_TRANSFER_F_DST_VRAMOFFSET)
    544     {
    545         pvDst = pvRam + pTransfer->Dst.offVramBuf;
    546     }
    547     else
    548     {
    549         RTGCPHYS phPage = pTransfer->Dst.phBuf;
    550         rc = PDMDevHlpPhysGCPhys2CCPtr(pDevIns, phPage, 0, &pvDst, &DstLock);
    551         AssertRC(rc);
    552         if (RT_SUCCESS(rc))
    553         {
    554             bDstLocked = true;
    555         }
    556     }
    557 
    558     if (RT_SUCCESS(rc))
    559     {
    560         memcpy(pvDst, pvSrc, pTransfer->cbTransferSize);
    561     }
    562 
    563     if (bSrcLocked)
    564         PDMDevHlpPhysReleasePageMappingLock(pDevIns, &SrcLock);
    565     if (bDstLocked)
    566         PDMDevHlpPhysReleasePageMappingLock(pDevIns, &DstLock);
     577            memcpy(pvDst, pvSrc, cbSubTransfer);
     578            cbTransfer -= cbSubTransfer;
     579            cbTransfered += cbSubTransfer;
     580        }
     581        else
     582        {
     583            cbTransfer = 0; /* to break */
     584        }
     585
     586        if (bSrcLocked)
     587            PDMDevHlpPhysReleasePageMappingLock(pDevIns, &SrcLock);
     588        if (bDstLocked)
     589            PDMDevHlpPhysReleasePageMappingLock(pDevIns, &DstLock);
     590    } while (cbTransfer);
    567591
    568592    if (RT_SUCCESS(rc))
  • trunk/src/VBox/GuestHost/OpenGL/util/vboxhgsmi.c

    r33241 r33306  
    6060#endif
    6161
     62#define VBOX_WITH_CRHGSMIPROFILE
     63#ifdef VBOX_WITH_CRHGSMIPROFILE
     64#include <iprt/time.h>
     65#include <stdio.h>
     66
     67typedef struct VBOXCRHGSMIPROFILE
     68{
     69    uint64_t cStartTime;
     70    uint64_t cStepsTime;
     71    uint64_t cSteps;
     72} VBOXCRHGSMIPROFILE, *PVBOXCRHGSMIPROFILE;
     73
     74#define VBOXCRHGSMIPROFILE_GET_TIME_NANO() RTTimeNanoTS()
     75#define VBOXCRHGSMIPROFILE_GET_TIME_MILLI() RTTimeMilliTS()
     76
     77/* 10 sec */
     78#define VBOXCRHGSMIPROFILE_LOG_STEP_TIME (10000000000.)
     79
     80DECLINLINE(void) vboxCrHgsmiProfileStart(PVBOXCRHGSMIPROFILE pProfile)
     81{
     82    pProfile->cStepsTime = 0;
     83    pProfile->cSteps = 0;
     84    pProfile->cStartTime = VBOXCRHGSMIPROFILE_GET_TIME_NANO();
     85}
     86
     87DECLINLINE(void) vboxCrHgsmiProfileStep(PVBOXCRHGSMIPROFILE pProfile, uint64_t cStepTime)
     88{
     89    pProfile->cStepsTime += cStepTime;
     90    ++pProfile->cSteps;
     91}
     92
     93typedef struct VBOXCRHGSMIPROFILE_SCOPE
     94{
     95    uint64_t cStartTime;
     96//    bool bDisable;
     97} VBOXCRHGSMIPROFILE_SCOPE, *PVBOXCRHGSMIPROFILE_SCOPE;
     98
     99static VBOXCRHGSMIPROFILE g_VBoxProfile;
     100
     101static void vboxCrHgsmiLog(char * szString, ...)
     102{
     103    char szBuffer[4096] = {0};
     104     va_list pArgList;
     105     va_start(pArgList, szString);
     106     _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList);
     107     va_end(pArgList);
     108
     109     VBoxCrHgsmiLog(szBuffer);
     110}
     111
     112DECLINLINE(void) vboxCrHgsmiProfileLog(PVBOXCRHGSMIPROFILE pProfile, uint64_t cTime)
     113{
     114    uint64_t profileTime = cTime - pProfile->cStartTime;
     115    double percent = ((double)100.0) * pProfile->cStepsTime / profileTime;
     116    double cps = ((double)1000000000.) * pProfile->cSteps / profileTime;
     117    vboxCrHgsmiLog("hgsmi: cps: %.1f, host %.1f%%\n", cps, percent);
     118}
     119
     120DECLINLINE(void) vboxCrHgsmiProfileScopeEnter(PVBOXCRHGSMIPROFILE_SCOPE pScope)
     121{
     122//    pScope->bDisable = false;
     123    pScope->cStartTime = VBOXCRHGSMIPROFILE_GET_TIME_NANO();
     124}
     125
     126DECLINLINE(void) vboxCrHgsmiProfileScopeExit(PVBOXCRHGSMIPROFILE_SCOPE pScope)
     127{
     128//    if (!pScope->bDisable)
     129    {
     130        uint64_t cTime = VBOXCRHGSMIPROFILE_GET_TIME_NANO();
     131        vboxCrHgsmiProfileStep(&g_VBoxProfile, cTime - pScope->cStartTime);
     132        if (VBOXCRHGSMIPROFILE_LOG_STEP_TIME < cTime - g_VBoxProfile.cStartTime)
     133        {
     134            vboxCrHgsmiProfileLog(&g_VBoxProfile, cTime);
     135            vboxCrHgsmiProfileStart(&g_VBoxProfile);
     136        }
     137    }
     138}
     139
     140
     141#define VBOXCRHGSMIPROFILE_INIT() vboxCrHgsmiProfileStart(&g_VBoxProfile)
     142#define VBOXCRHGSMIPROFILE_TERM() do {} while (0)
     143
     144#define VBOXCRHGSMIPROFILE_FUNC_PROLOGUE() \
     145        VBOXCRHGSMIPROFILE_SCOPE __vboxCrHgsmiProfileScope; \
     146        vboxCrHgsmiProfileScopeEnter(&__vboxCrHgsmiProfileScope);
     147
     148#define VBOXCRHGSMIPROFILE_FUNC_EPILOGUE() \
     149        vboxCrHgsmiProfileScopeExit(&__vboxCrHgsmiProfileScope); \
     150
     151
     152#else
     153#define VBOXCRHGSMIPROFILE_INIT() do {} while (0)
     154#define VBOXCRHGSMIPROFILE_TERM() do {} while (0)
     155#define VBOXCRHGSMIPROFILE_FUNC_PROLOGUE() do {} while (0)
     156#define VBOXCRHGSMIPROFILE_FUNC_EPILOGUE() do {} while (0)
     157#endif
     158
     159
    62160typedef struct {
    63161    int                  initialized;
     
    443541static void *crVBoxHGSMIAlloc(CRConnection *conn)
    444542{
    445     PCRVBOXHGSMI_CLIENT pClient = _crVBoxHGSMIClientGet();
    446     void *pvBuf = _crVBoxHGSMIDoAlloc(pClient, conn->buffer_size);
     543    PCRVBOXHGSMI_CLIENT pClient;
     544    void *pvBuf;
     545
     546    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
     547
     548    pClient = _crVBoxHGSMIClientGet();
     549    pvBuf = _crVBoxHGSMIDoAlloc(pClient, conn->buffer_size);
    447550    Assert(pvBuf);
     551
     552    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
     553
    448554    return pvBuf;
    449555}
     
    456562    pSubm->fFlags.Value = 0;
    457563    pSubm->fFlags.bDoNotRetire = 1;
    458     pSubm->fFlags.bDoNotSignalCompletion = 1; /* <- we do not need that actually since
    459                                                        * in case we want completion,
    460                                                        * we will block in _crVBoxHGSMICmdBufferGetRc (when locking the buffer)
    461                                                        * which is needed for getting the result */
     564//    pSubm->fFlags.bDoNotSignalCompletion = 1; /* <- we do not need that actually since
     565//                                                       * in case we want completion,
     566//                                                       * we will block in _crVBoxHGSMICmdBufferGetRc (when locking the buffer)
     567//                                                       * which is needed for getting the result */
    462568}
    463569
     
    467573# error "Port Me!!"
    468574#endif
     575
     576DECLINLINE(void) _crVBoxHGSMIWaitCmd(PCRVBOXHGSMI_CLIENT pClient)
     577{
     578    int rc = CRVBOXHGSMI_BUF_WAIT(pClient->pCmdBuffer);
     579    Assert(rc == 0);
     580}
    469581
    470582static void _crVBoxHGSMIWriteExact(CRConnection *conn, PCRVBOXHGSMI_CLIENT pClient, PVBOXUHGSMI_BUFFER pBuf, uint32_t offStart, unsigned int len)
     
    506618        if (RT_SUCCESS(rc))
    507619        {
     620            _crVBoxHGSMIWaitCmd(pClient);
    508621                /* @todo: do we need to wait for completion actually?
    509622                 * NOTE: in case we do not need completion,
     
    539652        if (RT_SUCCESS(rc))
    540653        {
     654            _crVBoxHGSMIWaitCmd(pClient);
    541655                /* @todo: do we need to wait for completion actually?
    542656                 * NOTE: in case we do not need completion,
     
    556670static void crVBoxHGSMIWriteExact(CRConnection *conn, const void *buf, unsigned int len)
    557671{
     672    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
    558673    Assert(0);
    559674
     
    566681//    _crVBoxHGSMIWriteExact(conn, pClient, pBuf, 0, len);
    567682//    _crVBoxHGSMIBufFree(pClient, pBuf);
     683    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    568684}
    569685
     
    609725        return;
    610726    }
     727
     728    _crVBoxHGSMIWaitCmd(pClient);
    611729
    612730    parms = (CRVBOXHGSMIREAD *)_crVBoxHGSMICmdBufferLockRo(pClient, sizeof (*parms));
     
    733851            break;
    734852        }
     853
     854        _crVBoxHGSMIWaitCmd(pClient);
    735855
    736856        parms = (CRVBOXHGSMIWRITEREAD *)_crVBoxHGSMICmdBufferLockRo(pClient, sizeof (*parms));
     
    799919    PVBOXUHGSMI_BUFFER pBuf;
    800920
     921    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
     922
    801923    if (!bufp) /* We're sending a user-allocated buffer. */
    802924    {
     
    811933        _crVBoxHGSMIWriteReadExact(conn, pClient, (void*)start, 0, len, false);
    812934#endif
     935        VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    813936        return;
    814937    }
     
    822945    Assert(pBuf);
    823946    if (!pBuf)
     947    {
     948        VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    824949        return;
     950    }
    825951
    826952    pClient = (PCRVBOXHGSMI_CLIENT)pBuf->pvUserData;
     
    847973     */
    848974    *bufp = NULL;
     975
     976    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    849977}
    850978
     
    852980{
    853981    PCRVBOXHGSMI_CLIENT pClient;
    854     PVBOXUHGSMI_BUFFER pBuf = _crVBoxHGSMIBufFromMemPtr(buf);
     982    PVBOXUHGSMI_BUFFER pBuf;
     983    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
     984    pBuf = _crVBoxHGSMIBufFromMemPtr(buf);
    855985    Assert(pBuf);
    856986    Assert(0);
    857987    CRASSERT(0);
    858988    if (!pBuf)
     989    {
     990        VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    859991        return;
     992    }
    860993    pClient = (PCRVBOXHGSMI_CLIENT)pBuf->pvUserData;
    861994    _crVBoxHGSMIReadExact(conn, pClient);
    862 }
    863 
    864 static void crVBoxHGSMIFree(CRConnection *conn, void *buf)
     995    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
     996}
     997
     998static void _crVBoxHGSMIFree(CRConnection *conn, void *buf)
    865999{
    8661000    CRVBOXHGSMIBUFFER *hgsmi_buffer = (CRVBOXHGSMIBUFFER *) buf - 1;
     
    8881022#endif
    8891023    }
     1024}
     1025static void crVBoxHGSMIFree(CRConnection *conn, void *buf)
     1026{
     1027    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
     1028    _crVBoxHGSMIFree(conn, buf);
     1029    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    8901030}
    8911031
     
    9671107        && cached_type != CR_MESSAGE_GATHER)
    9681108    {
    969         crVBoxHGSMIFree(conn, msg);
     1109        _crVBoxHGSMIFree(conn, msg);
    9701110    }
    9711111}
     
    9731113static void crVBoxHGSMIReceiveMessage(CRConnection *conn)
    9741114{
    975     PCRVBOXHGSMI_CLIENT pClient = _crVBoxHGSMIClientGet();
     1115    PCRVBOXHGSMI_CLIENT pClient;
     1116    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
     1117
     1118    pClient = _crVBoxHGSMIClientGet();
    9761119
    9771120    Assert(pClient);
     
    9791122
    9801123    _crVBoxHGSMIReceiveMessage(conn, pClient);
     1124    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    9811125}
    9821126/*
     
    9851129static void crVBoxHGSMIAccept( CRConnection *conn, const char *hostname, unsigned short port )
    9861130{
     1131    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
    9871132    Assert(0);
    9881133
     
    9911136    CRASSERT(FALSE);
    9921137#endif
     1138    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    9931139}
    9941140
     
    10381184#ifdef RT_OS_WINDOWS
    10391185    DWORD cbReturned;
     1186    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
    10401187
    10411188    if (g_crvboxhgsmi.hGuestDrv == INVALID_HANDLE_VALUE)
     
    10551202            Assert(0);
    10561203            crDebug("could not open VBox Guest Additions driver! rc = %d\n", GetLastError());
     1204            VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    10571205            return FALSE;
    10581206        }
    10591207    }
    10601208#else
     1209    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
     1210
    10611211    if (g_crvboxhgsmi.iGuestDrv == INVALID_HANDLE_VALUE)
    10621212    {
     
    10651215        {
    10661216            crDebug("could not open Guest Additions kernel module! rc = %d\n", errno);
     1217            VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    10671218            return FALSE;
    10681219        }
     
    10971248        if (info.result == VINF_SUCCESS)
    10981249        {
     1250            int rc;
    10991251            conn->u32ClientID = info.u32ClientID;
    11001252            crDebug("HGCM connect was successful: client id =0x%x\n", conn->u32ClientID);
    11011253
    1102             return crVBoxHGSMISetVersion(conn, CR_PROTOCOL_VERSION_MAJOR, CR_PROTOCOL_VERSION_MINOR);
     1254            rc = crVBoxHGSMISetVersion(conn, CR_PROTOCOL_VERSION_MAJOR, CR_PROTOCOL_VERSION_MINOR);
     1255            VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
     1256            return rc;
    11031257        }
    11041258        else
     
    11161270#endif
    11171271    }
     1272
     1273    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    11181274
    11191275    return FALSE;
     
    11351291    int i;
    11361292#endif
     1293    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
    11371294
    11381295    if (conn->pHostBuffer)
     
    12141371# endif
    12151372    }
     1373    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    12161374#endif /* IN_GUEST */
    12171375}
     
    12191377static void crVBoxHGSMIInstantReclaim(CRConnection *conn, CRMessage *mess)
    12201378{
     1379    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
    12211380    Assert(0);
    12221381
    1223     crVBoxHGSMIFree(conn, mess);
     1382    _crVBoxHGSMIFree(conn, mess);
    12241383    CRASSERT(FALSE);
     1384
     1385    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    12251386}
    12261387
    12271388static void crVBoxHGSMIHandleNewMessage( CRConnection *conn, CRMessage *msg, unsigned int len )
    12281389{
     1390    VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
    12291391    Assert(0);
    12301392
    12311393    CRASSERT(FALSE);
     1394    VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
    12321395}
    12331396
     
    12411404        pClient->pHgsmi = pHgsmi;
    12421405        rc = pHgsmi->pfnBufferCreate(pHgsmi, CRVBOXHGSMI_PAGE_ALIGN(1),
    1243                                 VBOXUHGSMI_SYNCHOBJECT_TYPE_SEMAPHORE, NULL,
     1406                                VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT,
     1407                                NULL,
    12441408                                &pClient->pCmdBuffer);
    12451409        AssertRC(rc);
     
    12471411        {
    12481412            rc = pHgsmi->pfnBufferCreate(pHgsmi, CRVBOXHGSMI_PAGE_ALIGN(0x800000),
    1249                                             VBOXUHGSMI_SYNCHOBJECT_TYPE_SEMAPHORE, NULL,
     1413                                            VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT,
     1414                                            NULL,
    12501415                                            &pClient->pHGBuffer);
    12511416            AssertRC(rc);
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