[Shader JIT] Add caching

This commit is contained in:
wheremyfoodat 2023-06-07 20:33:37 +03:00
parent 364443d66f
commit 4064abfdeb
9 changed files with 77 additions and 5 deletions

View file

@ -1,4 +1,5 @@
#include "PICA/shader_unit.hpp"
#include "cityhash.hpp"
void ShaderUnit::reset() {
vs.reset();
@ -30,4 +31,29 @@ void PICAShader::reset() {
addrRegister.x() = 0;
addrRegister.y() = 0;
loopCounter = 0;
codeHashDirty = true;
opdescHashDirty = true;
}
PICAShader::Hash PICAShader::getCodeHash() {
// Hash the code again if the code changed
if (codeHashDirty) {
codeHashDirty = false;
lastCodeHash = CityHash::CityHash64((const char*)&loadedShader[0], loadedShader.size() * sizeof(loadedShader[0]));
}
// Return the code hash
return lastCodeHash;
}
PICAShader::Hash PICAShader::getOpdescHash() {
// Hash the code again if the operand descriptors changed
if (opdescHashDirty) {
opdescHashDirty = false;
lastOpdescHash = CityHash::CityHash64((const char*)&operandDescriptors[0], operandDescriptors.size() * sizeof(operandDescriptors[0]));
}
// Return the code hash
return lastOpdescHash;
}