1
0
Fork 0

Parralelize buildtime shader loading

This commit is contained in:
Adrian Hedqvist 2020-11-28 15:20:19 +01:00
parent 10a19247f7
commit 1e2b1ba81e
4 changed files with 8 additions and 15 deletions

1
Cargo.lock generated
View file

@ -2130,6 +2130,7 @@ dependencies = [
"imgui-wgpu",
"imgui-winit-support",
"log",
"rayon",
"shaderc",
"tobj",
"wgpu",

View file

@ -26,3 +26,4 @@ shaderc = "0.7"
fs_extra = "1"
anyhow = "1"
glob = "0.3"
rayon = "1"

View file

@ -6,6 +6,7 @@ use std::{
env,
fs::{read_to_string, write},
};
use rayon::prelude::*;
struct ShaderData {
src: String,
@ -41,15 +42,13 @@ impl ShaderData {
}
fn main() -> Result<()> {
let mut shader_paths = [
glob("./src/**/*.vert")?,
glob("./src/**/*.frag")?,
glob("./src/**/*.comp")?,
];
let mut shader_paths = Vec::new();
shader_paths.extend(glob("./src/**/*.vert")?);
shader_paths.extend(glob("./src/**/*.frag")?);
shader_paths.extend(glob("./src/**/*.comp")?);
let shaders: Result<Vec<_>> = shader_paths
.iter_mut()
.flatten()
.into_par_iter()
.map(|glob_result| ShaderData::load(glob_result?))
.collect();

View file

@ -5,14 +5,6 @@ use winit::{dpi::PhysicalPosition, event::*, event_loop::{ControlFlow, EventLoop
use cgmath::prelude::*;
#[rustfmt::skip]
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.0, 0.0, 0.5, 1.0,
);
mod camera;
mod light;
mod model;