VirtualBox

Ignore:
Timestamp:
Mar 13, 2023 6:41:39 AM (23 months ago)
Author:
vboxsync
Message:

WDDM: DxgkDdiDXBuildPagingBuffer VRAM<->SysMem transfers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/gallium/VBoxMPDX.cpp

    r98103 r98925  
    599599
    600600
     601SIZE_T svgaGetAllocationSize(PVBOXWDDM_ALLOCATION pAllocation)
     602{
     603    if (pAllocation->enmType != VBOXWDDM_ALLOC_TYPE_D3D)
     604        return pAllocation->AllocData.SurfDesc.cbSize;
     605    return pAllocation->dx.desc.cbAllocation;
     606}
     607
     608
     609static NTSTATUS svgaPTSysMem2VRAM(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pAllocation, DXGKARG_BUILDPAGINGBUFFER *pBuildPagingBuffer)
     610{
     611    /* This is a simple memcopy. */
     612    RT_NOREF(pAllocation);
     613
     614    uint64_t const offVRAM = pBuildPagingBuffer->Transfer.Destination.SegmentAddress.QuadPart;
     615    UINT const TransferOffset = pBuildPagingBuffer->Transfer.TransferOffset;
     616    SIZE_T const TransferSize = pBuildPagingBuffer->Transfer.TransferSize;
     617    AssertReturn(   offVRAM <= pDevExt->cbVRAMCpuVisible
     618                 && TransferOffset <= pDevExt->cbVRAMCpuVisible - offVRAM
     619                 && TransferSize <= pDevExt->cbVRAMCpuVisible - offVRAM - TransferOffset,
     620                 STATUS_INVALID_PARAMETER);
     621
     622    void *pvSrc = MmGetSystemAddressForMdlSafe(pBuildPagingBuffer->Transfer.Source.pMdl, NormalPagePriority);
     623
     624    memcpy((uint8_t *)pDevExt->pvVisibleVram + offVRAM + TransferOffset,
     625           (uint8_t *)pvSrc + TransferOffset,
     626           TransferSize);
     627
     628    return STATUS_SUCCESS;
     629}
     630
     631
     632static NTSTATUS svgaPTVRAM2SysMem(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pAllocation, DXGKARG_BUILDPAGINGBUFFER *pBuildPagingBuffer)
     633{
     634    /* This is a simple memcopy. */
     635    RT_NOREF(pAllocation);
     636
     637    uint64_t const offVRAM = pBuildPagingBuffer->Transfer.Source.SegmentAddress.QuadPart;
     638    UINT const TransferOffset = pBuildPagingBuffer->Transfer.TransferOffset;
     639    SIZE_T const TransferSize = pBuildPagingBuffer->Transfer.TransferSize;
     640    AssertReturn(   offVRAM <= pDevExt->cbVRAMCpuVisible
     641                 && TransferOffset <= pDevExt->cbVRAMCpuVisible - offVRAM
     642                 && TransferSize <= pDevExt->cbVRAMCpuVisible - offVRAM - TransferOffset,
     643                 STATUS_INVALID_PARAMETER);
     644
     645    void *pvDst = MmGetSystemAddressForMdlSafe(pBuildPagingBuffer->Transfer.Destination.pMdl, NormalPagePriority);
     646
     647    memcpy((uint8_t *)pvDst + TransferOffset,
     648           (uint8_t *)pDevExt->pvVisibleVram + offVRAM + TransferOffset,
     649           TransferSize);
     650
     651    return STATUS_SUCCESS;
     652}
     653
     654
     655static NTSTATUS svgaPagingTransfer(PVBOXMP_DEVEXT pDevExt, DXGKARG_BUILDPAGINGBUFFER *pBuildPagingBuffer, uint32_t *pcbCommands)
     656{
     657    VBOXWDDM_EXT_VMSVGA *pSvga = pDevExt->pGa->hw.pSvga;
     658    RT_NOREF(pSvga);
     659
     660    PVBOXWDDM_ALLOCATION pAllocation = (PVBOXWDDM_ALLOCATION)pBuildPagingBuffer->Transfer.hAllocation;
     661    AssertReturn(pAllocation, STATUS_INVALID_PARAMETER);
     662
     663    SIZE_T cbAllocation = svgaGetAllocationSize(pAllocation);
     664    AssertReturn(   pBuildPagingBuffer->Transfer.TransferOffset <= cbAllocation
     665                 && pBuildPagingBuffer->Transfer.TransferSize <= cbAllocation - pBuildPagingBuffer->Transfer.TransferOffset,
     666                 STATUS_INVALID_PARAMETER);
     667
     668    if (pBuildPagingBuffer->Transfer.TransferSize == 0)
     669        return STATUS_SUCCESS;
     670
     671    NTSTATUS Status = STATUS_SUCCESS;
     672
     673    RT_NOREF(pcbCommands);
     674
     675    switch (pBuildPagingBuffer->Transfer.Source.SegmentId)
     676    {
     677        case 0: /* From system memory. */
     678        {
     679            if (pBuildPagingBuffer->Transfer.Destination.SegmentId == 1) /* To VRAM */
     680            {
     681                if (!pAllocation->dx.desc.fPrimary)
     682                    Status = svgaPTSysMem2VRAM(pDevExt, pAllocation, pBuildPagingBuffer);
     683                else
     684                {
     685                    /* D3D driver primary is a host resource with guest backing storage. */
     686                    /** @todo Copy to the backing storage and UPDATE_GB_SURFACE. */
     687                    Status = svgaPTSysMem2VRAM(pDevExt, pAllocation, pBuildPagingBuffer);
     688                }
     689            }
     690            else
     691                DEBUG_BREAKPOINT_TEST();
     692            break;
     693        }
     694        case 1: /* From VRAM. */
     695        {
     696            if (pBuildPagingBuffer->Transfer.Destination.SegmentId == 0) /* To system memory */
     697            {
     698                if (!pAllocation->dx.desc.fPrimary)
     699                    Status = svgaPTVRAM2SysMem(pDevExt, pAllocation, pBuildPagingBuffer);
     700                else
     701                {
     702                    /* D3D driver primary is a host resource with guest backing storage. */
     703                    /** @todo Issue READBACK, wait and then copy. */
     704                    Status = svgaPTVRAM2SysMem(pDevExt, pAllocation, pBuildPagingBuffer);
     705                }
     706            }
     707            else
     708                DEBUG_BREAKPOINT_TEST();
     709            break;
     710        }
     711
     712        default:
     713            DEBUG_BREAKPOINT_TEST();
     714    }
     715
     716    return Status;
     717}
     718
     719
    601720static NTSTATUS svgaPagingFill(PVBOXMP_DEVEXT pDevExt, DXGKARG_BUILDPAGINGBUFFER *pBuildPagingBuffer, uint32_t *pcbCommands)
    602721{
     
    8881007        case DXGK_OPERATION_TRANSFER:
    8891008        {
    890             DEBUG_BREAKPOINT_TEST();
     1009            Status = svgaPagingTransfer(pDevExt, pBuildPagingBuffer, &cbCommands);
    8911010            break;
    8921011        }
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