Merge branch 'main' into flycam-rewrite

This commit is contained in:
mars 2022-03-18 05:20:09 +00:00
commit 15bca6a6ca
6 changed files with 76 additions and 1 deletions

View File

@ -0,0 +1,20 @@
use cyborg::shader::{parse_wgsl, generate_wgsl, add_includes};
use cyborg::logger::Timer;
fn main() {
let comp_timer = Timer::start("Shader compilation");
// Generate a shader and preprocess it
let mut source = std::fs::read_to_string("src/shader.wgsl").unwrap();
source = add_includes(&source);
// Parse the WGSL into a usable module
let module = parse_wgsl(&source);
// Generate a valid WGSL string from the module
let gen_wgsl = generate_wgsl(&module);
println!("Generated WGSL:\n\n{}", gen_wgsl);
comp_timer.print_status();
}

View File

@ -0,0 +1,16 @@
use std::fs::read_to_string;
use cyborg::shader::{parse_wgsl, generate_wgsl, add_includes};
fn main() {
// Generate a shader and preprocess it
let mut source = read_to_string("src/shader.wgsl").unwrap();
source = add_includes(&source);
// Parse the WGSL into a usable module
let module = parse_wgsl(&source);
// Generate a valid WGSL string from the module
let gen_wgsl = generate_wgsl(&module);
println!("{:?}", module);
}

2
src/lib.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod logger;
pub mod shader;

19
src/logger.rs Normal file
View File

@ -0,0 +1,19 @@
use std::time::{Instant};
pub struct Timer<'a> {
name: &'a str,
start_time: Instant
}
impl<'a> Timer<'a> {
pub fn start(name: &'a str) -> Timer {
Timer {
name: name,
start_time: Instant::now()
}
}
pub fn print_status(&self) {
println!("{}: {}ms", self.name, Instant::now().duration_since(self.start_time).as_nanos() as f32 / 1_000_000.0)
}
}

View File

@ -7,7 +7,7 @@ use super::shader::{parse_wgsl, generate_wgsl, add_includes};
use crate::handle::*;
use crate::model::OnLoad;
use wgpu::util::DeviceExt;
use std::fs::{File, read_to_string};
use std::fs::read_to_string;
pub struct Renderer {
pub device: wgpu::Device,

View File

@ -67,4 +67,22 @@ pub fn add_includes(source: &String) -> String {
}
combined
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn preprocess_file() {
// Generate a shader and preprocess it
let mut source = read_to_string("src/shader.wgsl").unwrap();
source = add_includes(&source);
// Parse the WGSL into a usable module
let module = parse_wgsl(&source);
// Generate a valid WGSL string from the module
let gen_wgsl = generate_wgsl(&module);
}
}