Changeset 94241 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Mar 15, 2022 10:11:36 AM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 150497
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp
r94232 r94241 1939 1939 * Create D3D11 texture object. 1940 1940 */ 1941 D3D11_SUBRESOURCE_DATA *paInitialData = NULL; 1942 if (pSurface->paMipmapLevels[0].pSurfaceData) 1943 { 1944 /* Can happen for a non GBO surface or if GBO texture was updated prior to creation of the hardware resource. */ 1945 uint32_t const cSubresource = numMipLevels * pSurface->surfaceDesc.numArrayElements; 1946 paInitialData = (D3D11_SUBRESOURCE_DATA *)RTMemAlloc(cSubresource * sizeof(D3D11_SUBRESOURCE_DATA)); 1947 AssertPtrReturn(paInitialData, VERR_NO_MEMORY); 1948 1949 for (uint32_t i = 0; i < cSubresource; ++i) 1950 { 1951 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i]; 1952 D3D11_SUBRESOURCE_DATA *p = &paInitialData[i]; 1953 p->pSysMem = pMipmapLevel->pSurfaceData; 1954 p->SysMemPitch = pMipmapLevel->cbSurfacePitch; 1955 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane; 1956 } 1957 } 1958 1941 1959 HRESULT hr = S_OK; 1942 1960 if (pSurface->surfaceFlags & SVGA3D_SURFACE_SCREENTARGET) … … 1945 1963 * Create the texture in backend device and open for the specified context. 1946 1964 */ 1947 D3D11_SUBRESOURCE_DATA *paInitialData = NULL;1948 D3D11_SUBRESOURCE_DATA aInitialData[SVGA3D_MAX_MIP_LEVELS];1949 if (pSurface->paMipmapLevels[0].pSurfaceData)1950 {1951 /** @todo Can happen for a non GBO surface or if GBO texture was updated prior to creation if the hardware resource. Test this. */1952 for (uint32_t i = 0; i < numMipLevels; ++i)1953 {1954 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i];1955 D3D11_SUBRESOURCE_DATA *p = &aInitialData[i];1956 p->pSysMem = pMipmapLevel->pSurfaceData;1957 p->SysMemPitch = pMipmapLevel->cbSurfacePitch;1958 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane;1959 }1960 paInitialData = &aInitialData[0];1961 }1962 1963 1965 D3D11_TEXTURE2D_DESC td; 1964 1966 RT_ZERO(td); … … 2024 2026 Assert(cDepth == 1); 2025 2027 //DEBUG_BREAKPOINT_TEST(); 2026 D3D11_SUBRESOURCE_DATA *paInitialData = NULL;2027 D3D11_SUBRESOURCE_DATA aInitialData[6 * SVGA3D_MAX_MIP_LEVELS];2028 if (pSurface->paMipmapLevels[0].pSurfaceData)2029 {2030 /** @todo Can happen for a non GBO surface or if GBO texture was updated prior to creation if the hardware resource. Test this. */2031 /** @todo for (i = 0; i < pSurface->cFaces * numMipLevels; ++i) */2032 for (uint32_t iArray = 0; iArray < pSurface->surfaceDesc.numArrayElements; ++iArray)2033 {2034 for (uint32_t i = 0; i < numMipLevels; ++i)2035 {2036 uint32_t const iSubresource = vmsvga3dCalcSubresource(i, iArray, numMipLevels);2037 2038 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[iSubresource];2039 D3D11_SUBRESOURCE_DATA *p = &aInitialData[iSubresource];2040 p->pSysMem = pMipmapLevel->pSurfaceData;2041 p->SysMemPitch = pMipmapLevel->cbSurfacePitch;2042 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane;2043 }2044 }2045 paInitialData = &aInitialData[0];2046 }2047 2028 2048 2029 D3D11_TEXTURE2D_DESC td; … … 2122 2103 */ 2123 2104 Assert(pSurface->cFaces == 1); 2124 2125 D3D11_SUBRESOURCE_DATA *paInitialData = NULL; 2126 D3D11_SUBRESOURCE_DATA aInitialData[SVGA3D_MAX_MIP_LEVELS]; 2127 if (pSurface->paMipmapLevels[0].pSurfaceData) 2128 { 2129 /** @todo Can happen for a non GBO surface or if GBO texture was updated prior to creation if the hardware resource. Test this. */ 2130 for (uint32_t i = 0; i < numMipLevels; ++i) 2131 { 2132 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i]; 2133 D3D11_SUBRESOURCE_DATA *p = &aInitialData[i]; 2134 p->pSysMem = pMipmapLevel->pSurfaceData; 2135 p->SysMemPitch = pMipmapLevel->cbSurfacePitch; 2136 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane; 2137 } 2138 paInitialData = &aInitialData[0]; 2139 } 2105 Assert(pSurface->surfaceDesc.numArrayElements == 1); 2140 2106 2141 2107 D3D11_TEXTURE3D_DESC td; … … 2205 2171 */ 2206 2172 Assert(pSurface->cFaces == 1); 2207 2208 D3D11_SUBRESOURCE_DATA *paInitialData = NULL;2209 D3D11_SUBRESOURCE_DATA aInitialData[SVGA3D_MAX_MIP_LEVELS];2210 if (pSurface->paMipmapLevels[0].pSurfaceData)2211 {2212 /** @todo Can happen for a non GBO surface or if GBO texture was updated prior to creation if the hardware resource. Test this. */2213 for (uint32_t i = 0; i < numMipLevels; ++i)2214 {2215 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i];2216 D3D11_SUBRESOURCE_DATA *p = &aInitialData[i];2217 p->pSysMem = pMipmapLevel->pSurfaceData;2218 p->SysMemPitch = pMipmapLevel->cbSurfacePitch;2219 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane;2220 }2221 paInitialData = &aInitialData[0];2222 }2223 2173 2224 2174 D3D11_TEXTURE2D_DESC td; … … 2289 2239 Assert(hr == S_OK); 2290 2240 2241 RTMemFree(paInitialData); 2242 2291 2243 if (pSurface->autogenFilter != SVGA3D_TEX_FILTER_NONE) 2292 2244 { … … 2305 2257 else 2306 2258 pSurface->idAssociatedContext = pDXContext->cid; 2307 return VINF_SUCCESS;2308 }2309 2310 /** @todo different enmResType Failure. */2311 D3D_RELEASE(pBackendSurface->pStagingTexture);2312 D3D_RELEASE(pBackendSurface->pDynamicTexture);2313 D3D_RELEASE(pBackendSurface->u.pTexture2D);2314 RTMemFree(pBackendSurface);2315 return VERR_NO_MEMORY;2316 }2317 2318 2319 /** @todo This is practically the same code as vmsvga3dBackSurfaceCreateTexture */2320 static int vmsvga3dBackSurfaceCreateDepthStencilTexture(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface)2321 {2322 DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);2323 AssertReturn(pDXDevice->pDevice, VERR_INVALID_STATE);2324 2325 if (pSurface->pBackendSurface != NULL)2326 {2327 AssertFailed(); /** @todo Should the function not be used like that? */2328 vmsvga3dBackSurfaceDestroy(pThisCC, pSurface);2329 }2330 2331 PVMSVGA3DBACKENDSURFACE pBackendSurface;2332 int rc = dxBackendSurfaceAlloc(&pBackendSurface);2333 AssertRCReturn(rc, rc);2334 2335 uint32_t const cWidth = pSurface->paMipmapLevels[0].mipmapSize.width;2336 uint32_t const cHeight = pSurface->paMipmapLevels[0].mipmapSize.height;2337 uint32_t const cDepth = pSurface->paMipmapLevels[0].mipmapSize.depth;2338 uint32_t const numMipLevels = pSurface->cLevels;2339 2340 DXGI_FORMAT dxgiFormat = vmsvgaDXSurfaceFormat2Dxgi(pSurface->format);2341 AssertReturn(dxgiFormat != DXGI_FORMAT_UNKNOWN, E_FAIL);2342 2343 /*2344 * Create D3D11 texture object.2345 */2346 HRESULT hr = S_OK;2347 if (pSurface->surfaceFlags & SVGA3D_SURFACE_CUBEMAP)2348 {2349 /*2350 * CubeMap texture.2351 */2352 Assert(pSurface->cFaces == 6);2353 Assert(cWidth == cHeight);2354 Assert(cDepth == 1);2355 Assert(numMipLevels == 1);2356 //DEBUG_BREAKPOINT_TEST();2357 D3D11_SUBRESOURCE_DATA *paInitialData = NULL;2358 D3D11_SUBRESOURCE_DATA aInitialData[6 * SVGA3D_MAX_MIP_LEVELS];2359 if (pSurface->paMipmapLevels[0].pSurfaceData)2360 {2361 /** @todo Can happen for a non GBO surface or if GBO texture was updated prior to creation if the hardware resource. Test this. */2362 /** @todo for (i = 0; i < pSurface->cFaces * numMipLevels; ++i) */2363 for (uint32_t iArray = 0; iArray < pSurface->surfaceDesc.numArrayElements; ++iArray)2364 {2365 for (uint32_t i = 0; i < numMipLevels; ++i)2366 {2367 uint32_t const iSubresource = vmsvga3dCalcSubresource(i, iArray, numMipLevels);2368 2369 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[iSubresource];2370 D3D11_SUBRESOURCE_DATA *p = &aInitialData[iSubresource];2371 p->pSysMem = pMipmapLevel->pSurfaceData;2372 p->SysMemPitch = pMipmapLevel->cbSurfacePitch;2373 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane;2374 }2375 }2376 paInitialData = &aInitialData[0];2377 }2378 2379 D3D11_TEXTURE2D_DESC td;2380 RT_ZERO(td);2381 td.Width = cWidth;2382 td.Height = cHeight;2383 td.MipLevels = 1;2384 td.ArraySize = pSurface->surfaceDesc.numArrayElements;2385 td.Format = dxgiFormat;2386 td.SampleDesc.Count = 1;2387 td.SampleDesc.Quality = 0;2388 td.Usage = D3D11_USAGE_DEFAULT;2389 td.BindFlags = dxBindFlags(pSurface->surfaceFlags);2390 td.CPUAccessFlags = 0;2391 td.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;2392 2393 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->u.pTexture2D);2394 Assert(SUCCEEDED(hr));2395 if (SUCCEEDED(hr))2396 {2397 /* Map-able texture. */2398 td.MipLevels = 1; /* Must be for D3D11_USAGE_DYNAMIC. */2399 td.ArraySize = 1; /* Must be for D3D11_USAGE_DYNAMIC. */2400 td.Usage = D3D11_USAGE_DYNAMIC;2401 td.BindFlags = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */2402 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;2403 td.MiscFlags = 0;2404 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pDynamicTexture);2405 Assert(SUCCEEDED(hr));2406 }2407 2408 if (SUCCEEDED(hr))2409 {2410 /* Staging texture. */2411 td.Usage = D3D11_USAGE_STAGING;2412 td.BindFlags = 0; /* No flags allowed. */2413 td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;2414 td.MiscFlags = 0;2415 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pStagingTexture);2416 Assert(SUCCEEDED(hr));2417 }2418 2419 if (SUCCEEDED(hr))2420 {2421 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE_CUBE;2422 }2423 }2424 else if (pSurface->surfaceFlags & SVGA3D_SURFACE_1D)2425 {2426 AssertFailed(); /** @todo implement */2427 hr = E_FAIL;2428 }2429 else2430 {2431 if (cDepth > 1)2432 {2433 AssertFailed(); /** @todo implement */2434 hr = E_FAIL;2435 }2436 else2437 {2438 /*2439 * 2D texture.2440 */2441 Assert(pSurface->cFaces == 1);2442 Assert(numMipLevels == 1);2443 2444 D3D11_SUBRESOURCE_DATA *paInitialData = NULL;2445 D3D11_SUBRESOURCE_DATA aInitialData[SVGA3D_MAX_MIP_LEVELS];2446 if (pSurface->paMipmapLevels[0].pSurfaceData)2447 {2448 /** @todo Can happen for a non GBO surface or if GBO texture was updated prior to creation if the hardware resource. Test this. */2449 for (uint32_t i = 0; i < numMipLevels; ++i)2450 {2451 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i];2452 D3D11_SUBRESOURCE_DATA *p = &aInitialData[i];2453 p->pSysMem = pMipmapLevel->pSurfaceData;2454 p->SysMemPitch = pMipmapLevel->cbSurfacePitch;2455 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane;2456 }2457 paInitialData = &aInitialData[0];2458 }2459 2460 D3D11_TEXTURE2D_DESC td;2461 RT_ZERO(td);2462 td.Width = cWidth;2463 td.Height = cHeight;2464 td.MipLevels = 1;2465 td.ArraySize = pSurface->surfaceDesc.numArrayElements;2466 td.Format = dxgiFormat;2467 td.SampleDesc.Count = 1;2468 td.SampleDesc.Quality = 0;2469 td.Usage = D3D11_USAGE_DEFAULT;2470 td.BindFlags = dxBindFlags(pSurface->surfaceFlags);2471 td.CPUAccessFlags = 0;2472 td.MiscFlags = 0;2473 2474 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->u.pTexture2D);2475 Assert(SUCCEEDED(hr));2476 if (SUCCEEDED(hr))2477 {2478 /* Map-able texture. */2479 td.MipLevels = 1; /* Must be for D3D11_USAGE_DYNAMIC. */2480 td.ArraySize = 1; /* Must be for D3D11_USAGE_DYNAMIC. */2481 td.Usage = D3D11_USAGE_DYNAMIC;2482 td.BindFlags = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */2483 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;2484 td.MiscFlags = 0;2485 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pDynamicTexture);2486 Assert(SUCCEEDED(hr));2487 }2488 2489 if (SUCCEEDED(hr))2490 {2491 /* Staging texture. */2492 td.Usage = D3D11_USAGE_STAGING;2493 td.BindFlags = 0; /* No flags allowed. */2494 td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;2495 td.MiscFlags = 0;2496 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pStagingTexture);2497 Assert(SUCCEEDED(hr));2498 }2499 2500 if (SUCCEEDED(hr))2501 {2502 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE_2D;2503 }2504 }2505 }2506 2507 if (SUCCEEDED(hr))2508 {2509 /*2510 * Success.2511 */2512 pBackendSurface->enmDxgiFormat = dxgiFormat;2513 pSurface->pBackendSurface = pBackendSurface;2514 pSurface->idAssociatedContext = pDXContext->cid;2515 2259 return VINF_SUCCESS; 2516 2260 } … … 6710 6454 { 6711 6455 /* Create the actual texture. */ 6712 rc = vmsvga3dBackSurfaceCreate DepthStencilTexture(pThisCC, pDXContext, pSurface);6456 rc = vmsvga3dBackSurfaceCreateTexture(pThisCC, pDXContext, pSurface); 6713 6457 AssertRCReturn(rc, rc); 6714 6458 }
Note:
See TracChangeset
for help on using the changeset viewer.