Changeset 81360 in vbox
- Timestamp:
- Oct 18, 2019 3:58:52 PM (5 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h
r77114 r81360 607 607 AVLU32TREE pSharedObjectTree; 608 608 bool fStencilAsTexture; 609 D3DFORMAT d3dfmtRequested; 610 union 611 { 612 IDirect3DTexture9 *pTexture; 613 IDirect3DCubeTexture9 *pCubeTexture; 614 IDirect3DVolumeTexture9 *pVolumeTexture; 615 } emulated; 609 616 #endif 610 617 } VMSVGA3DSURFACE; … … 957 964 bool fSupportedSurfaceINTZ; 958 965 bool fSupportedSurfaceNULL; 966 bool fSupportedFormatUYVY : 1; 967 bool fSupportedFormatYUY2 : 1; 968 bool fSupportedFormatA8B8G8R8 : 1; 959 969 # endif 960 970 /** Window Thread. */ … … 1265 1275 const char *pszPath, const char *pszNamePrefix, const char *pszNameSuffix); 1266 1276 1277 #ifdef VMSVGA3D_DIRECT3D 1278 #define D3D_RELEASE(ptr) do { \ 1279 if (ptr) \ 1280 { \ 1281 (ptr)->Release(); \ 1282 (ptr) = 0; \ 1283 } \ 1284 } while (0) 1285 1286 HRESULT D3D9UpdateTexture(PVMSVGA3DCONTEXT pContext, 1287 PVMSVGA3DSURFACE pSurface); 1288 HRESULT D3D9GetRenderTargetData(PVMSVGA3DCONTEXT pContext, 1289 PVMSVGA3DSURFACE pSurface, 1290 uint32_t uFace, 1291 uint32_t uMipmap); 1292 HRESULT D3D9GetSurfaceLevel(PVMSVGA3DSURFACE pSurface, 1293 uint32_t uFace, 1294 uint32_t uMipmap, 1295 bool fBounce, 1296 IDirect3DSurface9 **ppD3DSurface); 1297 D3DFORMAT D3D9GetActualFormat(PVMSVGA3DSTATE pState, 1298 D3DFORMAT d3dfmt); 1299 bool D3D9CheckDeviceFormat(IDirect3D9 *pD3D9, 1300 DWORD Usage, 1301 D3DRESOURCETYPE RType, 1302 D3DFORMAT CheckFormat); 1303 #endif 1304 1267 1305 #endif /* !VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_internal_h */ 1268 1306 -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp
r81291 r81360 159 159 *********************************************************************************************************************************/ 160 160 static void vmsvgaDumpD3DCaps(D3DCAPS9 *pCaps, D3DADAPTER_IDENTIFIER9 const *pai9); 161 162 163 #define D3D_RELEASE(ptr) do { \164 if (ptr) \165 { \166 (ptr)->Release(); \167 (ptr) = 0; \168 } \169 } while (0)170 161 171 162 … … 228 219 vmsvgaDumpD3DCaps(&pState->caps, &ai9); 229 220 230 /* Check if INTZ is supported. */ 231 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT, 232 D3DDEVTYPE_HAL, 233 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */ 234 0, 235 D3DRTYPE_TEXTURE, 236 FOURCC_INTZ); 237 if (hr != D3D_OK) 221 if (!D3D9CheckDeviceFormat(pState->pD3D9, 0, D3DRTYPE_TEXTURE, FOURCC_INTZ)) 238 222 { 239 223 /* INTZ support is essential to support depth surfaces used as textures. */ … … 243 227 pState->fSupportedSurfaceINTZ = true; 244 228 245 /* Check if NULL is supported. */ 246 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT, 247 D3DDEVTYPE_HAL, 248 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */ 249 D3DUSAGE_RENDERTARGET, 250 D3DRTYPE_SURFACE, 251 FOURCC_NULL); 252 if (hr != D3D_OK) 229 if (!D3D9CheckDeviceFormat(pState->pD3D9, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, FOURCC_NULL)) 253 230 { 254 231 /* NULL is a dummy surface which can be used as a render target to save memory. */ … … 258 235 pState->fSupportedSurfaceNULL = true; 259 236 260 261 /* Check if DX9 depth stencil textures are supported */ 262 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT, 263 D3DDEVTYPE_HAL, 264 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */ 265 D3DUSAGE_DEPTHSTENCIL, 266 D3DRTYPE_TEXTURE, 267 D3DFMT_D16); 268 if (hr != D3D_OK) 237 /* Check if DX9 depth stencil textures are supported */ 238 if (!D3D9CheckDeviceFormat(pState->pD3D9, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_D16)) 269 239 { 270 240 LogRel(("VMSVGA: texture format D3DFMT_D16 not supported\n")); 271 241 } 272 242 273 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT, 274 D3DDEVTYPE_HAL, 275 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */ 276 D3DUSAGE_DEPTHSTENCIL, 277 D3DRTYPE_TEXTURE, 278 D3DFMT_D24X8); 279 if (hr != D3D_OK) 243 if (!D3D9CheckDeviceFormat(pState->pD3D9, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_D24X8)) 280 244 { 281 245 LogRel(("VMSVGA: texture format D3DFMT_D24X8 not supported\n")); 282 246 } 283 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT, 284 D3DDEVTYPE_HAL, 285 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */ 286 D3DUSAGE_DEPTHSTENCIL, 287 D3DRTYPE_TEXTURE, 288 D3DFMT_D24S8); 289 if (hr != D3D_OK) 247 248 if (!D3D9CheckDeviceFormat(pState->pD3D9, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_D24S8)) 290 249 { 291 250 LogRel(("VMSVGA: texture format D3DFMT_D24S8 not supported\n")); 292 251 } 252 253 /* Check some formats must be emulated. */ 254 if (D3D9CheckDeviceFormat(pState->pD3D9, 0, D3DRTYPE_TEXTURE, D3DFMT_UYVY)) 255 { 256 /* Native UYVY support has better performance. */ 257 LogRel(("VMSVGA: texture format D3DFMT_UYVY supported\n")); 258 pState->fSupportedFormatUYVY = true; 259 } 260 261 if (D3D9CheckDeviceFormat(pState->pD3D9, 0, D3DRTYPE_TEXTURE, D3DFMT_YUY2)) 262 { 263 /* Native YUY2 support has better performance. */ 264 LogRel(("VMSVGA: texture format D3DFMT_YUY2 supported\n")); 265 pState->fSupportedFormatYUY2 = true; 266 } 267 268 if (D3D9CheckDeviceFormat(pState->pD3D9, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A8B8G8R8)) 269 { 270 /* Native A8B8G8R8 support is good for OpenGL application in the guest. */ 271 LogRel(("VMSVGA: texture format D3DFMT_A8B8G8R8 supported\n")); 272 pState->fSupportedFormatA8B8G8R8 = true; 273 } 274 293 275 return VINF_SUCCESS; 294 276 } … … 406 388 | SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET; 407 389 break; 408 390 /* These formats can't be used as textures on AMD drivers (Intel works). 391 * Still report them as textures to the guest and emulate them in the device. 392 */ 393 case SVGA3D_DEVCAP_SURFACEFMT_UYVY: 394 case SVGA3D_DEVCAP_SURFACEFMT_YUY2: 395 result |= SVGA3DFORMAT_OP_TEXTURE; 396 break; 409 397 } 410 398 Log(("CAPS: %s =\n%s\n", vmsvga3dGetCapString(idx3dCaps), vmsvga3dGet3dFormatString(result))); … … 1125 1113 D3D_RELEASE(pSurface->u.pTexture); 1126 1114 D3D_RELEASE(pSurface->bounce.pTexture); 1115 D3D_RELEASE(pSurface->emulated.pTexture); 1127 1116 break; 1128 1117 … … 1130 1119 D3D_RELEASE(pSurface->u.pCubeTexture); 1131 1120 D3D_RELEASE(pSurface->bounce.pCubeTexture); 1121 D3D_RELEASE(pSurface->emulated.pCubeTexture); 1132 1122 break; 1133 1123 … … 1135 1125 D3D_RELEASE(pSurface->u.pVolumeTexture); 1136 1126 D3D_RELEASE(pSurface->bounce.pVolumeTexture); 1127 D3D_RELEASE(pSurface->emulated.pVolumeTexture); 1137 1128 break; 1138 1129 … … 1519 1510 && pSurfaceDest->u.pSurface) 1520 1511 { 1512 /// @todo should use the src context because only the shared hardware surface is required from the dst context, 1513 // while the src context may be also needed to copy data to the source bounce texture. 1521 1514 const uint32_t cidDst = pSurfaceDest->idAssociatedContext; 1522 1515 … … 1583 1576 && (pSurfaceSrc->fUsageD3D & D3DUSAGE_RENDERTARGET)) 1584 1577 { 1578 #if 1 1579 /* Copy the source texture mipmap level to the bounce texture. 1580 * Get the data using the surface associated context. 1581 */ 1582 PVMSVGA3DCONTEXT pContextSrc; 1583 rc = vmsvga3dContextFromCid(pState, pSurfaceSrc->idAssociatedContext, &pContextSrc); 1584 if (RT_SUCCESS(rc)) 1585 { 1586 hr = D3D9GetRenderTargetData(pContextSrc, pSurfaceSrc, src.face, src.mipmap); 1587 AssertMsg(hr == D3D_OK, ("D3D9GetRenderTargetData failed with %x\n", hr)); 1588 if (hr == D3D_OK) 1589 { 1590 /* Copy the source bounce texture to the destination surface. */ 1591 IDirect3DSurface9 *pBounceSurf; 1592 rc = vmsvga3dGetD3DSurface(pState, pContextDst, pSurfaceSrc, src.face, src.mipmap, true, &pBounceSurf); 1593 if (RT_SUCCESS(rc)) 1594 { 1595 POINT pointDest; 1596 pointDest.x = clipBox.x; 1597 pointDest.y = clipBox.y; 1598 1599 hr = pContextDst->pDevice->UpdateSurface(pBounceSurf, &RectSrc, pDest, &pointDest); 1600 Assert(hr == D3D_OK); 1601 1602 D3D_RELEASE(pBounceSurf); 1603 } 1604 else 1605 { 1606 AssertRC(rc); 1607 hr = E_INVALIDARG; 1608 } 1609 } 1610 } 1611 else 1612 { 1613 AssertRC(rc); 1614 hr = E_INVALIDARG; 1615 } 1616 #else 1585 1617 /* Copy the texture mipmap level to the bounce texture. */ 1586 1618 … … 1607 1639 D3D_RELEASE(pBounceSurf); 1608 1640 } 1641 #endif 1609 1642 } 1610 1643 else if ( (pSurfaceSrc->fUsageD3D & D3DUSAGE_RENDERTARGET) == 0 … … 1799 1832 1800 1833 /* Copy the new content to the actual texture object. */ 1834 #if 1 1835 HRESULT hr2 = D3D9UpdateTexture(pContext, pSurfaceDest); 1836 #else 1801 1837 IDirect3DBaseTexture9 *pSourceTexture; 1802 1838 IDirect3DBaseTexture9 *pDestinationTexture; … … 1812 1848 } 1813 1849 HRESULT hr2 = pContext->pDevice->UpdateTexture(pSourceTexture, pDestinationTexture); 1850 #endif 1814 1851 AssertMsg(hr2 == D3D_OK, ("UpdateTexture failed with %x\n", hr2)); RT_NOREF(hr2); 1815 1852 } … … 2010 2047 NULL); 2011 2048 AssertMsgReturn(hr == D3D_OK, ("CreateTexture (systemmem) failed with %x\n", hr), VERR_INTERNAL_ERROR); 2049 2050 if (pSurface->formatD3D != pSurface->d3dfmtRequested) 2051 { 2052 /* Create a staging texture/render target for format conversion. */ 2053 hr = pContext->pDevice->CreateTexture(cWidth, 2054 cHeight, 2055 numMipLevels, 2056 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET, 2057 pSurface->formatD3D, 2058 D3DPOOL_DEFAULT, 2059 &pSurface->emulated.pTexture, 2060 NULL); 2061 AssertMsgReturn(hr == D3D_OK, ("CreateTexture (emulated) failed with %x\n", hr), VERR_INTERNAL_ERROR); 2062 } 2012 2063 } 2013 2064 else … … 2145 2196 } 2146 2197 } 2147 else 2148 { 2149 IDirect3DTexture9 *pTexture = pSurface->bounce.pTexture ? pSurface->bounce.pTexture : pSurface->u.pTexture; 2198 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE) 2199 { 2200 IDirect3DTexture9 *pTexture; 2201 if (pSurface->bounce.pTexture) 2202 pTexture = pSurface->bounce.pTexture; 2203 else if (pSurface->formatD3D != pSurface->d3dfmtRequested) 2204 pTexture = pSurface->emulated.pTexture; 2205 else 2206 pTexture = pSurface->u.pTexture; 2150 2207 2151 2208 for (uint32_t i = 0; i < numMipLevels; ++i) … … 2178 2235 } 2179 2236 } 2237 else 2238 { 2239 AssertMsgFailedReturn(("enmD3DResType not expected %d\n", pSurface->enmD3DResType), VERR_INTERNAL_ERROR); 2240 } 2180 2241 2181 2242 if (pSurface->bounce.pTexture) 2182 2243 { 2183 2244 Log(("vmsvga3dBackCreateTexture: sync dirty texture from bounce buffer\n")); 2184 2185 2245 if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE) 2186 2246 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pVolumeTexture, pSurface->u.pVolumeTexture); 2187 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)2188 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pCubeTexture, pSurface->u.pCubeTexture);2189 2247 else 2190 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pTexture, pSurface->u.pTexture);2248 hr = D3D9UpdateTexture(pContext, pSurface); 2191 2249 AssertMsgReturn(hr == D3D_OK, ("UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 2192 2250 … … 2318 2376 { 2319 2377 HRESULT hr = D3D_OK; 2320 const uint32_t u32SurfHints = pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;2321 2378 const DWORD dwFlags = transfer == SVGA3D_READ_HOST_VRAM ? D3DLOCK_READONLY : 0; 2322 // if (u32SurfHints != 0x18 && u32SurfHints != 0x60) ASMBreakpoint();2323 2379 2324 2380 AssertReturn(pSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE, VERR_NOT_IMPLEMENTED); … … 2337 2393 AssertRCReturn(rc, rc); 2338 2394 2339 /** @todo inefficient for VRAM buffers!! */ 2340 if (fTexture) 2341 { 2342 if (pSurface->bounce.pTexture) 2395 if (transfer == SVGA3D_READ_HOST_VRAM) 2396 { 2397 /* Texture data is copied to the host VRAM. 2398 * Update the 'bounce' texture if necessary. 2399 */ 2400 if ( fTexture 2401 && pSurface->bounce.pTexture 2402 && iBox == 0 /* only the first time */) 2343 2403 { 2344 if ( transfer == SVGA3D_READ_HOST_VRAM 2345 && RT_BOOL(u32SurfHints & SVGA3D_SURFACE_HINT_RENDERTARGET) 2346 && iBox == 0 /* only the first time */) 2404 /** @todo inefficient for VRAM buffers!! */ 2405 if (RT_BOOL(pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET)) 2347 2406 { 2348 2407 /* Copy the texture mipmap level to the bounce texture. */ 2349 2350 /* Source is the texture, destination is the bounce texture. */ 2351 IDirect3DSurface9 *pSrc; 2352 rc = vmsvga3dGetD3DSurface(pState, pContext, pSurface, uHostFace, uHostMipmap, false, &pSrc); 2353 AssertRCReturn(rc, rc); 2354 2355 Assert(pSurf != pSrc); 2356 2357 hr = pContext->pDevice->GetRenderTargetData(pSrc, pSurf); 2358 AssertMsgReturn(hr == D3D_OK, ("GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR); 2359 2360 D3D_RELEASE(pSrc); 2408 hr = D3D9GetRenderTargetData(pContext, pSurface, uHostFace, uHostMipmap); 2409 AssertMsgReturn(hr == D3D_OK, ("D3D9GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR); 2361 2410 } 2362 2411 } … … 2422 2471 AssertMsgReturn(hr == D3D_OK, ("UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 2423 2472 2424 if (fTexture) 2425 { 2426 if (pSurface->bounce.pTexture) 2473 if (transfer == SVGA3D_WRITE_HOST_VRAM) 2474 { 2475 /* Data is copied to the texture. Copy updated 'bounce' texture to the actual if necessary. 2476 */ 2477 /// @todo for the last iBox only. 2478 if ( fTexture 2479 && pSurface->bounce.pTexture) 2427 2480 { 2428 if (transfer == SVGA3D_WRITE_HOST_VRAM) 2429 { 2430 LogFunc(("Sync texture from bounce buffer\n")); 2431 2432 /* Copy the new contents to the actual texture object. */ 2433 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pTexture, pSurface->u.pTexture); 2434 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceDMA: UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 2435 2436 /* Track the copy operation. */ 2437 vmsvga3dSurfaceTrackUsage(pState, pContext, pSurface); 2438 } 2481 LogFunc(("Sync texture from bounce buffer\n")); 2482 2483 /* Copy the new contents to the actual texture object. */ 2484 hr = D3D9UpdateTexture(pContext, pSurface); 2485 AssertMsgReturn(hr == D3D_OK, ("UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 2486 2487 /* Track the copy operation. */ 2488 vmsvga3dSurfaceTrackUsage(pState, pContext, pSurface); 2439 2489 } 2440 2490 } … … 2520 2570 else 2521 2571 { 2522 AssertMsgFailed(("Unsupported surface hint 0x%08X, type %d\n", u32SurfHints, pSurface->enmD3DResType));2572 AssertMsgFailed(("Unsupported surface flags 0x%08X, type %d\n", pSurface->surfaceFlags, pSurface->enmD3DResType)); 2523 2573 } 2524 2574 … … 5361 5411 if (!pVertexSurface->u.pVertexBuffer) 5362 5412 { 5363 LogFunc(("Create vertex buffer fDirty=%d\n", pVertexSurface->fDirty));5413 LogFunc(("Create vertex buffer sid=%x fDirty=%d\n", pVertexSurface->id, pVertexSurface->fDirty)); 5364 5414 5365 5415 const DWORD Usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY; /* possible severe performance penalty otherwise (according to d3d debug output */ … … 5789 5839 int rc2 = vmsvga3dSurfaceFromSid(pState, pContext->state.aRenderTargets[SVGA3D_RT_COLOR0], &pSurface); 5790 5840 if (RT_SUCCESS(rc2)) 5791 vmsvga3dInfoSurfaceToBitmap(NULL, pSurface, "bmp ", "rt", "-post");5841 vmsvga3dInfoSurfaceToBitmap(NULL, pSurface, "bmpd3d", "rt", "-post"); 5792 5842 } 5793 5843 #endif -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp
r76553 r81360 229 229 #ifdef VMSVGA3D_DIRECT3D 230 230 /* Translate the format and usage flags to D3D. */ 231 pSurface->formatD3D = vmsvga3dSurfaceFormat2D3D(format); 231 pSurface->d3dfmtRequested = vmsvga3dSurfaceFormat2D3D(format); 232 pSurface->formatD3D = D3D9GetActualFormat(pState, pSurface->d3dfmtRequested); 232 233 pSurface->multiSampleTypeD3D= vmsvga3dMultipeSampleCount2D3D(multisampleCount); 233 234 pSurface->fUsageD3D = 0; … … 245 246 /* pSurface->u.pSurface = NULL; */ 246 247 /* pSurface->bounce.pTexture = NULL; */ 248 /* pSurface->emulated.pTexture = NULL; */ 247 249 #else 248 250 vmsvga3dSurfaceFormat2OGL(pSurface, format); -
trunk/src/VBox/Devices/Makefile.kmk
r81250 r81360 297 297 if "$(KBUILD_TARGET)" == "win" && !defined(VBOX_WITH_VMSVGA3D_USE_OPENGL) 298 298 VBoxDD_DEFS += VMSVGA3D_DIRECT3D 299 VBoxDD_SOURCES += Graphics/DevVGA-SVGA3d-win.cpp 299 VBoxDD_SOURCES += \ 300 Graphics/DevVGA-SVGA3d-win.cpp \ 301 Graphics/DevVGA-SVGA3d-win-d3d9.cpp 300 302 VBoxDD_LIBS.win += d3d9.lib $(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/delayimp.lib 301 303 VBoxDD_LDFLAGS.win += /DELAYLOAD:d3d9.dll
Note:
See TracChangeset
for help on using the changeset viewer.