1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//! Use this crate to compile your GLSL shaders at compile time into binaries embedded in your program.
//!
//! This crate requires you to also use the `glsl-to-spirv-macros-impl` crate. Without it these macros will not work.
//! Unfortunately it is not yet possible to combine the two crates into one.
//!
//! Example usage:
//!
//! ```ignore
//! #[macro_use] extern crate glsl_to_spirv_macros;
//! #[macro_use] extern crate glsl_to_spirv_macros_impl;
//!
//! static some_shader: &'static [u8] = glsl_vs!{r#"
//!     // Shader code here
//! "#};
//!
//! fn main() {
//!     let another_shader = include_glsl_fs!("path/to/shader");
//! }
//! ```
//!
//! All macros in this crate return `&'static [u8]`, and can be used in the definition of `static` as well as local variables.
//! Every macro takes a string literal, e.g. `"..."`, `r#"..."#` etc.
//!
//! These macros generate Vulkan-compatible SPIR-V binaries using the official glslang compiler - they
//! are not designed for use with other APIs, like OpenCL.

/// Compiles a string containing a GLSL vertex shader into SPIR-V binary data.
#[macro_export]
macro_rules! glsl_vs {
    ($source:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[src=$source]
        #[ty="vs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles a string containing a GLSL fragment shader into SPIR-V binary data.
#[macro_export]
macro_rules! glsl_fs {
    ($source:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[src=$source]
        #[ty="fs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles a string containing a GLSL geometry shader into SPIR-V binary data.
#[macro_export]
macro_rules! glsl_gs {
    ($source:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[src=$source]
        #[ty="gs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles a string containing a GLSL tessellation control shader into SPIR-V binary data.
#[macro_export]
macro_rules! glsl_tcs {
    ($source:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[src=$source]
        #[ty="tcs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles a string containing a GLSL tessellation evaluation shader into SPIR-V binary data.
#[macro_export]
macro_rules! glsl_tes {
    ($source:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[src=$source]
        #[ty="tes"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles a string containing a GLSL compute shader into SPIR-V binary data.
#[macro_export]
macro_rules! glsl_cs {
    ($source:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[src=$source]
        #[ty="cs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles the specified file (path relative to the crate root) containing a GLSL vertex shader into SPIR-V binary data.
#[macro_export]
macro_rules! include_glsl_vs {
    ($path:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[path=$path]
        #[ty="vs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles the specified file (path relative to the crate root) containing a GLSL fragment shader into SPIR-V binary data.
#[macro_export]
macro_rules! include_glsl_fs {
    ($path:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[path=$path]
        #[ty="fs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles the specified file (path relative to the crate root) containing a GLSL geometry shader into SPIR-V binary data.
#[macro_export]
macro_rules! include_glsl_gs {
    ($path:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[path=$path]
        #[ty="gs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles the specified file (path relative to the crate root) containing a GLSL tessellation control shader into SPIR-V binary data.
#[macro_export]
macro_rules! include_glsl_tcs {
    ($path:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[path=$path]
        #[ty="tcs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles the specified file (path relative to the crate root) containing a GLSL tessellation evaluation shader into SPIR-V binary data.
#[macro_export]
macro_rules! include_glsl_tes {
    ($path:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[path=$path]
        #[ty="tes"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}

/// Compiles the specified file (path relative to the crate root) containing a GLSL compute shader into SPIR-V binary data.
#[macro_export]
macro_rules! include_glsl_cs {
    ($path:tt) => {{
        #[allow(dead_code)]
        #[derive(GLSLEmbedImpl)]
        #[path=$path]
        #[ty="cs"]
        struct Dummy;
        &DATA as &'static [u8]
    }};
}