1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-27 04:54:15 +01:00

[d3d8/9] Prevent device child ref underruns on release

This commit is contained in:
WinterSnowfall 2025-02-19 20:14:32 +02:00 committed by Philip Rebohle
parent 19361c962c
commit 317607e192
2 changed files with 33 additions and 5 deletions

View File

@ -31,16 +31,28 @@ namespace dxvk {
}
ULONG STDMETHODCALLTYPE Release() {
// ignore Release calls on objects with 0 refCount
if(unlikely(!this->m_refCount))
return this->m_refCount;
uint32_t oldRefCount, refCount;
do {
oldRefCount = this->m_refCount.load(std::memory_order_acquire);
// clamp value to 0 to prevent underruns
if (unlikely(!oldRefCount))
return 0;
refCount = oldRefCount - 1;
} while (!this->m_refCount.compare_exchange_weak(oldRefCount,
refCount,
std::memory_order_release,
std::memory_order_acquire));
uint32_t refCount = --this->m_refCount;
if (unlikely(!refCount)) {
auto* pDevice = GetDevice();
this->ReleasePrivate();
pDevice->Release();
}
return refCount;
}

View File

@ -25,12 +25,28 @@ namespace dxvk {
}
ULONG STDMETHODCALLTYPE Release() {
uint32_t refCount = --this->m_refCount;
uint32_t oldRefCount, refCount;
do {
oldRefCount = this->m_refCount.load(std::memory_order_acquire);
// clamp value to 0 to prevent underruns
if (unlikely(!oldRefCount))
return 0;
refCount = oldRefCount - 1;
} while (!this->m_refCount.compare_exchange_weak(oldRefCount,
refCount,
std::memory_order_release,
std::memory_order_acquire));
if (unlikely(!refCount)) {
auto* pDevice = GetDevice();
this->ReleasePrivate();
pDevice->Release();
}
return refCount;
}