GithubHelp home page GithubHelp logo

kryndex / rspirv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gfx-rs/rspirv

0.0 1.0 0.0 441 KB

Rust implementation of SPIR-V module processing functionalities

Home Page: https://docs.rs/rspirv

License: Apache License 2.0

Rust 100.00%

rspirv's Introduction

rspirv

Build Status Build status

Rust implementation of SPIR-V module processing functionalities. It aims to provide:

  • APIs for processing SPIR-V modules
  • Command line tools building on top of the APIs for common processing tasks

rspirv defines a common SPIR-V data representation (MR) as the medium for various purposes. rspirv also provides a builder to build the MR iteractively and a parser to parse a given SPIR-V binary module into its MR. A higher level structured representation is currently under developing.

SPIR-V is a common intermediate language for representing graphics shaders and compute kernels for multiple Khronos APIs, such as Vulkan, OpenGL, and OpenCL.

SPIRV-Tools is the Khronos Group's official C++ implementation of SPIR-V binary parser, assembler, disassembler, optimizer, and validator. rspirv is not a Rust language binding for that project; it is a complete rewrite using Rust.

Disclaimer

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

Documentation

The current implementation supports SPIR-V 1.1 (Revision 5).

Multiple crates are published from this project:

Name Crate Docs
rspirv Crate Documentation
spirv_headers Crate Documentation

In total rspirv APIs contains:

The Khronos SPIR-V JSON grammar is leveraged to generate parts of the source code using Cargo build scripts.

Please see the links to docs.rs for detailed documentation.

Status

I plan to implement serveral functionalities:

  • SPIR-V data representation (MR)
  • SPIR-V module builder
  • SPIR-V module assembler
  • SPIR-V binary module parser
  • SPIR-V binary module disassemebler
  • HLSL/GLSL to SPIR-V frontend (maybe)
  • SPIR-V MR to LLVM IR transformation (maybe)

The MR doesn't handle OpLine and OpNoLine well right now.

The SPIR-V binary module parser is almost feature complete; the only feature (that I am aware of) missing is 64-bit selectors in OpSwitch.

Usage

This project uses custom derive, which became available in the stable channel since 1.15. So to compile with a compiler from the stable channel, please make sure that the version is >= 1.15.

Examples

Building a SPIR-V module, assembling it, parsing it, and then disassembling it:

extern crate rspirv;
extern crate spirv_headers as spirv;

use rspirv::binary::Assemble;
use rspirv::binary::Disassemble;

fn main() {
    // Building
    let mut b = rspirv::mr::Builder::new();
    b.memory_model(spirv::AddressingModel::Logical, spirv::MemoryModel::GLSL450);
    let void = b.type_void();
    let voidf = b.type_function(void, vec![void]);
    b.begin_function(void,
                     None,
                     (spirv::FUNCTION_CONTROL_DONT_INLINE |
                      spirv::FUNCTION_CONTROL_CONST),
                     voidf)
     .unwrap();
    b.begin_basic_block(None).unwrap();
    b.ret().unwrap();
    b.end_function().unwrap();
    let module = b.module();

    // Assembling
    let code = module.assemble();
    assert!(code.len() > 20);  // Module header contains 5 words
    assert_eq!(spirv::MAGIC_NUMBER, code[0]);

    // Parsing
    let mut loader = rspirv::mr::Loader::new();
    rspirv::binary::parse_words(&code, &mut loader).unwrap();
    let module = loader.module();

    // Disassembling
    assert_eq!(module.disassemble(),
               "; SPIR-V\n\
                ; Version: 1.1\n\
                ; Generator: rspirv\n\
                ; Bound: 5\n\
                OpMemoryModel Logical GLSL450\n\
                %1 = OpTypeVoid\n\
                %2 = OpTypeFunction %1 %1\n\
                %3 = OpFunction  %1  DontInline|Const %2\n\
                %4 = OpLabel\n\
                OpReturn\n\
                OpFunctionEnd");
}

Contributions

This project is licensed under the Apache 2 license. Please see CONTRIBUTING before contributing.

Authors

This project is initialized and mainly developed by Lei Zhang (@antiagainst).

rspirv's People

Contributors

anderspitman avatar antiagainst avatar jonysy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.