diff --git a/base/VulkanTools.cpp b/base/VulkanTools.cpp index d4b0317e..53d309f9 100644 --- a/base/VulkanTools.cpp +++ b/base/VulkanTools.cpp @@ -79,7 +79,7 @@ namespace vks // Since all depth formats may be optional, we need to find a suitable depth format to use // Start with the highest precision packed format std::vector depthFormats = { - VK_FORMAT_D32_SFLOAT_S8_UINT, + //VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D16_UNORM_S8_UINT, @@ -101,6 +101,17 @@ namespace vks return false; } + VkBool32 formatHasStencil(VkFormat format) + { + std::vector stencilFormats = { + VK_FORMAT_S8_UINT, + VK_FORMAT_D16_UNORM_S8_UINT, + VK_FORMAT_D24_UNORM_S8_UINT, + VK_FORMAT_D32_SFLOAT_S8_UINT, + }; + return std::find(stencilFormats.begin(), stencilFormats.end(), format) != std::end(stencilFormats); + } + // Returns if a given format support LINEAR filtering VkBool32 formatIsFilterable(VkPhysicalDevice physicalDevice, VkFormat format, VkImageTiling tiling) { diff --git a/base/VulkanTools.h b/base/VulkanTools.h index d392e401..b28e0ebc 100644 --- a/base/VulkanTools.h +++ b/base/VulkanTools.h @@ -78,8 +78,10 @@ namespace vks // Returns false if none of the depth formats in the list is supported by the device VkBool32 getSupportedDepthFormat(VkPhysicalDevice physicalDevice, VkFormat *depthFormat); - // Returns if a given format support LINEAR filtering + // Returns tru a given format support LINEAR filtering VkBool32 formatIsFilterable(VkPhysicalDevice physicalDevice, VkFormat format, VkImageTiling tiling); + // Returns true if a given format has a stencil part + VkBool32 formatHasStencil(VkFormat format); // Put an image memory barrier for setting an image layout on the sub resource into the given command buffer void setImageLayout( diff --git a/examples/bloom/bloom.cpp b/examples/bloom/bloom.cpp index a775c00b..08d1fd34 100644 --- a/examples/bloom/bloom.cpp +++ b/examples/bloom/bloom.cpp @@ -196,7 +196,10 @@ public: depthStencilView.format = depthFormat; depthStencilView.flags = 0; depthStencilView.subresourceRange = {}; - depthStencilView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + depthStencilView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + if (vks::tools::formatHasStencil(depthFormat)) { + depthStencilView.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; + } depthStencilView.subresourceRange.baseMipLevel = 0; depthStencilView.subresourceRange.levelCount = 1; depthStencilView.subresourceRange.baseArrayLayer = 0;