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.
459{
460 if (!ctx.swapchain) {
461 return;
462 }
463
464 auto extent = ctx.swapchain->get_extent();
465
466 if (ctx.depth_image && ctx.depth_image->is_initialized()
467 && ctx.depth_image->get_width() == extent.width
468 && ctx.depth_image->get_height() == extent.height) {
469 return;
470 }
471
473
474 if (ctx.depth_image && ctx.depth_image->is_initialized()) {
475 device.waitIdle();
476 const auto& res = ctx.depth_image->get_image_resources();
477 if (res.image_view) {
478 device.destroyImageView(res.image_view);
479 }
480 if (res.memory) {
481 device.freeMemory(res.memory);
482 }
483 if (res.image) {
484 device.destroyImage(res.image);
485 }
486 ctx.depth_image.reset();
487 }
488
489 ctx.depth_image = std::make_shared<VKImage>(
490 extent.width, extent.height, 1,
491 vk::Format::eD32Sfloat,
494 1, 1,
496
498
499 if (!ctx.depth_image->is_initialized()) {
501 "Failed to create depth image for window '{}'",
502 ctx.window->get_create_info().title);
503 ctx.depth_image.reset();
504 return;
505 }
506
508 ctx.depth_image->get_image(),
509 vk::ImageLayout::eUndefined,
510 vk::ImageLayout::eDepthStencilAttachmentOptimal,
511 1, 1,
512 vk::ImageAspectFlagBits::eDepth);
513 ctx.depth_image->set_current_layout(vk::ImageLayout::eDepthStencilAttachmentOptimal);
514
516 "Created depth image for window '{}': {}x{}, D32_SFLOAT",
517 ctx.window->get_create_info().title,
518 extent.width, extent.height);
519}
#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)