mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 20:49:12 +12:00
[Shader JIT] Add caching
This commit is contained in:
parent
364443d66f
commit
4064abfdeb
9 changed files with 77 additions and 5 deletions
|
@ -1,7 +1,14 @@
|
|||
#include "PICA/dynapica/shader_rec.hpp"
|
||||
#include "cityhash.hpp"
|
||||
|
||||
#ifdef PANDA3DS_SHADER_JIT_SUPPORTED
|
||||
void ShaderJIT::reset() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
void ShaderJIT::prepare(PICAShader& shaderUnit) {
|
||||
printf("HAPPY HAPPY HAPPY\n");
|
||||
// We construct a shader hash from both the code and operand descriptor hashes
|
||||
// This is so that if only one of them changes, we still properly recompile the shader
|
||||
Hash hash = shaderUnit.getCodeHash() ^ shaderUnit.getOpdescHash();
|
||||
}
|
||||
#endif // PANDA3DS_SHADER_JIT_SUPPORTED
|
|
@ -12,6 +12,7 @@ GPU::GPU(Memory& mem) : mem(mem), renderer(*this, regs) {
|
|||
void GPU::reset() {
|
||||
regs.fill(0);
|
||||
shaderUnit.reset();
|
||||
shaderJIT.reset();
|
||||
std::memset(vram, 0, vramSize);
|
||||
|
||||
totalAttribCount = 0;
|
||||
|
@ -84,6 +85,10 @@ void GPU::drawArrays() {
|
|||
log("PICA::DrawElements(vertex count = %d, index buffer config = %08X)\n", vertexCount, indexBufferConfig);
|
||||
}
|
||||
|
||||
if constexpr (useShaderJIT) {
|
||||
shaderJIT.prepare(shaderUnit.vs);
|
||||
}
|
||||
|
||||
// Total number of input attributes to shader. Differs between GS and VS. Currently stubbed to the VS one, as we don't have geometry shaders.
|
||||
const u32 inputAttrCount = (regs[PICAInternalRegs::VertexShaderInputBufferCfg] & 0xf) + 1;
|
||||
const u64 inputAttrCfg = getVertexShaderInputConfig();
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue