mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-30 07:54:15 +01:00
Keep track of how often textures/buffers are locked on the CPU
For the upcoming preserve attachment optimisation, which will keep buffers/textures locked on the GPU between executions, we don't want to preserve any which are frequently locked on the CPU as that would result in lots of needless waiting for a resource to be unlocked by the GPU when it occasionally frees all preserve attachments when it could have been done much sooner. By checking if a resource has ever been locked on the CPU and using that to choose whether we preserve it we can avoid such waiting.
This commit is contained in:
parent
993ffb56f4
commit
6719572b3b
@ -331,6 +331,7 @@ namespace skyline::gpu {
|
|||||||
|
|
||||||
void Buffer::lock() {
|
void Buffer::lock() {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
accumulatedCpuLockCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Buffer::LockWithTag(ContextTag pTag) {
|
bool Buffer::LockWithTag(ContextTag pTag) {
|
||||||
@ -349,7 +350,11 @@ namespace skyline::gpu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Buffer::try_lock() {
|
bool Buffer::try_lock() {
|
||||||
return mutex.try_lock();
|
if (mutex.try_lock()) {
|
||||||
|
accumulatedCpuLockCounter++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferDelegate::BufferDelegate(Buffer *buffer) : buffer{buffer} {}
|
BufferDelegate::BufferDelegate(Buffer *buffer) : buffer{buffer} {}
|
||||||
|
@ -89,6 +89,9 @@ namespace skyline::gpu {
|
|||||||
int megaBufferTableShift; //!< Shift to apply to buffer offsets to get their megabuffer table index
|
int megaBufferTableShift; //!< Shift to apply to buffer offsets to get their megabuffer table index
|
||||||
std::vector<MegaBufferTableEntry> megaBufferTable; //!< Table of megabuffer allocations for regions of the buffer
|
std::vector<MegaBufferTableEntry> megaBufferTable; //!< Table of megabuffer allocations for regions of the buffer
|
||||||
|
|
||||||
|
static constexpr size_t FrequentlyLockedThreshold{2}; //!< Threshold for the number of times a buffer can be locked (not from context locks, only normal) before it should be considered frequently locked
|
||||||
|
size_t accumulatedCpuLockCounter{}; //!< Number of times buffer has been locked through non-ContextLocks
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BufferDelegate *delegate;
|
BufferDelegate *delegate;
|
||||||
|
|
||||||
@ -214,6 +217,13 @@ namespace skyline::gpu {
|
|||||||
return SequencedCpuBackingWritesBlocked();
|
return SequencedCpuBackingWritesBlocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If the buffer is frequently locked by threads using non-ContextLocks
|
||||||
|
*/
|
||||||
|
bool FrequentlyLocked() {
|
||||||
|
return accumulatedCpuLockCounter >= FrequentlyLockedThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Waits on a fence cycle if it exists till it's signalled and resets it after
|
* @brief Waits on a fence cycle if it exists till it's signalled and resets it after
|
||||||
* @note The buffer **must** be locked prior to calling this
|
* @note The buffer **must** be locked prior to calling this
|
||||||
|
@ -614,6 +614,7 @@ namespace skyline::gpu {
|
|||||||
|
|
||||||
void Texture::lock() {
|
void Texture::lock() {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
accumulatedCpuLockCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Texture::LockWithTag(ContextTag pTag) {
|
bool Texture::LockWithTag(ContextTag pTag) {
|
||||||
@ -631,7 +632,12 @@ namespace skyline::gpu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Texture::try_lock() {
|
bool Texture::try_lock() {
|
||||||
return mutex.try_lock();
|
if (mutex.try_lock()) {
|
||||||
|
accumulatedCpuLockCounter++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Texture::WaitOnBacking() {
|
bool Texture::WaitOnBacking() {
|
||||||
|
@ -423,6 +423,9 @@ namespace skyline::gpu {
|
|||||||
*/
|
*/
|
||||||
boost::container::small_vector<vk::BufferImageCopy, 10> GetBufferImageCopies();
|
boost::container::small_vector<vk::BufferImageCopy, 10> GetBufferImageCopies();
|
||||||
|
|
||||||
|
static constexpr size_t FrequentlyLockedThreshold{2}; //!< Threshold for the number of times a texture can be locked (not from context locks, only normal) before it should be considered frequently locked
|
||||||
|
size_t accumulatedCpuLockCounter{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<FenceCycle> cycle; //!< A fence cycle for when any host operation mutating the texture has completed, it must be waited on prior to any mutations to the backing
|
std::shared_ptr<FenceCycle> cycle; //!< A fence cycle for when any host operation mutating the texture has completed, it must be waited on prior to any mutations to the backing
|
||||||
std::optional<GuestTexture> guest;
|
std::optional<GuestTexture> guest;
|
||||||
@ -555,5 +558,12 @@ namespace skyline::gpu {
|
|||||||
.levelCount = VK_REMAINING_MIP_LEVELS,
|
.levelCount = VK_REMAINING_MIP_LEVELS,
|
||||||
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If the texture is frequently locked by threads using non-ContextLocks
|
||||||
|
*/
|
||||||
|
bool FrequentlyLocked() {
|
||||||
|
return accumulatedCpuLockCounter >= FrequentlyLockedThreshold;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user