Giter Club home page Giter Club logo

inline-spirv-rs's Introduction

Inline SPIR-V & JIT SPIR-V

Crate Documentation

inline-spirv and jit-spirv ease the way you write shaders. Although as game developers, we usually compile a permutation of shader stages for different objects and materials at runtime for the best flexibility; sometimes we do want to try out some new ideas and start up dirty. This crate helps you compile GLSL/HLSL shader in your Rust code, or in external files, into SPIR-V; and embed them right inside the binary, so you are freed from all the compilation hassle.

How to Use

To inline shader source:

use inline_spirv::include_spirv;

let spv: &'static [u32] = inline_spirv!(r#"
    #version 450 core
    void main() { gl_Position = vec4(0, 0, 0, 1); }
"#, vert);

To include a external shader source file:

use inline_spirv::include_spirv;

let spv: &'static [u32] = include_spirv!("assets/vert.hlsl", vert, hlsl, entry="Main");

To compile a runtime shader source just-in-time:

use jit_spirv::{jit_spirv, CompilationFeedback};

let feedback: CompilationFeedback = jit_spirv!(r#"
    #version 450
    layout(binding=0) writeonly buffer _0 { float data[]; };
    void main() {
        data[gl_GlobalInvocationID.x] = 1.0;
    }
"#, comp).unwrap();
let spv: &[u32] = &feedback.spv;

To include a precompiled SPIR-V binary:

use inline_spirv::include_spirv;

let spv: &'static [u32] = include_spirv!("assets/vert.spv");

For the full list of options please refer to the documentation.

Tips

The macro can be verbose especially you have a bunch of #includes, so please be aware of that you can alias and define a more customized macro for yourself:

use inline_spirv::include_spirv as include_spirv_raw;

macro_rules! include_spirv {
    ($path:expr, $stage:ident) => {
        include_spirv_raw!(
            $path,
            $stage, hlsl,
            entry="my_entry_pt",
            D VERBOSE_DEFINITION,
            D ANOTHER_VERBOSE_DEFINITION="verbose definition substitution",
            I "long/path/to/include/directory",
        )
    }
}

// ...
let vert: &[u32] = include_spirv!("examples/demo/assets/demo.hlsl", vert);

License

This project is licensed under either of

at your option.

inline-spirv-rs's People

Contributors

attackgoat avatar dparnell avatar nkipsc avatar penguinliong avatar zedrian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.