indirects.rs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //! What the indirect executions of a list ran, for the report of a removed
  2. //! device: with `VICTORY_D3D12_DRED=light` the lists carry no markers, and
  3. //! the two device losses of 2026-11-25 (sessions play-1125-0203 and n02)
  4. //! said only that a list of 814 (954) commands stopped at an indirect
  5. //! execution. The pipeline of each was found hours later by finding the
  6. //! same run of commands in a capture.
  7. //!
  8. //! Per list, in the order recorded: the pipeline (by its host object, whose
  9. //! name is kept once) and the first root constants (user data) it had. The
  10. //! report finds an indirect execution by how many the breadcrumbs' history
  11. //! has before it. Nothing is kept without device-removed data.
  12. //! `VICTORY_D3D12_DRED=faults` and no data at all: nothing is noted.
  13. use std::collections::HashMap;
  14. use std::sync::{Arc, Mutex};
  15. /// Words of user data kept of each execution.
  16. pub(crate) const WORDS: usize = 16;
  17. /// One indirect execution.
  18. #[derive(Clone, Copy)]
  19. pub(crate) struct Ran {
  20. pipeline: usize,
  21. kind: u32,
  22. count: u32,
  23. words: [u32; WORDS],
  24. used: u8,
  25. }
  26. #[derive(Default)]
  27. pub(crate) struct Indirects {
  28. names: HashMap<usize, String>,
  29. ran: Vec<Ran>,
  30. }
  31. /// A list's, shared with the report's table of lists.
  32. pub(crate) type Shared = Arc<Mutex<Indirects>>;
  33. impl Indirects {
  34. /// An indirect execution of `kind` (the argument's type) of at most
  35. /// `count` records with `pipeline` (a host object) and user data.
  36. pub(crate) fn note(&mut self, pipeline: usize, name: &str, kind: u32, count: u32, user: &[u32]) {
  37. self.names.entry(pipeline).or_insert_with(|| name.to_owned());
  38. let used = user.len().min(WORDS);
  39. let mut words = [0; WORDS];
  40. words[..used].copy_from_slice(&user[..used]);
  41. self.ran.push(Ran { pipeline, kind, count, words, used: used as u8 });
  42. }
  43. pub(crate) fn clear(&mut self) {
  44. self.ran.clear();
  45. if self.names.len() > 512 {
  46. self.names.clear();
  47. }
  48. }
  49. /// The `nth` execution (from 0): its text and its user data.
  50. pub(crate) fn nth(&self, nth: usize) -> Option<(String, &[u32])> {
  51. let ran = self.ran.get(nth)?;
  52. let name = self.names.get(&ran.pipeline).map_or("a pipeline", String::as_str);
  53. let words = &ran.words[..usize::from(ran.used)];
  54. Some((
  55. format!("{name} (indirect kind {} max {}, the list's indirect execution {nth}, user data {words:x?})", ran.kind, ran.count),
  56. words,
  57. ))
  58. }
  59. }
  60. /// How many indirect executions come before command `at` of a history of
  61. /// breadcrumb operations (`is` tells them): which of a list's it is.
  62. pub(crate) fn before<T>(history: &[T], at: usize, is: impl Fn(&T) -> bool) -> usize {
  63. history[..at.min(history.len())].iter().filter(|op| is(op)).count()
  64. }
  65. /// The heap slots the user data may name, for the report to describe: the
  66. /// words that are slots as they are, and the slots from where a word is a
  67. /// table's byte offset (32 bytes a descriptor), `table` of them.
  68. pub(crate) fn slots(words: &[u32], count: u32, table: u32) -> Vec<(usize, u32)> {
  69. let mut out = Vec::new();
  70. for (i, &word) in words.iter().enumerate() {
  71. if word > 0 && word < count && word % 32 != 0 {
  72. out.push((i, word));
  73. }
  74. if word % 32 == 0 && word / 32 > 16 && word / 32 < count {
  75. out.extend((0..table).map(|k| (i, word / 32 + k)).filter(|s| s.1 < count));
  76. }
  77. }
  78. out
  79. }
  80. #[cfg(test)]
  81. mod tests {
  82. use super::*;
  83. /// The execution a breadcrumb history stops at is found by the ones
  84. /// before it, and its pipeline and user data are told.
  85. #[test]
  86. fn an_indirect_execution_is_found_by_its_place_in_the_history() {
  87. let mut all = Indirects::default();
  88. all.note(1, "[compute a]", 2, 1, &[0x2549f40, 0x20, 0x11]);
  89. all.note(2, "[compute b]", 2, 1, &[7; 20]);
  90. all.note(1, "another name of the same is not taken", 10, 4, &[]);
  91. // dispatch, indirect, barrier, indirect, indirect
  92. let history = [6, 5, 15, 5, 5];
  93. let nth = before(&history, 3, |op| *op == 5);
  94. assert_eq!(nth, 1);
  95. let (text, words) = all.nth(nth).unwrap();
  96. assert!(text.starts_with("[compute b] (indirect kind 2 max 1"), "{text}");
  97. assert_eq!(words, [7; WORDS]);
  98. let (text, words) = all.nth(2).unwrap();
  99. assert!(text.starts_with("[compute a] (indirect kind 10 max 4"), "{text}");
  100. assert!(words.is_empty());
  101. assert!(all.nth(3).is_none());
  102. assert_eq!(before(&history, 99, |op| *op == 5), 3);
  103. all.clear();
  104. assert!(all.nth(0).is_none());
  105. }
  106. /// A table's byte offset names the slots from it on; a small word that
  107. /// is no multiple of a descriptor's bytes names its own slot.
  108. #[test]
  109. fn user_data_names_slots() {
  110. let words = [0, 0x2549f40, 0x20, 0x11, 0x26f1, 0xffff_ffff];
  111. let slots = slots(&words, 1_245_184, 2);
  112. assert_eq!(slots, [(1, 0x2549f40 / 32), (1, 0x2549f40 / 32 + 1), (3, 0x11), (4, 0x26f1)]);
  113. }
  114. }