Optimize shader state changes: avoid redundant SetupBatch calls by tracking VS config hash

This commit is contained in:
jbm11208 2025-05-12 00:41:05 -04:00 committed by OpenSauce
parent ed94588449
commit fa1389915f
2 changed files with 14 additions and 2 deletions

View File

@ -487,8 +487,12 @@ void PicaCore::SubmitImmediate(u32 value) {
}
void PicaCore::DrawImmediate() {
// Compile the vertex shader.
shader_engine->SetupBatch(vs_setup, regs.internal.vs.main_offset);
// Compute current VS config hash
u64 vs_hash = vs_setup.GetProgramCodeHash() ^ vs_setup.GetSwizzleDataHash();
if (vs_hash != last_vs_hash) {
shader_engine->SetupBatch(vs_setup, regs.internal.vs.main_offset);
last_vs_hash = vs_hash;
}
// Track vertex in the debug recorder.
if (debug_context) {
@ -590,6 +594,13 @@ void PicaCore::LoadVertices(bool is_indexed) {
std::array<AttributeBuffer, VERTEX_CACHE_SIZE> vertex_cache;
u32 vertex_cache_pos = 0;
// Compute current VS config hash
u64 vs_hash = vs_setup.GetProgramCodeHash() ^ vs_setup.GetSwizzleDataHash();
if (vs_hash != last_vs_hash) {
shader_engine->SetupBatch(vs_setup, regs.internal.vs.main_offset);
last_vs_hash = vs_hash;
}
// Compile the vertex shader for this batch.
ShaderUnit shader_unit;
AttributeBuffer vs_output;

View File

@ -306,6 +306,7 @@ private:
PrimitiveAssembler primitive_assembler;
CommandList cmd_list;
std::unique_ptr<ShaderEngine> shader_engine;
u64 last_vs_hash = 0xDEADBEEFDEADBEEF; // Track last used VS hash
};
#define GPU_REG_INDEX(field_name) (offsetof(Pica::PicaCore::Regs, field_name) / sizeof(u32))