Skip to content
Snippets Groups Projects

vulkan: Add support for importing and using dma_buf memory

Closed Philip Langdale requested to merge philipl/libplacebo:dma_buf into master

This change introduces a set of vulkan-specific functions to support importing dma_buf backed memory and then creating textures over that memory.

The specific use-case is supporting interop with vaapi hardware decoding, where dma_buf is used to export decoded video surfaces.

The API is a little rough as the VkDeviceMemory objects have to be directly exposed in the API. Due to the memory not corresponding 1:1 with the textures, the caller has to manage them explicitly.

I have a corresponding mpv change that demonstrates this all works.

Note that this code does not pass validation right now. We get errors reporting that the image is too big to fit into the memory it is being bound to, when offset and size are considered together.

Clearly it works in practice, and I think the issue is that the pitch of the VA Surface is different (smaller) than what would be used for a normal Vulkan image allocation. I suspect this cannot be fixed without using VK_EXT_image_drm_format_modifier which is not yet available. When this is used, there is a special tiling mode which tells Vulkan to expect a special pitch.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • added 1 commit

    • 9cd08fa7 - vulkan: Add support for importing and using dma_buf memory

    Compare with previous version

  • Author Contributor

    Substantially updated to manage imported memory with vk_memslice and abandoning ref counting in favour of dup()ing the fds. This is a lot simpler and actually moves us closer to running with validations.

    Right now I see a finite set of binding errors at mpv startup and then the stream plays fine without errors. This seems to be related to whatever strange things it's doing at probe time. I see 5 failed bind calls, and the sizes it's complaining about are the same, regardless of what sample I play, so this might be something that's mpv specific. I will dig further.

    In terms of comments, I need to add the import_caps but the rest are addressed or obsoleted.

  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • Niklas Haas
  • Philip Langdale resolved all discussions

    resolved all discussions

  • Philip Langdale added 3 commits

    added 3 commits

    • 529693d1 - gpu: Add import handle_caps
    • 4c3f405d - vulkan: Add support for external memory with dma_buf fds
    • aed63f77 - gpu: vulkan: Add support for creating textures bound to imported memory

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading