ShaderCompiler: Optimize compilation error printing

This commit is contained in:
Luo Zhihao 2025-09-04 16:50:40 +08:00
parent 6c9aa4c7d3
commit 5f737952fd
No known key found for this signature in database
GPG key ID: E10A25B618BD1E9B

View file

@ -1520,6 +1520,17 @@ Error ShaderCompiler::compile(RS::ShaderMode p_mode, const String &p_code, Ident
// Print the files.
for (const KeyValue<String, Vector<String>> &E : includes) {
int err_line = -1;
for (const ShaderLanguage::FilePosition &include_position : include_positions) {
if (include_position.file == E.key) {
err_line = include_position.line;
}
}
if (err_line < 0) {
// Skip files that don't contain errors.
continue;
}
if (E.key.is_empty()) {
if (p_path == "") {
print_line("--Main Shader--");
@ -1529,19 +1540,14 @@ Error ShaderCompiler::compile(RS::ShaderMode p_mode, const String &p_code, Ident
} else {
print_line("--" + E.key + "--");
}
int err_line = -1;
for (int i = 0; i < include_positions.size(); i++) {
if (include_positions[i].file == E.key) {
err_line = include_positions[i].line;
}
}
const Vector<String> &V = E.value;
for (int i = 0; i < V.size(); i++) {
if (i == err_line - 1) {
// Mark the error line to be visible without having to look at
// the trace at the end.
print_line(vformat("E%4d-> %s", i + 1, V[i]));
} else {
} else if ((i == err_line - 3) || (i == err_line - 2) || (i == err_line) || (i == err_line + 1)) {
// Print 4 lines around the error line.
print_line(vformat("%5d | %s", i + 1, V[i]));
}
}