From 0ee8d451e4888c50a33c56ca8373e7a9c32d519f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 19 May 2020 14:05:52 +0200 Subject: [PATCH] Replace map_fbid_inflightflips pair with a struct This makes it explicit what "first" and "second" are. This also allows to add more fields. --- src/drm.cpp | 27 ++++++++++++++------------- src/drm.hpp | 11 +++++++++-- src/rendervulkan.cpp | 2 +- src/steamcompmgr.cpp | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/drm.cpp b/src/drm.cpp index 962d5aa..7a952c2 100644 --- a/src/drm.cpp +++ b/src/drm.cpp @@ -207,11 +207,11 @@ static void page_flip_handler(int fd, unsigned int frame, { uint32_t previous_fbid = g_DRM.fbids_on_screen[ i ]; assert( previous_fbid != 0 ); - assert( g_DRM.map_fbid_inflightflips[ previous_fbid ].second > 0 ); + assert( g_DRM.map_fbid_inflightflips[ previous_fbid ].n_refs > 0 ); - g_DRM.map_fbid_inflightflips[ previous_fbid ].second--; + g_DRM.map_fbid_inflightflips[ previous_fbid ].n_refs--; - if ( g_DRM.map_fbid_inflightflips[ previous_fbid ].second == 0 ) + if ( g_DRM.map_fbid_inflightflips[ previous_fbid ].n_refs == 0 ) { // we flipped away from this previous fbid, now safe to delete std::lock_guard lock( g_DRM.free_queue_lock ); @@ -575,8 +575,8 @@ int drm_atomic_commit(struct drm_t *drm, struct Composite_t *pComposite, struct // potentially beat us to the refcount checks. for ( uint32_t i = 0; i < drm->fbids_in_req.size(); i++ ) { - assert( g_DRM.map_fbid_inflightflips[ drm->fbids_in_req[ i ] ].first == true ); - g_DRM.map_fbid_inflightflips[ drm->fbids_in_req[ i ] ].second++; + assert( g_DRM.map_fbid_inflightflips[ drm->fbids_in_req[ i ] ].held == true ); + g_DRM.map_fbid_inflightflips[ drm->fbids_in_req[ i ] ].n_refs++; } g_DRM.flipcount++; @@ -597,7 +597,7 @@ int drm_atomic_commit(struct drm_t *drm, struct Composite_t *pComposite, struct // Undo refcount if the commit didn't actually work for ( uint32_t i = 0; i < drm->fbids_in_req.size(); i++ ) { - g_DRM.map_fbid_inflightflips[ drm->fbids_in_req[ i ] ].second--; + g_DRM.map_fbid_inflightflips[ drm->fbids_in_req[ i ] ].n_refs--; } g_DRM.flipcount--; @@ -647,21 +647,22 @@ uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_dmabuf_attributes * { printf("make fbid %u\n", fb_id); } - assert( drm->map_fbid_inflightflips[ fb_id ].first == false ); + assert( drm->map_fbid_inflightflips[ fb_id ].held == false ); - drm->map_fbid_inflightflips[ fb_id ].first = true; - drm->map_fbid_inflightflips[ fb_id ].second = 0; + drm->map_fbid_inflightflips[ fb_id ].held = true; + drm->map_fbid_inflightflips[ fb_id ].n_refs = 0; return fb_id; } -void drm_free_fbid( struct drm_t *drm, uint32_t fbid ) +void drm_drop_fbid( struct drm_t *drm, uint32_t fbid ) { - assert( drm->map_fbid_inflightflips[ fbid ].first == true ); - drm->map_fbid_inflightflips[ fbid ].first = false; + assert( drm->map_fbid_inflightflips[ fbid ].held == true ); + drm->map_fbid_inflightflips[ fbid ].held = false; - if ( drm->map_fbid_inflightflips[ fbid ].second == 0 ) + if ( drm->map_fbid_inflightflips[ fbid ].n_refs == 0 ) { + /* FB isn't being used in any page-flip, free it immediately */ if ( s_drm_log != 0 ) { printf("free fbid %u\n", fbid); diff --git a/src/drm.hpp b/src/drm.hpp index 6af5891..495225d 100644 --- a/src/drm.hpp +++ b/src/drm.hpp @@ -37,6 +37,13 @@ struct connector { drmModePropertyRes **props_info; }; +struct fb { + /* A FB is held if it's being used by steamcompmgr */ + bool held; + /* Number of page-flips using the FB */ + std::atomic< uint32_t > n_refs; +}; + struct drm_t { int fd; @@ -64,7 +71,7 @@ struct drm_t { std::vector < uint32_t > fbids_in_req; std::vector < uint32_t > fbids_on_screen; - std::unordered_map< uint32_t, std::pair< bool, std::atomic< uint32_t > > > map_fbid_inflightflips; + std::unordered_map< uint32_t, struct fb > map_fbid_inflightflips; std::mutex free_queue_lock; std::vector< uint32_t > fbid_free_queue; @@ -91,7 +98,7 @@ 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 ); -void drm_free_fbid( struct drm_t *drm, uint32_t fbid ); +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 ); #ifndef C_SIDE diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index f877647..28c6da8 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -428,7 +428,7 @@ CVulkanTexture::~CVulkanTexture( void ) if ( m_FBID != 0 ) { - drm_free_fbid( &g_DRM, m_FBID ); + drm_drop_fbid( &g_DRM, m_FBID ); m_FBID = 0; } diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 68520ff..b0b4aeb 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -498,7 +498,7 @@ release_commit ( commit_t &commit ) { if ( commit.fb_id != 0 ) { - drm_free_fbid( &g_DRM, commit.fb_id ); + drm_drop_fbid( &g_DRM, commit.fb_id ); commit.fb_id = 0; }