Changeset 88831 in vbox for trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp
- Timestamp:
- May 3, 2021 12:37:23 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp
r88803 r88831 1268 1268 1269 1269 1270 static UINT dxBindFlags(SVGA3dSurfaceAllFlags surfaceFlags) 1271 { 1272 /* Catch unimplemented flags. */ 1273 Assert(!RT_BOOL(surfaceFlags & (SVGA3D_SURFACE_BIND_LOGICOPS | SVGA3D_SURFACE_BIND_RAW_VIEWS))); 1274 1275 UINT BindFlags = 0; 1276 1277 if (surfaceFlags & SVGA3D_SURFACE_BIND_VERTEX_BUFFER) BindFlags |= D3D11_BIND_VERTEX_BUFFER; 1278 if (surfaceFlags & SVGA3D_SURFACE_BIND_INDEX_BUFFER) BindFlags |= D3D11_BIND_INDEX_BUFFER; 1279 if (surfaceFlags & SVGA3D_SURFACE_BIND_CONSTANT_BUFFER) BindFlags |= D3D11_BIND_CONSTANT_BUFFER; 1280 if (surfaceFlags & SVGA3D_SURFACE_BIND_SHADER_RESOURCE) BindFlags |= D3D11_BIND_SHADER_RESOURCE; 1281 if (surfaceFlags & SVGA3D_SURFACE_BIND_RENDER_TARGET) BindFlags |= D3D11_BIND_RENDER_TARGET; 1282 if (surfaceFlags & SVGA3D_SURFACE_BIND_DEPTH_STENCIL) BindFlags |= D3D11_BIND_DEPTH_STENCIL; 1283 if (surfaceFlags & SVGA3D_SURFACE_BIND_STREAM_OUTPUT) BindFlags |= D3D11_BIND_STREAM_OUTPUT; 1284 if (surfaceFlags & SVGA3D_SURFACE_BIND_UAVIEW) BindFlags |= D3D11_BIND_UNORDERED_ACCESS; 1285 1286 return BindFlags; 1287 } 1288 1289 1270 1290 static int vmsvga3dBackSurfaceCreateTexture(PVMSVGA3DSTATE p3dState, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface) 1271 1291 { … … 1282 1302 AssertPtrReturn(pBackendSurface, VERR_NO_MEMORY); 1283 1303 1284 /** @todo Various texture types. */ 1285 ASMBreakpoint(); 1286 1304 uint32_t const cWidth = pSurface->paMipmapLevels[0].mipmapSize.width; 1305 uint32_t const cHeight = pSurface->paMipmapLevels[0].mipmapSize.height; 1306 uint32_t const cDepth = pSurface->paMipmapLevels[0].mipmapSize.depth; 1307 uint32_t const numMipLevels = pSurface->cLevels; 1308 1309 DXGI_FORMAT dxgiFormat = vmsvgaDXSurfaceFormat2Dxgi(pSurface->format); 1310 AssertReturn(dxgiFormat != DXGI_FORMAT_UNKNOWN, E_FAIL); 1311 1312 /* 1313 * Create D3D11 texture object. 1314 */ 1315 HRESULT hr = S_OK; 1316 if (pSurface->surfaceFlags & SVGA3D_SURFACE_CUBEMAP) 1317 { 1318 Assert(pSurface->cFaces == 6); 1319 Assert(cWidth == cHeight); 1320 Assert(cDepth == 1); 1321 1322 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_CUBE_TEXTURE; 1323 AssertFailed(); /** @todo implement */ 1324 hr = E_FAIL; 1325 } 1326 else if (pSurface->surfaceFlags & SVGA3D_SURFACE_1D) 1327 { 1328 AssertFailed(); /** @todo implement */ 1329 hr = E_FAIL; 1330 } 1331 else 1332 { 1333 if (cDepth > 1) 1334 { 1335 /* 1336 * Volume texture. 1337 */ 1338 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_VOLUME_TEXTURE; 1339 AssertFailed(); /** @todo implement */ 1340 hr = E_FAIL; 1341 } 1342 else 1343 { 1344 /* 1345 * 2D texture. 1346 */ 1347 Assert(pSurface->cFaces == 1); 1348 1349 D3D11_SUBRESOURCE_DATA *paInitialData = NULL; 1350 D3D11_SUBRESOURCE_DATA aInitialData[SVGA3D_MAX_MIP_LEVELS]; 1351 if (pSurface->paMipmapLevels[0].pSurfaceData) 1352 { 1353 /** @todo Can happen for a non GBO surface. Test this. */ 1354 for (uint32_t i = 0; i < numMipLevels; ++i) 1355 { 1356 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i]; 1357 D3D11_SUBRESOURCE_DATA *p = &aInitialData[i]; 1358 p->pSysMem = pMipmapLevel->pSurfaceData; 1359 p->SysMemPitch = pMipmapLevel->cbSurfacePitch; 1360 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane; 1361 } 1362 paInitialData = &aInitialData[0]; 1363 } 1364 1365 D3D11_TEXTURE2D_DESC td; 1366 RT_ZERO(td); 1367 td.Width = cWidth; 1368 td.Height = cHeight; 1369 td.MipLevels = numMipLevels; 1370 td.ArraySize = 1; /** @todo */ 1371 td.Format = dxgiFormat; 1372 td.SampleDesc.Count = 1; 1373 td.SampleDesc.Quality = 0; 1374 td.Usage = D3D11_USAGE_DEFAULT; 1375 td.BindFlags = dxBindFlags(pSurface->surfaceFlags); 1376 td.CPUAccessFlags = 0; /** @todo */ 1377 td.MiscFlags = 0; /** @todo */ 1378 if ( numMipLevels > 1 1379 && (td.BindFlags & (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET)) == (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET)) 1380 td.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS; /* Required for GenMips. */ 1381 1382 hr = pDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->u.Texture.pTexture); 1383 Assert(SUCCEEDED(hr)); 1384 if (SUCCEEDED(hr)) 1385 { 1386 /* Map-able texture. */ 1387 td.MipLevels = 1; /* Must be for D3D11_USAGE_DYNAMIC. */ 1388 td.Usage = D3D11_USAGE_DYNAMIC; 1389 td.BindFlags = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */ 1390 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 1391 td.MiscFlags = 0; 1392 hr = pDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->u.Texture.pDynamicTexture); 1393 Assert(SUCCEEDED(hr)); 1394 } 1395 1396 if (SUCCEEDED(hr)) 1397 { 1398 /* Staging texture. */ 1399 td.MipLevels = 1; 1400 td.Usage = D3D11_USAGE_STAGING; 1401 td.BindFlags = 0; /* No flags allowed. */ 1402 td.CPUAccessFlags = D3D11_CPU_ACCESS_READ; 1403 td.MiscFlags = 0; 1404 hr = pDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->u.Texture.pStagingTexture); 1405 Assert(SUCCEEDED(hr)); 1406 } 1407 1408 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE; 1409 } 1410 } 1411 1412 Assert(hr == S_OK); 1413 1414 if (pSurface->autogenFilter != SVGA3D_TEX_FILTER_NONE) 1415 { 1416 } 1417 1418 if (SUCCEEDED(hr)) 1419 { 1420 /* 1421 * Success. 1422 */ 1423 pBackendSurface->enmDxgiFormat = dxgiFormat; 1424 pSurface->pBackendSurface = pBackendSurface; 1425 pSurface->idAssociatedContext = pDXContext->cid; 1426 return VINF_SUCCESS; 1427 } 1428 1429 /* Failure. */ 1430 D3D_RELEASE(pBackendSurface->u.Texture.pStagingTexture); 1431 D3D_RELEASE(pBackendSurface->u.Texture.pDynamicTexture); 1432 D3D_RELEASE(pBackendSurface->u.Texture.pTexture); 1287 1433 RTMemFree(pBackendSurface); 1288 return VERR_NO T_IMPLEMENTED;1434 return VERR_NO_MEMORY; 1289 1435 } 1290 1436 … … 1448 1594 1449 1595 1596 static HRESULT dxCreateConstantBuffer(DXDEVICE *pDevice, VMSVGA3DSURFACE const *pSurface, PVMSVGA3DBACKENDSURFACE pBackendSurface) 1597 { 1598 D3D11_SUBRESOURCE_DATA *pInitialData = NULL; /** @todo */ 1599 D3D11_BUFFER_DESC bd; 1600 RT_ZERO(bd); 1601 bd.ByteWidth = pSurface->paMipmapLevels[0].cbSurface; 1602 bd.Usage = D3D11_USAGE_DYNAMIC; /** @todo HINT_STATIC */ 1603 bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 1604 bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 1605 bd.MiscFlags = 0; 1606 bd.StructureByteStride = 0; 1607 1608 return pDevice->pDevice->CreateBuffer(&bd, pInitialData, &pBackendSurface->u.Buffer.pBuffer); 1609 } 1610 1611 1612 static HRESULT dxCreateBuffer(DXDEVICE *pDevice, VMSVGA3DSURFACE const *pSurface, PVMSVGA3DBACKENDSURFACE pBackendSurface) 1613 { 1614 D3D11_SUBRESOURCE_DATA *pInitialData = NULL; /** @todo */ 1615 D3D11_BUFFER_DESC bd; 1616 RT_ZERO(bd); 1617 bd.ByteWidth = pSurface->paMipmapLevels[0].cbSurface; 1618 bd.Usage = D3D11_USAGE_DYNAMIC; /** @todo HINT_STATIC */ 1619 bd.BindFlags = D3D11_BIND_VERTEX_BUFFER 1620 | D3D11_BIND_INDEX_BUFFER; 1621 bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 1622 bd.MiscFlags = 0; 1623 bd.StructureByteStride = 0; 1624 1625 return pDevice->pDevice->CreateBuffer(&bd, pInitialData, &pBackendSurface->u.Buffer.pBuffer); 1626 } 1627 1628 1629 static int vmsvga3dBackSurfaceCreate(PVMSVGA3DSTATE p3dState, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface) 1630 { 1631 DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device; 1632 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 1633 1634 if (pSurface->pBackendSurface != NULL) 1635 { 1636 AssertFailed(); /** @todo Should the function not be used like that? */ 1637 vmsvga3dBackSurfaceDestroy(p3dState, pSurface); 1638 } 1639 1640 PVMSVGA3DBACKENDSURFACE pBackendSurface = (PVMSVGA3DBACKENDSURFACE)RTMemAllocZ(sizeof(VMSVGA3DBACKENDSURFACE)); 1641 AssertPtrReturn(pBackendSurface, VERR_NO_MEMORY); 1642 1643 HRESULT hr; 1644 1645 /* 1646 * Figure out the type of the surface. 1647 */ 1648 if (pSurface->surfaceFlags & SVGA3D_SURFACE_BIND_CONSTANT_BUFFER) 1649 { 1650 hr = dxCreateConstantBuffer(pDevice, pSurface, pBackendSurface); 1651 if (SUCCEEDED(hr)) 1652 { 1653 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_BUFFER; 1654 pBackendSurface->enmDxgiFormat = DXGI_FORMAT_UNKNOWN; 1655 } 1656 else 1657 D3D_RELEASE(pBackendSurface->u.Buffer.pBuffer); 1658 } 1659 else if (pSurface->surfaceFlags & ( SVGA3D_SURFACE_BIND_VERTEX_BUFFER 1660 | SVGA3D_SURFACE_BIND_INDEX_BUFFER 1661 | SVGA3D_SURFACE_HINT_VERTEXBUFFER 1662 | SVGA3D_SURFACE_HINT_INDEXBUFFER)) 1663 { 1664 hr = dxCreateBuffer(pDevice, pSurface, pBackendSurface); 1665 if (SUCCEEDED(hr)) 1666 { 1667 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_BUFFER; 1668 pBackendSurface->enmDxgiFormat = DXGI_FORMAT_UNKNOWN; 1669 } 1670 else 1671 D3D_RELEASE(pBackendSurface->u.Buffer.pBuffer); 1672 } 1673 else 1674 { 1675 AssertFailed(); /** @todo implement */ 1676 hr = E_FAIL; 1677 } 1678 1679 if (SUCCEEDED(hr)) 1680 { 1681 /* 1682 * Success. 1683 */ 1684 pSurface->pBackendSurface = pBackendSurface; 1685 pSurface->idAssociatedContext = pDXContext->cid; 1686 return VINF_SUCCESS; 1687 } 1688 1689 /* Failure. */ 1690 RTMemFree(pBackendSurface); 1691 return VERR_NO_MEMORY; 1692 } 1693 1694 1450 1695 int vmsvga3dInit(PPDMDEVINS pDevIns, PVGASTATE pThis, PVGASTATECC pThisCC) 1451 1696 { … … 1790 2035 1791 2036 1792 static DECLCALLBACK(int) vmsvga3dSurfaceMap(PVGASTATECC pThisCC, SVGA3dSurfaceImageId const *pImage, SVGA3dBox const *pBox,2037 static DECLCALLBACK(int) vmsvga3dSurfaceMap(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dSurfaceImageId const *pImage, SVGA3dBox const *pBox, 1793 2038 VMSVGA3D_SURFACE_MAP enmMapType, VMSVGA3D_MAPPED_SURFACE *pMap) 1794 2039 { … … 1804 2049 AssertRCReturn(rc, rc); 1805 2050 2051 PVMSVGA3DDXCONTEXT pDXContext; 1806 2052 PVMSVGA3DBACKENDSURFACE pBackendSurface = pSurface->pBackendSurface; 1807 2053 if (!pBackendSurface) 1808 return VERR_INVALID_PARAMETER; 1809 // AssertFailedReturn(VERR_INVALID_PARAMETER); /** @todo The caller must directly use the surface memory. */ 1810 1811 PVMSVGA3DDXCONTEXT pDXContext; 1812 vmsvga3dDXContextFromCid(pState, pSurface->idAssociatedContext, &pDXContext); 2054 { 2055 /* This means that the guest uploads new data to the surface. 2056 * So the data should be copied either to a host memory buffer, 2057 * or to the actual surface. 2058 * In the latter case the BackendSurface must be created here. 2059 */ 2060 rc = vmsvga3dDXContextFromCid(pState, idDXContext, &pDXContext); 2061 AssertRCReturn(rc, rc); 2062 2063 rc = vmsvga3dBackSurfaceCreate(pState, pDXContext, pSurface); 2064 AssertRCReturn(rc, rc); 2065 2066 pBackendSurface = pSurface->pBackendSurface; 2067 } 2068 else 2069 vmsvga3dDXContextFromCid(pState, pSurface->idAssociatedContext, &pDXContext); 2070 2071 Assert(pImage->face == 0 && pImage->mipmap == 0); /** @todo implement. */ 1813 2072 1814 2073 DXDEVICE *pDevice = NULL; … … 3166 3425 3167 3426 VMSVGA3D_MAPPED_SURFACE map; 3168 rc = vmsvga3dSurfaceMap(pThisCC, &image, &box, VMSVGA3D_SURFACE_MAP_WRITE_DISCARD, &map);3427 rc = vmsvga3dSurfaceMap(pThisCC, pSurface->idAssociatedContext, &image, &box, VMSVGA3D_SURFACE_MAP_WRITE_DISCARD, &map); 3169 3428 if (RT_SUCCESS(rc)) 3170 3429 { … … 3207 3466 #endif 3208 3467 } 3468 else if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE) 3469 { 3470 /** @todo This is generic code and should be in DevVGA-SVGA3d.cpp for backends which support Map/Unmap. */ 3471 AssertReturn(uHostFace == 0 && uHostMipmap == 0, VERR_INVALID_PARAMETER); 3472 3473 uint32_t const u32GuestBlockX = pBox->srcx / pSurface->cxBlock; 3474 uint32_t const u32GuestBlockY = pBox->srcy / pSurface->cyBlock; 3475 Assert(u32GuestBlockX * pSurface->cxBlock == pBox->srcx); 3476 Assert(u32GuestBlockY * pSurface->cyBlock == pBox->srcy); 3477 uint32_t const cBlocksX = (pBox->w + pSurface->cxBlock - 1) / pSurface->cxBlock; 3478 uint32_t const cBlocksY = (pBox->h + pSurface->cyBlock - 1) / pSurface->cyBlock; 3479 AssertMsgReturn(cBlocksX && cBlocksY, ("Empty box %dx%d\n", pBox->w, pBox->h), VERR_INTERNAL_ERROR); 3480 3481 /* vmsvgaR3GmrTransfer verifies uGuestOffset. 3482 * srcx(u32GuestBlockX) and srcy(u32GuestBlockY) have been verified in vmsvga3dSurfaceDMA 3483 * to not cause 32 bit overflow when multiplied by cbBlock and cbGuestPitch. 3484 */ 3485 uint64_t const uGuestOffset = u32GuestBlockX * pSurface->cbBlock + u32GuestBlockY * cbGuestPitch; 3486 AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER); 3487 3488 SVGA3dSurfaceImageId image; 3489 image.sid = pSurface->id; 3490 image.face = uHostFace; 3491 image.mipmap = uHostMipmap; 3492 3493 SVGA3dBox box; 3494 box.x = pBox->x; 3495 box.y = pBox->y; 3496 box.z = 0; 3497 box.w = pBox->w; 3498 box.h = pBox->h; 3499 box.d = 1; 3500 3501 VMSVGA3D_SURFACE_MAP const enmMap = transfer == SVGA3D_WRITE_HOST_VRAM 3502 ? VMSVGA3D_SURFACE_MAP_WRITE_DISCARD 3503 : VMSVGA3D_SURFACE_MAP_READ; 3504 3505 VMSVGA3D_MAPPED_SURFACE map; 3506 rc = vmsvga3dSurfaceMap(pThisCC, pSurface->idAssociatedContext, &image, &box, enmMap, &map); 3507 if (RT_SUCCESS(rc)) 3508 { 3509 /* Prepare parameters for vmsvgaR3GmrTransfer, which needs the host buffer address, size 3510 * and offset of the first scanline. 3511 */ 3512 uint32_t const cbLockedBuf = map.cbRowPitch * cBlocksY; 3513 uint8_t *pu8LockedBuf = (uint8_t *)map.pvData; 3514 uint32_t const offLockedBuf = 0; 3515 3516 rc = vmsvgaR3GmrTransfer(pThis, 3517 pThisCC, 3518 transfer, 3519 pu8LockedBuf, 3520 cbLockedBuf, 3521 offLockedBuf, 3522 map.cbRowPitch, 3523 GuestPtr, 3524 (uint32_t)uGuestOffset, 3525 cbGuestPitch, 3526 cBlocksX * pSurface->cbBlock, 3527 cBlocksY); 3528 AssertRC(rc); 3529 3530 bool const fWritten = (transfer == SVGA3D_WRITE_HOST_VRAM); 3531 vmsvga3dSurfaceUnmap(pThisCC, &image, &map, fWritten); 3532 } 3533 } 3209 3534 else 3210 3535 { … … 3384 3709 boxDst.d = 1; 3385 3710 3386 rc = vmsvgaR3UpdateGBSurfaceEx(pThisCC, &imageId, &boxDst, &ptSrc);3711 rc = vmsvgaR3UpdateGBSurfaceEx(pThisCC, pDXContext->cid, &imageId, &boxDst, &ptSrc); 3387 3712 AssertRCReturn(rc, rc); 3388 3713 } 3389 3714 3390 3715 dxConstantBufferSet(pDevice, slot, type, pSurface->pBackendSurface->u.Buffer.pBuffer); 3391 3392 uint32_t const idxShaderState = type - SVGA3D_SHADERTYPE_MIN;3393 SVGA3dConstantBufferBinding *pCBB = &pDXContext->svgaDXContext.shaderState[idxShaderState].constantBuffers[slot];3394 pCBB->sid = sid;3395 pCBB->offsetInBytes = offsetInBytes;3396 pCBB->sizeInBytes = sizeInBytes;3397 3716 return VINF_SUCCESS; 3398 3717 } … … 3482 3801 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 3483 3802 3484 pDevice->pImmediateContext->Draw(vertexCount, startVertexLocation); 3803 if (pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN) 3804 pDevice->pImmediateContext->Draw(vertexCount, startVertexLocation); 3805 else 3806 { 3807 /* 3808 * Emulate SVGA3D_PRIMITIVE_TRIANGLEFAN using an indexed draw of a triangle list. 3809 */ 3810 3811 /* Make sure that 16 bit indices are enough. 20000 ~= 65536 / 3 */ 3812 AssertReturn(vertexCount <= 20000, VERR_NOT_SUPPORTED); 3813 3814 /* Generate indices. */ 3815 UINT const IndexCount = 3 * (vertexCount - 2); /* 3_per_triangle * num_triangles */ 3816 UINT const cbAlloc = IndexCount * sizeof(USHORT); 3817 USHORT *paIndices = (USHORT *)RTMemAlloc(cbAlloc); 3818 AssertReturn(paIndices, VERR_NO_MEMORY); 3819 USHORT iVertex = 1; 3820 for (UINT i = 0; i < IndexCount; i+= 3) 3821 { 3822 paIndices[i] = 0; 3823 paIndices[i + 1] = iVertex; 3824 ++iVertex; 3825 paIndices[i + 2] = iVertex; 3826 } 3827 3828 D3D11_SUBRESOURCE_DATA InitData; 3829 InitData.pSysMem = paIndices; 3830 InitData.SysMemPitch = cbAlloc; 3831 InitData.SysMemSlicePitch = cbAlloc; 3832 3833 D3D11_BUFFER_DESC bd; 3834 RT_ZERO(bd); 3835 bd.ByteWidth = cbAlloc; 3836 bd.Usage = D3D11_USAGE_IMMUTABLE; 3837 bd.BindFlags = D3D11_BIND_INDEX_BUFFER; 3838 //bd.CPUAccessFlags = 0; 3839 //bd.MiscFlags = 0; 3840 //bd.StructureByteStride = 0; 3841 3842 ID3D11Buffer *pIndexBuffer = 0; 3843 HRESULT hr = pDevice->pDevice->CreateBuffer(&bd, &InitData, &pIndexBuffer); 3844 Assert(SUCCEEDED(hr));RT_NOREF(hr); 3845 3846 /* Save the current index buffer. */ 3847 ID3D11Buffer *pSavedIndexBuffer = 0; 3848 DXGI_FORMAT SavedFormat = DXGI_FORMAT_UNKNOWN; 3849 UINT SavedOffset = 0; 3850 pDevice->pImmediateContext->IAGetIndexBuffer(&pSavedIndexBuffer, &SavedFormat, &SavedOffset); 3851 3852 /* Set up the device state. */ 3853 pDevice->pImmediateContext->IASetIndexBuffer(pIndexBuffer, DXGI_FORMAT_R16_UINT, 0); 3854 pDevice->pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 3855 3856 UINT const StartIndexLocation = 0; 3857 INT const BaseVertexLocation = startVertexLocation; 3858 pDevice->pImmediateContext->DrawIndexed(IndexCount, StartIndexLocation, BaseVertexLocation); 3859 3860 /* Restore the device state. */ 3861 pDevice->pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); 3862 pDevice->pImmediateContext->IASetIndexBuffer(pSavedIndexBuffer, SavedFormat, SavedOffset); 3863 D3D_RELEASE(pSavedIndexBuffer); 3864 3865 /* Cleanup. */ 3866 D3D_RELEASE(pIndexBuffer); 3867 RTMemFree(paIndices); 3868 } 3869 3485 3870 return VINF_SUCCESS; 3486 3871 } … … 3495 3880 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 3496 3881 3882 Assert(pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN); 3883 3497 3884 pDevice->pImmediateContext->DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); 3498 3885 return VINF_SUCCESS; … … 3502 3889 static DECLCALLBACK(int) vmsvga3dBackDXDrawInstanced(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext) 3503 3890 { 3891 Assert(pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN); 3504 3892 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 3505 3893 … … 3512 3900 static DECLCALLBACK(int) vmsvga3dBackDXDrawIndexedInstanced(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext) 3513 3901 { 3902 Assert(pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN); 3514 3903 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 3515 3904 … … 3522 3911 static DECLCALLBACK(int) vmsvga3dBackDXDrawAuto(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext) 3523 3912 { 3913 Assert(pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN); 3524 3914 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 3525 3915 … … 3617 4007 box.d = 1; 3618 4008 3619 rc = vmsvgaR3UpdateGBSurface(pThisCC, &imageId, &box);4009 rc = vmsvgaR3UpdateGBSurface(pThisCC, pDXContext->cid, &imageId, &box); 3620 4010 AssertRCReturn(rc, rc); 3621 4011 } … … 3684 4074 box.d = 1; 3685 4075 3686 rc = vmsvgaR3UpdateGBSurface(pThisCC, &imageId, &box);4076 rc = vmsvgaR3UpdateGBSurface(pThisCC, pDXContext->cid, &imageId, &box); 3687 4077 AssertRCReturn(rc, rc); 3688 4078 } … … 3699 4089 3700 4090 pDevice->pImmediateContext->IASetIndexBuffer(pResource, enmDxgiFormat, offset); 3701 3702 pDXContext->svgaDXContext.inputAssembly.indexBufferSid = sid;3703 pDXContext->svgaDXContext.inputAssembly.indexBufferOffset = offset;3704 pDXContext->svgaDXContext.inputAssembly.indexBufferFormat = format;3705 3706 4091 return VINF_SUCCESS; 3707 4092 } … … 3717 4102 D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, 3718 4103 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, 3719 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, /* SVGA3D_PRIMITIVE_TRIANGLEFAN: No FAN in D3D11 */4104 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, /* SVGA3D_PRIMITIVE_TRIANGLEFAN: No FAN in D3D11. */ 3720 4105 D3D11_PRIMITIVE_TOPOLOGY_LINELIST_ADJ, 3721 4106 D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ, … … 3766 4151 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 3767 4152 3768 D3D11_PRIMITIVE_TOPOLOGY enmTopology = dxTopology(topology);4153 D3D11_PRIMITIVE_TOPOLOGY const enmTopology = dxTopology(topology); 3769 4154 pDevice->pImmediateContext->IASetPrimitiveTopology(enmTopology); 3770 pDXContext->svgaDXContext.inputAssembly.topology = topology;3771 4155 return VINF_SUCCESS; 3772 4156 } … … 3784 4168 for (uint32_t i = 0; i < cRenderTargetViewId; ++i) 3785 4169 { 3786 SVGA3dRenderTargetViewId renderTargetViewId = paRenderTargetViewId[i];4170 SVGA3dRenderTargetViewId const renderTargetViewId = paRenderTargetViewId[i]; 3787 4171 if (renderTargetViewId != SVGA3D_INVALID_ID) 3788 4172 {
Note:
See TracChangeset
for help on using the changeset viewer.