Skip to content

Commit daa1fc9

Browse files
committed
Merge pull request #107547 from beicause/shader-compiler-print-content-verbose
ShaderCompiler: Optimize compilation error printing
2 parents 7e5c689 + 5f73795 commit daa1fc9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

servers/rendering/shader_compiler.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,17 @@ Error ShaderCompiler::compile(RS::ShaderMode p_mode, const String &p_code, Ident
15201520

15211521
// Print the files.
15221522
for (const KeyValue<String, Vector<String>> &E : includes) {
1523+
int err_line = -1;
1524+
for (const ShaderLanguage::FilePosition &include_position : include_positions) {
1525+
if (include_position.file == E.key) {
1526+
err_line = include_position.line;
1527+
}
1528+
}
1529+
if (err_line < 0) {
1530+
// Skip files that don't contain errors.
1531+
continue;
1532+
}
1533+
15231534
if (E.key.is_empty()) {
15241535
if (p_path == "") {
15251536
print_line("--Main Shader--");
@@ -1529,19 +1540,14 @@ Error ShaderCompiler::compile(RS::ShaderMode p_mode, const String &p_code, Ident
15291540
} else {
15301541
print_line("--" + E.key + "--");
15311542
}
1532-
int err_line = -1;
1533-
for (int i = 0; i < include_positions.size(); i++) {
1534-
if (include_positions[i].file == E.key) {
1535-
err_line = include_positions[i].line;
1536-
}
1537-
}
15381543
const Vector<String> &V = E.value;
15391544
for (int i = 0; i < V.size(); i++) {
15401545
if (i == err_line - 1) {
15411546
// Mark the error line to be visible without having to look at
15421547
// the trace at the end.
15431548
print_line(vformat("E%4d-> %s", i + 1, V[i]));
1544-
} else {
1549+
} else if ((i == err_line - 3) || (i == err_line - 2) || (i == err_line) || (i == err_line + 1)) {
1550+
// Print 4 lines around the error line.
15451551
print_line(vformat("%5d | %s", i + 1, V[i]));
15461552
}
15471553
}

0 commit comments

Comments
 (0)