diff options
| author | 2020-04-05 18:39:24 -0400 | |
|---|---|---|
| committer | 2020-04-06 09:23:07 -0400 | |
| commit | 3dd5c07454bda0518b965f941399d64aabac5629 (patch) | |
| tree | 217539bf095122bc2d81898044bf488887196e28 /src/video_core/query_cache.h | |
| parent | Buffer Cache: Use vAddr instead of physical memory. (diff) | |
| download | yuzu-3dd5c07454bda0518b965f941399d64aabac5629.tar.gz yuzu-3dd5c07454bda0518b965f941399d64aabac5629.tar.xz yuzu-3dd5c07454bda0518b965f941399d64aabac5629.zip | |
Query Cache: Use VAddr instead of physical memory for adressing.
Diffstat (limited to 'src/video_core/query_cache.h')
| -rw-r--r-- | src/video_core/query_cache.h | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/video_core/query_cache.h b/src/video_core/query_cache.h index e66054ed0..84cbe93f6 100644 --- a/src/video_core/query_cache.h +++ b/src/video_core/query_cache.h | |||
| @@ -98,12 +98,12 @@ public: | |||
| 98 | static_cast<QueryCache&>(*this), | 98 | static_cast<QueryCache&>(*this), |
| 99 | VideoCore::QueryType::SamplesPassed}}} {} | 99 | VideoCore::QueryType::SamplesPassed}}} {} |
| 100 | 100 | ||
| 101 | void InvalidateRegion(CacheAddr addr, std::size_t size) { | 101 | void InvalidateRegion(VAddr addr, std::size_t size) { |
| 102 | std::unique_lock lock{mutex}; | 102 | std::unique_lock lock{mutex}; |
| 103 | FlushAndRemoveRegion(addr, size); | 103 | FlushAndRemoveRegion(addr, size); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | void FlushRegion(CacheAddr addr, std::size_t size) { | 106 | void FlushRegion(VAddr addr, std::size_t size) { |
| 107 | std::unique_lock lock{mutex}; | 107 | std::unique_lock lock{mutex}; |
| 108 | FlushAndRemoveRegion(addr, size); | 108 | FlushAndRemoveRegion(addr, size); |
| 109 | } | 109 | } |
| @@ -117,14 +117,18 @@ public: | |||
| 117 | void Query(GPUVAddr gpu_addr, VideoCore::QueryType type, std::optional<u64> timestamp) { | 117 | void Query(GPUVAddr gpu_addr, VideoCore::QueryType type, std::optional<u64> timestamp) { |
| 118 | std::unique_lock lock{mutex}; | 118 | std::unique_lock lock{mutex}; |
| 119 | auto& memory_manager = system.GPU().MemoryManager(); | 119 | auto& memory_manager = system.GPU().MemoryManager(); |
| 120 | const auto host_ptr = memory_manager.GetPointer(gpu_addr); | 120 | const std::optional<VAddr> cpu_addr_opt = |
| 121 | memory_manager.GpuToCpuAddress(gpu_addr); | ||
| 122 | ASSERT(cpu_addr_opt); | ||
| 123 | VAddr cpu_addr = *cpu_addr_opt; | ||
| 121 | 124 | ||
| 122 | CachedQuery* query = TryGet(ToCacheAddr(host_ptr)); | 125 | |
| 126 | CachedQuery* query = TryGet(cpu_addr); | ||
| 123 | if (!query) { | 127 | if (!query) { |
| 124 | const auto cpu_addr = memory_manager.GpuToCpuAddress(gpu_addr); | 128 | ASSERT_OR_EXECUTE(cpu_addr_opt, return;); |
| 125 | ASSERT_OR_EXECUTE(cpu_addr, return;); | 129 | const auto host_ptr = memory_manager.GetPointer(gpu_addr); |
| 126 | 130 | ||
| 127 | query = Register(type, *cpu_addr, host_ptr, timestamp.has_value()); | 131 | query = Register(type, cpu_addr, host_ptr, timestamp.has_value()); |
| 128 | } | 132 | } |
| 129 | 133 | ||
| 130 | query->BindCounter(Stream(type).Current(), timestamp); | 134 | query->BindCounter(Stream(type).Current(), timestamp); |
| @@ -173,11 +177,11 @@ protected: | |||
| 173 | 177 | ||
| 174 | private: | 178 | private: |
| 175 | /// Flushes a memory range to guest memory and removes it from the cache. | 179 | /// Flushes a memory range to guest memory and removes it from the cache. |
| 176 | void FlushAndRemoveRegion(CacheAddr addr, std::size_t size) { | 180 | void FlushAndRemoveRegion(VAddr addr, std::size_t size) { |
| 177 | const u64 addr_begin = static_cast<u64>(addr); | 181 | const u64 addr_begin = static_cast<u64>(addr); |
| 178 | const u64 addr_end = addr_begin + static_cast<u64>(size); | 182 | const u64 addr_end = addr_begin + static_cast<u64>(size); |
| 179 | const auto in_range = [addr_begin, addr_end](CachedQuery& query) { | 183 | const auto in_range = [addr_begin, addr_end](CachedQuery& query) { |
| 180 | const u64 cache_begin = query.GetCacheAddr(); | 184 | const u64 cache_begin = query.GetCpuAddr(); |
| 181 | const u64 cache_end = cache_begin + query.SizeInBytes(); | 185 | const u64 cache_end = cache_begin + query.SizeInBytes(); |
| 182 | return cache_begin < addr_end && addr_begin < cache_end; | 186 | return cache_begin < addr_end && addr_begin < cache_end; |
| 183 | }; | 187 | }; |
| @@ -193,7 +197,7 @@ private: | |||
| 193 | if (!in_range(query)) { | 197 | if (!in_range(query)) { |
| 194 | continue; | 198 | continue; |
| 195 | } | 199 | } |
| 196 | rasterizer.UpdatePagesCachedCount(query.CpuAddr(), query.SizeInBytes(), -1); | 200 | rasterizer.UpdatePagesCachedCount(query.GetCpuAddr(), query.SizeInBytes(), -1); |
| 197 | query.Flush(); | 201 | query.Flush(); |
| 198 | } | 202 | } |
| 199 | contents.erase(std::remove_if(std::begin(contents), std::end(contents), in_range), | 203 | contents.erase(std::remove_if(std::begin(contents), std::end(contents), in_range), |
| @@ -204,13 +208,13 @@ private: | |||
| 204 | /// Registers the passed parameters as cached and returns a pointer to the stored cached query. | 208 | /// Registers the passed parameters as cached and returns a pointer to the stored cached query. |
| 205 | CachedQuery* Register(VideoCore::QueryType type, VAddr cpu_addr, u8* host_ptr, bool timestamp) { | 209 | CachedQuery* Register(VideoCore::QueryType type, VAddr cpu_addr, u8* host_ptr, bool timestamp) { |
| 206 | rasterizer.UpdatePagesCachedCount(cpu_addr, CachedQuery::SizeInBytes(timestamp), 1); | 210 | rasterizer.UpdatePagesCachedCount(cpu_addr, CachedQuery::SizeInBytes(timestamp), 1); |
| 207 | const u64 page = static_cast<u64>(ToCacheAddr(host_ptr)) >> PAGE_SHIFT; | 211 | const u64 page = static_cast<u64>(cpu_addr) >> PAGE_SHIFT; |
| 208 | return &cached_queries[page].emplace_back(static_cast<QueryCache&>(*this), type, cpu_addr, | 212 | return &cached_queries[page].emplace_back(static_cast<QueryCache&>(*this), type, cpu_addr, |
| 209 | host_ptr); | 213 | host_ptr); |
| 210 | } | 214 | } |
| 211 | 215 | ||
| 212 | /// Tries to a get a cached query. Returns nullptr on failure. | 216 | /// Tries to a get a cached query. Returns nullptr on failure. |
| 213 | CachedQuery* TryGet(CacheAddr addr) { | 217 | CachedQuery* TryGet(VAddr addr) { |
| 214 | const u64 page = static_cast<u64>(addr) >> PAGE_SHIFT; | 218 | const u64 page = static_cast<u64>(addr) >> PAGE_SHIFT; |
| 215 | const auto it = cached_queries.find(page); | 219 | const auto it = cached_queries.find(page); |
| 216 | if (it == std::end(cached_queries)) { | 220 | if (it == std::end(cached_queries)) { |
| @@ -219,7 +223,7 @@ private: | |||
| 219 | auto& contents = it->second; | 223 | auto& contents = it->second; |
| 220 | const auto found = | 224 | const auto found = |
| 221 | std::find_if(std::begin(contents), std::end(contents), | 225 | std::find_if(std::begin(contents), std::end(contents), |
| 222 | [addr](auto& query) { return query.GetCacheAddr() == addr; }); | 226 | [addr](auto& query) { return query.GetCpuAddr() == addr; }); |
| 223 | return found != std::end(contents) ? &*found : nullptr; | 227 | return found != std::end(contents) ? &*found : nullptr; |
| 224 | } | 228 | } |
| 225 | 229 | ||
| @@ -323,14 +327,10 @@ public: | |||
| 323 | timestamp = timestamp_; | 327 | timestamp = timestamp_; |
| 324 | } | 328 | } |
| 325 | 329 | ||
| 326 | VAddr CpuAddr() const noexcept { | 330 | VAddr GetCpuAddr() const noexcept { |
| 327 | return cpu_addr; | 331 | return cpu_addr; |
| 328 | } | 332 | } |
| 329 | 333 | ||
| 330 | CacheAddr GetCacheAddr() const noexcept { | ||
| 331 | return ToCacheAddr(host_ptr); | ||
| 332 | } | ||
| 333 | |||
| 334 | u64 SizeInBytes() const noexcept { | 334 | u64 SizeInBytes() const noexcept { |
| 335 | return SizeInBytes(timestamp.has_value()); | 335 | return SizeInBytes(timestamp.has_value()); |
| 336 | } | 336 | } |