texture_cache: scan only the first page in FindImageFromRange (#5240)

* texture_cache: scan only the first page in FindImageFromRange

FindImageFromRange only accepts images whose guest address equals the
requested address, and every image is registered in all of its pages, so
the candidates are always found in the first page. Walking every page and
image of a large texel buffer range cost ~35-45 us per call and showed up as
the top per-draw cost in inFamous Second Son.

Also skip the lock in RegionManager::ForEachModifiedRange when no bit of
the requested type is set; the caller would be a no-op in that case.

inFamous Second Son (Salmon Bay dock): 23.2 -> 30.7 FPS.

* texture_cache: add ForEachImageWithAddress, drop region_manager change

Look up only the bucket of the first page and only images with the exact
address, as suggested in review. The lockless early out in
ForEachModifiedRange is removed since ChangeRegionState updates the state
bits before the tracker.

* texture_cache: drop redundant address check and comment

Image addresses are 256-byte aligned, so a matching key already implies the
same address.
This commit is contained in:
Lucas Daniel Duarte Cabral authored and GitHub committed 2026-10-04 02:21:45 +03:00
1 parent 43e4c4703e
commit 145932bf59
2 files changed
+15 -4

No files matched your search

@@ -595,10 +595,7 @@ ImageId TextureCache::FindImage(ImageDesc& desc, bool exact_fmt) {
ImageId TextureCache::FindImageFromRange(VAddr address, size_t size, bool ensure_valid) {
SmallVector<ImageId, 4> image_ids;
ForEachImageInRegion(address, size, [&](ImageId image_id, Image& image) {
if (image.info.guest_address != address) {
return;
}
ForEachImageWithAddress(address, [&](ImageId image_id, Image& image) {
if (ensure_valid && !image.SafeToDownload()) {
return;
}
@@ -277,6 +277,20 @@ public:
});
}
template <typename Func>
void ForEachImageWithAddress(VAddr cpu_addr, Func&& func) {
const auto it = page_table.find(cpu_addr >> Traits::PAGE_BITS);
if (it == nullptr) {
return;
}
const u32 key = u32(cpu_addr >> 8);
for (const auto& entry : it->entries) {
if (entry.key == key) {
func(entry.id, slot_images[entry.id]);
}
}
}
private:
/// Iterate over all page indices in a range
template <typename Func>