61: Cleanup examples by using wgpu::read_spirv instead of manually creating a Vec<u32> r=kvark a=rukai

Wait for me to update the git reference once https://github.com/gfx-rs/wgpu/pull/280 is merged.

Co-authored-by: Rukai <rubickent@gmail.com>
This commit is contained in:
bors[bot]
2019-08-12 20:57:53 +00:00
6 changed files with 11 additions and 36 deletions

View File

@@ -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"

View File

@@ -24,23 +24,13 @@ pub enum ShaderStage {
}
pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec<u32> {
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 {

View File

@@ -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(

View File

@@ -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: &[] });

View File

@@ -61,6 +61,7 @@ pub use wgn::{
TextureViewDimension,
VertexAttributeDescriptor,
VertexFormat,
read_spirv,
};
#[cfg(feature = "gl")]

View File

@@ -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(