VirtualBox

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


Ignore:
Timestamp:
Dec 2, 2017 9:27:46 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119382
Message:

Devices/Graphics: VMSVGA: do not recreate D3D vertex declaration if it has not changed.

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

Legend:

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

    r69859 r69905  
    831831    /* Occlusion query. */
    832832    VMSVGA3DQUERY occlusion;
     833
     834#ifdef VMSVGA3D_DIRECT3D
     835    /* State which is currently applied to the D3D device. It is recreated as needed and not saved.
     836     * The purpose is to remember the currently applied state and do not re-apply it if it has not changed.
     837     * Unnecessary state changes are very bad for performance.
     838     */
     839    struct
     840    {
     841        /* Vertex declaration. */
     842        IDirect3DVertexDeclaration9 *pVertexDecl;
     843        uint32_t cVertexElements;
     844        D3DVERTEXELEMENT9 aVertexElements[SVGA3D_MAX_VERTEX_ARRAYS + 1];
     845    } d3dState;
     846#endif
    833847} VMSVGA3DCONTEXT;
    834848/** Pointer to a VMSVGA3d context. */
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp

    r69904 r69905  
    28932893        Log(("vmsvga3dContextDestroy id %x\n", cid));
    28942894
     2895        /* Cleanup the device runtime state. */
     2896        D3D_RELEASE(pContext->d3dState.pVertexDecl);
     2897
    28952898        /* Check for all surfaces that are associated with this context to remove all dependencies */
    28962899        for (uint32_t sid = 0; sid < pState->cSurfaces; sid++)
     
    31653168            }
    31663169#endif /* #ifdef VMSVGA3D_DIRECT3D9_RESET */
     3170
     3171            /* Cleanup the device runtime state. */
     3172            D3D_RELEASE(pContext->d3dState.pVertexDecl);
     3173
    31673174            memset(&cs, 0, sizeof(cs));
    31683175            cs.cx = pThis->svga.uWidth;
     
    58105817    memcpy(&aVertexElements[numVertexDecls], &sVertexEnd, sizeof(sVertexEnd));
    58115818
    5812     /* Create and set the vertex declaration. */
    5813     IDirect3DVertexDeclaration9 *pVertexDeclD3D = NULL;
    5814     hr = pContext->pDevice->CreateVertexDeclaration(&aVertexElements[0], &pVertexDeclD3D);
    5815     AssertMsgReturn(hr == D3D_OK, ("CreateVertexDeclaration failed with %x\n", hr), VERR_INTERNAL_ERROR);
    5816 
    5817     hr = pContext->pDevice->SetVertexDeclaration(pVertexDeclD3D);
    5818     AssertMsgReturnStmt(hr == D3D_OK, ("SetVertexDeclaration failed with %x\n", hr),
    5819                         D3D_RELEASE(pVertexDeclD3D), VERR_INTERNAL_ERROR);
     5819    /* Check if this context already has the same vertex declaration. */
     5820    if (   pContext->d3dState.pVertexDecl
     5821        && pContext->d3dState.cVertexElements == numVertexDecls + 1
     5822        && memcmp(pContext->d3dState.aVertexElements,
     5823                  aVertexElements,
     5824                  pContext->d3dState.cVertexElements * sizeof(aVertexElements[0])) == 0)
     5825    {
     5826       /* Same. */
     5827    }
     5828    else
     5829    {
     5830        D3D_RELEASE(pContext->d3dState.pVertexDecl);
     5831
     5832        pContext->d3dState.cVertexElements = numVertexDecls + 1;
     5833        memcpy(pContext->d3dState.aVertexElements,
     5834               aVertexElements,
     5835               pContext->d3dState.cVertexElements * sizeof(aVertexElements[0]));
     5836
     5837        /* Create and set the vertex declaration. */
     5838        hr = pContext->pDevice->CreateVertexDeclaration(&aVertexElements[0], &pContext->d3dState.pVertexDecl);
     5839        AssertMsgReturn(hr == D3D_OK, ("CreateVertexDeclaration failed with %x\n", hr), VERR_INTERNAL_ERROR);
     5840
     5841        hr = pContext->pDevice->SetVertexDeclaration(pContext->d3dState.pVertexDecl);
     5842        AssertMsgReturnStmt(hr == D3D_OK, ("SetVertexDeclaration failed with %x\n", hr),
     5843                            D3D_RELEASE(pContext->d3dState.pVertexDecl),
     5844                            VERR_INTERNAL_ERROR);
     5845    }
    58205846
    58215847    /* Begin a scene before rendering anything. */
    58225848    hr = pContext->pDevice->BeginScene();
    5823     AssertMsgReturnStmt(hr == D3D_OK, ("BeginScene failed with %x\n", hr),
    5824                         D3D_RELEASE(pVertexDeclD3D), VERR_INTERNAL_ERROR);
     5849    AssertMsgReturn(hr == D3D_OK, ("BeginScene failed with %x\n", hr), VERR_INTERNAL_ERROR);
    58255850
    58265851    /* Now draw the primitives. */
     
    59195944    }
    59205945
    5921     /* Release vertex declaration, end the scene and do some cleanup regardless of the rc. */
    5922     D3D_RELEASE(pVertexDeclD3D);
    5923 
     5946    /* End the scene and do some cleanup regardless of the rc. */
    59245947    hr = pContext->pDevice->EndScene();
    59255948    AssertMsgReturn(hr == D3D_OK, ("EndScene failed with %x\n", hr), VERR_INTERNAL_ERROR);
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