shader: avoid recomputing hash for the same program
This commit is contained in:
parent
3cc460ab34
commit
d52ddd0ec4
3 changed files with 39 additions and 3 deletions
|
@ -12,6 +12,7 @@
|
|||
#include "common/assert.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/hash.h"
|
||||
#include "common/vector_math.h"
|
||||
#include "video_core/pica_types.h"
|
||||
#include "video_core/regs_rasterizer.h"
|
||||
|
@ -206,6 +207,36 @@ struct ShaderSetup {
|
|||
/// Used by the JIT, points to a compiled shader object.
|
||||
const void* cached_shader = nullptr;
|
||||
} engine_data;
|
||||
|
||||
void MarkProgramCodeDirty() {
|
||||
program_code_hash_dirty = true;
|
||||
}
|
||||
|
||||
void MarkSwizzleDataDirty() {
|
||||
swizzle_data_hash_dirty = true;
|
||||
}
|
||||
|
||||
u64 GetProgramCodeHash() {
|
||||
if (program_code_hash_dirty) {
|
||||
program_code_hash = Common::ComputeHash64(&program_code, sizeof(program_code));
|
||||
program_code_hash_dirty = false;
|
||||
}
|
||||
return program_code_hash;
|
||||
}
|
||||
|
||||
u64 GetSwizzleDataHash() {
|
||||
if (swizzle_data_hash_dirty) {
|
||||
swizzle_data_hash = Common::ComputeHash64(&swizzle_data, sizeof(swizzle_data));
|
||||
swizzle_data_hash_dirty = false;
|
||||
}
|
||||
return swizzle_data_hash;
|
||||
}
|
||||
|
||||
private:
|
||||
bool program_code_hash_dirty = true;
|
||||
bool swizzle_data_hash_dirty = true;
|
||||
u64 program_code_hash = 0xDEADC0DE;
|
||||
u64 swizzle_data_hash = 0xDEADC0DE;
|
||||
};
|
||||
|
||||
class ShaderEngine {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "common/hash.h"
|
||||
#include "common/microprofile.h"
|
||||
#include "video_core/shader/shader.h"
|
||||
#include "video_core/shader/shader_jit_x64.h"
|
||||
|
@ -18,8 +17,8 @@ void JitX64Engine::SetupBatch(ShaderSetup& setup, unsigned int entry_point) {
|
|||
ASSERT(entry_point < MAX_PROGRAM_CODE_LENGTH);
|
||||
setup.engine_data.entry_point = entry_point;
|
||||
|
||||
u64 code_hash = Common::ComputeHash64(&setup.program_code, sizeof(setup.program_code));
|
||||
u64 swizzle_hash = Common::ComputeHash64(&setup.swizzle_data, sizeof(setup.swizzle_data));
|
||||
u64 code_hash = setup.GetProgramCodeHash();
|
||||
u64 swizzle_hash = setup.GetSwizzleDataHash();
|
||||
|
||||
u64 cache_key = code_hash ^ swizzle_hash;
|
||||
auto iter = cache.find(cache_key);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue