diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 8b2662492a..818a6f2cff 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -24,7 +24,7 @@ gl = ["wgn/gfx-backend-gl"] [dependencies] #TODO: only depend on the published version -wgn = { package = "wgpu-native", version = "0.2.6", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "f72dfc9cbbcf752ea5905ff9b038f8ca3f1d3691"} +wgn = { package = "wgpu-native", version = "0.2.6", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "cf1bee30d6406d6393220736efdf91b5e429e0ca"} arrayvec = "0.4" zerocopy = "0.2" diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs index 78f2dfed2d..dfce63ee19 100644 --- a/wgpu/examples/framework.rs +++ b/wgpu/examples/framework.rs @@ -24,23 +24,13 @@ pub enum ShaderStage { } pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec { - use std::io::Read; - let ty = match stage { ShaderStage::Vertex => glsl_to_spirv::ShaderType::Vertex, ShaderStage::Fragment => glsl_to_spirv::ShaderType::Fragment, ShaderStage::Compute => glsl_to_spirv::ShaderType::Compute, }; - let mut output = glsl_to_spirv::compile(&code, ty).unwrap(); - let mut spv_bytes = Vec::new(); - output.read_to_end(&mut spv_bytes).unwrap(); - - let mut spv_words = Vec::new(); - for bytes4 in spv_bytes.chunks(4) { - spv_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); - } - spv_words + wgpu::read_spirv(glsl_to_spirv::compile(&code, ty).unwrap()).unwrap() } pub trait Example { diff --git a/wgpu/examples/hello-compute/main.rs b/wgpu/examples/hello-compute/main.rs index 733b276aa8..2d092aa031 100644 --- a/wgpu/examples/hello-compute/main.rs +++ b/wgpu/examples/hello-compute/main.rs @@ -25,12 +25,8 @@ fn main() { limits: wgpu::Limits::default(), }); - let cs_bytes = include_bytes!("shader.comp.spv"); - let mut cs_words = vec!(); - for bytes4 in cs_bytes.chunks(4) { - cs_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); - } - let cs_module = device.create_shader_module(&cs_words); + let cs = include_bytes!("shader.comp.spv"); + let cs_module = device.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&cs[..])).unwrap()); let staging_buffer = device .create_buffer_mapped( diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs index 328f02ef99..1840ca4581 100644 --- a/wgpu/examples/hello-triangle/main.rs +++ b/wgpu/examples/hello-triangle/main.rs @@ -60,19 +60,11 @@ fn main() { limits: wgpu::Limits::default(), }); - let vs_bytes = include_bytes!("shader.vert.spv"); - let mut vs_words = vec!(); - for bytes4 in vs_bytes.chunks(4) { - vs_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); - } - let vs_module = device.create_shader_module(&vs_words); + let vs = include_bytes!("shader.vert.spv"); + let vs_module = device.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&vs[..])).unwrap()); - let fs_bytes = include_bytes!("shader.frag.spv"); - let mut fs_words = vec!(); - for bytes4 in fs_bytes.chunks(4) { - fs_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); - } - let fs_module = device.create_shader_module(&fs_words); + let fs = include_bytes!("shader.frag.spv"); + let fs_module = device.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&fs[..])).unwrap()); let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { bindings: &[] }); diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index fdf848f526..54b8344b97 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -61,6 +61,7 @@ pub use wgn::{ TextureViewDimension, VertexAttributeDescriptor, VertexFormat, + read_spirv, }; #[cfg(feature = "gl")] diff --git a/wgpu/tests/multithreaded_compute.rs b/wgpu/tests/multithreaded_compute.rs index b28d1d2f16..bb430843e2 100644 --- a/wgpu/tests/multithreaded_compute.rs +++ b/wgpu/tests/multithreaded_compute.rs @@ -26,12 +26,8 @@ fn multithreaded_compute() { limits: wgpu::Limits::default(), }); - let cs_bytes = include_bytes!("../examples/hello-compute/shader.comp.spv"); - let mut cs_words = vec!(); - for bytes4 in cs_bytes.chunks(4) { - cs_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); - } - let cs_module = device.create_shader_module(&cs_words); + let cs = include_bytes!("../examples/hello-compute/shader.comp.spv"); + let cs_module = device.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&cs[..])).unwrap()); let staging_buffer = device .create_buffer_mapped(