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-wgpu",
"imgui-winit-support", "imgui-winit-support",
"log", "log",
"rayon",
"shaderc", "shaderc",
"tobj", "tobj",
"wgpu", "wgpu",

View file

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

View file

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

View file

@ -5,14 +5,6 @@ use winit::{dpi::PhysicalPosition, event::*, event_loop::{ControlFlow, EventLoop
use cgmath::prelude::*; 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 camera;
mod light; mod light;
mod model; mod model;