fix Vulkan errors on Wayland and Intel GPU

capabilities.min_image_count is 4 on my system, which is larger than
the hard-coded 2.

Use a default swapchain size if we're not getting any size information
from the surface capabilities.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur 2021-03-19 12:18:57 +01:00
parent 44bff2726c
commit 22eb418832
2 changed files with 10 additions and 3 deletions

View file

@ -320,6 +320,8 @@ impl VkInstance {
pub unsafe fn swapchain(
&self,
width: usize,
height: usize,
device: &VkDevice,
surface: &VkSurface,
) -> Result<VkSwapchain, Error> {
@ -353,8 +355,13 @@ impl VkInstance {
.find(|mode| mode == &vk::PresentModeKHR::MAILBOX)
.unwrap_or(vk::PresentModeKHR::FIFO);
let image_count = 2; // TODO
let extent = capabilities.current_extent; // TODO: wayland for example will complain here ..
let image_count = capabilities.min_image_count;
let mut extent = capabilities.current_extent;
if extent.width == u32::MAX || extent.height == u32::MAX {
// We're deciding the size.
extent.width = width as u32;
extent.height = height as u32;
}
let create_info = vk::SwapchainCreateInfoKHR::builder()
.surface(surface.surface)

View file

@ -25,7 +25,7 @@ fn main() -> Result<(), Error> {
let (instance, surface) = VkInstance::new(Some(&window))?;
unsafe {
let device = instance.device(surface.as_ref())?;
let mut swapchain = instance.swapchain(&device, surface.as_ref().unwrap())?;
let mut swapchain = instance.swapchain(WIDTH / 2, HEIGHT / 2, &device, surface.as_ref().unwrap())?;
let session = hub::Session::new(device);
let mut current_frame = 0;