Skip to main content

vyre_debug/
naga_trace.rs

1use naga::Module;
2use std::fs::File;
3use std::io::{BufRead, BufReader};
4use vyre_emit_naga::BindResultEntry;
5
6pub struct FailureTrace {
7    pub text: String,
8}
9
10pub fn failure_trace(module: &Module, error: &naga::valid::ValidationError) -> FailureTrace {
11    let text = format!(
12        "FAILURE: {:#?}\nentry_points={}\nfunctions={}\nglobals={}",
13        error,
14        module.entry_points.len(),
15        module.functions.len(),
16        module.global_variables.len()
17    );
18    FailureTrace { text }
19}
20
21pub fn failure_trace_wgsl(
22    module: &Module,
23    info: &naga::valid::ModuleInfo,
24    err: &naga::back::wgsl::Error,
25) -> FailureTrace {
26    let text = format!(
27        "FAILURE: {:#?}\nentry_points={}\nfunctions={}\nglobals={}\nmodule_info={:#?}",
28        err,
29        module.entry_points.len(),
30        module.functions.len(),
31        module.global_variables.len(),
32        info
33    );
34    FailureTrace { text }
35}
36
37pub fn load_bind_result_log(path: &str) -> Vec<BindResultEntry> {
38    let mut entries = Vec::new();
39    if let Ok(file) = File::open(path) {
40        let reader = BufReader::new(file);
41        for line in reader.lines().map_while(Result::ok) {
42            if let Ok(entry) = serde_json::from_str(&line) {
43                entries.push(entry);
44            }
45        }
46    }
47    entries
48}