more descriptor implimentations

master
Tom Gowan 6 years ago
parent 52946a0ec3
commit f753563525

@ -1,9 +1,9 @@
use crate::sr;
use crate::vk;
use crate::error::{ConvertError, Error}; use crate::error::{ConvertError, Error};
use crate::sr;
use crate::vk;
use std::convert::TryFrom;
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,
@ -14,7 +14,6 @@ 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
@ -29,19 +28,27 @@ impl TryFrom<DescriptorDescInfo> for SpirvTy<DescriptorDescTy> {
match d.descriptor_type { match d.descriptor_type {
SR::Undefined => Err(ConvertError::Unimplemented), SR::Undefined => Err(ConvertError::Unimplemented),
SR::Sampler => Ok(VK::Sampler), SR::Sampler => Ok(VK::Sampler),
SR::CombinedImageSampler => Ok(VK::CombinedImageSampler(SpirvTy::try_from(d.image)?.inner())), SR::CombinedImageSampler => Ok(VK::CombinedImageSampler(
SR::SampledImage => Err(ConvertError::Unimplemented), SpirvTy::try_from(d.image)?.inner(),
)),
SR::SampledImage => Ok(VK::Image(SpirvTy::try_from(d.image)?.inner())),
SR::StorageImage => Err(ConvertError::Unimplemented), SR::StorageImage => Err(ConvertError::Unimplemented),
SR::UniformTexelBuffer => Err(ConvertError::Unimplemented), SR::UniformTexelBuffer => Ok(VK::TexelBuffer {
SR::StorageTexelBuffer => Err(ConvertError::Unimplemented), storage: false,
SR::UniformBuffer => Err(ConvertError::Unimplemented), format: None,
SR::StorageBuffer => Err(ConvertError::Unimplemented), }),
SR::UniformBufferDynamic => Err(ConvertError::Unimplemented), SR::StorageTexelBuffer => Ok(VK::TexelBuffer {
SR::StorageBufferDynamic => Err(ConvertError::Unimplemented), storage: false,
SR::InputAttachment => Err(ConvertError::Unimplemented), format: None,
}),
SR::UniformBuffer => Ok(VK::Buffer(DescriptorBufferDesc{ dynamic: Some(false), storage: false })),
SR::StorageBuffer => Ok(VK::Buffer(DescriptorBufferDesc{ dynamic: Some(false), storage: true })),
SR::UniformBufferDynamic => Ok(VK::Buffer(DescriptorBufferDesc{ dynamic: Some(true), storage: false })),
SR::StorageBufferDynamic => Ok(VK::Buffer(DescriptorBufferDesc{ dynamic: Some(true), storage: true })),
SR::InputAttachment => Ok(SpirvTy::try_from(d.image)?.inner()),
SR::AccelerationStructureNV => Err(ConvertError::Unimplemented), SR::AccelerationStructureNV => Err(ConvertError::Unimplemented),
} }
.map(|t| SpirvTy{ inner: t }) .map(|t| SpirvTy { inner: t })
.map_err(Error::Layout) .map_err(Error::Layout)
} }
} }
@ -49,9 +56,11 @@ impl TryFrom<DescriptorDescInfo> for SpirvTy<DescriptorDescTy> {
impl TryFrom<sr::types::ReflectImageTraits> for SpirvTy<DescriptorImageDesc> { impl TryFrom<sr::types::ReflectImageTraits> for SpirvTy<DescriptorImageDesc> {
type Error = Error; type Error = Error;
fn try_from(d: sr::types::ReflectImageTraits) -> Result<Self, Self::Error> { fn try_from(d: sr::types::ReflectImageTraits) -> Result<Self, Self::Error> {
let conv_array_layers = |a, d|{ let conv_array_layers = |a, d| {
if a != 0 { if a != 0 {
DescriptorImageDescArray::Arrayed{max_layers: Some(d)} DescriptorImageDescArray::Arrayed {
max_layers: Some(d),
}
} else { } else {
DescriptorImageDescArray::NonArrayed DescriptorImageDescArray::NonArrayed
} }
@ -65,10 +74,29 @@ impl TryFrom<sr::types::ReflectImageTraits> for SpirvTy<DescriptorImageDesc> {
multisampled: d.ms != 0, multisampled: d.ms != 0,
array_layers: conv_array_layers(d.arrayed, d.depth), array_layers: conv_array_layers(d.arrayed, d.depth),
}; };
Ok(SpirvTy{inner: t}) Ok(SpirvTy { inner: t })
} }
} }
impl TryFrom<sr::types::ReflectImageTraits> for SpirvTy<DescriptorDescTy> {
type Error = Error;
fn try_from(d: sr::types::ReflectImageTraits) -> Result<Self, Self::Error> {
let conv_array_layers = |a, d| {
if a != 0 {
DescriptorImageDescArray::Arrayed {
max_layers: Some(d),
}
} else {
DescriptorImageDescArray::NonArrayed
}
};
let t = DescriptorDescTy::InputAttachment {
multisampled: d.ms != 0,
array_layers: conv_array_layers(d.arrayed, d.depth),
};
Ok(SpirvTy { inner: t })
}
}
impl TryFrom<sr::types::variable::ReflectDimension> for SpirvTy<DescriptorImageDescDimensions> { impl TryFrom<sr::types::variable::ReflectDimension> for SpirvTy<DescriptorImageDescDimensions> {
type Error = Error; type Error = Error;
fn try_from(d: sr::types::variable::ReflectDimension) -> Result<Self, Self::Error> { fn try_from(d: sr::types::variable::ReflectDimension) -> Result<Self, Self::Error> {
@ -81,7 +109,7 @@ impl TryFrom<sr::types::variable::ReflectDimension> for SpirvTy<DescriptorImageD
sr::types::variable::ReflectDimension::Cube => Ok(DescriptorImageDescDimensions::Cube), sr::types::variable::ReflectDimension::Cube => Ok(DescriptorImageDescDimensions::Cube),
_ => Err(ConvertError::Unimplemented), _ => Err(ConvertError::Unimplemented),
} }
.map(|t| SpirvTy{ inner: t }) .map(|t| SpirvTy { inner: t })
.map_err(Error::Layout) .map_err(Error::Layout)
} }
} }
@ -103,7 +131,7 @@ impl From<sr::types::image::ReflectImageFormat> for SpirvTy<Format> {
R11G11B10_FLOAT => unimplemented!(), R11G11B10_FLOAT => unimplemented!(),
R16_FLOAT => R16Sfloat, R16_FLOAT => R16Sfloat,
RGBA16 => unimplemented!(), RGBA16 => unimplemented!(),
RGB10A2 => unimplemented!(), RGB10A2 => unimplemented!(),
RG16 => unimplemented!(), RG16 => unimplemented!(),
RG8 => unimplemented!(), RG8 => unimplemented!(),
R16 => unimplemented!(), R16 => unimplemented!(),
@ -130,11 +158,11 @@ impl From<sr::types::image::ReflectImageFormat> for SpirvTy<Format> {
RG32_UINT => R32G32Uint, RG32_UINT => R32G32Uint,
RG16_UINT => R16G16Uint, RG16_UINT => R16G16Uint,
RG8_UINT => R8G8Uint, RG8_UINT => R8G8Uint,
R16_UINT =>R16Uint, R16_UINT => R16Uint,
R8_UINT =>R8Uint, R8_UINT => R8Uint,
}; };
SpirvTy{ inner }; SpirvTy { inner };
// This function shouldn't be called yet because // This function shouldn't be called yet because
// it is not implemented correctly // it is not implemented correctly
unreachable!() unreachable!()
} }

Loading…
Cancel
Save