Skip to content

Commit

Permalink
Shader decompiler: Add support for compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat committed Aug 25, 2024
1 parent 37a43e2 commit ca2d7e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/PICA/shader_decompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion src/core/PICA/shader_decompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ std::string ShaderDecompiler::decompile() {
return "";
}

compilationError = false;
decompiledShader = "";

switch (api) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit ca2d7e4

Please sign in to comment.