remove unimpl

master
Tom Gowan 6 years ago
parent 5840e837eb
commit 15cddaa35b

@ -1,4 +1,10 @@
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
Compile(shaderc::Error), Compile(shaderc::Error),
Layout(ConvertError),
}
#[derive(Debug)]
pub enum ConvertError {
Unimplemented,
} }

@ -8,7 +8,7 @@ mod watch;
pub use layouts::*; pub use layouts::*;
pub use reflection::LayoutData; pub use reflection::LayoutData;
pub use watch::{Message, Watch}; pub use watch::{Message, Watch};
pub use error::Error; pub use error::{Error, ConvertError};
use spirv_reflect as sr; use spirv_reflect as sr;
use vulkano as vk; use vulkano as vk;
@ -20,7 +20,6 @@ pub struct CompiledShaders {
pub fragment: Vec<u32>, pub fragment: Vec<u32>,
} }
pub fn load<T>(vertex: T, fragment: T) -> Result<CompiledShaders, Error> pub fn load<T>(vertex: T, fragment: T) -> Result<CompiledShaders, Error>
where where
T: AsRef<Path>, T: AsRef<Path>,
@ -30,6 +29,6 @@ where
Ok(CompiledShaders{ vertex, fragment }) Ok(CompiledShaders{ vertex, fragment })
} }
pub fn parse(code: &CompiledShaders) -> Entry { pub fn parse(code: &CompiledShaders) -> Result<Entry, Error> {
reflection::create_entry(code) reflection::create_entry(code)
} }

@ -5,8 +5,10 @@ use crate::vk::descriptor::descriptor::*;
use crate::vk::descriptor::pipeline_layout::PipelineLayoutDescPcRange; use crate::vk::descriptor::pipeline_layout::PipelineLayoutDescPcRange;
use crate::vk::pipeline::shader::ShaderInterfaceDefEntry; use crate::vk::pipeline::shader::ShaderInterfaceDefEntry;
use crate::CompiledShaders; use crate::CompiledShaders;
use crate::error::Error;
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryFrom;
pub struct ShaderInterfaces { pub struct ShaderInterfaces {
pub inputs: Vec<ShaderInterfaceDefEntry>, pub inputs: Vec<ShaderInterfaceDefEntry>,
@ -22,11 +24,11 @@ pub struct LayoutData {
pub pc_ranges: Vec<PipelineLayoutDescPcRange>, pub pc_ranges: Vec<PipelineLayoutDescPcRange>,
} }
pub fn create_entry(shaders: &CompiledShaders) -> Entry { pub fn create_entry(shaders: &CompiledShaders) -> Result<Entry, Error> {
let vertex_interfaces = create_interfaces(&shaders.vertex); let vertex_interfaces = create_interfaces(&shaders.vertex);
let vertex_layout = create_layouts(&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 {
inputs: fragment_interfaces.inputs, inputs: fragment_interfaces.inputs,
}; };
@ -53,14 +55,14 @@ pub fn create_entry(shaders: &CompiledShaders) -> Entry {
}, },
layout_data: vertex_layout, layout_data: vertex_layout,
}; };
Entry { Ok(Entry {
frag_input, frag_input,
frag_output, frag_output,
vert_input, vert_input,
vert_output, vert_output,
frag_layout, frag_layout,
vert_layout, vert_layout,
} })
} }
fn create_interfaces(data: &[u32]) -> ShaderInterfaces { fn create_interfaces(data: &[u32]) -> ShaderInterfaces {
@ -105,11 +107,12 @@ fn create_interfaces(data: &[u32]) -> ShaderInterfaces {
.expect("failed to load module") .expect("failed to load module")
} }
fn create_layouts(data: &[u32]) -> LayoutData { fn create_layouts(data: &[u32]) -> Result<LayoutData, Error> {
sr::ShaderModule::load_u32_data(data) sr::ShaderModule::load_u32_data(data)
.map(|m| { .map(|m| {
let (num_sets, num_bindings, descriptions) = m //let (num_sets, num_bindings, descriptions) = m
.enumerate_descriptor_sets(None) let descs =
m.enumerate_descriptor_sets(None)
.map(|sets| { .map(|sets| {
let num_sets = sets.len(); let num_sets = sets.len();
let num_bindings = sets let num_bindings = sets
@ -130,7 +133,8 @@ fn create_layouts(data: &[u32]) -> LayoutData {
descriptor_type: b.descriptor_type, descriptor_type: b.descriptor_type,
image: b.image, image: b.image,
}; };
let ty = SpirvTy::<DescriptorDescTy>::from(info).inner(); let ty = SpirvTy::<DescriptorDescTy>::try_from(info)?;
let ty = ty.inner();
let stages = ShaderStages::none(); let stages = ShaderStages::none();
let d = DescriptorDesc { let d = DescriptorDesc {
ty, ty,
@ -140,17 +144,19 @@ fn create_layouts(data: &[u32]) -> LayoutData {
// it's correct // it's correct
readonly: true, readonly: true,
}; };
(b.binding as usize, d) Ok((b.binding as usize, d))
}) })
.flat_map(|d| d.ok())
.collect::<HashMap<usize, DescriptorDesc>>(); .collect::<HashMap<usize, DescriptorDesc>>();
(i.set as usize, desc) (i.set as usize, desc)
}) })
.collect::<HashMap<usize, HashMap<usize, DescriptorDesc>>>(); .collect::<HashMap<usize, HashMap<usize, DescriptorDesc>>>();
(num_sets, num_bindings, descriptions) (num_sets, num_bindings, descriptions)
}) })
.expect("Failed to pass descriptors"); .into_iter();
let (num_constants, pc_ranges) = m //let (num_constants, pc_ranges) = m
.enumerate_push_constant_blocks(None) let pcs =
m.enumerate_push_constant_blocks(None)
.map(|constants| { .map(|constants| {
let num_constants = constants.len(); let num_constants = constants.len();
let pc_ranges = constants let pc_ranges = constants
@ -163,14 +169,14 @@ fn create_layouts(data: &[u32]) -> LayoutData {
.collect::<Vec<PipelineLayoutDescPcRange>>(); .collect::<Vec<PipelineLayoutDescPcRange>>();
(num_constants, pc_ranges) (num_constants, pc_ranges)
}) })
.expect("Failed to pass push constants"); .into_iter();
descs.flat_map(|(num_sets, num_bindings, descriptions)| pcs.map(|(num_constants, pc_ranges)|
LayoutData { LayoutData {
num_sets, num_sets,
num_bindings, num_bindings,
descriptions, descriptions,
num_constants, num_constants,
pc_ranges, pc_ranges,
} })).next()
}) })
.expect("failed to load module")
} }

