VirtualBox

Changeset 94101 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Mar 6, 2022 5:43:23 PM (3 years ago)
Author:
vboxsync
Message:

Devices/Graphics: initial code for single device mode, enabled for non Windows hosts: bugref:9830

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

Legend:

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

    r93635 r94101  
    143143
    144144# ifdef VBOX_WITH_VMSVGA3D
     145#  ifdef VMSVGA3D_DX
     146    /** DX context of the currently processed command buffer */
     147    uint32_t                 idDXContextCurrent;
     148    uint32_t                 u32Reserved;
     149#  endif
    145150    VMSVGA3DBACKENDFUNCS3D  *pFuncs3D;
    146151    VMSVGA3DBACKENDFUNCSVGPU9 *pFuncsVGPU9;
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA.cpp

    r93944 r94101  
    34423442    PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
    34433443
     3444# ifdef VBOX_WITH_VMSVGA3D
     3445#  ifdef VMSVGA3D_DX
     3446    /* Commands submitted for the SVGA3D_INVALID_ID context do not affect pipeline. So ignore them. */
     3447    if (idDXContext != SVGA3D_INVALID_ID)
     3448    {
     3449        if (pSvgaR3State->idDXContextCurrent != idDXContext)
     3450        {
     3451            LogFlow(("DXCTX: buffer %d->%d\n", pSvgaR3State->idDXContextCurrent, idDXContext));
     3452            vmsvga3dDXSwitchContext(pThisCC, idDXContext);
     3453            pSvgaR3State->idDXContextCurrent = idDXContext;
     3454        }
     3455    }
     3456#  endif
     3457# endif
     3458
    34443459    uint32_t RT_UNTRUSTED_VOLATILE_GUEST * const pFIFO = pThisCC->svga.pau32FIFO;
    34453460
     
    58125827
    58135828    RTListInit(&pSVGAState->MOBLRUList);
     5829# ifdef VBOX_WITH_VMSVGA3D
     5830#  ifdef VMSVGA3D_DX
     5831    pSVGAState->idDXContextCurrent = SVGA3D_INVALID_ID;
     5832#  endif
     5833# endif
    58145834    return rc;
    58155835}
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx.cpp

    r94063 r94101  
    5454    /* Copy the host structure back to the guest memory. */
    5555    memcpy(pSvgaDXContext, &pDXContext->svgaDXContext, sizeof(*pSvgaDXContext));
     56
     57    return rc;
     58}
     59
     60
     61int vmsvga3dDXSwitchContext(PVGASTATECC pThisCC, uint32_t cidNew)
     62{
     63    int rc;
     64    PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
     65    AssertReturn(pSvgaR3State->pFuncsDX && pSvgaR3State->pFuncsDX->pfnDXSwitchContext, VERR_INVALID_STATE);
     66    PVMSVGA3DSTATE p3dState = pThisCC->svga.p3dState;
     67    AssertReturn(p3dState, VERR_INVALID_STATE);
     68
     69    PVMSVGA3DDXCONTEXT pDXContextNew;
     70    rc = vmsvga3dDXContextFromCid(p3dState, cidNew, &pDXContextNew);
     71    AssertRCReturn(rc, rc);
     72
     73    /* Notify the host backend that context is about to be switched. */
     74    rc = pSvgaR3State->pFuncsDX->pfnDXSwitchContext(pThisCC, pDXContextNew);
     75    if (rc == VINF_NOT_IMPLEMENTED || RT_FAILURE(rc))
     76        return rc;
     77
     78    /** @todo Keep track of changes in the pipeline and apply only modified state. */
     79    #define DX_STATE_VS                0x00000001
     80    #define DX_STATE_PS                0x00000002
     81    #define DX_STATE_SAMPLERS          0x00000004
     82    #define DX_STATE_INPUTLAYOUT       0x00000008
     83    uint32_t u32TrackedState = 0
     84        | DX_STATE_VS
     85        | DX_STATE_PS
     86        | DX_STATE_SAMPLERS
     87        | DX_STATE_INPUTLAYOUT
     88        ;
     89
     90    if (u32TrackedState & DX_STATE_VS)
     91    {
     92        u32TrackedState &= ~DX_STATE_VS;
     93
     94        SVGA3dShaderType const shaderType = SVGA3D_SHADERTYPE_VS;
     95
     96        uint32_t const idxShaderState = shaderType - SVGA3D_SHADERTYPE_MIN;
     97        SVGA3dShaderId shaderId = pDXContextNew->svgaDXContext.shaderState[idxShaderState].shaderId;
     98
     99        /** @todo Same code as in DXSetShader, move to a static function with type and id as parms. */
     100        PVMSVGA3DSHADER pShader;
     101        if (shaderId != SVGA_ID_INVALID)
     102        {
     103            SVGACOTableDXShaderEntry *pEntry = &pDXContextNew->cot.paShader[shaderId];
     104            ASSERT_GUEST_RETURN(pEntry->type == shaderType, VERR_INVALID_PARAMETER);
     105            RT_UNTRUSTED_VALIDATED_FENCE();
     106
     107            pShader = &pDXContextNew->paShader[shaderId];
     108        }
     109        else
     110            pShader = NULL;
     111
     112        rc = pSvgaR3State->pFuncsDX->pfnDXSetShader(pThisCC, pDXContextNew, shaderType, pShader);
     113        AssertRC(rc);
     114    }
     115
     116    if (u32TrackedState & DX_STATE_PS)
     117    {
     118        u32TrackedState &= ~DX_STATE_PS;
     119
     120        SVGA3dShaderType const shaderType = SVGA3D_SHADERTYPE_PS;
     121
     122        uint32_t const idxShaderState = shaderType - SVGA3D_SHADERTYPE_MIN;
     123        SVGA3dShaderId shaderId = pDXContextNew->svgaDXContext.shaderState[idxShaderState].shaderId;
     124
     125        /** @todo Same code as in DXSetShader, move to a static function with type and id as parms. */
     126        PVMSVGA3DSHADER pShader;
     127        if (shaderId != SVGA_ID_INVALID)
     128        {
     129            SVGACOTableDXShaderEntry *pEntry = &pDXContextNew->cot.paShader[shaderId];
     130            ASSERT_GUEST_RETURN(pEntry->type == shaderType, VERR_INVALID_PARAMETER);
     131            RT_UNTRUSTED_VALIDATED_FENCE();
     132
     133            pShader = &pDXContextNew->paShader[shaderId];
     134        }
     135        else
     136            pShader = NULL;
     137
     138        rc = pSvgaR3State->pFuncsDX->pfnDXSetShader(pThisCC, pDXContextNew, shaderType, pShader);
     139        AssertRC(rc);
     140    }
     141
     142    if (u32TrackedState & DX_STATE_SAMPLERS)
     143    {
     144        u32TrackedState &= ~DX_STATE_SAMPLERS;
     145
     146        for (int i = SVGA3D_SHADERTYPE_MIN; i < SVGA3D_SHADERTYPE_DX10_MAX; ++i) /** SVGA3D_SHADERTYPE_MAX */
     147        {
     148            SVGA3dShaderType const shaderType = (SVGA3dShaderType)i;
     149            uint32_t const idxShaderState = shaderType - SVGA3D_SHADERTYPE_MIN;
     150
     151            uint32_t startSampler = 0;
     152            uint32_t cSamplerId = SVGA3D_DX_MAX_SAMPLERS;
     153            SVGA3dSamplerId *paSamplerId = &pDXContextNew->svgaDXContext.shaderState[idxShaderState].samplers[0];
     154
     155            rc = pSvgaR3State->pFuncsDX->pfnDXSetSamplers(pThisCC, pDXContextNew, startSampler, shaderType, cSamplerId, paSamplerId);
     156            AssertRC(rc);
     157        }
     158    }
     159
     160
     161    if (u32TrackedState & DX_STATE_INPUTLAYOUT)
     162    {
     163        u32TrackedState &= ~DX_STATE_INPUTLAYOUT;
     164
     165        SVGA3dElementLayoutId const elementLayoutId = pDXContextNew->svgaDXContext.inputAssembly.layoutId;
     166
     167        rc = pSvgaR3State->pFuncsDX->pfnDXSetInputLayout(pThisCC, pDXContextNew, elementLayoutId);
     168        AssertRC(rc);
     169    }
     170
     171    Assert(u32TrackedState == 0);
    56172
    57173    return rc;
     
    263379    ASSERT_GUEST_RETURN(   pCmd->shaderId < pDXContext->cot.cShader
    264380                        || pCmd->shaderId == SVGA_ID_INVALID, VERR_INVALID_PARAMETER);
    265     RT_UNTRUSTED_VALIDATED_FENCE();
     381    ASSERT_GUEST_RETURN(pCmd->type >= SVGA3D_SHADERTYPE_MIN && pCmd->type < SVGA3D_SHADERTYPE_MAX, VERR_INVALID_PARAMETER);
     382    RT_UNTRUSTED_VALIDATED_FENCE();
     383
     384    uint32_t const idxShaderState = pCmd->type - SVGA3D_SHADERTYPE_MIN;
     385    pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId = pCmd->shaderId;
    266386
    267387    PVMSVGA3DSHADER pShader;
     
    298418    ASSERT_GUEST_RETURN(pCmd->type >= SVGA3D_SHADERTYPE_MIN && pCmd->type < SVGA3D_SHADERTYPE_MAX, VERR_INVALID_PARAMETER);
    299419    ASSERT_GUEST_RETURN(pDXContext->cot.paSampler, VERR_INVALID_STATE);
     420    RT_UNTRUSTED_VALIDATED_FENCE();
     421
     422    uint32_t const idxShaderState = pCmd->type - SVGA3D_SHADERTYPE_MIN;
    300423    for (uint32_t i = 0; i < cSamplerId; ++i)
    301424    {
     
    303426        ASSERT_GUEST_RETURN(   samplerId < pDXContext->cot.cSampler
    304427                            || samplerId == SVGA_ID_INVALID, VERR_INVALID_PARAMETER);
     428        pDXContext->svgaDXContext.shaderState[idxShaderState].samplers[pCmd->startSampler + i] = samplerId;
    305429    }
    306430    RT_UNTRUSTED_VALIDATED_FENCE();
     
    483607    ASSERT_GUEST_RETURN(elementLayoutId < pDXContext->cot.cElementLayout, VERR_INVALID_PARAMETER);
    484608    RT_UNTRUSTED_VALIDATED_FENCE();
     609
     610    pDXContext->svgaDXContext.inputAssembly.layoutId = elementLayoutId;
    485611
    486612    rc = pSvgaR3State->pFuncsDX->pfnDXSetInputLayout(pThisCC, pDXContext, elementLayoutId);
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp

    r94063 r94101  
    5050# define VBOX_D3D11_LIBRARY_NAME "VBoxDxVk"
    5151#endif
     52
     53//#define DX_FORCE_SINGLE_DEVICE
    5254
    5355/* This is not available on non Windows hosts. */
     
    263265    PFN_D3D_DISASSEMBLE        pfnD3DDisassemble;
    264266
    265     /** @todo This device will be used for all rendering for "single DX device" mode. */
    266267    DXDEVICE                   dxDevice;               /* Device for the VMSVGA3D context independent operation. */
     268
     269    bool                       fSingleDevice;          /* Whether to use one DX device for all guest contexts. */
     270
     271    /** @todo Here a set of functions which do different job in single and multiple device modes. */
    267272} VMSVGA3DBACKEND;
    268273
     
    787792    int rc = VINF_SUCCESS;
    788793
     794    if (pBackend->fSingleDevice && pBackend->dxDevice.pDevice)
     795    {
     796        pDevice->pDevice = pBackend->dxDevice.pDevice;
     797        pDevice->pDevice->AddRef();
     798
     799        pDevice->pImmediateContext = pBackend->dxDevice.pImmediateContext;
     800        pDevice->pImmediateContext->AddRef();
     801
     802        pDevice->pDxgiFactory = pBackend->dxDevice.pDxgiFactory;
     803        pDevice->pDxgiFactory->AddRef();
     804
     805        pDevice->FeatureLevel = pBackend->dxDevice.FeatureLevel;
     806
     807        pDevice->pStagingBuffer = 0;
     808        pDevice->cbStagingBuffer = 0;
     809
     810        return rc;
     811    }
     812
    789813    IDXGIAdapter *pAdapter = NULL; /* Default adapter. */
    790814    static D3D_FEATURE_LEVEL const s_aFeatureLevels[] =
     
    9881012    if (cid != DX_CID_BACKEND)
    9891013    {
     1014        if (pState->pBackend->fSingleDevice)
     1015            return &pState->pBackend->dxDevice;
     1016
    9901017        VMSVGA3DDXCONTEXT *pDXContext;
    9911018        int rc = vmsvga3dDXContextFromCid(pState, cid, &pDXContext);
     
    10031030static DXDEVICE *dxDeviceFromContext(PVMSVGA3DSTATE p3dState, VMSVGA3DDXCONTEXT *pDXContext)
    10041031{
    1005     if (pDXContext)
     1032    if (pDXContext && !p3dState->pBackend->fSingleDevice)
    10061033        return &pDXContext->pBackendDXContext->dxDevice;
    10071034
     
    10361063static int dxContextWait(uint32_t cidDrawing, PVMSVGA3DSTATE pState)
    10371064{
     1065    if (pState->pBackend->fSingleDevice)
     1066      return VINF_SUCCESS;
     1067
    10381068    /* Flush cidDrawing context and issue a query. */
    10391069    DXDEVICE *pDXDevice = dxDeviceFromCid(cidDrawing, pState);
     
    10471077static int dxSurfaceWait(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface, uint32_t cidRequesting)
    10481078{
     1079    if (pState->pBackend->fSingleDevice)
     1080        return VINF_SUCCESS;
     1081
    10491082    VMSVGA3DBACKENDSURFACE *pBackendSurface = pSurface->pBackendSurface;
    10501083    if (!pBackendSurface)
     
    10761109
    10771110    uint32_t const cidRequesting = pDXContext ? pDXContext->cid : DX_CID_BACKEND;
    1078     if (cidRequesting == pSurface->idAssociatedContext)
     1111    if (cidRequesting == pSurface->idAssociatedContext || pState->pBackend->fSingleDevice)
    10791112        pResource = pBackendSurface->u.pResource;
    10801113    else
     
    18321865static DXDEVICE *dxSurfaceDevice(PVMSVGA3DSTATE p3dState, PVMSVGA3DSURFACE pSurface, PVMSVGA3DDXCONTEXT pDXContext, UINT *pMiscFlags)
    18331866{
     1867    if (p3dState->pBackend->fSingleDevice)
     1868    {
     1869        *pMiscFlags = 0;
     1870        return &p3dState->pBackend->dxDevice;
     1871    }
     1872
    18341873    if (dxIsSurfaceShareable(pSurface))
    18351874    {
     
    22202259        pBackendSurface->enmDxgiFormat = dxgiFormat;
    22212260        pSurface->pBackendSurface = pBackendSurface;
    2222         if (RT_BOOL(MiscFlags & D3D11_RESOURCE_MISC_SHARED))
     2261        if (p3dState->pBackend->fSingleDevice || RT_BOOL(MiscFlags & D3D11_RESOURCE_MISC_SHARED))
    22232262            pSurface->idAssociatedContext = DX_CID_BACKEND;
    22242263        else
     
    28062845        Log6Func(("Load D3DDisassemble: %Rrc\n", rc2));
    28072846    }
     2847
     2848#if !defined(RT_OS_WINDOWS) || defined(DX_FORCE_SINGLE_DEVICE)
     2849    pBackend->fSingleDevice = true;
     2850#endif
     2851
     2852    LogRelMax(1, ("VMSVGA: Single DX device mode: %s\n", pBackend->fSingleDevice ? "enabled" : "disabled"));
     2853
    28082854//DEBUG_BREAKPOINT_TEST();
    28092855    return rc;
     
    42034249        {
    42044250            /* Create the target if it can be used as a device context shared resource (render or screen target). */
    4205             if (dxIsSurfaceShareable(pDstSurface))
     4251            if (pBackend->fSingleDevice || dxIsSurfaceShareable(pDstSurface))
    42064252            {
    42074253                rc = vmsvga3dBackSurfaceCreateTexture(pThisCC, NULL, pDstSurface);
     
    50915137
    50925138
     5139static DECLCALLBACK(int) vmsvga3dBackDXSwitchContext(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContextNew)
     5140{
     5141    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
     5142    if (!pBackend->fSingleDevice)
     5143        return VINF_NOT_IMPLEMENTED; /* Not required. */
     5144
     5145    /* The new context state will be applied by the generic DX code. */
     5146    RT_NOREF(pDXContextNew);
     5147    return VINF_SUCCESS;
     5148}
     5149
     5150
    50935151static DECLCALLBACK(int) vmsvga3dBackDXReadbackContext(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)
    50945152{
     
    52285286        Assert(pDXShader->pShader);
    52295287        Assert(pDXShader->enmShaderType >= SVGA3D_SHADERTYPE_MIN && pDXShader->enmShaderType < SVGA3D_SHADERTYPE_MAX);
    5230         uint32_t const idxShaderState = pDXShader->enmShaderType - SVGA3D_SHADERTYPE_MIN;
    5231         pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId = pShader->id;
    52325288    }
    52335289    else
     
    52475303    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    52485304
    5249     uint32_t const idxShaderState = type - SVGA3D_SHADERTYPE_MIN;
    52505305    ID3D11SamplerState *papSamplerState[SVGA3D_DX_MAX_SAMPLERS];
    52515306    for (uint32_t i = 0; i < cSamplerId; ++i)
     
    52595314        else
    52605315            papSamplerState[i] = NULL;
    5261 
    5262         pDXContext->svgaDXContext.shaderState[idxShaderState].samplers[startSampler + i] = samplerId;
    52635316    }
    52645317
     
    57225775    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    57235776
    5724     pDXContext->svgaDXContext.inputAssembly.layoutId = elementLayoutId;
    5725 
    5726     DXELEMENTLAYOUT *pDXElementLayout = &pDXContext->pBackendDXContext->paElementLayout[elementLayoutId];
    5727     if (!pDXElementLayout->pElementLayout)
    5728     {
    5729         uint32_t const idxShaderState = SVGA3D_SHADERTYPE_VS - SVGA3D_SHADERTYPE_MIN;
    5730         uint32_t const shid = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId;
    5731         AssertReturnStmt(shid < pDXContext->pBackendDXContext->cShader,
    5732                          LogRelMax(16, ("VMSVGA: DX shader is not set in DXSetInputLayout: shid = 0x%x\n", shid)),
    5733                          VERR_INVALID_STATE);
    5734         DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[shid];
    5735         AssertReturnStmt(pDXShader->pvDXBC,
    5736                          LogRelMax(16, ("VMSVGA: DX shader bytecode is not available in DXSetInputLayout: shid = %u\n", shid)),
    5737                          VERR_INVALID_STATE);
    5738         HRESULT hr = pDevice->pDevice->CreateInputLayout(pDXElementLayout->aElementDesc,
    5739                                                          pDXElementLayout->cElementDesc,
    5740                                                          pDXShader->pvDXBC,
    5741                                                          pDXShader->cbDXBC,
    5742                                                          &pDXElementLayout->pElementLayout);
    5743         AssertReturn(SUCCEEDED(hr), VERR_NO_MEMORY);
    5744     }
    5745 
    5746     pDevice->pImmediateContext->IASetInputLayout(pDXElementLayout->pElementLayout);
     5777    ID3D11InputLayout *pInputLayout = NULL;
     5778    if (elementLayoutId != SVGA3D_INVALID_ID)
     5779    {
     5780        DXELEMENTLAYOUT *pDXElementLayout = &pDXContext->pBackendDXContext->paElementLayout[elementLayoutId];
     5781        if (!pDXElementLayout->pElementLayout)
     5782        {
     5783            uint32_t const idxShaderState = SVGA3D_SHADERTYPE_VS - SVGA3D_SHADERTYPE_MIN;
     5784            uint32_t const shid = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId;
     5785            AssertReturnStmt(shid < pDXContext->pBackendDXContext->cShader,
     5786                             LogRelMax(16, ("VMSVGA: DX shader is not set in DXSetInputLayout: shid = 0x%x\n", shid)),
     5787                             VERR_INVALID_STATE);
     5788            DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[shid];
     5789            AssertReturnStmt(pDXShader->pvDXBC,
     5790                             LogRelMax(16, ("VMSVGA: DX shader bytecode is not available in DXSetInputLayout: shid = %u\n", shid)),
     5791                             VERR_INVALID_STATE);
     5792            HRESULT hr = pDevice->pDevice->CreateInputLayout(pDXElementLayout->aElementDesc,
     5793                                                             pDXElementLayout->cElementDesc,
     5794                                                             pDXShader->pvDXBC,
     5795                                                             pDXShader->cbDXBC,
     5796                                                             &pDXElementLayout->pElementLayout);
     5797            AssertReturn(SUCCEEDED(hr), VERR_NO_MEMORY);
     5798        }
     5799
     5800        pInputLayout = pDXElementLayout->pElementLayout;
     5801    }
     5802
     5803    pDevice->pImmediateContext->IASetInputLayout(pInputLayout);
    57475804    return VINF_SUCCESS;
    57485805}
     
    77487805                p->pfnDXDestroyContext            = vmsvga3dBackDXDestroyContext;
    77497806                p->pfnDXBindContext               = vmsvga3dBackDXBindContext;
     7807                p->pfnDXSwitchContext             = vmsvga3dBackDXSwitchContext;
    77507808                p->pfnDXReadbackContext           = vmsvga3dBackDXReadbackContext;
    77517809                p->pfnDXInvalidateContext         = vmsvga3dBackDXInvalidateContext;
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.h

    r94063 r94101  
    396396    DECLCALLBACKMEMBER(int, pfnDXDestroyContext,            (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext));
    397397    DECLCALLBACKMEMBER(int, pfnDXBindContext,               (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext));
     398    DECLCALLBACKMEMBER(int, pfnDXSwitchContext,             (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContextNew));
    398399    DECLCALLBACKMEMBER(int, pfnDXReadbackContext,           (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext));
    399400    DECLCALLBACKMEMBER(int, pfnDXInvalidateContext,         (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext));
     
    520521/* Helpers. */
    521522int vmsvga3dDXUnbindContext(PVGASTATECC pThisCC, uint32_t cid, SVGADXContextMobFormat *pSvgaDXContext);
     523int vmsvga3dDXSwitchContext(PVGASTATECC pThisCC, uint32_t cidNew);
    522524
    523525/* Command handlers. */
Note: See TracChangeset for help on using the changeset viewer.

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