diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/query_cache.h | 36 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_rasterizer.cpp | 4 |
3 files changed, 22 insertions, 23 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 | } |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index cb4928bbe..1f603b668 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -661,10 +661,9 @@ void RasterizerOpenGL::FlushRegion(VAddr addr, u64 size) { | |||
| 661 | if (!addr || !size) { | 661 | if (!addr || !size) { |
| 662 | return; | 662 | return; |
| 663 | } | 663 | } |
| 664 | CacheAddr cache_addr = ToCacheAddr(system.Memory().GetPointer(addr)); | ||
| 665 | texture_cache.FlushRegion(addr, size); | 664 | texture_cache.FlushRegion(addr, size); |
| 666 | buffer_cache.FlushRegion(addr, size); | 665 | buffer_cache.FlushRegion(addr, size); |
| 667 | query_cache.FlushRegion(cache_addr, size); | 666 | query_cache.FlushRegion(addr, size); |
| 668 | } | 667 | } |
| 669 | 668 | ||
| 670 | void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size) { | 669 | void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size) { |
| @@ -676,7 +675,7 @@ void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size) { | |||
| 676 | texture_cache.InvalidateRegion(addr, size); | 675 | texture_cache.InvalidateRegion(addr, size); |
| 677 | shader_cache.InvalidateRegion(cache_addr, size); | 676 | shader_cache.InvalidateRegion(cache_addr, size); |
| 678 | buffer_cache.InvalidateRegion(addr, size); | 677 | buffer_cache.InvalidateRegion(addr, size); |
| 679 | query_cache.InvalidateRegion(cache_addr, size); | 678 | query_cache.InvalidateRegion(addr, size); |
| 680 | } | 679 | } |
| 681 | 680 | ||
| 682 | void RasterizerOpenGL::FlushAndInvalidateRegion(VAddr addr, u64 size) { | 681 | void RasterizerOpenGL::FlushAndInvalidateRegion(VAddr addr, u64 size) { |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index b6ba5de12..199533517 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp | |||
| @@ -502,7 +502,7 @@ void RasterizerVulkan::FlushRegion(VAddr addr, u64 size) { | |||
| 502 | CacheAddr cache_addr = ToCacheAddr(system.Memory().GetPointer(addr)); | 502 | CacheAddr cache_addr = ToCacheAddr(system.Memory().GetPointer(addr)); |
| 503 | texture_cache.FlushRegion(addr, size); | 503 | texture_cache.FlushRegion(addr, size); |
| 504 | buffer_cache.FlushRegion(addr, size); | 504 | buffer_cache.FlushRegion(addr, size); |
| 505 | query_cache.FlushRegion(cache_addr, size); | 505 | query_cache.FlushRegion(addr, size); |
| 506 | } | 506 | } |
| 507 | 507 | ||
| 508 | void RasterizerVulkan::InvalidateRegion(VAddr addr, u64 size) { | 508 | void RasterizerVulkan::InvalidateRegion(VAddr addr, u64 size) { |
| @@ -513,7 +513,7 @@ void RasterizerVulkan::InvalidateRegion(VAddr addr, u64 size) { | |||
| 513 | texture_cache.InvalidateRegion(addr, size); | 513 | texture_cache.InvalidateRegion(addr, size); |
| 514 | pipeline_cache.InvalidateRegion(cache_addr, size); | 514 | pipeline_cache.InvalidateRegion(cache_addr, size); |
| 515 | buffer_cache.InvalidateRegion(addr, size); | 515 | buffer_cache.InvalidateRegion(addr, size); |
| 516 | query_cache.InvalidateRegion(cache_addr, size); | 516 | query_cache.InvalidateRegion(addr, size); |
| 517 | } | 517 | } |
| 518 | 518 | ||
| 519 | void RasterizerVulkan::FlushAndInvalidateRegion(VAddr addr, u64 size) { | 519 | void RasterizerVulkan::FlushAndInvalidateRegion(VAddr addr, u64 size) { |