diff --git a/src/drm.cpp b/src/drm.cpp index 21efa20bb..8d313695d 100644 --- a/src/drm.cpp +++ b/src/drm.cpp @@ -13,9 +13,14 @@ #include #include +extern "C" { +#include +} + #include "drm.hpp" #include "main.hpp" #include "vblankmanager.hpp" +#include "wlserver.hpp" #include "gpuvis_trace_utils.h" @@ -631,7 +636,7 @@ int drm_atomic_commit(struct drm_t *drm, struct Composite_t *pComposite, struct return ret; } -uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_dmabuf_attributes *dma_buf ) +uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_buffer *buf, struct wlr_dmabuf_attributes *dma_buf ) { assert( dma_buf->n_planes == 1); @@ -655,7 +660,15 @@ uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_dmabuf_attributes * } assert( drm->map_fbid_inflightflips[ fb_id ].held == false ); + if ( buf != nullptr ) + { + wlserver_lock(); + buf = wlr_buffer_lock( buf ); + wlserver_unlock(); + } + drm->map_fbid_inflightflips[ fb_id ].id = fb_id; + drm->map_fbid_inflightflips[ fb_id ].buf = buf; drm->map_fbid_inflightflips[ fb_id ].held = true; drm->map_fbid_inflightflips[ fb_id ].n_refs = 0; @@ -672,6 +685,13 @@ static void drm_free_fb( struct drm_t *drm, struct fb *fb ) perror( "drmModeRmFB failed" ); } + if ( fb->buf != nullptr ) + { + wlserver_lock(); + wlr_buffer_unlock( fb->buf ); + wlserver_unlock(); + } + fb = {}; } diff --git a/src/drm.hpp b/src/drm.hpp index 27f99546f..c1de43952 100644 --- a/src/drm.hpp +++ b/src/drm.hpp @@ -40,6 +40,8 @@ struct connector { struct fb { uint32_t id; + /* Client buffer, if any */ + struct wlr_buffer *buf; /* A FB is held if it's being used by steamcompmgr */ bool held; /* Number of page-flips using the FB */ @@ -97,6 +99,6 @@ extern bool g_bDebugLayers; int init_drm(struct drm_t *drm, const char *device, const char *mode_str, unsigned int vrefresh); int drm_atomic_commit(struct drm_t *drm, struct Composite_t *pComposite, struct VulkanPipeline_t *pPipeline ); -uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_dmabuf_attributes *dma_buf ); +uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_buffer *buf, struct wlr_dmabuf_attributes *dma_buf ); void drm_drop_fbid( struct drm_t *drm, uint32_t fbid ); bool drm_can_avoid_composite( struct drm_t *drm, struct Composite_t *pComposite, struct VulkanPipeline_t *pPipeline ); diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index f09cc94cb..f93cd4581 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -347,6 +347,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, VkFormat format, bo // We assume we own the memory when doing this right now. // We could support the import scenario as well if needed // assert( bTextureable == false ); + assert( pDMA == nullptr ); m_DMA.modifier = DRM_FORMAT_MOD_INVALID; m_DMA.n_planes = 1; @@ -376,7 +377,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, VkFormat format, bo m_DMA.stride[0] = image_layout.rowPitch; - m_FBID = drm_fbid_from_dmabuf( &g_DRM, &m_DMA ); + m_FBID = drm_fbid_from_dmabuf( &g_DRM, nullptr, &m_DMA ); if ( m_FBID == 0 ) return false; diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 4f2f97cdc..6c5cf29a9 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -529,7 +529,7 @@ import_commit ( struct wlr_buffer *buf, struct wlr_dmabuf_attributes *dmabuf, co if ( BIsNested() == False ) { - commit.fb_id = drm_fbid_from_dmabuf( &g_DRM, dmabuf ); + commit.fb_id = drm_fbid_from_dmabuf( &g_DRM, buf, dmabuf ); assert( commit.fb_id != 0 ); }