VirtualBox

Changeset 108880 in vbox


Ignore:
Timestamp:
Apr 8, 2025 9:27:48 AM (12 days ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168331
Message:

WDDM: UMD: use KMRESOURCE instead of hAllocation as parameter for StorePatchLocation; cleanup. bugref:10885

Location:
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/dx
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/dx/VBoxDX.cpp

    r107086 r108880  
    55
    66/*
    7  * Copyright (C) 2022-2024 Oracle and/or its affiliates.
     7 * Copyright (C) 2022-2025 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    4646
    4747
    48 static uint32_t vboxDXGetSubresourceOffset(PVBOXDX_RESOURCE pResource, UINT Subresource)
     48static uint32_t vboxDXGetSubresourceOffset(VBOXDXALLOCATIONDESC const *pAllocationDesc, UINT Subresource)
    4949{
    5050    surf_size_struct baseLevelSize;
    51     baseLevelSize.width  = pResource->AllocationDesc.surfaceInfo.size.width;
    52     baseLevelSize.height = pResource->AllocationDesc.surfaceInfo.size.height;
    53     baseLevelSize.depth  = pResource->AllocationDesc.surfaceInfo.size.depth;
    54 
    55     uint32_t const numMipLevels = pResource->AllocationDesc.surfaceInfo.numMipLevels;
     51    baseLevelSize.width  = pAllocationDesc->surfaceInfo.size.width;
     52    baseLevelSize.height = pAllocationDesc->surfaceInfo.size.height;
     53    baseLevelSize.depth  = pAllocationDesc->surfaceInfo.size.depth;
     54
     55    uint32_t const numMipLevels = pAllocationDesc->surfaceInfo.numMipLevels;
    5656    uint32_t const face = Subresource / numMipLevels;
    5757    uint32_t const mip = Subresource % numMipLevels;
    58     return svga3dsurface_get_image_offset(pResource->AllocationDesc.surfaceInfo.format,
     58    return svga3dsurface_get_image_offset(pAllocationDesc->surfaceInfo.format,
    5959                                          baseLevelSize, numMipLevels, face, mip);
    6060}
    6161
    6262
    63 static uint32_t vboxDXGetSubresourceSize(PVBOXDX_RESOURCE pResource, UINT Subresource)
     63static uint32_t vboxDXGetSubresourceSize(VBOXDXALLOCATIONDESC const *pAllocationDesc, UINT Subresource)
    6464{
    6565    surf_size_struct baseLevelSize;
    66     baseLevelSize.width  = pResource->AllocationDesc.surfaceInfo.size.width;
    67     baseLevelSize.height = pResource->AllocationDesc.surfaceInfo.size.height;
    68     baseLevelSize.depth  = pResource->AllocationDesc.surfaceInfo.size.depth;
    69 
    70     uint32_t const numMipLevels = pResource->AllocationDesc.surfaceInfo.numMipLevels;
     66    baseLevelSize.width  = pAllocationDesc->surfaceInfo.size.width;
     67    baseLevelSize.height = pAllocationDesc->surfaceInfo.size.height;
     68    baseLevelSize.depth  = pAllocationDesc->surfaceInfo.size.depth;
     69
     70    uint32_t const numMipLevels = pAllocationDesc->surfaceInfo.numMipLevels;
    7171    /*uint32_t const face = Subresource / numMipLevels; - unused */
    7272    uint32_t const mip = Subresource % numMipLevels;
    7373
    74     const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(pResource->AllocationDesc.surfaceInfo.format);
     74    const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(pAllocationDesc->surfaceInfo.format);
    7575
    7676    surf_size_struct mipSize = svga3dsurface_get_mip_size(baseLevelSize, mip);
     
    7979
    8080
    81 static void vboxDXGetSubresourcePitch(PVBOXDX_RESOURCE pResource, UINT Subresource, UINT *pRowPitch, UINT *pDepthPitch)
    82 {
    83     if (pResource->AllocationDesc.surfaceInfo.format == SVGA3D_BUFFER)
    84     {
    85         *pRowPitch = pResource->AllocationDesc.surfaceInfo.size.width;
     81static void vboxDXGetSubresourcePitch(VBOXDXALLOCATIONDESC const *pAllocationDesc, UINT Subresource, UINT *pRowPitch, UINT *pDepthPitch)
     82{
     83    if (pAllocationDesc->surfaceInfo.format == SVGA3D_BUFFER)
     84    {
     85        *pRowPitch = pAllocationDesc->surfaceInfo.size.width;
    8686        *pDepthPitch = *pRowPitch;
    8787        return;
    8888    }
    8989
    90     uint32_t const numMipLevels = pResource->AllocationDesc.surfaceInfo.numMipLevels;
     90    uint32_t const numMipLevels = pAllocationDesc->surfaceInfo.numMipLevels;
    9191    /* uint32_t const face = Subresource / numMipLevels; - unused */
    9292    uint32_t const mip = Subresource % numMipLevels;
    9393
    9494    surf_size_struct baseLevelSize;
    95     baseLevelSize.width  = pResource->AllocationDesc.surfaceInfo.size.width;
    96     baseLevelSize.height = pResource->AllocationDesc.surfaceInfo.size.height;
    97     baseLevelSize.depth  = pResource->AllocationDesc.surfaceInfo.size.depth;
    98 
    99     const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(pResource->AllocationDesc.surfaceInfo.format);
     95    baseLevelSize.width  = pAllocationDesc->surfaceInfo.size.width;
     96    baseLevelSize.height = pAllocationDesc->surfaceInfo.size.height;
     97    baseLevelSize.depth  = pAllocationDesc->surfaceInfo.size.depth;
     98
     99    const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(pAllocationDesc->surfaceInfo.format);
    100100
    101101    surf_size_struct mipSize = svga3dsurface_get_mip_size(baseLevelSize, mip);
     
    108108
    109109
    110 static void vboxDXGetResourceBoxDimensions(PVBOXDX_RESOURCE pResource, UINT Subresource, SVGA3dBox *pBox,
     110static void vboxDXGetResourceBoxDimensions(VBOXDXALLOCATIONDESC const *pAllocationDesc, UINT Subresource, SVGA3dBox *pBox,
    111111                                           uint32_t *pOffPixel, uint32_t *pcbRow, uint32_t *pcRows, uint32_t *pDepth)
    112112{
    113     if (pResource->AllocationDesc.surfaceInfo.format == SVGA3D_BUFFER)
     113    if (pAllocationDesc->surfaceInfo.format == SVGA3D_BUFFER)
    114114    {
    115115        *pOffPixel = pBox->x;
     
    120120    }
    121121
    122     const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(pResource->AllocationDesc.surfaceInfo.format);
     122    const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(pAllocationDesc->surfaceInfo.format);
    123123
    124124    surf_size_struct baseLevelSize;
    125     baseLevelSize.width  = pResource->AllocationDesc.surfaceInfo.size.width;
    126     baseLevelSize.height = pResource->AllocationDesc.surfaceInfo.size.height;
    127     baseLevelSize.depth  = pResource->AllocationDesc.surfaceInfo.size.depth;
    128 
    129     uint32_t const numMipLevels = pResource->AllocationDesc.surfaceInfo.numMipLevels;
     125    baseLevelSize.width  = pAllocationDesc->surfaceInfo.size.width;
     126    baseLevelSize.height = pAllocationDesc->surfaceInfo.size.height;
     127    baseLevelSize.depth  = pAllocationDesc->surfaceInfo.size.depth;
     128
     129    uint32_t const numMipLevels = pAllocationDesc->surfaceInfo.numMipLevels;
    130130    uint32_t const mip = Subresource % numMipLevels;
    131131
     
    139139    svga3dsurface_get_size_in_blocks(desc, &boxSize, &blocks);
    140140
    141     *pOffPixel = svga3dsurface_get_pixel_offset(pResource->AllocationDesc.surfaceInfo.format,
     141    *pOffPixel = svga3dsurface_get_pixel_offset(pAllocationDesc->surfaceInfo.format,
    142142                                                mipSize.width, mipSize.height,
    143143                                                pBox->x, pBox->y, pBox->z);
     
    147147}
    148148
    149 static void vboxDXGetSubresourceBox(PVBOXDX_RESOURCE pResource, UINT Subresource, SVGA3dBox *pBox)
     149
     150static void vboxDXGetSubresourceBox(VBOXDXALLOCATIONDESC const *pAllocationDesc, UINT Subresource, SVGA3dBox *pBox)
    150151{
    151152    surf_size_struct baseLevelSize;
    152     baseLevelSize.width  = pResource->AllocationDesc.surfaceInfo.size.width;
    153     baseLevelSize.height = pResource->AllocationDesc.surfaceInfo.size.height;
    154     baseLevelSize.depth  = pResource->AllocationDesc.surfaceInfo.size.depth;
    155 
    156     uint32_t const numMipLevels = pResource->AllocationDesc.surfaceInfo.numMipLevels;
     153    baseLevelSize.width  = pAllocationDesc->surfaceInfo.size.width;
     154    baseLevelSize.height = pAllocationDesc->surfaceInfo.size.height;
     155    baseLevelSize.depth  = pAllocationDesc->surfaceInfo.size.depth;
     156
     157    uint32_t const numMipLevels = pAllocationDesc->surfaceInfo.numMipLevels;
    157158    uint32_t const mip = Subresource % numMipLevels;
    158159
     
    235236
    236237
    237 void vboxDXStorePatchLocation(PVBOXDX_DEVICE pDevice, void *pvPatch, VBOXDXALLOCATIONTYPE enmAllocationType,
    238                               D3DKMT_HANDLE hAllocation, uint32_t offAllocation, bool fWriteOperation)
    239 {
     238void vboxDXStorePatchLocation(PVBOXDX_DEVICE pDevice, void *pvPatch, PVBOXDXKMRESOURCE pKMResource,
     239                              uint32_t offAllocation, bool fWriteOperation)
     240{
     241    D3DKMT_HANDLE hAllocation = vboxDXGetAllocation(pKMResource);
    240242    if (!hAllocation)
    241243        return;
     
    272274    pPatchLocation->AllocationIndex = idxAllocation;
    273275    pPatchLocation->Value = 0;
    274     pPatchLocation->DriverId = enmAllocationType;
     276    pPatchLocation->DriverId = pKMResource->AllocationDesc.enmAllocationType;
    275277    pPatchLocation->AllocationOffset = offAllocation;
    276278    pPatchLocation->PatchOffset = (uintptr_t)pvPatch - (uintptr_t)pDevice->pCommandBuffer;
    277279    pPatchLocation->SplitOffset = pDevice->cbCommandBuffer;
    278280    ++pDevice->cPatchLocations;
     281
     282    /* Move the KM resource to the head of the resource list. */
     283    RTListNodeRemove(&pKMResource->nodeResource);
     284    RTListPrepend(&pDevice->listResources, &pKMResource->nodeResource);
    279285}
    280286
     
    313319            if (pResource)
    314320            {
    315                 D3DKMT_HANDLE const hAllocation = vboxDXGetAllocation(pResource);
     321                PVBOXDXKMRESOURCE const pKMResource = vboxDXGetKMResource(pResource);
    316322                uint32 const offsetInBytes = pCBS->aFirstConstant[i] * (4 * sizeof(UINT));
    317323                uint32 const sizeInBytes = pCBS->aNumConstants[i] * (4 * sizeof(UINT));
    318324                LogFunc(("type %d, slot %d, off %d, size %d, cbAllocation %d",
    319                          enmShaderType, i, offsetInBytes, sizeInBytes, pResource->AllocationDesc.cbAllocation));
    320 
    321                 vgpu10SetSingleConstantBuffer(pDevice, i, enmShaderType, hAllocation, offsetInBytes, sizeInBytes);
     325                         enmShaderType, i, offsetInBytes, sizeInBytes, pKMResource->AllocationDesc.cbAllocation));
     326
     327                vgpu10SetSingleConstantBuffer(pDevice, i, enmShaderType, pKMResource, offsetInBytes, sizeInBytes);
    322328            }
    323329            else
     
    349355
    350356    /* Fetch allocation handles. */
    351     D3DKMT_HANDLE aAllocations[SVGA3D_MAX_VERTEX_ARRAYS];
     357    PVBOXDXKMRESOURCE aKMResources[SVGA3D_MAX_VERTEX_ARRAYS];
    352358    for (unsigned i = pVBS->StartSlot; i < pVBS->StartSlot + pVBS->NumBuffers; ++i)
    353359    {
    354360        PVBOXDX_RESOURCE pResource = pVBS->apResource[i];
    355         aAllocations[i] = vboxDXGetAllocation(pResource);
    356     }
    357 
    358     vgpu10SetVertexBuffers(pDevice, pVBS->StartSlot, pVBS->NumBuffers, aAllocations,
     361        aKMResources[i] = vboxDXGetKMResource(pResource);
     362    }
     363
     364    vgpu10SetVertexBuffers(pDevice, pVBS->StartSlot, pVBS->NumBuffers, aKMResources,
    359365                           &pVBS->aStrides[pVBS->StartSlot], &pVBS->aOffsets[pVBS->StartSlot]);
    360366
     
    381387    PVBOXDXINDEXBUFFERSTATE pIBS = &pDevice->pipeline.IndexBuffer;
    382388
    383     D3DKMT_HANDLE const hAllocation = vboxDXGetAllocation(pIBS->pBuffer);
     389    PVBOXDXKMRESOURCE const pKMResource = vboxDXGetKMResource(pIBS->pBuffer);
    384390    SVGA3dSurfaceFormat const svgaFormat = vboxDXDxgiToSvgaFormat(pIBS->Format);
    385     vgpu10SetIndexBuffer(pDevice, hAllocation, svgaFormat, pIBS->Offset);
     391    vgpu10SetIndexBuffer(pDevice, pKMResource, svgaFormat, pIBS->Offset);
    386392}
    387393
     
    577583
    578584
    579 static uint32_t vboxDXCalcResourceAllocationSize(PVBOXDX_RESOURCE pResource)
     585PVBOXDXKMRESOURCE vboxDXAllocateKMResource(PVBOXDX_DEVICE pDevice, HANDLE hResource,
     586                                           PFNVBOXDXINITALLOCATIONDESC pfnInitAllocationDesc,
     587                                           void const *pvInitData, bool fZero)
     588{
     589    PVBOXDXKMRESOURCE pKMResource = (PVBOXDXKMRESOURCE)RTMemAllocZ(sizeof(VBOXDXKMRESOURCE));
     590    AssertReturnStmt(pKMResource, vboxDXDeviceSetError(pDevice, E_OUTOFMEMORY), NULL);
     591
     592    pfnInitAllocationDesc(&pKMResource->AllocationDesc, pvInitData);
     593
     594    D3DDDI_ALLOCATIONINFO2 ddiAllocationInfo;
     595    RT_ZERO(ddiAllocationInfo);
     596    ddiAllocationInfo.pPrivateDriverData    = &pKMResource->AllocationDesc;
     597    ddiAllocationInfo.PrivateDriverDataSize = sizeof(pKMResource->AllocationDesc);
     598    if (pKMResource->AllocationDesc.fPrimary)
     599    {
     600        ddiAllocationInfo.VidPnSourceId     = pKMResource->AllocationDesc.PrimaryDesc.VidPnSourceId;
     601        ddiAllocationInfo.Flags.Primary     = 1;
     602    }
     603
     604    D3DDDICB_ALLOCATE ddiAllocate;
     605    RT_ZERO(ddiAllocate);
     606    ddiAllocate.hResource        = hResource;
     607    ddiAllocate.NumAllocations   = 1;
     608    ddiAllocate.pAllocationInfo2 = &ddiAllocationInfo;
     609
     610    HRESULT hr = pDevice->pRTCallbacks->pfnAllocateCb(pDevice->hRTDevice.handle, &ddiAllocate);
     611    LogFlowFunc(("pfnAllocateCb returned 0x%x, hKMResource 0x%X, hAllocation 0x%X", hr, ddiAllocate.hKMResource, ddiAllocationInfo.hAllocation));
     612    AssertReturnStmt(SUCCEEDED(hr),
     613                     vboxDXDeallocateKMResource(pDevice, pKMResource); vboxDXDeviceSetError(pDevice, hr),
     614                     false);
     615
     616    pKMResource->hAllocation = ddiAllocationInfo.hAllocation;
     617
     618    if (fZero)
     619    {
     620        D3DDDICB_LOCK ddiLock;
     621        RT_ZERO(ddiLock);
     622        ddiLock.hAllocation = ddiAllocationInfo.hAllocation;
     623        ddiLock.Flags.WriteOnly = 1;
     624        hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
     625        if (SUCCEEDED(hr))
     626        {
     627            memset(ddiLock.pData, 0, pKMResource->AllocationDesc.cbAllocation);
     628
     629            D3DDDICB_UNLOCK ddiUnlock;
     630            ddiUnlock.NumAllocations = 1;
     631            ddiUnlock.phAllocations = &ddiLock.hAllocation;
     632            hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
     633        }
     634        AssertReturnStmt(SUCCEEDED(hr),
     635                         vboxDXDeallocateKMResource(pDevice, pKMResource); vboxDXDeviceSetError(pDevice, hr),
     636                         false);
     637    }
     638
     639    return pKMResource;
     640}
     641
     642
     643PVBOXDXKMRESOURCE vboxDXOpenKMResource(PVBOXDX_DEVICE pDevice, D3DKMT_HANDLE hAllocation,
     644                                       VBOXDXALLOCATIONDESC const *pDesc)
     645{
     646    PVBOXDXKMRESOURCE pKMResource = (PVBOXDXKMRESOURCE)RTMemAllocZ(sizeof(VBOXDXKMRESOURCE));
     647    AssertReturnStmt(pKMResource, vboxDXDeviceSetError(pDevice, E_OUTOFMEMORY), NULL);
     648
     649    pKMResource->hAllocation = hAllocation;
     650    pKMResource->AllocationDesc = *pDesc;
     651    pKMResource->flags.fOpened = 1;
     652    return pKMResource;
     653}
     654
     655
     656void vboxDXDeallocateKMResource(PVBOXDX_DEVICE pDevice, PVBOXDXKMRESOURCE pKMResource)
     657{
     658    if (pKMResource)
     659    {
     660        Assert(!pKMResource->flags.fOpened);
     661
     662        if (pKMResource->hAllocation)
     663        {
     664            D3DDDICB_DEALLOCATE ddiDeallocate;
     665            RT_ZERO(ddiDeallocate);
     666            //ddiDeallocate.hResource    = NULL;
     667            ddiDeallocate.NumAllocations = 1;
     668            ddiDeallocate.HandleList     = &pKMResource->hAllocation;
     669
     670            HRESULT hr = pDevice->pRTCallbacks->pfnDeallocateCb(pDevice->hRTDevice.handle, &ddiDeallocate);
     671            LogFlowFunc(("pfnDeallocateCb returned 0x%x, hAllocation 0x%x", hr, pKMResource->hAllocation));
     672            AssertStmt(SUCCEEDED(hr), vboxDXDeviceSetError(pDevice, hr));
     673        }
     674
     675        RTMemFree(pKMResource);
     676    }
     677}
     678
     679
     680static uint32_t vboxDXCalcResourceAllocationSize(VBOXDXALLOCATIONDESC const *pAllocationDesc)
    580681{
    581682    /* The allocation holds the entire resource:
     
    585686     */
    586687    surf_size_struct base_level_size;
    587     base_level_size.width  = pResource->AllocationDesc.surfaceInfo.size.width;
    588     base_level_size.height = pResource->AllocationDesc.surfaceInfo.size.height;
    589     base_level_size.depth  = pResource->AllocationDesc.surfaceInfo.size.depth;
    590 
    591     return svga3dsurface_get_serialized_size_extended(pResource->AllocationDesc.surfaceInfo.format,
     688    base_level_size.width  = pAllocationDesc->surfaceInfo.size.width;
     689    base_level_size.height = pAllocationDesc->surfaceInfo.size.height;
     690    base_level_size.depth  = pAllocationDesc->surfaceInfo.size.depth;
     691
     692    return svga3dsurface_get_serialized_size_extended(pAllocationDesc->surfaceInfo.format,
    592693                                                      base_level_size,
    593                                                       pResource->AllocationDesc.surfaceInfo.numMipLevels,
    594                                                       pResource->AllocationDesc.surfaceInfo.arraySize,
    595                                                       pResource->AllocationDesc.surfaceInfo.multisampleCount);
     694                                                      pAllocationDesc->surfaceInfo.numMipLevels,
     695                                                      pAllocationDesc->surfaceInfo.arraySize,
     696                                                      pAllocationDesc->surfaceInfo.multisampleCount);
    596697}
    597698
     
    695796
    696797
    697 int vboxDXInitResourceData(PVBOXDX_RESOURCE pResource, const D3D11DDIARG_CREATERESOURCE *pCreateResource)
    698 {
    699     /* Store data which might be needed later. */
    700     pResource->ResourceDimension = pCreateResource->ResourceDimension;
    701     pResource->Usage             = (D3D10_DDI_RESOURCE_USAGE)pCreateResource->Usage;
    702     for (UINT i = 0; i < pCreateResource->MipLevels; ++i)
    703         pResource->aMipInfoList[i] = pCreateResource->pMipInfoList[i];
     798static void resourceAllocationDesc(VBOXDXALLOCATIONDESC *pDesc, void const *pvInitData)
     799{
     800    const D3D11DDIARG_CREATERESOURCE *pCreateResource = (const D3D11DDIARG_CREATERESOURCE *)pvInitData;
    704801
    705802    /* Init surface information which will be used by the miniport to define the surface. */
    706     VBOXDXALLOCATIONDESC *pDesc = &pResource->AllocationDesc;
    707803    pDesc->surfaceInfo.surfaceFlags       = vboxDXCalcSurfaceFlags(pCreateResource);
    708804    pDesc->surfaceInfo.format             = vboxDXDxgiToSvgaFormat(pCreateResource->Format);
     
    741837    /* Finally set the allocation type and compute the size. */
    742838    pDesc->enmAllocationType = VBOXDXALLOCATIONTYPE_SURFACE;
    743     pDesc->cbAllocation = vboxDXCalcResourceAllocationSize(pResource);
    744 
    745     /* Init remaining fields. */
     839    pDesc->cbAllocation = vboxDXCalcResourceAllocationSize(pDesc);
     840}
     841
     842
     843bool vboxDXCreateResource(PVBOXDX_DEVICE pDevice, PVBOXDX_RESOURCE pResource,
     844                          const D3D11DDIARG_CREATERESOURCE *pCreateResource)
     845{
     846    bool const fZero = pCreateResource->pInitialDataUP == NULL
     847                    && (   pCreateResource->Usage == D3D10_DDI_USAGE_DYNAMIC
     848                        || pCreateResource->Usage == D3D10_DDI_USAGE_STAGING);
     849
     850    pResource->pKMResource = vboxDXAllocateKMResource(pDevice, pResource->hRTResource.handle,
     851                                                      resourceAllocationDesc, pCreateResource, fZero);
     852    if (!pResource->pKMResource)
     853    {
     854        /* Might be not enough memory due to temporary staging buffers. */
     855        vboxDXFlush(pDevice, true);
     856        pResource->pKMResource = vboxDXAllocateKMResource(pDevice, pResource->hRTResource.handle,
     857                                                          resourceAllocationDesc, pCreateResource, fZero);
     858    }
     859
     860    if (!pResource->pKMResource)
     861        return false;
     862
     863    pResource->ResourceDimension = pCreateResource->ResourceDimension;
     864    pResource->Usage             = (D3D10_DDI_RESOURCE_USAGE)pCreateResource->Usage;
     865    for (UINT i = 0; i < pCreateResource->MipLevels; ++i)
     866        pResource->aMipInfoList[i] = pCreateResource->pMipInfoList[i];
    746867    pResource->cSubresources = pCreateResource->MipLevels * pCreateResource->ArraySize;
    747     pResource->pKMResource = NULL;
    748868    pResource->uMap = 0;
     869
    749870    RTListInit(&pResource->listSRV);
    750871    RTListInit(&pResource->listRTV);
     
    755876    RTListInit(&pResource->listVPOV);
    756877
    757     return VINF_SUCCESS;
    758 }
    759 
    760 
    761 static HRESULT dxAllocate(PVBOXDX_DEVICE pDevice, PVBOXDX_RESOURCE pResource, D3DKMT_HANDLE *phAllocation)
    762 {
    763     D3DDDI_ALLOCATIONINFO2 ddiAllocationInfo;
    764     RT_ZERO(ddiAllocationInfo);
    765     //ddiAllocationInfo.pSystemMem            = 0;
    766     ddiAllocationInfo.pPrivateDriverData    = &pResource->AllocationDesc;
    767     ddiAllocationInfo.PrivateDriverDataSize = sizeof(pResource->AllocationDesc);
    768     if (pResource->AllocationDesc.fPrimary)
    769     {
    770         ddiAllocationInfo.VidPnSourceId     = pResource->AllocationDesc.PrimaryDesc.VidPnSourceId;
    771         ddiAllocationInfo.Flags.Primary     = pResource->AllocationDesc.fPrimary;
    772     }
    773 
    774     D3DDDICB_ALLOCATE ddiAllocate;
    775     RT_ZERO(ddiAllocate);
    776     //ddiAllocate.pPrivateDriverData    = NULL;
    777     //ddiAllocate.PrivateDriverDataSize = 0;
    778     ddiAllocate.hResource             = pResource->hRTResource.handle;
    779     ddiAllocate.NumAllocations        = 1;
    780     ddiAllocate.pAllocationInfo2      = &ddiAllocationInfo;
    781 
    782     HRESULT hr = pDevice->pRTCallbacks->pfnAllocateCb(pDevice->hRTDevice.handle, &ddiAllocate);
    783     LogFlowFunc((" pfnAllocateCb returned %d, hKMResource 0x%X, hAllocation 0x%X", hr, ddiAllocate.hKMResource, ddiAllocationInfo.hAllocation));
    784 
    785     if (SUCCEEDED(hr))
    786         *phAllocation = ddiAllocationInfo.hAllocation;
    787 
    788     return hr;
    789 }
    790 
    791 
    792 bool vboxDXCreateResource(PVBOXDX_DEVICE pDevice, PVBOXDX_RESOURCE pResource,
    793                           const D3D11DDIARG_CREATERESOURCE *pCreateResource)
    794 {
    795     pResource->pKMResource = (PVBOXDXKMRESOURCE)RTMemAllocZ(sizeof(VBOXDXKMRESOURCE));
    796     AssertReturnStmt(pResource->pKMResource, vboxDXDeviceSetError(pDevice, E_OUTOFMEMORY), false);
    797 
    798     D3DKMT_HANDLE hAllocation = 0;
    799     HRESULT hr = dxAllocate(pDevice, pResource, &hAllocation);
    800     if (FAILED(hr))
    801     {
    802         /* Might be not enough memory due to temporary staging buffers. */
    803         vboxDXFlush(pDevice, true);
    804         hr = dxAllocate(pDevice, pResource, &hAllocation);
    805     }
    806     AssertReturnStmt(SUCCEEDED(hr), RTMemFree(pResource->pKMResource); vboxDXDeviceSetError(pDevice, hr), false);
    807 
    808     pResource->pKMResource->pResource = pResource;
    809     pResource->pKMResource->hAllocation = hAllocation;
     878    pResource->pKMResource->resource.pResource = pResource;
     879
    810880    RTListAppend(&pDevice->listResources, &pResource->pKMResource->nodeResource);
    811881
     
    813883    {
    814884        /* Upload the data to the resource. */
    815         for (unsigned i = 0; i < pResource->cSubresources; ++i)
     885        for (UINT i = 0; i < pResource->cSubresources; ++i)
    816886            vboxDXResourceUpdateSubresourceUP(pDevice, pResource, i, NULL,
    817887                                              pCreateResource->pInitialDataUP[i].pSysMem,
     
    820890
    821891    }
    822     else
    823     {
    824         /** @todo Test Lock/Unlock. Not sure if memset is really necessary. */
    825         if (   pResource->Usage == D3D10_DDI_USAGE_DYNAMIC
    826             || pResource->Usage == D3D10_DDI_USAGE_STAGING)
    827         {
    828             /* Zero the allocation. */
    829             D3DDDICB_LOCK ddiLock;
    830             RT_ZERO(ddiLock);
    831             ddiLock.hAllocation = vboxDXGetAllocation(pResource);
    832             ddiLock.Flags.WriteOnly = 1;
    833             hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
    834             if (SUCCEEDED(hr))
    835             {
    836                 memset(ddiLock.pData, 0, pResource->AllocationDesc.cbAllocation);
    837 
    838                 hAllocation = vboxDXGetAllocation(pResource);
    839 
    840                 D3DDDICB_UNLOCK ddiUnlock;
    841                 ddiUnlock.NumAllocations = 1;
    842                 ddiUnlock.phAllocations = &hAllocation;
    843                 hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    844             }
    845         }
    846     }
    847892
    848893    return true;
     
    858903                     vboxDXDeviceSetError(pDevice, E_INVALIDARG), false);
    859904
    860     pResource->pKMResource = (PVBOXDXKMRESOURCE)RTMemAllocZ(sizeof(VBOXDXKMRESOURCE));
    861     AssertReturnStmt(pResource->pKMResource, vboxDXDeviceSetError(pDevice, E_OUTOFMEMORY), false);
    862 
    863     VBOXDXALLOCATIONDESC const *pDesc = (VBOXDXALLOCATIONDESC *)pOpenResource->pOpenAllocationInfo2[0].pPrivateDriverData;
     905    pResource->pKMResource = vboxDXOpenKMResource(pDevice, pOpenResource->pOpenAllocationInfo2[0].hAllocation,
     906                                                  (VBOXDXALLOCATIONDESC *)pOpenResource->pOpenAllocationInfo2[0].pPrivateDriverData);
     907    if (!pResource->pKMResource)
     908        return false;
     909
     910    VBOXDXALLOCATIONDESC const *pDesc = vboxDXGetAllocationDesc(pResource);
    864911
    865912    /* Restore resource data. */
     
    868915    for (UINT i = 0; i < pDesc->surfaceInfo.numMipLevels; ++i)
    869916        RT_ZERO(pResource->aMipInfoList[i]);
    870 
    871     pResource->AllocationDesc = *pDesc;
    872     pResource->AllocationDesc.resourceInfo.MiscFlags |= D3D10_DDI_RESOURCE_MISC_SHARED;
    873 
    874     /* Init remaining fields. */
    875917    pResource->cSubresources = pDesc->surfaceInfo.numMipLevels * pDesc->surfaceInfo.arraySize;
    876     pResource->uMap             = 0;
     918    pResource->uMap = 0;
     919
    877920    RTListInit(&pResource->listSRV);
    878921    RTListInit(&pResource->listRTV);
     
    883926    RTListInit(&pResource->listVPOV);
    884927
    885     pResource->pKMResource->pResource = pResource;
    886     pResource->pKMResource->hAllocation = pOpenResource->pOpenAllocationInfo2[0].hAllocation;
     928    pResource->pKMResource->resource.pResource = pResource;
     929
    887930    RTListAppend(&pDevice->listResources, &pResource->pKMResource->nodeResource);
     931
    888932    return true;
    889933}
     
    912956    RTListNodeRemove(&pResource->pKMResource->nodeResource);
    913957
    914     if (pResource->AllocationDesc.fPrimary)
     958    if (pResource->pKMResource->AllocationDesc.fPrimary)
    915959    {
    916960        /* Delete immediately. */
    917         D3DDDICB_DEALLOCATE ddiDeallocate;
    918         RT_ZERO(ddiDeallocate);
    919         //ddiDeallocate.hResource      = NULL;
    920         ddiDeallocate.NumAllocations = 1;
    921         ddiDeallocate.HandleList     = &pResource->pKMResource->hAllocation;
    922 
    923         HRESULT hr = pDevice->pRTCallbacks->pfnDeallocateCb(pDevice->hRTDevice.handle, &ddiDeallocate);
    924         LogFlowFunc(("pfnDeallocateCb returned %d", hr));
    925         AssertStmt(SUCCEEDED(hr), vboxDXDeviceSetError(pDevice, hr));
    926 
    927         RTMemFree(pResource->pKMResource);
     961        vboxDXDeallocateKMResource(pDevice, pResource->pKMResource);
     962        pResource->pKMResource = 0;
    928963    }
    929964    else
    930965    {
    931         if (!RT_BOOL(pResource->AllocationDesc.resourceInfo.MiscFlags & D3D10_DDI_RESOURCE_MISC_SHARED))
     966        if (   !pResource->pKMResource->flags.fOpened
     967            && !RT_BOOL(pResource->pKMResource->AllocationDesc.resourceInfo.MiscFlags & D3D10_DDI_RESOURCE_MISC_SHARED))
    932968        {
    933969            /* Set the resource for deferred destruction. */
    934             pResource->pKMResource->pResource = NULL;
     970            pResource->pKMResource->resource.pResource = NULL;
    935971            RTListAppend(&pDevice->listDestroyedResources, &pResource->pKMResource->nodeResource);
    936972        }
     
    15081544{
    15091545    vboxDXSetupPipeline(pDevice);
    1510     vgpu10DrawIndexedInstancedIndirect(pDevice, vboxDXGetAllocation(pResource), AlignedByteOffsetForArgs);
     1546    vgpu10DrawIndexedInstancedIndirect(pDevice, vboxDXGetKMResource(pResource), AlignedByteOffsetForArgs);
    15111547}
    15121548
     
    15151551{
    15161552    vboxDXSetupPipeline(pDevice);
    1517     vgpu10DrawInstancedIndirect(pDevice, vboxDXGetAllocation(pResource), AlignedByteOffsetForArgs);
     1553    vgpu10DrawInstancedIndirect(pDevice, vboxDXGetKMResource(pResource), AlignedByteOffsetForArgs);
    15181554}
    15191555
     
    15331569
    15341570
    1535 static void vboxDXDestroyCOAllocation(PVBOXDX_DEVICE pDevice, PVBOXDXCOALLOCATION pCOAllocation)
     1571static void vboxDXDestroyCOAllocation(PVBOXDX_DEVICE pDevice, PVBOXDXKMRESOURCE pCOAllocation)
    15361572{
    15371573    if (pCOAllocation)
    15381574    {
    1539         if (pCOAllocation->hCOAllocation)
    1540         {
    1541             D3DDDICB_DEALLOCATE ddiDeallocate;
    1542             RT_ZERO(ddiDeallocate);
    1543             ddiDeallocate.NumAllocations = 1;
    1544             ddiDeallocate.HandleList     = &pCOAllocation->hCOAllocation;
    1545 
    1546             HRESULT hr = pDevice->pRTCallbacks->pfnDeallocateCb(pDevice->hRTDevice.handle, &ddiDeallocate);
    1547             LogFlowFunc(("pfnDeallocateCb returned %d", hr));
    1548             AssertStmt(SUCCEEDED(hr), vboxDXDeviceSetError(pDevice, hr));
    1549 
    1550             pCOAllocation->hCOAllocation = 0;
    1551         }
    1552 
    1553         RTMemFree(pCOAllocation);
    1554     }
    1555 }
    1556 
    1557 
    1558 static bool vboxDXCreateCOAllocation(PVBOXDX_DEVICE pDevice, RTLISTANCHOR *pList, PVBOXDXCOALLOCATION *ppCOAllocation, uint32_t cbAllocation)
    1559 {
    1560     PVBOXDXCOALLOCATION pCOAllocation = (PVBOXDXCOALLOCATION)RTMemAllocZ(sizeof(VBOXDXCOALLOCATION));
    1561     AssertReturnStmt(pCOAllocation, vboxDXDeviceSetError(pDevice, E_OUTOFMEMORY), false);
    1562 
    1563     VBOXDXALLOCATIONDESC desc;
    1564     RT_ZERO(desc);
    1565     desc.enmAllocationType = VBOXDXALLOCATIONTYPE_CO;
    1566     desc.cbAllocation      = cbAllocation;
    1567 
    1568     D3DDDI_ALLOCATIONINFO2 ddiAllocationInfo;
    1569     RT_ZERO(ddiAllocationInfo);
    1570     ddiAllocationInfo.pPrivateDriverData    = &desc;
    1571     ddiAllocationInfo.PrivateDriverDataSize = sizeof(desc);
    1572 
    1573     D3DDDICB_ALLOCATE ddiAllocate;
    1574     RT_ZERO(ddiAllocate);
    1575     ddiAllocate.NumAllocations   = 1;
    1576     ddiAllocate.pAllocationInfo2 = &ddiAllocationInfo;
    1577 
    1578     HRESULT hr = pDevice->pRTCallbacks->pfnAllocateCb(pDevice->hRTDevice.handle, &ddiAllocate);
    1579     LogFlowFunc(("pfnAllocateCb returned %d, hKMResource 0x%X, hAllocation 0x%X", hr, ddiAllocate.hKMResource, ddiAllocationInfo.hAllocation));
    1580     AssertReturnStmt(SUCCEEDED(hr),
    1581                      vboxDXDestroyCOAllocation(pDevice, pCOAllocation); vboxDXDeviceSetError(pDevice, hr), false);
    1582 
    1583     pCOAllocation->hCOAllocation = ddiAllocationInfo.hAllocation;
    1584 
    1585     D3DDDICB_LOCK ddiLock;
    1586     RT_ZERO(ddiLock);
    1587     ddiLock.hAllocation = ddiAllocationInfo.hAllocation;
    1588     ddiLock.Flags.WriteOnly = 1;
    1589     hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
    1590     if (SUCCEEDED(hr))
    1591     {
    1592         memset(ddiLock.pData, 0, cbAllocation);
    1593 
    1594         D3DDDICB_UNLOCK ddiUnlock;
    1595         ddiUnlock.NumAllocations = 1;
    1596         ddiUnlock.phAllocations = &ddiAllocationInfo.hAllocation;
    1597         hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    1598     }
    1599     AssertReturnStmt(SUCCEEDED(hr),
    1600                      vboxDXDestroyCOAllocation(pDevice, pCOAllocation); vboxDXDeviceSetError(pDevice, hr), false);
    1601 
    1602     pCOAllocation->cbAllocation = cbAllocation;
     1575        Assert(pCOAllocation->AllocationDesc.enmAllocationType == VBOXDXALLOCATIONTYPE_CO);
     1576
     1577        /* Remove from the global list of resources. */
     1578        RTListNodeRemove(&pCOAllocation->nodeResource);
     1579        vboxDXDeallocateKMResource(pDevice, pCOAllocation);
     1580    }
     1581}
     1582
     1583
     1584static void coAllocationDesc(VBOXDXALLOCATIONDESC *pDesc, void const *pvInitData)
     1585{
     1586    pDesc->enmAllocationType = VBOXDXALLOCATIONTYPE_CO; /* Context Object allocation. */
     1587    pDesc->cbAllocation      = *(uint32_t *)pvInitData;
     1588}
     1589
     1590
     1591static bool vboxDXCreateCOAllocation(PVBOXDX_DEVICE pDevice, RTLISTANCHOR *pList, PVBOXDXKMRESOURCE *ppCOAllocation, uint32_t cbAllocation)
     1592{
     1593    PVBOXDXKMRESOURCE pCOAllocation = vboxDXAllocateKMResource(pDevice, 0, coAllocationDesc, &cbAllocation, true);
     1594    if (!pCOAllocation)
     1595        return false;
    16031596
    16041597    /* Initially the allocation contains one big free block and zero sized free blocks. */
    1605     pCOAllocation->aOffset[0] = 0;
    1606     for (unsigned i = 1; i < RT_ELEMENTS(pCOAllocation->aOffset); ++i)
    1607         pCOAllocation->aOffset[i] = cbAllocation;
    1608 
    1609     RTListAppend(pList, &pCOAllocation->nodeAllocationsChain);
     1598    pCOAllocation->co.aOffset[0] = 0;
     1599    for (unsigned i = 1; i < RT_ELEMENTS(pCOAllocation->co.aOffset); ++i)
     1600        pCOAllocation->co.aOffset[i] = cbAllocation;
     1601
     1602    /* Add to the chain of COAs. */
     1603    RTListAppend(pList, &pCOAllocation->co.nodeAllocationsChain);
     1604
     1605    /* Add to the global list of resources. */
     1606    RTListAppend(&pDevice->listResources, &pCOAllocation->nodeResource);
    16101607
    16111608    *ppCOAllocation = pCOAllocation;
     
    16131610}
    16141611
    1615 #define IS_CO_BLOCK_FREE(_a, _i) (((_a)->u64Bitmap & (1ULL << (_i))) == 0)
    1616 #define IS_CO_BLOCK_USED(_a, _i) (((_a)->u64Bitmap & (1ULL << (_i))) != 0)
    1617 #define SET_CO_BLOCK_FREE(_a, _i) (((_a)->u64Bitmap &= ~(1ULL << (_i))))
    1618 #define SET_CO_BLOCK_USED(_a, _i) (((_a)->u64Bitmap |= (1ULL << (_i))))
    1619 
    1620 static bool vboxDXCOABlockAlloc(PVBOXDXCOALLOCATION pCOAllocation, uint32_t cb, uint32_t *poff)
    1621 {
     1612#define IS_CO_BLOCK_FREE(_a, _i) (((_a)->co.u64Bitmap & (1ULL << (_i))) == 0)
     1613#define IS_CO_BLOCK_USED(_a, _i) (((_a)->co.u64Bitmap & (1ULL << (_i))) != 0)
     1614#define SET_CO_BLOCK_FREE(_a, _i) (((_a)->co.u64Bitmap &= ~(1ULL << (_i))))
     1615#define SET_CO_BLOCK_USED(_a, _i) (((_a)->co.u64Bitmap |= (1ULL << (_i))))
     1616
     1617static bool vboxDXCOABlockAlloc(PVBOXDXKMRESOURCE pCOAllocation, uint32_t cb, uint32_t *poff)
     1618{
     1619    Assert(pCOAllocation->AllocationDesc.enmAllocationType == VBOXDXALLOCATIONTYPE_CO);
     1620
    16221621    //DEBUG_BREAKPOINT_TEST();
    16231622    /* Search for a big enough free block. The last block is a special case. */
    16241623    unsigned i = 0;
    1625     for (; i < RT_ELEMENTS(pCOAllocation->aOffset) - 1; ++i)
     1624    for (; i < RT_ELEMENTS(pCOAllocation->co.aOffset) - 1; ++i)
    16261625    {
    16271626        if (   IS_CO_BLOCK_FREE(pCOAllocation, i)
    1628             && pCOAllocation->aOffset[i + 1] - pCOAllocation->aOffset[i] >= cb)
     1627            && pCOAllocation->co.aOffset[i + 1] - pCOAllocation->co.aOffset[i] >= cb)
    16291628        {
    16301629            /* Found one. */
     
    16331632            /* If the next block is free, then add the remaining space to it. */
    16341633            if (IS_CO_BLOCK_FREE(pCOAllocation, i + 1))
    1635                 pCOAllocation->aOffset[i + 1] = pCOAllocation->aOffset[i] + cb;
    1636 
    1637             *poff = pCOAllocation->aOffset[i];
     1634                pCOAllocation->co.aOffset[i + 1] = pCOAllocation->co.aOffset[i] + cb;
     1635
     1636            *poff = pCOAllocation->co.aOffset[i];
    16381637            return true;
    16391638        }
     
    16421641    /* Last block. */
    16431642    if (   IS_CO_BLOCK_FREE(pCOAllocation, i)
    1644         && pCOAllocation->cbAllocation - pCOAllocation->aOffset[i] >= cb)
     1643        && pCOAllocation->AllocationDesc.cbAllocation - pCOAllocation->co.aOffset[i] >= cb)
    16451644    {
    16461645        /* Found one. */
    16471646        SET_CO_BLOCK_USED(pCOAllocation, i);
    16481647
    1649         *poff = pCOAllocation->aOffset[i];
     1648        *poff = pCOAllocation->co.aOffset[i];
    16501649        return true;
    16511650    }
     
    16551654
    16561655
    1657 static void vboxDXCOABlockFree(PVBOXDXCOALLOCATION pCOAllocation, uint32_t offBlock)
    1658 {
     1656static void vboxDXCOABlockFree(PVBOXDXKMRESOURCE pCOAllocation, uint32_t offBlock)
     1657{
     1658    Assert(pCOAllocation->AllocationDesc.enmAllocationType == VBOXDXALLOCATIONTYPE_CO);
     1659
    16591660    //DEBUG_BREAKPOINT_TEST();
    1660     for (unsigned i = 0; i < RT_ELEMENTS(pCOAllocation->aOffset); ++i)
    1661     {
    1662         if (pCOAllocation->aOffset[i] == offBlock)
     1661    for (unsigned i = 0; i < RT_ELEMENTS(pCOAllocation->co.aOffset); ++i)
     1662    {
     1663        if (pCOAllocation->co.aOffset[i] == offBlock)
    16631664        {
    16641665            Assert(IS_CO_BLOCK_USED(pCOAllocation, i));
     
    16721673
    16731674
     1675static void shadersAllocationDesc(VBOXDXALLOCATIONDESC *pDesc, void const *pvInitData)
     1676{
     1677    pDesc->enmAllocationType = VBOXDXALLOCATIONTYPE_SHADERS;
     1678    pDesc->cbAllocation      = *(uint32_t *)pvInitData;
     1679}
     1680
     1681
    16741682static bool vboxDXEnsureShaderAllocation(PVBOXDX_DEVICE pDevice)
    16751683{
    1676     if (!pDevice->hShaderAllocation)
    1677     {
    1678         VBOXDXALLOCATIONDESC desc;
    1679         RT_ZERO(desc);
    1680         desc.enmAllocationType = VBOXDXALLOCATIONTYPE_SHADERS;
    1681         desc.cbAllocation      = SVGA3D_MAX_SHADER_MEMORY_BYTES;
    1682 
    1683         D3DDDI_ALLOCATIONINFO2 ddiAllocationInfo;
    1684         RT_ZERO(ddiAllocationInfo);
    1685         //ddiAllocationInfo.pSystemMem            = 0;
    1686         ddiAllocationInfo.pPrivateDriverData    = &desc;
    1687         ddiAllocationInfo.PrivateDriverDataSize = sizeof(desc);
    1688         //ddiAllocationInfo.VidPnSourceId         = 0;
    1689         //ddiAllocationInfo.Flags.Value           = 0;
    1690 
    1691         D3DDDICB_ALLOCATE ddiAllocate;
    1692         RT_ZERO(ddiAllocate);
    1693         //ddiAllocate.pPrivateDriverData    = NULL;
    1694         //ddiAllocate.PrivateDriverDataSize = 0;
    1695         //ddiAllocate.hResource             = 0;
    1696         ddiAllocate.NumAllocations        = 1;
    1697         ddiAllocate.pAllocationInfo2      = &ddiAllocationInfo;
    1698 
    1699         HRESULT hr = pDevice->pRTCallbacks->pfnAllocateCb(pDevice->hRTDevice.handle, &ddiAllocate);
    1700         LogFlowFunc((" pfnAllocateCb returned %d, hKMResource 0x%X, hAllocation 0x%X", hr, ddiAllocate.hKMResource, ddiAllocationInfo.hAllocation));
    1701         AssertReturnStmt(SUCCEEDED(hr), vboxDXDeviceSetError(pDevice, hr), false);
    1702 
    1703         pDevice->hShaderAllocation  = ddiAllocationInfo.hAllocation;
    1704         pDevice->cbShaderAllocation = SVGA3D_MAX_SHADER_MEMORY_BYTES;
    1705         pDevice->cbShaderAvailable  = SVGA3D_MAX_SHADER_MEMORY_BYTES;
     1684    if (!pDevice->pShadersKMResource)
     1685    {
     1686        uint32_t const cbAllocation = SVGA3D_MAX_SHADER_MEMORY_BYTES;
     1687        pDevice->pShadersKMResource = vboxDXAllocateKMResource(pDevice, 0, shadersAllocationDesc,
     1688                                                               &cbAllocation, false);
     1689        if (!pDevice->pShadersKMResource)
     1690            return false;
     1691
     1692        pDevice->cbShaderAvailable  = cbAllocation;
    17061693        pDevice->offShaderFree      = 0;
     1694
     1695        RTListAppend(&pDevice->listResources, &pDevice->pShadersKMResource->nodeResource);
    17071696    }
    17081697
     
    17721761
    17731762    uint32_t const cbShaderTotal = pShader->cbShader + pShader->cbSignatures;
    1774     if (pDevice->cbShaderAllocation - pDevice->offShaderFree < cbShaderTotal)
     1763    if (pDevice->pShadersKMResource->AllocationDesc.cbAllocation - pDevice->offShaderFree < cbShaderTotal)
    17751764    {
    17761765        if (pDevice->cbShaderAvailable < cbShaderTotal)
     
    18241813    D3DDDICB_LOCK ddiLock;
    18251814    RT_ZERO(ddiLock);
    1826     ddiLock.hAllocation = pDevice->hShaderAllocation;
     1815    ddiLock.hAllocation = vboxDXGetAllocation(pDevice->pShadersKMResource);
    18271816    ddiLock.Flags.WriteOnly = 1;
    18281817    HRESULT hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
     
    18381827        D3DDDICB_UNLOCK ddiUnlock;
    18391828        ddiUnlock.NumAllocations = 1;
    1840         ddiUnlock.phAllocations = &pDevice->hShaderAllocation;
     1829        ddiUnlock.phAllocations = &ddiLock.hAllocation;
    18411830        hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    18421831    }
     
    18511840
    18521841    vgpu10DefineShader(pDevice, pShader->uShaderId, pShader->enmShaderType, cbShaderTotal);
    1853     vgpu10BindShader(pDevice, pShader->uShaderId, pDevice->hShaderAllocation, pShader->offShader);
     1842    vgpu10BindShader(pDevice, pShader->uShaderId, pDevice->pShadersKMResource, pShader->offShader);
    18541843}
    18551844
     
    18801869    pShader->gs.cbOutputStreamDecls = pShader->gs.NumEntries * sizeof(*pOutputStreamDecl);
    18811870    pShader->gs.pCOAllocation = NULL;
    1882     PVBOXDXCOALLOCATION pIter;
    1883     RTListForEach(&pDevice->listCOAStreamOutput, pIter, VBOXDXCOALLOCATION, nodeAllocationsChain)
     1871    PVBOXDXKMRESOURCE pIter;
     1872    RTListForEach(&pDevice->listCOAStreamOutput, pIter, VBOXDXKMRESOURCE, co.nodeAllocationsChain)
    18841873    {
    18851874        if (vboxDXCOABlockAlloc(pIter, pShader->gs.cbOutputStreamDecls, &pShader->gs.offStreamOutputDecls))
     
    19041893    D3DDDICB_LOCK ddiLock;
    19051894    RT_ZERO(ddiLock);
    1906     ddiLock.hAllocation = pShader->gs.pCOAllocation->hCOAllocation;
     1895    ddiLock.hAllocation = vboxDXGetAllocation(pShader->gs.pCOAllocation);
    19071896    ddiLock.Flags.WriteOnly = 1;
    19081897    HRESULT hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
     
    19271916        D3DDDICB_UNLOCK ddiUnlock;
    19281917        ddiUnlock.NumAllocations = 1;
    1929         ddiUnlock.phAllocations = &pShader->gs.pCOAllocation->hCOAllocation;
     1918        ddiUnlock.phAllocations = &ddiLock.hAllocation;
    19301919        hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    19311920    }
    19321921    AssertReturnVoidStmt(SUCCEEDED(hr),
    1933                          vboxDXHandleFree(pDevice->hHTShader, &pShader->uShaderId);
     1922                         vboxDXHandleFree(pDevice->hHTStreamOutput, &pShader->gs.uStreamOutputId);
    19341923                         vboxDXDeviceSetError(pDevice, hr));
    19351924
     
    19371926    vgpu10DefineStreamOutputWithMob(pDevice, pShader->gs.uStreamOutputId, pShader->gs.NumEntries, pShader->gs.NumStrides,
    19381927                                    pShader->gs.BufferStridesInBytes, pShader->gs.RasterizedStream);
    1939     vgpu10BindStreamOutput(pDevice, pShader->gs.uStreamOutputId, pShader->gs.pCOAllocation->hCOAllocation,
     1928    vgpu10BindStreamOutput(pDevice, pShader->gs.uStreamOutputId, pShader->gs.pCOAllocation,
    19401929                           pShader->gs.offStreamOutputDecls, pShader->gs.cbOutputStreamDecls);
    19411930}
     
    20542043    pQuery->pCOAllocation = NULL;
    20552044    uint32_t const cbAlloc = (pQuery->Query != D3D10DDI_QUERY_EVENT ? sizeof(uint32_t) : 0) + pQueryInfo->cbDataSvga;
    2056     PVBOXDXCOALLOCATION pIter;
    2057     RTListForEach(&pDevice->listCOAQuery, pIter, VBOXDXCOALLOCATION, nodeAllocationsChain)
     2045    PVBOXDXKMRESOURCE pIter;
     2046    RTListForEach(&pDevice->listCOAQuery, pIter, VBOXDXKMRESOURCE, co.nodeAllocationsChain)
    20582047    {
    20592048        if (vboxDXCOABlockAlloc(pIter, cbAlloc, &pQuery->offQuery))
     
    20822071        D3DDDICB_LOCK ddiLock;
    20832072        RT_ZERO(ddiLock);
    2084         ddiLock.hAllocation = pQuery->pCOAllocation->hCOAllocation;
     2073        ddiLock.hAllocation = vboxDXGetAllocation(pQuery->pCOAllocation);
    20852074        ddiLock.Flags.WriteOnly = 1;
    20862075        HRESULT hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
     
    20912080            D3DDDICB_UNLOCK ddiUnlock;
    20922081            ddiUnlock.NumAllocations = 1;
    2093             ddiUnlock.phAllocations = &pQuery->pCOAllocation->hCOAllocation;
     2082            ddiUnlock.phAllocations = &ddiLock.hAllocation;
    20942083            hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    20952084        }
     
    20972086
    20982087        vgpu10DefineQuery(pDevice, pQuery->uQueryId, pQuery->svga.queryType, pQuery->svga.flags);
    2099         vgpu10BindQuery(pDevice, pQuery->uQueryId, pQuery->pCOAllocation->hCOAllocation);
     2088        vgpu10BindQuery(pDevice, pQuery->uQueryId, pQuery->pCOAllocation);
    21002089        vgpu10SetQueryOffset(pDevice, pQuery->uQueryId, pQuery->offQuery);
    21012090    }
     
    21452134    {
    21462135        pQuery->u64Value = ASMAtomicIncU64(&pDevice->u64MobFenceValue);
    2147         vgpu10MobFence64(pDevice, pQuery->u64Value, pQuery->pCOAllocation->hCOAllocation, pQuery->offQuery);
     2136        vgpu10MobFence64(pDevice, pQuery->u64Value, pQuery->pCOAllocation, pQuery->offQuery);
    21482137        return;
    21492138    }
     
    21662155        D3DDDICB_LOCK ddiLock;
    21672156        RT_ZERO(ddiLock);
    2168         ddiLock.hAllocation = pQuery->pCOAllocation->hCOAllocation;
     2157        ddiLock.hAllocation = vboxDXGetAllocation(pQuery->pCOAllocation);
    21692158        ddiLock.Flags.ReadOnly = 1;
    21702159        HRESULT hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
     
    21752164            D3DDDICB_UNLOCK ddiUnlock;
    21762165            ddiUnlock.NumAllocations = 1;
    2177             ddiUnlock.phAllocations = &pQuery->pCOAllocation->hCOAllocation;
     2166            ddiUnlock.phAllocations = &ddiLock.hAllocation;
    21782167            hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    21792168        }
     
    22042193    D3DDDICB_LOCK ddiLock;
    22052194    RT_ZERO(ddiLock);
    2206     ddiLock.hAllocation = pQuery->pCOAllocation->hCOAllocation;
     2195    ddiLock.hAllocation = vboxDXGetAllocation(pQuery->pCOAllocation);
    22072196    ddiLock.Flags.ReadOnly = 1;
    22082197    HRESULT hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
     
    22162205        D3DDDICB_UNLOCK ddiUnlock;
    22172206        ddiUnlock.NumAllocations = 1;
    2218         ddiUnlock.phAllocations = &pQuery->pCOAllocation->hCOAllocation;
     2207        ddiUnlock.phAllocations = &ddiLock.hAllocation;
    22192208        hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    22202209    }
     
    23832372
    23842373void vboxDXSoSetTargets(PVBOXDX_DEVICE pDevice, uint32_t NumTargets,
    2385                         D3DKMT_HANDLE *paAllocations, uint32_t *paOffsets, uint32_t *paSizes)
    2386 {
    2387     vgpu10SoSetTargets(pDevice, NumTargets, paAllocations, paOffsets, paSizes);
     2374                        PVBOXDXKMRESOURCE *papKMResources, uint32_t *paOffsets, uint32_t *paSizes)
     2375{
     2376    vgpu10SoSetTargets(pDevice, NumTargets, papKMResources, paOffsets, paSizes);
    23882377}
    23892378
     
    23972386                     || pDstResource->Usage == D3D10_DDI_USAGE_STAGING,
    23982387                     vboxDXDeviceSetError(pDevice, E_INVALIDARG), false);
     2388
     2389    VBOXDXALLOCATIONDESC const *pDstAllocationDesc = vboxDXGetAllocationDesc(pDstResource);
     2390    AssertReturn(pDstAllocationDesc, false);
    23992391
    24002392    SVGA3dBox destBox;
     
    24102402    else
    24112403    {
    2412         vboxDXGetSubresourceBox(pDstResource, DstSubresource, &destBox);
     2404        vboxDXGetSubresourceBox(pDstAllocationDesc, DstSubresource, &destBox);
    24132405    }
    24142406
     
    24172409    uint32_t cRows;
    24182410    uint32_t Depth;
    2419     vboxDXGetResourceBoxDimensions(pDstResource, DstSubresource, &destBox, &offPixel, &cbRow, &cRows, &Depth);
     2411    vboxDXGetResourceBoxDimensions(pDstAllocationDesc, DstSubresource, &destBox, &offPixel, &cbRow, &cRows, &Depth);
    24202412
    24212413    UINT DstRowPitch;
    24222414    UINT DstDepthPitch;
    2423     vboxDXGetSubresourcePitch(pDstResource, DstSubresource, &DstRowPitch, &DstDepthPitch);
     2415    vboxDXGetSubresourcePitch(pDstAllocationDesc, DstSubresource, &DstRowPitch, &DstDepthPitch);
    24242416
    24252417    /* The allocation contains all subresources, so get subresource offset too. */
    2426     offPixel += vboxDXGetSubresourceOffset(pDstResource, DstSubresource);
    2427     //uint32_t const cbSubresource = vboxDXGetSubresourceSize(pDstResource, DstSubresource);
     2418    offPixel += vboxDXGetSubresourceOffset(pDstAllocationDesc, DstSubresource);
     2419    //uint32_t const cbSubresource = vboxDXGetSubresourceSize(pDstAllocationDesc, DstSubresource);
    24282420
    24292421    D3DDDICB_LOCK ddiLock;
     
    24462438        }
    24472439
    2448         D3DKMT_HANDLE const hAllocation = vboxDXGetAllocation(pDstResource);
    2449 
    24502440        D3DDDICB_UNLOCK ddiUnlock;
    24512441        ddiUnlock.NumAllocations = 1;
    2452         ddiUnlock.phAllocations = &hAllocation;
     2442        ddiUnlock.phAllocations = &ddiLock.hAllocation;
    24532443        hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    24542444        if (SUCCEEDED(hr))
     
    24562446            /* Inform the host that the resource has been updated. */
    24572447            SVGA3dBox box;
    2458             vboxDXGetSubresourceBox(pDstResource, DstSubresource, &box);
    2459             vgpu10UpdateSubResource(pDevice, vboxDXGetAllocation(pDstResource), DstSubresource, &box);
     2448            vboxDXGetSubresourceBox(pDstAllocationDesc, DstSubresource, &box);
     2449            vgpu10UpdateSubResource(pDevice, vboxDXGetKMResource(pDstResource), DstSubresource, &box);
    24602450            return true;
    24612451        }
     
    24902480        }
    24912481
    2492         D3DKMT_HANDLE const hAllocation = vboxDXGetAllocation(pBuffer);
    2493 
    24942482        D3DDDICB_UNLOCK ddiUnlock;
    24952483        ddiUnlock.NumAllocations = 1;
    2496         ddiUnlock.phAllocations = &hAllocation;
     2484        ddiUnlock.phAllocations = &ddiLock.hAllocation;
    24972485        hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    24982486        if (SUCCEEDED(hr))
     
    25382526
    25392527    pStagingResource->hRTResource.handle = 0; /* This resource has not been created by D3D runtime. */
    2540     int rc = vboxDXInitResourceData(pStagingResource, &createResource);
    2541     if (RT_SUCCESS(rc))
    2542     {
    2543         if (vboxDXCreateResource(pDevice, pStagingResource, &createResource))
    2544             return pStagingResource;
    2545     }
     2528    if (vboxDXCreateResource(pDevice, pStagingResource, &createResource))
     2529        return pStagingResource;
     2530
    25462531    RTMemFree(pStagingResource);
    25472532    vboxDXDeviceSetError(pDevice, E_OUTOFMEMORY);
     
    26012586     */
    26022587
     2588    VBOXDXALLOCATIONDESC const *pDstAllocationDesc = vboxDXGetAllocationDesc(pDstResource);
     2589    AssertReturnVoid(pDstAllocationDesc);
     2590
    26032591    /*
    26042592     * Allocate a staging buffer big enough to hold the entire subresource.
    26052593     */
    2606     uint32_t const cbStagingBuffer = vboxDXGetSubresourceSize(pDstResource, DstSubresource);
     2594    uint32_t const cbStagingBuffer = vboxDXGetSubresourceSize(pDstAllocationDesc, DstSubresource);
    26072595    PVBOXDX_RESOURCE pStagingBuffer = vboxDXCreateStagingBuffer(pDevice, cbStagingBuffer);
    26082596    if (!pStagingBuffer)
     
    26232611    }
    26242612    else
    2625         vboxDXGetSubresourceBox(pDstResource, DstSubresource, &destBox);
     2613        vboxDXGetSubresourceBox(pDstAllocationDesc, DstSubresource, &destBox);
    26262614
    26272615    uint32_t offPixel;
     
    26292617    UINT cRows;
    26302618    UINT Depth;
    2631     vboxDXGetResourceBoxDimensions(pDstResource, DstSubresource, &destBox, &offPixel, &cbRow, &cRows, &Depth);
     2619    vboxDXGetResourceBoxDimensions(pDstAllocationDesc, DstSubresource, &destBox, &offPixel, &cbRow, &cRows, &Depth);
    26322620
    26332621    UINT cbRowPitch;
    26342622    UINT cbDepthPitch;
    2635     vboxDXGetSubresourcePitch(pDstResource, DstSubresource, &cbRowPitch, &cbDepthPitch);
     2623    vboxDXGetSubresourcePitch(pDstAllocationDesc, DstSubresource, &cbRowPitch, &cbDepthPitch);
    26362624
    26372625    if (!vboxDXUpdateStagingBufferUP(pDevice, pStagingBuffer,
     
    26512639    box.h = 1;
    26522640    box.d = 1;
    2653     vgpu10UpdateSubResource(pDevice, vboxDXGetAllocation(pStagingBuffer), 0, &box);
     2641    vgpu10UpdateSubResource(pDevice, vboxDXGetKMResource(pStagingBuffer), 0, &box);
    26542642
    26552643    /* Issue SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER */
     
    26572645    uint32 srcPitch = cbRowPitch;
    26582646    uint32 srcSlicePitch = cbDepthPitch;
    2659     vgpu10TransferFromBuffer(pDevice, vboxDXGetAllocation(pStagingBuffer), srcOffset, srcPitch, srcSlicePitch,
    2660                              vboxDXGetAllocation(pDstResource), DstSubresource, destBox);
    2661 
    2662     RTListPrepend(&pDevice->listStagingResources, &pStagingBuffer->pKMResource->nodeStaging);
     2647    vgpu10TransferFromBuffer(pDevice, vboxDXGetKMResource(pStagingBuffer), srcOffset, srcPitch, srcSlicePitch,
     2648                             vboxDXGetKMResource(pDstResource), DstSubresource, destBox);
     2649
     2650    RTListPrepend(&pDevice->listStagingResources, &pStagingBuffer->pKMResource->resource.nodeStaging);
    26632651}
    26642652
     
    26702658                       D3D10_DDI_MAP DDIMap, UINT Flags, D3D10DDI_MAPPED_SUBRESOURCE *pMappedSubResource)
    26712659{
     2660    D3DKMT_HANDLE const hAllocation = vboxDXGetAllocation(pResource);
     2661    AssertReturnVoidStmt(hAllocation, vboxDXDeviceSetError(pDevice, E_INVALIDARG));
     2662
    26722663    /** @todo Need to take into account various variants Dynamic/Staging/ Discard/NoOverwrite, etc. */
    26732664    Assert(pResource->uMap == 0); /* Must not be already mapped */
    26742665
    2675     if (dxIsAllocationInUse(pDevice, vboxDXGetAllocation(pResource)))
     2666    if (dxIsAllocationInUse(pDevice, hAllocation))
    26762667    {
    26772668        vboxDXFlush(pDevice, true);
     
    26872678    if (DDIMap == D3D10_DDI_MAP_READ || DDIMap == D3D10_DDI_MAP_READWRITE)
    26882679    {
    2689         vgpu10ReadbackSubResource(pDevice, vboxDXGetAllocation(pResource), Subresource);
     2680        vgpu10ReadbackSubResource(pDevice, vboxDXGetKMResource(pResource), Subresource);
    26902681        vboxDXFlush(pDevice, true);
    26912682        /* DXGK now knows that the allocation is in use. So pfnLockCb waits until the data is ready. */
     
    26972688    {
    26982689        RT_ZERO(ddiLock);
    2699         ddiLock.hAllocation = vboxDXGetAllocation(pResource);
     2690        ddiLock.hAllocation = hAllocation;
    27002691        ddiLock.Flags.ReadOnly =   DDIMap == D3D10_DDI_MAP_READ;
    27012692        ddiLock.Flags.WriteOnly =  DDIMap == D3D10_DDI_MAP_WRITE
     
    27272718            pResource->pKMResource->hAllocation = ddiLock.hAllocation;
    27282719
    2729         uint32_t const offSubresource = vboxDXGetSubresourceOffset(pResource, Subresource);
     2720        VBOXDXALLOCATIONDESC const *pAllocationDesc = vboxDXGetAllocationDesc(pResource);
     2721
     2722        uint32_t const offSubresource = vboxDXGetSubresourceOffset(pAllocationDesc, Subresource);
    27302723        pMappedSubResource->pData = (uint8_t *)ddiLock.pData + offSubresource;
    2731         vboxDXGetSubresourcePitch(pResource, Subresource, &pMappedSubResource->RowPitch, &pMappedSubResource->DepthPitch);
     2724        vboxDXGetSubresourcePitch(pAllocationDesc, Subresource, &pMappedSubResource->RowPitch, &pMappedSubResource->DepthPitch);
    27322725
    27332726        pResource->DDIMap = DDIMap;
     
    27412734{
    27422735    D3DKMT_HANDLE const hAllocation = vboxDXGetAllocation(pResource);
     2736    AssertReturnVoidStmt(hAllocation, vboxDXDeviceSetError(pDevice, E_INVALIDARG));
    27432737
    27442738    D3DDDICB_UNLOCK ddiUnlock;
     
    27542748            /* Inform the host that the resource has been updated. */
    27552749            SVGA3dBox box;
    2756             vboxDXGetSubresourceBox(pResource, Subresource, &box);
    2757             vgpu10UpdateSubResource(pDevice, vboxDXGetAllocation(pResource), Subresource, &box);
     2750            vboxDXGetSubresourceBox(vboxDXGetAllocationDesc(pResource), Subresource, &box);
     2751            vgpu10UpdateSubResource(pDevice, vboxDXGetKMResource(pResource), Subresource, &box);
    27582752        }
    27592753
     
    28312825    }
    28322826
    2833     vgpu10DefineShaderResourceView(pDevice, pShaderResourceView->uShaderResourceViewId, vboxDXGetAllocation(pShaderResourceView->pResource),
     2827    vgpu10DefineShaderResourceView(pDevice, pShaderResourceView->uShaderResourceViewId, vboxDXGetKMResource(pShaderResourceView->pResource),
    28342828                                   pShaderResourceView->svga.format, pShaderResourceView->svga.resourceDimension,
    28352829                                   &pShaderResourceView->svga.desc);
     
    28962890    }
    28972891
    2898     vgpu10DefineRenderTargetView(pDevice, pRenderTargetView->uRenderTargetViewId, vboxDXGetAllocation(pRenderTargetView->pResource),
     2892    vgpu10DefineRenderTargetView(pDevice, pRenderTargetView->uRenderTargetViewId, vboxDXGetKMResource(pRenderTargetView->pResource),
    28992893                                 pRenderTargetView->svga.format, pRenderTargetView->svga.resourceDimension,
    29002894                                 &pRenderTargetView->svga.desc);
     
    29652959    pDepthStencilView->svga.flags = pDepthStencilView->Flags;
    29662960
    2967     vgpu10DefineDepthStencilView(pDevice, pDepthStencilView->uDepthStencilViewId, vboxDXGetAllocation(pDepthStencilView->pResource),
     2961    vgpu10DefineDepthStencilView(pDevice, pDepthStencilView->uDepthStencilViewId, vboxDXGetKMResource(pDepthStencilView->pResource),
    29682962                                 pDepthStencilView->svga.format, pDepthStencilView->svga.resourceDimension,
    29692963                                 pDepthStencilView->svga.mipSlice, pDepthStencilView->svga.firstArraySlice,
     
    30823076        if (pResource)
    30833077        {
    3084             uint32_t const cMaxConstants = pResource->AllocationDesc.cbAllocation / (4 * sizeof(UINT));
     3078            uint32_t const cMaxConstants = pResource->pKMResource->AllocationDesc.cbAllocation / (4 * sizeof(UINT));
    30853079            uint32_t const FirstConstant = pFirstConstant ? pFirstConstant[i] : 0;
    30863080            uint32_t NumConstants = pNumConstants ? pNumConstants[i] : cMaxConstants;
     
    31023096        LogFunc(("type %d, slot %d, first %d, num %d, cbAllocation %d",
    31033097                 enmShaderType, StartSlot + i, pCBS->aFirstConstant[StartSlot + i], pCBS->aNumConstants[StartSlot + i],
    3104                  pResource ? pResource->AllocationDesc.cbAllocation : -1));
     3098                 pResource ? pResource->pKMResource->AllocationDesc.cbAllocation : -1));
    31053099    }
    31063100
     
    31393133    else
    31403134    {
    3141         vboxDXGetSubresourceBox(pSrcResource, SrcSubresource, &srcBox);
    3142     }
    3143 
    3144     vgpu10ResourceCopyRegion(pDevice, vboxDXGetAllocation(pDstResource), DstSubresource,
    3145                               DstX, DstY, DstZ, vboxDXGetAllocation(pSrcResource), SrcSubresource, srcBox);
     3135        vboxDXGetSubresourceBox(vboxDXGetAllocationDesc(pSrcResource), SrcSubresource, &srcBox);
     3136    }
     3137
     3138    vgpu10ResourceCopyRegion(pDevice, vboxDXGetKMResource(pDstResource), DstSubresource,
     3139                              DstX, DstY, DstZ, vboxDXGetKMResource(pSrcResource), SrcSubresource, srcBox);
    31463140}
    31473141
     
    31493143void vboxDXResourceCopy(PVBOXDX_DEVICE pDevice, PVBOXDX_RESOURCE pDstResource, PVBOXDX_RESOURCE pSrcResource)
    31503144{
    3151     vgpu10ResourceCopy(pDevice, vboxDXGetAllocation(pDstResource), vboxDXGetAllocation(pSrcResource));
     3145    vgpu10ResourceCopy(pDevice, vboxDXGetKMResource(pDstResource), vboxDXGetKMResource(pSrcResource));
    31523146}
    31533147
     
    31573151{
    31583152    SVGA3dSurfaceFormat const copyFormat = vboxDXDxgiToSvgaFormat(ResolveFormat);
    3159     vgpu10ResolveCopy(pDevice, vboxDXGetAllocation(pDstResource), DstSubresource,
    3160                       vboxDXGetAllocation(pSrcResource), SrcSubresource, copyFormat);
     3153    vgpu10ResolveCopy(pDevice, vboxDXGetKMResource(pDstResource), DstSubresource,
     3154                      vboxDXGetKMResource(pSrcResource), SrcSubresource, copyFormat);
    31613155}
    31623156
     
    32433237        if (!pShaderResourceView->fDefined)
    32443238        {
    3245             vgpu10DefineShaderResourceView(pDevice, pShaderResourceView->uShaderResourceViewId, vboxDXGetAllocation(pShaderResourceView->pResource),
     3239            vgpu10DefineShaderResourceView(pDevice, pShaderResourceView->uShaderResourceViewId, vboxDXGetKMResource(pShaderResourceView->pResource),
    32463240                                           pShaderResourceView->svga.format, pShaderResourceView->svga.resourceDimension,
    32473241                                           &pShaderResourceView->svga.desc);
     
    32553249        if (!pRenderTargetView->fDefined)
    32563250        {
    3257             vgpu10DefineRenderTargetView(pDevice, pRenderTargetView->uRenderTargetViewId, vboxDXGetAllocation(pRenderTargetView->pResource),
     3251            vgpu10DefineRenderTargetView(pDevice, pRenderTargetView->uRenderTargetViewId, vboxDXGetKMResource(pRenderTargetView->pResource),
    32583252                                         pRenderTargetView->svga.format, pRenderTargetView->svga.resourceDimension,
    32593253                                         &pRenderTargetView->svga.desc);
     
    32673261        if (!pDepthStencilView->fDefined)
    32683262        {
    3269             vgpu10DefineDepthStencilView(pDevice, pDepthStencilView->uDepthStencilViewId, vboxDXGetAllocation(pDepthStencilView->pResource),
     3263            vgpu10DefineDepthStencilView(pDevice, pDepthStencilView->uDepthStencilViewId, vboxDXGetKMResource(pDepthStencilView->pResource),
    32703264                                         pDepthStencilView->svga.format, pDepthStencilView->svga.resourceDimension,
    32713265                                         pDepthStencilView->svga.mipSlice, pDepthStencilView->svga.firstArraySlice,
     
    32803274        if (!pUnorderedAccessView->fDefined)
    32813275        {
    3282             vgpu10DefineUAView(pDevice, pUnorderedAccessView->uUnorderedAccessViewId, vboxDXGetAllocation(pUnorderedAccessView->pResource),
     3276            vgpu10DefineUAView(pDevice, pUnorderedAccessView->uUnorderedAccessViewId, vboxDXGetKMResource(pUnorderedAccessView->pResource),
    32833277                               pUnorderedAccessView->svga.format, pUnorderedAccessView->svga.resourceDimension,
    32843278                               pUnorderedAccessView->svga.desc);
     
    32933287        {
    32943288            vgpu10DefineVideoDecoderOutputView(pDevice, pVDOV->uVideoDecoderOutputViewId,
    3295                                                vboxDXGetAllocation(pVDOV->pResource),
     3289                                               vboxDXGetKMResource(pVDOV->pResource),
    32963290                                               pVDOV->svga.desc);
    32973291            pVDOV->fDefined = true;
     
    33053299        {
    33063300            vgpu10DefineVideoProcessorInputView(pDevice, pVPIV->uVideoProcessorInputViewId,
    3307                                                 vboxDXGetAllocation(pVPIV->pResource),
     3301                                                vboxDXGetKMResource(pVPIV->pResource),
    33083302                                                pVPIV->svga.ContentDesc, pVPIV->svga.VPIVDesc);
    33093303            pVPIV->fDefined = true;
     
    33173311        {
    33183312            vgpu10DefineVideoProcessorOutputView(pDevice, pVPOV->uVideoProcessorOutputViewId,
    3319                                                  vboxDXGetAllocation(pVPOV->pResource),
     3313                                                 vboxDXGetKMResource(pVPOV->pResource),
    33203314                                                 pVPOV->svga.ContentDesc, pVPOV->svga.VPOVDesc);
    33213315            pVPOV->fDefined = true;
     
    35943588    }
    35953589
    3596     vgpu10DefineUAView(pDevice, pUnorderedAccessView->uUnorderedAccessViewId, vboxDXGetAllocation(pUnorderedAccessView->pResource),
     3590    vgpu10DefineUAView(pDevice, pUnorderedAccessView->uUnorderedAccessViewId, vboxDXGetKMResource(pUnorderedAccessView->pResource),
    35973591                       pUnorderedAccessView->svga.format, pUnorderedAccessView->svga.resourceDimension,
    35983592                       pUnorderedAccessView->svga.desc);
     
    36813675{
    36823676    vboxDXSetupPipeline(pDevice);
    3683     vgpu10DispatchIndirect(pDevice, vboxDXGetAllocation(pResource), AlignedByteOffsetForArgs);
     3677    vgpu10DispatchIndirect(pDevice, vboxDXGetKMResource(pResource), AlignedByteOffsetForArgs);
    36843678}
    36853679
     
    36873681void vboxDXCopyStructureCount(PVBOXDX_DEVICE pDevice, PVBOXDX_RESOURCE pDstBuffer, UINT DstAlignedByteOffset, PVBOXDXUNORDEREDACCESSVIEW pSrcView)
    36883682{
    3689     vgpu10CopyStructureCount(pDevice, pSrcView->uUnorderedAccessViewId, vboxDXGetAllocation(pDstBuffer), DstAlignedByteOffset);
     3683    vgpu10CopyStructureCount(pDevice, pSrcView->uUnorderedAccessViewId, vboxDXGetKMResource(pDstBuffer), DstAlignedByteOffset);
    36903684}
    36913685
     
    37003694
    37013695    SVGA3dBox boxSrc;
    3702     vboxDXGetSubresourceBox(pSrcResource, SrcSubresource, &boxSrc); /* Entire subresource. */
     3696    vboxDXGetSubresourceBox(vboxDXGetAllocationDesc(pSrcResource), SrcSubresource, &boxSrc); /* Entire subresource. */
    37033697
    37043698    SVGA3dBox boxDest;
     
    37123706    SVGA3dDXPresentBltMode mode = 0;
    37133707
    3714     vgpu10PresentBlt(pDevice, vboxDXGetAllocation(pSrcResource), SrcSubresource, vboxDXGetAllocation(pDstResource), DstSubresource,
     3708    vgpu10PresentBlt(pDevice, vboxDXGetKMResource(pSrcResource), SrcSubresource, vboxDXGetKMResource(pDstResource), DstSubresource,
    37153709                     boxSrc, boxDest, mode);
    37163710    return S_OK;
     
    37493743    /* Move staging resources to the deferred destruction queue. */
    37503744    PVBOXDXKMRESOURCE pKMResource, pNextKMResource;
    3751     RTListForEachSafe(&pDevice->listStagingResources, pKMResource, pNextKMResource, VBOXDXKMRESOURCE, nodeStaging)
    3752     {
    3753         RTListNodeRemove(&pKMResource->nodeStaging);
    3754 
    3755         PVBOXDX_RESOURCE pStagingResource = pKMResource->pResource;
    3756         pKMResource->pResource = NULL;
     3745    RTListForEachSafe(&pDevice->listStagingResources, pKMResource, pNextKMResource, VBOXDXKMRESOURCE, resource.nodeStaging)
     3746    {
     3747        RTListNodeRemove(&pKMResource->resource.nodeStaging);
     3748
     3749        PVBOXDX_RESOURCE pStagingResource = pKMResource->resource.pResource;
     3750        pKMResource->resource.pResource = NULL;
    37573751
    37583752        Assert(pStagingResource->pKMResource == pKMResource);
     
    37743768    {
    37753769        RTListNodeRemove(&pKMResource->nodeResource);
    3776 
    3777         D3DDDICB_DEALLOCATE ddiDeallocate;
    3778         RT_ZERO(ddiDeallocate);
    3779         //ddiDeallocate.hResource      = NULL;
    3780         ddiDeallocate.NumAllocations = 1;
    3781         ddiDeallocate.HandleList     = &pKMResource->hAllocation;
    3782 
    3783         HRESULT hr = pDevice->pRTCallbacks->pfnDeallocateCb(pDevice->hRTDevice.handle, &ddiDeallocate);
    3784         LogFlowFunc(("pfnDeallocateCb returned %d", hr));
    3785         AssertStmt(SUCCEEDED(hr), vboxDXDeviceSetError(pDevice, hr));
    3786 
    3787         RTMemFree(pKMResource);
     3770        vboxDXDeallocateKMResource(pDevice, pKMResource);
    37883771    }
    37893772}
     
    40654048    PVBOXDXKMRESOURCE pKMResource, pNextKMResource;
    40664049    RTListForEachSafe(&pDevice->listResources, pKMResource, pNextKMResource, VBOXDXKMRESOURCE, nodeResource)
    4067         vboxDXDestroyResource(pDevice, pKMResource->pResource);
     4050    {
     4051        if (pKMResource->AllocationDesc.enmAllocationType == VBOXDXALLOCATIONTYPE_SURFACE)
     4052            vboxDXDestroyResource(pDevice, pKMResource->resource.pResource);
     4053    }
    40684054
    40694055    dxDestroyDeferredResources(pDevice);
     
    40774063        vboxDXDestroyQuery(pDevice, pQuery);
    40784064
    4079     PVBOXDXCOALLOCATION pCOA, pNextCOA;
    4080     RTListForEachSafe(&pDevice->listCOAQuery, pCOA, pNextCOA, VBOXDXCOALLOCATION, nodeAllocationsChain)
     4065    PVBOXDXKMRESOURCE pCOA, pNextCOA;
     4066    RTListForEachSafe(&pDevice->listCOAQuery, pCOA, pNextCOA, VBOXDXKMRESOURCE, co.nodeAllocationsChain)
    40814067        vboxDXDestroyCOAllocation(pDevice, pCOA);
    4082     RTListForEachSafe(&pDevice->listCOAStreamOutput, pCOA, pNextCOA, VBOXDXCOALLOCATION, nodeAllocationsChain)
     4068    RTListForEachSafe(&pDevice->listCOAStreamOutput, pCOA, pNextCOA, VBOXDXKMRESOURCE, co.nodeAllocationsChain)
    40834069        vboxDXDestroyCOAllocation(pDevice, pCOA);
    40844070
    4085     if (pDevice->hShaderAllocation)
    4086     {
    4087         D3DDDICB_DEALLOCATE ddiDeallocate;
    4088         RT_ZERO(ddiDeallocate);
    4089         ddiDeallocate.NumAllocations = 1;
    4090         ddiDeallocate.HandleList     = &pDevice->hShaderAllocation;
    4091 
    4092         HRESULT hr = pDevice->pRTCallbacks->pfnDeallocateCb(pDevice->hRTDevice.handle, &ddiDeallocate);
    4093         LogFlowFunc(("pfnDeallocateCb returned %d", hr));
    4094         AssertStmt(SUCCEEDED(hr), vboxDXDeviceSetError(pDevice, hr));
    4095 
    4096         pDevice->hShaderAllocation = 0;
     4071    if (pDevice->pShadersKMResource)
     4072    {
     4073        RTListNodeRemove(&pDevice->pShadersKMResource->nodeResource);
     4074        vboxDXDeallocateKMResource(pDevice, pDevice->pShadersKMResource);
     4075        pDevice->pShadersKMResource = 0;
    40974076    }
    40984077
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/dx/VBoxDX.h

    r106061 r108880  
    55
    66/*
    7  * Copyright (C) 2011-2024 Oracle and/or its affiliates.
     7 * Copyright (C) 2011-2025 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    117117
    118118/*
    119  * A Context Object Allocation holds up to VBOXDX_COALLOCATION_MAX_OBJECTS objects (queries, etc)
     119 * A Context Object Allocation (COA) holds up to VBOXDX_COALLOCATION_MAX_OBJECTS objects (queries, etc)
    120120 */
    121121#define VBOXDX_COALLOCATION_MAX_OBJECTS (64)                /* Use a 64 bit field as free bitmap. */
    122 typedef struct VBOXDXCOALLOCATION                           /* Allocation for context objects (query, etc). */
    123 {
    124     RTLISTNODE                  nodeAllocationsChain;       /* Allocations can be chained. */
    125     D3DKMT_HANDLE               hCOAllocation;              /* Allocation handle. */
    126     uint32_t                    cbAllocation;               /* Size of this allocation. */
    127     uint64_t                    u64Bitmap;                  /* Bitmap of allocated blocks. */
    128     uint32_t                    aOffset[VBOXDX_COALLOCATION_MAX_OBJECTS]; /* Start offsets of blocks. */
    129 } VBOXDXCOALLOCATION, *PVBOXDXCOALLOCATION;
     122
     123/*
     124 * This structure is allocated by the driver. It is used for accounting of allocations
     125 * and for storing information which might be needed after the resource is destroyed by D3D runtime.
     126 * KM stands for Kernel Mode.
     127 */
     128typedef struct VBOXDXKMRESOURCE
     129{
     130    RTLISTNODE                     nodeResource;            /* VBOXDX_DEVICE::listResources, listDestroyedResources. */
     131    D3DKMT_HANDLE                  hAllocation;
     132    struct
     133    {
     134        uint32_t                   fOpened : 1;
     135        uint32_t                   fReserved : 31;
     136    } flags;
     137    VBOXDXALLOCATIONDESC           AllocationDesc;
     138    union
     139    {
     140        struct /* D3D resource */
     141        {
     142            struct VBOXDX_RESOURCE *pResource;              /* The structure allocated by D3D runtime. */
     143            RTLISTNODE             nodeStaging;             /* VBOXDX_DEVICE::listStagingResources if this resource is a staging buffer. */
     144        } resource;
     145        struct /* Context object allocation */
     146        {
     147            RTLISTNODE             nodeAllocationsChain;    /* CO allocations can be chained. */
     148            uint64_t               u64Bitmap;               /* Bitmap of allocated blocks. */
     149            uint32_t               aOffset[VBOXDX_COALLOCATION_MAX_OBJECTS]; /* Start offsets of blocks. */
     150        } co;
     151    };
     152} VBOXDXKMRESOURCE, *PVBOXDXKMRESOURCE;
    130153
    131154typedef struct VBOXDXSHADER
     
    149172        uint32_t                offStreamOutputDecls;       /* Offset of the declarations in the CO allocation. */
    150173        uint32_t                cbOutputStreamDecls;
    151         PVBOXDXCOALLOCATION     pCOAllocation;
     174        PVBOXDXKMRESOURCE       pCOAllocation;
    152175    } gs;                                                   /* For GS. */
    153176    /* shader bytecode */
     
    179202    uint32_t                    uQueryId;
    180203    uint32_t                    offQuery;                   /* Offset of the query in the query allocation. */
    181     PVBOXDXCOALLOCATION         pCOAllocation;
     204    PVBOXDXKMRESOURCE           pCOAllocation;
    182205    uint64_t u64Value;
    183206    /* Result for queries in SIGNALED state. */
    184207} VBOXDXQUERY, *PVBOXDXQUERY;
    185208
    186 /*
    187  * This structure is allocated by the driver. It is used for accounting of resources
    188  * and for storing information which might be needed after the resource is destroyed by runtime.
    189  * KM stands for Kernel Mode.
    190  */
    191 typedef struct VBOXDXKMRESOURCE
    192 {
    193     RTLISTNODE                  nodeResource;               /* VBOXDX_DEVICE::listResources, listDestroyedResources. */
    194     struct VBOXDX_RESOURCE     *pResource;                  /* The structure allocated by D3D runtime. */
    195     D3DKMT_HANDLE               hAllocation;
    196     RTLISTNODE                  nodeStaging;                /* VBOXDX_DEVICE::listStagingResources if this resource is a staging buffer. */
    197 } VBOXDXKMRESOURCE, *PVBOXDXKMRESOURCE;
    198 
    199209typedef struct VBOXDX_RESOURCE
    200210{
    201211    PVBOXDXKMRESOURCE              pKMResource;
    202     //RTLISTNODE                     nodeResource;            /* VBOXDX_DEVICE::listResources. */
    203212    D3D10DDI_HRTRESOURCE           hRTResource;
    204213    D3D10DDIRESOURCE_TYPE          ResourceDimension;
    205214    D3D10_DDI_RESOURCE_USAGE       Usage;
    206     VBOXDXALLOCATIONDESC           AllocationDesc;
    207215    UINT                           cSubresources;
    208216    union
     
    581589
    582590    /* Shaders */
    583     D3DKMT_HANDLE               hShaderAllocation;          /* Shader allocation for this context. */
    584     uint32_t                    cbShaderAllocation;         /* Size of the shader's allocation: SVGA3D_MAX_SHADER_MEMORY_BYTES. */
     591    PVBOXDXKMRESOURCE           pShadersKMResource;         /* Shader's allocation: SVGA3D_MAX_SHADER_MEMORY_BYTES. */
    585592    uint32_t                    cbShaderAvailable;          /* How many bytes is free in the shader's allocation. */
    586593    uint32_t                    offShaderFree;              /* Offset of the next free byte in the shader's allocation. */
     
    589596    /* Queries */
    590597    RTLISTANCHOR                listQueries;                /* All queries of this device, to be able to repack them in the allocation. */
    591     RTLISTANCHOR                listCOAQuery;               /* List of VBOXDXCOALLOCATION for all query types. */
     598    RTLISTANCHOR                listCOAQuery;               /* List of COA VBOXDXKMRESOURCEs for all query types. */
    592599    uint64_t volatile           u64MobFenceValue;
    593600
    594601    /* Stream output declarations */
    595     RTLISTANCHOR                listCOAStreamOutput;        /* List of VBOXDXCOALLOCATION for stream output declarations. */
     602    RTLISTANCHOR                listCOAStreamOutput;        /* List of COA VBOXDXKMRESOURCEs for stream output declarations. */
    596603
    597604    /* Pipeline state. */
     
    614621    struct
    615622    {
    616         D3DKMT_HANDLE           hAllocation;                /* For querying capabilities of the host device. */
    617         uint32_t                cbAllocation;
     623        PVBOXDXKMRESOURCE       pKMResource;                /* For querying capabilities of the host device. */
    618624        uint64_t volatile       u64MobFenceValue;           /* Fence value for host queries. */
    619625
     
    645651void vboxDXCommandBufferCommit(PVBOXDX_DEVICE pDevice);
    646652
    647 void vboxDXStorePatchLocation(PVBOXDX_DEVICE pDevice, void *pvPatch, VBOXDXALLOCATIONTYPE enmAllocationType,
    648                               D3DKMT_HANDLE hAllocation, uint32_t offAllocation, bool fWriteOperation);
     653void vboxDXStorePatchLocation(PVBOXDX_DEVICE pDevice, void *pvPatch, PVBOXDXKMRESOURCE pKMResource,
     654                              uint32_t offAllocation, bool fWriteOperation);
     655
     656typedef void FNVBOXDXINITALLOCATIONDESC(VBOXDXALLOCATIONDESC *pDesc, void const *pvInitData);
     657typedef FNVBOXDXINITALLOCATIONDESC *PFNVBOXDXINITALLOCATIONDESC;
     658PVBOXDXKMRESOURCE vboxDXAllocateKMResource(PVBOXDX_DEVICE pDevice, HANDLE hResource,
     659                                           PFNVBOXDXINITALLOCATIONDESC pfnInitAllocationDesc,
     660                                           void const *pvInitData, bool fZero);
     661void vboxDXDeallocateKMResource(PVBOXDX_DEVICE pDevice, PVBOXDXKMRESOURCE pKMResource);
    649662
    650663SVGA3dSurfaceFormat vboxDXDxgiToSvgaFormat(DXGI_FORMAT enmDxgiFormat);
    651664
    652 int vboxDXInitResourceData(PVBOXDX_RESOURCE pResource, const D3D11DDIARG_CREATERESOURCE *pCreateResource);
    653665bool vboxDXCreateResource(PVBOXDX_DEVICE pDevice, PVBOXDX_RESOURCE pResource,
    654666                          const D3D11DDIARG_CREATERESOURCE *pCreateResource);
     
    711723                              D3D10_DDI_MAP DDIMap, UINT Flags, D3D10DDI_MAPPED_SUBRESOURCE *pMappedSubResource);
    712724void vboxDXResourceUnmap(PVBOXDX_DEVICE pDevice, PVBOXDX_RESOURCE pResource, UINT Subresource);
    713 void vboxDXSoSetTargets(PVBOXDX_DEVICE pDevice, uint32_t NumTargets, D3DKMT_HANDLE *paAllocations, uint32_t *paOffsets, uint32_t *paSizes);
     725void vboxDXSoSetTargets(PVBOXDX_DEVICE pDevice, uint32_t NumTargets, PVBOXDXKMRESOURCE *papKMResources, uint32_t *paOffsets, uint32_t *paSizes);
    714726void vboxDXCreateShaderResourceView(PVBOXDX_DEVICE pDevice, PVBOXDXSHADERRESOURCEVIEW pShaderResourceView);
    715727void vboxDXGenMips(PVBOXDX_DEVICE pDevice, PVBOXDXSHADERRESOURCEVIEW pShaderResourceView);
     
    833845}
    834846
     847DECLINLINE(PVBOXDXKMRESOURCE) vboxDXGetKMResource(PVBOXDX_RESOURCE pResource)
     848{
     849    return pResource ? pResource->pKMResource : 0;
     850}
     851
     852DECLINLINE(D3DKMT_HANDLE) vboxDXGetAllocation(PVBOXDXKMRESOURCE pKMResource)
     853{
     854    return pKMResource ? pKMResource->hAllocation : 0;
     855}
     856
    835857DECLINLINE(D3DKMT_HANDLE) vboxDXGetAllocation(PVBOXDX_RESOURCE pResource)
    836858{
    837     return pResource ? pResource->pKMResource->hAllocation : 0;
     859    return pResource ? vboxDXGetAllocation(pResource->pKMResource) : 0;
    838860}
    839861
     862DECLINLINE(VBOXDXALLOCATIONDESC *) vboxDXGetAllocationDesc(PVBOXDXKMRESOURCE pKMResource)
     863{
     864    return pKMResource ? &pKMResource->AllocationDesc : 0;
     865}
     866
     867DECLINLINE(VBOXDXALLOCATIONDESC *) vboxDXGetAllocationDesc(PVBOXDX_RESOURCE pResource)
     868{
     869    return pResource ? vboxDXGetAllocationDesc(pResource->pKMResource) : 0;
     870}
     871
    840872#endif /* !GA_INCLUDED_SRC_WINNT_Graphics_Video_disp_wddm_dx_VBoxDX_h */
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/dx/VBoxDXCmd.cpp

    r106061 r108880  
    55
    66/*
    7  * Copyright (C) 2022-2024 Oracle and/or its affiliates.
     7 * Copyright (C) 2022-2025 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    656656int vgpu10BindStreamOutput(PVBOXDX_DEVICE pDevice,
    657657                           SVGA3dStreamOutputId soid,
    658                            D3DKMT_HANDLE hAllocation,
     658                           PVBOXDXKMRESOURCE pKMResource,
    659659                           uint32 offsetInBytes,
    660660                           uint32 sizeInBytes)
     
    671671    SET_CMD_FIELD(sizeInBytes);
    672672
    673     vboxDXStorePatchLocation(pDevice, &cmd->mobid, VBOXDXALLOCATIONTYPE_CO,
    674                              hAllocation, offsetInBytes, true);
     673    vboxDXStorePatchLocation(pDevice, &cmd->mobid, pKMResource,
     674                             offsetInBytes, true);
    675675
    676676    vboxDXCommandBufferCommit(pDevice);
     
    712712int vgpu10BindShader(PVBOXDX_DEVICE pDevice,
    713713                     uint32_t shid,
    714                      D3DKMT_HANDLE hAllocation,
     714                     PVBOXDXKMRESOURCE pKMResource,
    715715                     uint32_t offsetInBytes)
    716716{
     
    726726    SET_CMD_FIELD(offsetInBytes);
    727727
    728     vboxDXStorePatchLocation(pDevice, &cmd->mobid, VBOXDXALLOCATIONTYPE_SHADERS,
    729                              hAllocation, offsetInBytes, true);
     728    vboxDXStorePatchLocation(pDevice, &cmd->mobid, pKMResource,
     729                             offsetInBytes, true);
    730730
    731731    vboxDXCommandBufferCommit(pDevice);
     
    753753                           uint32_t startBuffer,
    754754                           uint32_t numBuffers,
    755                            D3DKMT_HANDLE *paAllocations,
     755                           PVBOXDXKMRESOURCE *papKMResources,
    756756                           const UINT *paStrides,
    757757                           const UINT *paOffsets)
     
    773773        pVertexBuffer->stride = paStrides[i];
    774774        pVertexBuffer->offset = paOffsets[i];
    775         vboxDXStorePatchLocation(pDevice, &pVertexBuffer->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    776                                  paAllocations[i], 0, false);
     775        vboxDXStorePatchLocation(pDevice, &pVertexBuffer->sid, papKMResources[i],
     776                                 0, false);
    777777    }
    778778
     
    782782
    783783int vgpu10SetIndexBuffer(PVBOXDX_DEVICE pDevice,
    784                          D3DKMT_HANDLE hAllocation,
     784                         PVBOXDXKMRESOURCE pKMResource,
    785785                         SVGA3dSurfaceFormat format,
    786786                         uint32_t offset)
     
    795795    SET_CMD_FIELD(format);
    796796    SET_CMD_FIELD(offset);
    797     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    798                              hAllocation, 0, false);
     797    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     798                             0, false);
    799799
    800800    vboxDXCommandBufferCommit(pDevice);
     
    804804int vgpu10SoSetTargets(PVBOXDX_DEVICE pDevice,
    805805                       uint32_t numTargets,
    806                        D3DKMT_HANDLE *paAllocations,
     806                       PVBOXDXKMRESOURCE *papKMResources,
    807807                       uint32_t *paOffsets,
    808808                       uint32_t *paSizes)
     
    824824        pSoTarget->offset      = paOffsets[i];
    825825        pSoTarget->sizeInBytes = paSizes[i];
    826         vboxDXStorePatchLocation(pDevice, &pSoTarget->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    827                                  paAllocations[i], 0, true);
     826        vboxDXStorePatchLocation(pDevice, &pSoTarget->sid, papKMResources[i],
     827                                 0, true);
    828828    }
    829829
     
    835835int vgpu10DefineShaderResourceView(PVBOXDX_DEVICE pDevice,
    836836                                   SVGA3dShaderResourceViewId shaderResourceViewId,
    837                                    D3DKMT_HANDLE hAllocation,
     837                                   PVBOXDXKMRESOURCE pKMResource,
    838838                                   SVGA3dSurfaceFormat format,
    839839                                   SVGA3dResourceType resourceDimension,
     
    851851    SET_CMD_FIELD(resourceDimension);
    852852    cmd->desc = *pDesc;
    853     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    854                              hAllocation, 0, false);
     853    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     854                             0, false);
    855855
    856856    vboxDXCommandBufferCommit(pDevice);
     
    893893int vgpu10DefineRenderTargetView(PVBOXDX_DEVICE pDevice,
    894894                                 SVGA3dRenderTargetViewId renderTargetViewId,
    895                                  D3DKMT_HANDLE hAllocation,
     895                                 PVBOXDXKMRESOURCE pKMResource,
    896896                                 SVGA3dSurfaceFormat format,
    897897                                 SVGA3dResourceType resourceDimension,
     
    909909    SET_CMD_FIELD(resourceDimension);
    910910    cmd->desc = *pDesc;
    911     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    912                              hAllocation, 0, true);
     911    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     912                             0, true);
    913913
    914914    vboxDXCommandBufferCommit(pDevice);
     
    10261026int vgpu10DefineDepthStencilView(PVBOXDX_DEVICE pDevice,
    10271027                                 SVGA3dDepthStencilViewId depthStencilViewId,
    1028                                  D3DKMT_HANDLE hAllocation,
     1028                                 PVBOXDXKMRESOURCE pKMResource,
    10291029                                 SVGA3dSurfaceFormat format,
    10301030                                 SVGA3dResourceType resourceDimension,
     
    10481048    SET_CMD_FIELD(arraySize);
    10491049    SET_CMD_FIELD(flags);
    1050     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    1051                              hAllocation, 0, true);
     1050    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     1051                             0, true);
    10521052
    10531053    vboxDXCommandBufferCommit(pDevice);
     
    11461146                                  uint32 slot,
    11471147                                  SVGA3dShaderType type,
    1148                                   D3DKMT_HANDLE hAllocation,
     1148                                  PVBOXDXKMRESOURCE pKMResource,
    11491149                                  uint32 offsetInBytes,
    11501150                                  uint32 sizeInBytes)
     
    11611161    SET_CMD_FIELD(offsetInBytes);
    11621162    SET_CMD_FIELD(sizeInBytes);
    1163     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    1164                              hAllocation, 0, false);
     1163    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     1164                             0, false);
    11651165
    11661166    vboxDXCommandBufferCommit(pDevice);
     
    11701170
    11711171int vgpu10UpdateSubResource(PVBOXDX_DEVICE pDevice,
    1172                             D3DKMT_HANDLE hAllocation,
     1172                            PVBOXDXKMRESOURCE pKMResource,
    11731173                            uint32 subResource,
    11741174                            const SVGA3dBox *pBox)
     
    11831183    SET_CMD_FIELD(subResource);
    11841184    cmd->box = *pBox;
    1185     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    1186                              hAllocation, 0, true);
     1185    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     1186                             0, true);
    11871187
    11881188    vboxDXCommandBufferCommit(pDevice);
     
    11921192
    11931193int vgpu10ReadbackSubResource(PVBOXDX_DEVICE pDevice,
    1194                               D3DKMT_HANDLE hAllocation,
     1194                              PVBOXDXKMRESOURCE pKMResource,
    11951195                              uint32 subResource)
    11961196{
     
    12071207     * before getting the allocation data in pfnLockCb.
    12081208     */
    1209     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    1210                              hAllocation, 0, true);
     1209    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     1210                             0, true);
    12111211
    12121212    vboxDXCommandBufferCommit(pDevice);
     
    12161216
    12171217int vgpu10TransferFromBuffer(PVBOXDX_DEVICE pDevice,
    1218                              D3DKMT_HANDLE hSrcAllocation,
     1218                             PVBOXDXKMRESOURCE pSrcKMResource,
    12191219                             uint32 srcOffset,
    12201220                             uint32 srcPitch,
    12211221                             uint32 srcSlicePitch,
    1222                              D3DKMT_HANDLE hDstAllocation,
     1222                             PVBOXDXKMRESOURCE pDstKMResource,
    12231223                             uint32 destSubResource,
    12241224                             SVGA3dBox const &destBox)
     
    12371237    SET_CMD_FIELD(destSubResource);
    12381238    SET_CMD_FIELD(destBox);
    1239     vboxDXStorePatchLocation(pDevice, &cmd->srcSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1240                              hSrcAllocation, 0, false);
    1241     vboxDXStorePatchLocation(pDevice, &cmd->destSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1242                              hDstAllocation, 0, true);
     1239    vboxDXStorePatchLocation(pDevice, &cmd->srcSid, pSrcKMResource,
     1240                             0, false);
     1241    vboxDXStorePatchLocation(pDevice, &cmd->destSid, pDstKMResource,
     1242                             0, true);
    12431243
    12441244    vboxDXCommandBufferCommit(pDevice);
     
    12481248
    12491249int vgpu10ResourceCopyRegion(PVBOXDX_DEVICE pDevice,
    1250                              D3DKMT_HANDLE hDstAllocation,
     1250                             PVBOXDXKMRESOURCE pDstKMResource,
    12511251                             uint32 dstSubResource,
    12521252                             uint32 dstX,
    12531253                             uint32 dstY,
    12541254                             uint32 dstZ,
    1255                              D3DKMT_HANDLE hSrcAllocation,
     1255                             PVBOXDXKMRESOURCE pSrcKMResource,
    12561256                             uint32 srcSubResource,
    12571257                             SVGA3dBox const &srcBox)
     
    12771277    cmd->box.srcz = srcBox.z;
    12781278
    1279     vboxDXStorePatchLocation(pDevice, &cmd->dstSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1280                              hDstAllocation, 0, true);
    1281     vboxDXStorePatchLocation(pDevice, &cmd->srcSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1282                              hSrcAllocation, 0, false);
     1279    vboxDXStorePatchLocation(pDevice, &cmd->dstSid, pDstKMResource,
     1280                             0, true);
     1281    vboxDXStorePatchLocation(pDevice, &cmd->srcSid, pSrcKMResource,
     1282                             0, false);
    12831283
    12841284    vboxDXCommandBufferCommit(pDevice);
     
    12881288
    12891289int vgpu10ResourceCopy(PVBOXDX_DEVICE pDevice,
    1290                        D3DKMT_HANDLE hDstAllocation,
    1291                        D3DKMT_HANDLE hSrcAllocation)
     1290                       PVBOXDXKMRESOURCE pDstKMResource,
     1291                       PVBOXDXKMRESOURCE pSrcKMResource)
    12921292{
    12931293    void *pvCmd = vboxDXCommandBufferReserve(pDevice, SVGA_3D_CMD_DX_PRED_COPY,
     
    13001300    cmd->srcSid = SVGA3D_INVALID_ID;
    13011301
    1302     vboxDXStorePatchLocation(pDevice, &cmd->dstSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1303                              hDstAllocation, 0, true);
    1304     vboxDXStorePatchLocation(pDevice, &cmd->srcSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1305                              hSrcAllocation, 0, false);
     1302    vboxDXStorePatchLocation(pDevice, &cmd->dstSid, pDstKMResource,
     1303                             0, true);
     1304    vboxDXStorePatchLocation(pDevice, &cmd->srcSid, pSrcKMResource,
     1305                             0, false);
    13061306
    13071307    vboxDXCommandBufferCommit(pDevice);
     
    13111311
    13121312int vgpu10ResolveCopy(PVBOXDX_DEVICE pDevice,
    1313                       D3DKMT_HANDLE hDstAllocation,
     1313                      PVBOXDXKMRESOURCE pDstKMResource,
    13141314                      uint32 dstSubResource,
    1315                       D3DKMT_HANDLE hSrcAllocation,
     1315                      PVBOXDXKMRESOURCE pSrcKMResource,
    13161316                      uint32 srcSubResource,
    13171317                      SVGA3dSurfaceFormat copyFormat)
     
    13291329    SET_CMD_FIELD(copyFormat);
    13301330
    1331     vboxDXStorePatchLocation(pDevice, &cmd->dstSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1332                              hDstAllocation, 0, true);
    1333     vboxDXStorePatchLocation(pDevice, &cmd->srcSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1334                              hSrcAllocation, 0, false);
     1331    vboxDXStorePatchLocation(pDevice, &cmd->dstSid, pDstKMResource,
     1332                             0, true);
     1333    vboxDXStorePatchLocation(pDevice, &cmd->srcSid, pSrcKMResource,
     1334                             0, false);
    13351335
    13361336    vboxDXCommandBufferCommit(pDevice);
     
    13411341int vgpu10MobFence64(PVBOXDX_DEVICE pDevice,
    13421342                     uint64 value,
    1343                      D3DKMT_HANDLE hAllocation,
     1343                     PVBOXDXKMRESOURCE pKMResource,
    13441344                     uint32 mobOffset)
    13451345{
     
    13541354    SET_CMD_FIELD(mobOffset);
    13551355
    1356     vboxDXStorePatchLocation(pDevice, &cmd->mobId, VBOXDXALLOCATIONTYPE_CO,
    1357                              hAllocation, mobOffset, true);
     1356    vboxDXStorePatchLocation(pDevice, &cmd->mobId, pKMResource,
     1357                             mobOffset, true);
    13581358
    13591359    vboxDXCommandBufferCommit(pDevice);
     
    14001400int vgpu10BindQuery(PVBOXDX_DEVICE pDevice,
    14011401                    SVGA3dQueryId queryId,
    1402                     D3DKMT_HANDLE hAllocation)
     1402                    PVBOXDXKMRESOURCE pKMResource)
    14031403{
    14041404    void *pvCmd = vboxDXCommandBufferReserve(pDevice, SVGA_3D_CMD_DX_BIND_QUERY,
     
    14111411    cmd->mobid = SVGA3D_INVALID_ID;
    14121412
    1413     vboxDXStorePatchLocation(pDevice, &cmd->mobid, VBOXDXALLOCATIONTYPE_CO,
    1414                              hAllocation, 0, true);
     1413    vboxDXStorePatchLocation(pDevice, &cmd->mobid, pKMResource,
     1414                             0, true);
    14151415
    14161416    vboxDXCommandBufferCommit(pDevice);
     
    15051505int vgpu10DefineUAView(PVBOXDX_DEVICE pDevice,
    15061506                       SVGA3dUAViewId uaViewId,
    1507                        D3DKMT_HANDLE hAllocation,
     1507                       PVBOXDXKMRESOURCE pKMResource,
    15081508                       SVGA3dSurfaceFormat format,
    15091509                       SVGA3dResourceType resourceDimension,
     
    15211521    SET_CMD_FIELD(resourceDimension);
    15221522    SET_CMD_FIELD(desc);
    1523     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    1524                              hAllocation, 0, true);
     1523    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     1524                             0, true);
    15251525
    15261526    vboxDXCommandBufferCommit(pDevice);
     
    16661666
    16671667int vgpu10DispatchIndirect(PVBOXDX_DEVICE pDevice,
    1668                            D3DKMT_HANDLE hAllocation,
     1668                           PVBOXDXKMRESOURCE pKMResource,
    16691669                           uint32 byteOffsetForArgs)
    16701670{
     
    16781678    SET_CMD_FIELD(byteOffsetForArgs);
    16791679
    1680     vboxDXStorePatchLocation(pDevice, &cmd->argsBufferSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1681                              hAllocation, 0, false);
     1680    vboxDXStorePatchLocation(pDevice, &cmd->argsBufferSid, pKMResource,
     1681                             0, false);
    16821682
    16831683    vboxDXCommandBufferCommit(pDevice);
     
    16871687
    16881688int vgpu10DrawIndexedInstancedIndirect(PVBOXDX_DEVICE pDevice,
    1689                                        D3DKMT_HANDLE hAllocation,
     1689                                       PVBOXDXKMRESOURCE pKMResource,
    16901690                                       uint32 byteOffsetForArgs)
    16911691{
     
    16991699    SET_CMD_FIELD(byteOffsetForArgs);
    17001700
    1701     vboxDXStorePatchLocation(pDevice, &cmd->argsBufferSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1702                              hAllocation, 0, false);
     1701    vboxDXStorePatchLocation(pDevice, &cmd->argsBufferSid, pKMResource,
     1702                             0, false);
    17031703
    17041704    vboxDXCommandBufferCommit(pDevice);
     
    17081708
    17091709int vgpu10DrawInstancedIndirect(PVBOXDX_DEVICE pDevice,
    1710                                 D3DKMT_HANDLE hAllocation,
     1710                                PVBOXDXKMRESOURCE pKMResource,
    17111711                                uint32 byteOffsetForArgs)
    17121712{
     
    17201720    SET_CMD_FIELD(byteOffsetForArgs);
    17211721
    1722     vboxDXStorePatchLocation(pDevice, &cmd->argsBufferSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1723                              hAllocation, 0, false);
     1722    vboxDXStorePatchLocation(pDevice, &cmd->argsBufferSid, pKMResource,
     1723                             0, false);
    17241724
    17251725    vboxDXCommandBufferCommit(pDevice);
     
    17301730int vgpu10CopyStructureCount(PVBOXDX_DEVICE pDevice,
    17311731                             SVGA3dUAViewId srcUAViewId,
    1732                              D3DKMT_HANDLE hDstBuffer,
     1732                             PVBOXDXKMRESOURCE pDstKMResource,
    17331733                             uint32 destByteOffset)
    17341734{
     
    17431743    SET_CMD_FIELD(destByteOffset);
    17441744
    1745     vboxDXStorePatchLocation(pDevice, &cmd->destSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1746                              hDstBuffer, 0, true);
     1745    vboxDXStorePatchLocation(pDevice, &cmd->destSid, pDstKMResource,
     1746                             0, true);
    17471747
    17481748    vboxDXCommandBufferCommit(pDevice);
     
    17521752
    17531753int vgpu10PresentBlt(PVBOXDX_DEVICE pDevice,
    1754                      D3DKMT_HANDLE hSrcAllocation,
     1754                     PVBOXDXKMRESOURCE pSrcKMResource,
    17551755                     uint32 srcSubResource,
    1756                      D3DKMT_HANDLE hDstAllocation,
     1756                     PVBOXDXKMRESOURCE pDstKMResource,
    17571757                     uint32 destSubResource,
    17581758                     SVGA3dBox const &boxSrc,
     
    17741774    SET_CMD_FIELD(mode);
    17751775
    1776     vboxDXStorePatchLocation(pDevice, &cmd->srcSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1777                              hSrcAllocation, 0, false);
    1778     vboxDXStorePatchLocation(pDevice, &cmd->dstSid, VBOXDXALLOCATIONTYPE_SURFACE,
    1779                              hDstAllocation, 0, true);
     1776    vboxDXStorePatchLocation(pDevice, &cmd->srcSid, pSrcKMResource,
     1777                             0, false);
     1778    vboxDXStorePatchLocation(pDevice, &cmd->dstSid, pDstKMResource,
     1779                             0, true);
    17801780
    17811781    vboxDXCommandBufferCommit(pDevice);
     
    18041804int vgpu10DefineVideoDecoderOutputView(PVBOXDX_DEVICE pDevice,
    18051805                                       VBSVGA3dVideoDecoderOutputViewId videoDecoderOutputViewId,
    1806                                        D3DKMT_HANDLE hAllocation,
     1806                                       PVBOXDXKMRESOURCE pKMResource,
    18071807                                       VBSVGA3dVDOVDesc const &desc)
    18081808{
     
    18161816    cmd->sid = SVGA3D_INVALID_ID;
    18171817    SET_CMD_FIELD(desc);
    1818     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    1819                              hAllocation, 0, true);
     1818    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     1819                             0, true);
    18201820
    18211821    vboxDXCommandBufferCommit(pDevice);
     
    18651865                                    VBSVGA3dVideoDecoderId videoDecoderId,
    18661866                                    uint32 bufferCount,
    1867                                     D3DKMT_HANDLE const *pahAllocation,
     1867                                    PVBOXDXKMRESOURCE const *papKMResources,
    18681868                                    VBSVGA3dVideoDecoderBufferDesc const *paBufferDesc)
    18691869{
     
    18831883    for (uint32_t i = 0; i < bufferCount; ++i)
    18841884    {
    1885         vboxDXStorePatchLocation(pDevice, &paCmdBufferDesc[i].sidBuffer, VBOXDXALLOCATIONTYPE_SURFACE,
    1886                                  pahAllocation[i], 0, false);
     1885        vboxDXStorePatchLocation(pDevice, &paCmdBufferDesc[i].sidBuffer, papKMResources[i],
     1886                                 0, false);
    18871887    }
    18881888
     
    19101910int vgpu10DefineVideoProcessorInputView(PVBOXDX_DEVICE pDevice,
    19111911                                        VBSVGA3dVideoProcessorInputViewId videoProcessorInputViewId,
    1912                                         D3DKMT_HANDLE hAllocation,
     1912                                        PVBOXDXKMRESOURCE pKMResource,
    19131913                                        VBSVGA3dVideoProcessorDesc const &contentDesc,
    19141914                                        VBSVGA3dVPIVDesc const &desc)
     
    19241924    SET_CMD_FIELD(contentDesc);
    19251925    SET_CMD_FIELD(desc);
    1926     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    1927                              hAllocation, 0, true);
     1926    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     1927                             0, true);
    19281928
    19291929    vboxDXCommandBufferCommit(pDevice);
     
    19341934int vgpu10DefineVideoProcessorOutputView(PVBOXDX_DEVICE pDevice,
    19351935                                         VBSVGA3dVideoProcessorOutputViewId videoProcessorOutputViewId,
    1936                                          D3DKMT_HANDLE hAllocation,
     1936                                         PVBOXDXKMRESOURCE pKMResource,
    19371937                                         VBSVGA3dVideoProcessorDesc const &contentDesc,
    19381938                                         VBSVGA3dVPOVDesc const &desc)
     
    19481948    SET_CMD_FIELD(contentDesc);
    19491949    SET_CMD_FIELD(desc);
    1950     vboxDXStorePatchLocation(pDevice, &cmd->sid, VBOXDXALLOCATIONTYPE_SURFACE,
    1951                              hAllocation, 0, true);
     1950    vboxDXStorePatchLocation(pDevice, &cmd->sid, pKMResource,
     1951                             0, true);
    19521952
    19531953    vboxDXCommandBufferCommit(pDevice);
     
    24902490int vgpu10GetVideoCapability(PVBOXDX_DEVICE pDevice,
    24912491                             VBSVGA3dVideoCapability capability,
    2492                              D3DKMT_HANDLE hAllocation,
     2492                             PVBOXDXKMRESOURCE pKMResource,
    24932493                             uint32 offsetInBytes,
    24942494                             uint32 sizeInBytes,
     
    25072507    SET_CMD_FIELD(fenceValue);
    25082508
    2509     vboxDXStorePatchLocation(pDevice, &cmd->mobid, VBOXDXALLOCATIONTYPE_CO,
    2510                              hAllocation, offsetInBytes, true);
    2511 
    2512     vboxDXCommandBufferCommit(pDevice);
    2513     return VINF_SUCCESS;
    2514 }
     2509    vboxDXStorePatchLocation(pDevice, &cmd->mobid, pKMResource,
     2510                             offsetInBytes, true);
     2511
     2512    vboxDXCommandBufferCommit(pDevice);
     2513    return VINF_SUCCESS;
     2514}
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/dx/VBoxDXCmd.h

    r106061 r108880  
    55
    66/*
    7  * Copyright (C) 2022-2024 Oracle and/or its affiliates.
     7 * Copyright (C) 2022-2025 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    171171int vgpu10BindStreamOutput(PVBOXDX_DEVICE pDevice,
    172172                           SVGA3dStreamOutputId soid,
    173                            D3DKMT_HANDLE hAllocation,
     173                           PVBOXDXKMRESOURCE pKMResource,
    174174                           uint32 offsetInBytes,
    175175                           uint32 sizeInBytes);
     
    180180int vgpu10BindShader(PVBOXDX_DEVICE pDevice,
    181181                     uint32_t shid,
    182                      D3DKMT_HANDLE hAllocation,
     182                     PVBOXDXKMRESOURCE pKMResource,
    183183                     uint32_t offsetInBytes);
    184184int vgpu10SetShader(PVBOXDX_DEVICE pDevice,
     
    188188                           uint32_t startBuffer,
    189189                           uint32_t numBuffers,
    190                            D3DKMT_HANDLE *paAllocations,
     190                           PVBOXDXKMRESOURCE *papKMResources,
    191191                           const UINT *paStrides,
    192192                           const UINT *paOffsets);
    193193int vgpu10SetIndexBuffer(PVBOXDX_DEVICE pDevice,
    194                          D3DKMT_HANDLE hAllocation,
     194                         PVBOXDXKMRESOURCE pKMResource,
    195195                         SVGA3dSurfaceFormat format,
    196196                         uint32_t offset);
    197197int vgpu10SoSetTargets(PVBOXDX_DEVICE pDevice,
    198198                       uint32_t numTargets,
    199                        D3DKMT_HANDLE *paAllocations,
     199                       PVBOXDXKMRESOURCE *papKMResources,
    200200                       uint32_t *paOffsets,
    201201                       uint32_t *paSizes);
    202202int vgpu10DefineShaderResourceView(PVBOXDX_DEVICE pDevice,
    203203                                   SVGA3dShaderResourceViewId shaderResourceViewId,
    204                                    D3DKMT_HANDLE hAllocation,
     204                                   PVBOXDXKMRESOURCE pKMResource,
    205205                                   SVGA3dSurfaceFormat format,
    206206                                   SVGA3dResourceType resourceDimension,
     
    212212int vgpu10DefineRenderTargetView(PVBOXDX_DEVICE pDevice,
    213213                                 SVGA3dRenderTargetViewId renderTargetViewId,
    214                                  D3DKMT_HANDLE hAllocation,
     214                                 PVBOXDXKMRESOURCE pKMResource,
    215215                                 SVGA3dSurfaceFormat format,
    216216                                 SVGA3dResourceType resourceDimension,
     
    223223int vgpu10DefineDepthStencilView(PVBOXDX_DEVICE pDevice,
    224224                                 SVGA3dDepthStencilViewId depthStencilViewId,
    225                                  D3DKMT_HANDLE hAllocation,
     225                                 PVBOXDXKMRESOURCE pKMResource,
    226226                                 SVGA3dSurfaceFormat format,
    227227                                 SVGA3dResourceType resourceDimension,
     
    250250                                  uint32 slot,
    251251                                  SVGA3dShaderType type,
    252                                   D3DKMT_HANDLE hAllocation,
     252                                  PVBOXDXKMRESOURCE pKMResource,
    253253                                  uint32 offsetInBytes,
    254254                                  uint32 sizeInBytes);
    255255int vgpu10UpdateSubResource(PVBOXDX_DEVICE pDevice,
    256                             D3DKMT_HANDLE hAllocation,
     256                            PVBOXDXKMRESOURCE pKMResource,
    257257                            uint32 subResource,
    258258                            const SVGA3dBox *pBox);
    259259int vgpu10ReadbackSubResource(PVBOXDX_DEVICE pDevice,
    260                             D3DKMT_HANDLE hAllocation,
     260                            PVBOXDXKMRESOURCE pKMResource,
    261261                            uint32 subResource);
    262262int vgpu10TransferFromBuffer(PVBOXDX_DEVICE pDevice,
    263                              D3DKMT_HANDLE hSrcAllocation,
     263                             PVBOXDXKMRESOURCE pSrcKMResource,
    264264                             uint32 srcOffset,
    265265                             uint32 srcPitch,
    266266                             uint32 srcSlicePitch,
    267                              D3DKMT_HANDLE hDstAllocation,
     267                             PVBOXDXKMRESOURCE pDstKMResource,
    268268                             uint32 destSubResource,
    269269                             SVGA3dBox const &destBox);
    270270int vgpu10ResourceCopyRegion(PVBOXDX_DEVICE pDevice,
    271                              D3DKMT_HANDLE hDstAllocation,
     271                             PVBOXDXKMRESOURCE pDstKMResource,
    272272                             uint32 dstSubResource,
    273273                             uint32 dstX,
    274274                             uint32 dstY,
    275275                             uint32 dstZ,
    276                              D3DKMT_HANDLE hSrcAllocation,
     276                             PVBOXDXKMRESOURCE pSrcKMResource,
    277277                             uint32 srcSubResource,
    278278                             SVGA3dBox const &srcBox);
    279279int vgpu10ResourceCopy(PVBOXDX_DEVICE pDevice,
    280                        D3DKMT_HANDLE hDstAllocation,
    281                        D3DKMT_HANDLE hSrcAllocation);
     280                       PVBOXDXKMRESOURCE pDstKMResource,
     281                       PVBOXDXKMRESOURCE pSrcKMResource);
    282282int vgpu10ResolveCopy(PVBOXDX_DEVICE pDevice,
    283                       D3DKMT_HANDLE hDstAllocation,
     283                      PVBOXDXKMRESOURCE pDstKMResource,
    284284                      uint32 dstSubResource,
    285                       D3DKMT_HANDLE hSrcAllocation,
     285                      PVBOXDXKMRESOURCE pSrcKMResource,
    286286                      uint32 srcSubResource,
    287287                      SVGA3dSurfaceFormat copyFormat);
    288288int vgpu10MobFence64(PVBOXDX_DEVICE pDevice,
    289289                     uint64 value,
    290                      D3DKMT_HANDLE hAllocation,
     290                     PVBOXDXKMRESOURCE pKMResource,
    291291                     uint32 mobOffset);
    292292int vgpu10DefineQuery(PVBOXDX_DEVICE pDevice,
     
    298298int vgpu10BindQuery(PVBOXDX_DEVICE pDevice,
    299299                    SVGA3dQueryId queryId,
    300                     D3DKMT_HANDLE hAllocation);
     300                    PVBOXDXKMRESOURCE pKMResource);
    301301int vgpu10SetQueryOffset(PVBOXDX_DEVICE pDevice,
    302302                         SVGA3dQueryId queryId,
     
    313313int vgpu10DefineUAView(PVBOXDX_DEVICE pDevice,
    314314                       SVGA3dUAViewId uaViewId,
    315                        D3DKMT_HANDLE hAllocation,
     315                       PVBOXDXKMRESOURCE pKMResource,
    316316                       SVGA3dSurfaceFormat format,
    317317                       SVGA3dResourceType resourceDimension,
     
    341341                   uint32 threadGroupCountZ);
    342342int vgpu10DispatchIndirect(PVBOXDX_DEVICE pDevice,
    343                            D3DKMT_HANDLE hAllocation,
     343                           PVBOXDXKMRESOURCE pKMResource,
    344344                           uint32 byteOffsetForArgs);
    345345int vgpu10DrawIndexedInstancedIndirect(PVBOXDX_DEVICE pDevice,
    346                                        D3DKMT_HANDLE hAllocation,
     346                                       PVBOXDXKMRESOURCE pKMResource,
    347347                                       uint32 byteOffsetForArgs);
    348348int vgpu10DrawInstancedIndirect(PVBOXDX_DEVICE pDevice,
    349                                 D3DKMT_HANDLE hAllocation,
     349                                PVBOXDXKMRESOURCE pKMResource,
    350350                                uint32 byteOffsetForArgs);
    351351int vgpu10CopyStructureCount(PVBOXDX_DEVICE pDevice,
    352352                             SVGA3dUAViewId srcUAViewId,
    353                              D3DKMT_HANDLE hDstBuffer,
     353                             PVBOXDXKMRESOURCE pDstKMResource,
    354354                             uint32 destByteOffset);
    355355int vgpu10ClearRenderTargetViewRegion(PVBOXDX_DEVICE pDevice,
     
    359359                                      uint32_t cRects);
    360360int vgpu10PresentBlt(PVBOXDX_DEVICE pDevice,
    361                      D3DKMT_HANDLE hSrcAllocation,
     361                     PVBOXDXKMRESOURCE pSrcKMResource,
    362362                     uint32 srcSubResource,
    363                      D3DKMT_HANDLE hDstAllocation,
     363                     PVBOXDXKMRESOURCE pDstKMResource,
    364364                     uint32 destSubResource,
    365365                     SVGA3dBox const &boxSrc,
     
    372372int vgpu10DefineVideoDecoderOutputView(PVBOXDX_DEVICE pDevice,
    373373                                       VBSVGA3dVideoDecoderOutputViewId videoDecoderOutputViewId,
    374                                        D3DKMT_HANDLE hAllocation,
     374                                       PVBOXDXKMRESOURCE pKMResource,
    375375                                       VBSVGA3dVDOVDesc const &desc);
    376376int vgpu10DefineVideoDecoder(PVBOXDX_DEVICE pDevice,
     
    384384                                    VBSVGA3dVideoDecoderId videoDecoderId,
    385385                                    uint32 bufferCount,
    386                                     D3DKMT_HANDLE const *pahAllocation,
     386                                    PVBOXDXKMRESOURCE const *papKMResources,
    387387                                    VBSVGA3dVideoDecoderBufferDesc const *paBufferDesc);
    388388int vgpu10VideoDecoderEndFrame(PVBOXDX_DEVICE pDevice,
     
    390390int vgpu10DefineVideoProcessorInputView(PVBOXDX_DEVICE pDevice,
    391391                                        VBSVGA3dVideoProcessorInputViewId videoProcessorInputViewId,
    392                                         D3DKMT_HANDLE hAllocation,
     392                                        PVBOXDXKMRESOURCE pKMResource,
    393393                                        VBSVGA3dVideoProcessorDesc const &contentDesc,
    394394                                        VBSVGA3dVPIVDesc const &desc);
    395395int vgpu10DefineVideoProcessorOutputView(PVBOXDX_DEVICE pDevice,
    396396                                         VBSVGA3dVideoProcessorOutputViewId videoProcessorOutputViewId,
    397                                          D3DKMT_HANDLE hAllocation,
     397                                         PVBOXDXKMRESOURCE pKMResource,
    398398                                         VBSVGA3dVideoProcessorDesc const &contentDesc,
    399399                                         VBSVGA3dVPOVDesc const &desc);
     
    509509int vgpu10GetVideoCapability(PVBOXDX_DEVICE pDevice,
    510510                             VBSVGA3dVideoCapability capability,
    511                              D3DKMT_HANDLE hAllocation,
     511                             PVBOXDXKMRESOURCE pKMResource,
    512512                             uint32 offsetInBytes,
    513513                             uint32 sizeInBytes,
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/dx/VBoxDXDDI.cpp

    r106582 r108880  
    55
    66/*
    7  * Copyright (C) 2020-2024 Oracle and/or its affiliates.
     7 * Copyright (C) 2020-2025 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    973973
    974974    /* Fetch allocation handles. */
    975     D3DKMT_HANDLE aAllocations[SVGA3D_DX_MAX_SOTARGETS];
     975    PVBOXDXKMRESOURCE apKMResources[SVGA3D_DX_MAX_SOTARGETS];
    976976    uint32_t aOffsets[SVGA3D_DX_MAX_SOTARGETS];
    977977    uint32_t aSizes[SVGA3D_DX_MAX_SOTARGETS];
     
    981981        {
    982982            VBOXDX_RESOURCE *pResource = (PVBOXDX_RESOURCE)phResource[i].pDrvPrivate;
    983             aAllocations[i] = vboxDXGetAllocation(pResource);
     983            apKMResources[i] = vboxDXGetKMResource(pResource);
    984984            aOffsets[i] = pOffsets[i];
    985             aSizes[i] = pResource ? pResource->AllocationDesc.cbAllocation : 0;
     985            aSizes[i] = apKMResources[i] ? apKMResources[i]->AllocationDesc.cbAllocation : 0;
    986986        }
    987987        else
    988988        {
    989             aAllocations[i] = 0;
     989            apKMResources[i] = 0;
    990990            aOffsets[i] = 0;
    991991            aSizes[i] = 0;
     
    993993    }
    994994
    995     vboxDXSoSetTargets(pDevice, NumTargets, aAllocations, aOffsets, aSizes);
     995    vboxDXSoSetTargets(pDevice, NumTargets, apKMResources, aOffsets, aSizes);
    996996}
    997997
     
    13581358
    13591359    pResource->hRTResource = hRTResource;
    1360     int rc = vboxDXInitResourceData(pResource, pCreateResource);
    1361     if (RT_SUCCESS(rc))
    1362         vboxDXCreateResource(pDevice, pResource, pCreateResource);
     1360    vboxDXCreateResource(pDevice, pResource, pCreateResource);
    13631361}
    13641362
     
    13881386        pCreateResource->ArraySize));
    13891387
    1390         D3D11DDIARG_CREATERESOURCE CreateResource;
    1391         CreateResource.pMipInfoList      = pCreateResource->pMipInfoList;
    1392         CreateResource.pInitialDataUP    = pCreateResource->pInitialDataUP;
    1393         CreateResource.ResourceDimension = pCreateResource->ResourceDimension;
    1394         CreateResource.Usage             = pCreateResource->Usage;
    1395         CreateResource.BindFlags         = pCreateResource->BindFlags;
    1396         CreateResource.MapFlags          = pCreateResource->MapFlags;
    1397         CreateResource.MiscFlags         = pCreateResource->MiscFlags;
    1398         CreateResource.Format            = pCreateResource->Format;
    1399         CreateResource.SampleDesc        = pCreateResource->SampleDesc;
    1400         CreateResource.MipLevels         = pCreateResource->MipLevels;
    1401         CreateResource.ArraySize         = pCreateResource->ArraySize;
    1402         CreateResource.pPrimaryDesc      = pCreateResource->pPrimaryDesc;
    1403         CreateResource.ByteStride        = 0;
    1404         CreateResource.DecoderBufferType = D3D11_1DDI_VIDEO_DECODER_BUFFER_UNKNOWN;
    1405         CreateResource.TextureLayout     = D3DWDDM2_0DDI_TL_UNDEFINED;
     1388    D3D11DDIARG_CREATERESOURCE CreateResource;
     1389    CreateResource.pMipInfoList      = pCreateResource->pMipInfoList;
     1390    CreateResource.pInitialDataUP    = pCreateResource->pInitialDataUP;
     1391    CreateResource.ResourceDimension = pCreateResource->ResourceDimension;
     1392    CreateResource.Usage             = pCreateResource->Usage;
     1393    CreateResource.BindFlags         = pCreateResource->BindFlags;
     1394    CreateResource.MapFlags          = pCreateResource->MapFlags;
     1395    CreateResource.MiscFlags         = pCreateResource->MiscFlags;
     1396    CreateResource.Format            = pCreateResource->Format;
     1397    CreateResource.SampleDesc        = pCreateResource->SampleDesc;
     1398    CreateResource.MipLevels         = pCreateResource->MipLevels;
     1399    CreateResource.ArraySize         = pCreateResource->ArraySize;
     1400    CreateResource.pPrimaryDesc      = pCreateResource->pPrimaryDesc;
     1401    CreateResource.ByteStride        = 0;
     1402    CreateResource.DecoderBufferType = D3D11_1DDI_VIDEO_DECODER_BUFFER_UNKNOWN;
     1403    CreateResource.TextureLayout     = D3DWDDM2_0DDI_TL_UNDEFINED;
    14061404
    14071405    pResource->hRTResource = hRTResource;
    1408     int rc = vboxDXInitResourceData(pResource, &CreateResource);
    1409     if (RT_SUCCESS(rc))
    1410         vboxDXCreateResource(pDevice, pResource, &CreateResource);
     1406    vboxDXCreateResource(pDevice, pResource, &CreateResource);
    14111407}
    14121408
     
    38673863    LogFlowFunc(("pDevice 0x%p, pResource 0x%p, subres %d", pDevice, pResource, pDisplayModeData->SubResourceIndex));
    38683864
    3869     AssertReturn(pResource->AllocationDesc.fPrimary && pDisplayModeData->SubResourceIndex == 0, E_INVALIDARG);
     3865    AssertReturn(pResource->pKMResource
     3866              && pResource->pKMResource->AllocationDesc.fPrimary
     3867              && pDisplayModeData->SubResourceIndex == 0, E_INVALIDARG);
    38703868
    38713869    D3DDDICB_SETDISPLAYMODE ddiSetDisplayMode;
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/dx/VBoxDXVideo.cpp

    r106061 r108880  
    55
    66/*
    7  * Copyright (C) 2023-2024 Oracle and/or its affiliates.
     7 * Copyright (C) 2023-2025 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    4242static void vboxDXDestroyVideoDeviceAllocation(PVBOXDX_DEVICE pDevice)
    4343{
    44     if (pDevice->VideoDevice.hAllocation)
    45     {
    46         D3DDDICB_DEALLOCATE ddiDeallocate;
    47         RT_ZERO(ddiDeallocate);
    48         ddiDeallocate.NumAllocations = 1;
    49         ddiDeallocate.HandleList     = &pDevice->VideoDevice.hAllocation;
    50 
    51         HRESULT hr = pDevice->pRTCallbacks->pfnDeallocateCb(pDevice->hRTDevice.handle, &ddiDeallocate);
    52         LogFlowFunc(("pfnDeallocateCb returned %d", hr));
    53         AssertStmt(SUCCEEDED(hr), vboxDXDeviceSetError(pDevice, hr));
    54 
    55         pDevice->VideoDevice.hAllocation = 0;
    56         pDevice->VideoDevice.cbAllocation = 0;
    57     }
     44    if (pDevice->VideoDevice.pKMResource)
     45    {
     46        RTListNodeRemove(&pDevice->VideoDevice.pKMResource->nodeResource);
     47        vboxDXDeallocateKMResource(pDevice, pDevice->VideoDevice.pKMResource);
     48        pDevice->VideoDevice.pKMResource = 0;
     49    }
     50}
     51
     52
     53static void videoDeviceAllocationDesc(VBOXDXALLOCATIONDESC *pDesc, void const *pvInitData)
     54{
     55    pDesc->enmAllocationType = VBOXDXALLOCATIONTYPE_CO; /* Context Object allocation. */
     56    pDesc->cbAllocation      = *(uint32_t *)pvInitData;
    5857}
    5958
     
    6160static bool vboxDXCreateVideoDeviceAllocation(PVBOXDX_DEVICE pDevice, uint32_t cbAllocation)
    6261{
    63     VBOXDXALLOCATIONDESC desc;
    64     RT_ZERO(desc);
    65     desc.enmAllocationType = VBOXDXALLOCATIONTYPE_CO; /* Context Object allocation. */
    66     desc.cbAllocation      = cbAllocation;
    67 
    68     D3DDDI_ALLOCATIONINFO2 ddiAllocationInfo;
    69     RT_ZERO(ddiAllocationInfo);
    70     ddiAllocationInfo.pPrivateDriverData    = &desc;
    71     ddiAllocationInfo.PrivateDriverDataSize = sizeof(desc);
    72 
    73     D3DDDICB_ALLOCATE ddiAllocate;
    74     RT_ZERO(ddiAllocate);
    75     ddiAllocate.NumAllocations   = 1;
    76     ddiAllocate.pAllocationInfo2 = &ddiAllocationInfo;
    77 
    78     HRESULT hr = pDevice->pRTCallbacks->pfnAllocateCb(pDevice->hRTDevice.handle, &ddiAllocate);
    79     LogFlowFunc(("pfnAllocateCb returned %d, hKMResource 0x%X, hAllocation 0x%X", hr, ddiAllocate.hKMResource, ddiAllocationInfo.hAllocation));
    80     AssertReturnStmt(SUCCEEDED(hr), vboxDXDeviceSetError(pDevice, hr), false);
    81 
    82     pDevice->VideoDevice.hAllocation = ddiAllocationInfo.hAllocation;
    83     pDevice->VideoDevice.cbAllocation = cbAllocation;
    84 
    85     D3DDDICB_LOCK ddiLock;
    86     RT_ZERO(ddiLock);
    87     ddiLock.hAllocation = ddiAllocationInfo.hAllocation;
    88     ddiLock.Flags.WriteOnly = 1;
    89     hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
    90     if (SUCCEEDED(hr))
    91     {
    92         memset(ddiLock.pData, 0, cbAllocation);
    93 
    94         D3DDDICB_UNLOCK ddiUnlock;
    95         ddiUnlock.NumAllocations = 1;
    96         ddiUnlock.phAllocations = &ddiAllocationInfo.hAllocation;
    97         hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    98     }
    99     AssertReturnStmt(SUCCEEDED(hr),
    100                      vboxDXDestroyVideoDeviceAllocation(pDevice); vboxDXDeviceSetError(pDevice, hr), false);
     62    pDevice->VideoDevice.pKMResource = vboxDXAllocateKMResource(pDevice, 0, videoDeviceAllocationDesc,
     63                                                                &cbAllocation, true);
     64    if (!pDevice->VideoDevice.pKMResource)
     65        return false;
     66
     67    RTListAppend(&pDevice->listResources, &pDevice->VideoDevice.pKMResource->nodeResource);
    10168    return true;
    10269}
     
    10572static bool vboxDXEnsureVideoDeviceAllocation(PVBOXDX_DEVICE pDevice)
    10673{
    107     if (!pDevice->VideoDevice.hAllocation)
     74    if (!pDevice->VideoDevice.pKMResource)
    10875        return vboxDXCreateVideoDeviceAllocation(pDevice, _64K);
    10976    return true;
     
    12087
    12188    uint32 const offsetInBytes = 0;
    122     uint32 const sizeInBytes = pDevice->VideoDevice.cbAllocation - offsetInBytes;
     89    uint32 const sizeInBytes = pDevice->VideoDevice.pKMResource->AllocationDesc.cbAllocation - offsetInBytes;
    12390    AssertReturnVoid(cbDataIn <= sizeInBytes - RT_UOFFSETOF(VBSVGA3dVideoCapabilityMobLayout, data));
    12491
     
    12794        D3DDDICB_LOCK ddiLock;
    12895        RT_ZERO(ddiLock);
    129         ddiLock.hAllocation = pDevice->VideoDevice.hAllocation;
     96        ddiLock.hAllocation = vboxDXGetAllocation(pDevice->VideoDevice.pKMResource);
    13097        ddiLock.Flags.ReadOnly = 1;
    13198        HRESULT hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
     
    137104            D3DDDICB_UNLOCK ddiUnlock;
    138105            ddiUnlock.NumAllocations = 1;
    139             ddiUnlock.phAllocations = &pDevice->VideoDevice.hAllocation;
     106            ddiUnlock.phAllocations = &ddiLock.hAllocation;
    140107            hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    141108        }
     
    144111
    145112    uint64_t const fenceValue = ASMAtomicIncU64(&pDevice->VideoDevice.u64MobFenceValue);
    146     vgpu10GetVideoCapability(pDevice, cap, pDevice->VideoDevice.hAllocation, offsetInBytes, sizeInBytes, fenceValue);
     113    vgpu10GetVideoCapability(pDevice, cap, pDevice->VideoDevice.pKMResource, offsetInBytes, sizeInBytes, fenceValue);
    147114    vboxDXDeviceFlushCommands(pDevice);
    148115
     
    155122        D3DDDICB_LOCK ddiLock;
    156123        RT_ZERO(ddiLock);
    157         ddiLock.hAllocation = pDevice->VideoDevice.hAllocation;
     124        ddiLock.hAllocation = vboxDXGetAllocation(pDevice->VideoDevice.pKMResource);
    158125        ddiLock.Flags.ReadOnly = 1;
    159126        HRESULT hr = pDevice->pRTCallbacks->pfnLockCb(pDevice->hRTDevice.handle, &ddiLock);
     
    181148            D3DDDICB_UNLOCK ddiUnlock;
    182149            ddiUnlock.NumAllocations = 1;
    183             ddiUnlock.phAllocations = &pDevice->VideoDevice.hAllocation;
     150            ddiUnlock.phAllocations = &ddiLock.hAllocation;
    184151            hr = pDevice->pRTCallbacks->pfnUnlockCb(pDevice->hRTDevice.handle, &ddiUnlock);
    185152        }
     
    498465
    499466    vgpu10DefineVideoDecoderOutputView(pDevice, pVideoDecoderOutputView->uVideoDecoderOutputViewId,
    500                                        vboxDXGetAllocation(pVideoDecoderOutputView->pResource),
     467                                       vboxDXGetKMResource(pVideoDecoderOutputView->pResource),
    501468                                       pVideoDecoderOutputView->svga.desc);
    502469
     
    555522                                        UINT BufferCount, D3D11_1DDI_VIDEO_DECODER_BUFFER_DESC const *pBufferDesc)
    556523{
    557     void *pvTmpBuffer = RTMemTmpAlloc(BufferCount * (sizeof(D3DKMT_HANDLE) + sizeof(VBSVGA3dVideoDecoderBufferDesc)));
     524    void *pvTmpBuffer = RTMemTmpAlloc(BufferCount * (sizeof(PVBOXDXKMRESOURCE) + sizeof(VBSVGA3dVideoDecoderBufferDesc)));
    558525    if (!pvTmpBuffer)
    559526        return E_OUTOFMEMORY;
    560527
    561     D3DKMT_HANDLE *pahAllocation = (D3DKMT_HANDLE *)pvTmpBuffer;
    562     VBSVGA3dVideoDecoderBufferDesc *paBD = (VBSVGA3dVideoDecoderBufferDesc *)((uint8_t *)pvTmpBuffer + BufferCount * sizeof(D3DKMT_HANDLE));
     528    PVBOXDXKMRESOURCE *papKMResource = (PVBOXDXKMRESOURCE *)pvTmpBuffer;
     529    VBSVGA3dVideoDecoderBufferDesc *paBD = (VBSVGA3dVideoDecoderBufferDesc *)((uint8_t *)pvTmpBuffer + BufferCount * sizeof(PVBOXDXKMRESOURCE));
    563530
    564531    for (UINT i = 0; i < BufferCount; ++i)
     
    567534
    568535        PVBOXDX_RESOURCE pBuffer = (PVBOXDX_RESOURCE)s->hResource.pDrvPrivate;
    569         pahAllocation[i] = vboxDXGetAllocation(pBuffer);
     536        papKMResource[i] = vboxDXGetKMResource(pBuffer);
    570537
    571538        VBSVGA3dVideoDecoderBufferDesc *d = &paBD[i];
     
    601568    }
    602569
    603     vgpu10VideoDecoderSubmitBuffers(pDevice, pVideoDecoder->uVideoDecoderId, BufferCount, pahAllocation, paBD);
     570    vgpu10VideoDecoderSubmitBuffers(pDevice, pVideoDecoder->uVideoDecoderId, BufferCount, papKMResource, paBD);
    604571    RTMemTmpFree(pvTmpBuffer);
    605572    return S_OK;
     
    635602
    636603    vgpu10DefineVideoProcessorInputView(pDevice, pVideoProcessorInputView->uVideoProcessorInputViewId,
    637                                         vboxDXGetAllocation(pVideoProcessorInputView->pResource),
     604                                        vboxDXGetKMResource(pVideoProcessorInputView->pResource),
    638605                                        pVideoProcessorInputView->svga.ContentDesc, *pDesc);
    639606
     
    670637
    671638    vgpu10DefineVideoProcessorOutputView(pDevice, pVideoProcessorOutputView->uVideoProcessorOutputViewId,
    672                                          vboxDXGetAllocation(pVideoProcessorOutputView->pResource),
     639                                         vboxDXGetKMResource(pVideoProcessorOutputView->pResource),
    673640                                         pVideoProcessorOutputView->svga.ContentDesc, *pDesc);
    674641
Note: See TracChangeset for help on using the changeset viewer.

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