Skip to content

Commit 45f2312

Browse files
authored
Put shader modules at the top of the example runners (#229)
1 parent 2f63add commit 45f2312

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

examples/runners/ash/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ use std::io::Cursor;
1717
use std::ops::Drop;
1818
use structopt::StructOpt;
1919

20+
fn shader_module() -> &'static [u8] {
21+
&include_bytes!(env!("sky_shader.spv"))[..]
22+
}
23+
2024
// Simple offset_of macro akin to C++ offsetof
2125
#[macro_export]
2226
macro_rules! offset_of {
@@ -619,7 +623,7 @@ fn main() {
619623
})
620624
.collect();
621625

622-
let mut spv_file = Cursor::new(&include_bytes!(env!("sky_shader.spv"))[..]);
626+
let mut spv_file = Cursor::new(shader_module());
623627
let code = read_spv(&mut spv_file).expect("Failed to read spv file");
624628
let shader_info = vk::ShaderModuleCreateInfo::builder().code(&code);
625629

examples/runners/cpu/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use rayon::prelude::*;
33
use spirv_std::glam::{vec2, Vec4};
44
use std::time::Instant;
55

6+
use sky_shader as shader_module;
7+
68
// apply the srgb OETF (i.e. do "linear to sRGB")
79
fn srgb_oetf(x: f32) -> f32 {
810
if x <= 0.0031308 {
@@ -47,7 +49,7 @@ fn main() {
4749
);
4850

4951
// evaluate the fragment shader for the specific pixel
50-
let color = sky_shader::fs(screen_pos);
52+
let color = shader_module::fs(screen_pos);
5153

5254
color_u32_from_vec4(color)
5355
})

examples/runners/wgpu-compute/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
fn shader_module() -> wgpu::ShaderModuleSource<'static> {
2+
wgpu::include_spirv!(env!("compute_shader.spv"))
3+
}
4+
15
fn create_device_queue() -> (wgpu::Device, wgpu::Queue) {
26
async fn create_device_queue_async() -> (wgpu::Device, wgpu::Queue) {
37
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
@@ -35,7 +39,7 @@ fn main() {
3539
let (device, queue) = create_device_queue();
3640

3741
// Load the shaders from disk
38-
let module = device.create_shader_module(wgpu::include_spirv!(env!("compute_shader.spv")));
42+
let module = device.create_shader_module(shader_module());
3943

4044
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
4145
label: None,

examples/runners/wgpu/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use winit::{
44
window::Window,
55
};
66

7+
fn shader_module() -> wgpu::ShaderModuleSource<'static> {
8+
wgpu::include_spirv!(env!("sky_shader.spv"))
9+
}
10+
711
async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::TextureFormat) {
812
let size = window.inner_size();
913
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
@@ -39,7 +43,7 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::
3943
.expect("Failed to create device");
4044

4145
// Load the shaders from disk
42-
let module = device.create_shader_module(wgpu::include_spirv!(env!("sky_shader.spv")));
46+
let module = device.create_shader_module(shader_module());
4347

4448
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
4549
label: None,

0 commit comments

Comments
 (0)