Only rehash textures after 1ms has passed since the last hash

This massively improves the framerate in many titles, for example the
title screen on Turok sees a jump from ~2fps to 160fps with this alone.

I understand this isn't the best solution, but it is the best tradeoff
so far between not hashing resources at all (texture updates by xbox won't
propegate to host textures) or hashing every usage (extremely slow).

A better method would be dirty pages/memory watches, but it's not easily
possible with the current Cxbx-Reloaded design.
This commit is contained in:
Luke Usher 2018-02-01 21:28:37 +00:00
parent 06516410a6
commit 9ebee168a9
1 changed files with 8417 additions and 8407 deletions

View File

@ -742,6 +742,7 @@ typedef struct {
void* pXboxData = nullptr;
size_t szXboxDataSize = 0;
uint32_t hash = 0;
std::chrono::time_point<std::chrono::high_resolution_clock> lastHashedTime;
} host_resource_info_t;
std::map <resource_key_t, host_resource_info_t> g_HostResources;
@ -818,12 +819,20 @@ bool HostResourceRequiresUpdate(resource_key_t key)
return false;
}
// Rehash the resource after a certain amount of milliseconds has passed
// We do this because hashing every single use is too expensive
// Note: This will have to do until we get proper dirty page support
// Even with a 1ms hash lifetime, Turok goes from 2fps to 160fps on the title screen
auto now = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(it->second.lastHashedTime - now).count();
if (duration > 1) {
uint32_t oldHash = it->second.hash;
it->second.hash = XXHash32::hash(it->second.pXboxData, it->second.szXboxDataSize, 0);
if (it->second.hash != oldHash) {
return true;
}
}
return false;
}
@ -842,6 +851,7 @@ void SetHostResource(XTL::X_D3DResource* pXboxResource, XTL::IDirect3DResource8*
hostResourceInfo.pXboxData = GetDataFromXboxResource(pXboxResource);
hostResourceInfo.szXboxDataSize = GetXboxResourceSize(pXboxResource);
hostResourceInfo.hash = XXHash32::hash(hostResourceInfo.pXboxData, hostResourceInfo.szXboxDataSize, 0);
hostResourceInfo.lastHashedTime = std::chrono::high_resolution_clock::now();
g_HostResources[key] = hostResourceInfo;