Hold client buffers till KMS stops using them

This commit is contained in:
Simon Ser 2020-05-19 14:37:46 +02:00 committed by Pierre-Loup A. Griffais
parent 31a0713455
commit aac57e7c75
4 changed files with 27 additions and 4 deletions

View file

@ -13,9 +13,14 @@
#include <sys/select.h>
#include <signal.h>
extern "C" {
#include <wlr/types/wlr_buffer.h>
}
#include "drm.hpp"
#include "main.hpp"
#include "vblankmanager.hpp"
#include "wlserver.hpp"
#include "gpuvis_trace_utils.h"
@ -631,7 +636,7 @@ out:
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 = {};
}

View file

@ -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 );

View file

@ -384,6 +384,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, VkFormat format, cr
// We could support the import scenario as well if needed (but we
// already have a DMA-BUF in that case).
// assert( bTextureable == false );
assert( pDMA == nullptr );
struct wlr_dmabuf_attributes dmabuf = {};
dmabuf.modifier = DRM_FORMAT_MOD_INVALID;
@ -405,7 +406,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, VkFormat format, cr
dmabuf.stride[0] = m_unRowPitch;
m_FBID = drm_fbid_from_dmabuf( &g_DRM, &dmabuf );
m_FBID = drm_fbid_from_dmabuf( &g_DRM, nullptr, &dmabuf );
if ( m_FBID == 0 )
return false;

View file

@ -555,7 +555,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 );
}