diff options
| author | 2020-04-05 19:18:00 -0400 | |
|---|---|---|
| committer | 2020-04-06 09:23:07 -0400 | |
| commit | ea535d9470fb86f274304f76fd02300618b3500e (patch) | |
| tree | 4bf313590ae7024bc0d2f4cfb6c24e57dda73189 /src/video_core/rasterizer_cache.h | |
| parent | Query Cache: Use VAddr instead of physical memory for adressing. (diff) | |
| download | yuzu-ea535d9470fb86f274304f76fd02300618b3500e.tar.gz yuzu-ea535d9470fb86f274304f76fd02300618b3500e.tar.xz yuzu-ea535d9470fb86f274304f76fd02300618b3500e.zip | |
Shader/Pipeline Cache: Use VAddr instead of physical memory for addressing.
Diffstat (limited to 'src/video_core/rasterizer_cache.h')
| -rw-r--r-- | src/video_core/rasterizer_cache.h | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/src/video_core/rasterizer_cache.h b/src/video_core/rasterizer_cache.h index 6de1597a2..22987751e 100644 --- a/src/video_core/rasterizer_cache.h +++ b/src/video_core/rasterizer_cache.h | |||
| @@ -18,22 +18,14 @@ | |||
| 18 | 18 | ||
| 19 | class RasterizerCacheObject { | 19 | class RasterizerCacheObject { |
| 20 | public: | 20 | public: |
| 21 | explicit RasterizerCacheObject(const u8* host_ptr) | 21 | explicit RasterizerCacheObject(const VAddr cpu_addr) : cpu_addr{cpu_addr} {} |
| 22 | : host_ptr{host_ptr}, cache_addr{ToCacheAddr(host_ptr)} {} | ||
| 23 | 22 | ||
| 24 | virtual ~RasterizerCacheObject(); | 23 | virtual ~RasterizerCacheObject(); |
| 25 | 24 | ||
| 26 | CacheAddr GetCacheAddr() const { | 25 | VAddr GetCpuAddr() const { |
| 27 | return cache_addr; | 26 | return cpu_addr; |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | const u8* GetHostPtr() const { | ||
| 31 | return host_ptr; | ||
| 32 | } | ||
| 33 | |||
| 34 | /// Gets the address of the shader in guest memory, required for cache management | ||
| 35 | virtual VAddr GetCpuAddr() const = 0; | ||
| 36 | |||
| 37 | /// Gets the size of the shader in guest memory, required for cache management | 29 | /// Gets the size of the shader in guest memory, required for cache management |
| 38 | virtual std::size_t GetSizeInBytes() const = 0; | 30 | virtual std::size_t GetSizeInBytes() const = 0; |
| 39 | 31 | ||
| @@ -68,8 +60,7 @@ private: | |||
| 68 | bool is_registered{}; ///< Whether the object is currently registered with the cache | 60 | bool is_registered{}; ///< Whether the object is currently registered with the cache |
| 69 | bool is_dirty{}; ///< Whether the object is dirty (out of sync with guest memory) | 61 | bool is_dirty{}; ///< Whether the object is dirty (out of sync with guest memory) |
| 70 | u64 last_modified_ticks{}; ///< When the object was last modified, used for in-order flushing | 62 | u64 last_modified_ticks{}; ///< When the object was last modified, used for in-order flushing |
| 71 | const u8* host_ptr{}; ///< Pointer to the memory backing this cached region | 63 | VAddr cpu_addr{}; ///< Cpu address memory, unique from emulated virtual address space |
| 72 | CacheAddr cache_addr{}; ///< Cache address memory, unique from emulated virtual address space | ||
| 73 | }; | 64 | }; |
| 74 | 65 | ||
| 75 | template <class T> | 66 | template <class T> |
| @@ -80,7 +71,7 @@ public: | |||
| 80 | explicit RasterizerCache(VideoCore::RasterizerInterface& rasterizer) : rasterizer{rasterizer} {} | 71 | explicit RasterizerCache(VideoCore::RasterizerInterface& rasterizer) : rasterizer{rasterizer} {} |
| 81 | 72 | ||
| 82 | /// Write any cached resources overlapping the specified region back to memory | 73 | /// Write any cached resources overlapping the specified region back to memory |
| 83 | void FlushRegion(CacheAddr addr, std::size_t size) { | 74 | void FlushRegion(VAddr addr, std::size_t size) { |
| 84 | std::lock_guard lock{mutex}; | 75 | std::lock_guard lock{mutex}; |
| 85 | 76 | ||
| 86 | const auto& objects{GetSortedObjectsFromRegion(addr, size)}; | 77 | const auto& objects{GetSortedObjectsFromRegion(addr, size)}; |
| @@ -90,7 +81,7 @@ public: | |||
| 90 | } | 81 | } |
| 91 | 82 | ||
| 92 | /// Mark the specified region as being invalidated | 83 | /// Mark the specified region as being invalidated |
| 93 | void InvalidateRegion(CacheAddr addr, u64 size) { | 84 | void InvalidateRegion(VAddr addr, u64 size) { |
| 94 | std::lock_guard lock{mutex}; | 85 | std::lock_guard lock{mutex}; |
| 95 | 86 | ||
| 96 | const auto& objects{GetSortedObjectsFromRegion(addr, size)}; | 87 | const auto& objects{GetSortedObjectsFromRegion(addr, size)}; |
| @@ -114,27 +105,20 @@ public: | |||
| 114 | 105 | ||
| 115 | protected: | 106 | protected: |
| 116 | /// Tries to get an object from the cache with the specified cache address | 107 | /// Tries to get an object from the cache with the specified cache address |
| 117 | T TryGet(CacheAddr addr) const { | 108 | T TryGet(VAddr addr) const { |
| 118 | const auto iter = map_cache.find(addr); | 109 | const auto iter = map_cache.find(addr); |
| 119 | if (iter != map_cache.end()) | 110 | if (iter != map_cache.end()) |
| 120 | return iter->second; | 111 | return iter->second; |
| 121 | return nullptr; | 112 | return nullptr; |
| 122 | } | 113 | } |
| 123 | 114 | ||
| 124 | T TryGet(const void* addr) const { | ||
| 125 | const auto iter = map_cache.find(ToCacheAddr(addr)); | ||
| 126 | if (iter != map_cache.end()) | ||
| 127 | return iter->second; | ||
| 128 | return nullptr; | ||
| 129 | } | ||
| 130 | |||
| 131 | /// Register an object into the cache | 115 | /// Register an object into the cache |
| 132 | virtual void Register(const T& object) { | 116 | virtual void Register(const T& object) { |
| 133 | std::lock_guard lock{mutex}; | 117 | std::lock_guard lock{mutex}; |
| 134 | 118 | ||
| 135 | object->SetIsRegistered(true); | 119 | object->SetIsRegistered(true); |
| 136 | interval_cache.add({GetInterval(object), ObjectSet{object}}); | 120 | interval_cache.add({GetInterval(object), ObjectSet{object}}); |
| 137 | map_cache.insert({object->GetCacheAddr(), object}); | 121 | map_cache.insert({object->GetCpuAddr(), object}); |
| 138 | rasterizer.UpdatePagesCachedCount(object->GetCpuAddr(), object->GetSizeInBytes(), 1); | 122 | rasterizer.UpdatePagesCachedCount(object->GetCpuAddr(), object->GetSizeInBytes(), 1); |
| 139 | } | 123 | } |
| 140 | 124 | ||
| @@ -144,7 +128,7 @@ protected: | |||
| 144 | 128 | ||
| 145 | object->SetIsRegistered(false); | 129 | object->SetIsRegistered(false); |
| 146 | rasterizer.UpdatePagesCachedCount(object->GetCpuAddr(), object->GetSizeInBytes(), -1); | 130 | rasterizer.UpdatePagesCachedCount(object->GetCpuAddr(), object->GetSizeInBytes(), -1); |
| 147 | const CacheAddr addr = object->GetCacheAddr(); | 131 | const VAddr addr = object->GetCpuAddr(); |
| 148 | interval_cache.subtract({GetInterval(object), ObjectSet{object}}); | 132 | interval_cache.subtract({GetInterval(object), ObjectSet{object}}); |
| 149 | map_cache.erase(addr); | 133 | map_cache.erase(addr); |
| 150 | } | 134 | } |
| @@ -173,7 +157,7 @@ protected: | |||
| 173 | 157 | ||
| 174 | private: | 158 | private: |
| 175 | /// Returns a list of cached objects from the specified memory region, ordered by access time | 159 | /// Returns a list of cached objects from the specified memory region, ordered by access time |
| 176 | std::vector<T> GetSortedObjectsFromRegion(CacheAddr addr, u64 size) { | 160 | std::vector<T> GetSortedObjectsFromRegion(VAddr addr, u64 size) { |
| 177 | if (size == 0) { | 161 | if (size == 0) { |
| 178 | return {}; | 162 | return {}; |
| 179 | } | 163 | } |
| @@ -197,13 +181,13 @@ private: | |||
| 197 | } | 181 | } |
| 198 | 182 | ||
| 199 | using ObjectSet = std::set<T>; | 183 | using ObjectSet = std::set<T>; |
| 200 | using ObjectCache = std::unordered_map<CacheAddr, T>; | 184 | using ObjectCache = std::unordered_map<VAddr, T>; |
| 201 | using IntervalCache = boost::icl::interval_map<CacheAddr, ObjectSet>; | 185 | using IntervalCache = boost::icl::interval_map<VAddr, ObjectSet>; |
| 202 | using ObjectInterval = typename IntervalCache::interval_type; | 186 | using ObjectInterval = typename IntervalCache::interval_type; |
| 203 | 187 | ||
| 204 | static auto GetInterval(const T& object) { | 188 | static auto GetInterval(const T& object) { |
| 205 | return ObjectInterval::right_open(object->GetCacheAddr(), | 189 | return ObjectInterval::right_open(object->GetCpuAddr(), |
| 206 | object->GetCacheAddr() + object->GetSizeInBytes()); | 190 | object->GetCpuAddr() + object->GetSizeInBytes()); |
| 207 | } | 191 | } |
| 208 | 192 | ||
| 209 | ObjectCache map_cache; | 193 | ObjectCache map_cache; |