yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

nvnflinger: release queued handles immediately on disconnection

This commit is contained in:
Liam 2022-10-26 21:35:19 -04:00
parent cdb9fe978f
commit 2cdfbbc07d
4 changed files with 17 additions and 6 deletions

View File

@ -255,15 +255,16 @@ std::optional<NvMap::FreeInfo> NvMap::FreeHandle(Handle::Id handle, bool interna
.address = handle_description->address, .address = handle_description->address,
.size = handle_description->size, .size = handle_description->size,
.was_uncached = handle_description->flags.map_uncached.Value() != 0, .was_uncached = handle_description->flags.map_uncached.Value() != 0,
.can_unlock = true,
}; };
} else { } else {
return std::nullopt; 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 that
if (!hWeak.expired()) { if (!hWeak.expired()) {
LOG_DEBUG(Service_NVDRV, "nvmap handle: {} wasn't freed as it is still in use", handle); 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; return freeInfo;

View File

@ -105,6 +105,7 @@ public:
u64 address; //!< Address the handle referred to before deletion u64 address; //!< Address the handle referred to before deletion
u64 size; //!< Page-aligned handle size u64 size; //!< Page-aligned handle size
bool was_uncached; //!< If the handle was allocated as uncached bool 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); explicit NvMap(Tegra::Host1x::Host1x& host1x);

View File

@ -251,10 +251,12 @@ NvResult nvmap::IocFree(const std::vector<u8>& input, std::vector<u8>& output) {
} }
if (auto freeInfo{file.FreeHandle(params.handle, false)}) { if (auto freeInfo{file.FreeHandle(params.handle, false)}) {
if (freeInfo->can_unlock) {
ASSERT(system.CurrentProcess() ASSERT(system.CurrentProcess()
->PageTable() ->PageTable()
.UnlockForDeviceAddressSpace(freeInfo->address, freeInfo->size) .UnlockForDeviceAddressSpace(freeInfo->address, freeInfo->size)
.IsSuccess()); .IsSuccess());
}
params.address = freeInfo->address; params.address = freeInfo->address;
params.size = static_cast<u32>(freeInfo->size); params.size = static_cast<u32>(freeInfo->size);
params.flags.raw = 0; params.flags.raw = 0;

View File

@ -742,6 +742,13 @@ Status BufferQueueProducer::Disconnect(NativeWindowApi api) {
return Status::NoError; 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) { switch (api) {
case NativeWindowApi::Egl: case NativeWindowApi::Egl:
case NativeWindowApi::Cpu: case NativeWindowApi::Cpu: