mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
[PICA] Switch to xxh3 by default
This commit is contained in:
parent
f82b27ddba
commit
f0f7327b90
4 changed files with 60 additions and 23 deletions
|
@ -0,0 +1,16 @@
|
||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
// Defines to pick which hash algorithm to use for the PICA (For hashing shaders, etc)
|
||||||
|
// Please only define one of them
|
||||||
|
//#define PANDA3DS_PICA_CITYHASH
|
||||||
|
#define PANDA3DS_PICA_XXHASH3
|
||||||
|
|
||||||
|
namespace PICAHash {
|
||||||
|
#if defined(PANDA3DS_PICA_CITYHASH) || defined(PANDA3DS_PICA_XXHASH3)
|
||||||
|
using HashType = std::uint64_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
HashType computeHash(const char* buf, std::size_t len);
|
||||||
|
} // namespace PICAHash
|
|
@ -5,6 +5,7 @@
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
#include "opengl.hpp"
|
#include "opengl.hpp"
|
||||||
#include "PICA/float_types.hpp"
|
#include "PICA/float_types.hpp"
|
||||||
|
#include "PICA/pica_hash.hpp"
|
||||||
|
|
||||||
enum class ShaderType {
|
enum class ShaderType {
|
||||||
Vertex, Geometry
|
Vertex, Geometry
|
||||||
|
@ -105,7 +106,7 @@ protected:
|
||||||
// We use a hashmap for matching 3DS shaders to their equivalent compiled code in our shader cache in the shader JIT
|
// We use a hashmap for matching 3DS shaders to their equivalent compiled code in our shader cache in the shader JIT
|
||||||
// We choose our hash type to be a 64-bit integer by default, as the collision chance is very tiny and generating it is decently optimal
|
// We choose our hash type to be a 64-bit integer by default, as the collision chance is very tiny and generating it is decently optimal
|
||||||
// Ideally we want to be able to support multiple different types of hash depending on compilation settings, but let's get this working first
|
// Ideally we want to be able to support multiple different types of hash depending on compilation settings, but let's get this working first
|
||||||
using Hash = u64;
|
using Hash = PICAHash::HashType;
|
||||||
|
|
||||||
Hash lastCodeHash = 0; // Last hash computed for the shader code (Used for the JIT caching mechanism)
|
Hash lastCodeHash = 0; // Last hash computed for the shader code (Used for the JIT caching mechanism)
|
||||||
Hash lastOpdescHash = 0; // Last hash computed for the operand descriptors (Also used for the JIT)
|
Hash lastOpdescHash = 0; // Last hash computed for the operand descriptors (Also used for the JIT)
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include "PICA/pica_hash.hpp"
|
||||||
|
#include "PICA/shader.hpp"
|
||||||
|
|
||||||
|
#ifdef PANDA3DS_PICA_CITYHASH
|
||||||
|
#include "cityhash.hpp"
|
||||||
|
#elif defined(PANDA3DS_PICA_XXHASH3)
|
||||||
|
#include "xxhash/xxhash.h"
|
||||||
|
#else
|
||||||
|
#error No hashing algorithm defined for the PICA (See pica_hash.hpp for details)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PICAHash::HashType PICAHash::computeHash(const char* buf, std::size_t len) {
|
||||||
|
#ifdef PANDA3DS_PICA_CITYHASH
|
||||||
|
return CityHash::CityHash64(buf, len);
|
||||||
|
#elif defined(PANDA3DS_PICA_XXHASH3)
|
||||||
|
return XXH3_64bits(buf, len);
|
||||||
|
#else
|
||||||
|
#error No hashing algorithm defined for PICAHash::computeHash
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
PICAShader::Hash PICAShader::getCodeHash() {
|
||||||
|
// Hash the code again if the code changed
|
||||||
|
if (codeHashDirty) {
|
||||||
|
codeHashDirty = false;
|
||||||
|
lastCodeHash = PICAHash::computeHash((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 = PICAHash::computeHash((const char*)&operandDescriptors[0], operandDescriptors.size() * sizeof(operandDescriptors[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the code hash
|
||||||
|
return lastOpdescHash;
|
||||||
|
}
|
|
@ -34,26 +34,4 @@ void PICAShader::reset() {
|
||||||
|
|
||||||
codeHashDirty = true;
|
codeHashDirty = true;
|
||||||
opdescHashDirty = 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
Reference in a new issue