Expand description
§zenfg-snapshot
zenfg-snapshot provides portable, wgpu-independent Snapshot 1.2 wire types,
JSON codec, validation, and legacy migration. It is the Rust counterpart of the
normative @zenfg/snapshot package and depends only on Serde, serde_json, and
thiserror.
Snapshot documents contain graph structure and diagnostics, not GPU commands or resource contents, and cannot replay a frame. Wire-format versioning is independent from this crate’s beta API version.
Snapshot 1.1 inputs are validated before migration to 1.2; their CPU timing is
marked not-collected. Writers and standalone validators accept canonical 1.2
only. Existing Legacy provenance and extensions are preserved.
§Installation
cargo add zenfg-snapshot@=0.1.0§Quick start
Use a Cargo application and add serde_json for the JSON value conversions in
this example. Put the code in fn main() -> Result<(), Box<dyn std::error::Error>>
and finish with Ok(()). Run cargo run; all assertions pass without a GPU.
Lines prefixed with # are rustdoc test scaffolding, not lines to paste.
Parse untrusted JSON text to validate and normalize a canonical Snapshot:
use zenfg_snapshot::{
decode_frame_graph_snapshot, parse_frame_graph_snapshot, to_json_pretty,
validate_frame_graph_snapshot, validate_typed_frame_graph_snapshot,
};
let json_text = r#"{
"format": "zenfg.frame-graph-snapshot",
"version": { "major": 1, "minor": 1 },
"producer": { "name": "example" },
"capture": { "frameIndex": 0 },
"graph": {
"groups": [], "nodes": [], "resources": [], "textureViews": [],
"accesses": [], "dependencies": [], "roots": [], "segments": []
},
"memory": {
"allocationReport": { "status": "available", "allocations": [] },
"poolReport": { "status": "unavailable", "reason": "not captured" }
},
"timings": {
"gpu": { "status": "unavailable", "reason": "not captured" }
},
"diagnostics": [],
"extensions": {}
}"#;
let decoded = parse_frame_graph_snapshot(json_text)?;
let value = serde_json::to_value(&decoded.snapshot)?;
assert!(validate_frame_graph_snapshot(&value).is_empty());
let decoded_from_value = decode_frame_graph_snapshot(value)?;
assert_eq!(decoded_from_value.snapshot, decoded.snapshot);
assert!(validate_typed_frame_graph_snapshot(&decoded.snapshot).is_ok());
let canonical_json = to_json_pretty(&decoded.snapshot)?;
assert!(canonical_json.contains("zenfg.frame-graph-snapshot"));Successful decoding returns a canonical Snapshot 1.2 value and explicit migration provenance when historical input was upgraded. Unknown formats and versions are rejected.
§Common tasks
| Task | Public API |
|---|---|
| Parse untrusted JSON text | parse_frame_graph_snapshot() |
Decode an already-parsed serde_json::Value | decode_frame_graph_snapshot() |
| Validate canonical JSON-shaped data | validate_frame_graph_snapshot() |
| Validate a typed in-memory Snapshot | validate_typed_frame_graph_snapshot() |
| Serialize validated typed data | to_json(), to_json_pretty() |
| Handle decode failures | SnapshotDecodeError |
| Inspect structured issues | SnapshotIssue, SnapshotIssueSeverity |
| Read format, version, and depth limits | FRAME_GRAPH_SNAPSHOT_FORMAT, FRAME_GRAPH_SNAPSHOT_VERSION, FRAME_GRAPH_SNAPSHOT_MAX_EXTENSION_DEPTH |
The crate exports FrameGraphSnapshotV1 and all wire types with Serialize and
Deserialize. Exact fields and error variants are documented on
docs.rs.
§Consumer and producer boundaries
- Use parse or decode for untrusted input. Canonical Snapshot 1.2, Legacy V0, and Legacy Candidate V1 are accepted; supported historical data is migrated explicitly.
- Use
validate_typed_frame_graph_snapshot()before returning a typed producer value.to_json()andto_json_pretty()perform the same checks before writing wire output. - Validation returns structured issues with stable codes, JSON Pointer paths, and messages.
- Unknown versions are rejected until an explicit migration is implemented and tested. Missing legacy facts remain absent rather than being invented.
- The crate has no wgpu dependency. Runtime-to-Snapshot projection belongs to
zenfgbehind itssnapshotfeature.
The normative Schema, specification, fixtures, and conformance manifest are
published by @zenfg/snapshot. See the
Snapshot 1.2 specification
for the complete structural and cross-field contract.
§Common mistakes
| Symptom | Fix |
|---|---|
| Legacy input fails typed or canonical validation | Decode it first so the explicit migration runs. |
| Serialization rejects a typed value | Validate it and inspect the structured issue before writing JSON. |
| An unknown version looks structurally similar | Reject it until a reader implements a tested migration. |
| A producer expects validation to add missing facts | Populate required facts explicitly; validators do not invent diagnostics. |
| A Snapshot is expected to replay GPU work | Use an application-owned command/resource capture mechanism instead. |
§Complete example
The crate ships a compile-checked
examples/basic.rs
workflow. Cross-language fixtures and producer projections live in the
normative @zenfg/snapshot conformance corpus.
§Further reading
§Documentation and versions
This README describes zenfg-snapshot 0.1.0. Registry badges show the current published channel, not your installed version.
- Exact installed APIs: read the included
src/, or runcargo doc --openin your consuming project. - Online guide (development branch). The site may describe changes newer than this package.
- Rust API for this version.
- Source and documentation for this release.
- Shared concepts for this release and compatibility.
- Plain Markdown documentation index (development branch).
- Complete Cargo recipes are included in
examples/.
Structs§
- Frame
Graph Snapshot V1 - Canonical, strongly typed ZenFG FrameGraph Snapshot 1.2 document.
- Snapshot
Access - One declared node-to-resource access and its normalized affected region.
- Snapshot
Allocation - One physical allocation compatibility class and estimated size.
- Snapshot
Buffer Range - Byte range for a captured buffer access; absent size means the remaining buffer.
- Snapshot
Capture - Frame identity, capture time, and optional migration provenance.
- Snapshot
CpuNode Timing - CPU duration in microseconds associated with one retained node of any kind.
- Snapshot
Decode Error - Failure to parse, recognize, migrate, validate, or deserialize a Snapshot.
- Snapshot
Decode Result - Canonical snapshot plus provenance and non-fatal migration diagnostics.
- Snapshot
Dependency - One value-carrying or ordering edge between captured graph nodes.
- Snapshot
Diagnostic - Structured producer diagnostic with optional graph entity references.
- Snapshot
GpuNode Timing - GPU duration, in microseconds, associated with one retained node.
- Snapshot
Graph - Relational graph tables that make up the portable captured frame.
- Snapshot
Group - One recording debug group and its optional parent relationship.
- Snapshot
Issue - One structured Snapshot validation or migration diagnostic.
- Snapshot
Lifetime - Inclusive retained execution-order interval for one logical resource.
- Snapshot
Memory - Allocation-plan and cross-frame resource-pool facts for the capture.
- Snapshot
Migration - Provenance and unavailable facts recorded when converting a historical format.
- Snapshot
Node - One recorded graph node with its original metadata and compile outcome.
- Snapshot
Producer - Identity and optional runtime metadata of the library that produced a capture.
- Snapshot
Resource - One logical resource with descriptor, usage, lifetime, and allocation facts.
- Snapshot
Resource Root - A final resource selection. Missing facts require Legacy provenance.
- Snapshot
Root Resolution - Compiler-provided final content sources.
- Snapshot
Runtime - Optional graphics implementation, API, and native backend facts.
- Snapshot
Segment - One ordered frame-graph or external-submission execution segment.
- Snapshot
Texture Region - Normalized mip, layer/depth-slice, and aspect region for a texture access.
- Snapshot
Texture Size - Three-dimensional texture extent using JSON-safe integer fields.
- Snapshot
Texture View - Fully normalized texture-view descriptor referenced by captured accesses.
- Snapshot
Timings - Optional timing families captured alongside the graph.
- Snapshot
Version - Major/minor version carried by every Snapshot document.
Enums§
- Snapshot
Access Kind - Portable pipeline or copy role of one resource access.
- Snapshot
Access Mode - Whether a captured access reads or writes its resource.
- Snapshot
Allocation Report - Available physical allocation table or an explicit unavailability reason.
- Snapshot
CpuTimings - CPU synchronous elapsed timings, independent of GPU completion.
- Snapshot
Decode Source - Input wire shape recognized by a successful decode.
- Snapshot
Dependency Kind - Whether a dependency carries a logical value or only constrains ordering.
- Snapshot
Diagnostic Severity - Portable severity of a captured producer diagnostic.
- Snapshot
GpuTimings - Available GPU pass timings or an explicit unavailability reason.
- Snapshot
Initial Contents - Whether a resource range is readable at the start of the captured frame.
- Snapshot
Issue Severity - Severity assigned to a validation or migration issue.
- Snapshot
Json Error - Failure to validate or serialize an in-memory Snapshot.
- Snapshot
Migration Source Format - Historical wire format from which a canonical V1 document was migrated.
- Snapshot
Node Compile State - Whether a recorded node was retained, and its order or culling reason.
- Snapshot
Node Kind - Portable kind of work represented by a captured graph node.
- Snapshot
Pool Report - Available resource-pool counters or an explicit unavailability reason.
- Snapshot
Resource Descriptor - Portable physical descriptor for a captured texture or buffer.
- Snapshot
Resource Kind - Portable texture-or-buffer discriminator.
- Snapshot
Resource Origin - Ownership and allocation origin of a captured logical resource.
- Snapshot
Resource Range - Resolved non-empty logical output range.
- Snapshot
Root - One observable resource/node root and its retention reason.
- Snapshot
Root Reason - Portable reason that a node or resource remains observable after compilation.
- Snapshot
Segment Kind - Ownership of command submission for one execution segment.
- Snapshot
Unavailable Fact - Canonical graph fact that a historical source format could not represent.
- Snapshot
Usage Flag - One normalized WebGPU usage flag in protocol-defined ordering.
- Snapshot
Write Contents - Whether a write overwrites or preserves the prior logical value.
Constants§
- FRAME_
GRAPH_ SNAPSHOT_ FORMAT - Canonical
formatdiscriminator for ZenFG Snapshot 1.2 documents. - FRAME_
GRAPH_ SNAPSHOT_ MAX_ EXTENSION_ DEPTH - Maximum number of nested JSON container levels allowed in one extension value.
- FRAME_
GRAPH_ SNAPSHOT_ VERSION - Snapshot wire version emitted by this crate.
- LEGACY_
CANDIDATE_ FRAME_ GRAPH_ SNAPSHOT_ FORMAT - Historical pre-release
formatdiscriminator accepted for migration.
Functions§
- decode_
frame_ graph_ snapshot - Migrates when necessary, validates, and deserializes an arbitrary JSON value.
- parse_
frame_ graph_ snapshot - Parses, migrates when necessary, and validates a Snapshot JSON document.
- to_json
- Validates and serializes a canonical Snapshot as compact JSON.
- to_
json_ pretty - Validates and serializes a canonical Snapshot as human-readable JSON.
- validate_
frame_ graph_ snapshot - Validates an arbitrary JSON value against Snapshot 1.2.
- validate_
typed_ frame_ graph_ snapshot - Validates a typed Snapshot without producing JSON text.