The open source OpenXR runtime

c/client: Don't use wil::unique_handle it makes code more complicated

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2071>

authored by

Jakob Bornecrantz and committed by
korejan
c6842348 adacf8a9

+33 -13
+19 -7
src/xrt/compositor/client/comp_d3d11_client.cpp
··· 763 763 static void 764 764 client_d3d11_compositor_init_try_timeline_semaphores(struct client_d3d11_compositor *c) 765 765 { 766 + struct xrt_compositor_semaphore *xcsem{nullptr}; 767 + HANDLE timeline_semaphore_handle_raw{}; 768 + xrt_result_t xret; 769 + 770 + // Set the value to something non-zero. 766 771 c->timeline_semaphore_value = 1; 772 + 767 773 // See if we can make a "timeline semaphore", also known as ID3D11Fence 768 774 if (!c->xcn->base.create_semaphore || !c->xcn->base.layer_commit_with_semaphore) { 769 775 return; 770 776 } 771 - struct xrt_compositor_semaphore *xcsem = nullptr; 772 - wil::unique_handle timeline_semaphore_handle; 773 - if (XRT_SUCCESS != xrt_comp_create_semaphore(&(c->xcn->base), timeline_semaphore_handle.put(), &xcsem)) { 777 + 778 + /* 779 + * This call returns a HANDLE in the out_handle argument, it is owned by 780 + * the returned xrt_compositor_semaphore object we should not track it. 781 + */ 782 + xret = xrt_comp_create_semaphore( // 783 + &(c->xcn->base), // xc 784 + &timeline_semaphore_handle_raw, // out_handle 785 + &xcsem); // out_xcsem 786 + if (xret != XRT_SUCCESS) { 774 787 D3D_WARN(c, "Native compositor tried but failed to created a timeline semaphore for us."); 775 788 return; 776 789 } ··· 779 792 // Because importFence throws on failure we use this ref. 780 793 unique_compositor_semaphore_ref timeline_semaphore{xcsem}; 781 794 782 - // unique_compositor_semaphore_ref now owns the handle. 783 - HANDLE timeline_semaphore_handle_raw = timeline_semaphore_handle.release(); 784 - 785 - // try to import and signal 795 + // Try to import the fence. 786 796 wil::com_ptr<ID3D11Fence> fence = import_fence(*(c->fence_device), timeline_semaphore_handle_raw); 797 + 798 + // And try to signal the fence to make sure it works. 787 799 HRESULT hr = c->fence_context->Signal(fence.get(), c->timeline_semaphore_value); 788 800 if (!SUCCEEDED(hr)) { 789 801 D3D_WARN(c,
+14 -6
src/xrt/compositor/client/comp_d3d12_client.cpp
··· 1022 1022 static void 1023 1023 client_d3d12_compositor_init_try_timeline_semaphores(struct client_d3d12_compositor *c) 1024 1024 { 1025 + struct xrt_compositor_semaphore *xcsem{nullptr}; 1026 + HANDLE timeline_semaphore_handle_raw{}; 1027 + xrt_result_t xret; 1028 + 1029 + // Set the value to something non-zero. 1025 1030 c->timeline_semaphore_value = 1; 1026 1031 1027 1032 // See if we can make a "timeline semaphore", also known as ID3D12Fence ··· 1029 1034 return; 1030 1035 } 1031 1036 1032 - struct xrt_compositor_semaphore *xcsem = nullptr; 1033 - wil::unique_handle timeline_semaphore_handle; 1034 - if (XRT_SUCCESS != xrt_comp_create_semaphore(&(c->xcn->base), timeline_semaphore_handle.put(), &xcsem)) { 1037 + /* 1038 + * This call returns a HANDLE in the out_handle argument, it is owned by 1039 + * the returned xrt_compositor_semaphore object we should not track it. 1040 + */ 1041 + xret = xrt_comp_create_semaphore( // 1042 + &(c->xcn->base), // xc 1043 + &timeline_semaphore_handle_raw, // out_handle 1044 + &xcsem); // out_xcsem 1045 + if (xret != XRT_SUCCESS) { 1035 1046 D3D_WARN(c, "Native compositor tried but failed to created a timeline semaphore for us."); 1036 1047 return; 1037 1048 } ··· 1039 1050 1040 1051 // Because importFence throws on failure we use this ref. 1041 1052 unique_compositor_semaphore_ref timeline_semaphore{xcsem}; 1042 - 1043 - // unique_compositor_semaphore_ref now owns the handle. 1044 - HANDLE timeline_semaphore_handle_raw = timeline_semaphore_handle.release(); 1045 1053 1046 1054 // Try to import, importFence throws on failure. 1047 1055 wil::com_ptr<ID3D12Fence1> fence = xrt::auxiliary::d3d::d3d12::importFence( //