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