mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-21 06:01:43 +00:00
a/vk: Expose get_device_memory_handle as vk_get_native_handle_from_device_memory
This commit is contained in:
parent
9463de7e6f
commit
7952773908
|
@ -551,6 +551,89 @@ vk_create_image_from_native(struct vk_bundle *vk,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD)
|
||||||
|
|
||||||
|
static VkResult
|
||||||
|
get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle)
|
||||||
|
{
|
||||||
|
// vkGetMemoryFdKHR parameter
|
||||||
|
VkMemoryGetFdInfoKHR fd_info = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
|
||||||
|
.memory = device_memory,
|
||||||
|
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
|
||||||
|
};
|
||||||
|
|
||||||
|
int fd;
|
||||||
|
VkResult ret = vk->vkGetMemoryFdKHR(vk->device, &fd_info, &fd);
|
||||||
|
if (ret != VK_SUCCESS) {
|
||||||
|
// COMP_ERROR(c, "->image - vkGetMemoryFdKHR: %s",
|
||||||
|
// vk_result_string(ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_handle = fd;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
|
||||||
|
|
||||||
|
static VkResult
|
||||||
|
get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle)
|
||||||
|
{
|
||||||
|
// vkGetMemoryAndroidHardwareBufferANDROID parameter
|
||||||
|
VkMemoryGetAndroidHardwareBufferInfoANDROID ahb_info = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_ANDROID_HARDWARE_BUFFER_INFO_ANDROID,
|
||||||
|
.pNext = NULL,
|
||||||
|
.memory = device_memory,
|
||||||
|
};
|
||||||
|
|
||||||
|
AHardwareBuffer *buf = NULL;
|
||||||
|
VkResult ret = vk->vkGetMemoryAndroidHardwareBufferANDROID(vk->device, &ahb_info, &buf);
|
||||||
|
if (ret != VK_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_handle = buf;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE)
|
||||||
|
|
||||||
|
static VkResult
|
||||||
|
get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle)
|
||||||
|
{
|
||||||
|
// vkGetMemoryWin32HandleKHR parameter
|
||||||
|
VkMemoryGetWin32HandleInfoKHR win32_info = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR,
|
||||||
|
.pNext = NULL,
|
||||||
|
.memory = device_memory,
|
||||||
|
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR,
|
||||||
|
};
|
||||||
|
|
||||||
|
HANDLE handle = NULL;
|
||||||
|
VkResult ret = vk->vkGetMemoryWin32HandleKHR(vk->device, &win32_info, &handle);
|
||||||
|
if (ret != VK_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_handle = handle;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error "Needs port"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
VkResult
|
||||||
|
vk_get_native_handle_from_device_memory(struct vk_bundle *vk,
|
||||||
|
VkDeviceMemory device_memory,
|
||||||
|
xrt_graphics_buffer_handle_t *out_handle)
|
||||||
|
{
|
||||||
|
return get_device_memory_handle(vk, device_memory, out_handle);
|
||||||
|
}
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
vk_create_sampler(struct vk_bundle *vk, VkSamplerAddressMode clamp_mode, VkSampler *out_sampler)
|
vk_create_sampler(struct vk_bundle *vk, VkSamplerAddressMode clamp_mode, VkSampler *out_sampler)
|
||||||
{
|
{
|
||||||
|
|
|
@ -668,6 +668,23 @@ vk_create_image_from_native(struct vk_bundle *vk,
|
||||||
VkImage *out_image,
|
VkImage *out_image,
|
||||||
VkDeviceMemory *out_mem);
|
VkDeviceMemory *out_mem);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Given a DeviceMemory handle created to be exportable, outputs the native buffer type (FD on desktop Linux)
|
||||||
|
* equivalent.
|
||||||
|
*
|
||||||
|
* Caller assumes ownership of handle which should be unreferenced with @ref u_graphics_buffer_unref
|
||||||
|
*
|
||||||
|
* @param vk Vulkan bundle
|
||||||
|
* @param device_memory The memory to get the handle of
|
||||||
|
* @param[out] out_handle A pointer to the handle to populate
|
||||||
|
*
|
||||||
|
* @ingroup aux_vk
|
||||||
|
*/
|
||||||
|
VkResult
|
||||||
|
vk_get_native_handle_from_device_memory(struct vk_bundle *vk,
|
||||||
|
VkDeviceMemory device_memory,
|
||||||
|
xrt_graphics_buffer_handle_t *out_handle);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @ingroup aux_vk
|
* @ingroup aux_vk
|
||||||
* Helper to create a VkImage
|
* Helper to create a VkImage
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
#ifdef XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER
|
#ifdef XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER
|
||||||
#include "android/android_ahardwarebuffer_allocator.h"
|
#include "android/android_ahardwarebuffer_allocator.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Helper functions.
|
* Helper functions.
|
||||||
|
@ -44,81 +42,6 @@ get_image_memory_handle_type(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD)
|
|
||||||
|
|
||||||
static VkResult
|
|
||||||
get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle)
|
|
||||||
{
|
|
||||||
// vkGetMemoryFdKHR parameter
|
|
||||||
VkMemoryGetFdInfoKHR fd_info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
|
|
||||||
.memory = device_memory,
|
|
||||||
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
|
|
||||||
};
|
|
||||||
|
|
||||||
int fd;
|
|
||||||
VkResult ret = vk->vkGetMemoryFdKHR(vk->device, &fd_info, &fd);
|
|
||||||
if (ret != VK_SUCCESS) {
|
|
||||||
// COMP_ERROR(c, "->image - vkGetMemoryFdKHR: %s",
|
|
||||||
// vk_result_string(ret));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_handle = fd;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
|
|
||||||
|
|
||||||
static VkResult
|
|
||||||
get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle)
|
|
||||||
{
|
|
||||||
// vkGetMemoryAndroidHardwareBufferANDROID parameter
|
|
||||||
VkMemoryGetAndroidHardwareBufferInfoANDROID ahb_info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_ANDROID_HARDWARE_BUFFER_INFO_ANDROID,
|
|
||||||
.pNext = NULL,
|
|
||||||
.memory = device_memory,
|
|
||||||
};
|
|
||||||
|
|
||||||
AHardwareBuffer *buf = NULL;
|
|
||||||
VkResult ret = vk->vkGetMemoryAndroidHardwareBufferANDROID(vk->device, &ahb_info, &buf);
|
|
||||||
if (ret != VK_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_handle = buf;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE)
|
|
||||||
|
|
||||||
static VkResult
|
|
||||||
get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle)
|
|
||||||
{
|
|
||||||
// vkGetMemoryWin32HandleKHR parameter
|
|
||||||
VkMemoryGetWin32HandleInfoKHR win32_info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR,
|
|
||||||
.pNext = NULL,
|
|
||||||
.memory = device_memory,
|
|
||||||
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR,
|
|
||||||
};
|
|
||||||
|
|
||||||
HANDLE handle = NULL;
|
|
||||||
VkResult ret = vk->vkGetMemoryWin32HandleKHR(vk->device, &win32_info, &handle);
|
|
||||||
if (ret != VK_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_handle = handle;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#error "Needs port"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static VkResult
|
static VkResult
|
||||||
create_image(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info, struct vk_image *out_image)
|
create_image(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info, struct vk_image *out_image)
|
||||||
{
|
{
|
||||||
|
@ -442,7 +365,7 @@ vk_ic_get_handles(struct vk_bundle *vk,
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (; i < vkic->image_count && i < max_handles; i++) {
|
for (; i < vkic->image_count && i < max_handles; i++) {
|
||||||
ret = get_device_memory_handle(vk, vkic->images[i].memory, &out_handles[i]);
|
ret = vk_get_native_handle_from_device_memory(vk, vkic->images[i].memory, &out_handles[i]);
|
||||||
if (ret != VK_SUCCESS) {
|
if (ret != VK_SUCCESS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue