Lock TextureManager/BufferManager during submission

Multiple threads concurrently accessing the `TextureManager`/`BufferManager` (Referred to as "resource managers") has a potential deadlock with a resource being locked while acquiring the resource manager lock while the thread owning it tries to acquire a lock on the resource resulting in a deadlock.

This has been fixed with locking of resource manager now being externally handled which ensures it can be locked prior to locking any resources, `CommandExecutor` provides accessors for retrieving the resource manager which automatically handles locking aside doing so on attachment of resources.
This commit is contained in:
PixelyIon
2022-06-26 14:58:58 +05:30
parent 1239907ce8
commit 0ac5f4ce27
9 changed files with 117 additions and 16 deletions

View File

@ -6,6 +6,18 @@
namespace skyline::gpu {
TextureManager::TextureManager(GPU &gpu) : gpu(gpu) {}
void TextureManager::lock() {
mutex.lock();
}
void TextureManager::unlock() {
mutex.unlock();
}
bool TextureManager::try_lock() {
return mutex.try_lock();
}
std::shared_ptr<TextureView> TextureManager::FindOrCreate(const GuestTexture &guestTexture, ContextTag tag) {
auto guestMapping{guestTexture.mappings.front()};
@ -23,7 +35,6 @@ namespace skyline::gpu {
* 5) Create a new texture and insert it in the map then return it
*/
std::scoped_lock lock(mutex);
std::shared_ptr<Texture> match{};
auto mappingEnd{std::upper_bound(textures.begin(), textures.end(), guestMapping)}, hostMapping{mappingEnd};
while (hostMapping != textures.begin() && (--hostMapping)->end() > guestMapping.begin()) {