1
0
mirror of synced 2025-11-09 12:57:13 +00:00

hacked in the ability to specify compiler options

This commit is contained in:
2019-07-07 00:58:13 -07:00
parent afd4e39c44
commit baf9c022ef
2 changed files with 31 additions and 4 deletions

View File

@@ -8,10 +8,17 @@ use std::path::{Path, PathBuf};
pub fn compile<T>(path: T, shader_kind: ShaderKind) -> Result<Vec<u32>, CompileError> pub fn compile<T>(path: T, shader_kind: ShaderKind) -> Result<Vec<u32>, CompileError>
where where
T: AsRef<Path>, 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. // TODO Probably shouldn't create this every time.
let mut compiler = shaderc::Compiler::new().ok_or(CompileError::CreateCompiler)?; 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 f = File::open(&path).map_err(CompileError::Open)?;
let mut src = String::new(); let mut src = String::new();
f.read_to_string(&mut src).map_err(CompileError::Open)?; f.read_to_string(&mut src).map_err(CompileError::Open)?;

View File

@@ -10,6 +10,7 @@ pub use reflection::LayoutData;
pub use watch::{Message, Watch}; pub use watch::{Message, Watch};
pub use error::*; pub use error::*;
use shaderc::CompileOptions;
use spirv_reflect as sr; use spirv_reflect as sr;
use vulkano as vk; use vulkano as vk;
use std::path::Path; use std::path::Path;
@@ -26,9 +27,16 @@ pub fn load<T>(vertex: T, fragment: T) -> Result<CompiledShaders, Error>
where where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap();
let vertex = compiler::compile(vertex, ShaderKind::Vertex).map_err(Error::Compile)?; let vertex = compiler::compile(vertex, ShaderKind::Vertex).map_err(Error::Compile)?;
let fragment = compiler::compile(fragment, ShaderKind::Fragment).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 // 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 where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let compute = compiler::compile(compute, ShaderKind::Compute).map_err(Error::Compile)?; let options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap();
Ok(CompiledShaders{ vertex: Vec::new(), fragment: Vec::new(), compute }) 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> { pub fn parse_compute(code: &CompiledShaders) -> Result<Entry, Error> {