replay: the display library line names the sidecar by SHA-256 and git blob id

The planner's condition on the display sidecar: every play states which
display library it ran. The report's display library line now gives the
sidecar's length, its SHA-256, and its git blob id (the SHA-1 of
"blob LENGTH\0" and the bytes). The blob id names the file in the host's tree:
every stream so far holds blob b1aea1f0, 47,426 bytes. The doc also says the
sidecar holds the host's display shaders alone, and that a player makes only
the device's library from source of no arguments from it.

The validation crate takes sha1 0.11 (RustCrypto, MIT OR Apache-2.0; the same
digest family as sha2 0.11) for the blob id.

Test: the integration test expects the 5-byte sidecar's SHA-256 and the blob
id `git hash-object` gives for the same bytes (8d7ffd7e). Verified by the lane
check named in the hand-over.
This commit is contained in:
Anees Iqbal committed 2026-11-18 18:07:35 -08:00
1 parent 0ee01c4eda
commit 37fffd39fc
6 files changed
+31 -12

No files matched your search

+1
View File
@@ -37,6 +37,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
# SHA-256 on the CPU's own instructions where it has them (ARMv8's SHA2 extension, x86's SHA-NI),
# detected at run time; nothing here uses the default `alloc` and `oid` features.
sha1 = { version = "0.11", default-features = false }
sha2 = { version = "0.11", default-features = false }
# Dev and test builds keep line tables (file and line in backtraces) and no other debug info, and
@@ -39,6 +39,7 @@ memchr = "2"
rusqlite = { version = "0.32", features = ["bundled"] }
serde.workspace = true
serde_json.workspace = true
sha1.workspace = true
sha2.workspace = true
wait-timeout = "0.2"
@@ -194,6 +194,22 @@ fn shapes(options: &BTreeMap<String, String>) -> i32 {
const BEFORE_COMPLETION_FIX: &str =
"recorded before the recorder's completion fix: the stream may differ from what the program did";
/// The report's `display library` line of a stream with the sidecar `metallib`: its length, its
/// SHA-256, and its git blob id (the SHA-1 of `blob LENGTH\0` and the bytes), which names the
/// file in the host's tree.
fn display_line(metallib: &[u8]) -> String {
use sha1::Digest as _;
let sha256 = metal2vulkan_validation::replay::hex(&sha2::Sha256::digest(metallib));
let mut blob = sha1::Sha1::new();
blob.update(format!("blob {}\0", metallib.len()).as_bytes());
blob.update(metallib);
let blob = metal2vulkan_validation::replay::hex(&blob.finalize());
format!(
"display library the stream's sidecar, {} bytes, sha256 {sha256}, git blob {blob}",
metallib.len()
)
}
/// The report's `range` line: the recording range the play used, where it came from, and whether
/// the play ends there or `--past-range yes` takes it past.
fn range_line(range: RecordingRange, source: RangeSource, past: bool) -> String {
@@ -269,10 +285,7 @@ fn play(options: &BTreeMap<String, String>) -> i32 {
let display = display_library(&PathBuf::from(&options["stream"]));
let display = match std::fs::read(&display) {
Ok(metallib) => {
report.line(&format!(
"display library the stream's sidecar, {} bytes",
metallib.len()
));
report.line(&display_line(&metallib));
Some(metallib)
}
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
@@ -27,7 +27,7 @@ pub use stream::{
segments, Call, StreamError, StreamReader, StreamWriter, FLAG_ANNOUNCED_BYTES_RECORDED,
FLAG_COMPLETION_BYTES_RECORDED,
};
pub use value::{Hash, Name, Value};
pub use value::{hex, Hash, Name, Value};
#[cfg(test)]
mod tests;
@@ -67,7 +67,7 @@ fn a_report_names_the_recording_range_the_play_used() {
}
/// The line after the range says whether the stream has the host's display library beside it,
/// `NAME.display.metallib`, and its length.
/// `NAME.display.metallib`, and its length, SHA-256 and git blob id.
#[test]
fn a_report_names_the_display_library_beside_the_stream() {
let dir = ScratchDir::new("replay-display-report").unwrap();
@@ -86,8 +86,10 @@ fn a_report_names_the_display_library_beside_the_stream() {
"display library none: the host's library from source is skipped"
);
std::fs::write(dir.path().join("s.display.metallib"), b"MTLB!").unwrap();
// `git hash-object` of the five bytes names the same blob.
assert_eq!(
line("beside"),
"display library the stream's sidecar, 5 bytes"
"display library the stream's sidecar, 5 bytes, sha256 \
6cfdce7eee577852d35aebca1eb2891e635bec8546b3038e31348ff5f9a5ce0c, git blob 8d7ffd7ee222d331e5a1c416934ff13a9ab9b1be"
);
}
+7 -5
View File
@@ -44,8 +44,9 @@ hold guest data and is never committed. Tests write their own streams.
- **The display library sidecar.** `NAME.display.metallib` beside the first segment, as
`NAME.range`, is the metallib of the host's own display shaders, which the host makes as a
library from source: the stream's `newLibraryWithSource:options:error:` of the device with no
arguments. A program's own libraries reach the stream as data (`newLibraryWithData:error:`,
section 9), never as source. A player makes that library of the sidecar, as of data; a stream
arguments. It holds the host's display shaders alone, never a program's: a program's own
libraries reach the stream as data (`newLibraryWithData:error:`, section 9), never as source. A
player makes that one library of the sidecar, as of data, and nothing else of it; a stream
without one leaves it skipped and counted, with the host's draws that use it.
| kind | record | payload |
@@ -463,9 +464,10 @@ counted from 0), completes the work committed so far, reports as at the stream's
`until-frame F` as `--until-frame` does. A sidecar that reads as neither `last-frame F` nor
`whole` is an error.
- **The display library.** The report's line after `range` is `display library the stream's
sidecar, N bytes` where the stream has `NAME.display.metallib` (section 1), and the host's
library from source is made of it on either runtime; else `display library none: the host's
library from source is skipped`.
sidecar, N bytes, sha256 HEX, git blob ID` where the stream has `NAME.display.metallib` (section
1), which names the file the play ran by its SHA-256 and its git blob id in the host's tree, and
the host's library from source is made of it on either runtime; else `display library none: the
host's library from source is skipped`.
- **Streams recorded before the completion fix.** Where the stream's header lacks bit 1 (section
6), the report's first line is, by itself, `recorded before the recorder's completion fix: the
stream may differ from what the program did`, so no table taken from the report loses it.