Compare commits
3 Commits
24bcc55e74
...
dcaba617e1
Author | SHA1 | Date |
---|---|---|
turtle1331 | dcaba617e1 | |
Skye Terran | f88e3e7158 | |
Skye Terran | 0b9a68c906 |
|
@ -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::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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue