|
|
@ -677,12 +677,6 @@ RasterizerCacheOpenGL::RasterizerCacheOpenGL() {
|
|
|
|
draw_framebuffer.Create();
|
|
|
|
draw_framebuffer.Create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RasterizerCacheOpenGL::~RasterizerCacheOpenGL() {
|
|
|
|
|
|
|
|
while (!surface_cache.empty()) {
|
|
|
|
|
|
|
|
UnregisterSurface(surface_cache.begin()->second);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Surface RasterizerCacheOpenGL::GetTextureSurface(const Tegra::Texture::FullTextureInfo& config) {
|
|
|
|
Surface RasterizerCacheOpenGL::GetTextureSurface(const Tegra::Texture::FullTextureInfo& config) {
|
|
|
|
return GetSurface(SurfaceParams::CreateForTexture(config));
|
|
|
|
return GetSurface(SurfaceParams::CreateForTexture(config));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -766,27 +760,25 @@ Surface RasterizerCacheOpenGL::GetSurface(const SurfaceParams& params, bool pres
|
|
|
|
return {};
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
|
|
// Look up surface in the cache based on address
|
|
|
|
// Look up surface in the cache based on address
|
|
|
|
const auto& search{surface_cache.find(params.addr)};
|
|
|
|
Surface surface{TryGet(params.addr)};
|
|
|
|
Surface surface;
|
|
|
|
if (surface) {
|
|
|
|
if (search != surface_cache.end()) {
|
|
|
|
|
|
|
|
surface = search->second;
|
|
|
|
|
|
|
|
if (Settings::values.use_accurate_framebuffers) {
|
|
|
|
if (Settings::values.use_accurate_framebuffers) {
|
|
|
|
// If use_accurate_framebuffers is enabled, always load from memory
|
|
|
|
// If use_accurate_framebuffers is enabled, always load from memory
|
|
|
|
FlushSurface(surface);
|
|
|
|
FlushSurface(surface);
|
|
|
|
UnregisterSurface(surface);
|
|
|
|
Unregister(surface);
|
|
|
|
} else if (surface->GetSurfaceParams().IsCompatibleSurface(params)) {
|
|
|
|
} else if (surface->GetSurfaceParams().IsCompatibleSurface(params)) {
|
|
|
|
// Use the cached surface as-is
|
|
|
|
// Use the cached surface as-is
|
|
|
|
return surface;
|
|
|
|
return surface;
|
|
|
|
} else if (preserve_contents) {
|
|
|
|
} else if (preserve_contents) {
|
|
|
|
// If surface parameters changed and we care about keeping the previous data, recreate
|
|
|
|
// If surface parameters changed and we care about keeping the previous data, recreate
|
|
|
|
// the surface from the old one
|
|
|
|
// the surface from the old one
|
|
|
|
UnregisterSurface(surface);
|
|
|
|
Unregister(surface);
|
|
|
|
Surface new_surface{RecreateSurface(surface, params)};
|
|
|
|
Surface new_surface{RecreateSurface(surface, params)};
|
|
|
|
RegisterSurface(new_surface);
|
|
|
|
Register(new_surface);
|
|
|
|
return new_surface;
|
|
|
|
return new_surface;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Delete the old surface before creating a new one to prevent collisions.
|
|
|
|
// Delete the old surface before creating a new one to prevent collisions.
|
|
|
|
UnregisterSurface(surface);
|
|
|
|
Unregister(surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -797,7 +789,7 @@ Surface RasterizerCacheOpenGL::GetSurface(const SurfaceParams& params, bool pres
|
|
|
|
if (!surface) {
|
|
|
|
if (!surface) {
|
|
|
|
surface = std::make_shared<CachedSurface>(params);
|
|
|
|
surface = std::make_shared<CachedSurface>(params);
|
|
|
|
ReserveSurface(surface);
|
|
|
|
ReserveSurface(surface);
|
|
|
|
RegisterSurface(surface);
|
|
|
|
Register(surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Only load surface from memory if we care about the contents
|
|
|
|
// Only load surface from memory if we care about the contents
|
|
|
@ -894,7 +886,7 @@ Surface RasterizerCacheOpenGL::TryFindFramebufferSurface(VAddr cpu_addr) const {
|
|
|
|
// framebuffer overlaps surfaces.
|
|
|
|
// framebuffer overlaps surfaces.
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Surface> surfaces;
|
|
|
|
std::vector<Surface> surfaces;
|
|
|
|
for (const auto& surface : surface_cache) {
|
|
|
|
for (const auto& surface : GetCache()) {
|
|
|
|
const auto& params = surface.second->GetSurfaceParams();
|
|
|
|
const auto& params = surface.second->GetSurfaceParams();
|
|
|
|
const VAddr surface_cpu_addr = params.GetCpuAddr();
|
|
|
|
const VAddr surface_cpu_addr = params.GetCpuAddr();
|
|
|
|
if (cpu_addr >= surface_cpu_addr && cpu_addr < (surface_cpu_addr + params.size_in_bytes)) {
|
|
|
|
if (cpu_addr >= surface_cpu_addr && cpu_addr < (surface_cpu_addr + params.size_in_bytes)) {
|
|
|
@ -912,51 +904,6 @@ Surface RasterizerCacheOpenGL::TryFindFramebufferSurface(VAddr cpu_addr) const {
|
|
|
|
return surfaces[0];
|
|
|
|
return surfaces[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RasterizerCacheOpenGL::FlushRegion(Tegra::GPUVAddr /*addr*/, size_t /*size*/) {
|
|
|
|
|
|
|
|
// TODO(bunnei): This is unused in the current implementation of the rasterizer cache. We should
|
|
|
|
|
|
|
|
// probably implement this in the future, but for now, the `use_accurate_framebufers` setting
|
|
|
|
|
|
|
|
// can be used to always flush.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RasterizerCacheOpenGL::InvalidateRegion(Tegra::GPUVAddr addr, size_t size) {
|
|
|
|
|
|
|
|
for (auto iter = surface_cache.cbegin(); iter != surface_cache.cend();) {
|
|
|
|
|
|
|
|
const auto& surface{iter->second};
|
|
|
|
|
|
|
|
const auto& params{surface->GetSurfaceParams()};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (params.IsOverlappingRegion(addr, size)) {
|
|
|
|
|
|
|
|
UnregisterSurface(surface);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RasterizerCacheOpenGL::RegisterSurface(const Surface& surface) {
|
|
|
|
|
|
|
|
const auto& params{surface->GetSurfaceParams()};
|
|
|
|
|
|
|
|
const auto& search{surface_cache.find(params.addr)};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (search != surface_cache.end()) {
|
|
|
|
|
|
|
|
// Registered already
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
surface_cache[params.addr] = surface;
|
|
|
|
|
|
|
|
UpdatePagesCachedCount(params.addr, params.size_in_bytes, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RasterizerCacheOpenGL::UnregisterSurface(const Surface& surface) {
|
|
|
|
|
|
|
|
const auto& params{surface->GetSurfaceParams()};
|
|
|
|
|
|
|
|
const auto& search{surface_cache.find(params.addr)};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (search == surface_cache.end()) {
|
|
|
|
|
|
|
|
// Unregistered already
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdatePagesCachedCount(params.addr, params.size_in_bytes, -1);
|
|
|
|
|
|
|
|
surface_cache.erase(search);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RasterizerCacheOpenGL::ReserveSurface(const Surface& surface) {
|
|
|
|
void RasterizerCacheOpenGL::ReserveSurface(const Surface& surface) {
|
|
|
|
const auto& surface_reserve_key{SurfaceReserveKey::Create(surface->GetSurfaceParams())};
|
|
|
|
const auto& surface_reserve_key{SurfaceReserveKey::Create(surface->GetSurfaceParams())};
|
|
|
|
surface_reserve[surface_reserve_key] = surface;
|
|
|
|
surface_reserve[surface_reserve_key] = surface;
|
|
|
@ -966,49 +913,10 @@ Surface RasterizerCacheOpenGL::TryGetReservedSurface(const SurfaceParams& params
|
|
|
|
const auto& surface_reserve_key{SurfaceReserveKey::Create(params)};
|
|
|
|
const auto& surface_reserve_key{SurfaceReserveKey::Create(params)};
|
|
|
|
auto search{surface_reserve.find(surface_reserve_key)};
|
|
|
|
auto search{surface_reserve.find(surface_reserve_key)};
|
|
|
|
if (search != surface_reserve.end()) {
|
|
|
|
if (search != surface_reserve.end()) {
|
|
|
|
RegisterSurface(search->second);
|
|
|
|
Register(search->second);
|
|
|
|
return search->second;
|
|
|
|
return search->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Map, typename Interval>
|
|
|
|
|
|
|
|
constexpr auto RangeFromInterval(Map& map, const Interval& interval) {
|
|
|
|
|
|
|
|
return boost::make_iterator_range(map.equal_range(interval));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RasterizerCacheOpenGL::UpdatePagesCachedCount(Tegra::GPUVAddr addr, u64 size, int delta) {
|
|
|
|
|
|
|
|
const u64 num_pages = ((addr + size - 1) >> Tegra::MemoryManager::PAGE_BITS) -
|
|
|
|
|
|
|
|
(addr >> Tegra::MemoryManager::PAGE_BITS) + 1;
|
|
|
|
|
|
|
|
const u64 page_start = addr >> Tegra::MemoryManager::PAGE_BITS;
|
|
|
|
|
|
|
|
const u64 page_end = page_start + num_pages;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace OpenGL
|
|
|
|
} // namespace OpenGL
|
|
|
|