Changeset 94242 in vbox for trunk/src/VBox
- Timestamp:
- Mar 15, 2022 10:52:56 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp
r94241 r94242 147 147 } u; 148 148 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; 153 166 154 167 /* Screen targets are created as shared surfaces. */ … … 1819 1832 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 1820 1833 td.MiscFlags = 0; 1821 hr = pDXDevice->pDevice->CreateTexture2D(&td, 0, &pBackendSurface-> pDynamicTexture);1834 hr = pDXDevice->pDevice->CreateTexture2D(&td, 0, &pBackendSurface->dynamic.pTexture2D); 1822 1835 Assert(SUCCEEDED(hr)); 1823 1836 } … … 1829 1842 td.BindFlags = 0; /* No flags allowed. */ 1830 1843 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); 1832 1845 Assert(SUCCEEDED(hr)); 1833 1846 } … … 1860 1873 1861 1874 /* Failure. */ 1862 D3D_RELEASE(pBackendSurface-> pStagingTexture);1863 D3D_RELEASE(pBackendSurface-> pDynamicTexture);1875 D3D_RELEASE(pBackendSurface->staging.pTexture2D); 1876 D3D_RELEASE(pBackendSurface->dynamic.pTexture2D); 1864 1877 D3D_RELEASE(pBackendSurface->u.pTexture2D); 1865 1878 RTMemFree(pBackendSurface); … … 1987 2000 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 1988 2001 td.MiscFlags = 0; 1989 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface-> pDynamicTexture);2002 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->dynamic.pTexture2D); 1990 2003 Assert(SUCCEEDED(hr)); 1991 2004 } … … 1997 2010 td.BindFlags = 0; /* No flags allowed. */ 1998 2011 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); 2000 2013 Assert(SUCCEEDED(hr)); 2001 2014 } … … 2055 2068 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 2056 2069 td.MiscFlags = 0; 2057 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface-> pDynamicTexture);2070 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->dynamic.pTexture2D); 2058 2071 Assert(SUCCEEDED(hr)); 2059 2072 } … … 2066 2079 td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; 2067 2080 td.MiscFlags = 0; 2068 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface-> pStagingTexture);2081 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->staging.pTexture2D); 2069 2082 Assert(SUCCEEDED(hr)); 2070 2083 } … … 2092 2105 else if (pSurface->surfaceFlags & SVGA3D_SURFACE_1D) 2093 2106 { 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 } 2096 2171 } 2097 2172 else … … 2130 2205 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 2131 2206 td.MiscFlags = 0; 2132 hr = pDXDevice->pDevice->CreateTexture3D(&td, paInitialData, &pBackendSurface-> pDynamicTexture3D);2207 hr = pDXDevice->pDevice->CreateTexture3D(&td, paInitialData, &pBackendSurface->dynamic.pTexture3D); 2133 2208 Assert(SUCCEEDED(hr)); 2134 2209 } … … 2141 2216 td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; 2142 2217 td.MiscFlags = 0; 2143 hr = pDXDevice->pDevice->CreateTexture3D(&td, paInitialData, &pBackendSurface-> pStagingTexture3D);2218 hr = pDXDevice->pDevice->CreateTexture3D(&td, paInitialData, &pBackendSurface->staging.pTexture3D); 2144 2219 Assert(SUCCEEDED(hr)); 2145 2220 } … … 2200 2275 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 2201 2276 td.MiscFlags = 0; 2202 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface-> pDynamicTexture);2277 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->dynamic.pTexture2D); 2203 2278 Assert(SUCCEEDED(hr)); 2204 2279 } … … 2211 2286 td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; 2212 2287 td.MiscFlags = 0; 2213 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface-> pStagingTexture);2288 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->staging.pTexture2D); 2214 2289 Assert(SUCCEEDED(hr)); 2215 2290 } … … 2260 2335 } 2261 2336 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); 2266 2340 RTMemFree(pBackendSurface); 2267 2341 return VERR_NO_MEMORY; … … 2989 3063 if (enmMapType == VMSVGA3D_SURFACE_MAP_READ) 2990 3064 { 2991 pMappedTexture = pBackendSurface-> pStagingTexture;3065 pMappedTexture = pBackendSurface->staging.pTexture2D; 2992 3066 2993 3067 /* 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); 2995 3069 } 2996 3070 else if (enmMapType == VMSVGA3D_SURFACE_MAP_WRITE) 2997 pMappedTexture = pBackendSurface-> pStagingTexture;3071 pMappedTexture = pBackendSurface->staging.pTexture2D; 2998 3072 else 2999 pMappedTexture = pBackendSurface-> pDynamicTexture;3073 pMappedTexture = pBackendSurface->dynamic.pTexture2D; 3000 3074 3001 3075 UINT const Subresource = 0; /* Screen target surfaces have only one subresource. */ … … 3018 3092 AssertFailedStmt(rc = VERR_NOT_SUPPORTED); 3019 3093 } 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 3021 3096 || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_CUBE 3022 3097 || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D) 3023 3098 { 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 3034 3099 dxSurfaceWait(pState, pSurface, pSurface->idAssociatedContext); 3035 3100 … … 3037 3102 if (enmMapType == VMSVGA3D_SURFACE_MAP_READ) 3038 3103 { 3039 pMappedResource = (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D) 3040 ? (ID3D11Resource *)pBackendSurface->pStagingTexture3D 3041 : (ID3D11Resource *)pBackendSurface->pStagingTexture; 3104 pMappedResource = pBackendSurface->staging.pResource; 3042 3105 3043 3106 /* Copy the texture content to the staging texture. … … 3065 3128 } 3066 3129 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; 3070 3131 else 3071 pMappedResource = (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D) 3072 ? (ID3D11Resource *)pBackendSurface->pDynamicTexture3D 3073 : (ID3D11Resource *)pBackendSurface->pDynamicTexture; 3132 pMappedResource = pBackendSurface->dynamic.pResource; 3074 3133 3075 3134 UINT const Subresource = 0; … … 3183 3242 ID3D11Texture2D *pMappedTexture; 3184 3243 if (pMap->enmMapType == VMSVGA3D_SURFACE_MAP_READ) 3185 pMappedTexture = pBackendSurface-> pStagingTexture;3244 pMappedTexture = pBackendSurface->staging.pTexture2D; 3186 3245 else if (pMap->enmMapType == VMSVGA3D_SURFACE_MAP_WRITE) 3187 pMappedTexture = pBackendSurface-> pStagingTexture;3246 pMappedTexture = pBackendSurface->staging.pTexture2D; 3188 3247 else 3189 pMappedTexture = pBackendSurface-> pDynamicTexture;3248 pMappedTexture = pBackendSurface->dynamic.pTexture2D; 3190 3249 3191 3250 UINT const Subresource = 0; /* Screen target surfaces have only one subresource. */ … … 3218 3277 } 3219 3278 } 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 3221 3281 || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_CUBE 3222 3282 || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D) … … 3224 3284 ID3D11Resource *pMappedResource; 3225 3285 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; 3229 3287 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; 3233 3289 else 3234 pMappedResource = (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D) 3235 ? (ID3D11Resource *)pBackendSurface->pDynamicTexture3D 3236 : (ID3D11Resource *)pBackendSurface->pDynamicTexture; 3290 pMappedResource = pBackendSurface->dynamic.pResource; 3237 3291 3238 3292 UINT const Subresource = 0; /* Staging or dynamic textures have one subresource. */ … … 4420 4474 } 4421 4475 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); 4440 4485 } 4441 4486 else if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER) … … 4627 4672 #endif 4628 4673 } 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 4630 4676 || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D) 4631 4677 {
Note:
See TracChangeset
for help on using the changeset viewer.