hacked out some stuff while I'm testing

master
mitchellhansen 5 years ago
parent d1c3a5f562
commit 903f1a349d

@ -2,12 +2,13 @@ use shade_runner as sr;
use std::path::PathBuf; use std::path::PathBuf;
fn main() { fn main() {
let project_root = std::env::current_dir().expect("failed to get root directory");
let mut vert_path = project_root.clone(); // let project_root = std::env::current_dir().expect("failed to get root directory");
vert_path.push(PathBuf::from("examples/shaders/vert.glsl")); // let mut vert_path = project_root.clone();
let mut frag_path = project_root.clone(); // vert_path.push(PathBuf::from("examples/shaders/vert.glsl"));
frag_path.push(PathBuf::from("examples/shaders/frag.glsl")); // let mut frag_path = project_root.clone();
let shader = sr::load(vert_path, frag_path).expect("Failed to compile"); // frag_path.push(PathBuf::from("examples/shaders/frag.glsl"));
let vulkano_entry = sr::parse(&shader).expect("failed to parse"); // let shader = sr::load(vert_path, frag_path).expect("Failed to compile");
dbg!(vulkano_entry); // let vulkano_entry = sr::parse(&shader).expect("failed to parse");
// dbg!(vulkano_entry);
} }

@ -7,51 +7,46 @@ use crate::reflection::LayoutData;
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct Entry { pub struct Entry {
pub frag_input: FragInput, pub input: Option<Input>,
pub frag_output: FragOutput, pub output: Option<Output>,
pub frag_layout: FragLayout, pub layout: Layout,
pub vert_input: VertInput,
pub vert_output: VertOutput,
pub vert_layout: VertLayout,
pub compute_layout: ComputeLayout,
} }
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct FragInput { pub struct Input {
pub inputs: Vec<ShaderInterfaceDefEntry>, pub inputs: Vec<ShaderInterfaceDefEntry>,
} }
unsafe impl ShaderInterfaceDef for FragInput { unsafe impl ShaderInterfaceDef for Input {
type Iter = FragInputIter; type Iter = InputIter;
fn elements(&self) -> FragInputIter { fn elements(&self) -> InputIter {
self.inputs.clone().into_iter() self.inputs.clone().into_iter()
} }
} }
pub type FragInputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>; pub type InputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>;
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct FragOutput { pub struct Output {
pub outputs: Vec<ShaderInterfaceDefEntry>, pub outputs: Vec<ShaderInterfaceDefEntry>,
} }
unsafe impl ShaderInterfaceDef for FragOutput { unsafe impl ShaderInterfaceDef for Output {
type Iter = FragOutputIter; type Iter = OutputIter;
fn elements(&self) -> FragOutputIter { fn elements(&self) -> OutputIter {
self.outputs.clone().into_iter() self.outputs.clone().into_iter()
} }
} }
pub type FragOutputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>; pub type OutputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>;
// Layout same as with vertex shader.
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct FragLayout { pub struct Layout {
pub layout_data: LayoutData, pub layout_data: LayoutData,
} }
impl FragLayout { impl Layout {
const STAGES: ShaderStages = ShaderStages { const STAGES: ShaderStages = ShaderStages {
vertex: false, vertex: false,
tessellation_control: false, tessellation_control: false,
@ -61,130 +56,8 @@ impl FragLayout {
compute: false, compute: false,
}; };
} }
unsafe impl PipelineLayoutDesc for FragLayout {
fn num_sets(&self) -> usize {
self.layout_data.num_sets
}
fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
self.layout_data.num_bindings.get(&set).map(|&b|b)
}
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
self.layout_data.descriptions.get(&set)
.and_then(|s|s.get(&binding))
.map(|desc| {
let mut desc = desc.clone();
desc.stages = FragLayout::STAGES;
desc
})
}
fn num_push_constants_ranges(&self) -> usize {
self.layout_data.num_constants
}
fn push_constants_range(&self, num: usize) -> Option<PipelineLayoutDescPcRange> {
self.layout_data.pc_ranges.get(num)
.map(|desc| {
let mut desc = *desc;
desc.stages = FragLayout::STAGES;
desc
})
}
}
#[derive(Debug, Clone, Default)]
pub struct VertInput {
pub inputs: Vec<ShaderInterfaceDefEntry>,
}
unsafe impl ShaderInterfaceDef for VertInput {
type Iter = VertInputIter;
fn elements(&self) -> VertInputIter {
self.inputs.clone().into_iter()
}
}
pub type VertInputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>;
#[derive(Debug, Clone, Default)]
pub struct VertOutput {
pub outputs: Vec<ShaderInterfaceDefEntry>,
}
unsafe impl ShaderInterfaceDef for VertOutput {
type Iter = VertOutputIter;
fn elements(&self) -> VertOutputIter {
self.outputs.clone().into_iter()
}
}
pub type VertOutputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>;
// This structure describes layout of this stage.
#[derive(Debug, Clone, Default)]
pub struct VertLayout {
pub layout_data: LayoutData,
}
impl VertLayout {
const STAGES: ShaderStages = ShaderStages {
vertex: true,
tessellation_control: false,
tessellation_evaluation: false,
geometry: false,
fragment: false,
compute: false,
};
}
unsafe impl PipelineLayoutDesc for VertLayout {
fn num_sets(&self) -> usize {
self.layout_data.num_sets
}
fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
self.layout_data.num_bindings.get(&set).map(|&b|b)
}
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
self.layout_data.descriptions.get(&set)
.and_then(|s|s.get(&binding))
.map(|desc| {
let mut desc = desc.clone();
desc.stages = VertLayout::STAGES;
desc
})
}
fn num_push_constants_ranges(&self) -> usize {
self.layout_data.num_constants
}
fn push_constants_range(&self, num: usize) -> Option<PipelineLayoutDescPcRange> {
self.layout_data.pc_ranges.get(num)
.map(|desc| {
let mut desc = *desc;
desc.stages = VertLayout::STAGES;
desc
})
}
}
#[derive(Debug, Clone, Default)]
pub struct ComputeLayout {
pub layout_data: LayoutData,
}
impl ComputeLayout {
const STAGES: ShaderStages = ShaderStages {
vertex: false,
tessellation_control: false,
tessellation_evaluation: false,
geometry: false,
fragment: false,
compute: true,
};
}
unsafe impl PipelineLayoutDesc for ComputeLayout { unsafe impl PipelineLayoutDesc for Layout {
fn num_sets(&self) -> usize { fn num_sets(&self) -> usize {
self.layout_data.num_sets self.layout_data.num_sets
} }
@ -196,7 +69,7 @@ unsafe impl PipelineLayoutDesc for ComputeLayout {
.and_then(|s|s.get(&binding)) .and_then(|s|s.get(&binding))
.map(|desc| { .map(|desc| {
let mut desc = desc.clone(); let mut desc = desc.clone();
desc.stages = Self::STAGES; desc.stages = Layout::STAGES;
desc desc
}) })
@ -208,7 +81,7 @@ unsafe impl PipelineLayoutDesc for ComputeLayout {
self.layout_data.pc_ranges.get(num) self.layout_data.pc_ranges.get(num)
.map(|desc| { .map(|desc| {
let mut desc = *desc; let mut desc = *desc;
desc.stages = Self::STAGES; desc.stages = Layout::STAGES;
desc desc
}) })

@ -28,13 +28,21 @@ pub struct CompiledShader {
pub spriv: Vec<u32>, pub spriv: Vec<u32>,
} }
pub fn load<T>(input: T, shader_kind: ShaderKind) -> Result<CompiledShader, Error>
where
T: AsRef<Path>,
{
Ok(CompiledShader { spriv: compiler::compile(input, shader_kind).map_err(Error::Compile)? })
}
/// Loads and compiles the vertex shader /// Loads and compiles the vertex shader
pub fn load_vertex<T>(vertex: T) -> Result<CompiledShader, Error> pub fn load_vertex<T>(vertex: T) -> Result<CompiledShader, Error>
where where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let vertex = compiler::compile(vertex, ShaderKind::Vertex).map_err(Error::Compile)?; let vertex = compiler::compile(vertex, ShaderKind::Vertex).map_err(Error::Compile)?;
Ok(CompiledShader{ spriv: vertex }) Ok(CompiledShader { spriv: vertex })
} }
/// Loads and compiles the fragment shader /// Loads and compiles the fragment shader
@ -42,8 +50,8 @@ pub fn load_fragment<T>(fragment: T) -> Result<CompiledShader, Error>
where where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let fragment = compiler::compile(vertex, ShaderKind::Fragment).map_err(Error::Compile)?; let fragment = compiler::compile(fragment, ShaderKind::Fragment).map_err(Error::Compile)?;
Ok(CompiledShader{ spriv: fragment }) Ok(CompiledShader { spriv: fragment })
} }
/// Loads and compiles the geometry shader /// Loads and compiles the geometry shader
@ -51,55 +59,51 @@ pub fn load_geometry<T>(geometry: T) -> Result<CompiledShader, Error>
where where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let geometry = compiler::compile(vertex, ShaderKind::Geometry).map_err(Error::Compile)?; let geometry = compiler::compile(geometry, ShaderKind::Geometry).map_err(Error::Compile)?;
Ok(CompiledShader{ spriv: geometry }) Ok(CompiledShader { spriv: geometry })
} }
/// Loads and compiles the tessellation shader /// Loads and compiles the tessellation shader
pub fn load_tessellation_control<T>(geometry: T) -> Result<CompiledShader, Error> pub fn load_tessellation_control<T>(tessellation_control: T) -> Result<CompiledShader, Error>
where where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let tess = compiler::compile(vertex, ShaderKind::TessControl).map_err(Error::Compile)?; let tess = compiler::compile(tessellation_control, ShaderKind::TessControl).map_err(Error::Compile)?;
Ok(CompiledShader{ spriv: tess }) Ok(CompiledShader { spriv: tess })
} }
/// Loads and compiles the tessellation shader /// Loads and compiles the tessellation shader
pub fn load_tessellation_evaluation<T>(geometry: T) -> Result<CompiledShader, Error> pub fn load_tessellation_evaluation<T>(tessellation_evaluation: T) -> Result<CompiledShader, Error>
where where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let tess = compiler::compile(vertex, ShaderKind::TessEvaluation).map_err(Error::Compile)?; let tess = compiler::compile(tessellation_evaluation, ShaderKind::TessEvaluation).map_err(Error::Compile)?;
Ok(CompiledShader{ spriv: tess }) Ok(CompiledShader { spriv: tess })
} }
// TODO this should be incorpoarted into load but that would be pub fn load_compute<T>(compute: T) -> Result<CompiledShader, Error>
// a breaking change. Do this in next major version where
pub fn load_compute<T>(compute: T) -> Result<CompiledShaders, Error>
where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(); let options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap();
load_compute_with_options(compute, options) load_compute_with_options(compute, options)
} }
pub fn load_compute_with_options<T>(compute: T, options: CompileOptions) -> Result<CompiledShaders, Error> pub fn load_compute_with_options<T>(compute: T, options: CompileOptions) -> Result<CompiledShader, Error>
where where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let compute = compiler::compile_with_options(compute, ShaderKind::Compute, options).map_err(Error::Compile)?; let compute = compiler::compile_with_options(compute, ShaderKind::Compute, options).map_err(Error::Compile)?;
Ok(CompiledShaders{ Ok(CompiledShader {
vertex: Vec::new(), spriv: compute,
fragment: Vec::new(),
compute,
}) })
} }
pub fn parse_compute(code: &CompiledShaders) -> Result<Entry, Error> { pub fn parse_compute(code: &CompiledShader) -> Result<Entry, Error> {
reflection::create_compute_entry(code) reflection::create_compute_entry(&code.spriv)
} }
/// Parses the shaders and gives an entry point /// Parses the shaders and gives an entry point
pub fn parse(code: &CompiledShaders) -> Result<Entry, Error> { pub fn parse(code: &CompiledShader) -> Result<Entry, Error> {
reflection::create_entry(code) reflection::create_entry(&code.spriv)
} }

