hacked in the ability to specify compiler options

master
mitchellhansen 5 years ago
parent afd4e39c44
commit baf9c022ef

@ -8,10 +8,17 @@ use std::path::{Path, PathBuf};
pub fn compile<T>(path: T, shader_kind: ShaderKind) -> Result<Vec<u32>, CompileError>
where
T: AsRef<Path>,
{
let mut options = CompileOptions::new().ok_or(CompileError::CreateCompiler)?;
compile_with_options(path, shader_kind, options)
}
pub fn compile_with_options<T>(path: T, shader_kind: ShaderKind, mut options: CompileOptions) -> Result<Vec<u32>, CompileError>
where
T: AsRef<Path>,
{
// 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)?;

@ -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<T>(vertex: T, fragment: T) -> Result<CompiledShaders, Error>
where
T: AsRef<Path>,
{
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<T>(compute: T) -> Result<CompiledShaders, Error>
where
T: AsRef<Path>,
{
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<T>(compute: T, options: CompileOptions) -> Result<CompiledShaders, Error>
where
T: AsRef<Path>,
{
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<Entry, Error> {

Loading…
Cancel
Save