$ show gfx-rs/rspirv
rspirv is a Rust workspace providing comprehensive SPIR-V module processing functionality. It includes a core library (rspirv) with a low-level data representation (DR) for raw instructions and a higher-level structured representation (SR) with type-safe indices. The project also features a binary parser, an assembler, a disassembler CLI (rspirv-dis), and a code generator (rspirv-autogen) that derives Rust types from the official SPIR-V JSON grammar. The parser supports custom consumers via the Consumer trait, enabling streaming or custom processing. The builder (dr/build) allows programmatic construction of SPIR-V modules. The lift module converts from DR to SR, bridging the two representations. The codebase is heavily auto-generated from the SPIR-V specification, ensuring spec compliance, but this also introduces risks of drift if the grammar submodule is not updated. The project is actively maintained with CI/CD pipelines, and the multi-crate workspace is designed for both library reuse and standalone tool usage.
The LLM identified 2 files worth highlighting for reuse:
Provides strongly-typed index `Token<T>` and a generic `Storage<T>` container with deduplication via `fetch_or_append`. This is a clean, self-contained pattern for managing interned data like types and constants in the structured representation. It can be extracted and reused in any project requiring index-based data management with automatic deduplication.
`LiftStorage<T>` wraps `Storage` with an fxhash-based mapping from SPIR-V word IDs to `Token` indices. It serves as a bridge between the flat SPIR-V ID space and the structured index space of the SR, providing efficient caching and lookup. This isolated module demonstrates a reusable pattern for mapping external identifiers to internal typed references.