diff options
| author | 2018-08-28 18:43:08 -0400 | |
|---|---|---|
| committer | 2018-08-31 13:07:27 -0400 | |
| commit | 16d65182f99ed1066c8e88a774d0a3637f97ae01 (patch) | |
| tree | 3c10dfc449c7ebeaf40b9c249a9b483a714ecf3e /src/video_core/rasterizer_cache.h | |
| parent | Implement BC6H_UF16 & BC6H_SF16 (#1092) (diff) | |
| download | yuzu-16d65182f99ed1066c8e88a774d0a3637f97ae01.tar.gz yuzu-16d65182f99ed1066c8e88a774d0a3637f97ae01.tar.xz yuzu-16d65182f99ed1066c8e88a774d0a3637f97ae01.zip | |
gl_rasterizer: Fix issues with the rasterizer cache.
- Use a single cached page map.
- Fix calculation of ending page.
Diffstat (limited to 'src/video_core/rasterizer_cache.h')
| -rw-r--r-- | src/video_core/rasterizer_cache.h | 54 |
1 files changed, 8 insertions, 46 deletions
diff --git a/src/video_core/rasterizer_cache.h b/src/video_core/rasterizer_cache.h index 7a0492a4e..51245f502 100644 --- a/src/video_core/rasterizer_cache.h +++ b/src/video_core/rasterizer_cache.h | |||
| @@ -5,12 +5,13 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <unordered_map> | 7 | #include <unordered_map> |
| 8 | #include <boost/icl/interval_map.hpp> | ||
| 9 | #include <boost/range/iterator_range.hpp> | ||
| 10 | 8 | ||
| 11 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "core/core.h" | ||
| 12 | #include "core/memory.h" | 11 | #include "core/memory.h" |
| 13 | #include "video_core/memory_manager.h" | 12 | #include "video_core/memory_manager.h" |
| 13 | #include "video_core/rasterizer_interface.h" | ||
| 14 | #include "video_core/renderer_base.h" | ||
| 14 | 15 | ||
| 15 | template <class T> | 16 | template <class T> |
| 16 | class RasterizerCache : NonCopyable { | 17 | class RasterizerCache : NonCopyable { |
| @@ -54,8 +55,9 @@ protected: | |||
| 54 | return; | 55 | return; |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 57 | cached_objects[object->GetAddr()] = object; | 58 | auto& rasterizer = Core::System::GetInstance().Renderer().Rasterizer(); |
| 58 | UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), 1); | 59 | rasterizer.UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), 1); |
| 60 | cached_objects[object->GetAddr()] = std::move(object); | ||
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | /// Unregisters an object from the cache | 63 | /// Unregisters an object from the cache |
| @@ -66,51 +68,11 @@ protected: | |||
| 66 | return; | 68 | return; |
| 67 | } | 69 | } |
| 68 | 70 | ||
| 69 | UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), -1); | 71 | auto& rasterizer = Core::System::GetInstance().Renderer().Rasterizer(); |
| 72 | rasterizer.UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), -1); | ||
| 70 | cached_objects.erase(search); | 73 | cached_objects.erase(search); |
| 71 | } | 74 | } |
| 72 | 75 | ||
| 73 | private: | 76 | private: |
| 74 | using PageMap = boost::icl::interval_map<u64, int>; | ||
| 75 | |||
| 76 | template <typename Map, typename Interval> | ||
| 77 | constexpr auto RangeFromInterval(Map& map, const Interval& interval) { | ||
| 78 | return boost::make_iterator_range(map.equal_range(interval)); | ||
| 79 | } | ||
| 80 | |||
| 81 | /// Increase/decrease the number of object in pages touching the specified region | ||
| 82 | void UpdatePagesCachedCount(Tegra::GPUVAddr addr, u64 size, int delta) { | ||
| 83 | const u64 page_start{addr >> Tegra::MemoryManager::PAGE_BITS}; | ||
| 84 | const u64 page_end{(addr + size) >> Tegra::MemoryManager::PAGE_BITS}; | ||
| 85 | |||
| 86 | // Interval maps will erase segments if count reaches 0, so if delta is negative we have to | ||
| 87 | // subtract after iterating | ||
| 88 | const auto pages_interval = PageMap::interval_type::right_open(page_start, page_end); | ||
| 89 | if (delta > 0) | ||
| 90 | cached_pages.add({pages_interval, delta}); | ||
| 91 | |||
| 92 | for (const auto& pair : RangeFromInterval(cached_pages, pages_interval)) { | ||
| 93 | const auto interval = pair.first & pages_interval; | ||
| 94 | const int count = pair.second; | ||
| 95 | |||
| 96 | const Tegra::GPUVAddr interval_start_addr = boost::icl::first(interval) | ||
| 97 | << Tegra::MemoryManager::PAGE_BITS; | ||
| 98 | const Tegra::GPUVAddr interval_end_addr = boost::icl::last_next(interval) | ||
| 99 | << Tegra::MemoryManager::PAGE_BITS; | ||
| 100 | const u64 interval_size = interval_end_addr - interval_start_addr; | ||
| 101 | |||
| 102 | if (delta > 0 && count == delta) | ||
| 103 | Memory::RasterizerMarkRegionCached(interval_start_addr, interval_size, true); | ||
| 104 | else if (delta < 0 && count == -delta) | ||
| 105 | Memory::RasterizerMarkRegionCached(interval_start_addr, interval_size, false); | ||
| 106 | else | ||
| 107 | ASSERT(count >= 0); | ||
| 108 | } | ||
| 109 | |||
| 110 | if (delta < 0) | ||
| 111 | cached_pages.add({pages_interval, delta}); | ||
| 112 | } | ||
| 113 | |||
| 114 | std::unordered_map<Tegra::GPUVAddr, T> cached_objects; | 77 | std::unordered_map<Tegra::GPUVAddr, T> cached_objects; |
| 115 | PageMap cached_pages; | ||
| 116 | }; | 78 | }; |