Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions attachments/32_ecosystem_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <optional>
#include <stdexcept>
#include <vector>
#include <vulkan/vulkan_format_traits.hpp>

#if defined(__INTELLISENSE__) || !defined(USE_CPP20_MODULES)
# include <vulkan/vulkan_raii.hpp>
Expand Down Expand Up @@ -137,6 +138,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;
Expand Down Expand Up @@ -811,9 +813,14 @@ class HelloTriangleApplication
void createDepthResources()
{
vk::Format depthFormat = findDepthFormat();
depthImageAspect = vk::ImageAspectFlagBits::eDepth;
if (vk::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<vk::Format> &candidates, vk::ImageTiling tiling, vk::FormatFeatureFlags features) const
Expand Down Expand Up @@ -843,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;
Expand Down Expand Up @@ -1376,7 +1378,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,
Expand Down Expand Up @@ -1416,7 +1418,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,
Expand Down
Loading