replay.rs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //! `victory replay`: a captured frame run again (docs/replay.md).
  2. use std::path::PathBuf;
  3. use anyhow::{Context, Result};
  4. use clap::{Args, ValueEnum};
  5. use victory_hle::replay::play::{self, Options};
  6. #[derive(Clone, Copy, ValueEnum)]
  7. enum Timing {
  8. /// Each list.
  9. Lists,
  10. /// Each command (adds some time of its own).
  11. Detailed,
  12. }
  13. #[derive(Clone, Copy, ValueEnum)]
  14. enum Buffers {
  15. AsRecorded,
  16. /// All in the card's memory.
  17. Vram,
  18. /// All in the PC's memory.
  19. Sysmem,
  20. }
  21. #[derive(Args)]
  22. pub(crate) struct Replay {
  23. /// The folder given as VICTORY_RECORD (its last capture) or a capture.
  24. folder: PathBuf,
  25. /// How often the frame is run.
  26. #[arg(long, default_value_t = 5)]
  27. loops: u32,
  28. /// Do not put back, between runs, what a run changed.
  29. #[arg(long)]
  30. no_restore: bool,
  31. #[arg(long, value_enum, default_value_t = Timing::Lists)]
  32. timing: Timing,
  33. /// Pipelines listed with detailed timing.
  34. #[arg(long, default_value_t = 20)]
  35. top: usize,
  36. /// Where the picture goes (default: replay.png in the capture).
  37. #[arg(long)]
  38. image: Option<PathBuf>,
  39. /// Run the frame unchanged first, and print both.
  40. #[arg(long)]
  41. compare: bool,
  42. /// Leave out unordered-access barriers.
  43. #[arg(long)]
  44. no_barriers: bool,
  45. /// Join barrier calls with no work between them.
  46. #[arg(long)]
  47. merge_barriers: bool,
  48. /// Leave out the argument clamps: what they bound is kept from a first run.
  49. #[arg(long)]
  50. skip_clamps: bool,
  51. /// Leave out the hash and compare passes over card buffers.
  52. #[arg(long)]
  53. skip_hash_passes: bool,
  54. /// Where buffers lie.
  55. #[arg(long, value_enum, default_value_t = Buffers::AsRecorded)]
  56. buffers: Buffers,
  57. /// One ExecuteCommandLists for the whole frame.
  58. #[arg(long)]
  59. one_submit: bool,
  60. /// Run only these lists, by their place in the frame (`3..7`, or `5`);
  61. /// of the others only barriers.
  62. #[arg(long)]
  63. only: Option<String>,
  64. /// Leave out what runs a pipeline whose name or DXIL hash has this in it
  65. /// (may be given several times).
  66. #[arg(long = "skip-shader")]
  67. skip_shader: Vec<String>,
  68. /// Use the D3D12 debug layer (slow).
  69. #[arg(long)]
  70. debug_layer: bool,
  71. }
  72. /// `3..7` (both included) or `5`.
  73. fn range(text: &str) -> Option<(u32, u32)> {
  74. match text.split_once("..") {
  75. Some((a, b)) => Some((a.trim().parse().ok()?, b.trim().parse().ok()?)),
  76. None => text.trim().parse().ok().map(|n| (n, n)),
  77. }
  78. }
  79. pub(crate) fn run(r: Replay) -> Result<()> {
  80. let only = match &r.only {
  81. Some(text) => Some(range(text).with_context(|| format!("--only {text}: not a list or a range of lists (3..7)"))?),
  82. None => None,
  83. };
  84. let options = Options {
  85. loops: r.loops.max(1),
  86. restore: !r.no_restore,
  87. detailed: matches!(r.timing, Timing::Detailed),
  88. top: r.top,
  89. image: r.image,
  90. buffers: match r.buffers {
  91. Buffers::AsRecorded => play::Buffers::AsRecorded,
  92. Buffers::Vram => play::Buffers::Card,
  93. Buffers::Sysmem => play::Buffers::Pc,
  94. },
  95. no_barriers: r.no_barriers,
  96. merge_barriers: r.merge_barriers,
  97. skip_clamps: r.skip_clamps,
  98. skip_hash_passes: r.skip_hash_passes,
  99. one_submit: r.one_submit,
  100. only,
  101. skip_shaders: r.skip_shader,
  102. compare: r.compare,
  103. debug: r.debug_layer,
  104. };
  105. let reports = play::replay(&r.folder, &options)?;
  106. for (what, report) in &reports {
  107. println!("{}", report.text(what));
  108. }
  109. if let [(_, before), (_, after)] = &reports[..] {
  110. println!("{:+.2} ms", after.median_ms() - before.median_ms());
  111. }
  112. Ok(())
  113. }
  114. #[cfg(test)]
  115. mod tests {
  116. #[test]
  117. fn ranges() {
  118. assert_eq!(super::range("3..7"), Some((3, 7)));
  119. assert_eq!(super::range("5"), Some((5, 5)));
  120. assert_eq!(super::range("x"), None);
  121. assert_eq!(super::range("1..x"), None);
  122. }
  123. }