Use atomics for CVulkanTexture refcounts.
Otherwise the double access on destruction could be very messy. The default for all these operations is the cst memory order which is certainly good enough though technically not the most optimal. (Could do acq_rel for all of them).
This commit is contained in:
parent
3a1776f0f8
commit
c0d745baac
2 changed files with 9 additions and 7 deletions
|
@ -716,6 +716,10 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, VkFormat format, cr
|
|||
return true;
|
||||
}
|
||||
|
||||
CVulkanTexture::CVulkanTexture( void ) : nRefCount( 1 )
|
||||
{
|
||||
}
|
||||
|
||||
CVulkanTexture::~CVulkanTexture( void )
|
||||
{
|
||||
if ( m_pMappedData != nullptr )
|
||||
|
@ -1866,9 +1870,7 @@ void vulkan_garbage_collect( void )
|
|||
for ( uint32_t ref = 0; ref < g_scratchCommandBuffers[ i ].refs.size(); ref++ )
|
||||
{
|
||||
CVulkanTexture *pTex = g_scratchCommandBuffers[ i ].refs[ ref ];
|
||||
pTex->nRefCount--;
|
||||
|
||||
if ( pTex->nRefCount == 0 )
|
||||
if ( --pTex->nRefCount == 0 )
|
||||
{
|
||||
setVulkanTexture( pTex->handle, nullptr);
|
||||
delete pTex;
|
||||
|
@ -1962,9 +1964,7 @@ void vulkan_free_texture( VulkanTexture_t vulkanTex )
|
|||
assert( pTex != nullptr );
|
||||
assert( pTex->handle == vulkanTex );
|
||||
|
||||
pTex->nRefCount--;
|
||||
|
||||
if ( pTex->nRefCount == 0 )
|
||||
if ( --pTex->nRefCount == 0 )
|
||||
{
|
||||
delete pTex;
|
||||
setVulkanTexture( vulkanTex, nullptr );
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint32_t VulkanTexture_t;
|
||||
|
@ -103,6 +104,7 @@ public:
|
|||
|
||||
bool BInit( uint32_t width, uint32_t height, VkFormat format, createFlags flags, wlr_dmabuf_attributes *pDMA = nullptr );
|
||||
|
||||
CVulkanTexture( void );
|
||||
~CVulkanTexture( void );
|
||||
|
||||
bool m_bInitialized = false;
|
||||
|
@ -117,7 +119,7 @@ public:
|
|||
|
||||
uint32_t m_FBID = 0;
|
||||
|
||||
int32_t nRefCount = 1;
|
||||
std::atomic<int32_t> nRefCount;
|
||||
|
||||
VulkanTexture_t handle = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue