descriptor layout
This commit is contained in:
9
tests/shaders/frag3.glsl
Normal file
9
tests/shaders/frag3.glsl
Normal file
@@ -0,0 +1,9 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec4 f_color;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
f_color = texture(tex, vec2(0.0, 0.5));
|
||||
}
|
||||
8
tests/shaders/vert3.glsl
Normal file
8
tests/shaders/vert3.glsl
Normal file
@@ -0,0 +1,8 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
}
|
||||
|
||||
161
tests/tests.rs
161
tests/tests.rs
@@ -4,9 +4,10 @@ use shade_runner::*;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
use vulkano::descriptor::descriptor::ShaderStages;
|
||||
use vulkano::descriptor::descriptor::*;
|
||||
use vulkano::format::*;
|
||||
use vulkano::pipeline::shader::ShaderInterfaceDefEntry;
|
||||
use vulkano::descriptor::pipeline_layout::PipelineLayoutDesc;
|
||||
|
||||
fn setup() {
|
||||
color_backtrace::install();
|
||||
@@ -31,6 +32,27 @@ fn difference(e: &str, t: &str) -> String {
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
fn descriptor_layout<T>(desc: &T) -> String
|
||||
where
|
||||
T: PipelineLayoutDesc,
|
||||
{
|
||||
let num_sets = desc.num_sets();
|
||||
let mut r = format!("{:?}", num_sets);
|
||||
for n in 0..num_sets {
|
||||
let num_bindings = desc.num_bindings_in_set(n);
|
||||
r = format!("{:?}{:?}", r, num_bindings);
|
||||
for b in num_bindings {
|
||||
r = format!("{:?}{:?}", r, desc.descriptor(n, b));
|
||||
}
|
||||
}
|
||||
let num_push_constants = desc.num_push_constants_ranges();
|
||||
r = format!("{:?}{:?}", r, num_push_constants);
|
||||
for i in 0..num_push_constants {
|
||||
r = format!("{:?}{:?}", r, desc.push_constants_range(i));
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
fn parse<T>(vertex: T, fragment: T) -> shade_runner::Entry
|
||||
where
|
||||
T: AsRef<Path>,
|
||||
@@ -66,6 +88,7 @@ fn test_shade1() {
|
||||
layout_data: LayoutData {
|
||||
num_sets: 0,
|
||||
num_bindings: HashMap::new(),
|
||||
descriptions: HashMap::new(),
|
||||
},
|
||||
},
|
||||
vert_input: VertInput {
|
||||
@@ -98,23 +121,23 @@ fn test_shade1() {
|
||||
fn test_shade2() {
|
||||
setup();
|
||||
let target = Entry {
|
||||
frag_input: FragInput {
|
||||
frag_input: FragInput {
|
||||
inputs: vec![
|
||||
ShaderInterfaceDefEntry {
|
||||
location: 0..1,
|
||||
format: Format::R32G32B32A32Sfloat,
|
||||
name: Some(Cow::Borrowed("cool")),
|
||||
},
|
||||
location: 0..1,
|
||||
format: Format::R32G32B32A32Sfloat,
|
||||
name: Some(Cow::Borrowed("cool")),
|
||||
},
|
||||
ShaderInterfaceDefEntry {
|
||||
location: 1..2,
|
||||
format: Format::R32G32Sfloat,
|
||||
name: Some(Cow::Borrowed("yep")),
|
||||
},
|
||||
location: 1..2,
|
||||
format: Format::R32G32Sfloat,
|
||||
name: Some(Cow::Borrowed("yep")),
|
||||
},
|
||||
ShaderInterfaceDefEntry {
|
||||
location: 2..3,
|
||||
format: Format::R32Sfloat,
|
||||
name: Some(Cow::Borrowed("monkey")),
|
||||
},
|
||||
location: 2..3,
|
||||
format: Format::R32Sfloat,
|
||||
name: Some(Cow::Borrowed("monkey")),
|
||||
},
|
||||
],
|
||||
},
|
||||
frag_output: FragOutput {
|
||||
@@ -132,6 +155,7 @@ fn test_shade2() {
|
||||
layout_data: LayoutData {
|
||||
num_sets: 0,
|
||||
num_bindings: HashMap::new(),
|
||||
descriptions: HashMap::new(),
|
||||
},
|
||||
},
|
||||
vert_input: VertInput {
|
||||
@@ -144,20 +168,20 @@ fn test_shade2() {
|
||||
vert_output: VertOutput {
|
||||
outputs: vec![
|
||||
ShaderInterfaceDefEntry {
|
||||
location: 0..1,
|
||||
format: Format::R32G32B32A32Sfloat,
|
||||
name: Some(Cow::Borrowed("cool")),
|
||||
},
|
||||
location: 0..1,
|
||||
format: Format::R32G32B32A32Sfloat,
|
||||
name: Some(Cow::Borrowed("cool")),
|
||||
},
|
||||
ShaderInterfaceDefEntry {
|
||||
location: 1..2,
|
||||
format: Format::R32G32Sfloat,
|
||||
name: Some(Cow::Borrowed("yep")),
|
||||
},
|
||||
location: 1..2,
|
||||
format: Format::R32G32Sfloat,
|
||||
name: Some(Cow::Borrowed("yep")),
|
||||
},
|
||||
ShaderInterfaceDefEntry {
|
||||
location: 2..3,
|
||||
format: Format::R32Sfloat,
|
||||
name: Some(Cow::Borrowed("monkey")),
|
||||
},
|
||||
location: 2..3,
|
||||
format: Format::R32Sfloat,
|
||||
name: Some(Cow::Borrowed("monkey")),
|
||||
},
|
||||
],
|
||||
},
|
||||
vert_layout: VertLayout(ShaderStages {
|
||||
@@ -176,3 +200,88 @@ fn test_shade2() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shade3() {
|
||||
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: 1,
|
||||
num_bindings: vec![(0, 1)].into_iter().collect(),
|
||||
descriptions: vec![(
|
||||
0,
|
||||
vec![(
|
||||
0,
|
||||
DescriptorDesc {
|
||||
ty: DescriptorDescTy::CombinedImageSampler(DescriptorImageDesc {
|
||||
sampled: true,
|
||||
dimensions: DescriptorImageDescDimensions::TwoDimensional,
|
||||
format: None,
|
||||
multisampled: false,
|
||||
array_layers: DescriptorImageDescArray::NonArrayed,
|
||||
}),
|
||||
array_count: 1,
|
||||
stages: ShaderStages {
|
||||
fragment: true,
|
||||
..ShaderStages::none()
|
||||
},
|
||||
readonly: true,
|
||||
},
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
},
|
||||
},
|
||||
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("vert3.glsl", "frag3.glsl");
|
||||
do_test(&entry.frag_input, &target.frag_input);
|
||||
do_test(&entry.frag_output, &target.frag_output);
|
||||
do_test(&entry.vert_input, &target.vert_input);
|
||||
do_test(&entry.vert_output, &target.vert_output);
|
||||
do_test(&descriptor_layout(&entry.frag_layout), &descriptor_layout(&target.frag_layout));
|
||||
do_test(&descriptor_layout(&entry.vert_layout), &descriptor_layout(&target.vert_layout));
|
||||
|
||||
}
|
||||
|
||||
fn do_test<T>(a: &T, b: &T)
|
||||
where
|
||||
T: std::fmt::Debug,
|
||||
{
|
||||
let a = format!("{:?}", a);
|
||||
let b = format!("{:?}", b);
|
||||
assert_eq!(
|
||||
&a,
|
||||
&b,
|
||||
"\n\nDifference: {}",
|
||||
difference(&a, &b)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user