Skip to content

Commit

Permalink
Workaround for Image::getMipViewCreateInfos() build error in Clang.
Browse files Browse the repository at this point in the history
  • Loading branch information
stripe2933 committed Oct 6, 2024
1 parent efcd1e0 commit 030d599
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions interface/images/Image.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ import :utils;
#define NOEXCEPT_IF_RELEASE
#endif

// This macro is for Clang's false-positive build error when using lambda in initializer of non-inline variable in named
// modules. We can specify the inline keyword to workaround this.
// See: https://github.com/llvm/llvm-project/issues/110146
// TODO: remove this macro when the issue fixed.
#if __clang__
#define CLANG_INLINE inline
#else
#define CLANG_INLINE
#endif

namespace vku {
/**
* A thin wrapper around <tt>vk::Image</tt> with additional information such as extent, format, mip levels and array
Expand Down Expand Up @@ -75,11 +85,11 @@ namespace vku {
* Get <tt>vk::ImageViewCreateInfo</tt> structs for all mip levels with the specified \p type. Aspect flags are
* inferred from the image format.
* @param type Image view type (default=<tt>vk::ImageViewType::e2D<tt>).
* @return Vector of <tt>vk::ImageViewCreateInfo</tt> structs for all mip levels.
* @return Range of <tt>vk::ImageViewCreateInfo</tt> structs for all mip levels.
* @note See <tt>inferAspectFlags(vk::Format)</tt> for aspect flags inference rule.
* @note It internally calls <tt>inferAspectFlags(vk::Format)</tt> and <tt>getViewCreateInfo(const vk::ImageSubresourceRange&, vk::ImageViewType)</tt>.
*/
[[nodiscard]] auto getMipViewCreateInfos(VULKAN_HPP_NAMESPACE::ImageViewType type = VULKAN_HPP_NAMESPACE::ImageViewType::e2D) const NOEXCEPT_IF_RELEASE -> std::vector<VULKAN_HPP_NAMESPACE::ImageViewCreateInfo> {
[[nodiscard]] CLANG_INLINE auto getMipViewCreateInfos(VULKAN_HPP_NAMESPACE::ImageViewType type = VULKAN_HPP_NAMESPACE::ImageViewType::e2D) const NOEXCEPT_IF_RELEASE {
return std::views::iota(0U, mipLevels)
| std::views::transform([&, aspectFlags = inferAspectFlags(format)](std::uint32_t level) {
return VULKAN_HPP_NAMESPACE::ImageViewCreateInfo {
Expand All @@ -90,8 +100,7 @@ namespace vku {
{},
{ aspectFlags, level, 1, 0, VULKAN_HPP_NAMESPACE::RemainingArrayLayers }
};
})
| std::ranges::to<std::vector>();
});
}

/**
Expand Down

0 comments on commit 030d599

Please sign in to comment.