{"id":13756992,"url":"https://github.com/gfx-rs/rspirv","last_synced_at":"2025-05-14T00:08:04.052Z","repository":{"id":35495359,"uuid":"70991953","full_name":"gfx-rs/rspirv","owner":"gfx-rs","description":"Rust implementation of SPIR-V module processing functionalities","archived":false,"fork":false,"pushed_at":"2025-04-22T13:19:04.000Z","size":1650,"stargazers_count":469,"open_issues_count":26,"forks_count":61,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-06T20:12:58.339Z","etag":null,"topics":["binary","disassembler","module","opencl","opengl","rust","spirv","vulkan"],"latest_commit_sha":null,"homepage":"https://docs.rs/rspirv","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gfx-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-10-15T14:17:32.000Z","updated_at":"2025-05-05T01:41:01.000Z","dependencies_parsed_at":"2023-01-15T22:12:08.299Z","dependency_job_id":"2aeb3937-5c2e-45ce-a784-fe3bbe8b9839","html_url":"https://github.com/gfx-rs/rspirv","commit_stats":{"total_commits":497,"total_committers":40,"mean_commits":12.425,"dds":0.329979879275654,"last_synced_commit":"000052d7b303856a46b814a2936a66f6726e0d80"},"previous_names":["google/rspirv"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gfx-rs%2Frspirv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gfx-rs%2Frspirv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gfx-rs%2Frspirv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gfx-rs%2Frspirv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gfx-rs","download_url":"https://codeload.github.com/gfx-rs/rspirv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252794428,"owners_count":21805195,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary","disassembler","module","opencl","opengl","rust","spirv","vulkan"],"created_at":"2024-08-03T11:01:00.738Z","updated_at":"2025-05-14T00:08:04.021Z","avatar_url":"https://github.com/gfx-rs.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"rspirv\n======\n\n[![Actions Status](https://github.com/gfx-rs/rspirv/workflows/Continuous%20integration/badge.svg)](https://github.com/gfx-rs/rspirv/actions)\n[![Matrix Room](https://img.shields.io/badge/Matrix-%23gfx%3Amatrix.org-blueviolet.svg)](https://matrix.to/#/#gfx:matrix.org)\n\n**R**u**s**t implementation of S**PIR**-**V** module processing functionalities.\nIt aims to provide:\n\n* APIs for processing SPIR-V modules\n* Command line tools building on top of the APIs for common processing tasks\n\nrspirv defines a common SPIR-V [data representation][doc-dr] (DR) as the\nmedium for various purposes. rspirv also provides a [builder][doc-builder] to\nbuild the DR interactively and a [parser][doc-parser] to parse a given SPIR-V\nbinary module into its DR. A higher level structured representation is currently\nunder developing.\n\n[SPIR-V][spirv] is a common intermediate language for representing graphics\nshaders and compute kernels for multiple Khronos APIs, such as [Vulkan][vulkan],\n[OpenGL][opengl], and [OpenCL][opencl].\n\n[SPIRV-Tools][spirv-tools] is the Khronos Group's official C++ implementation of\nSPIR-V binary parser, assembler, disassembler, optimizer, and validator. rspirv\nis not a Rust language binding for that project; it is a complete rewrite using\nRust.\n\nDocumentation\n-------------\n\nThe current implementation supports SPIR-V 1.5 (Revision 4).\n\nMultiple crates are published from this project:\n\n|  Name  |   Crate   |   Docs   |\n| :----: | :-------: | :------: |\n| rspirv | [![Crate][img-crate-rspirv]][crate-rspirv]   | [![Documentation][img-doc-rspirv]][doc-rspirv]   |\n| spirv  | [![Crate][img-crate-headers]][crate-headers] | [![Documentation][img-doc-headers]][doc-headers] |\n\nIn total rspirv APIs contains:\n* The [SPIR-V header][doc-headers] (all SPIR-V structs, enums, and constants)\n* The whole [SPIR-V grammar][doc-grammar] (instruction layouts and their\n  operands)\n* A [data representation][doc-dr] of SPIR-V modules and its loader and builder\n* SPIR-V [binary][doc-binary] module decoding and parsing functionalities\n\nThe Khronos SPIR-V [JSON grammar][json-grammar] is leveraged to generate parts\nof the source code using [`rspirv-autogen`][autogen].\n\nPlease see the links to docs.rs for detailed documentation.\n\nStatus\n------\n\nI plan to implement several functionalities:\n\n- [x] SPIR-V [data representation][doc-dr] (DR)\n- [x] SPIR-V module [builder][doc-builder]\n- [ ] SPIR-V module assembler\n- [x] SPIR-V binary module [parser][doc-parser]\n- [x] SPIR-V binary module disassembler\n- [ ] HLSL/GLSL to SPIR-V frontend (maybe)\n- [ ] SPIR-V DR to LLVM IR transformation (maybe)\n\nThe DR doesn't handle `OpLine` and `OpNoLine` well right now.\n\nThe SPIR-V binary module parser is feature complete.\n\nUsage\n-----\n\nThis project uses associated constants, which became available in the stable channel\nsince [1.20][rust-1.20]. So to compile with a compiler from the stable channel,\nplease make sure that the version is \u003e= 1.20.\n\nExamples\n--------\n\nBuilding a SPIR-V module, assembling it, parsing it, and then disassembling it:\n\n```rust\nuse rspirv::binary::Assemble;\nuse rspirv::binary::Disassemble;\n\nfn main() {\n    // Building\n    let mut b = rspirv::dr::Builder::new();\n    b.set_version(1, 0);\n    b.capability(spirv::Capability::Shader);\n    b.memory_model(spirv::AddressingModel::Logical, spirv::MemoryModel::GLSL450);\n    let void = b.type_void();\n    let voidf = b.type_function(void, vec![]);\n    let fun = b\n        .begin_function(\n            void,\n            None,\n            spirv::FunctionControl::DONT_INLINE | spirv::FunctionControl::CONST,\n            voidf,\n        )\n        .unwrap();\n    b.begin_basic_block(None).unwrap();\n    b.ret().unwrap();\n    b.end_function().unwrap();\n    b.entry_point(spirv::ExecutionModel::Vertex, fun, \"foo\", vec![]);\n    let module = b.module();\n\n    // Assembling\n    let code = module.assemble();\n    assert!(code.len() \u003e 20); // Module header contains 5 words\n    assert_eq!(spirv::MAGIC_NUMBER, code[0]);\n\n    // Parsing\n    let mut loader = rspirv::dr::Loader::new();\n    rspirv::binary::parse_words(\u0026code, \u0026mut loader).unwrap();\n    let module = loader.module();\n\n    // Disassembling\n    assert_eq!(\n        module.disassemble(),\n        \"; SPIR-V\\n\\\n         ; Version: 1.0\\n\\\n         ; Generator: rspirv\\n\\\n         ; Bound: 5\\n\\\n         OpCapability Shader\\n\\\n         OpMemoryModel Logical GLSL450\\n\\\n         OpEntryPoint Vertex %3 \\\"foo\\\"\\n\\\n         %1 = OpTypeVoid\\n\\\n         %2 = OpTypeFunction %1\\n\\\n         %3 = OpFunction  %1  DontInline|Const %2\\n\\\n         %4 = OpLabel\\n\\\n         OpReturn\\n\\\n         OpFunctionEnd\"\n    );\n}\n```\n\nDirectory Organization\n----------------------\n\nThere are multiple crates inside this repo:\n\n- `autogen/`: Crate to generate various Rust code snippets used in the modules\n  in `spirv/` and `rspirv/`, from SPIR-V's JSON grammar. If you are not\n  modifying `spirv/` or `rspirv/`, you don't need to care about this directory.\n- `spirv/`: The `spirv` crate.\n- `rspirv/`: The core `rspirv` crate.\n- `dis/`: A binary SPIR-V disassembler based on the `rspirv` crate.\n- `spirv-blobs`: SPIR-V blobs provided by the user for testing.\n\nBuild\n-----\n\n```sh\ngit clone https://github.com/gfx-rs/rspirv.git /path/to/rspirv\n```\n\nIf you just want to compile and use the `spirv` crate:\n\n```sh\ncd /path/to/rspirv/spirv\ncargo build\n```\n\nIf you just want to compile and use the `rspirv` crate:\n\n```sh\ncd /path/to/rspirv/rspirv\ncargo build\n```\n\nIf you want to refresh the `spirv` or `rspirv` crate with new code\nsnippets generated from SPIR-V's JSON grammar:\n\n```sh\ncd /path/to/rspirv\n# Clone the SPIRV-Headers repo\ngit submodule update --init\ncargo run -p rspirv-autogen\n```\n\nTest\n----\n\nRunning `cargo test` would scan `spirv-blobs` folder and its subfolders\n(with symlinks followed) for any SPIR-V binary blobs. The test will try to\nload them, disassemble them, and then compose back from the internal\nrepresentations, ensuring the smooth round-trip.\n\nContributions\n-------------\n\nThis project is licensed under the Apache License, Version 2.0\n([LICENSE](LICENSE) or http://www.apache.org/licenses/LICENSE-2.0).\nPlease see [CONTRIBUTING](CONTRIBUTING.md) before contributing.\n\n### Authors\n\nThis project is initialized Lei Zhang ([@antiagainst][me]) and currently\ndeveloped by the gfx-rs [Translators][github-translators] team.\n\n[autogen]: ./autogen/README.md\n[img-crate-rspirv]: https://img.shields.io/crates/v/rspirv.svg\n[img-doc-rspirv]: https://docs.rs/rspirv/badge.svg\n[crate-rspirv]: https://crates.io/crates/rspirv\n[doc-rspirv]: https://docs.rs/rspirv\n[img-crate-headers]: https://img.shields.io/crates/v/spirv.svg\n[img-doc-headers]: https://docs.rs/spirv/badge.svg\n[crate-headers]: https://crates.io/crates/spirv\n[doc-headers]: https://docs.rs/spirv\n[spirv]: https://www.khronos.org/registry/spir-v/\n[vulkan]: https://www.khronos.org/vulkan/\n[opengl]: https://www.opengl.org/\n[opencl]: https://www.khronos.org/opencl/\n[me]: https://github.com/antiagainst\n[github-translators]: https://github.com/orgs/gfx-rs/teams/translators\n[json-grammar]: https://github.com/KhronosGroup/SPIRV-Headers/tree/master/include/spirv\n[spirv-tools]: https://github.com/KhronosGroup/SPIRV-Tools\n[doc-dr]: https://docs.rs/rspirv/*/rspirv/dr/index.html\n[doc-builder]: https://docs.rs/rspirv/*/rspirv/dr/struct.Builder.html\n[doc-parser]: https://docs.rs/rspirv/*/rspirv/binary/struct.Parser.html\n[doc-grammar]: https://docs.rs/rspirv/*/rspirv/grammar/index.html\n[doc-binary]: https://docs.rs/rspirv/*/rspirv/binary/index.html\n[rust-1.20]: https://blog.rust-lang.org/2017/08/31/Rust-1.20.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgfx-rs%2Frspirv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgfx-rs%2Frspirv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgfx-rs%2Frspirv/lists"}