diff options
Diffstat (limited to 'src/video_core/query_cache.h')
| -rw-r--r-- | src/video_core/query_cache.h | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/video_core/query_cache.h b/src/video_core/query_cache.h index e66054ed0..5ea2b01f2 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,16 @@ 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 = memory_manager.GpuToCpuAddress(gpu_addr); |
| 121 | ASSERT(cpu_addr_opt); | ||
| 122 | VAddr cpu_addr = *cpu_addr_opt; | ||
| 121 | 123 | ||
| 122 | CachedQuery* query = TryGet(ToCacheAddr(host_ptr)); | 124 | CachedQuery* query = TryGet(cpu_addr); |
| 123 | if (!query) { | 125 | if (!query) { |
| 124 | const auto cpu_addr = memory_manager.GpuToCpuAddress(gpu_addr); | 126 | ASSERT_OR_EXECUTE(cpu_addr_opt, return;); |
| 125 | ASSERT_OR_EXECUTE(cpu_addr, return;); | 127 | const auto host_ptr = memory_manager.GetPointer(gpu_addr); |
| 126 | 128 | ||
| 127 | query = Register(type, *cpu_addr, host_ptr, timestamp.has_value()); | 129 | query = Register(type, cpu_addr, host_ptr, timestamp.has_value()); |
| 128 | } | 130 | } |
| 129 | 131 | ||
| 130 | query->BindCounter(Stream(type).Current(), timestamp); | 132 | query->BindCounter(Stream(type).Current(), timestamp); |
| @@ -173,11 +175,11 @@ protected: | |||
| 173 | 175 | ||
| 174 | private: | 176 | private: |
| 175 | /// Flushes a memory range to guest memory and removes it from the cache. | 177 | /// Flushes a memory range to guest memory and removes it from the cache. |
| 176 | void FlushAndRemoveRegion(CacheAddr addr, std::size_t size) { | 178 | void FlushAndRemoveRegion(VAddr addr, std::size_t size) { |
| 177 | const u64 addr_begin = static_cast<u64>(addr); | 179 | const u64 addr_begin = static_cast<u64>(addr); |
| 178 | const u64 addr_end = addr_begin + static_cast<u64>(size); | 180 | const u64 addr_end = addr_begin + static_cast<u64>(size); |
| 179 | const auto in_range = [addr_begin, addr_end](CachedQuery& query) { | 181 | const auto in_range = [addr_begin, addr_end](CachedQuery& query) { |
| 180 | const u64 cache_begin = query.GetCacheAddr(); | 182 | const u64 cache_begin = query.GetCpuAddr(); |
| 181 | const u64 cache_end = cache_begin + query.SizeInBytes(); | 183 | const u64 cache_end = cache_begin + query.SizeInBytes(); |
| 182 | return cache_begin < addr_end && addr_begin < cache_end; | 184 | return cache_begin < addr_end && addr_begin < cache_end; |
| 183 | }; | 185 | }; |
| @@ -193,7 +195,7 @@ private: | |||
| 193 | if (!in_range(query)) { | 195 | if (!in_range(query)) { |
| 194 | continue; | 196 | continue; |
| 195 | } | 197 | } |
| 196 | rasterizer.UpdatePagesCachedCount(query.CpuAddr(), query.SizeInBytes(), -1); | 198 | rasterizer.UpdatePagesCachedCount(query.GetCpuAddr(), query.SizeInBytes(), -1); |
| 197 | query.Flush(); | 199 | query.Flush(); |
| 198 | } | 200 | } |
| 199 | contents.erase(std::remove_if(std::begin(contents), std::end(contents), in_range), | 201 | contents.erase(std::remove_if(std::begin(contents), std::end(contents), in_range), |
| @@ -204,22 +206,21 @@ private: | |||
| 204 | /// Registers the passed parameters as cached and returns a pointer to the stored cached query. | 206 | /// 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) { | 207 | CachedQuery* Register(VideoCore::QueryType type, VAddr cpu_addr, u8* host_ptr, bool timestamp) { |
| 206 | rasterizer.UpdatePagesCachedCount(cpu_addr, CachedQuery::SizeInBytes(timestamp), 1); | 208 | rasterizer.UpdatePagesCachedCount(cpu_addr, CachedQuery::SizeInBytes(timestamp), 1); |
| 207 | const u64 page = static_cast<u64>(ToCacheAddr(host_ptr)) >> PAGE_SHIFT; | 209 | const u64 page = static_cast<u64>(cpu_addr) >> PAGE_SHIFT; |
| 208 | return &cached_queries[page].emplace_back(static_cast<QueryCache&>(*this), type, cpu_addr, | 210 | return &cached_queries[page].emplace_back(static_cast<QueryCache&>(*this), type, cpu_addr, |
| 209 | host_ptr); | 211 | host_ptr); |
| 210 | } | 212 | } |
| 211 | 213 | ||
| 212 | /// Tries to a get a cached query. Returns nullptr on failure. | 214 | /// Tries to a get a cached query. Returns nullptr on failure. |
| 213 | CachedQuery* TryGet(CacheAddr addr) { | 215 | CachedQuery* TryGet(VAddr addr) { |
| 214 | const u64 page = static_cast<u64>(addr) >> PAGE_SHIFT; | 216 | const u64 page = static_cast<u64>(addr) >> PAGE_SHIFT; |
| 215 | const auto it = cached_queries.find(page); | 217 | const auto it = cached_queries.find(page); |
| 216 | if (it == std::end(cached_queries)) { | 218 | if (it == std::end(cached_queries)) { |
| 217 | return nullptr; | 219 | return nullptr; |
| 218 | } | 220 | } |
| 219 | auto& contents = it->second; | 221 | auto& contents = it->second; |
| 220 | const auto found = | 222 | const auto found = std::find_if(std::begin(contents), std::end(contents), |
| 221 | std::find_if(std::begin(contents), std::end(contents), | 223 | [addr](auto& query) { return query.GetCpuAddr() == addr; }); |
| 222 | [addr](auto& query) { return query.GetCacheAddr() == addr; }); | ||
| 223 | return found != std::end(contents) ? &*found : nullptr; | 224 | return found != std::end(contents) ? &*found : nullptr; |
| 224 | } | 225 | } |
| 225 | 226 | ||
| @@ -323,14 +324,10 @@ public: | |||
| 323 | timestamp = timestamp_; | 324 | timestamp = timestamp_; |
| 324 | } | 325 | } |
| 325 | 326 | ||
| 326 | VAddr CpuAddr() const noexcept { | 327 | VAddr GetCpuAddr() const noexcept { |
| 327 | return cpu_addr; | 328 | return cpu_addr; |
| 328 | } | 329 | } |
| 329 | 330 | ||
| 330 | CacheAddr GetCacheAddr() const noexcept { | ||
| 331 | return ToCacheAddr(host_ptr); | ||
| 332 | } | ||
| 333 | |||
| 334 | u64 SizeInBytes() const noexcept { | 331 | u64 SizeInBytes() const noexcept { |
| 335 | return SizeInBytes(timestamp.has_value()); | 332 | return SizeInBytes(timestamp.has_value()); |
| 336 | } | 333 | } |