|Summary:||Mapping a DMABUF frame as a VkImage and then copying/blitting the image to another produces blank output|
|Component:||Drivers/Vulkan/intel||Assignee:||Intel 3D Bugs Mailing List <intel-3d-bugs>|
|Status:||RESOLVED NOTOURBUG||QA Contact:||Intel 3D Bugs Mailing List <intel-3d-bugs>|
|i915 platform:||i915 features:|
Description atomnuker 2018-01-30 19:02:21 UTC
Hi, As the title says, mapping a DMABUF image via VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT or VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR (both work the same) and then trying to vkCmdBlitImage or vkCmdCopyImage to another image results in a blank output image (all 0's). The aim is to detile the image. You can replicate if you clone this repo (sorry I couldn't make a small standalone program): https://github.com/atomnuker/FFmpeg/tree/exp_vulkan Configure with ./configure --enable-libdrm --enable-vulkan Run with: sudo ./ffmpeg_g -init_hw_device "vulkan=sl:0,extensions=VK_EXT_debug_report" -device /dev/dri/card0 -crtc_id 0 -framerate 60 -format bgr0 -f kmsgrab -i /dev/zero -filter_hw_device sl -vf hwmap,chromaticaberration_vulkan,hwdownload,format=bgr0 -y -loglevel trace -c:v rawvideo out.nut Playing back the .nut file via mpv should display a recording of the screen but instead its blank. The odd thing is that if the VkImage is created with linear tiling (and misinforming the driver by doing so) then the output will not be a blank image but a tiled recording of the screen. Here's the code which does the mapping: https://github.com/atomnuker/FFmpeg/blob/exp_vulkan/libavutil/hwcontext_vulkan.c#L1186 Here's the command buffer: https://github.com/atomnuker/FFmpeg/blob/exp_vulkan/libavfilter/vf_caberration_vulkan.c#L196 The repo requires the newest version of the validation layer and libvulkan.
Comment 1 Jason Ekstrand 2018-01-30 20:23:13 UTC
I think the problem you are running into is that VK_EXT_external_memory_dma_buf is purely a memory sharing mechanism and doesn't actually provide needed APIs for importing images. That will be covered by VK_EXT_image_drm_format_modifier which has not yet been finalized. It's definitely in-progress and we're hoping to get things nailed down very soon. In the mean time, what you're trying to do is still possible, you just have to go about it differently. Instead of creating a linear VkImage on the DMABUF, create a VkBuffer and then use vkCmdCopyBufferToImage and provide the image stride using bufferRowLength. The current Vulkan WSI code in mesa already does this internally for cross-GPU sharing via prime.
Comment 2 atomnuker 2018-01-30 21:18:06 UTC
(In reply to Jason Ekstrand from comment #1) > I think the problem you are running into is that > VK_EXT_external_memory_dma_buf is purely a memory sharing mechanism and > doesn't actually provide needed APIs for importing images. That will be > covered by VK_EXT_image_drm_format_modifier which has not yet been > finalized. It's definitely in-progress and we're hoping to get things > nailed down very soon. > > In the mean time, what you're trying to do is still possible, you just have > to go about it differently. Instead of creating a linear VkImage on the > DMABUF, create a VkBuffer and then use vkCmdCopyBufferToImage and provide > the image stride using bufferRowLength. The current Vulkan WSI code in mesa > already does this internally for cross-GPU sharing via prime. I see, thanks. I guess I'll wait until that extension gets finalized.
Comment 3 atomnuker 2018-02-01 17:28:34 UTC
Issue still occurs when copying to a VkBuffer and then to a VkImage.
Comment 4 atomnuker 2018-03-27 18:59:03 UTC
Closing, the format modifier API will hopefully fix this. If it doesn't will reopen.
Comment 5 Mike Mestnik 2019-02-10 20:11:06 UTC
I'm looking for the code behind this report, but github doesn't have copies of this file from a year ago. The oldest is: https://github.com/atomnuker/FFmpeg/blob/b0e1c170d69be817e6ec6cabd89767217bbf4f66/libavutil/hwcontext_vulkan.c#L1186 It may help me with my own dmabuf import: https://www.reddit.com/r/vulkan/comments/ap6pa0/vkwayland_dmabuf_import_fails_with_vk_error/