mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-27 13:54:16 +01:00
[d3d8/9] Prevent device child ref underruns on release
This commit is contained in:
parent
19361c962c
commit
317607e192
@ -31,16 +31,28 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ULONG STDMETHODCALLTYPE Release() {
|
ULONG STDMETHODCALLTYPE Release() {
|
||||||
// ignore Release calls on objects with 0 refCount
|
uint32_t oldRefCount, refCount;
|
||||||
if(unlikely(!this->m_refCount))
|
|
||||||
return this->m_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)) {
|
if (unlikely(!refCount)) {
|
||||||
auto* pDevice = GetDevice();
|
auto* pDevice = GetDevice();
|
||||||
this->ReleasePrivate();
|
this->ReleasePrivate();
|
||||||
pDevice->Release();
|
pDevice->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return refCount;
|
return refCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,12 +25,28 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ULONG STDMETHODCALLTYPE Release() {
|
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)) {
|
if (unlikely(!refCount)) {
|
||||||
auto* pDevice = GetDevice();
|
auto* pDevice = GetDevice();
|
||||||
this->ReleasePrivate();
|
this->ReleasePrivate();
|
||||||
pDevice->Release();
|
pDevice->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return refCount;
|
return refCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user