[GPU] TextureCache lockless pre-check

lockless accessors for base_outdated/mips_outdated and skip lock
acquisition when textures appear up to date
This commit is contained in:
Herman S.
2025-12-31 14:08:01 +09:00
parent 067641668f
commit 77852914ff
2 changed files with 27 additions and 0 deletions

View File

@@ -693,6 +693,21 @@ void TextureCache::LoadTexturesData(Texture** textures, uint32_t n_textures) {
}
}
// Lockless pre-check: count how many textures appear outdated.
// If none appear outdated, skip the lock entirely.
uint32_t likely_outdated = 0;
for (uint32_t i = 0; i < n_textures; ++i) {
Texture* current = textures[i];
if (current->base_outdated_lockless() ||
current->mips_outdated_lockless()) {
++likely_outdated;
}
}
if (likely_outdated == 0) {
// All textures appear up-to-date, skip lock acquisition
return;
}
uint64_t index_base_outdated = 0;
uint64_t index_mips_outdated = 0;
uint32_t nkept = 0;
@@ -811,6 +826,13 @@ void TextureCache::LoadTexturesData(Texture** textures, uint32_t n_textures) {
}
}
bool TextureCache::LoadTextureData(Texture& texture) {
// Lockless pre-check: if texture appears up-to-date, skip the lock.
// This is safe because worst case is a false positive (we acquire lock
// unnecessarily), never a false negative.
if (!texture.base_outdated_lockless() && !texture.mips_outdated_lockless()) {
return true;
}
// Check what needs to be uploaded.
bool base_outdated, mips_outdated;
{