From 62dff3401cd7adbece3bec03fabfd56cc8d8218b Mon Sep 17 00:00:00 2001 From: Fernando Velazquez Innella Date: Fri, 16 Jun 2023 15:50:31 -0400 Subject: [PATCH] c/client: Wait till D3D12 images aren't in use before releasing the swapchain This adds a fence signal + CPU wait on the compositor queue before destroying the swapchain. It fixes a crash in the OpenXR CTS automated tests for D3D12. --- .../compositor/client/comp_d3d12_client.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/xrt/compositor/client/comp_d3d12_client.cpp b/src/xrt/compositor/client/comp_d3d12_client.cpp index 65837f56a..f9f84c542 100644 --- a/src/xrt/compositor/client/comp_d3d12_client.cpp +++ b/src/xrt/compositor/client/comp_d3d12_client.cpp @@ -396,8 +396,24 @@ client_d3d12_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index) static void client_d3d12_swapchain_destroy(struct xrt_swapchain *xsc) { - // letting destruction do it all + /* + * Letting automatic destruction do it all, happens at the end of + * this function once the sc variable goes out of scope. + */ std::unique_ptr sc(as_client_d3d12_swapchain(xsc)); + + // this swapchain resources may be in flight, wait till compositor finishes using them + struct client_d3d12_compositor *c = sc->c; + if (c && c->fence) { + c->timeline_semaphore_value++; + HRESULT hr = c->app_queue->Signal(c->fence.get(), c->timeline_semaphore_value); + + xrt::auxiliary::d3d::d3d12::waitOnFenceWithTimeout( // + c->fence, // + c->local_wait_event, // + c->timeline_semaphore_value, // + kFenceTimeout); // + } }