@ -1,6 +1,6 @@
use crate::error::Error; use crate::error::Error;
use crate::layouts::*; use crate::layouts::*;
use crate::sr; use crate::{sr, CompiledShader};
use crate::srvk::{DescriptorDescInfo, SpirvTy}; use crate::srvk::{DescriptorDescInfo, SpirvTy};
use crate::vk::descriptor::descriptor::*; use crate::vk::descriptor::descriptor::*;
use crate::vk::descriptor::pipeline_layout::PipelineLayoutDescPcRange; use crate::vk::descriptor::pipeline_layout::PipelineLayoutDescPcRange;
@ -24,46 +24,40 @@ pub struct LayoutData {
pub pc_ranges: Vec<PipelineLayoutDescPcRange>, pub pc_ranges: Vec<PipelineLayoutDescPcRange>,
} }
pub fn create_entry(shaders: &CompiledShaders) -> Result<Entry, Error> { pub fn create_entry(spirv: &Vec<u32>) -> Result<Entry, Error> {
let vertex_interfaces = create_interfaces(&shaders.vertex)?;
let vertex_layout = create_layouts(&shaders.vertex)?;
let fragment_interfaces = create_interfaces(&shaders.fragment)?;
let fragment_layout = create_layouts(&shaders.fragment)?;
let frag_input = FragInput { let vertex_interfaces = create_interfaces(spirv)?;
inputs: fragment_interfaces.inputs, let vertex_layout = create_layouts(spirv)?;
};
let frag_output = FragOutput { let input = Some(Input {
outputs: fragment_interfaces.outputs,
};
let frag_layout = FragLayout {
layout_data: fragment_layout,
};
let vert_input = VertInput {
inputs: vertex_interfaces.inputs, inputs: vertex_interfaces.inputs,
}; });
let vert_output = VertOutput { let output = Some(Output {
outputs: vertex_interfaces.outputs, outputs: vertex_interfaces.outputs,
}; });
let vert_layout = VertLayout { let layout = Layout {
layout_data: vertex_layout, layout_data: vertex_layout,
}; };
Ok(Entry { Ok(Entry {
frag_input, input,
frag_output, output,
vert_input, layout,
vert_output,
frag_layout,
vert_layout,
compute_layout: Default::default(),
}) })
} }
pub fn create_compute_entry(shaders: &CompiledShaders) -> Result<Entry, Error> { pub fn create_compute_entry(spirv: &Vec<u32>) -> Result<Entry, Error> {
create_layouts(&shaders.compute).map(|layout_data| {
let mut entry = Entry::default(); let compute_layout = create_layouts(spirv)?;
entry.compute_layout = ComputeLayout{ layout_data };
entry let layout = Layout {
layout_data: compute_layout,
};
Ok(Entry {
input: None,
output: None,
layout,
}) })
} }

