Shader decompiler: Add support for compilation errors

This commit is contained in:
wheremyfoodat 2024-08-25 19:34:56 +03:00
parent 37a43e245f
commit ca2d7e40ea
2 changed files with 14 additions and 1 deletions

View file

@ -99,6 +99,7 @@ namespace PICA::ShaderGen {
API api;
Language language;
bool compilationError = false;
void compileInstruction(u32& pc, bool& finished);
// Compile range "range" and returns the end PC or if we're "finished" with the program (called an END instruction)

View file

@ -247,6 +247,7 @@ std::string ShaderDecompiler::decompile() {
return "";
}
compilationError = false;
decompiledShader = "";
switch (api) {
@ -324,6 +325,13 @@ std::string ShaderDecompiler::decompile() {
}
}
// We allow some leeway for "compilation errors" in addition to control flow errors, in cases where eg an unimplemented instruction
// or an instruction that we can't emulate in GLSL is found in the instruction stream. Just like control flow errors, these return an empty string
// and the renderer core will decide to use CPU shaders instead
if (compilationError) [[unlikely]] {
return "";
}
return decompiledShader;
}
@ -707,7 +715,11 @@ void ShaderDecompiler::compileInstruction(u32& pc, bool& finished) {
return;
case ShaderOpcodes::NOP: break;
default: Helpers::panic("GLSL recompiler: Unknown opcode: %X", opcode); break;
default:
Helpers::warn("GLSL recompiler: Unknown opcode: %X. Falling back to CPU shaders", opcode);
compilationError = true;
break;
}
}