Skip to content

Commit

Permalink
Hold client buffers till KMS stops using them
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Jun 11, 2020
1 parent ba20f07 commit 9bf349e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
21 changes: 20 additions & 1 deletion src/drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <sys/select.h>
#include <signal.h>

extern "C" {
#include <wlr/types/wlr_buffer.h>
}

#include "drm.hpp"
#include "main.hpp"
#include "vblankmanager.hpp"
Expand Down Expand Up @@ -631,7 +635,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);

Expand All @@ -655,7 +659,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;

Expand All @@ -672,6 +684,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 = {};
}

Expand Down
5 changes: 4 additions & 1 deletion src/drm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {
}

#include "rendervulkan.hpp"
#include "wlserver.h"

#include <unordered_map>
#include <utility>
Expand Down Expand Up @@ -40,6 +41,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 */
Expand Down Expand Up @@ -97,6 +100,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 );
3 changes: 2 additions & 1 deletion src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,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 );
}

Expand Down

0 comments on commit 9bf349e

Please sign in to comment.