parseShaderCompileErrors function Debugging and profiling

List<ShaderCompileDiagnostic> parseShaderCompileErrors(
  1. String log
)

Parses the diagnostics a shader compiler wrote to log. Lines that match no known format are dropped, so a log with only prose yields nothing.

Implementation

List<ShaderCompileDiagnostic> parseShaderCompileErrors(String log) {
  final result = <ShaderCompileDiagnostic>[];
  for (final match in _glslangLine.allMatches(log)) {
    final file = match.group(2)!.trim();
    result.add(
      ShaderCompileDiagnostic(
        message: match.group(4)!.trim(),
        line: int.tryParse(match.group(3)!),
        // glslang names the source string index when it has no file.
        file: file.isEmpty || int.tryParse(file) != null ? null : file,
        isError: match.group(1) == 'ERROR',
      ),
    );
  }
  for (final match in _clangLine.allMatches(log)) {
    result.add(
      ShaderCompileDiagnostic(
        message: match.group(4)!.trim(),
        line: int.tryParse(match.group(2)!),
        file: match.group(1),
        isError: match.group(3) == 'error',
      ),
    );
  }
  return result;
}