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.
724{
725 if (!ctx.swapchain) {
726 return;
727 }
728
729 auto extent = ctx.swapchain->get_extent();
730
731 if (ctx.depth_image && ctx.depth_image->is_initialized()
732 && ctx.depth_image->get_width() == extent.width
733 && ctx.depth_image->get_height() == extent.height) {
734 return;
735 }
736
738
739 if (ctx.depth_image && ctx.depth_image->is_initialized()) {
741 const auto& res = ctx.depth_image->get_image_resources();
742 if (res.image_view) {
743 device.destroyImageView(res.image_view);
744 }
745 if (res.memory) {
746 device.freeMemory(res.memory);
747 }
748 if (res.image) {
749 device.destroyImage(res.image);
750 }
751 ctx.depth_image.reset();
752 }
753
754 ctx.depth_image = std::make_shared<VKImage>(
755 extent.width, extent.height, 1,
756 vk::Format::eD32Sfloat,
759 1, 1,
761
763
764 if (!ctx.depth_image->is_initialized()) {
766 "Failed to create depth image for window '{}'",
767 ctx.window->get_create_info().title);
768 ctx.depth_image.reset();
769 return;
770 }
771
773 ctx.depth_image->get_image(),
774 vk::ImageLayout::eUndefined,
775 vk::ImageLayout::eDepthStencilAttachmentOptimal,
776 1, 1,
777 vk::ImageAspectFlagBits::eDepth);
778 ctx.depth_image->set_current_layout(vk::ImageLayout::eDepthStencilAttachmentOptimal);
779
781 "Created depth image for window '{}': {}x{}, D32_SFLOAT",
782 ctx.window->get_create_info().title,
783 extent.width, extent.height);
784}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
vk::PhysicalDevice device
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)