@ -90,14 +90,14 @@ impl GraphicsLoader {
} }
fn reload(&self) { fn reload(&self) {
match crate::load(&self.vertex, &self.fragment) { // match crate::load(&self.vertex, &self.fragment) {
Ok(shaders) => { // Ok(shaders) => {
let entry = crate::parse(&shaders); // let entry = crate::parse(&shaders);
let msg = entry.map(|entry| Message { shaders, entry }); // let msg = entry.map(|entry| Message { shaders, entry });
self.tx.send(msg).ok() // self.tx.send(msg).ok()
} // }
Err(e) => self.tx.send(Err(e)).ok(), // Err(e) => self.tx.send(Err(e)).ok(),
}; // };
} }
} }
@ -113,14 +113,14 @@ impl ComputeLoader {
} }
fn reload(&self) { fn reload(&self) {
match crate::load_compute(&self.compute) { // match crate::load_compute(&self.compute) {
Ok(shaders) => { // Ok(shaders) => {
let entry = crate::parse_compute(&shaders); // let entry = crate::parse_compute(&shaders);
let msg = entry.map(|entry| Message { shaders, entry }); // let msg = entry.map(|entry| Message { shaders, entry });
self.tx.send(msg).ok() // self.tx.send(msg).ok()
} // }
Err(e) => self.tx.send(Err(e)).ok(), // Err(e) => self.tx.send(Err(e)).ok(),
}; // };
} }
} }

