added vertex layouts

master
Tom Gowan 6 years ago
parent a43fff68e0
commit 97248e5e9f

@ -113,27 +113,38 @@ unsafe impl ShaderInterfaceDef for VertOutput {
pub type VertOutputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>; pub type VertOutputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>;
// This structure describes layout of this stage. // This structure describes layout of this stage.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Clone)]
pub struct VertLayout(pub ShaderStages); pub struct VertLayout {
pub stages: ShaderStages,
pub layout_data: LayoutData,
}
unsafe impl PipelineLayoutDesc for VertLayout { unsafe impl PipelineLayoutDesc for VertLayout {
// Number of descriptor sets it takes.
fn num_sets(&self) -> usize { fn num_sets(&self) -> usize {
0 self.layout_data.num_sets
} }
// Number of entries (bindings) in each set. fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
fn num_bindings_in_set(&self, _set: usize) -> Option<usize> { self.layout_data.num_bindings.get(&set).map(|&i| i)
None
} }
// Descriptor descriptions. fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
fn descriptor(&self, _set: usize, _binding: usize) -> Option<DescriptorDesc> { self.layout_data.descriptions.get(&set)
None .and_then(|s|s.get(&binding))
.map(|desc| {
let mut desc = desc.clone();
desc.stages = self.stages.clone();
desc
})
} }
// Number of push constants ranges (think: number of push constants).
fn num_push_constants_ranges(&self) -> usize { fn num_push_constants_ranges(&self) -> usize {
0 self.layout_data.num_constants
} }
// Each push constant range in memory. fn push_constants_range(&self, num: usize) -> Option<PipelineLayoutDescPcRange> {
fn push_constants_range(&self, _num: usize) -> Option<PipelineLayoutDescPcRange> { self.layout_data.pc_ranges.get(num)
None .map(|desc| {
let mut desc = desc.clone();
desc.stages = self.stages.clone();
desc
})
} }
} }

@ -24,6 +24,7 @@ pub struct LayoutData {
pub fn create_entry(shaders: &CompiledShaders) -> Entry { pub fn create_entry(shaders: &CompiledShaders) -> Entry {
let vertex_interfaces = create_interfaces(&shaders.vertex); let vertex_interfaces = create_interfaces(&shaders.vertex);
let vertex_layout = create_layouts(&shaders.vertex);
let fragment_interfaces = create_interfaces(&shaders.fragment); let fragment_interfaces = create_interfaces(&shaders.fragment);
let fragment_layout = create_layouts(&shaders.fragment); let fragment_layout = create_layouts(&shaders.fragment);
let frag_input = FragInput { let frag_input = FragInput {
@ -45,10 +46,13 @@ pub fn create_entry(shaders: &CompiledShaders) -> Entry {
let vert_output = VertOutput { let vert_output = VertOutput {
outputs: vertex_interfaces.outputs, outputs: vertex_interfaces.outputs,
}; };
let vert_layout = VertLayout(ShaderStages { let vert_layout = VertLayout {
vertex: true, stages: ShaderStages {
..ShaderStages::none() vertex: true,
}); ..ShaderStages::none()
},
layout_data: vertex_layout,
};
Entry { Entry {
frag_input, frag_input,
frag_output, frag_output,

@ -112,10 +112,19 @@ fn test_shade1() {
vert_output: VertOutput { vert_output: VertOutput {
outputs: Vec::new(), outputs: Vec::new(),
}, },
vert_layout: VertLayout(ShaderStages { vert_layout: VertLayout {
vertex: true, stages: ShaderStages {
..ShaderStages::none() vertex: true,
}), ..ShaderStages::none()
},
layout_data: LayoutData {
num_sets: 0,
num_bindings: HashMap::new(),
descriptions: HashMap::new(),
num_constants: 0,
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);
@ -190,10 +199,19 @@ fn test_shade2() {
}, },
], ],
}, },
vert_layout: VertLayout(ShaderStages { vert_layout: VertLayout {
vertex: true, stages: ShaderStages {
..ShaderStages::none() vertex: true,
}), ..ShaderStages::none()
},
layout_data: LayoutData {
num_sets: 0,
num_bindings: HashMap::new(),
descriptions: HashMap::new(),
num_constants: 0,
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);
@ -258,10 +276,19 @@ fn test_shade3() {
vert_output: VertOutput { vert_output: VertOutput {
outputs: Vec::new(), outputs: Vec::new(),
}, },
vert_layout: VertLayout(ShaderStages { vert_layout: VertLayout {
vertex: true, stages: ShaderStages {
..ShaderStages::none() vertex: true,
}), ..ShaderStages::none()
},
layout_data: LayoutData {
num_sets: 0,
num_bindings: HashMap::new(),
descriptions: HashMap::new(),
num_constants: 0,
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);
@ -320,10 +347,19 @@ fn test_shade4() {
vert_output: VertOutput { vert_output: VertOutput {
outputs: Vec::new(), outputs: Vec::new(),
}, },
vert_layout: VertLayout(ShaderStages { vert_layout: VertLayout {
vertex: true, stages: ShaderStages {
..ShaderStages::none() vertex: true,
}), ..ShaderStages::none()
},
layout_data: LayoutData {
num_sets: 0,
num_bindings: HashMap::new(),
descriptions: HashMap::new(),
num_constants: 0,
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);

Loading…
Cancel
Save