Skip to content

Commit 494a0c3

Browse files
authored
vulkano-shaders - proc macros 2.0 (#1062)
* vulkano_shaders_derive exposes a proc_macro instead of a proc_macro_derive * move vulkano_shader out of vulkano_shaders_derive and deprecate vulkano_shaders_derive * Update documentation * Move vulkano_shader! to root of mod, so it works with rust 1.30
1 parent 7a11120 commit 494a0c3

22 files changed

+909
-926
lines changed

Diff for: CHANGELOG.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Unreleased (Breaking)
22

3-
- `vulkano_shaders::reflect` now returns `Result<proc_macro2::TokenStream, Error>` instead of `Result<String, Error>`
3+
- Export features and device extensions from the device module instead of the instance module
4+
+ `instance::Features` -> `device::Features`
5+
+ `instance::DeviceExtensions` -> `device::DeviceExtensions`
6+
+ `instance::RawDeviceExtensions` -> `device::RawDeviceExtensions`
7+
- Added `vulkano_shaders::vulkano_shader` proc macro, use this instead of `vulkano_shader_deriver::VulkanoShaders`.
8+
- The entire `vulkano_shader_derive` crate is deprecated.
9+
- `vulkano_shaders::{reflect, compile, Error}` are no longer public.
410
- Removed mir support, as it is being removed from the vulkan spec.
511
- Remove vulkano_shaders::build_glsl_shaders
612
- Split `PersistentDescriptorSetError::MissingUsage` into `MissingImageUsage` and `MissingBufferUsage`
@@ -14,10 +20,6 @@
1420

1521
# Version 0.10.0 (2018-08-10)
1622

17-
- Export features and device extensions from the device module instead of the instance module
18-
+ `instance::Features` -> `device::Features`
19-
+ `instance::DeviceExtensions` -> `device::DeviceExtensions`
20-
+ `instance::RawDeviceExtensions` -> `device::RawDeviceExtensions`
2123
- Use dynamically loaded `libvulkan` like on other platforms instead of linking to MoltenVK on macOS
2224
- Updated winit to version 0.17.
2325
- Allow custom implementations of `RenderPassDesc` to specify `VK_SUBPASS_EXTERNAL` as a dependency source or destination

Diff for: examples/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66

77
[dependencies]
88
vulkano = { path = "../vulkano" }
9-
vulkano-shader-derive = { path = "../vulkano-shader-derive" }
9+
vulkano-shaders = { path = "../vulkano-shaders" }
1010
vulkano-win = { path = "../vulkano-win" }
1111
cgmath = "0.16.1"
1212
image = "0.20.0"

Diff for: examples/src/bin/basic-compute-shader.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
// Note that since we don't create any window, fewer imports are needed.
1717
extern crate vulkano;
18-
#[macro_use]
19-
extern crate vulkano_shader_derive;
18+
extern crate vulkano_shaders;
2019

2120
use vulkano::buffer::BufferUsage;
2221
use vulkano::buffer::CpuAccessibleBuffer;
@@ -29,9 +28,28 @@ use vulkano::instance::InstanceExtensions;
2928
use vulkano::pipeline::ComputePipeline;
3029
use vulkano::sync::now;
3130
use vulkano::sync::GpuFuture;
31+
use vulkano_shaders::vulkano_shader;
3232

3333
use std::sync::Arc;
3434

35+
vulkano_shader!{
36+
mod_name: cs,
37+
ty: "compute",
38+
src: "
39+
#version 450
40+
41+
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
42+
43+
layout(set = 0, binding = 0) buffer Data {
44+
uint data[];
45+
} data;
46+
47+
void main() {
48+
uint idx = gl_GlobalInvocationID.x;
49+
data.data[idx] *= 12;
50+
}"
51+
}
52+
3553
fn main() {
3654
// As with other examples, the first step is to create an instance.
3755
let instance = Instance::new(None, &InstanceExtensions::none(), None)
@@ -79,28 +97,6 @@ fn main() {
7997
// If you are familiar with graphics pipeline, the principle is the same except that compute
8098
// pipelines are much simpler to create.
8199
let pipeline = Arc::new({
82-
// TODO: explain
83-
#[allow(dead_code)]
84-
mod cs {
85-
#[derive(VulkanoShader)]
86-
#[ty = "compute"]
87-
#[src = "
88-
#version 450
89-
90-
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
91-
92-
layout(set = 0, binding = 0) buffer Data {
93-
uint data[];
94-
} data;
95-
96-
void main() {
97-
uint idx = gl_GlobalInvocationID.x;
98-
data.data[idx] *= 12;
99-
}"
100-
]
101-
struct Dummy;
102-
}
103-
104100
let shader = cs::Shader::load(device.clone())
105101
.expect("failed to create shader module");
106102
ComputePipeline::new(device.clone(), &shader.main_entry_point(), &())

Diff for: examples/src/bin/deferred/frame/ambient_lighting_system.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use vulkano::pipeline::blend::BlendOp;
2323
use vulkano::pipeline::GraphicsPipeline;
2424
use vulkano::pipeline::GraphicsPipelineAbstract;
2525
use vulkano::pipeline::viewport::Viewport;
26+
use vulkano_shaders::vulkano_shader;
2627

2728
use std::sync::Arc;
2829

@@ -142,27 +143,23 @@ struct Vertex {
142143
}
143144
impl_vertex!(Vertex, position);
144145

145-
mod vs {
146-
#[derive(VulkanoShader)]
147-
#[allow(dead_code)]
148-
#[ty = "vertex"]
149-
#[src = "
146+
vulkano_shader!{
147+
mod_name: vs,
148+
ty: "vertex",
149+
src: "
150150
#version 450
151151
152152
layout(location = 0) in vec2 position;
153153
154154
void main() {
155155
gl_Position = vec4(position, 0.0, 1.0);
156-
}
157-
"]
158-
struct Dummy;
156+
}"
159157
}
160158

161-
mod fs {
162-
#[derive(VulkanoShader)]
163-
#[allow(dead_code)]
164-
#[ty = "fragment"]
165-
#[src = "
159+
vulkano_shader!{
160+
mod_name: fs,
161+
ty: "fragment",
162+
src: "
166163
#version 450
167164
168165
// The `color_input` parameter of the `draw` method.
@@ -180,7 +177,5 @@ void main() {
180177
vec3 in_diffuse = subpassLoad(u_diffuse).rgb;
181178
f_color.rgb = push_constants.color.rgb * in_diffuse;
182179
f_color.a = 1.0;
183-
}
184-
"]
185-
struct Dummy;
180+
}"
186181
}

Diff for: examples/src/bin/deferred/frame/directional_lighting_system.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use vulkano::pipeline::blend::BlendOp;
2323
use vulkano::pipeline::GraphicsPipeline;
2424
use vulkano::pipeline::GraphicsPipelineAbstract;
2525
use vulkano::pipeline::viewport::Viewport;
26+
use vulkano_shaders::vulkano_shader;
2627
use cgmath::Vector3;
2728

2829
use std::sync::Arc;
@@ -154,27 +155,23 @@ struct Vertex {
154155
}
155156
impl_vertex!(Vertex, position);
156157

157-
mod vs {
158-
#[derive(VulkanoShader)]
159-
#[allow(dead_code)]
160-
#[ty = "vertex"]
161-
#[src = "
158+
vulkano_shader!{
159+
mod_name: vs,
160+
ty: "vertex",
161+
src: "
162162
#version 450
163163
164164
layout(location = 0) in vec2 position;
165165
166166
void main() {
167167
gl_Position = vec4(position, 0.0, 1.0);
168-
}
169-
"]
170-
struct Dummy;
168+
}"
171169
}
172170

173-
mod fs {
174-
#[derive(VulkanoShader)]
175-
#[allow(dead_code)]
176-
#[ty = "fragment"]
177-
#[src = "
171+
vulkano_shader!{
172+
mod_name: fs,
173+
ty: "fragment",
174+
src: "
178175
#version 450
179176
180177
// The `color_input` parameter of the `draw` method.
@@ -203,7 +200,5 @@ void main() {
203200
vec3 in_diffuse = subpassLoad(u_diffuse).rgb;
204201
f_color.rgb = light_percent * push_constants.color.rgb * in_diffuse;
205202
f_color.a = 1.0;
206-
}
207-
"]
208-
struct Dummy;
203+
}"
209204
}

Diff for: examples/src/bin/deferred/frame/point_lighting_system.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use vulkano::pipeline::blend::BlendOp;
2323
use vulkano::pipeline::GraphicsPipeline;
2424
use vulkano::pipeline::GraphicsPipelineAbstract;
2525
use vulkano::pipeline::viewport::Viewport;
26+
use vulkano_shaders::vulkano_shader;
2627
use cgmath::Matrix4;
2728
use cgmath::Vector3;
2829

@@ -168,11 +169,10 @@ struct Vertex {
168169
}
169170
impl_vertex!(Vertex, position);
170171

171-
mod vs {
172-
#[derive(VulkanoShader)]
173-
#[allow(dead_code)]
174-
#[ty = "vertex"]
175-
#[src = "
172+
vulkano_shader!{
173+
mod_name: vs,
174+
ty: "vertex",
175+
src: "
176176
#version 450
177177
178178
layout(location = 0) in vec2 position;
@@ -181,16 +181,13 @@ layout(location = 0) out vec2 v_screen_coords;
181181
void main() {
182182
v_screen_coords = position;
183183
gl_Position = vec4(position, 0.0, 1.0);
184-
}
185-
"]
186-
struct Dummy;
184+
}"
187185
}
188186

189-
mod fs {
190-
#[derive(VulkanoShader)]
191-
#[allow(dead_code)]
192-
#[ty = "fragment"]
193-
#[src = "
187+
vulkano_shader!{
188+
mod_name: fs,
189+
ty: "fragment",
190+
src: "
194191
#version 450
195192
196193
// The `color_input` parameter of the `draw` method.
@@ -236,7 +233,5 @@ void main() {
236233
vec3 in_diffuse = subpassLoad(u_diffuse).rgb;
237234
f_color.rgb = push_constants.color.rgb * light_percent * in_diffuse;
238235
f_color.a = 1.0;
239-
}
240-
"]
241-
struct Dummy;
236+
}"
242237
}

Diff for: examples/src/bin/deferred/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
extern crate cgmath;
3030
#[macro_use]
3131
extern crate vulkano;
32-
#[macro_use]
33-
extern crate vulkano_shader_derive;
32+
extern crate vulkano_shaders;
3433
extern crate winit;
3534
extern crate vulkano_win;
3635

Diff for: examples/src/bin/deferred/triangle_draw_system.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use vulkano::framebuffer::Subpass;
1818
use vulkano::pipeline::GraphicsPipeline;
1919
use vulkano::pipeline::GraphicsPipelineAbstract;
2020
use vulkano::pipeline::viewport::Viewport;
21+
use vulkano_shaders::vulkano_shader;
2122

2223
use std::sync::Arc;
2324

@@ -94,27 +95,23 @@ struct Vertex {
9495
}
9596
impl_vertex!(Vertex, position);
9697

97-
mod vs {
98-
#[derive(VulkanoShader)]
99-
#[allow(dead_code)]
100-
#[ty = "vertex"]
101-
#[src = "
98+
vulkano_shader!{
99+
mod_name: vs,
100+
ty: "vertex",
101+
src: "
102102
#version 450
103103
104104
layout(location = 0) in vec2 position;
105105
106106
void main() {
107107
gl_Position = vec4(position, 0.0, 1.0);
108-
}
109-
"]
110-
struct Dummy;
108+
}"
111109
}
112110

113-
mod fs {
114-
#[derive(VulkanoShader)]
115-
#[allow(dead_code)]
116-
#[ty = "fragment"]
117-
#[src = "
111+
vulkano_shader!{
112+
mod_name: fs,
113+
ty: "fragment",
114+
src: "
118115
#version 450
119116
120117
layout(location = 0) out vec4 f_color;
@@ -123,7 +120,5 @@ layout(location = 1) out vec3 f_normal;
123120
void main() {
124121
f_color = vec4(1.0, 1.0, 1.0, 1.0);
125122
f_normal = vec3(0.0, 0.0, 1.0);
126-
}
127-
"]
128-
struct Dummy;
123+
}"
129124
}

Diff for: examples/src/bin/image/main.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ extern crate winit;
1313

1414
#[macro_use]
1515
extern crate vulkano;
16-
#[macro_use]
17-
extern crate vulkano_shader_derive;
16+
extern crate vulkano_shaders;
1817
extern crate vulkano_win;
1918

2019
use vulkano_win::VkSurfaceBuild;
2120
use vulkano::sync::GpuFuture;
21+
use vulkano_shaders::vulkano_shader;
2222

2323
use std::sync::Arc;
2424

@@ -242,10 +242,10 @@ fn main() {
242242
}
243243
}
244244

245-
mod vs {
246-
#[derive(VulkanoShader)]
247-
#[ty = "vertex"]
248-
#[src = "
245+
vulkano_shader!{
246+
mod_name: vs,
247+
ty: "vertex",
248+
src: "
249249
#version 450
250250
251251
layout(location = 0) in vec2 position;
@@ -254,16 +254,13 @@ layout(location = 0) out vec2 tex_coords;
254254
void main() {
255255
gl_Position = vec4(position, 0.0, 1.0);
256256
tex_coords = position + vec2(0.5);
257-
}
258-
"]
259-
#[allow(dead_code)]
260-
struct Dummy;
257+
}"
261258
}
262259

263-
mod fs {
264-
#[derive(VulkanoShader)]
265-
#[ty = "fragment"]
266-
#[src = "
260+
vulkano_shader!{
261+
mod_name: fs,
262+
ty: "fragment",
263+
src: "
267264
#version 450
268265
269266
layout(location = 0) in vec2 tex_coords;
@@ -273,8 +270,5 @@ layout(set = 0, binding = 0) uniform sampler2D tex;
273270
274271
void main() {
275272
f_color = texture(tex, tex_coords);
276-
}
277-
"]
278-
#[allow(dead_code)]
279-
struct Dummy;
273+
}"
280274
}

0 commit comments

Comments
 (0)