hacked out some stuff while I'm testing
This commit is contained in:
167
src/layouts.rs
167
src/layouts.rs
@@ -7,51 +7,46 @@ use crate::reflection::LayoutData;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Entry {
|
||||
pub frag_input: FragInput,
|
||||
pub frag_output: FragOutput,
|
||||
pub frag_layout: FragLayout,
|
||||
pub vert_input: VertInput,
|
||||
pub vert_output: VertOutput,
|
||||
pub vert_layout: VertLayout,
|
||||
pub compute_layout: ComputeLayout,
|
||||
pub input: Option<Input>,
|
||||
pub output: Option<Output>,
|
||||
pub layout: Layout,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct FragInput {
|
||||
pub struct Input {
|
||||
pub inputs: Vec<ShaderInterfaceDefEntry>,
|
||||
}
|
||||
|
||||
unsafe impl ShaderInterfaceDef for FragInput {
|
||||
type Iter = FragInputIter;
|
||||
unsafe impl ShaderInterfaceDef for Input {
|
||||
type Iter = InputIter;
|
||||
|
||||
fn elements(&self) -> FragInputIter {
|
||||
fn elements(&self) -> InputIter {
|
||||
self.inputs.clone().into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
pub type FragInputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>;
|
||||
pub type InputIter = std::vec::IntoIter<ShaderInterfaceDefEntry>;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct FragOutput {
|
||||
pub struct Output {
|
||||
pub outputs: Vec<ShaderInterfaceDefEntry>,
|
||||
}
|
||||
|
||||
unsafe impl ShaderInterfaceDef for FragOutput {
|
||||
type Iter = FragOutputIter;
|
||||
unsafe impl ShaderInterfaceDef for Output {
|
||||
type Iter = OutputIter;
|
||||
|
||||
fn elements(&self) -> FragOutputIter {
|
||||
fn elements(&self) -> OutputIter {
|
||||
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)]
|
||||
pub struct FragLayout {
|
||||
pub struct Layout {
|
||||
pub layout_data: LayoutData,
|
||||
}
|
||||
impl FragLayout {
|
||||
impl Layout {
|
||||
const STAGES: ShaderStages = ShaderStages {
|
||||
vertex: false,
|
||||
tessellation_control: false,
|
||||
@@ -61,7 +56,8 @@ impl FragLayout {
|
||||
compute: false,
|
||||
};
|
||||
}
|
||||
unsafe impl PipelineLayoutDesc for FragLayout {
|
||||
|
||||
unsafe impl PipelineLayoutDesc for Layout {
|
||||
fn num_sets(&self) -> usize {
|
||||
self.layout_data.num_sets
|
||||
}
|
||||
@@ -73,7 +69,7 @@ unsafe impl PipelineLayoutDesc for FragLayout {
|
||||
.and_then(|s|s.get(&binding))
|
||||
.map(|desc| {
|
||||
let mut desc = desc.clone();
|
||||
desc.stages = FragLayout::STAGES;
|
||||
desc.stages = Layout::STAGES;
|
||||
desc
|
||||
})
|
||||
|
||||
@@ -85,132 +81,9 @@ unsafe impl PipelineLayoutDesc for FragLayout {
|
||||
self.layout_data.pc_ranges.get(num)
|
||||
.map(|desc| {
|
||||
let mut desc = *desc;
|
||||
desc.stages = FragLayout::STAGES;
|
||||
desc.stages = Layout::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 {
|
||||
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 = Self::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 = Self::STAGES;
|
||||
desc
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
54
src/lib.rs
54
src/lib.rs
@@ -28,13 +28,21 @@ pub struct CompiledShader {
|
||||
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
|
||||
pub fn load_vertex<T>(vertex: T) -> Result<CompiledShader, Error>
|
||||
where
|
||||
T: AsRef<Path>,
|
||||
{
|
||||
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
|
||||
@@ -42,8 +50,8 @@ pub fn load_fragment<T>(fragment: T) -> Result<CompiledShader, Error>
|
||||
where
|
||||
T: AsRef<Path>,
|
||||
{
|
||||
let fragment = compiler::compile(vertex, ShaderKind::Fragment).map_err(Error::Compile)?;
|
||||
Ok(CompiledShader{ spriv: fragment })
|
||||
let fragment = compiler::compile(fragment, ShaderKind::Fragment).map_err(Error::Compile)?;
|
||||
Ok(CompiledShader { spriv: fragment })
|
||||
}
|
||||
|
||||
/// Loads and compiles the geometry shader
|
||||
@@ -51,55 +59,51 @@ pub fn load_geometry<T>(geometry: T) -> Result<CompiledShader, Error>
|
||||
where
|
||||
T: AsRef<Path>,
|
||||
{
|
||||
let geometry = compiler::compile(vertex, ShaderKind::Geometry).map_err(Error::Compile)?;
|
||||
Ok(CompiledShader{ spriv: geometry })
|
||||
let geometry = compiler::compile(geometry, ShaderKind::Geometry).map_err(Error::Compile)?;
|
||||
Ok(CompiledShader { spriv: geometry })
|
||||
}
|
||||
|
||||
/// 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
|
||||
T: AsRef<Path>,
|
||||
{
|
||||
let tess = compiler::compile(vertex, ShaderKind::TessControl).map_err(Error::Compile)?;
|
||||
Ok(CompiledShader{ spriv: tess })
|
||||
let tess = compiler::compile(tessellation_control, ShaderKind::TessControl).map_err(Error::Compile)?;
|
||||
Ok(CompiledShader { spriv: tess })
|
||||
}
|
||||
|
||||
/// 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
|
||||
T: AsRef<Path>,
|
||||
{
|
||||
let tess = compiler::compile(vertex, ShaderKind::TessEvaluation).map_err(Error::Compile)?;
|
||||
Ok(CompiledShader{ spriv: tess })
|
||||
let tess = compiler::compile(tessellation_evaluation, ShaderKind::TessEvaluation).map_err(Error::Compile)?;
|
||||
Ok(CompiledShader { spriv: tess })
|
||||
}
|
||||
|
||||
// TODO this should be incorpoarted into load but that would be
|
||||
// a breaking change. Do this in next major version
|
||||
pub fn load_compute<T>(compute: T) -> Result<CompiledShaders, Error>
|
||||
where
|
||||
T: AsRef<Path>,
|
||||
pub fn load_compute<T>(compute: T) -> Result<CompiledShader, Error>
|
||||
where
|
||||
T: AsRef<Path>,
|
||||
{
|
||||
let options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap();
|
||||
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
|
||||
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,
|
||||
Ok(CompiledShader {
|
||||
spriv: compute,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_compute(code: &CompiledShaders) -> Result<Entry, Error> {
|
||||
reflection::create_compute_entry(code)
|
||||
pub fn parse_compute(code: &CompiledShader) -> Result<Entry, Error> {
|
||||
reflection::create_compute_entry(&code.spriv)
|
||||
}
|
||||
|
||||
/// Parses the shaders and gives an entry point
|
||||
pub fn parse(code: &CompiledShaders) -> Result<Entry, Error> {
|
||||
reflection::create_entry(code)
|
||||
pub fn parse(code: &CompiledShader) -> Result<Entry, Error> {
|
||||
reflection::create_entry(&code.spriv)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::error::Error;
|
||||
use crate::layouts::*;
|
||||
use crate::sr;
|
||||
use crate::{sr, CompiledShader};
|
||||
use crate::srvk::{DescriptorDescInfo, SpirvTy};
|
||||
use crate::vk::descriptor::descriptor::*;
|
||||
use crate::vk::descriptor::pipeline_layout::PipelineLayoutDescPcRange;
|
||||
@@ -24,46 +24,40 @@ pub struct LayoutData {
|
||||
pub pc_ranges: Vec<PipelineLayoutDescPcRange>,
|
||||
}
|
||||
|
||||
pub fn create_entry(shaders: &CompiledShaders) -> 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)?;
|
||||
pub fn create_entry(spirv: &Vec<u32>) -> Result<Entry, Error> {
|
||||
|
||||
let frag_input = FragInput {
|
||||
inputs: fragment_interfaces.inputs,
|
||||
};
|
||||
let frag_output = FragOutput {
|
||||
outputs: fragment_interfaces.outputs,
|
||||
};
|
||||
let frag_layout = FragLayout {
|
||||
layout_data: fragment_layout,
|
||||
};
|
||||
let vert_input = VertInput {
|
||||
let vertex_interfaces = create_interfaces(spirv)?;
|
||||
let vertex_layout = create_layouts(spirv)?;
|
||||
|
||||
let input = Some(Input {
|
||||
inputs: vertex_interfaces.inputs,
|
||||
};
|
||||
let vert_output = VertOutput {
|
||||
});
|
||||
let output = Some(Output {
|
||||
outputs: vertex_interfaces.outputs,
|
||||
};
|
||||
let vert_layout = VertLayout {
|
||||
});
|
||||
let layout = Layout {
|
||||
layout_data: vertex_layout,
|
||||
};
|
||||
|
||||
Ok(Entry {
|
||||
frag_input,
|
||||
frag_output,
|
||||
vert_input,
|
||||
vert_output,
|
||||
frag_layout,
|
||||
vert_layout,
|
||||
compute_layout: Default::default(),
|
||||
input,
|
||||
output,
|
||||
layout,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_compute_entry(shaders: &CompiledShaders) -> Result<Entry, Error> {
|
||||
create_layouts(&shaders.compute).map(|layout_data| {
|
||||
let mut entry = Entry::default();
|
||||
entry.compute_layout = ComputeLayout{ layout_data };
|
||||
entry
|
||||
pub fn create_compute_entry(spirv: &Vec<u32>) -> Result<Entry, Error> {
|
||||
|
||||
let compute_layout = create_layouts(spirv)?;
|
||||
|
||||
let layout = Layout {
|
||||
layout_data: compute_layout,
|
||||
};
|
||||
|
||||
Ok(Entry {
|
||||
input: None,
|
||||
output: None,
|
||||
layout,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
32
src/watch.rs
32
src/watch.rs
@@ -90,14 +90,14 @@ impl GraphicsLoader {
|
||||
}
|
||||
|
||||
fn reload(&self) {
|
||||
match crate::load(&self.vertex, &self.fragment) {
|
||||
Ok(shaders) => {
|
||||
let entry = crate::parse(&shaders);
|
||||
let msg = entry.map(|entry| Message { shaders, entry });
|
||||
self.tx.send(msg).ok()
|
||||
}
|
||||
Err(e) => self.tx.send(Err(e)).ok(),
|
||||
};
|
||||
// match crate::load(&self.vertex, &self.fragment) {
|
||||
// Ok(shaders) => {
|
||||
// let entry = crate::parse(&shaders);
|
||||
// let msg = entry.map(|entry| Message { shaders, entry });
|
||||
// self.tx.send(msg).ok()
|
||||
// }
|
||||
// Err(e) => self.tx.send(Err(e)).ok(),
|
||||
// };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,14 +113,14 @@ impl ComputeLoader {
|
||||
}
|
||||
|
||||
fn reload(&self) {
|
||||
match crate::load_compute(&self.compute) {
|
||||
Ok(shaders) => {
|
||||
let entry = crate::parse_compute(&shaders);
|
||||
let msg = entry.map(|entry| Message { shaders, entry });
|
||||
self.tx.send(msg).ok()
|
||||
}
|
||||
Err(e) => self.tx.send(Err(e)).ok(),
|
||||
};
|
||||
// match crate::load_compute(&self.compute) {
|
||||
// Ok(shaders) => {
|
||||
// let entry = crate::parse_compute(&shaders);
|
||||
// let msg = entry.map(|entry| Message { shaders, entry });
|
||||
// self.tx.send(msg).ok()
|
||||
// }
|
||||
// Err(e) => self.tx.send(Err(e)).ok(),
|
||||
// };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user