From a093feca62982f33be89811b89b6f3f412ef4815 Mon Sep 17 00:00:00 2001 From: Subv Date: Sun, 1 Jul 2018 10:48:50 -0500 Subject: nvmap: Return the address of the nvmap object when Freeing it for the last time. This behavior is confirmed by reverse engineering. --- src/core/hle/service/nvdrv/devices/nvmap.cpp | 13 ++++++++++--- src/core/hle/service/nvdrv/devices/nvmap.h | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp index 23fe98190..2fc7c87e0 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.cpp +++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp @@ -148,6 +148,7 @@ u32 nvmap::IocParam(const std::vector& input, std::vector& output) { } u32 nvmap::IocFree(const std::vector& input, std::vector& output) { + // TODO(Subv): These flags are unconfirmed. enum FreeFlags { Freed = 0, NotFreedYet = 1, @@ -161,15 +162,21 @@ u32 nvmap::IocFree(const std::vector& input, std::vector& output) { auto itr = handles.find(params.handle); ASSERT(itr != handles.end()); + ASSERT(itr->second->refcount > 0); + itr->second->refcount--; - params.refcount = itr->second->refcount; params.size = itr->second->size; - if (itr->second->refcount == 0) + if (itr->second->refcount == 0) { params.flags = Freed; - else + // The address of the nvmap is written to the output if we're finally freeing it, otherwise + // 0 is written. + params.address = itr->second->addr; + } else { params.flags = NotFreedYet; + params.address = 0; + } handles.erase(params.handle); diff --git a/src/core/hle/service/nvdrv/devices/nvmap.h b/src/core/hle/service/nvdrv/devices/nvmap.h index 39fafaa7c..f2eec6409 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.h +++ b/src/core/hle/service/nvdrv/devices/nvmap.h @@ -94,7 +94,7 @@ private: struct IocFreeParams { u32_le handle; INSERT_PADDING_BYTES(4); - u64_le refcount; + u64_le address; u32_le size; u32_le flags; }; -- cgit v1.2.3 From 6c0c81dfdc49c1e9dba9af778b9d6d7cf2008ae5 Mon Sep 17 00:00:00 2001 From: Subv Date: Sun, 1 Jul 2018 10:50:06 -0500 Subject: GPU: Remove a surface from the cache when its backing memory is being unmapped from the GPU's MMU. --- src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index c1eea861d..7d8ed6920 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp @@ -8,6 +8,8 @@ #include "core/core.h" #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h" #include "core/hle/service/nvdrv/devices/nvmap.h" +#include "video_core/renderer_base.h" +#include "video_core/video_core.h" namespace Service::Nvidia::Devices { @@ -154,6 +156,9 @@ u32 nvhost_as_gpu::UnmapBuffer(const std::vector& input, std::vector& ou ASSERT_MSG(itr != buffer_mappings.end(), "Tried to unmap invalid mapping"); + // Remove this memory region from the rasterizer cache. + VideoCore::g_renderer->Rasterizer()->FlushAndInvalidateRegion(params.offset, itr->second.size); + params.offset = gpu.memory_manager->UnmapBuffer(params.offset, itr->second.size); buffer_mappings.erase(itr->second.offset); -- cgit v1.2.3