The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tests: Add basic d3d12 client compositor tests

+99 -3
+4 -3
tests/CMakeLists.txt
··· 29 29 if(XRT_HAVE_D3D11) 30 30 list(APPEND tests tests_aux_d3d_d3d11 tests_comp_client_d3d11) 31 31 endif() 32 - # if(XRT_HAVE_D3D12) 33 - # endif() 32 + if(XRT_HAVE_D3D12) 33 + list(APPEND tests tests_comp_client_d3d12) 34 + endif() 34 35 if(XRT_HAVE_VULKAN) 35 36 list(APPEND tests tests_comp_client_vulkan) 36 37 endif() ··· 66 67 endif() 67 68 68 69 if(XRT_HAVE_D3D12) 69 - # target_link_libraries(tests_comp_client_d3d12 PRIVATE comp_client comp_mock) 70 + target_link_libraries(tests_comp_client_d3d12 PRIVATE comp_client comp_mock) 70 71 endif() 71 72 72 73 if(XRT_HAVE_VULKAN)
+95
tests/tests_comp_client_d3d12.cpp
··· 1 + // Copyright 2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Direct3D 12 tests. 6 + * @author Ryan Pavlik <ryan.pavlik@collabora.com> 7 + */ 8 + 9 + 10 + #include "mock/mock_compositor.h" 11 + #include "client/comp_d3d12_client.h" 12 + 13 + #include "catch/catch.hpp" 14 + #include "util/u_handles.h" 15 + 16 + #include <d3d/d3d_dxgi_helpers.hpp> 17 + #include <d3d/d3d_d3d12_helpers.hpp> 18 + #include <stdint.h> 19 + #include <util/u_win32_com_guard.hpp> 20 + 21 + #include <d3d11_4.h> 22 + 23 + 24 + using namespace xrt::auxiliary::d3d; 25 + using namespace xrt::auxiliary::d3d::d3d12; 26 + using namespace xrt::auxiliary::util; 27 + 28 + TEST_CASE("d3d12_client_compositor", "[.][needgpu]") 29 + { 30 + xrt_compositor_native *xcn = mock_create_native_compositor(); 31 + struct mock_compositor *mc = mock_compositor(&(xcn->base)); 32 + 33 + ComGuard comGuard; 34 + 35 + wil::com_ptr<ID3D12Device> device = createDevice(); 36 + wil::com_ptr<ID3D12CommandQueue> queue; 37 + D3D12_COMMAND_QUEUE_DESC desc{D3D12_COMMAND_LIST_TYPE_DIRECT, D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, 38 + D3D12_COMMAND_QUEUE_FLAG_NONE, 0}; 39 + device->CreateCommandQueue(&desc, IID_PPV_ARGS(queue.put())); 40 + struct xrt_compositor_d3d12 *xcd3d = client_d3d12_compositor_create(xcn, device.get(), queue.get()); 41 + struct xrt_compositor *xc = &xcd3d->base; 42 + 43 + SECTION("Swapchain create and import") 44 + { 45 + struct Data 46 + { 47 + bool nativeCreateCalled = false; 48 + 49 + bool nativeImportCalled = false; 50 + } data; 51 + mc->userdata = &data; 52 + mc->compositor_hooks.create_swapchain = 53 + [](struct mock_compositor *mc, struct mock_compositor_swapchain *mcsc, 54 + const struct xrt_swapchain_create_info *info, struct xrt_swapchain **out_xsc) { 55 + auto *data = static_cast<Data *>(mc->userdata); 56 + data->nativeCreateCalled = true; 57 + return XRT_SUCCESS; 58 + }; 59 + mc->compositor_hooks.import_swapchain = 60 + [](struct mock_compositor *mc, struct mock_compositor_swapchain *mcsc, 61 + const struct xrt_swapchain_create_info *info, struct xrt_image_native *native_images, 62 + uint32_t image_count, struct xrt_swapchain **out_xscc) { 63 + auto *data = static_cast<Data *>(mc->userdata); 64 + data->nativeImportCalled = true; 65 + // need to release the native handles to avoid leaks 66 + for (uint32_t i = 0; i < image_count; ++i) { 67 + u_graphics_buffer_unref(&native_images[i].handle); 68 + } 69 + return XRT_SUCCESS; 70 + }; 71 + xrt_swapchain_create_info xsci{}; 72 + xsci.format = DXGI_FORMAT_B8G8R8A8_UNORM_SRGB; 73 + xsci.bits = (xrt_swapchain_usage_bits)(XRT_SWAPCHAIN_USAGE_COLOR | XRT_SWAPCHAIN_USAGE_SAMPLED); 74 + xsci.sample_count = 1; 75 + xsci.width = 800; 76 + xsci.height = 600; 77 + xsci.face_count = 1; 78 + xsci.array_size = 1; 79 + xsci.mip_count = 1; 80 + SECTION("Swapchain Create") 81 + { 82 + struct xrt_swapchain *xsc = nullptr; 83 + // This will fail because the mock compositor doesn't actually import, but it will get far 84 + // enough to trigger our hook and update the flag. 85 + xrt_comp_create_swapchain(xc, &xsci, &xsc); 86 + // D3D always imports into the native compositor 87 + CHECK(data.nativeImportCalled); 88 + CHECK_FALSE(data.nativeCreateCalled); 89 + xrt_swapchain_reference(&xsc, nullptr); 90 + } 91 + } 92 + 93 + xrt_comp_destroy(&xc); 94 + xrt_comp_native_destroy(&xcn); 95 + }