From 002d6fa9a4d4d2e635e3db73d5693e3b532383b2 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Sun, 17 Nov 2024 16:18:35 +0100 Subject: [PATCH] Move create_image_view to vkSwapchain->create_present_image_view --- src/vulkan/vk_device.rs | 26 -------------------------- src/vulkan/vk_swapchain.rs | 29 +++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/vulkan/vk_device.rs b/src/vulkan/vk_device.rs index d895d20..b6b550e 100644 --- a/src/vulkan/vk_device.rs +++ b/src/vulkan/vk_device.rs @@ -69,32 +69,6 @@ impl VkDevice { self.queues.get(queue_index as usize) } - pub(super) fn create_image_view( - &self, - image: vk::Image, - surface_format: vk::SurfaceFormatKHR, - ) -> VkResult { - let create_view_info = vk::ImageViewCreateInfo::default() - .view_type(vk::ImageViewType::TYPE_2D) - .format(surface_format.format) - .components(vk::ComponentMapping { - r: vk::ComponentSwizzle::R, - g: vk::ComponentSwizzle::G, - b: vk::ComponentSwizzle::B, - a: vk::ComponentSwizzle::A, - }) - .subresource_range(vk::ImageSubresourceRange { - aspect_mask: vk::ImageAspectFlags::COLOR, - base_mip_level: 0, - level_count: 1, - base_array_layer: 0, - layer_count: 1, - }) - .image(image); - - unsafe { self.handle.create_image_view(&create_view_info, None) } - } - pub(super) fn create_command_pool( &self, info: &vk::CommandPoolCreateInfo, diff --git a/src/vulkan/vk_swapchain.rs b/src/vulkan/vk_swapchain.rs index 6a4375e..3402796 100644 --- a/src/vulkan/vk_swapchain.rs +++ b/src/vulkan/vk_swapchain.rs @@ -96,8 +96,7 @@ impl VkSwapchain { let present_images_view = present_images .iter() .map(|i| { - self.device - .create_image_view(*i, self.surface_format) + self.create_present_image_view(*i) .expect("Failed to create image view") }) .collect::>(); @@ -210,6 +209,32 @@ impl VkSwapchain { .find(|&mode| mode == vk::PresentModeKHR::MAILBOX) .unwrap_or(vk::PresentModeKHR::FIFO) } + + fn create_present_image_view(&self, image: vk::Image) -> VkResult { + let create_view_info = vk::ImageViewCreateInfo::default() + .view_type(vk::ImageViewType::TYPE_2D) + .format(self.surface_format.format) + .components(vk::ComponentMapping { + r: vk::ComponentSwizzle::R, + g: vk::ComponentSwizzle::G, + b: vk::ComponentSwizzle::B, + a: vk::ComponentSwizzle::A, + }) + .subresource_range(vk::ImageSubresourceRange { + aspect_mask: vk::ImageAspectFlags::COLOR, + base_mip_level: 0, + level_count: 1, + base_array_layer: 0, + layer_count: 1, + }) + .image(image); + + unsafe { + self.device + .handle + .create_image_view(&create_view_info, None) + } + } } impl Drop for VkSwapchain {