@ -1,7 +1,9 @@
use crate::sr; use crate::sr;
use crate::vk; use crate::vk;
use crate::error::{ConvertError, Error};
use vk::descriptor::descriptor::*; use vk::descriptor::descriptor::*;
use vk::format::Format; use vk::format::Format;
use std::convert::TryFrom;
pub struct SpirvTy<T> { pub struct SpirvTy<T> {
inner: T, inner: T,
@ -12,34 +14,35 @@ pub struct DescriptorDescInfo {
pub image: sr::types::ReflectImageTraits, pub image: sr::types::ReflectImageTraits,
} }
impl<T> SpirvTy<T> { impl<T> SpirvTy<T> {
pub fn inner(self) -> T { pub fn inner(self) -> T {
self.inner self.inner
} }
} }
impl From<DescriptorDescInfo> for SpirvTy<DescriptorDescTy> { impl TryFrom<DescriptorDescInfo> for SpirvTy<DescriptorDescTy> {
fn from(d: DescriptorDescInfo) -> Self { type Error = Error;
fn try_from(d: DescriptorDescInfo) -> Result<Self, Self::Error> {
use sr::types::ReflectDescriptorType as SR; use sr::types::ReflectDescriptorType as SR;
use DescriptorDescTy as VK; use DescriptorDescTy as VK;
let t = match d.descriptor_type { match d.descriptor_type {
SR::Undefined => unreachable!(), SR::Undefined => Err(ConvertError::Unimplemented),
SR::Sampler => VK::Sampler, SR::Sampler => Ok(VK::Sampler),
SR::CombinedImageSampler => VK::CombinedImageSampler(SpirvTy::from(d.image).inner()), SR::CombinedImageSampler => Ok(VK::CombinedImageSampler(SpirvTy::from(d.image).inner())),
SR::SampledImage => unreachable!(), SR::SampledImage => Err(ConvertError::Unimplemented),
SR::StorageImage => unreachable!(), SR::StorageImage => Err(ConvertError::Unimplemented),
SR::UniformTexelBuffer => unreachable!(), SR::UniformTexelBuffer => Err(ConvertError::Unimplemented),
SR::StorageTexelBuffer => unreachable!(), SR::StorageTexelBuffer => Err(ConvertError::Unimplemented),
SR::UniformBuffer => unreachable!(), SR::UniformBuffer => Err(ConvertError::Unimplemented),
SR::StorageBuffer => unreachable!(), SR::StorageBuffer => Err(ConvertError::Unimplemented),
SR::UniformBufferDynamic => unreachable!(), SR::UniformBufferDynamic => Err(ConvertError::Unimplemented),
SR::StorageBufferDynamic => unreachable!(), SR::StorageBufferDynamic => Err(ConvertError::Unimplemented),
SR::InputAttachment => unreachable!(), SR::InputAttachment => Err(ConvertError::Unimplemented),
SR::AccelerationStructureNV => unreachable!(), SR::AccelerationStructureNV => Err(ConvertError::Unimplemented),
}; }
SpirvTy { .map(|t| SpirvTy{ inner: t })
inner: t, .map_err(|e| Error::Layout(e))
}
} }
} }
@ -136,7 +139,7 @@ impl From<sr::types::ReflectFormat> for SpirvTy<Format> {
use sr::types::ReflectFormat::*; use sr::types::ReflectFormat::*;
use Format::*; use Format::*;
let t = match f { let t = match f {
Undefined => unreachable!(), Undefined => unimplemented!(),
R32_UINT => R32Uint, R32_UINT => R32Uint,
R32_SINT => R32Sint, R32_SINT => R32Sint,
R32_SFLOAT => R32Sfloat, R32_SFLOAT => R32Sfloat,

Loading…
Cancel
Save