mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-31 05:52:11 +01:00
[dxvk] Use separate counters for read/write resource usage
It is not unrealistic at all to overflow the 18-bit and 14-bit counters in modern games, so just use two 32-bit counters instead. Avoid 64-bit atomics due to poor performance on 32-bit builts.
This commit is contained in:
parent
71e74f1810
commit
1347aeba33
@ -20,10 +20,7 @@ namespace dxvk {
|
||||
* is recorded, it will be marked as 'in use'.
|
||||
*/
|
||||
class DxvkResource : public RcObject {
|
||||
constexpr static uint32_t UseCountIncrementW = 1 << 18;
|
||||
constexpr static uint32_t UseCountIncrementR = 1;
|
||||
constexpr static uint32_t UseCountMaskW = ~(UseCountIncrementW - 1);
|
||||
constexpr static uint32_t UseCountMaskR = ~(UseCountIncrementR - 1);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~DxvkResource();
|
||||
@ -39,10 +36,10 @@ namespace dxvk {
|
||||
* \returns \c true if the resource is in use
|
||||
*/
|
||||
bool isInUse(DxvkAccess access = DxvkAccess::Read) const {
|
||||
uint32_t mask = access == DxvkAccess::Write
|
||||
? UseCountMaskW
|
||||
: UseCountMaskR;
|
||||
return m_useCount.load() & mask;
|
||||
bool result = m_useCountW.load();
|
||||
if (access == DxvkAccess::Read)
|
||||
result |= m_useCountR.load();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,8 +49,11 @@ namespace dxvk {
|
||||
* \param Access Resource access type
|
||||
*/
|
||||
void acquire(DxvkAccess access) {
|
||||
if (access != DxvkAccess::None)
|
||||
m_useCount += getIncrement(access);
|
||||
if (access != DxvkAccess::None) {
|
||||
(access == DxvkAccess::Read
|
||||
? m_useCountR
|
||||
: m_useCountW) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,19 +63,17 @@ namespace dxvk {
|
||||
* \param Access Resource access type
|
||||
*/
|
||||
void release(DxvkAccess access) {
|
||||
if (access != DxvkAccess::None)
|
||||
m_useCount -= getIncrement(access);
|
||||
if (access != DxvkAccess::None) {
|
||||
(access == DxvkAccess::Read
|
||||
? m_useCountR
|
||||
: m_useCountW) -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::atomic<uint32_t> m_useCount = { 0u };
|
||||
|
||||
static constexpr uint32_t getIncrement(DxvkAccess access) {
|
||||
return access == DxvkAccess::Write
|
||||
? UseCountIncrementW
|
||||
: UseCountIncrementR;
|
||||
}
|
||||
std::atomic<uint32_t> m_useCountR = { 0u };
|
||||
std::atomic<uint32_t> m_useCountW = { 0u };
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user