diff --git a/app/src/main/cpp/skyline/gpu/descriptor_allocator.cpp b/app/src/main/cpp/skyline/gpu/descriptor_allocator.cpp index caf7eec9..152a15d1 100644 --- a/app/src/main/cpp/skyline/gpu/descriptor_allocator.cpp +++ b/app/src/main/cpp/skyline/gpu/descriptor_allocator.cpp @@ -38,10 +38,17 @@ namespace skyline::gpu { pool->freeSetCount--; } + DescriptorAllocator::ActiveDescriptorSet::ActiveDescriptorSet(DescriptorAllocator::ActiveDescriptorSet &&other) noexcept { + pool = std::move(other.pool); + static_cast(*this) = std::exchange(static_cast(other), vk::DescriptorSet{}); + } + DescriptorAllocator::ActiveDescriptorSet::~ActiveDescriptorSet() { - std::scoped_lock lock(*pool); - pool->getDevice().freeDescriptorSets(**pool, 1, this, *pool->getDispatcher()); - pool->freeSetCount++; + if (static_cast(*this)) { + std::scoped_lock lock(*pool); + pool->getDevice().freeDescriptorSets(**pool, 1, this, *pool->getDispatcher()); + pool->freeSetCount++; + } } DescriptorAllocator::DescriptorAllocator(GPU &gpu) : gpu(gpu) { diff --git a/app/src/main/cpp/skyline/gpu/descriptor_allocator.h b/app/src/main/cpp/skyline/gpu/descriptor_allocator.h index 9e83e619..e7b574e2 100644 --- a/app/src/main/cpp/skyline/gpu/descriptor_allocator.h +++ b/app/src/main/cpp/skyline/gpu/descriptor_allocator.h @@ -50,6 +50,13 @@ namespace skyline::gpu { ActiveDescriptorSet(std::shared_ptr pool, vk::DescriptorSet set); public: + ActiveDescriptorSet(ActiveDescriptorSet &&other) noexcept; + + /* Delete the move constructor to prevent early freeing of the descriptor set */ + ActiveDescriptorSet(const ActiveDescriptorSet &) = delete; + + ActiveDescriptorSet &operator=(const ActiveDescriptorSet &) = delete; + ~ActiveDescriptorSet(); };