|
@@ -5,12 +5,13 @@
|
|
|
#pragma once
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
#include <unordered_map>
|
|
|
-#include <boost/icl/interval_map.hpp>
|
|
|
|
|
-#include <boost/range/iterator_range.hpp>
|
|
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
#include "common/common_types.h"
|
|
|
|
|
+#include "core/core.h"
|
|
|
#include "core/memory.h"
|
|
#include "core/memory.h"
|
|
|
#include "video_core/memory_manager.h"
|
|
#include "video_core/memory_manager.h"
|
|
|
|
|
+#include "video_core/rasterizer_interface.h"
|
|
|
|
|
+#include "video_core/renderer_base.h"
|
|
|
|
|
|
|
|
template <class T>
|
|
template <class T>
|
|
|
class RasterizerCache : NonCopyable {
|
|
class RasterizerCache : NonCopyable {
|
|
@@ -54,8 +55,9 @@ protected:
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- cached_objects[object->GetAddr()] = object;
|
|
|
|
|
- UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), 1);
|
|
|
|
|
|
|
+ auto& rasterizer = Core::System::GetInstance().Renderer().Rasterizer();
|
|
|
|
|
+ rasterizer.UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), 1);
|
|
|
|
|
+ cached_objects[object->GetAddr()] = std::move(object);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Unregisters an object from the cache
|
|
/// Unregisters an object from the cache
|
|
@@ -66,51 +68,11 @@ protected:
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), -1);
|
|
|
|
|
|
|
+ auto& rasterizer = Core::System::GetInstance().Renderer().Rasterizer();
|
|
|
|
|
+ rasterizer.UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), -1);
|
|
|
cached_objects.erase(search);
|
|
cached_objects.erase(search);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
private:
|
|
|
- using PageMap = boost::icl::interval_map<u64, int>;
|
|
|
|
|
-
|
|
|
|
|
- template <typename Map, typename Interval>
|
|
|
|
|
- constexpr auto RangeFromInterval(Map& map, const Interval& interval) {
|
|
|
|
|
- return boost::make_iterator_range(map.equal_range(interval));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /// Increase/decrease the number of object in pages touching the specified region
|
|
|
|
|
- void UpdatePagesCachedCount(Tegra::GPUVAddr addr, u64 size, int delta) {
|
|
|
|
|
- const u64 page_start{addr >> Tegra::MemoryManager::PAGE_BITS};
|
|
|
|
|
- const u64 page_end{(addr + size) >> Tegra::MemoryManager::PAGE_BITS};
|
|
|
|
|
-
|
|
|
|
|
- // Interval maps will erase segments if count reaches 0, so if delta is negative we have to
|
|
|
|
|
- // subtract after iterating
|
|
|
|
|
- const auto pages_interval = PageMap::interval_type::right_open(page_start, page_end);
|
|
|
|
|
- if (delta > 0)
|
|
|
|
|
- cached_pages.add({pages_interval, delta});
|
|
|
|
|
-
|
|
|
|
|
- for (const auto& pair : RangeFromInterval(cached_pages, pages_interval)) {
|
|
|
|
|
- const auto interval = pair.first & pages_interval;
|
|
|
|
|
- const int count = pair.second;
|
|
|
|
|
-
|
|
|
|
|
- const Tegra::GPUVAddr interval_start_addr = boost::icl::first(interval)
|
|
|
|
|
- << Tegra::MemoryManager::PAGE_BITS;
|
|
|
|
|
- const Tegra::GPUVAddr interval_end_addr = boost::icl::last_next(interval)
|
|
|
|
|
- << Tegra::MemoryManager::PAGE_BITS;
|
|
|
|
|
- const u64 interval_size = interval_end_addr - interval_start_addr;
|
|
|
|
|
-
|
|
|
|
|
- if (delta > 0 && count == delta)
|
|
|
|
|
- Memory::RasterizerMarkRegionCached(interval_start_addr, interval_size, true);
|
|
|
|
|
- else if (delta < 0 && count == -delta)
|
|
|
|
|
- Memory::RasterizerMarkRegionCached(interval_start_addr, interval_size, false);
|
|
|
|
|
- else
|
|
|
|
|
- ASSERT(count >= 0);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (delta < 0)
|
|
|
|
|
- cached_pages.add({pages_interval, delta});
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
std::unordered_map<Tegra::GPUVAddr, T> cached_objects;
|
|
std::unordered_map<Tegra::GPUVAddr, T> cached_objects;
|
|
|
- PageMap cached_pages;
|
|
|
|
|
};
|
|
};
|