Changeset 103983 in vbox for trunk/src/VBox/Additions/WINNT/Graphics
- Timestamp:
- Mar 21, 2024 12:06:03 PM (10 months ago)
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d11main.cpp
r101082 r103983 28 28 #include "d3d11render.h" 29 29 30 #include <iprt/file.h> 31 #include <iprt/formats/bmp.h> 30 32 #include <iprt/string.h> 33 34 /* 35 * Utilities. 36 */ 37 uint8_t *readBmpFile(char const *pszFilename, uint32_t cbPixel, uint32_t *pWidth, uint32_t *pHeight, uint32_t *pcbData) 38 { 39 uint8_t *pu8Data = NULL; 40 uint32_t cbFileData = 0; 41 42 RTFILE f = NIL_RTFILE; 43 int rc = RTFileOpen(&f, pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE); 44 if (RT_SUCCESS(rc)) 45 { 46 BMPFILEHDR fileHdr; 47 rc = RTFileRead(f, &fileHdr, sizeof(fileHdr), NULL); 48 if (RT_SUCCESS(rc)) 49 { 50 uint32_t const cbHdr = fileHdr.offBits - sizeof(fileHdr); 51 if (cbHdr == sizeof(BITMAPV4HEADER)) 52 { 53 BITMAPV4HEADER hdrV4; 54 rc = RTFileRead(f, &hdrV4, sizeof(hdrV4), NULL); 55 if (RT_SUCCESS(rc)) 56 { 57 *pWidth = hdrV4.bV4Width; 58 *pHeight = (uint32_t)-hdrV4.bV4Height; 59 } 60 } 61 else if (cbHdr == sizeof(BMPWIN3XINFOHDR)) 62 { 63 BMPWIN3XINFOHDR coreHdr; 64 rc = RTFileRead(f, &coreHdr, sizeof(coreHdr), NULL); 65 if (RT_SUCCESS(rc)) 66 { 67 *pWidth = coreHdr.uWidth; 68 *pHeight = (uint32_t)(-(int32_t)coreHdr.uHeight); 69 } 70 } 71 else 72 rc = VERR_NOT_SUPPORTED; 73 74 if (RT_SUCCESS(rc)) 75 { 76 cbFileData = fileHdr.cbFileSize - fileHdr.offBits; 77 pu8Data = (uint8_t *)RTMemAlloc(cbFileData); 78 if (pu8Data) 79 rc = RTFileRead(f, pu8Data, cbFileData, NULL); 80 else 81 rc = VERR_NO_MEMORY; 82 } 83 } 84 85 RTFileClose(f); 86 } 87 88 if (RT_SUCCESS(rc)) 89 { 90 /* If the actual data has less bits than 32, then convert the pixels. */ 91 uint32_t const *s = (uint32_t *)pu8Data; 92 if (cbPixel == 2) 93 { 94 uint16_t *d = (uint16_t *)pu8Data; 95 for (unsigned i = 0 ; i < cbFileData / 4; ++i) 96 *d++ = (uint16_t)*s++; 97 } 98 else if (cbPixel == 1) 99 { 100 uint8_t *d = (uint8_t *)pu8Data; 101 for (unsigned i = 0 ; i < cbFileData / 4; ++i) 102 *d++ = (uint8_t)*s++; 103 } 104 105 *pcbData = (cbFileData / 4) * cbPixel; 106 } 107 else 108 { 109 RTMemFree(pu8Data); 110 pu8Data = NULL; 111 } 112 113 return pu8Data; 114 } 115 31 116 32 117 class D3D11Test : public D3D11DeviceProvider … … 289 374 mRTHeight = clientRect.bottom; 290 375 376 bool const fDirectOutput = mpRender->IsDirectOutputRequired(this); 377 291 378 /* 292 379 * Render. … … 297 384 if (mRender.pDevice) 298 385 { 299 D3D11_TEXTURE2D_DESC texDesc; 300 RT_ZERO(texDesc); 301 texDesc.Width = mRTWidth; 302 texDesc.Height = mRTHeight; 303 texDesc.MipLevels = 1; 304 texDesc.ArraySize = 1; 305 texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 306 texDesc.SampleDesc.Count = 1; 307 texDesc.SampleDesc.Quality = 0; 308 texDesc.Usage = D3D11_USAGE_DEFAULT; 309 texDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; 310 texDesc.CPUAccessFlags = 0; 311 texDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX; 312 313 HTEST(mRender.pDevice->CreateTexture2D(&texDesc, 0, &mRender.pRenderTarget)); 314 HTEST(mRender.pDevice->CreateRenderTargetView(mRender.pRenderTarget, 0, &mRender.pRenderTargetView)); 315 316 /* Get the shared handle. */ 317 HTEST(mRender.pRenderTarget->QueryInterface(__uuidof(IDXGIResource), (void**)&mRender.pDxgiResource)); 318 HTEST(mRender.pDxgiResource->GetSharedHandle(&mSharedHandle)); 319 320 HTEST(mRender.pRenderTarget->QueryInterface(__uuidof(IDXGIKeyedMutex), (LPVOID*)&mRender.pDXGIKeyedMutex)); 386 if (!fDirectOutput) 387 { 388 D3D11_TEXTURE2D_DESC texDesc; 389 RT_ZERO(texDesc); 390 texDesc.Width = mRTWidth; 391 texDesc.Height = mRTHeight; 392 texDesc.MipLevels = 1; 393 texDesc.ArraySize = 1; 394 texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 395 texDesc.SampleDesc.Count = 1; 396 texDesc.SampleDesc.Quality = 0; 397 texDesc.Usage = D3D11_USAGE_DEFAULT; 398 texDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; 399 texDesc.CPUAccessFlags = 0; 400 texDesc.MiscFlags = fDirectOutput ? 0 : D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX; 401 402 HTEST(mRender.pDevice->CreateTexture2D(&texDesc, 0, &mRender.pRenderTarget)); 403 HTEST(mRender.pDevice->CreateRenderTargetView(mRender.pRenderTarget, 0, &mRender.pRenderTargetView)); 404 405 /* Get the shared handle. */ 406 HTEST(mRender.pRenderTarget->QueryInterface(__uuidof(IDXGIResource), (void**)&mRender.pDxgiResource)); 407 HTEST(mRender.pDxgiResource->GetSharedHandle(&mSharedHandle)); 408 409 HTEST(mRender.pRenderTarget->QueryInterface(__uuidof(IDXGIKeyedMutex), (LPVOID*)&mRender.pDXGIKeyedMutex)); 410 } 321 411 322 412 if (mpRender->IsDepthStencilBufferRequired(this)) … … 357 447 * Output. 358 448 */ 359 d3d11TestCreateDevice(&mOutput.pDevice, 360 &mOutput.pImmediateContext, 361 &mOutput.pDxgiFactory); 362 if (mOutput.pDxgiFactory) 363 { 364 DXGI_SWAP_CHAIN_DESC sd; 365 RT_ZERO(sd); 366 sd.BufferDesc.Width = mRTWidth; 367 sd.BufferDesc.Height = mRTHeight; 368 sd.BufferDesc.RefreshRate.Numerator = 60; 369 sd.BufferDesc.RefreshRate.Denominator = 1; 370 sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 371 sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; 372 sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; 373 sd.SampleDesc.Count = 1; 374 sd.SampleDesc.Quality = 0; 375 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 376 sd.BufferCount = 1; 377 sd.OutputWindow = mHwnd; 378 sd.Windowed = true; 379 sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; 380 sd.Flags = 0; 381 382 HTEST(mOutput.pDxgiFactory->CreateSwapChain(mOutput.pDevice, &sd, &mOutput.pSwapChain)); 383 384 HTEST(mOutput.pSwapChain->ResizeBuffers(1, mRTWidth, mRTHeight, DXGI_FORMAT_B8G8R8A8_UNORM, 0)); 385 386 HTEST(mOutput.pDevice->OpenSharedResource(mSharedHandle, __uuidof(ID3D11Texture2D), (void**)&mOutput.pSharedTexture)); 387 HTEST(mOutput.pSharedTexture->QueryInterface(__uuidof(IDXGIKeyedMutex), (LPVOID*)&mOutput.pDXGIKeyedMutex)); 449 if (fDirectOutput) 450 { 451 if (mRender.pDxgiFactory) 452 { 453 DXGI_SWAP_CHAIN_DESC sd; 454 RT_ZERO(sd); 455 sd.BufferDesc.Width = mRTWidth; 456 sd.BufferDesc.Height = mRTHeight; 457 sd.BufferDesc.RefreshRate.Numerator = 60; 458 sd.BufferDesc.RefreshRate.Denominator = 1; 459 sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 460 sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; 461 sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; 462 sd.SampleDesc.Count = 1; 463 sd.SampleDesc.Quality = 0; 464 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 465 sd.BufferCount = 1; 466 sd.OutputWindow = mHwnd; 467 sd.Windowed = true; 468 sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; 469 sd.Flags = 0; 470 471 HTEST(mRender.pDxgiFactory->CreateSwapChain(mRender.pDevice, &sd, &mOutput.pSwapChain)); 472 473 HTEST(mOutput.pSwapChain->ResizeBuffers(1, mRTWidth, mRTHeight, DXGI_FORMAT_B8G8R8A8_UNORM, 0)); 474 } 475 } 476 else 477 { 478 d3d11TestCreateDevice(&mOutput.pDevice, 479 &mOutput.pImmediateContext, 480 &mOutput.pDxgiFactory); 481 if (mOutput.pDxgiFactory) 482 { 483 DXGI_SWAP_CHAIN_DESC sd; 484 RT_ZERO(sd); 485 sd.BufferDesc.Width = mRTWidth; 486 sd.BufferDesc.Height = mRTHeight; 487 sd.BufferDesc.RefreshRate.Numerator = 60; 488 sd.BufferDesc.RefreshRate.Denominator = 1; 489 sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 490 sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; 491 sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; 492 sd.SampleDesc.Count = 1; 493 sd.SampleDesc.Quality = 0; 494 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 495 sd.BufferCount = 1; 496 sd.OutputWindow = mHwnd; 497 sd.Windowed = true; 498 sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; 499 sd.Flags = 0; 500 501 HTEST(mOutput.pDxgiFactory->CreateSwapChain(mOutput.pDevice, &sd, &mOutput.pSwapChain)); 502 503 HTEST(mOutput.pSwapChain->ResizeBuffers(1, mRTWidth, mRTHeight, DXGI_FORMAT_B8G8R8A8_UNORM, 0)); 504 505 HTEST(mOutput.pDevice->OpenSharedResource(mSharedHandle, __uuidof(ID3D11Texture2D), (void**)&mOutput.pSharedTexture)); 506 HTEST(mOutput.pSharedTexture->QueryInterface(__uuidof(IDXGIKeyedMutex), (LPVOID*)&mOutput.pDXGIKeyedMutex)); 507 } 388 508 } 389 509 … … 693 813 float elapsed = 0; 694 814 815 bool const fDirectOutput = mpRender->IsDirectOutputRequired(this); 816 695 817 D3D11BLITTER Blitter; 696 BlitInit(&Blitter, mOutput.pDevice, mOutput.pImmediateContext); 818 if (fDirectOutput) 819 RT_ZERO(Blitter); 820 else 821 BlitInit(&Blitter, mOutput.pDevice, mOutput.pImmediateContext); 697 822 698 823 do … … 744 869 mpRender->TimeAdvance(dt); 745 870 746 DWORD result = mRender.pDXGIKeyedMutex->AcquireSync(0, 1000); 747 if (result == WAIT_OBJECT_0) 871 if (fDirectOutput) 748 872 { 749 /* 750 * Use the shared texture from the render device. 751 */ 752 mRender.pImmediateContext->OMSetRenderTargets(1, &mRender.pRenderTargetView, mRender.pDepthStencilView); 753 mpRender->DoRender(this); 873 ID3D11Texture2D *pBackBuffer = NULL; 874 HTEST(mOutput.pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBackBuffer))); 875 if (pBackBuffer) 876 { 877 ID3D11RenderTargetView *pRenderTargetView = 0; 878 HTEST(mRender.pDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView)); 879 880 mRender.pImmediateContext->OMSetRenderTargets(1, &pRenderTargetView, mRender.pDepthStencilView); 881 882 mRender.pRenderTargetView = pRenderTargetView; 883 mpRender->DoRender(this); 884 mRender.pRenderTargetView = NULL; 885 886 D3D_RELEASE(pRenderTargetView); 887 D3D_RELEASE(pBackBuffer); 888 } 889 else 890 D3DTestShowError(hr, "pSwapChain->GetBuffer (DirectOutput)"); 754 891 } 755 892 else 756 D3DTestShowError(hr, "Render.AcquireSync(0)");757 result = mRender.pDXGIKeyedMutex->ReleaseSync(1);758 if (result == WAIT_OBJECT_0)759 { }760 else761 D3DTestShowError(hr, "Render.ReleaseSync(1)");762 763 /*764 * Copy the rendered scene to the backbuffer and present.765 */766 ID3D11Texture2D *pBackBuffer = NULL;767 HTEST(mOutput.pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBackBuffer)));768 if (pBackBuffer)769 893 { 770 result = mOutput.pDXGIKeyedMutex->AcquireSync(1, 1000);894 DWORD result = mRender.pDXGIKeyedMutex->AcquireSync(0, 1000); 771 895 if (result == WAIT_OBJECT_0) 772 896 { 773 897 /* 774 * Use the shared texture from the outputdevice.898 * Use the shared texture from the render device. 775 899 */ 776 float cDstWidth = static_cast<float>(mRTWidth); 777 float cDstHeight = static_cast<float>(mRTHeight); 778 779 D3D11_RECT rectDst; 780 rectDst.left = 0; 781 rectDst.top = 0; 782 rectDst.right = mRTWidth; 783 rectDst.bottom = mRTHeight; 784 785 ID3D11ShaderResourceView *pShaderResourceView = 0; 786 HTEST(Blitter.pDevice->CreateShaderResourceView(mOutput.pSharedTexture, NULL, &pShaderResourceView)); 787 788 ID3D11RenderTargetView *pRenderTargetView = 0; 789 HTEST(Blitter.pDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView)); 790 791 BlitFromTexture(&Blitter, pRenderTargetView, cDstWidth, cDstHeight, rectDst, pShaderResourceView); 792 793 D3D_RELEASE(pRenderTargetView); 794 D3D_RELEASE(pShaderResourceView); 900 mRender.pImmediateContext->OMSetRenderTargets(1, &mRender.pRenderTargetView, mRender.pDepthStencilView); 901 mpRender->DoRender(this); 795 902 } 796 903 else 797 D3DTestShowError(hr, " Output.AcquireSync(1)");798 result = m Output.pDXGIKeyedMutex->ReleaseSync(0);904 D3DTestShowError(hr, "Render.AcquireSync(0)"); 905 result = mRender.pDXGIKeyedMutex->ReleaseSync(1); 799 906 if (result == WAIT_OBJECT_0) 800 907 { } 801 908 else 802 D3DTestShowError(hr, "Output.ReleaseSync(0)"); 803 804 D3D_RELEASE(pBackBuffer); 909 D3DTestShowError(hr, "Render.ReleaseSync(1)"); 910 911 /* 912 * Copy the rendered scene to the backbuffer and present. 913 */ 914 ID3D11Texture2D *pBackBuffer = NULL; 915 HTEST(mOutput.pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBackBuffer))); 916 if (pBackBuffer) 917 { 918 result = mOutput.pDXGIKeyedMutex->AcquireSync(1, 1000); 919 if (result == WAIT_OBJECT_0) 920 { 921 /* 922 * Use the shared texture from the output device. 923 */ 924 float cDstWidth = static_cast<float>(mRTWidth); 925 float cDstHeight = static_cast<float>(mRTHeight); 926 927 D3D11_RECT rectDst; 928 rectDst.left = 0; 929 rectDst.top = 0; 930 rectDst.right = mRTWidth; 931 rectDst.bottom = mRTHeight; 932 933 ID3D11ShaderResourceView *pShaderResourceView = 0; 934 HTEST(Blitter.pDevice->CreateShaderResourceView(mOutput.pSharedTexture, NULL, &pShaderResourceView)); 935 936 ID3D11RenderTargetView *pRenderTargetView = 0; 937 HTEST(Blitter.pDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView)); 938 939 BlitFromTexture(&Blitter, pRenderTargetView, cDstWidth, cDstHeight, rectDst, pShaderResourceView); 940 941 D3D_RELEASE(pRenderTargetView); 942 D3D_RELEASE(pShaderResourceView); 943 } 944 else 945 D3DTestShowError(hr, "Output.AcquireSync(1)"); 946 result = mOutput.pDXGIKeyedMutex->ReleaseSync(0); 947 if (result == WAIT_OBJECT_0) 948 { } 949 else 950 D3DTestShowError(hr, "Output.ReleaseSync(0)"); 951 952 D3D_RELEASE(pBackBuffer); 953 } 805 954 } 806 955 -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d11render.cpp
r100055 r103983 28 28 #include "d3d11render.h" 29 29 30 31 /* 32 * Utilities 33 */ 30 34 31 35 #if 0 … … 677 681 } 678 682 683 //#include "D3D11RenderVMCloud.txt" 679 684 680 685 /* … … 696 701 case 4: 697 702 return new D3D11RenderDrawIndexed(); 703 // case 5: 704 // return new D3D11RenderTest(); 698 705 default: 699 706 break; -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d11render.h
r101082 r103983 32 32 #endif 33 33 34 #include <d3d11 .h>34 #include <d3d11_1.h> 35 35 36 36 #include <iprt/asm.h> … … 87 87 virtual void TimeAdvance(float dt) { (void)dt; return; } 88 88 virtual bool IsDepthStencilBufferRequired(D3D11DeviceProvider *pDP) { (void)pDP; return true; } 89 virtual bool IsDirectOutputRequired(D3D11DeviceProvider *pDP) { (void)pDP; return false; } 89 90 }; 90 91 … … 92 93 void DeleteRender(D3D11Render *pRender); 93 94 95 uint8_t *readBmpFile(char const *pszFilename, uint32_t cbPixel, uint32_t *pWidth, uint32_t *pHeight, uint32_t *pcbData); 96 94 97 #endif /* !GA_INCLUDED_SRC_WINNT_Graphics_Video_disp_wddm_gallium_test_d3d11render_h */
Note:
See TracChangeset
for help on using the changeset viewer.