1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-31 14:52:11 +01:00

[dxvk] Factor DxvkResource code into DxvkPagedResource

And remove the now obsolete code.
This commit is contained in:
Philip Rebohle 2024-10-17 16:31:22 +02:00 committed by Philip Rebohle
parent 6540ab4f3e
commit 4c0cbbef6a
18 changed files with 93 additions and 165 deletions

View File

@ -3,7 +3,8 @@
#include <utility>
#include <vector>
#include "../dxvk/dxvk_resource.h"
#include "../dxvk/dxvk_memory.h"
#include "../dxvk/dxvk_sparse.h"
#include "../util/com/com_guid.h"
#include "../util/com/com_object.h"

View File

@ -7,7 +7,6 @@
#include "dxvk_format.h"
#include "dxvk_hash.h"
#include "dxvk_memory.h"
#include "dxvk_resource.h"
#include "dxvk_sparse.h"
namespace dxvk {

View File

@ -7,7 +7,6 @@
#include "dxvk_bind_mask.h"
#include "dxvk_graphics_state.h"
#include "dxvk_pipelayout.h"
#include "dxvk_resource.h"
#include "dxvk_shader.h"
#include "dxvk_stats.h"

View File

@ -3,7 +3,6 @@
#include "dxvk_buffer.h"
#include "dxvk_framebuffer.h"
#include "dxvk_limits.h"
#include "dxvk_resource.h"
#include "dxvk_shader.h"
namespace dxvk {

View File

@ -6,7 +6,6 @@
#include "dxvk_context_state.h"
#include "dxvk_objects.h"
#include "dxvk_queue.h"
#include "dxvk_resource.h"
#include "dxvk_util.h"
namespace dxvk {

View File

@ -5,7 +5,7 @@
#include <utility>
#include <vector>
#include "dxvk_resource.h"
#include "dxvk_include.h"
#include "../util/thread.h"

View File

@ -3,7 +3,7 @@
#include <atomic>
#include <vector>
#include "dxvk_resource.h"
#include "dxvk_include.h"
namespace dxvk {

View File

@ -7,10 +7,11 @@
#include "../util/util_small_vector.h"
#include "dxvk_resource.h"
#include "dxvk_include.h"
namespace dxvk {
class DxvkDevice;
class DxvkCommandList;
class DxvkGpuQueryPool;

View File

@ -9,7 +9,6 @@
#include "dxvk_graphics_state.h"
#include "dxvk_pipelayout.h"
#include "dxvk_renderpass.h"
#include "dxvk_resource.h"
#include "dxvk_shader.h"
#include "dxvk_stats.h"

View File

@ -3,7 +3,6 @@
#include "dxvk_descriptor.h"
#include "dxvk_format.h"
#include "dxvk_memory.h"
#include "dxvk_resource.h"
#include "dxvk_sparse.h"
#include "dxvk_util.h"

View File

@ -8,7 +8,6 @@
#include "dxvk_barrier.h"
#include "dxvk_cmdlist.h"
#include "dxvk_hash.h"
#include "dxvk_resource.h"
namespace dxvk {

View File

@ -7,7 +7,7 @@
#include "dxvk_barrier.h"
#include "dxvk_cmdlist.h"
#include "dxvk_resource.h"
#include "dxvk_image.h"
namespace dxvk {

View File

@ -1,18 +0,0 @@
#include "dxvk_resource.h"
namespace dxvk {
std::atomic<uint64_t> DxvkResource::s_cookie = { 0ull };
DxvkResource::DxvkResource()
: m_useCount(0ull), m_cookie(++s_cookie) {
}
DxvkResource::~DxvkResource() {
}
}

View File

@ -1,129 +0,0 @@
#pragma once
#include "dxvk_include.h"
#include "dxvk_memory.h"
namespace dxvk {
/**
* \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 {
static constexpr uint64_t RdAccessShift = 24;
static constexpr uint64_t WrAccessShift = 44;
static constexpr uint64_t RefcountMask = (1ull << RdAccessShift) - 1;
static constexpr uint64_t RdAccessMask = ((1ull << (WrAccessShift - RdAccessShift)) - 1) << RdAccessShift;
static constexpr uint64_t WrAccessMask = ((1ull << (64 - WrAccessShift)) - 1) << WrAccessShift;
static constexpr uint64_t RefcountInc = 1ull;
static constexpr uint64_t RdAccessInc = 1ull << RdAccessShift;
static constexpr uint64_t WrAccessInc = 1ull << WrAccessShift;
public:
DxvkResource();
virtual ~DxvkResource();
/**
* \brief Unique object identifier
*
* Can be used to identify an object even when
* the lifetime of the object is unknown, and
* without referencing the actual object.
* \returns Unique identifier
*/
uint64_t cookie() const {
return m_cookie;
}
/**
* \brief Increments reference count
*/
void incRef() {
acquire(DxvkAccess::None);
}
/**
* \brief Decrements reference count
*/
void decRef() {
release(DxvkAccess::None);
}
/**
* \brief Acquires resource with given access
*
* Atomically increments both the reference count
* as well as the use count for the given access.
*/
void acquire(DxvkAccess access) {
m_useCount += getIncrement(access);
}
/**
* \brief Releases resource with given access
*
* Atomically decrements both the reference count
* as well as the use count for the given access.
*/
void release(DxvkAccess access) {
if (!(m_useCount -= getIncrement(access)))
delete this;
}
/**
* \brief Converts reference type
*
* \param [in] from Old access type
* \param [in] to New access type
*/
void convertRef(DxvkAccess from, DxvkAccess to) {
uint64_t increment = getIncrement(to) - getIncrement(from);
if (increment)
m_useCount += increment;
}
/**
* \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 {
uint64_t mask = WrAccessMask;
if (access == DxvkAccess::Read)
mask |= RdAccessMask;
return bool(m_useCount.load() & mask);
}
private:
std::atomic<uint64_t> m_useCount;
uint64_t m_cookie;
static constexpr uint64_t getIncrement(DxvkAccess access) {
uint64_t increment = RefcountInc;
if (access != DxvkAccess::None) {
increment |= (access == DxvkAccess::Read)
? RdAccessInc : WrAccessInc;
}
return increment;
}
static std::atomic<uint64_t> s_cookie;
};
}

View File

@ -5,7 +5,8 @@
#include "../util/util_bit.h"
#include "../util/thread.h"
#include "dxvk_resource.h"
#include "dxvk_hash.h"
#include "dxvk_include.h"
namespace dxvk {

View File

@ -7,6 +7,11 @@
namespace dxvk {
DxvkPagedResource::~DxvkPagedResource() {
}
DxvkResourceRef::~DxvkResourceRef() {
auto resource = reinterpret_cast<DxvkPagedResource*>(m_ptr & ~AccessMask);
resource->release(DxvkAccess(m_ptr & AccessMask));

View File

@ -2,8 +2,8 @@
#include <map>
#include "dxvk_access.h"
#include "dxvk_memory.h"
#include "dxvk_resource.h"
namespace dxvk {
@ -427,13 +427,80 @@ namespace dxvk {
/**
* \brief Paged resource
*
* Base class for any resource that can
* hold a sparse page table.
* Base class for memory-backed resources that may
* or may not also have a sparse page table.
*/
class DxvkPagedResource : public DxvkResource {
class DxvkPagedResource {
public:
virtual ~DxvkPagedResource();
/**
* \brief Increments reference count
*/
force_inline void incRef() {
acquire(DxvkAccess::None);
}
/**
* \brief Decrements reference count
*/
force_inline void decRef() {
release(DxvkAccess::None);
}
/**
* \brief Acquires resource with given access
*
* Atomically increments both the reference count
* as well as the use count for the given access.
*/
force_inline void acquire(DxvkAccess access) {
m_useCount.fetch_add(getIncrement(access), std::memory_order_acquire);
}
/**
* \brief Releases resource with given access
*
* Atomically decrements both the reference count
* as well as the use count for the given access.
*/
force_inline void release(DxvkAccess access) {
uint64_t increment = getIncrement(access);
uint64_t remaining = m_useCount.fetch_sub(increment, std::memory_order_release);
if (unlikely(remaining == increment))
delete this;
}
/**
* \brief Converts reference type
*
* \param [in] from Old access type
* \param [in] to New access type
*/
force_inline void convertRef(DxvkAccess from, DxvkAccess to) {
uint64_t increment = getIncrement(to) - getIncrement(from);
if (increment)
m_useCount.fetch_add(increment, std::memory_order_acq_rel);
}
/**
* \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
*/
force_inline bool isInUse(DxvkAccess access) const {
return m_useCount.load(std::memory_order_acquire) >= getIncrement(access);
}
/**
* \brief Queries sparse page table
*
@ -443,6 +510,14 @@ namespace dxvk {
*/
virtual DxvkSparsePageTable* getSparsePageTable() = 0;
private:
std::atomic<uint64_t> m_useCount = { 0u };
static constexpr uint64_t getIncrement(DxvkAccess access) {
return uint64_t(1u) << (uint32_t(access) * 20u);
}
};

View File

@ -99,7 +99,6 @@ dxvk_src = [
'dxvk_platform_exts.cpp',
'dxvk_presenter.cpp',
'dxvk_queue.cpp',
'dxvk_resource.cpp',
'dxvk_sampler.cpp',
'dxvk_shader.cpp',
'dxvk_shader_key.cpp',