2017-10-10 23:32:13 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "dxvk_include.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-06-16 10:40:30 +02:00
|
|
|
enum class DxvkAccess {
|
2017-11-26 13:24:01 +01:00
|
|
|
Read = 0,
|
|
|
|
Write = 1,
|
2019-09-19 19:35:52 +02:00
|
|
|
None = 2,
|
2017-11-26 13:24:01 +01:00
|
|
|
};
|
|
|
|
|
2018-06-16 10:40:30 +02:00
|
|
|
using DxvkAccessFlags = Flags<DxvkAccess>;
|
2017-11-26 13:24:01 +01:00
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
/**
|
|
|
|
* \brief DXVK resource
|
|
|
|
*
|
|
|
|
* Keeps track of whether the resource is currently in use
|
|
|
|
* by the GPU. As soon as a command that uses the resource
|
|
|
|
* is recorded, it will be marked as 'in use'.
|
|
|
|
*/
|
|
|
|
class DxvkResource : public RcObject {
|
2019-09-21 02:45:23 +02:00
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~DxvkResource();
|
|
|
|
|
2019-09-19 19:35:52 +02:00
|
|
|
/**
|
|
|
|
* \brief Checks whether resource is in use
|
|
|
|
*
|
|
|
|
* Returns \c true if there are pending accesses to
|
|
|
|
* the resource by the GPU matching the given access
|
|
|
|
* type. Note that checking for reads will also return
|
|
|
|
* \c true if the resource is being written to.
|
|
|
|
* \param [in] access Access type to check for
|
|
|
|
* \returns \c true if the resource is in use
|
|
|
|
*/
|
|
|
|
bool isInUse(DxvkAccess access = DxvkAccess::Read) const {
|
2019-09-21 19:04:14 +02:00
|
|
|
bool result = m_useCountW.load() != 0;
|
2019-09-21 02:45:23 +02:00
|
|
|
if (access == DxvkAccess::Read)
|
2019-09-21 19:04:14 +02:00
|
|
|
result |= m_useCountR.load() != 0;
|
2019-09-21 02:45:23 +02:00
|
|
|
return result;
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 19:35:52 +02:00
|
|
|
/**
|
|
|
|
* \brief Acquires resource
|
|
|
|
*
|
|
|
|
* Increments use count for the given access type.
|
|
|
|
* \param Access Resource access type
|
|
|
|
*/
|
|
|
|
void acquire(DxvkAccess access) {
|
2019-09-21 02:45:23 +02:00
|
|
|
if (access != DxvkAccess::None) {
|
|
|
|
(access == DxvkAccess::Read
|
|
|
|
? m_useCountR
|
|
|
|
: m_useCountW) += 1;
|
|
|
|
}
|
2019-09-19 19:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Releases resource
|
|
|
|
*
|
|
|
|
* Decrements use count for the given access type.
|
|
|
|
* \param Access Resource access type
|
|
|
|
*/
|
|
|
|
void release(DxvkAccess access) {
|
2019-09-21 02:45:23 +02:00
|
|
|
if (access != DxvkAccess::None) {
|
|
|
|
(access == DxvkAccess::Read
|
|
|
|
? m_useCountR
|
|
|
|
: m_useCountW) -= 1;
|
|
|
|
}
|
2019-09-19 19:35:52 +02:00
|
|
|
}
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2019-09-21 02:45:23 +02:00
|
|
|
std::atomic<uint32_t> m_useCountR = { 0u };
|
|
|
|
std::atomic<uint32_t> m_useCountW = { 0u };
|
2019-09-19 19:35:52 +02:00
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|