Skip to content

Commit

Permalink
ValidationError-ify Surface and Swapchain (vulkano-rs#2236)
Browse files Browse the repository at this point in the history
* Add `RequiresAllOf`, automatically enable required extensions and features

* Add more missing backticks and backslashes to error messages

* Use updated VUIDs that require `acceleration_structure`

* ValidationError-ify `Surface` and `Swapchain`

* Update vulkano/src/lib.rs

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

* Update vulkano/src/lib.rs

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

* Don't draw if the window has zero size

---------

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>
  • Loading branch information
2 people authored and hakolao committed Feb 20, 2024
1 parent ec1a109 commit 772a204
Show file tree
Hide file tree
Showing 36 changed files with 3,586 additions and 2,906 deletions.
20 changes: 9 additions & 11 deletions examples/src/bin/async-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ use vulkano::{
sampler::{Sampler, SamplerCreateInfo},
swapchain::{
acquire_next_image, AcquireError, Surface, Swapchain, SwapchainCreateInfo,
SwapchainCreationError, SwapchainPresentInfo,
SwapchainPresentInfo,
},
sync::{self, FlushError, GpuFuture},
VulkanLibrary,
Expand Down Expand Up @@ -545,21 +545,19 @@ fn main() {
channel.send(()).unwrap();
}
Event::RedrawEventsCleared => {
let dimensions = window.inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
let image_extent: [u32; 2] = window.inner_size().into();

if image_extent.contains(&0) {
return;
}

if recreate_swapchain {
let (new_swapchain, new_images) =
match swapchain.recreate(SwapchainCreateInfo {
image_extent: dimensions.into(),
let (new_swapchain, new_images) = swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..swapchain.create_info()
}) {
Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => return,
Err(e) => panic!("failed to recreate swapchain: {e}"),
};
})
.expect("failed to recreate swapchain");

swapchain = new_swapchain;
framebuffers = window_size_dependent_setup(
Expand Down
20 changes: 9 additions & 11 deletions examples/src/bin/buffer-allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use vulkano::{
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
swapchain::{
acquire_next_image, AcquireError, Surface, Swapchain, SwapchainCreateInfo,
SwapchainCreationError, SwapchainPresentInfo,
SwapchainPresentInfo,
},
sync::{self, FlushError, GpuFuture},
VulkanLibrary,
Expand Down Expand Up @@ -292,23 +292,21 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = window.inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
let image_extent: [u32; 2] = window.inner_size().into();

if image_extent.contains(&0) {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) =
match swapchain.recreate(SwapchainCreateInfo {
image_extent: dimensions.into(),
let (new_swapchain, new_images) = swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..swapchain.create_info()
}) {
Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => return,
Err(e) => panic!("failed to recreate swapchain: {e}"),
};
})
.expect("failed to recreate swapchain");

swapchain = new_swapchain;
framebuffers = window_size_dependent_setup(
Expand Down
21 changes: 10 additions & 11 deletions examples/src/bin/clear_attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use vulkano::{
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass},
swapchain::{
acquire_next_image, AcquireError, Surface, Swapchain, SwapchainCreateInfo,
SwapchainCreationError, SwapchainPresentInfo,
SwapchainPresentInfo,
},
sync::{self, FlushError, GpuFuture},
VulkanLibrary,
Expand Down Expand Up @@ -175,22 +175,21 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = window.inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
let image_extent: [u32; 2] = window.inner_size().into();

if image_extent.contains(&0) {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => return,
Err(e) => panic!("failed to recreate swapchain: {e}"),
};
let (new_swapchain, new_images) = swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..swapchain.create_info()
})
.expect("failed to recreate swapchain");

swapchain = new_swapchain;
width = swapchain.image_extent()[0];
Expand Down
21 changes: 10 additions & 11 deletions examples/src/bin/deferred/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use vulkano::{
memory::allocator::StandardMemoryAllocator,
swapchain::{
acquire_next_image, AcquireError, Surface, Swapchain, SwapchainCreateInfo,
SwapchainCreationError, SwapchainPresentInfo,
SwapchainPresentInfo,
},
sync::{self, FlushError, GpuFuture},
VulkanLibrary,
Expand Down Expand Up @@ -199,22 +199,21 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = window.inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
let image_extent: [u32; 2] = window.inner_size().into();

if image_extent.contains(&0) {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => return,
Err(e) => panic!("failed to recreate swapchain: {e}"),
};
let (new_swapchain, new_images) = swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..swapchain.create_info()
})
.expect("failed to recreate swapchain");
let new_images = new_images
.into_iter()
.map(|image| ImageView::new_default(image).unwrap())
Expand Down
26 changes: 12 additions & 14 deletions examples/src/bin/gl-interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ mod linux {
},
render_pass::{Framebuffer, RenderPass, Subpass},
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo},
swapchain::{
AcquireError, Surface, Swapchain, SwapchainCreateInfo, SwapchainCreationError,
SwapchainPresentInfo,
},
swapchain::{AcquireError, Surface, Swapchain, SwapchainCreateInfo, SwapchainPresentInfo},
sync::{
now,
semaphore::{
Expand Down Expand Up @@ -287,20 +284,21 @@ mod linux {
})
.unwrap();

let image_extent: [u32; 2] = window.inner_size().into();

if image_extent.contains(&0) {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) =
match swapchain.recreate(SwapchainCreateInfo {
image_extent: window.inner_size().into(),
let (new_swapchain, new_images) = swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..swapchain.create_info()
}) {
Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => {
return
}
Err(e) => panic!("failed to recreate swapchain: {e}"),
};
})
.expect("failed to recreate swapchain");

