|
| 1 | +//! Command-recording strategy override for render-graph diagnostics. |
| 2 | +
|
| 3 | +use crate::labeled_enum; |
| 4 | + |
| 5 | +labeled_enum! { |
| 6 | + /// Render-graph command-recording mode used for profiling and diagnostics. |
| 7 | + pub enum CommandRecordingMode: "command recording mode" { |
| 8 | + default => Auto; |
| 9 | + |
| 10 | + /// Use the renderer's conservative automatic command-recording policy. |
| 11 | + Auto => { |
| 12 | + persist: "auto", |
| 13 | + label: "Auto", |
| 14 | + }, |
| 15 | + /// Record graph commands serially, preferring the coarsest encoder path. |
| 16 | + Serial => { |
| 17 | + persist: "serial", |
| 18 | + label: "Serial", |
| 19 | + }, |
| 20 | + /// Record independent views across Rayon workers when there is enough draw work. |
| 21 | + AcrossViews => { |
| 22 | + persist: "across_views", |
| 23 | + label: "Across views", |
| 24 | + aliases: ["per_view", "per_view_parallel"], |
| 25 | + }, |
| 26 | + /// Record scheduler-admitted pass units inside one view across Rayon workers. |
| 27 | + InView => { |
| 28 | + persist: "in_view", |
| 29 | + label: "In-view", |
| 30 | + aliases: ["in_view_parallel"], |
| 31 | + }, |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +impl CommandRecordingMode { |
| 36 | + /// Numeric value used by Tracy plots and compact diagnostics. |
| 37 | + pub const fn as_plot_value(self) -> u64 { |
| 38 | + match self { |
| 39 | + Self::Auto => 0, |
| 40 | + Self::Serial => 1, |
| 41 | + Self::AcrossViews => 2, |
| 42 | + Self::InView => 3, |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +#[cfg(test)] |
| 48 | +mod tests { |
| 49 | + use super::CommandRecordingMode; |
| 50 | + |
| 51 | + #[test] |
| 52 | + fn command_recording_mode_parses_aliases() { |
| 53 | + assert_eq!( |
| 54 | + CommandRecordingMode::parse_persist("auto"), |
| 55 | + Some(CommandRecordingMode::Auto) |
| 56 | + ); |
| 57 | + assert_eq!( |
| 58 | + CommandRecordingMode::parse_persist("per_view_parallel"), |
| 59 | + Some(CommandRecordingMode::AcrossViews) |
| 60 | + ); |
| 61 | + assert_eq!( |
| 62 | + CommandRecordingMode::parse_persist("in_view_parallel"), |
| 63 | + Some(CommandRecordingMode::InView) |
| 64 | + ); |
| 65 | + assert_eq!(CommandRecordingMode::parse_persist(""), None); |
| 66 | + } |
| 67 | +} |
0 commit comments