diff --git a/src/compiler.rs b/src/compiler.rs index a7829ba..22ad593 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -8,10 +8,17 @@ use std::path::{Path, PathBuf}; pub fn compile(path: T, shader_kind: ShaderKind) -> Result, CompileError> where T: AsRef, +{ + let mut options = CompileOptions::new().ok_or(CompileError::CreateCompiler)?; + compile_with_options(path, shader_kind, options) +} + +pub fn compile_with_options(path: T, shader_kind: ShaderKind, mut options: CompileOptions) -> Result, CompileError> + where + T: AsRef, { // TODO Probably shouldn't create this every time. let mut compiler = shaderc::Compiler::new().ok_or(CompileError::CreateCompiler)?; - let mut options = CompileOptions::new().ok_or(CompileError::CreateCompiler)?; let mut f = File::open(&path).map_err(CompileError::Open)?; let mut src = String::new(); f.read_to_string(&mut src).map_err(CompileError::Open)?; diff --git a/src/lib.rs b/src/lib.rs index 8de337e..9f075b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ pub use reflection::LayoutData; pub use watch::{Message, Watch}; pub use error::*; +use shaderc::CompileOptions; use spirv_reflect as sr; use vulkano as vk; use std::path::Path; @@ -26,9 +27,16 @@ pub fn load(vertex: T, fragment: T) -> Result where T: AsRef, { + let options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(); + let vertex = compiler::compile(vertex, ShaderKind::Vertex).map_err(Error::Compile)?; let fragment = compiler::compile(fragment, ShaderKind::Fragment).map_err(Error::Compile)?; - Ok(CompiledShaders{ vertex, fragment, compute: Vec::new() }) + + Ok(CompiledShaders{ + vertex, + fragment, + compute: Vec::new(), + }) } // TODO this should be incorpoarted into load but that would be @@ -37,8 +45,20 @@ pub fn load_compute(compute: T) -> Result where T: AsRef, { - let compute = compiler::compile(compute, ShaderKind::Compute).map_err(Error::Compile)?; - Ok(CompiledShaders{ vertex: Vec::new(), fragment: Vec::new(), compute }) + let options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(); + load_compute_with_options(compute, options) +} + +pub fn load_compute_with_options(compute: T, options: CompileOptions) -> Result + where + T: AsRef, +{ + let compute = compiler::compile_with_options(compute, ShaderKind::Compute, options).map_err(Error::Compile)?; + Ok(CompiledShaders{ + vertex: Vec::new(), + fragment: Vec::new(), + compute, + }) } pub fn parse_compute(code: &CompiledShaders) -> Result {