VERY experimental Nintendo Switch 2 emulator
C++
nvnflinger: release queued handles immediately on disconnection
Liama71c698323fd
diff --git a/src/core/hle/service/nvdrv/core/nvmap.cpp b/src/core/hle/service/nvdrv/core/nvmap.cppindex fbd8a74a55..a51ca54447 100644--- a/src/core/hle/service/nvdrv/core/nvmap.cpp+++ b/src/core/hle/service/nvdrv/core/nvmap.cpp@@ -255,15 +255,16 @@ std::optional<NvMap::FreeInfo> NvMap::FreeHandle(Handle::Id handle, bool interna.address = handle_description->address,.size = handle_description->size,.was_uncached = handle_description->flags.map_uncached.Value() != 0,+ .can_unlock = true,};} else {return std::nullopt;}- // Handle hasn't been freed from memory, set address to 0 to mark that the handle wasn't freed+ // If the handle hasn't been freed from memory, mark thatif (!hWeak.expired()) {LOG_DEBUG(Service_NVDRV, "nvmap handle: {} wasn't freed as it is still in use", handle);- freeInfo.address = 0;+ freeInfo.can_unlock = false;}return freeInfo;diff --git a/src/core/hle/service/nvdrv/core/nvmap.h b/src/core/hle/service/nvdrv/core/nvmap.hindex b9dd3801f4..a8e5738909 100644--- a/src/core/hle/service/nvdrv/core/nvmap.h+++ b/src/core/hle/service/nvdrv/core/nvmap.h@@ -105,6 +105,7 @@ public:u64 address; //!< Address the handle referred to before deletionu64 size; //!< Page-aligned handle sizebool was_uncached; //!< If the handle was allocated as uncached+ bool can_unlock; //!< If the address region is ready to be unlocked};explicit NvMap(Tegra::Host1x::Host1x& host1x);diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cppindex b606790217..44388655d3 100644--- a/src/core/hle/service/nvdrv/devices/nvmap.cpp+++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp@@ -251,10 +251,12 @@ NvResult nvmap::IocFree(const std::vector<u8>& input, std::vector<u8>& output) {}if (auto freeInfo{file.FreeHandle(params.handle, false)}) {- ASSERT(system.CurrentProcess()- ->PageTable()- .UnlockForDeviceAddressSpace(freeInfo->address, freeInfo->size)- .IsSuccess());+ if (freeInfo->can_unlock) {+ ASSERT(system.CurrentProcess()+ ->PageTable()+ .UnlockForDeviceAddressSpace(freeInfo->address, freeInfo->size)+ .IsSuccess());+ }params.address = freeInfo->address;params.size = static_cast<u32>(freeInfo->size);params.flags.raw = 0;diff --git a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp b/src/core/hle/service/nvflinger/buffer_queue_producer.cppindex 77ddbb6efb..41ba44b215 100644--- a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp+++ b/src/core/hle/service/nvflinger/buffer_queue_producer.cpp@@ -742,6 +742,13 @@ Status BufferQueueProducer::Disconnect(NativeWindowApi api) {return Status::NoError;}+ // HACK: We are not Android. Remove handle for items in queue, and clear queue.+ // Allows synchronous destruction of nvmap handles.+ for (auto& item : core->queue) {+ nvmap.FreeHandle(item.graphic_buffer->BufferId(), true);+ }+ core->queue.clear();+switch (api) {case NativeWindowApi::Egl:case NativeWindowApi::Cpu: