Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Better validation and errors #1966

Merged
merged 2 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions vulkano-shaders/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,27 +251,30 @@ fn write_impls<'a>(
) -> impl Iterator<Item = TokenStream> + 'a {
let struct_ident = format_ident!("{}", struct_name);

(types_meta.partial_eq.then(|| {
let fields = rust_members
.iter()
.filter(|Member { is_dummy, .. }| !is_dummy)
.map(|Member { name, .. }| {
quote! {
if self.#name != other.#name {
return false
(types_meta
.partial_eq
.then(|| {
let fields = rust_members
.iter()
.filter(|Member { is_dummy, .. }| !is_dummy)
.map(|Member { name, .. }| {
quote! {
if self.#name != other.#name {
return false
}
}
}
});
});

quote! {
impl PartialEq for #struct_ident {
fn eq(&self, other: &Self) -> bool {
#( #fields )*
true
quote! {
impl PartialEq for #struct_ident {
fn eq(&self, other: &Self) -> bool {
#( #fields )*
true
}
}
}
}
}).into_iter())
})
.into_iter())
.chain(types_meta.debug.then(|| {
let fields = rust_members
.iter()
Expand All @@ -283,8 +286,8 @@ fn write_impls<'a>(

quote! {
impl std::fmt::Debug for #struct_ident {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
formatter
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
f
.debug_struct(#struct_name)
#( #fields )*
.finish()
Expand All @@ -303,8 +306,8 @@ fn write_impls<'a>(

quote! {
impl std::fmt::Display for #struct_ident {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
formatter
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
f
.debug_struct(#struct_name)
#( #fields )*
.finish()
Expand All @@ -323,7 +326,12 @@ fn write_impls<'a>(
}
}
}))
.chain(types_meta.impls.iter().map(move |i| quote!{ #i for #struct_ident {} }))
.chain(
types_meta
.impls
.iter()
.map(move |i| quote! { #i for #struct_ident {} }),
)
}

fn has_defined_layout(spirv: &Spirv, struct_id: Id) -> bool {
Expand Down
14 changes: 10 additions & 4 deletions vulkano-win/src/winit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use std::{borrow::Borrow, error::Error, fmt, rc::Rc, sync::Arc};
use std::{
borrow::Borrow,
error::Error,
fmt::{Display, Error as FmtError, Formatter},
rc::Rc,
sync::Arc,
};
use vulkano::{
instance::{Instance, InstanceExtensions},
swapchain::{Surface, SurfaceCreationError},
Expand Down Expand Up @@ -80,11 +86,11 @@ impl Error for CreationError {
}
}

impl fmt::Display for CreationError {
impl Display for CreationError {
#[inline]
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
write!(
fmt,
f,
"{}",
match *self {
CreationError::SurfaceCreationError(_) => "error while creating the surface",
Expand Down
68 changes: 35 additions & 33 deletions vulkano/autogen/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
let requires_items = requires.iter().map(|require| {
let require_items = require.api_version.iter().map(|version| {
let version = format_ident!("V{}_{}", version.0, version.1);
quote! { api_version >= Version::#version }
quote! { api_version >= crate::Version::#version }
}).chain(require.instance_extensions.iter().map(|ext| {
quote! { instance_extensions.#ext }
})).chain(require.device_extensions.iter().map(|ext| {
Expand All @@ -114,19 +114,20 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {

let api_version_items = require.api_version.as_ref().map(|version| {
let version = format_ident!("V{}_{}", version.0, version.1);
quote! { Some(Version::#version) }
quote! { Some(crate::Version::#version) }
}).unwrap_or_else(|| quote!{ None });
let device_extensions_items = require.device_extensions.iter().map(|ext| ext.to_string());
let instance_extensions_items = require.instance_extensions.iter().map(|ext| ext.to_string());

quote! {
if !(#(#require_items)||*) {
return Err(ExtensionRestrictionError {
return Err(crate::device::ExtensionRestrictionError {
extension: #name_string,
restriction: ExtensionRestriction::Requires(OneOfRequirements {
restriction: crate::device::ExtensionRestriction::Requires(crate::RequiresOneOf {
api_version: #api_version_items,
device_extensions: &[#(#device_extensions_items),*],
instance_extensions: &[#(#instance_extensions_items),*],
..Default::default()
}),
})
}
Expand All @@ -136,19 +137,19 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
let string = extension.to_string();
quote! {
if self.#extension {
return Err(ExtensionRestrictionError {
return Err(crate::device::ExtensionRestrictionError {
extension: #name_string,
restriction: ExtensionRestriction::ConflictsDeviceExtension(#string),
restriction: crate::device::ExtensionRestriction::ConflictsDeviceExtension(#string),
});
}
}
});
let required_if_supported = if *required_if_supported {
quote! {
if supported.#name {
return Err(ExtensionRestrictionError {
return Err(crate::device::ExtensionRestrictionError {
extension: #name_string,
restriction: ExtensionRestriction::RequiredIfSupported,
restriction: crate::device::ExtensionRestriction::RequiredIfSupported,
});
}
}
Expand All @@ -159,9 +160,9 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
quote! {
if self.#name {
if !supported.#name {
return Err(ExtensionRestrictionError {
return Err(crate::device::ExtensionRestrictionError {
extension: #name_string,
restriction: ExtensionRestriction::NotSupported,
restriction: crate::device::ExtensionRestriction::NotSupported,
});
}

Expand All @@ -181,9 +182,9 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
pub(super) fn check_requirements(
&self,
supported: &DeviceExtensions,
api_version: Version,
instance_extensions: &InstanceExtensions,
) -> Result<(), ExtensionRestrictionError> {
api_version: crate::Version,
instance_extensions: &crate::instance::InstanceExtensions,
) -> Result<(), crate::device::ExtensionRestrictionError> {
let device_extensions = self;
#(#check_requirements_items)*
Ok(())
Expand All @@ -207,7 +208,7 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
.iter()
.map(|version| {
let version = format_ident!("V{}_{}", version.0, version.1);
quote! { api_version >= Version::#version }
quote! { api_version >= crate::Version::#version }
})
.chain(require.instance_extensions.iter().map(|ext| {
quote! { instance_extensions.#ext }
Expand All @@ -221,7 +222,7 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
.as_ref()
.map(|version| {
let version = format_ident!("V{}_{}", version.0, version.1);
quote! { Some(Version::#version) }
quote! { Some(crate::Version::#version) }
})
.unwrap_or_else(|| quote! { None });
let device_extensions_items =
Expand All @@ -233,12 +234,13 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {

quote! {
if !(#(#require_items)||*) {
return Err(ExtensionRestrictionError {
return Err(crate::instance::ExtensionRestrictionError {
extension: #name_string,
restriction: ExtensionRestriction::Requires(OneOfRequirements {
restriction: crate::instance::ExtensionRestriction::Requires(crate::RequiresOneOf {
api_version: #api_version_items,
device_extensions: &[#(#device_extensions_items),*],
instance_extensions: &[#(#instance_extensions_items),*],
..Default::default()
}),
})
}
Expand All @@ -248,9 +250,9 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
quote! {
if self.#name {
if !supported.#name {
return Err(ExtensionRestrictionError {
return Err(crate::instance::ExtensionRestrictionError {
extension: #name_string,
restriction: ExtensionRestriction::NotSupported,
restriction: crate::instance::ExtensionRestriction::NotSupported,
});
}

Expand All @@ -267,8 +269,8 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
pub(super) fn check_requirements(
&self,
supported: &InstanceExtensions,
api_version: Version,
) -> Result<(), ExtensionRestrictionError> {
api_version: crate::Version,
) -> Result<(), crate::instance::ExtensionRestrictionError> {
let instance_extensions = self;
#(#check_requirements_items)*
Ok(())
Expand Down Expand Up @@ -348,7 +350,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
let from_extensions_for_vec_cstring_items =
members.iter().map(|ExtensionsMember { name, raw, .. }| {
quote! {
if x.#name { data.push(CString::new(#raw).unwrap()); }
if x.#name { data.push(std::ffi::CString::new(#raw).unwrap()); }
}
});

Expand Down Expand Up @@ -441,7 +443,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
}
}

impl BitAnd for #struct_name {
impl std::ops::BitAnd for #struct_name {
type Output = #struct_name;

#[inline]
Expand All @@ -450,14 +452,14 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
}
}

impl BitAndAssign for #struct_name {
impl std::ops::BitAndAssign for #struct_name {
#[inline]
fn bitand_assign(&mut self, rhs: Self) {
*self = self.union(&rhs);
}
}

impl BitOr for #struct_name {
impl std::ops::BitOr for #struct_name {
type Output = #struct_name;

#[inline]
Expand All @@ -466,14 +468,14 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
}
}

impl BitOrAssign for #struct_name {
impl std::ops::BitOrAssign for #struct_name {
#[inline]
fn bitor_assign(&mut self, rhs: Self) {
*self = self.intersection(&rhs);
}
}

impl BitXor for #struct_name {
impl std::ops::BitXor for #struct_name {
type Output = #struct_name;

#[inline]
Expand All @@ -482,14 +484,14 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
}
}

impl BitXorAssign for #struct_name {
impl std::ops::BitXorAssign for #struct_name {
#[inline]
fn bitxor_assign(&mut self, rhs: Self) {
*self = self.symmetric_difference(&rhs);
}
}

impl Sub for #struct_name {
impl std::ops::Sub for #struct_name {
type Output = #struct_name;

#[inline]
Expand All @@ -498,7 +500,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
}
}

impl SubAssign for #struct_name {
impl std::ops::SubAssign for #struct_name {
#[inline]
fn sub_assign(&mut self, rhs: Self) {
*self = self.difference(&rhs);
Expand All @@ -507,7 +509,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->

impl std::fmt::Debug for #struct_name {
#[allow(unused_assignments)]
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
write!(f, "[")?;

let mut first = true;
Expand All @@ -517,7 +519,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
}
}

impl<'a, I> From<I> for #struct_name where I: IntoIterator<Item = &'a CStr> {
impl<'a, I> From<I> for #struct_name where I: IntoIterator<Item = &'a std::ffi::CStr> {
fn from(names: I) -> Self {
let mut extensions = Self::empty();
for name in names {
Expand All @@ -530,7 +532,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
}
}

impl<'a> From<&'a #struct_name> for Vec<CString> {
impl<'a> From<&'a #struct_name> for Vec<std::ffi::CString> {
fn from(x: &'a #struct_name) -> Self {
let mut data = Self::new();
#(#from_extensions_for_vec_cstring_items)*
Expand Down
Loading