diff options
author | bunnei <bunneidev@gmail.com> | 2020-05-24 21:23:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-24 21:23:38 +0200 |
commit | 1adabdac7fa0c5804b0472fa1cd215efaecd119b (patch) | |
tree | 279af5e18ec3fedf1f8d979cf162ed77e9e4f46f /src/video_core/rasterizer_cache.h | |
parent | Merge pull request #3964 from ReinUsesLisp/arb-integration (diff) | |
parent | RasterizerCache: Correct documentation. (diff) | |
download | yuzu-1adabdac7fa0c5804b0472fa1cd215efaecd119b.tar yuzu-1adabdac7fa0c5804b0472fa1cd215efaecd119b.tar.gz yuzu-1adabdac7fa0c5804b0472fa1cd215efaecd119b.tar.bz2 yuzu-1adabdac7fa0c5804b0472fa1cd215efaecd119b.tar.lz yuzu-1adabdac7fa0c5804b0472fa1cd215efaecd119b.tar.xz yuzu-1adabdac7fa0c5804b0472fa1cd215efaecd119b.tar.zst yuzu-1adabdac7fa0c5804b0472fa1cd215efaecd119b.zip |
Diffstat (limited to 'src/video_core/rasterizer_cache.h')
-rw-r--r-- | src/video_core/rasterizer_cache.h | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/video_core/rasterizer_cache.h b/src/video_core/rasterizer_cache.h index 22987751e..096ee337c 100644 --- a/src/video_core/rasterizer_cache.h +++ b/src/video_core/rasterizer_cache.h @@ -56,9 +56,27 @@ public: last_modified_ticks = cache.GetModifiedTicks(); } + void SetMemoryMarked(bool is_memory_marked_) { + is_memory_marked = is_memory_marked_; + } + + bool IsMemoryMarked() const { + return is_memory_marked; + } + + void SetSyncPending(bool is_sync_pending_) { + is_sync_pending = is_sync_pending_; + } + + bool IsSyncPending() const { + return is_sync_pending; + } + private: bool is_registered{}; ///< Whether the object is currently registered with the cache bool is_dirty{}; ///< Whether the object is dirty (out of sync with guest memory) + bool is_memory_marked{}; ///< Whether the object is marking rasterizer memory. + bool is_sync_pending{}; ///< Whether the object is pending deletion. u64 last_modified_ticks{}; ///< When the object was last modified, used for in-order flushing VAddr cpu_addr{}; ///< Cpu address memory, unique from emulated virtual address space }; @@ -94,6 +112,30 @@ public: } } + void OnCPUWrite(VAddr addr, std::size_t size) { + std::lock_guard lock{mutex}; + + for (const auto& object : GetSortedObjectsFromRegion(addr, size)) { + if (object->IsRegistered()) { + UnmarkMemory(object); + object->SetSyncPending(true); + marked_for_unregister.emplace_back(object); + } + } + } + + void SyncGuestHost() { + std::lock_guard lock{mutex}; + + for (const auto& object : marked_for_unregister) { + if (object->IsRegistered()) { + object->SetSyncPending(false); + Unregister(object); + } + } + marked_for_unregister.clear(); + } + /// Invalidates everything in the cache void InvalidateAll() { std::lock_guard lock{mutex}; @@ -120,19 +162,32 @@ protected: interval_cache.add({GetInterval(object), ObjectSet{object}}); map_cache.insert({object->GetCpuAddr(), object}); rasterizer.UpdatePagesCachedCount(object->GetCpuAddr(), object->GetSizeInBytes(), 1); + object->SetMemoryMarked(true); } /// Unregisters an object from the cache virtual void Unregister(const T& object) { std::lock_guard lock{mutex}; + UnmarkMemory(object); object->SetIsRegistered(false); - rasterizer.UpdatePagesCachedCount(object->GetCpuAddr(), object->GetSizeInBytes(), -1); + if (object->IsSyncPending()) { + marked_for_unregister.remove(object); + object->SetSyncPending(false); + } const VAddr addr = object->GetCpuAddr(); interval_cache.subtract({GetInterval(object), ObjectSet{object}}); map_cache.erase(addr); } + void UnmarkMemory(const T& object) { + if (!object->IsMemoryMarked()) { + return; + } + rasterizer.UpdatePagesCachedCount(object->GetCpuAddr(), object->GetSizeInBytes(), -1); + object->SetMemoryMarked(false); + } + /// Returns a ticks counter used for tracking when cached objects were last modified u64 GetModifiedTicks() { std::lock_guard lock{mutex}; @@ -194,4 +249,5 @@ private: IntervalCache interval_cache; ///< Cache of objects u64 modified_ticks{}; ///< Counter of cache state ticks, used for in-order flushing VideoCore::RasterizerInterface& rasterizer; + std::list<T> marked_for_unregister; }; |