mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-15 10:50:06 +00:00
nvservices: unmap only on last container free
This commit is contained in:
parent
0cbb555e9a
commit
06fd7f2012
@ -49,6 +49,7 @@ SessionId Container::OpenSession(Kernel::KProcess* process) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (session.process == process) {
|
if (session.process == process) {
|
||||||
|
session.ref_count++;
|
||||||
return session.id;
|
return session.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,6 +67,7 @@ SessionId Container::OpenSession(Kernel::KProcess* process) {
|
|||||||
}
|
}
|
||||||
auto& session = impl->sessions[new_id];
|
auto& session = impl->sessions[new_id];
|
||||||
session.is_active = true;
|
session.is_active = true;
|
||||||
|
session.ref_count = 1;
|
||||||
// Optimization
|
// Optimization
|
||||||
if (process->IsApplication()) {
|
if (process->IsApplication()) {
|
||||||
auto& page_table = process->GetPageTable().GetBasePageTable();
|
auto& page_table = process->GetPageTable().GetBasePageTable();
|
||||||
@ -114,8 +116,11 @@ SessionId Container::OpenSession(Kernel::KProcess* process) {
|
|||||||
|
|
||||||
void Container::CloseSession(SessionId session_id) {
|
void Container::CloseSession(SessionId session_id) {
|
||||||
std::scoped_lock lk(impl->session_guard);
|
std::scoped_lock lk(impl->session_guard);
|
||||||
impl->file.UnmapAllHandles(session_id);
|
|
||||||
auto& session = impl->sessions[session_id.id];
|
auto& session = impl->sessions[session_id.id];
|
||||||
|
if (--session.ref_count > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
impl->file.UnmapAllHandles(session_id);
|
||||||
auto& smmu = impl->host1x.MemoryManager();
|
auto& smmu = impl->host1x.MemoryManager();
|
||||||
if (session.has_preallocated_area) {
|
if (session.has_preallocated_area) {
|
||||||
const DAddr region_start = session.mapper->GetRegionStart();
|
const DAddr region_start = session.mapper->GetRegionStart();
|
||||||
|
@ -46,6 +46,7 @@ struct Session {
|
|||||||
bool has_preallocated_area{};
|
bool has_preallocated_area{};
|
||||||
std::unique_ptr<HeapMapper> mapper{};
|
std::unique_ptr<HeapMapper> mapper{};
|
||||||
bool is_active{};
|
bool is_active{};
|
||||||
|
s32 ref_count{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Container {
|
class Container {
|
||||||
|
@ -333,10 +333,14 @@ void NvMap::UnmapAllHandles(NvCore::SessionId session_id) {
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
for (auto& [id, handle] : handles_copy) {
|
for (auto& [id, handle] : handles_copy) {
|
||||||
if (handle->session_id.id == session_id.id) {
|
{
|
||||||
FreeHandle(id, false);
|
std::scoped_lock lk{handle->mutex};
|
||||||
|
if (handle->session_id.id != session_id.id || handle->dupes <= 0) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
FreeHandle(id, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Service::Nvidia::NvCore
|
} // namespace Service::Nvidia::NvCore
|
||||||
|
Loading…
Reference in New Issue
Block a user