swapchain = new_swapchain;
framebuffers = window_size_dependent_setup(
Expand Down
21 changes: 10 additions & 11 deletions examples/src/bin/image-self-copy-blit/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use vulkano::{
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo},
swapchain::{
acquire_next_image, AcquireError, Surface, Swapchain, SwapchainCreateInfo,
SwapchainCreationError, SwapchainPresentInfo,
SwapchainPresentInfo,
},
sync::{self, FlushError, GpuFuture},
VulkanLibrary,
Expand Down Expand Up @@ -421,22 +421,21 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = window.inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
let image_extent: [u32; 2] = window.inner_size().into();

if image_extent.contains(&0) {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => return,
Err(e) => panic!("failed to recreate swapchain: {e}"),
};
let (new_swapchain, new_images) = swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..swapchain.create_info()
})
.expect("failed to recreate swapchain");

swapchain = new_swapchain;
framebuffers =
Expand Down
21 changes: 10 additions & 11 deletions examples/src/bin/image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use vulkano::{
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo},
swapchain::{
acquire_next_image, AcquireError, Surface, Swapchain, SwapchainCreateInfo,
SwapchainCreationError, SwapchainPresentInfo,
SwapchainPresentInfo,
},
sync::{self, FlushError, GpuFuture},
VulkanLibrary,
Expand Down Expand Up @@ -347,22 +347,21 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = window.inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
let image_extent: [u32; 2] = window.inner_size().into();

if image_extent.contains(&0) {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => return,
Err(e) => panic!("failed to recreate swapchain: {e}"),
};
let (new_swapchain, new_images) = swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..swapchain.create_info()
})
.expect("failed to recreate swapchain");

swapchain = new_swapchain;
framebuffers =
Expand Down
21 changes: 10 additions & 11 deletions examples/src/bin/immutable-sampler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use vulkano::{
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo},
swapchain::{
acquire_next_image, AcquireError, Surface, Swapchain, SwapchainCreateInfo,
SwapchainCreationError, SwapchainPresentInfo,
SwapchainPresentInfo,
},
sync::{self, FlushError, GpuFuture},
VulkanLibrary,
Expand Down Expand Up @@ -368,22 +368,21 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = window.inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
let image_extent: [u32; 2] = window.inner_size().into();

if image_extent.contains(&0) {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => return,
Err(e) => panic!("failed to recreate swapchain: {e}"),
};
let (new_swapchain, new_images) = swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..swapchain.create_info()
})
.expect("failed to recreate swapchain");

swapchain = new_swapchain;
framebuffers =
Expand Down
20 changes: 9 additions & 11 deletions examples/src/bin/indirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use vulkano::{
single_pass_renderpass,
swapchain::{
acquire_next_image, AcquireError, Surface, Swapchain, SwapchainCreateInfo,
SwapchainCreationError, SwapchainPresentInfo,
SwapchainPresentInfo,
},
sync::{self, FlushError, GpuFuture},
VulkanLibrary,
Expand Down Expand Up @@ -384,23 +384,21 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = window.inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
let image_extent: [u32; 2] = window.inner_size().into();

if image_extent.contains(&0) {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) =
match swapchain.recreate(SwapchainCreateInfo {
image_extent: dimensions.into(),
let (new_swapchain, new_images) = swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..swapchain.create_info()
}) {
Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => return,
Err(e) => panic!("failed to recreate swapchain: {e}"),
};
})
.expect("failed to recreate swapchain");

swapchain = new_swapchain;
framebuffers = window_size_dependent_setup(
Expand Down
Loading

0 comments on commit 772a204

Please # to comment.