Ensure depth image exists at current swapchain extent.
Creates or recreates a D32_SFLOAT depth image matching the swapchain extent. No-op if depth image already matches.
701{
702 if (!ctx.swapchain) {
703 return;
704 }
705
706 auto extent = ctx.swapchain->get_extent();
707
708 if (ctx.depth_image && ctx.depth_image->is_initialized()
709 && ctx.depth_image->get_width() == extent.width
710 && ctx.depth_image->get_height() == extent.height) {
711 return;
712 }
713
715
716 if (ctx.depth_image && ctx.depth_image->is_initialized()) {
717 device.waitIdle();
718 const auto& res = ctx.depth_image->get_image_resources();
719 if (res.image_view) {
720 device.destroyImageView(res.image_view);
721 }
722 if (res.memory) {
723 device.freeMemory(res.memory);
724 }
725 if (res.image) {
726 device.destroyImage(res.image);
727 }
728 ctx.depth_image.reset();
729 }
730
731 ctx.depth_image = std::make_shared<VKImage>(
732 extent.width, extent.height, 1,
733 vk::Format::eD32Sfloat,
736 1, 1,
738
740
741 if (!ctx.depth_image->is_initialized()) {
743 "Failed to create depth image for window '{}'",
744 ctx.window->get_create_info().title);
745 ctx.depth_image.reset();
746 return;
747 }
748
750 ctx.depth_image->get_image(),
751 vk::ImageLayout::eUndefined,
752 vk::ImageLayout::eDepthStencilAttachmentOptimal,
753 1, 1,
754 vk::ImageAspectFlagBits::eDepth);
755 ctx.depth_image->set_current_layout(vk::ImageLayout::eDepthStencilAttachmentOptimal);
756
758 "Created depth image for window '{}': {}x{}, D32_SFLOAT",
759 ctx.window->get_create_info().title,
760 extent.width, extent.height);
761}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
void initialize_image(const std::shared_ptr< VKImage > &image)
Initialize a VKImage (allocate VkImage, memory, and create image view)
void transition_image_layout(vk::Image image, vk::ImageLayout old_layout, vk::ImageLayout new_layout, uint32_t mip_levels=1, uint32_t array_layers=1, vk::ImageAspectFlags aspect_flags=vk::ImageAspectFlagBits::eColor)
Transition image layout using a pipeline barrier.
BackendResourceManager * m_resource_manager
vk::Device get_device() const
Get logical device.
@ DEPTH_STENCIL
Depth/stencil attachment.
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.
@ IMAGE_2D
2D image (grayscale or single channel)