diff --git a/src/xrt/auxiliary/d3d/d3d_d3d12_allocator.cpp b/src/xrt/auxiliary/d3d/d3d_d3d12_allocator.cpp index 0295116d6..3db8298bc 100644 --- a/src/xrt/auxiliary/d3d/d3d_d3d12_allocator.cpp +++ b/src/xrt/auxiliary/d3d/d3d_d3d12_allocator.cpp @@ -1,10 +1,11 @@ -// Copyright 2020-2022, Collabora, Ltd. +// Copyright 2020-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief D3D12 backed image buffer allocator. * @author Rylie Pavlik * @author Fernando Velazquez Innella + * @author Korcan Hussein * @ingroup aux_d3d */ @@ -74,7 +75,8 @@ allocateSharedImages(ID3D12Device &device, const xrt_swapchain_create_info &xsci, size_t image_count, std::vector> &out_images, - std::vector &out_handles) + std::vector &out_handles, + std::uint64_t &out_image_mem_size) try { if (0 != (xsci.create & XRT_SWAPCHAIN_CREATE_PROTECTED_CONTENT)) { return XRT_ERROR_SWAPCHAIN_FLAG_VALID_BUT_UNSUPPORTED; @@ -155,6 +157,8 @@ try { } out_images = std::move(images); out_handles = std::move(handles); + const D3D12_RESOURCE_ALLOCATION_INFO alloc_info = device.GetResourceAllocationInfo(0, 1, &desc); + out_image_mem_size = alloc_info.SizeInBytes; return XRT_SUCCESS; } DEFAULT_CATCH(XRT_ERROR_ALLOCATION) @@ -177,6 +181,7 @@ d3d12_images_allocate(struct xrt_image_native_allocator *xina, try { d3d12_allocator *d3da = reinterpret_cast(xina); + std::uint64_t image_mem_size = 0; std::vector> images; std::vector handles; auto result = xrt::auxiliary::d3d::d3d12::allocateSharedImages( // @@ -184,7 +189,8 @@ d3d12_images_allocate(struct xrt_image_native_allocator *xina, *xsci, // xsci image_count, // image_count images, // out_images - handles); // out_handles + handles, // out_handles + image_mem_size); // out_image_mem_size (in bytes) if (result != XRT_SUCCESS) { return result; @@ -193,6 +199,7 @@ d3d12_images_allocate(struct xrt_image_native_allocator *xina, for (size_t i = 0; i < image_count; ++i) { out_images[i].handle = handles[i].release(); out_images[i].is_dxgi_handle = false; + out_images[i].size = image_mem_size; } return XRT_SUCCESS; diff --git a/src/xrt/auxiliary/d3d/d3d_d3d12_allocator.hpp b/src/xrt/auxiliary/d3d/d3d_d3d12_allocator.hpp index 034f0957c..2bf4d165c 100644 --- a/src/xrt/auxiliary/d3d/d3d_d3d12_allocator.hpp +++ b/src/xrt/auxiliary/d3d/d3d_d3d12_allocator.hpp @@ -1,10 +1,11 @@ -// Copyright 2020-2023, Collabora, Ltd. +// Copyright 2020-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Higher-level D3D12-backed image buffer allocation routine. * @author Rylie Pavlik * @author Fernando Velazquez Innella + * @author Korcan Hussein * @ingroup aux_d3d */ @@ -17,6 +18,7 @@ #include #include +#include #include @@ -32,6 +34,7 @@ namespace xrt::auxiliary::d3d::d3d12 { * @param keyed_mutex Whether to create images with a shared "keyed mutex" as well * @param[out] out_images A vector that will be cleared and populated with the images. * @param[out] out_handles A vector that will be cleared and populated with the corresponding native handles. + * @param[out] out_image_mem_size The image memory allocation size in bytes * * @return xrt_result_t, one of: * - @ref XRT_SUCCESS @@ -45,6 +48,7 @@ allocateSharedImages(ID3D12Device &device, const xrt_swapchain_create_info &xsci, size_t image_count, std::vector> &out_images, - std::vector &out_handles); + std::vector &out_handles, + std::uint64_t &out_image_mem_size); }; // namespace xrt::auxiliary::d3d::d3d12 diff --git a/src/xrt/compositor/client/comp_d3d12_client.cpp b/src/xrt/compositor/client/comp_d3d12_client.cpp index bb5815d72..ced57a5f0 100644 --- a/src/xrt/compositor/client/comp_d3d12_client.cpp +++ b/src/xrt/compositor/client/comp_d3d12_client.cpp @@ -1,4 +1,4 @@ -// Copyright 2019-2023, Collabora, Ltd. +// Copyright 2019-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -6,6 +6,7 @@ * @author Rylie Pavlik * @author Jakob Bornecrantz * @author Fernando Velazquez Innella + * @author Korcan Hussein * @ingroup comp_client */ @@ -494,6 +495,7 @@ try { std::unique_ptr sc = std::make_unique(); sc->data = std::make_unique(c->log_level); auto &data = sc->data; + std::uint64_t image_mem_size = 0; // Allocate images xret = xrt::auxiliary::d3d::d3d12::allocateSharedImages( // @@ -501,7 +503,8 @@ try { xinfo, // image_count, // data->images, // - data->handles); // + data->handles, // + image_mem_size); // if (xret != XRT_SUCCESS) { return xret; } @@ -597,7 +600,8 @@ try { xinfo, // xsci image_count, // image_count data->comp_images, // out_images - data->comp_handles); // out_handles + data->comp_handles, // out_handles + image_mem_size); // out_image_mem_size (in bytes) if (xret != XRT_SUCCESS) { return xret; } @@ -628,7 +632,8 @@ try { std::vector &handles = compositorNeedsCopy ? data->comp_handles : data->handles; // Import into the native compositor, to create the corresponding swapchain which we wrap. - xret = xrt::compositor::client::importFromHandleDuplicates(*(c->xcn), handles, vkinfo, true, sc->xsc); + xret = xrt::compositor::client::importFromHandleDuplicates(*(c->xcn), handles, vkinfo, image_mem_size, true, + sc->xsc); if (xret != XRT_SUCCESS) { D3D_ERROR(c, "Error importing D3D swapchain into native compositor"); return xret; diff --git a/src/xrt/compositor/client/comp_d3d_common.hpp b/src/xrt/compositor/client/comp_d3d_common.hpp index a5541628d..a30b6b2f6 100644 --- a/src/xrt/compositor/client/comp_d3d_common.hpp +++ b/src/xrt/compositor/client/comp_d3d_common.hpp @@ -1,4 +1,4 @@ -// Copyright 2019-2022, Collabora, Ltd. +// Copyright 2019-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -6,6 +6,7 @@ * @author Rylie Pavlik * @author Jakob Bornecrantz * @author Fernando Velazquez Innella + * @author Korcan Hussein * @ingroup comp_client */ #pragma once @@ -41,6 +42,7 @@ using unique_swapchain_ref = * @param xcn The native compositor * @param handles A vector of uniquely-owned handles. These will be duplicated, not consumed, by this import. * @param vkinfo The swapchain create info, with format as a Vulkan constant + * @param image_mem_size The image memory allocation size in bytes * @param use_dedicated_allocation Passed through to @ref xrt_image_native * @param[out] out_xsc The swapchain to populate * @return XRT_SUCCESS if everything went well, otherwise whatever error a call internally returned. @@ -49,6 +51,7 @@ static inline xrt_result_t importFromHandleDuplicates(xrt_compositor_native &xcn, std::vector const &handles, const struct xrt_swapchain_create_info &vkinfo, + const std::uint64_t image_mem_size, bool use_dedicated_allocation, unique_swapchain_ref &out_xsc) { @@ -65,7 +68,7 @@ importFromHandleDuplicates(xrt_compositor_native &xcn, wil::unique_handle duped{u_graphics_buffer_ref(handle.get())}; xrt_image_native xin{}; xin.handle = duped.get(); - xin.size = 0; + xin.size = image_mem_size; xin.use_dedicated_allocation = use_dedicated_allocation; handlesForImport.emplace_back(std::move(duped));