Changeset 86815 in vbox for trunk/src/VBox/Additions/WINNT/Graphics/Video
- Timestamp:
- Nov 5, 2020 9:45:32 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 141259
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test
- Files:
-
- 2 added
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/Makefile.kmk
r82968 r86815 36 36 VBoxGaD3DTest-x86_BLD_TRG_ARCH = x86 37 37 38 39 PROGRAMS += VBoxD3D11 40 VBoxD3D11_TEMPLATE = VBoxR3StaticNonPedantic 41 VBoxD3D11_SDKS = WINDDK80 42 VBoxD3D11_CXXFLAGS += -wd4458 -wd4838 -wd5029 -wd5039 43 VBoxD3D11_LIBS = d3d11.lib 44 VBoxD3D11_SOURCES = \ 45 d3d11main.cpp \ 46 d3d11render.cpp 47 48 # 49 # 32-bit version of VBoxD3D11. 50 # 51 PROGRAMS.amd64 += VBoxD3D11-x86 52 VBoxD3D11-x86_EXTENDS = VBoxD3D11 53 VBoxD3D11-x86_BLD_TRG_ARCH = x86 54 38 55 include $(FILE_KBUILD_SUB_FOOTER) -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d11main.cpp
r86251 r86815 1 1 /* $Id$ */ 2 2 /** @file 3 * Gallium D3D testcase. Win32 application to run Gallium D3D9tests.3 * D3D testcase. Win32 application to run D3D11 tests. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #include "d3d 9render.h"18 #include "d3d11render.h" 19 19 20 20 #include <stdio.h> 21 21 22 #define D3D9TEST_MAX_DEVICES 2 23 24 class D3D9Test : public D3D9DeviceProvider 22 class D3D11Test : public D3D11DeviceProvider 25 23 { 26 24 public: 27 D3D 9Test();28 ~D3D 9Test();25 D3D11Test(); 26 ~D3D11Test(); 29 27 30 28 HRESULT Init(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow); 31 29 int Run(); 32 30 33 virtual int DeviceCount(); 34 virtual IDirect3DDevice9 *Device(int index); 31 virtual ID3D11Device *Device(); 32 virtual ID3D11DeviceContext *ImmediateContext(); 33 virtual ID3D11RenderTargetView *RenderTargetView(); 35 34 36 35 private: 37 36 HRESULT initWindow(HINSTANCE hInstance, int nCmdShow); 38 HRESULT initDirect3D 9(int cDevices);37 HRESULT initDirect3D11(); 39 38 void parseCmdLine(LPSTR lpCmdLine); 40 39 static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); … … 47 46 RenderModeFPS = 2 48 47 } miRenderMode; 48 49 49 HWND mHwnd; 50 IDirect3D9Ex *mpD3D9; 51 int mcDevices; 52 IDirect3DDevice9 *mpaDevices[D3D9TEST_MAX_DEVICES]; 53 D3D9Render *mpRender; 54 55 D3DPRESENT_PARAMETERS mPP; 50 51 struct 52 { 53 ID3D11Device *pDevice; /* Device for rendering. */ 54 ID3D11DeviceContext *pImmediateContext; /* Associated context. */ 55 IDXGIFactory *pDxgiFactory; /* DXGI Factory associated with the rendering device. */ 56 ID3D11Texture2D *pRenderTarget; /* The render target. */ 57 ID3D11RenderTargetView *pRenderTargetView; /* The render target view. */ 58 IDXGIResource *pDxgiResource; /* Interface of the render target. */ 59 IDXGIKeyedMutex *pDXGIKeyedMutex; /* Synchronization interface for the render device. */ 60 } mRender; 61 62 HANDLE mSharedHandle; 63 64 struct 65 { 66 ID3D11Device *pDevice; /* Device for the output drawing. */ 67 ID3D11DeviceContext *pImmediateContext; /* Corresponding context. */ 68 IDXGIFactory *pDxgiFactory; /* DXGI Factory associated with the output device. */ 69 IDXGISwapChain *pSwapChain; /* Swap chain for displaying in the mHwnd window. */ 70 ID3D11Texture2D *pSharedTexture; /* The texture to draw. Shared resource of mRender.pRenderTarget */ 71 IDXGIKeyedMutex *pDXGIKeyedMutex; /* Synchronization interface for the render device. */ 72 } mOutput; 73 74 D3D11Render *mpRender; 56 75 }; 57 76 58 D3D 9Test::D3D9Test()77 D3D11Test::D3D11Test() 59 78 : 60 miRenderId( 3),79 miRenderId(1), 61 80 miRenderMode(RenderModeStep), 62 81 mHwnd(0), 63 mpD3D9(0), 64 mcDevices(1), 82 mSharedHandle(0), 65 83 mpRender(0) 66 84 { 67 memset(&mpaDevices, 0, sizeof(mpaDevices));68 memset(&mPP, 0, sizeof(mPP));69 } 70 71 D3D 9Test::~D3D9Test()85 RT_ZERO(mRender); 86 RT_ZERO(mOutput); 87 } 88 89 D3D11Test::~D3D11Test() 72 90 { 73 91 if (mpRender) … … 76 94 mpRender = 0; 77 95 } 78 for (int i = 0; i < mcDevices; ++i) 79 { 80 if (mpaDevices[i]) 81 { 82 mpaDevices[i]->Release(); 83 mpaDevices[i] = 0; 84 } 85 } 86 87 if (mpD3D9) 88 { 89 mpD3D9->Release(); 90 mpD3D9 = 0; 91 } 92 } 93 94 LRESULT CALLBACK D3D9Test::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 96 97 if (mOutput.pImmediateContext) 98 mOutput.pImmediateContext->ClearState(); 99 if (mRender.pImmediateContext) 100 mRender.pImmediateContext->ClearState(); 101 102 D3D_RELEASE(mOutput.pDevice); 103 D3D_RELEASE(mOutput.pImmediateContext); 104 D3D_RELEASE(mOutput.pDxgiFactory); 105 D3D_RELEASE(mOutput.pSwapChain); 106 D3D_RELEASE(mOutput.pSharedTexture); 107 D3D_RELEASE(mOutput.pDXGIKeyedMutex); 108 109 D3D_RELEASE(mRender.pDevice); 110 D3D_RELEASE(mRender.pImmediateContext); 111 D3D_RELEASE(mRender.pDxgiFactory); 112 D3D_RELEASE(mRender.pRenderTarget); 113 D3D_RELEASE(mRender.pRenderTargetView); 114 D3D_RELEASE(mRender.pDxgiResource); 115 D3D_RELEASE(mRender.pDXGIKeyedMutex); 116 } 117 118 LRESULT CALLBACK D3D11Test::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 95 119 { 96 120 switch (msg) … … 109 133 } 110 134 111 HRESULT D3D 9Test::initWindow(HINSTANCE hInstance,135 HRESULT D3D11Test::initWindow(HINSTANCE hInstance, 112 136 int nCmdShow) 113 137 { 114 138 HRESULT hr = S_OK; 115 139 116 WNDCLASSA wc = { 0 }; 140 WNDCLASSA wc; 141 RT_ZERO(wc); 117 142 wc.style = CS_HREDRAW | CS_VREDRAW; 118 143 wc.lpfnWndProc = wndProc; … … 124 149 wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 125 150 wc.lpszMenuName = 0; 126 wc.lpszClassName = "D3D 9TestWndClassName";151 wc.lpszClassName = "D3D11TestWndClassName"; 127 152 128 153 if (RegisterClassA(&wc)) … … 131 156 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, false); 132 157 133 mHwnd = CreateWindowA("D3D 9TestWndClassName",134 "D3D 9Test",158 mHwnd = CreateWindowA("D3D11TestWndClassName", 159 "D3D11 Test", 135 160 WS_OVERLAPPEDWINDOW, 136 161 100, 100, r.right, r.bottom, … … 156 181 } 157 182 158 HRESULT D3D9Test::initDirect3D9(int cDevices) 159 { 160 mcDevices = cDevices; 161 162 HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &mpD3D9); 163 if (FAILED(hr)) 164 { 165 D3DTestShowError(hr, "Direct3DCreate9Ex"); 166 return hr; 167 } 168 169 /* Verify hardware support for current screen mode. */ 170 D3DDISPLAYMODE mode; 171 hr = mpD3D9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode); 172 if (FAILED(hr)) 173 { 174 D3DTestShowError(hr, "GetAdapterDisplayMode"); 175 return hr; 176 } 177 178 hr = mpD3D9->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mode.Format, mode.Format, true); 179 if (FAILED(hr)) 180 { 181 D3DTestShowError(hr, "CheckDeviceType"); 182 return hr; 183 } 184 185 /* Create identical devices. */ 186 for (int i = 0; i < mcDevices; ++i) 187 { 188 #if 0 189 mPP.BackBufferWidth = 0; 190 mPP.BackBufferHeight = 0; 191 mPP.BackBufferFormat = D3DFMT_UNKNOWN; 192 #else 193 mPP.BackBufferWidth = 640; 194 mPP.BackBufferHeight = 480; 195 mPP.BackBufferFormat = D3DFMT_X8R8G8B8; 183 static HRESULT d3d11TestCreateDevice(ID3D11Device **ppDevice, 184 ID3D11DeviceContext **ppImmediateContext, 185 IDXGIFactory **ppDxgiFactory) 186 { 187 HRESULT hr = S_OK; 188 189 IDXGIAdapter *pAdapter = NULL; /* Default adapter. */ 190 static const D3D_FEATURE_LEVEL aFeatureLevels[] = 191 { 192 D3D_FEATURE_LEVEL_11_1, 193 D3D_FEATURE_LEVEL_11_0, 194 D3D_FEATURE_LEVEL_9_3, 195 }; 196 UINT Flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; 197 #ifdef DEBUG 198 Flags |= D3D11_CREATE_DEVICE_DEBUG; 196 199 #endif 197 mPP.BackBufferCount = 1; 198 mPP.MultiSampleType = D3DMULTISAMPLE_NONE; 199 mPP.MultiSampleQuality = 0; 200 mPP.SwapEffect = D3DSWAPEFFECT_DISCARD; 201 mPP.hDeviceWindow = mHwnd; 202 mPP.Windowed = true; 203 mPP.EnableAutoDepthStencil = true; 204 mPP.AutoDepthStencilFormat = D3DFMT_D24S8; 205 mPP.Flags = 0; 206 mPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; 207 mPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; 208 209 hr = mpD3D9->CreateDevice(D3DADAPTER_DEFAULT, 210 D3DDEVTYPE_HAL, 211 mHwnd, 212 D3DCREATE_HARDWARE_VERTEXPROCESSING, 213 &mPP, 214 &mpaDevices[i]); 215 if (FAILED(hr)) 216 { 217 D3DTestShowError(hr, "CreateDevice"); 218 } 219 } 200 D3D_FEATURE_LEVEL FeatureLevel = D3D_FEATURE_LEVEL_9_1; 201 202 HTEST(D3D11CreateDevice(pAdapter, 203 D3D_DRIVER_TYPE_HARDWARE, 204 NULL, 205 Flags, 206 aFeatureLevels, 207 RT_ELEMENTS(aFeatureLevels), 208 D3D11_SDK_VERSION, 209 ppDevice, 210 &FeatureLevel, 211 ppImmediateContext)); 212 213 if (FeatureLevel != D3D_FEATURE_LEVEL_11_1) 214 { 215 D3DTestShowError(hr, "FeatureLevel"); 216 } 217 218 IDXGIDevice *pDxgiDevice = 0; 219 hr = (*ppDevice)->QueryInterface(__uuidof(IDXGIDevice), (void**)&pDxgiDevice); 220 if (SUCCEEDED(hr)) 221 { 222 IDXGIAdapter *pDxgiAdapter = 0; 223 hr = pDxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&pDxgiAdapter); 224 if (SUCCEEDED(hr)) 225 { 226 HTEST(pDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)ppDxgiFactory)); 227 D3D_RELEASE(pDxgiAdapter); 228 } 229 else 230 D3DTestShowError(hr, "IDXGIAdapter"); 231 232 D3D_RELEASE(pDxgiDevice); 233 } 234 else 235 D3DTestShowError(hr, "IDXGIDevice"); 220 236 221 237 return hr; 222 238 } 223 239 224 void D3D9Test::parseCmdLine(LPSTR lpCmdLine) 225 { 226 /* Very simple: test number followed by step flag. 227 * Default is test 0, step mode: 0 1 240 HRESULT D3D11Test::initDirect3D11() 241 { 242 HRESULT hr = S_OK; 243 244 /* 245 * Render. 228 246 */ 247 d3d11TestCreateDevice(&mRender.pDevice, 248 &mRender.pImmediateContext, 249 &mRender.pDxgiFactory); 250 if (mRender.pDevice) 251 { 252 D3D11_TEXTURE2D_DESC texDesc; 253 RT_ZERO(texDesc); 254 texDesc.Width = 800; 255 texDesc.Height = 600; 256 texDesc.MipLevels = 1; 257 texDesc.ArraySize = 1; 258 texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 259 texDesc.SampleDesc.Count = 1; 260 texDesc.SampleDesc.Quality = 0; 261 texDesc.Usage = D3D11_USAGE_DEFAULT; 262 texDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; 263 texDesc.CPUAccessFlags = 0; 264 texDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX; 265 266 HTEST(mRender.pDevice->CreateTexture2D(&texDesc, 0, &mRender.pRenderTarget)); 267 HTEST(mRender.pDevice->CreateRenderTargetView(mRender.pRenderTarget, 0, &mRender.pRenderTargetView)); 268 269 /* Get the shared handle. */ 270 HTEST(mRender.pRenderTarget->QueryInterface(__uuidof(IDXGIResource), (void**)&mRender.pDxgiResource)); 271 HTEST(mRender.pDxgiResource->GetSharedHandle(&mSharedHandle)); 272 273 HTEST(mRender.pRenderTarget->QueryInterface(__uuidof(IDXGIKeyedMutex), (LPVOID*)&mRender.pDXGIKeyedMutex)); 274 } 275 276 if (mRender.pImmediateContext) 277 { 278 // Set the viewport transform. 279 D3D11_VIEWPORT mScreenViewport; 280 mScreenViewport.TopLeftX = 0; 281 mScreenViewport.TopLeftY = 0; 282 mScreenViewport.Width = static_cast<float>(800); 283 mScreenViewport.Height = static_cast<float>(600); 284 mScreenViewport.MinDepth = 0.0f; 285 mScreenViewport.MaxDepth = 1.0f; 286 287 mRender.pImmediateContext->RSSetViewports(1, &mScreenViewport); 288 } 289 290 /* 291 * Output. 292 */ 293 d3d11TestCreateDevice(&mOutput.pDevice, 294 &mOutput.pImmediateContext, 295 &mOutput.pDxgiFactory); 296 if (mOutput.pDxgiFactory) 297 { 298 DXGI_SWAP_CHAIN_DESC sd; 299 RT_ZERO(sd); 300 sd.BufferDesc.Width = 800; 301 sd.BufferDesc.Height = 600; 302 sd.BufferDesc.RefreshRate.Numerator = 60; 303 sd.BufferDesc.RefreshRate.Denominator = 1; 304 sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 305 sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; 306 sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; 307 sd.SampleDesc.Count = 1; 308 sd.SampleDesc.Quality = 0; 309 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 310 sd.BufferCount = 1; 311 sd.OutputWindow = mHwnd; 312 sd.Windowed = true; 313 sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; 314 sd.Flags = 0; 315 316 HTEST(mOutput.pDxgiFactory->CreateSwapChain(mOutput.pDevice, &sd, &mOutput.pSwapChain)); 317 318 HTEST(mOutput.pSwapChain->ResizeBuffers(1, 800, 600, DXGI_FORMAT_B8G8R8A8_UNORM, 0)); 319 320 HTEST(mOutput.pDevice->OpenSharedResource(mSharedHandle, __uuidof(ID3D11Texture2D), (void**)&mOutput.pSharedTexture)); 321 HTEST(mOutput.pSharedTexture->QueryInterface(__uuidof(IDXGIKeyedMutex), (LPVOID*)&mOutput.pDXGIKeyedMutex)); 322 } 323 324 return hr; 325 } 326 327 void D3D11Test::parseCmdLine(LPSTR lpCmdLine) 328 { 329 /* Very simple: a test identifier followed by the render mode. */ 229 330 if (!lpCmdLine) 230 331 return; … … 261 362 } 262 363 263 HRESULT D3D 9Test::Init(HINSTANCE hInstance,364 HRESULT D3D11Test::Init(HINSTANCE hInstance, 264 365 LPSTR lpCmdLine, 265 366 int nCmdShow) … … 273 374 if (mpRender) 274 375 { 275 const int cDevices = mpRender->RequiredDeviceCount(); 276 hr = initDirect3D9(cDevices); 376 hr = initDirect3D11(); 277 377 if (SUCCEEDED(hr)) 278 378 { … … 286 386 else 287 387 { 388 D3DTestShowError(0, "No render"); 288 389 hr = E_FAIL; 289 390 } … … 293 394 } 294 395 295 int D3D9Test::Run() 296 { 396 int D3D11Test::Run() 397 { 398 HRESULT hr = S_OK; 399 297 400 bool fFirst = true; 298 401 MSG msg; … … 351 454 if (mpRender) 352 455 { 456 /* 457 * Render the scene. 458 */ 353 459 mpRender->TimeAdvance(dt); 354 mpRender->DoRender(this); 460 461 DWORD result = mRender.pDXGIKeyedMutex->AcquireSync(0, 1000); 462 if (result == WAIT_OBJECT_0) 463 { 464 /* 465 * Use the shared texture from the render device. 466 */ 467 mRender.pImmediateContext->OMSetRenderTargets(1, &mRender.pRenderTargetView, NULL); 468 mpRender->DoRender(this); 469 } 470 else 471 D3DTestShowError(hr, "Render.AcquireSync(0)"); 472 result = mRender.pDXGIKeyedMutex->ReleaseSync(1); 473 if (result == WAIT_OBJECT_0) 474 { } 475 else 476 D3DTestShowError(hr, "Render.ReleaseSync(1)"); 477 478 /* 479 * Copy the rendered scene to the backbuffer and present. 480 */ 481 ID3D11Texture2D *pBackBuffer = NULL; 482 HTEST(mOutput.pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBackBuffer))); 483 if (pBackBuffer) 484 { 485 result = mOutput.pDXGIKeyedMutex->AcquireSync(1, 1000); 486 if (result == WAIT_OBJECT_0) 487 { 488 /* 489 * Use the shared texture from the output device. 490 */ 491 mOutput.pImmediateContext->CopyResource(pBackBuffer, mOutput.pSharedTexture); 492 } 493 else 494 D3DTestShowError(hr, "Output.AcquireSync(1)"); 495 result = mOutput.pDXGIKeyedMutex->ReleaseSync(0); 496 if (result == WAIT_OBJECT_0) 497 { } 498 else 499 D3DTestShowError(hr, "Output.ReleaseSync(0)"); 500 501 D3D_RELEASE(pBackBuffer); 502 } 503 504 HTEST(mOutput.pSwapChain->Present(0, 0)); 505 355 506 fFirst = false; 356 507 } … … 364 515 float msPerFrame = elapsed * 1000.0f / cFrames; 365 516 char sz[256]; 366 _snprintf(sz, sizeof(sz), "D3D 9Test FPS %d Frame Time %fms", cFrames, msPerFrame);517 _snprintf(sz, sizeof(sz), "D3D11 Test FPS %d Frame Time %fms", cFrames, msPerFrame); 367 518 SetWindowTextA(mHwnd, sz); 368 519 … … 379 530 } 380 531 381 int D3D9Test::DeviceCount() 382 { 383 return mcDevices; 384 } 385 386 IDirect3DDevice9 *D3D9Test::Device(int index) 387 { 388 if (index < mcDevices) 389 return mpaDevices[index]; 390 return NULL; 532 ID3D11Device *D3D11Test::Device() 533 { 534 return mRender.pDevice; 535 } 536 537 ID3D11DeviceContext *D3D11Test::ImmediateContext() 538 { 539 return mRender.pImmediateContext; 540 } 541 542 ID3D11RenderTargetView *D3D11Test::RenderTargetView() 543 { 544 return mRender.pRenderTargetView; 391 545 } 392 546 … … 399 553 400 554 int result = 0; 401 D3D 9Test test;555 D3D11Test test; 402 556 403 557 HRESULT hr = test.Init(hInstance, lpCmdLine, nCmdShow);
Note:
See TracChangeset
for help on using the changeset viewer.