Dup FD in CVulkanTexture::BInit
This saves us the wlr_dmabuf_attributes juggle and makes it easier to understand the FDs ownership and lifetime.
This commit is contained in:
parent
db876af1c4
commit
b305b7f123
3 changed files with 14 additions and 15 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "rendervulkan.hpp"
|
#include "rendervulkan.hpp"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
|
@ -306,6 +307,16 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, VkFormat format, bo
|
||||||
|
|
||||||
if ( pDMA != nullptr )
|
if ( pDMA != nullptr )
|
||||||
{
|
{
|
||||||
|
assert( pDMA->n_planes == 1 );
|
||||||
|
|
||||||
|
// Importing memory from a FD transfers ownership of the FD
|
||||||
|
int fd = dup( pDMA->fd[0] );
|
||||||
|
if ( fd < 0 )
|
||||||
|
{
|
||||||
|
perror( "dup failed" );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// We're importing WSI buffers from GL or Vulkan, set implicit_sync
|
// We're importing WSI buffers from GL or Vulkan, set implicit_sync
|
||||||
wsiAllocInfo.sType = VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA;
|
wsiAllocInfo.sType = VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA;
|
||||||
wsiAllocInfo.implicit_sync = true;
|
wsiAllocInfo.implicit_sync = true;
|
||||||
|
@ -316,7 +327,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, VkFormat format, bo
|
||||||
// Memory already provided by pDMA
|
// Memory already provided by pDMA
|
||||||
importMemoryInfo.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR;
|
importMemoryInfo.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR;
|
||||||
importMemoryInfo.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
|
importMemoryInfo.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
|
||||||
importMemoryInfo.fd = pDMA->fd[0];
|
importMemoryInfo.fd = fd;
|
||||||
importMemoryInfo.pNext = allocInfo.pNext;
|
importMemoryInfo.pNext = allocInfo.pNext;
|
||||||
|
|
||||||
allocInfo.pNext = &importMemoryInfo;
|
allocInfo.pNext = &importMemoryInfo;
|
||||||
|
|
|
@ -514,21 +514,8 @@ import_commit ( struct wlr_dmabuf_attributes *dmabuf, commit_t &commit )
|
||||||
{
|
{
|
||||||
if ( BIsNested() == False )
|
if ( BIsNested() == False )
|
||||||
{
|
{
|
||||||
// We'll also need a copy for Vulkan to consume below.
|
|
||||||
|
|
||||||
int fdCopy = dup( dmabuf->fd[0] );
|
|
||||||
|
|
||||||
if ( fdCopy == -1 )
|
|
||||||
{
|
|
||||||
close( dmabuf->fd[0] );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
commit.fb_id = drm_fbid_from_dmabuf( &g_DRM, dmabuf );
|
commit.fb_id = drm_fbid_from_dmabuf( &g_DRM, dmabuf );
|
||||||
assert( commit.fb_id != 0 );
|
assert( commit.fb_id != 0 );
|
||||||
|
|
||||||
close( dmabuf->fd[0] );
|
|
||||||
dmabuf->fd[0] = fdCopy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
commit.vulkanTex = vulkan_create_texture_from_dmabuf( dmabuf );
|
commit.vulkanTex = vulkan_create_texture_from_dmabuf( dmabuf );
|
||||||
|
@ -2031,6 +2018,7 @@ void check_new_wayland_res( void )
|
||||||
commit_t newCommit = {};
|
commit_t newCommit = {};
|
||||||
|
|
||||||
bool bSuccess = import_commit( &wayland_commit_queue[ i ].attribs, newCommit );
|
bool bSuccess = import_commit( &wayland_commit_queue[ i ].attribs, newCommit );
|
||||||
|
wlr_dmabuf_attributes_finish( &wayland_commit_queue[ i ].attribs );
|
||||||
|
|
||||||
if ( bSuccess == true )
|
if ( bSuccess == true )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue