The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

a/vk: Expose get_device_memory_handle as vk_get_native_handle_from_device_memory

authored by

Ryan Pavlik and committed by
Jakob Bornecrantz
79527739 9463de7e

+101 -78
+83
src/xrt/auxiliary/vk/vk_helpers.c
··· 551 551 return ret; 552 552 } 553 553 554 + #if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD) 555 + 556 + static VkResult 557 + get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle) 558 + { 559 + // vkGetMemoryFdKHR parameter 560 + VkMemoryGetFdInfoKHR fd_info = { 561 + .sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR, 562 + .memory = device_memory, 563 + .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR, 564 + }; 565 + 566 + int fd; 567 + VkResult ret = vk->vkGetMemoryFdKHR(vk->device, &fd_info, &fd); 568 + if (ret != VK_SUCCESS) { 569 + // COMP_ERROR(c, "->image - vkGetMemoryFdKHR: %s", 570 + // vk_result_string(ret)); 571 + return ret; 572 + } 573 + 574 + *out_handle = fd; 575 + 576 + return ret; 577 + } 578 + 579 + #elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER) 580 + 581 + static VkResult 582 + get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle) 583 + { 584 + // vkGetMemoryAndroidHardwareBufferANDROID parameter 585 + VkMemoryGetAndroidHardwareBufferInfoANDROID ahb_info = { 586 + .sType = VK_STRUCTURE_TYPE_MEMORY_GET_ANDROID_HARDWARE_BUFFER_INFO_ANDROID, 587 + .pNext = NULL, 588 + .memory = device_memory, 589 + }; 590 + 591 + AHardwareBuffer *buf = NULL; 592 + VkResult ret = vk->vkGetMemoryAndroidHardwareBufferANDROID(vk->device, &ahb_info, &buf); 593 + if (ret != VK_SUCCESS) { 594 + return ret; 595 + } 596 + 597 + *out_handle = buf; 598 + 599 + return ret; 600 + } 601 + 602 + #elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE) 603 + 604 + static VkResult 605 + get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle) 606 + { 607 + // vkGetMemoryWin32HandleKHR parameter 608 + VkMemoryGetWin32HandleInfoKHR win32_info = { 609 + .sType = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR, 610 + .pNext = NULL, 611 + .memory = device_memory, 612 + .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR, 613 + }; 614 + 615 + HANDLE handle = NULL; 616 + VkResult ret = vk->vkGetMemoryWin32HandleKHR(vk->device, &win32_info, &handle); 617 + if (ret != VK_SUCCESS) { 618 + return ret; 619 + } 620 + 621 + *out_handle = handle; 622 + 623 + return ret; 624 + } 625 + #else 626 + #error "Needs port" 627 + #endif 628 + 629 + VkResult 630 + vk_get_native_handle_from_device_memory(struct vk_bundle *vk, 631 + VkDeviceMemory device_memory, 632 + xrt_graphics_buffer_handle_t *out_handle) 633 + { 634 + return get_device_memory_handle(vk, device_memory, out_handle); 635 + } 636 + 554 637 VkResult 555 638 vk_create_sampler(struct vk_bundle *vk, VkSamplerAddressMode clamp_mode, VkSampler *out_sampler) 556 639 {
+17
src/xrt/auxiliary/vk/vk_helpers.h
··· 669 669 VkDeviceMemory *out_mem); 670 670 671 671 /*! 672 + * Given a DeviceMemory handle created to be exportable, outputs the native buffer type (FD on desktop Linux) 673 + * equivalent. 674 + * 675 + * Caller assumes ownership of handle which should be unreferenced with @ref u_graphics_buffer_unref 676 + * 677 + * @param vk Vulkan bundle 678 + * @param device_memory The memory to get the handle of 679 + * @param[out] out_handle A pointer to the handle to populate 680 + * 681 + * @ingroup aux_vk 682 + */ 683 + VkResult 684 + vk_get_native_handle_from_device_memory(struct vk_bundle *vk, 685 + VkDeviceMemory device_memory, 686 + xrt_graphics_buffer_handle_t *out_handle); 687 + 688 + /*! 672 689 * @ingroup aux_vk 673 690 * Helper to create a VkImage 674 691 */
+1 -78
src/xrt/auxiliary/vk/vk_image_allocator.c
··· 22 22 #ifdef XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER 23 23 #include "android/android_ahardwarebuffer_allocator.h" 24 24 #endif 25 - 26 - 27 25 /* 28 26 * 29 27 * Helper functions. ··· 43 41 #error "need port" 44 42 #endif 45 43 } 46 - 47 - #if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD) 48 - 49 - static VkResult 50 - get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle) 51 - { 52 - // vkGetMemoryFdKHR parameter 53 - VkMemoryGetFdInfoKHR fd_info = { 54 - .sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR, 55 - .memory = device_memory, 56 - .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR, 57 - }; 58 - 59 - int fd; 60 - VkResult ret = vk->vkGetMemoryFdKHR(vk->device, &fd_info, &fd); 61 - if (ret != VK_SUCCESS) { 62 - // COMP_ERROR(c, "->image - vkGetMemoryFdKHR: %s", 63 - // vk_result_string(ret)); 64 - return ret; 65 - } 66 - 67 - *out_handle = fd; 68 - 69 - return ret; 70 - } 71 - 72 - #elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER) 73 - 74 - static VkResult 75 - get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle) 76 - { 77 - // vkGetMemoryAndroidHardwareBufferANDROID parameter 78 - VkMemoryGetAndroidHardwareBufferInfoANDROID ahb_info = { 79 - .sType = VK_STRUCTURE_TYPE_MEMORY_GET_ANDROID_HARDWARE_BUFFER_INFO_ANDROID, 80 - .pNext = NULL, 81 - .memory = device_memory, 82 - }; 83 - 84 - AHardwareBuffer *buf = NULL; 85 - VkResult ret = vk->vkGetMemoryAndroidHardwareBufferANDROID(vk->device, &ahb_info, &buf); 86 - if (ret != VK_SUCCESS) { 87 - return ret; 88 - } 89 - 90 - *out_handle = buf; 91 - 92 - return ret; 93 - } 94 - 95 - #elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE) 96 - 97 - static VkResult 98 - get_device_memory_handle(struct vk_bundle *vk, VkDeviceMemory device_memory, xrt_graphics_buffer_handle_t *out_handle) 99 - { 100 - // vkGetMemoryWin32HandleKHR parameter 101 - VkMemoryGetWin32HandleInfoKHR win32_info = { 102 - .sType = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR, 103 - .pNext = NULL, 104 - .memory = device_memory, 105 - .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR, 106 - }; 107 - 108 - HANDLE handle = NULL; 109 - VkResult ret = vk->vkGetMemoryWin32HandleKHR(vk->device, &win32_info, &handle); 110 - if (ret != VK_SUCCESS) { 111 - return ret; 112 - } 113 - 114 - *out_handle = handle; 115 - 116 - return ret; 117 - } 118 - #else 119 - #error "Needs port" 120 - #endif 121 44 122 45 static VkResult 123 46 create_image(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info, struct vk_image *out_image) ··· 442 365 443 366 size_t i = 0; 444 367 for (; i < vkic->image_count && i < max_handles; i++) { 445 - ret = get_device_memory_handle(vk, vkic->images[i].memory, &out_handles[i]); 368 + ret = vk_get_native_handle_from_device_memory(vk, vkic->images[i].memory, &out_handles[i]); 446 369 if (ret != VK_SUCCESS) { 447 370 break; 448 371 }