diff --git a/bin/convert.rs b/bin/convert.rs index 121c2a3717..89ce8759ee 100644 --- a/bin/convert.rs +++ b/bin/convert.rs @@ -249,7 +249,7 @@ fn main() { #[cfg(feature = "dot-out")] "dot" => { use naga::back::dot; - let output = dot::write(&module).unwrap(); + let output = dot::write(&module, analysis.as_ref()).unwrap(); fs::write(output_path, output).unwrap(); } other => { diff --git a/src/back/dot/mod.rs b/src/back/dot/mod.rs index 4016352485..8996058407 100644 --- a/src/back/dot/mod.rs +++ b/src/back/dot/mod.rs @@ -4,7 +4,10 @@ * of IR inspection and debugging. !*/ -use crate::arena::Handle; +use crate::{ + arena::Handle, + proc::analyzer::{Analysis, FunctionInfo}, +}; use std::{ borrow::Cow, @@ -140,7 +143,12 @@ const COLORS: &[&str] = &[ "#d9d9d9", ]; -fn write_fun(output: &mut String, prefix: String, fun: &crate::Function) -> Result<(), FmtError> { +fn write_fun( + output: &mut String, + prefix: String, + fun: &crate::Function, + info: Option<&FunctionInfo>, +) -> Result<(), FmtError> { enum Payload<'a> { Arguments(&'a [Handle]), Local(Handle), @@ -312,11 +320,18 @@ fn write_fun(output: &mut String, prefix: String, fun: &crate::Function) -> Resu (Cow::Borrowed("ArrayLength"), 7) } }; + + // give uniform expressions an outline + let color_attr = match info { + Some(info) if info[handle].uniformity.non_uniform_result.is_none() => "fillcolor", + _ => "color", + }; writeln!( output, - "\t\t{}_e{} [ color=\"{}\" label=\"{:?} {}\" ]", + "\t\t{}_e{} [ {}=\"{}\" label=\"{:?} {}\" ]", prefix, handle.index(), + color_attr, COLORS[color_id], handle, label, @@ -354,7 +369,7 @@ fn write_fun(output: &mut String, prefix: String, fun: &crate::Function) -> Resu Some(Payload::Global(h)) => { writeln!( output, - "\t\tg{} -> {}_e{} [color=gray]", + "\t\tg{} -> {}_e{} [fillcolor=gray]", h.index(), prefix, handle.index(), @@ -414,7 +429,7 @@ fn write_fun(output: &mut String, prefix: String, fun: &crate::Function) -> Resu Ok(()) } -pub fn write(module: &crate::Module) -> Result { +pub fn write(module: &crate::Module, analysis: Option<&Analysis>) -> Result { use std::fmt::Write as _; let mut output = String::new(); @@ -443,14 +458,16 @@ pub fn write(module: &crate::Module) -> Result { handle, name(&fun.name) )?; - write_fun(&mut output, prefix, fun)?; + let info = analysis.map(|a| &a[handle]); + write_fun(&mut output, prefix, fun, info)?; writeln!(output, "\t}}")?; } for (ep_index, ep) in module.entry_points.iter().enumerate() { let prefix = format!("ep{}", ep_index); writeln!(output, "\tsubgraph cluster_{} {{", prefix)?; writeln!(output, "\t\tlabel=\"{:?}/'{}'\"", ep.stage, ep.name)?; - write_fun(&mut output, prefix, &ep.function)?; + let info = analysis.map(|a| a.get_entry_point(ep_index)); + write_fun(&mut output, prefix, &ep.function, info)?; writeln!(output, "\t}}")?; } diff --git a/tests/out/quad.dot.snap b/tests/out/quad.dot.snap index 6a564fad2e..b839e856d6 100644 --- a/tests/out/quad.dot.snap +++ b/tests/out/quad.dot.snap @@ -12,7 +12,7 @@ digraph Module { label="Vertex/'main'" node [ style=filled ] ep0_l0 [ shape=hexagon label="[1] 'out'" ] - ep0_e0 [ color="#ffffb3" label="[1] Constant" ] + ep0_e0 [ fillcolor="#ffffb3" label="[1] Constant" ] ep0_e1 [ color="#8dd3c7" label="[2] Argument[0]" ] ep0_e2 [ color="#8dd3c7" label="[3] Argument[1]" ] ep0_e3 [ color="#8dd3c7" label="[4] Local" ] @@ -24,8 +24,8 @@ digraph Module { ep0_e6 [ color="#fdb462" label="[7] Multiply" ] ep0_e1 -> ep0_e6 [ label="right" ] ep0_e0 -> ep0_e6 [ label="left" ] - ep0_e7 [ color="#ffffb3" label="[8] Constant" ] - ep0_e8 [ color="#ffffb3" label="[9] Constant" ] + ep0_e7 [ fillcolor="#ffffb3" label="[8] Constant" ] + ep0_e8 [ fillcolor="#ffffb3" label="[9] Constant" ] ep0_e9 [ color="#bebada" label="[10] Compose" ] { ep0_e6 ep0_e7 ep0_e8 } -> ep0_e9 ep0_e10 [ color="#fb8072" label="[11] Load" ] @@ -59,11 +59,11 @@ digraph Module { subgraph cluster_ep1 { label="Fragment/'main'" node [ style=filled ] - ep1_e0 [ color="#ffffb3" label="[1] Constant" ] - ep1_e1 [ color="#ffffb3" label="[2] Global" ] - g1 -> ep1_e1 [color=gray] - ep1_e2 [ color="#ffffb3" label="[3] Global" ] - g0 -> ep1_e2 [color=gray] + ep1_e0 [ fillcolor="#ffffb3" label="[1] Constant" ] + ep1_e1 [ fillcolor="#ffffb3" label="[2] Global" ] + g1 -> ep1_e1 [fillcolor=gray] + ep1_e2 [ fillcolor="#ffffb3" label="[3] Global" ] + g0 -> ep1_e2 [fillcolor=gray] ep1_e3 [ color="#8dd3c7" label="[4] Argument[0]" ] ep1_e4 [ color="#80b1d3" label="[5] ImageSample" ] ep1_e1 -> ep1_e4 [ label="sampler" ] @@ -71,7 +71,7 @@ digraph Module { ep1_e3 -> ep1_e4 [ label="coordinate" ] ep1_e5 [ color="#8dd3c7" label="[6] AccessIndex[3]" ] ep1_e4 -> ep1_e5 [ label="base" ] - ep1_e6 [ color="#ffffb3" label="[7] Constant" ] + ep1_e6 [ fillcolor="#ffffb3" label="[7] Constant" ] ep1_e7 [ color="#fdb462" label="[8] Equal" ] ep1_e6 -> ep1_e7 [ label="right" ] ep1_e5 -> ep1_e7 [ label="left" ] diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 8d36b69513..225042ef79 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -106,7 +106,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) { #[cfg(feature = "dot-out")] { if targets.contains(Targets::DOT) { - let string = naga::back::dot::write(module).unwrap(); + let string = naga::back::dot::write(module, Some(&analysis)).unwrap(); with_snapshot_settings(|| { insta::assert_snapshot!(format!("{}.dot", name), string); });