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

initial commit

This commit is contained in:
Tom Gowan
2019-04-26 13:00:38 +10:00
commit 0755b4f807
16 changed files with 651 additions and 0 deletions

7
tests/shaders/frag1.glsl Normal file
View File

@@ -0,0 +1,7 @@
#version 450
layout(location = 0) out vec4 f_color;
void main() {
f_color = vec4(0.0, 0.5, 1.0, 1.0);
}

13
tests/shaders/frag2.glsl Normal file
View File

@@ -0,0 +1,13 @@
#version 450
layout(location = 0) in vec4 cool;
layout(location = 1) in vec2 yep;
layout(location = 2) in float monkey;
layout(location = 0) out vec4 f_color;
void main() {
vec4 t = cool;
t.yw += yep;
t.x -= monkey;
f_color = t;
}

10
tests/shaders/vert1.glsl Normal file
View File

@@ -0,0 +1,10 @@
#version 450
layout(location = 0) in vec2 position;
void main() {
vec2 p = position;
p.x += 0.2;
gl_Position = vec4(p, 0.0, 1.0);
}

14
tests/shaders/vert2.glsl Normal file
View File

@@ -0,0 +1,14 @@
#version 450
layout(location = 0) in vec2 position;
layout(location = 0) out vec4 cool;
layout(location = 1) out vec2 yep;
layout(location = 2) out float monkey;
void main() {
cool = vec4(0.0, 0.5, 1.0, 1.0);
yep = position;
monkey = 0.9;
gl_Position = vec4(yep, 0.0, 1.0);
}

178
tests/tests.rs Normal file
View File

@@ -0,0 +1,178 @@
use color_backtrace;
use difference::{Changeset, Difference};
use shade_runner::*;
use std::borrow::Cow;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use vulkano::descriptor::descriptor::ShaderStages;
use vulkano::format::*;
use vulkano::pipeline::shader::ShaderInterfaceDefEntry;
fn setup() {
color_backtrace::install();
}
fn difference(e: &str, t: &str) -> String {
let diffs = Changeset::new(&e, &t, "");
diffs
.diffs
.iter()
.filter(|d| match d {
Difference::Add(_) => true,
Difference::Rem(_) => true,
_ => false,
})
.map(|d| match d {
Difference::Add(a) => format!("add: {}", a),
Difference::Rem(a) => format!("remove: {}", a),
_ => "".to_string(),
})
.collect::<Vec<String>>()
.join("\n")
}
fn parse<T>(vertex: T, fragment: T) -> shade_runner::Entry
where
T: AsRef<Path>,
{
let project_root = std::env::current_dir().expect("failed to get root directory");
let mut path = project_root.clone();
path.push(PathBuf::from("tests/shaders/"));
let mut vertex_path = path.clone();
vertex_path.push(vertex);
let mut fragment_path = path.clone();
fragment_path.push(fragment);
let shader = shade_runner::load(vertex_path, fragment_path).expect("Failed to compile");
shade_runner::parse(&shader)
}
#[test]
fn test_shade1() {
setup();
let target = Entry {
frag_input: FragInput { inputs: Vec::new() },
frag_output: FragOutput {
outputs: vec![ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_color")),
}],
},
frag_layout: FragLayout {
stages: ShaderStages {
fragment: true,
..ShaderStages::none()
},
layout_data: LayoutData {
num_sets: 0,
num_bindings: HashMap::new(),
},
},
vert_input: VertInput {
inputs: vec![ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("position")),
}],
},
vert_output: VertOutput {
outputs: Vec::new(),
},
vert_layout: VertLayout(ShaderStages {
vertex: true,
..ShaderStages::none()
}),
};
let entry = parse("vert1.glsl", "frag1.glsl");
let entry = format!("{:?}", entry);
let target = format!("{:?}", target);
assert_eq!(
&entry,
&target,
"\n\nDifference: {}",
difference(&entry, &target)
);
}
#[test]
fn test_shade2() {
setup();
let target = Entry {
frag_input: FragInput {
inputs: vec![
ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("cool")),
},
ShaderInterfaceDefEntry {
location: 1..2,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("yep")),
},
ShaderInterfaceDefEntry {
location: 2..3,
format: Format::R32Sfloat,
name: Some(Cow::Borrowed("monkey")),
},
],
},
frag_output: FragOutput {
outputs: vec![ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_color")),
}],
},
frag_layout: FragLayout {
stages: ShaderStages {
fragment: true,
..ShaderStages::none()
},
layout_data: LayoutData {
num_sets: 0,
num_bindings: HashMap::new(),
},
},
vert_input: VertInput {
inputs: vec![ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("position")),
}],
},
vert_output: VertOutput {
outputs: vec![
ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("cool")),
},
ShaderInterfaceDefEntry {
location: 1..2,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("yep")),
},
ShaderInterfaceDefEntry {
location: 2..3,
format: Format::R32Sfloat,
name: Some(Cow::Borrowed("monkey")),
},
],
},
vert_layout: VertLayout(ShaderStages {
vertex: true,
..ShaderStages::none()
}),
};
let entry = parse("vert2.glsl", "frag2.glsl");
let entry = format!("{:?}", entry);
let target = format!("{:?}", target);
assert_eq!(
&entry,
&target,
"\n\nDifference: {}",
difference(&entry, &target)
);
}