pull/112/head
Ben Hansen 4 years ago
parent 8e9ff17565
commit 6f29ba738b

5
.gitignore vendored

@ -4,4 +4,7 @@ target/
/image.png
/output*.*
output/
output/
/trace
trace.zip

@ -37,9 +37,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -54,7 +51,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -63,7 +60,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -37,9 +37,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -54,7 +51,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -63,7 +60,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -37,9 +37,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -54,7 +51,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -63,7 +60,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -37,9 +37,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -54,7 +51,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -63,7 +60,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -37,9 +37,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -54,7 +51,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -63,7 +60,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -37,9 +37,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -54,7 +51,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -63,7 +60,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -40,9 +40,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -57,7 +54,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -66,7 +63,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -40,9 +40,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -57,7 +54,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -66,7 +63,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -40,9 +40,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -57,7 +54,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -66,7 +63,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -40,9 +40,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -57,7 +54,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -66,7 +63,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -41,9 +41,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
// UDPATED!
let mut shader_paths = Vec::new();
@ -58,7 +55,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -67,7 +64,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -40,9 +40,6 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -57,7 +54,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -66,7 +63,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -1,4 +1,4 @@
use failure::bail;
use anyhow::*;
use fs_extra::copy_items;
use fs_extra::dir::CopyOptions;
use glob::glob;
@ -6,64 +6,6 @@ use std::env;
use std::fs::{read_to_string, write};
use std::path::PathBuf;
fn main() {
copy_res();
compile_shaders();
}
fn copy_res() {
// This tells cargo to rerun this script if something in /res/ changes.
println!("cargo:rerun-if-changed=res/*");
let out_dir = env::var("OUT_DIR").unwrap();
let mut copy_options = CopyOptions::new();
copy_options.overwrite = true;
let mut paths_to_copy = Vec::new();
paths_to_copy.push("res/");
copy_items(&paths_to_copy, out_dir, &copy_options).unwrap();
}
fn compile_shaders() {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert").unwrap(),
glob("./src/**/*.frag").unwrap(),
glob("./src/**/*.comp").unwrap(),
];
// This could be parallelized
let shaders = shader_paths
.iter_mut()
.flatten()
.map(|glob_result| ShaderData::load(glob_result.unwrap()).unwrap())
.collect::<Vec<ShaderData>>();
let mut compiler = shaderc::Compiler::new().unwrap();
// This can't be parallelized. The [shaderc::Compiler] is not
// thread safe. Also, it creates a lot of resources. You could
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders {
let compiled = compiler
.compile_into_spirv(
&shader.src,
shader.kind,
&shader.src_path.to_str().unwrap(),
"main",
None,
)
.unwrap();
write(shader.spv_path, compiled.as_binary_u8()).unwrap();
}
// panic!("Debugging...");
}
struct ShaderData {
src: String,
src_path: PathBuf,
@ -72,8 +14,12 @@ struct ShaderData {
}
impl ShaderData {
pub fn load(src_path: PathBuf) -> Result<Self, failure::Error> {
let extension = src_path.extension().unwrap().to_str().unwrap();
pub fn load(src_path: PathBuf) -> Result<Self> {
let extension = src_path
.extension()
.context("File has no extension")?
.to_str()
.context("Extension cannot be converted to &str")?;
let kind = match extension {
"vert" => shaderc::ShaderKind::Vertex,
"frag" => shaderc::ShaderKind::Fragment,
@ -92,3 +38,57 @@ impl ShaderData {
})
}
}
fn main() -> Result<()> {
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
glob("./src/**/*.frag")?,
glob("./src/**/*.comp")?,
];
// This could be parallelized
let shaders = shader_paths
.iter_mut()
.flatten()
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
// This can't be parallelized. The [shaderc::Compiler] is not
// thread safe. Also, it creates a lot of resources. You could
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,
&shader.src_path.to_str().unwrap(),
"main",
None,
)?;
write(shader.spv_path, compiled.as_binary_u8())?;
}
// This tells cargo to rerun this script if something in /res/ changes.
println!("cargo:rerun-if-changed=res/*");
let out_dir = env::var("OUT_DIR")?;
let mut copy_options = CopyOptions::new();
copy_options.overwrite = true;
let mut paths_to_copy = Vec::new();
paths_to_copy.push("res/");
match copy_items(&paths_to_copy, out_dir, &copy_options) {
Ok(_) => {}
Err(e) => eprintln!("{}", e),
}
Ok(())
}

@ -40,14 +40,11 @@ impl ShaderData {
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=res/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./res/**/*.vert")?,
glob("./res/**/*.frag")?,
glob("./res/**/*.comp")?,
glob("./src/**/*.vert")?,
glob("./src/**/*.frag")?,
glob("./src/**/*.comp")?,
];
// This could be parallelized
@ -57,7 +54,7 @@ fn main() -> Result<()> {
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
@ -66,7 +63,10 @@ fn main() -> Result<()> {
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,

@ -1,3 +1,4 @@
use crate::any;
use crate::input;
use crate::state::{self, GameState};
use crate::util;

@ -1 +1 @@
Subproject commit d764e13f7b3afe4455cb376ae3eb562c001c6752
Subproject commit e3e8e4c1672e2b7691b907f0ac89021341d81021

@ -295,10 +295,10 @@ We've removed shaderc from our dependencies and added a new `[build-depencies]`
Now we can put some code in our `build.rs`.
```rust
use glob::glob;
use anyhow::*;
use glob::glob;
use std::fs::{read_to_string, write};
use std::path::{PathBuf};
use std::path::PathBuf;
struct ShaderData {
src: String,
@ -309,7 +309,8 @@ struct ShaderData {
impl ShaderData {
pub fn load(src_path: PathBuf) -> Result<Self> {
let extension = src_path.extension()
let extension = src_path
.extension()
.context("File has no extension")?
.to_str()
.context("Extension cannot be converted to &str")?;
@ -323,14 +324,16 @@ impl ShaderData {
let src = read_to_string(src_path.clone())?;
let spv_path = src_path.with_extension(format!("{}.spv", extension));
Ok(Self { src, src_path, spv_path, kind })
Ok(Self {
src,
src_path,
spv_path,
kind,
})
}
}
fn main() -> Result<()> {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");
// Collect all shaders recursively within /src/
let mut shader_paths = [
glob("./src/**/*.vert")?,
@ -339,30 +342,31 @@ fn main() -> Result<()> {
];
// This could be parallelized
let shaders = shader_paths.iter_mut()
let shaders = shader_paths
.iter_mut()
.flatten()
.map(|glob_result| {
ShaderData::load(glob_result?)
})
.map(|glob_result| ShaderData::load(glob_result?))
.collect::<Vec<Result<_>>>()
.into_iter()
.collect::<Result<Vec<_>>>();
.collect::<Result<Vec<_>>>()?;
let mut compiler = shaderc::Compiler::new()
.context("Unable to create shader compiler")?;
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?;
// This can't be parallelized. The [shaderc::Compiler] is not
// thread safe. Also, it creates a lot of resources. You could
// spawn multiple processes to handle this, but it would probably
// be better just to only compile shaders that have been changed
// recently.
for shader in shaders? {
for shader in shaders {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed={:?}", shader.src_path);
let compiled = compiler.compile_into_spirv(
&shader.src,
shader.kind,
&shader.src_path.to_str().unwrap(),
"main",
None
None,
)?;
write(shader.spv_path, compiled.as_binary_u8())?;
}

Loading…
Cancel
Save