Merge branch 'main' into flycam-rewrite
This commit is contained in:
commit
dcaba617e1
|
@ -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();
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod logger;
|
||||||
|
pub mod shader;
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ use super::shader::{parse_wgsl, generate_wgsl, add_includes};
|
||||||
use crate::handle::*;
|
use crate::handle::*;
|
||||||
use crate::model::OnLoad;
|
use crate::model::OnLoad;
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
use std::fs::{File, read_to_string};
|
use std::fs::read_to_string;
|
||||||
|
|
||||||
pub struct Renderer {
|
pub struct Renderer {
|
||||||
pub device: wgpu::Device,
|
pub device: wgpu::Device,
|
||||||
|
|
|
@ -67,4 +67,22 @@ pub fn add_includes(source: &String) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
combined
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue