VirtualBox

Changeset 94242 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 15, 2022 10:52:56 AM (3 years ago)
Author:
vboxsync
Message:

Devices/Graphics: 1D textures; cleaned up usage of dynamic and staging resources: bugref:9830

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp

    r94241 r94242  
    147147    } u;
    148148
    149     ID3D11Texture2D    *pDynamicTexture;  /* For screen updates from memory. */ /** @todo One for all screens. */
    150     ID3D11Texture2D    *pStagingTexture;  /* For Reading the screen content. */ /** @todo One for all screens. */
    151     ID3D11Texture3D    *pDynamicTexture3D;  /* For screen updates from memory. */ /** @todo One for all screens. */
    152     ID3D11Texture3D    *pStagingTexture3D;  /* For Reading the screen content. */ /** @todo One for all screens. */
     149    /* For updates from memory. */
     150    union /** @todo One per format. */
     151    {
     152        ID3D11Resource     *pResource;
     153        ID3D11Texture1D    *pTexture1D;
     154        ID3D11Texture2D    *pTexture2D;
     155        ID3D11Texture3D    *pTexture3D;
     156    } dynamic;
     157
     158    /* For reading the texture content. */
     159    union /** @todo One per format. */
     160    {
     161        ID3D11Resource     *pResource;
     162        ID3D11Texture1D    *pTexture1D;
     163        ID3D11Texture2D    *pTexture2D;
     164        ID3D11Texture3D    *pTexture3D;
     165    } staging;
    153166
    154167    /* Screen targets are created as shared surfaces. */
     
    18191832        td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    18201833        td.MiscFlags      = 0;
    1821         hr = pDXDevice->pDevice->CreateTexture2D(&td, 0, &pBackendSurface->pDynamicTexture);
     1834        hr = pDXDevice->pDevice->CreateTexture2D(&td, 0, &pBackendSurface->dynamic.pTexture2D);
    18221835        Assert(SUCCEEDED(hr));
    18231836    }
     
    18291842        td.BindFlags      = 0; /* No flags allowed. */
    18301843        td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
    1831         hr = pDXDevice->pDevice->CreateTexture2D(&td, 0, &pBackendSurface->pStagingTexture);
     1844        hr = pDXDevice->pDevice->CreateTexture2D(&td, 0, &pBackendSurface->staging.pTexture2D);
    18321845        Assert(SUCCEEDED(hr));
    18331846    }
     
    18601873
    18611874    /* Failure. */
    1862     D3D_RELEASE(pBackendSurface->pStagingTexture);
    1863     D3D_RELEASE(pBackendSurface->pDynamicTexture);
     1875    D3D_RELEASE(pBackendSurface->staging.pTexture2D);
     1876    D3D_RELEASE(pBackendSurface->dynamic.pTexture2D);
    18641877    D3D_RELEASE(pBackendSurface->u.pTexture2D);
    18651878    RTMemFree(pBackendSurface);
     
    19872000            td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    19882001            td.MiscFlags      = 0;
    1989             hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pDynamicTexture);
     2002            hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->dynamic.pTexture2D);
    19902003            Assert(SUCCEEDED(hr));
    19912004        }
     
    19972010            td.BindFlags      = 0; /* No flags allowed. */
    19982011            td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
    1999             hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pStagingTexture);
     2012            hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->staging.pTexture2D);
    20002013            Assert(SUCCEEDED(hr));
    20012014        }
     
    20552068            td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    20562069            td.MiscFlags      = 0;
    2057             hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pDynamicTexture);
     2070            hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->dynamic.pTexture2D);
    20582071            Assert(SUCCEEDED(hr));
    20592072        }
     
    20662079            td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
    20672080            td.MiscFlags      = 0;
    2068             hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pStagingTexture);
     2081            hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->staging.pTexture2D);
    20692082            Assert(SUCCEEDED(hr));
    20702083        }
     
    20922105    else if (pSurface->surfaceFlags & SVGA3D_SURFACE_1D)
    20932106    {
    2094         AssertFailed(); /** @todo implement */
    2095         hr = E_FAIL;
     2107        /*
     2108         * 1D texture.
     2109         */
     2110        Assert(pSurface->cFaces == 1);
     2111
     2112        D3D11_TEXTURE1D_DESC td;
     2113        RT_ZERO(td);
     2114        td.Width              = cWidth;
     2115        td.MipLevels          = numMipLevels;
     2116        td.ArraySize          = pSurface->surfaceDesc.numArrayElements;
     2117        td.Format             = dxgiFormat;
     2118        td.Usage              = D3D11_USAGE_DEFAULT;
     2119        td.BindFlags          = dxBindFlags(pSurface->surfaceFlags);
     2120        td.CPUAccessFlags     = 0;
     2121        td.MiscFlags          = MiscFlags; /** @todo */
     2122        if (   numMipLevels > 1
     2123            && (td.BindFlags & (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET)) == (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET))
     2124            td.MiscFlags     |= D3D11_RESOURCE_MISC_GENERATE_MIPS; /* Required for GenMips. */
     2125
     2126        hr = pDXDevice->pDevice->CreateTexture1D(&td, paInitialData, &pBackendSurface->u.pTexture1D);
     2127        Assert(SUCCEEDED(hr));
     2128        if (SUCCEEDED(hr))
     2129        {
     2130            /* Map-able texture. */
     2131            td.MipLevels      = 1; /* Must be for D3D11_USAGE_DYNAMIC. */
     2132            td.ArraySize      = 1; /* Must be for D3D11_USAGE_DYNAMIC. */
     2133            td.Usage          = D3D11_USAGE_DYNAMIC;
     2134            td.BindFlags      = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */
     2135            td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
     2136            td.MiscFlags      = 0;
     2137            hr = pDXDevice->pDevice->CreateTexture1D(&td, paInitialData, &pBackendSurface->dynamic.pTexture1D);
     2138            Assert(SUCCEEDED(hr));
     2139        }
     2140
     2141        if (SUCCEEDED(hr))
     2142        {
     2143            /* Staging texture. */
     2144            td.Usage          = D3D11_USAGE_STAGING;
     2145            td.BindFlags      = 0; /* No flags allowed. */
     2146            td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
     2147            td.MiscFlags      = 0;
     2148            hr = pDXDevice->pDevice->CreateTexture1D(&td, paInitialData, &pBackendSurface->staging.pTexture1D);
     2149            Assert(SUCCEEDED(hr));
     2150        }
     2151
     2152        if (   SUCCEEDED(hr)
     2153            && MiscFlags == D3D11_RESOURCE_MISC_SHARED)
     2154        {
     2155            /* Get the shared handle. */
     2156            IDXGIResource *pDxgiResource = NULL;
     2157            hr = pBackendSurface->u.pTexture1D->QueryInterface(__uuidof(IDXGIResource), (void**)&pDxgiResource);
     2158            Assert(SUCCEEDED(hr));
     2159            if (SUCCEEDED(hr))
     2160            {
     2161                hr = pDxgiResource->GetSharedHandle(&pBackendSurface->SharedHandle);
     2162                Assert(SUCCEEDED(hr));
     2163                D3D_RELEASE(pDxgiResource);
     2164            }
     2165        }
     2166
     2167        if (SUCCEEDED(hr))
     2168        {
     2169            pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE_1D;
     2170        }
    20962171    }
    20972172    else
     
    21302205                td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    21312206                td.MiscFlags      = 0;
    2132                 hr = pDXDevice->pDevice->CreateTexture3D(&td, paInitialData, &pBackendSurface->pDynamicTexture3D);
     2207                hr = pDXDevice->pDevice->CreateTexture3D(&td, paInitialData, &pBackendSurface->dynamic.pTexture3D);
    21332208                Assert(SUCCEEDED(hr));
    21342209            }
     
    21412216                td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
    21422217                td.MiscFlags      = 0;
    2143                 hr = pDXDevice->pDevice->CreateTexture3D(&td, paInitialData, &pBackendSurface->pStagingTexture3D);
     2218                hr = pDXDevice->pDevice->CreateTexture3D(&td, paInitialData, &pBackendSurface->staging.pTexture3D);
    21442219                Assert(SUCCEEDED(hr));
    21452220            }
     
    22002275                td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    22012276                td.MiscFlags      = 0;
    2202                 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pDynamicTexture);
     2277                hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->dynamic.pTexture2D);
    22032278                Assert(SUCCEEDED(hr));
    22042279            }
     
    22112286                td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
    22122287                td.MiscFlags      = 0;
    2213                 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pStagingTexture);
     2288                hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->staging.pTexture2D);
    22142289                Assert(SUCCEEDED(hr));
    22152290            }
     
    22602335    }
    22612336
    2262     /** @todo different enmResType Failure. */
    2263     D3D_RELEASE(pBackendSurface->pStagingTexture);
    2264     D3D_RELEASE(pBackendSurface->pDynamicTexture);
    2265     D3D_RELEASE(pBackendSurface->u.pTexture2D);
     2337    D3D_RELEASE(pBackendSurface->staging.pResource);
     2338    D3D_RELEASE(pBackendSurface->dynamic.pResource);
     2339    D3D_RELEASE(pBackendSurface->u.pResource);
    22662340    RTMemFree(pBackendSurface);
    22672341    return VERR_NO_MEMORY;
     
    29893063        if (enmMapType == VMSVGA3D_SURFACE_MAP_READ)
    29903064        {
    2991             pMappedTexture = pBackendSurface->pStagingTexture;
     3065            pMappedTexture = pBackendSurface->staging.pTexture2D;
    29923066
    29933067            /* Copy the texture content to the staging texture. */
    2994             pDevice->pImmediateContext->CopyResource(pBackendSurface->pStagingTexture, pBackendSurface->u.pTexture2D);
     3068            pDevice->pImmediateContext->CopyResource(pBackendSurface->staging.pTexture2D, pBackendSurface->u.pTexture2D);
    29953069        }
    29963070        else if (enmMapType == VMSVGA3D_SURFACE_MAP_WRITE)
    2997             pMappedTexture = pBackendSurface->pStagingTexture;
     3071            pMappedTexture = pBackendSurface->staging.pTexture2D;
    29983072        else
    2999             pMappedTexture = pBackendSurface->pDynamicTexture;
     3073            pMappedTexture = pBackendSurface->dynamic.pTexture2D;
    30003074
    30013075        UINT const Subresource = 0; /* Screen target surfaces have only one subresource. */
     
    30183092            AssertFailedStmt(rc = VERR_NOT_SUPPORTED);
    30193093    }
    3020     else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
     3094    else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_1D
     3095             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
    30213096             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_CUBE
    30223097             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    30233098    {
    3024 //Assert(pImage->face == 0 && pImage->mipmap == 0);
    3025 if (!(   (pBackendSurface->pStagingTexture && pBackendSurface->pDynamicTexture)
    3026       || (pBackendSurface->pStagingTexture3D && pBackendSurface->pDynamicTexture3D)
    3027      )
    3028    )
    3029 {
    3030     AssertFailed();
    3031     return VERR_NOT_IMPLEMENTED;
    3032 }
    3033 
    30343099        dxSurfaceWait(pState, pSurface, pSurface->idAssociatedContext);
    30353100
     
    30373102        if (enmMapType == VMSVGA3D_SURFACE_MAP_READ)
    30383103        {
    3039             pMappedResource = (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    3040                             ? (ID3D11Resource *)pBackendSurface->pStagingTexture3D
    3041                             : (ID3D11Resource *)pBackendSurface->pStagingTexture;
     3104            pMappedResource = pBackendSurface->staging.pResource;
    30423105
    30433106            /* Copy the texture content to the staging texture.
     
    30653128        }
    30663129        else if (enmMapType == VMSVGA3D_SURFACE_MAP_WRITE)
    3067             pMappedResource = (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    3068                             ? (ID3D11Resource *)pBackendSurface->pStagingTexture3D
    3069                             : (ID3D11Resource *)pBackendSurface->pStagingTexture;
     3130            pMappedResource = pBackendSurface->staging.pResource;
    30703131        else
    3071             pMappedResource = (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    3072                             ? (ID3D11Resource *)pBackendSurface->pDynamicTexture3D
    3073                             : (ID3D11Resource *)pBackendSurface->pDynamicTexture;
     3132            pMappedResource = pBackendSurface->dynamic.pResource;
    30743133
    30753134        UINT const Subresource = 0;
     
    31833242        ID3D11Texture2D *pMappedTexture;
    31843243        if (pMap->enmMapType == VMSVGA3D_SURFACE_MAP_READ)
    3185             pMappedTexture = pBackendSurface->pStagingTexture;
     3244            pMappedTexture = pBackendSurface->staging.pTexture2D;
    31863245        else if (pMap->enmMapType == VMSVGA3D_SURFACE_MAP_WRITE)
    3187             pMappedTexture = pBackendSurface->pStagingTexture;
     3246            pMappedTexture = pBackendSurface->staging.pTexture2D;
    31883247        else
    3189             pMappedTexture = pBackendSurface->pDynamicTexture;
     3248            pMappedTexture = pBackendSurface->dynamic.pTexture2D;
    31903249
    31913250        UINT const Subresource = 0; /* Screen target surfaces have only one subresource. */
     
    32183277        }
    32193278    }
    3220     else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
     3279    else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_1D
     3280             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
    32213281             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_CUBE
    32223282             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
     
    32243284        ID3D11Resource *pMappedResource;
    32253285        if (pMap->enmMapType == VMSVGA3D_SURFACE_MAP_READ)
    3226             pMappedResource = (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    3227                             ? (ID3D11Resource *)pBackendSurface->pStagingTexture3D
    3228                             : (ID3D11Resource *)pBackendSurface->pStagingTexture;
     3286            pMappedResource = pBackendSurface->staging.pResource;
    32293287        else if (pMap->enmMapType == VMSVGA3D_SURFACE_MAP_WRITE)
    3230             pMappedResource = (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    3231                             ? (ID3D11Resource *)pBackendSurface->pStagingTexture3D
    3232                             : (ID3D11Resource *)pBackendSurface->pStagingTexture;
     3288            pMappedResource = pBackendSurface->staging.pResource;
    32333289        else
    3234             pMappedResource = (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    3235                             ? (ID3D11Resource *)pBackendSurface->pDynamicTexture3D
    3236                             : (ID3D11Resource *)pBackendSurface->pDynamicTexture;
     3290            pMappedResource = pBackendSurface->dynamic.pResource;
    32373291
    32383292        UINT const Subresource = 0; /* Staging or dynamic textures have one subresource. */
     
    44204474    }
    44214475
    4422     if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_SCREEN_TARGET)
    4423     {
    4424         D3D_RELEASE(pBackendSurface->pStagingTexture);
    4425         D3D_RELEASE(pBackendSurface->pDynamicTexture);
    4426         D3D_RELEASE(pBackendSurface->u.pTexture2D);
    4427     }
    4428     else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
    4429              || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_CUBE)
    4430     {
    4431         D3D_RELEASE(pBackendSurface->pStagingTexture);
    4432         D3D_RELEASE(pBackendSurface->pDynamicTexture);
    4433         D3D_RELEASE(pBackendSurface->u.pTexture2D);
    4434     }
    4435     else if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    4436     {
    4437         D3D_RELEASE(pBackendSurface->pStagingTexture3D);
    4438         D3D_RELEASE(pBackendSurface->pDynamicTexture3D);
    4439         D3D_RELEASE(pBackendSurface->u.pTexture3D);
     4476    if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_SCREEN_TARGET
     4477        || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_1D
     4478        || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
     4479        || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_CUBE
     4480        || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
     4481    {
     4482        D3D_RELEASE(pBackendSurface->staging.pResource);
     4483        D3D_RELEASE(pBackendSurface->dynamic.pResource);
     4484        D3D_RELEASE(pBackendSurface->u.pResource);
    44404485    }
    44414486    else if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER)
     
    46274672#endif
    46284673    }
    4629     else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
     4674    else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_1D
     4675             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
    46304676             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    46314677    {
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