From e375779cd421970aae7d66d8197a34c1417d7504 Mon Sep 17 00:00:00 2001 From: swayam singal Date: Wed, 29 Jul 2026 11:16:00 +0530 Subject: [PATCH 1/2] Fix depth-stencil image aspect masks --- attachments/32_ecosystem_utilities.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/attachments/32_ecosystem_utilities.cpp b/attachments/32_ecosystem_utilities.cpp index a0a4c2d2..b5154c16 100644 --- a/attachments/32_ecosystem_utilities.cpp +++ b/attachments/32_ecosystem_utilities.cpp @@ -137,6 +137,7 @@ class HelloTriangleApplication vk::raii::Image depthImage = nullptr; vk::raii::DeviceMemory depthImageMemory = nullptr; vk::raii::ImageView depthImageView = nullptr; + vk::ImageAspectFlags depthImageAspect = vk::ImageAspectFlagBits::eDepth; uint32_t mipLevels = 0; vk::raii::Image textureImage = nullptr; @@ -811,9 +812,14 @@ class HelloTriangleApplication void createDepthResources() { vk::Format depthFormat = findDepthFormat(); + depthImageAspect = vk::ImageAspectFlagBits::eDepth; + if (hasStencilComponent(depthFormat)) + { + depthImageAspect |= vk::ImageAspectFlagBits::eStencil; + } createImage(swapChainExtent.width, swapChainExtent.height, 1, msaaSamples, depthFormat, vk::ImageTiling::eOptimal, vk::ImageUsageFlagBits::eDepthStencilAttachment, vk::MemoryPropertyFlagBits::eDeviceLocal, depthImage, depthImageMemory); - depthImageView = createImageView(depthImage, depthFormat, vk::ImageAspectFlagBits::eDepth, 1); + depthImageView = createImageView(depthImage, depthFormat, depthImageAspect, 1); } vk::Format findSupportedFormat(const std::vector &candidates, vk::ImageTiling tiling, vk::FormatFeatureFlags features) const @@ -1376,7 +1382,7 @@ class HelloTriangleApplication .oldLayout = vk::ImageLayout::eUndefined, .newLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal, .image = *depthImage, - .subresourceRange = {vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1}}; + .subresourceRange = {depthImageAspect, 0, 1, 0, 1}}; vk::ImageMemoryBarrier2 swapchainBarrier{ .srcStageMask = vk::PipelineStageFlagBits2::eColorAttachmentOutput, @@ -1416,7 +1422,7 @@ class HelloTriangleApplication .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = *depthImage, - .subresourceRange = {vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1}}; + .subresourceRange = {depthImageAspect, 0, 1, 0, 1}}; vk::ImageMemoryBarrier swapchainBarrier{ .srcAccessMask = vk::AccessFlagBits::eNone, From f2b8e25f521682f12d4beaacda1b2a81cd03cb51 Mon Sep 17 00:00:00 2001 From: swayam singal Date: Wed, 29 Jul 2026 14:38:49 +0530 Subject: [PATCH 2/2] Use Vulkan format stencil helper --- attachments/32_ecosystem_utilities.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/attachments/32_ecosystem_utilities.cpp b/attachments/32_ecosystem_utilities.cpp index b5154c16..16352b3e 100644 --- a/attachments/32_ecosystem_utilities.cpp +++ b/attachments/32_ecosystem_utilities.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #if defined(__INTELLISENSE__) || !defined(USE_CPP20_MODULES) # include @@ -813,7 +814,7 @@ class HelloTriangleApplication { vk::Format depthFormat = findDepthFormat(); depthImageAspect = vk::ImageAspectFlagBits::eDepth; - if (hasStencilComponent(depthFormat)) + if (vk::hasStencilComponent(depthFormat)) { depthImageAspect |= vk::ImageAspectFlagBits::eStencil; } @@ -849,11 +850,6 @@ class HelloTriangleApplication vk::FormatFeatureFlagBits::eDepthStencilAttachment); } - static bool hasStencilComponent(vk::Format format) - { - return format == vk::Format::eD32SfloatS8Uint || format == vk::Format::eD24UnormS8Uint; - } - void createTextureImage() { int texWidth, texHeight, texChannels;