From 13ea0ab546c4297814cd6d2a7c6dd85e423f9145 Mon Sep 17 00:00:00 2001 From: Fernando Velazquez Innella Date: Wed, 6 Mar 2024 11:04:29 -0500 Subject: [PATCH] c/client: Run D3D12 swapchain initial barriers after all possible points of failure. --- .../compositor/client/comp_d3d12_client.cpp | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/xrt/compositor/client/comp_d3d12_client.cpp b/src/xrt/compositor/client/comp_d3d12_client.cpp index 678037753..8ba32c4e6 100644 --- a/src/xrt/compositor/client/comp_d3d12_client.cpp +++ b/src/xrt/compositor/client/comp_d3d12_client.cpp @@ -525,33 +525,6 @@ try { /// @todo No idea if this is right, might depend on whether it's the compute or graphics compositor! D3D12_RESOURCE_STATES compositorResourceState = D3D12_RESOURCE_STATE_COMMON; - // app_images do not inherit the initial state of images, so - // transition all app images from _COMMON to the correct state - { - D3D12_RESOURCE_BARRIER barrier{}; - barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON; - barrier.Transition.StateAfter = appResourceState; - barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; - - data->state.resize(image_count, barrier.Transition.StateAfter); - - std::vector barriers; - for (const auto &image : data->app_images) { - barrier.Transition.pResource = image.get(); - barriers.emplace_back(barrier); - } - wil::com_ptr commandList; - THROW_IF_FAILED(c->device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, - c->command_allocator.get(), nullptr, - IID_PPV_ARGS(commandList.put()))); - commandList->ResourceBarrier((UINT)barriers.size(), barriers.data()); - commandList->Close(); - std::array commandLists{commandList.get()}; - - c->app_queue->ExecuteCommandLists((UINT)commandLists.size(), commandLists.data()); - } - data->appResourceState = appResourceState; data->compositorResourceState = compositorResourceState; @@ -662,6 +635,33 @@ try { return xret; } + // app_images do not inherit the initial state of images, so + // transition all app images from _COMMON to the correct state + { + D3D12_RESOURCE_BARRIER barrier{}; + barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON; + barrier.Transition.StateAfter = appResourceState; + barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + + data->state.resize(image_count, barrier.Transition.StateAfter); + + std::vector barriers; + for (const auto &image : data->app_images) { + barrier.Transition.pResource = image.get(); + barriers.emplace_back(barrier); + } + wil::com_ptr commandList; + THROW_IF_FAILED(c->device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, + c->command_allocator.get(), nullptr, + IID_PPV_ARGS(commandList.put()))); + commandList->ResourceBarrier((UINT)barriers.size(), barriers.data()); + commandList->Close(); + std::array commandLists{commandList.get()}; + + c->app_queue->ExecuteCommandLists((UINT)commandLists.size(), commandLists.data()); + } + auto release_image_fn = compositorNeedsCopy // ? client_d3d12_swapchain_release_image_copy : client_d3d12_swapchain_release_image;