@ -1,345 +1,345 @@
use color_backtrace; //use color_backtrace;
use difference::{Changeset, Difference}; //use difference::{Changeset, Difference};
use shade_runner::*; //use shade_runner::*;
use std::borrow::Cow; //use std::borrow::Cow;
use std::collections::HashMap; //use std::collections::HashMap;
use std::path::{Path, PathBuf}; //use std::path::{Path, PathBuf};
use vulkano::descriptor::descriptor::*; //use vulkano::descriptor::descriptor::*;
use vulkano::descriptor::pipeline_layout::{PipelineLayoutDesc, PipelineLayoutDescPcRange}; //use vulkano::descriptor::pipeline_layout::{PipelineLayoutDesc, PipelineLayoutDescPcRange};
use vulkano::format::*; //use vulkano::format::*;
use vulkano::pipeline::shader::ShaderInterfaceDefEntry; //use vulkano::pipeline::shader::ShaderInterfaceDefEntry;
//
fn setup() { //fn setup() {
color_backtrace::install(); // color_backtrace::install();
} //}
//
fn difference(e: &str, t: &str) -> String { //fn difference(e: &str, t: &str) -> String {
let diffs = Changeset::new(&e, &t, ""); // let diffs = Changeset::new(&e, &t, "");
diffs // diffs
.diffs // .diffs
.iter() // .iter()
.filter(|d| match d { // .filter(|d| match d {
Difference::Add(_) => true, // Difference::Add(_) => true,
Difference::Rem(_) => true, // Difference::Rem(_) => true,
_ => false, // _ => false,
}) // })
.map(|d| match d { // .map(|d| match d {
Difference::Add(a) => format!("add: {}", a), // Difference::Add(a) => format!("add: {}", a),
Difference::Rem(a) => format!("remove: {}", a), // Difference::Rem(a) => format!("remove: {}", a),
_ => "".to_string(), // _ => "".to_string(),
}) // })
.collect::<Vec<String>>() // .collect::<Vec<String>>()
.join("\n") // .join("\n")
} //}
//
fn descriptor_layout<T>(desc: &T) -> String //fn descriptor_layout<T>(desc: &T) -> String
where //where
T: PipelineLayoutDesc, // T: PipelineLayoutDesc,
{ //{
let num_sets = desc.num_sets(); // let num_sets = desc.num_sets();
let mut r = format!("{:?}", num_sets); // let mut r = format!("{:?}", num_sets);
for n in 0..num_sets { // for n in 0..num_sets {
let num_bindings = desc.num_bindings_in_set(n); // let num_bindings = desc.num_bindings_in_set(n);
r = format!("{:?}{:?}", r, num_bindings); // r = format!("{:?}{:?}", r, num_bindings);
for b in num_bindings { // for b in num_bindings {
r = format!("{:?}{:?}", r, desc.descriptor(n, b)); // r = format!("{:?}{:?}", r, desc.descriptor(n, b));
} // }
} // }
let num_push_constants = desc.num_push_constants_ranges(); // let num_push_constants = desc.num_push_constants_ranges();
r = format!("{:?}{:?}", r, num_push_constants); // r = format!("{:?}{:?}", r, num_push_constants);
for i in 0..num_push_constants { // for i in 0..num_push_constants {
r = format!("{:?}{:?}", r, desc.push_constants_range(i)); // r = format!("{:?}{:?}", r, desc.push_constants_range(i));
} // }
r // r
} //}
//
fn parse<T>(vertex: T, fragment: T) -> shade_runner::Entry //fn parse<T>(vertex: T, fragment: T) -> shade_runner::Entry
where //where
T: AsRef<Path>, // T: AsRef<Path>,
{ //{
let project_root = std::env::current_dir().expect("failed to get root directory"); // let project_root = std::env::current_dir().expect("failed to get root directory");
let mut path = project_root.clone(); // let mut path = project_root.clone();
path.push(PathBuf::from("tests/shaders/")); // path.push(PathBuf::from("tests/shaders/"));
let mut vertex_path = path.clone(); // let mut vertex_path = path.clone();
vertex_path.push(vertex); // vertex_path.push(vertex);
let mut fragment_path = path.clone(); // let mut fragment_path = path.clone();
fragment_path.push(fragment); // fragment_path.push(fragment);
let shader = shade_runner::load(vertex_path, fragment_path).expect("Failed to compile"); // let shader = shade_runner::load(vertex_path, fragment_path).expect("Failed to compile");
shade_runner::parse(&shader).unwrap() // shade_runner::parse(&shader).unwrap()
} //}
//
fn do_test<T>(a: &T, b: &T) //fn do_test<T>(a: &T, b: &T)
where //where
T: std::fmt::Debug, // T: std::fmt::Debug,
{ //{
let a = format!("{:?}", a); // let a = format!("{:?}", a);
let b = format!("{:?}", b); // let b = format!("{:?}", b);
assert_eq!(&a, &b, "\n\nDifference: {}", difference(&a, &b)); // assert_eq!(&a, &b, "\n\nDifference: {}", difference(&a, &b));
} //}
//
#[test] //#[test]
fn test_shade1() { //fn test_shade1() {
setup(); // setup();
let target = Entry { // let target = Entry {
compute_layout: Default::default(), // compute_layout: Default::default(),
frag_input: FragInput { inputs: Vec::new() }, // frag_input: FragInput { inputs: Vec::new() },
frag_output: FragOutput { // frag_output: FragOutput {
outputs: vec![ShaderInterfaceDefEntry { // outputs: vec![ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32B32A32Sfloat, // format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_color")), // name: Some(Cow::Borrowed("f_color")),
}], // }],
}, // },
frag_layout: FragLayout { // frag_layout: FragLayout {
layout_data: LayoutData { // layout_data: LayoutData {
num_sets: 0, // num_sets: 0,
num_bindings: HashMap::new(), // num_bindings: HashMap::new(),
descriptions: HashMap::new(), // descriptions: HashMap::new(),
num_constants: 0, // num_constants: 0,
pc_ranges: Vec::new(), // pc_ranges: Vec::new(),
}, // },
}, // },
vert_input: VertInput { // vert_input: VertInput {
inputs: vec![ShaderInterfaceDefEntry { // inputs: vec![ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32Sfloat, // format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("position")), // name: Some(Cow::Borrowed("position")),
}], // }],
}, // },
vert_output: VertOutput { // vert_output: VertOutput {
outputs: Vec::new(), // outputs: Vec::new(),
}, // },
vert_layout: VertLayout { // vert_layout: VertLayout {
layout_data: LayoutData { // layout_data: LayoutData {
num_sets: 0, // num_sets: 0,
num_bindings: HashMap::new(), // num_bindings: HashMap::new(),
descriptions: HashMap::new(), // descriptions: HashMap::new(),
num_constants: 0, // num_constants: 0,
pc_ranges: Vec::new(), // pc_ranges: Vec::new(),
}, // },
}, // },
}; // };
let entry = parse("vert1.glsl", "frag1.glsl"); // let entry = parse("vert1.glsl", "frag1.glsl");
do_test(&entry, &target); // do_test(&entry, &target);
} //}
//
#[test] //#[test]
fn test_shade2() { //fn test_shade2() {
setup(); // setup();
let target = Entry { // let target = Entry {
compute_layout: Default::default(), // compute_layout: Default::default(),
frag_input: FragInput { // frag_input: FragInput {
inputs: vec![ // inputs: vec![
ShaderInterfaceDefEntry { // ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32B32A32Sfloat, // format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("cool")), // name: Some(Cow::Borrowed("cool")),
}, // },
ShaderInterfaceDefEntry { // ShaderInterfaceDefEntry {
location: 1..2, // location: 1..2,
format: Format::R32G32Sfloat, // format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("yep")), // name: Some(Cow::Borrowed("yep")),
}, // },
ShaderInterfaceDefEntry { // ShaderInterfaceDefEntry {
location: 2..3, // location: 2..3,
format: Format::R32Sfloat, // format: Format::R32Sfloat,
name: Some(Cow::Borrowed("monkey")), // name: Some(Cow::Borrowed("monkey")),
}, // },
], // ],
}, // },
frag_output: FragOutput { // frag_output: FragOutput {
outputs: vec![ShaderInterfaceDefEntry { // outputs: vec![ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32B32A32Sfloat, // format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_color")), // name: Some(Cow::Borrowed("f_color")),
}], // }],
}, // },
frag_layout: FragLayout { // frag_layout: FragLayout {
layout_data: LayoutData { // layout_data: LayoutData {
num_sets: 0, // num_sets: 0,
num_bindings: HashMap::new(), // num_bindings: HashMap::new(),
descriptions: HashMap::new(), // descriptions: HashMap::new(),
num_constants: 0, // num_constants: 0,
pc_ranges: Vec::new(), // pc_ranges: Vec::new(),
}, // },
}, // },
vert_input: VertInput { // vert_input: VertInput {
inputs: vec![ShaderInterfaceDefEntry { // inputs: vec![ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32Sfloat, // format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("position")), // name: Some(Cow::Borrowed("position")),
}], // }],
}, // },
vert_output: VertOutput { // vert_output: VertOutput {
outputs: vec![ // outputs: vec![
ShaderInterfaceDefEntry { // ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32B32A32Sfloat, // format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("cool")), // name: Some(Cow::Borrowed("cool")),
}, // },
ShaderInterfaceDefEntry { // ShaderInterfaceDefEntry {
location: 1..2, // location: 1..2,
format: Format::R32G32Sfloat, // format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("yep")), // name: Some(Cow::Borrowed("yep")),
}, // },
ShaderInterfaceDefEntry { // ShaderInterfaceDefEntry {
location: 2..3, // location: 2..3,
format: Format::R32Sfloat, // format: Format::R32Sfloat,
name: Some(Cow::Borrowed("monkey")), // name: Some(Cow::Borrowed("monkey")),
}, // },
], // ],
}, // },
vert_layout: VertLayout { // vert_layout: VertLayout {
layout_data: LayoutData { // layout_data: LayoutData {
num_sets: 0, // num_sets: 0,
num_bindings: HashMap::new(), // num_bindings: HashMap::new(),
descriptions: HashMap::new(), // descriptions: HashMap::new(),
num_constants: 0, // num_constants: 0,
pc_ranges: Vec::new(), // pc_ranges: Vec::new(),
}, // },
}, // },
}; // };
let entry = parse("vert2.glsl", "frag2.glsl"); // let entry = parse("vert2.glsl", "frag2.glsl");
do_test(&entry, &target); // do_test(&entry, &target);
} //}
//
#[test] //#[test]
fn test_shade3() { //fn test_shade3() {
setup(); // setup();
let target = Entry { // let target = Entry {
compute_layout: Default::default(), // compute_layout: Default::default(),
frag_input: FragInput { inputs: Vec::new() }, // frag_input: FragInput { inputs: Vec::new() },
frag_output: FragOutput { // frag_output: FragOutput {
outputs: vec![ShaderInterfaceDefEntry { // outputs: vec![ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32B32A32Sfloat, // format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_color")), // name: Some(Cow::Borrowed("f_color")),
}], // }],
}, // },
frag_layout: FragLayout { // frag_layout: FragLayout {
layout_data: LayoutData { // layout_data: LayoutData {
num_sets: 1, // num_sets: 1,
num_bindings: vec![(0, 1)].into_iter().collect(), // num_bindings: vec![(0, 1)].into_iter().collect(),
descriptions: vec![( // descriptions: vec![(
0, // 0,
vec![( // vec![(
0, // 0,
DescriptorDesc { // DescriptorDesc {
ty: DescriptorDescTy::CombinedImageSampler(DescriptorImageDesc { // ty: DescriptorDescTy::CombinedImageSampler(DescriptorImageDesc {
sampled: true, // sampled: true,
dimensions: DescriptorImageDescDimensions::TwoDimensional, // dimensions: DescriptorImageDescDimensions::TwoDimensional,
format: None, // format: None,
multisampled: false, // multisampled: false,
array_layers: DescriptorImageDescArray::NonArrayed, // array_layers: DescriptorImageDescArray::NonArrayed,
}), // }),
array_count: 1, // array_count: 1,
stages: ShaderStages { // stages: ShaderStages {
fragment: true, // fragment: true,
..ShaderStages::none() // ..ShaderStages::none()
}, // },
readonly: true, // readonly: true,
}, // },
)] // )]
.into_iter() // .into_iter()
.collect(), // .collect(),
)] // )]
.into_iter() // .into_iter()
.collect(), // .collect(),
num_constants: 0, // num_constants: 0,
pc_ranges: Vec::new(), // pc_ranges: Vec::new(),
}, // },
}, // },
vert_input: VertInput { // vert_input: VertInput {
inputs: vec![ShaderInterfaceDefEntry { // inputs: vec![ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32Sfloat, // format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("position")), // name: Some(Cow::Borrowed("position")),
}], // }],
}, // },
vert_output: VertOutput { // vert_output: VertOutput {
outputs: Vec::new(), // outputs: Vec::new(),
}, // },
vert_layout: VertLayout { // vert_layout: VertLayout {
layout_data: LayoutData { // layout_data: LayoutData {
num_sets: 0, // num_sets: 0,
num_bindings: HashMap::new(), // num_bindings: HashMap::new(),
descriptions: HashMap::new(), // descriptions: HashMap::new(),
num_constants: 0, // num_constants: 0,
pc_ranges: Vec::new(), // pc_ranges: Vec::new(),
}, // },
}, // },
}; // };
let entry = parse("vert3.glsl", "frag3.glsl"); // let entry = parse("vert3.glsl", "frag3.glsl");
do_test(&entry.frag_input, &target.frag_input); // do_test(&entry.frag_input, &target.frag_input);
do_test(&entry.frag_output, &target.frag_output); // do_test(&entry.frag_output, &target.frag_output);
do_test(&entry.vert_input, &target.vert_input); // do_test(&entry.vert_input, &target.vert_input);
do_test(&entry.vert_output, &target.vert_output); // do_test(&entry.vert_output, &target.vert_output);
do_test( // do_test(
&descriptor_layout(&entry.frag_layout), // &descriptor_layout(&entry.frag_layout),
&descriptor_layout(&target.frag_layout), // &descriptor_layout(&target.frag_layout),
); // );
do_test( // do_test(
&descriptor_layout(&entry.vert_layout), // &descriptor_layout(&entry.vert_layout),
&descriptor_layout(&target.vert_layout), // &descriptor_layout(&target.vert_layout),
); // );
} //}
//
#[test] //#[test]
fn test_shade4() { //fn test_shade4() {
setup(); // setup();
let target = Entry { // let target = Entry {
compute_layout: Default::default(), // compute_layout: Default::default(),
frag_input: FragInput { inputs: Vec::new() }, // frag_input: FragInput { inputs: Vec::new() },
frag_output: FragOutput { // frag_output: FragOutput {
outputs: vec![ShaderInterfaceDefEntry { // outputs: vec![ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32B32A32Sfloat, // format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_color")), // name: Some(Cow::Borrowed("f_color")),
}], // }],
}, // },
frag_layout: FragLayout { // frag_layout: FragLayout {
layout_data: LayoutData { // layout_data: LayoutData {
num_sets: 0, // num_sets: 0,
num_bindings: HashMap::new(), // num_bindings: HashMap::new(),
descriptions: HashMap::new(), // descriptions: HashMap::new(),
num_constants: 1, // num_constants: 1,
pc_ranges: vec![PipelineLayoutDescPcRange { // pc_ranges: vec![PipelineLayoutDescPcRange {
offset: 0, // offset: 0,
size: 16, // size: 16,
stages: ShaderStages { // stages: ShaderStages {
fragment: true, // fragment: true,
..ShaderStages::none() // ..ShaderStages::none()
}, // },
}], // }],
}, // },
}, // },
vert_input: VertInput { // vert_input: VertInput {
inputs: vec![ShaderInterfaceDefEntry { // inputs: vec![ShaderInterfaceDefEntry {
location: 0..1, // location: 0..1,
format: Format::R32G32Sfloat, // format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("position")), // name: Some(Cow::Borrowed("position")),
}], // }],
}, // },
vert_output: VertOutput { // vert_output: VertOutput {
outputs: Vec::new(), // outputs: Vec::new(),
}, // },
vert_layout: VertLayout { // vert_layout: VertLayout {
layout_data: LayoutData { // layout_data: LayoutData {
num_sets: 0, // num_sets: 0,
num_bindings: HashMap::new(), // num_bindings: HashMap::new(),
descriptions: HashMap::new(), // descriptions: HashMap::new(),
num_constants: 0, // num_constants: 0,
pc_ranges: Vec::new(), // pc_ranges: Vec::new(),
}, // },
}, // },
}; // };
let entry = parse("vert4.glsl", "frag4.glsl"); // let entry = parse("vert4.glsl", "frag4.glsl");
do_test(&entry.frag_input, &target.frag_input); // do_test(&entry.frag_input, &target.frag_input);
do_test(&entry.frag_output, &target.frag_output); // do_test(&entry.frag_output, &target.frag_output);
do_test(&entry.vert_input, &target.vert_input); // do_test(&entry.vert_input, &target.vert_input);
do_test(&entry.vert_output, &target.vert_output); // do_test(&entry.vert_output, &target.vert_output);
do_test( // do_test(
&descriptor_layout(&entry.frag_layout), // &descriptor_layout(&entry.frag_layout),
&descriptor_layout(&target.frag_layout), // &descriptor_layout(&target.frag_layout),
); // );
} //}

Loading…
Cancel
Save