Vulkan-Samples icon indicating copy to clipboard operation
Vulkan-Samples copied to clipboard

"Extent size is not unique" HPPVulkanException thrown on Android for almost any sample

Open cmannett85 opened this issue 7 months ago • 6 comments

Running on Android 15 on a Pixel 8, though I think it's the Android part that's important:

[error] Error Message: Extent size is not unique : ERROR_INITIALIZATION_FAILED

More info in the debugger (specifically this is from the texture_loading sample):

(lldb) bt
* thread #28, name = 'Thread-2', stop reason = breakpoint 1.1
  * frame #0: 0x00000070b41f9d94 libvulkan_samples.so`vkb::rendering::RenderTarget<(vkb::BindingType)1>::init(this=0xb40000739ec54d80, images_=size=0) at render_target.h:248:3
    frame #1: 0x00000070b41f98e0 libvulkan_samples.so`vkb::rendering::RenderTarget<(vkb::BindingType)1>::RenderTarget(this=0xb40000739ec54d80, images=size=0) at render_target.h:224:3
    frame #2: 0x00000070b41f7048 libvulkan_samples.so`std::__ndk1::__unique_if<vkb::rendering::RenderTarget<(vkb::BindingType)1>>::__unique_single std::__ndk1::make_unique[abi:ne190000]<vkb::rendering::RenderTarget<(vkb::BindingType)1>, std::__ndk1::vector<vkb::core::HPPImage, std::__ndk1::allocator<vkb::core::HPPImage>>>(__args=size=0) at unique_ptr.h:621:30
    frame #3: 0x00000070b41f6b74 libvulkan_samples.so`vkb::rendering::RenderTarget<(vkb::BindingType)1>::default_create_func_impl(swapchain_image=0x00000071c477a090) at render_target.h:214:9
    frame #4: 0x00000070b41f69d0 libvulkan_samples.so`vkb::rendering::RenderTarget<(vkb::BindingType)1>::DEFAULT_CREATE_FUNC::'lambda'(this=0xb4000071eec59d38, swapchain_image=0x00000071c477a090)::operator()(vkb::core::HPPImage&&) const at render_target.h:192:10
    frame #10: 0x00000070b4345410 libvulkan_samples.so`std::__ndk1::function<std::__ndk1::unique_ptr<vkb::rendering::RenderTarget<(vkb::BindingType)1>, std::__ndk1::default_delete<vkb::rendering::RenderTarget<(vkb::BindingType)1>>> (vkb::core::HPPImage&&)>::operator()(this=0xb4000071eec59d30, __arg=0x00000071c477a090) const at function.h:981:10
    frame #11: 0x00000070b43e6e50 libvulkan_samples.so`vkb::rendering::RenderContext<(vkb::BindingType)1>::prepare(this=0xb4000071eec59d10, thread_count=1, create_render_target_func_=vkb::rendering::RenderTarget<vkb::BindingType::Cpp>::CreateFunc @ 0x00000071c477a1f0) at render_context.h:660:40
    frame #12: 0x00000070b42f05e4 libvulkan_samples.so`vkb::VulkanSample<(vkb::BindingType)0>::prepare_render_context(this=0xb4000072aeca2bb0) at vulkan_sample.h:1374:18
    frame #13: 0x00000070b42e2ef8 libvulkan_samples.so`vkb::VulkanSample<(vkb::BindingType)0>::prepare(this=0xb4000072aeca2bb0, options=0x00000071c477b090) at vulkan_sample.h:1344:2
    frame #14: 0x00000070b42dcce0 libvulkan_samples.so`ApiVulkanSample::prepare(this=0xb4000072aeca2bb0, options=0x00000071c477b090) at api_vulkan_sample.cpp:34:21
    frame #15: 0x00000070b4958d20 libvulkan_samples.so`TextureLoading::prepare(this=0xb4000072aeca2bb0, options=0x00000071c477b090) at texture_loading.cpp:720:24
    frame #16: 0x00000070b422d1a0 libvulkan_samples.so`vkb::Platform::start_app(this=0x00000071c477b440) at platform.cpp:480:19
    frame #17: 0x00000070b422c988 libvulkan_samples.so`vkb::Platform::main_loop_frame(this=0x00000071c477b440) at platform.cpp:198:9
    frame #18: 0x00000070b422dab0 libvulkan_samples.so`vkb::Platform::main_loop(this=0x00000071c477b440) at platform.cpp:255:15
    frame #19: 0x00000070b4221588 libvulkan_samples.so`platform_main(context=0xb40000732ec6ec10) at main.cpp:67:19
    frame #20: 0x00000070b422149c libvulkan_samples.so`android_main(state=0xb4000072bec764d0) at main.cpp:43:1
    frame #21: 0x00000070b4dd50d4 libvulkan_samples.so`android_app_entry(param=0xb4000072bec764d0) at android_native_app_glue.c:236:5
    frame #22: 0x0000007479adb378 libc.so`__pthread_start(void*) + 184
    frame #23: 0x0000007479acd0a4 libc.so`__start_thread + 68
(lldb) p unique_extent
(std::set<vk::Extent2D>) size=2 {
  [0] = (width = 1080, height = 2400)
  [1] = (width = 1080, height = 2400)
}

So it's failing because the std::less function object used by std::set appears to be giving the wrong results. Using the debug console further:

(lldb) p (vk::Extent2D{1080, 2400} < vk::Extent2D{1080, 2400})
error: Couldn't look up symbols:
  vk::Extent2D::operator VkExtent2D*()
Hint: The expression tried to call a function that is not present in the target, perhaps because it was optimized out by the compiler.
(lldb) p (vk::Extent2D{1080, 2400} == vk::Extent2D{1080, 2400})
(bool) true

The Vulkan C++ header (vulkan_structs.hpp:9959) has this:

#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR )
    auto operator<=>( Extent2D const & ) const = default;
#else
    bool operator==( Extent2D const & rhs ) const VULKAN_HPP_NOEXCEPT
    {
#  if defined( VULKAN_HPP_USE_REFLECT )
      return this->reflect() == rhs.reflect();
#  else
      return ( width == rhs.width ) && ( height == rhs.height );
#  endif
    }

    bool operator!=( Extent2D const & rhs ) const VULKAN_HPP_NOEXCEPT
    {
      return !operator==( rhs );
    }
#endif

There's no less-than operator if VULKAN_HPP_HAS_SPACESHIP_OPERATOR is false...

cmannett85 avatar Apr 15 '26 10:04 cmannett85

I've just confirmed that VULKAN_HPP_HAS_SPACESHIP_OPERATOR is indeed false. I'm surprised it even compiles.

cmannett85 avatar Apr 15 '26 11:04 cmannett85

I also get this error, never got it to work on Android , I had to literally compile for windows then run the exe through an emulator just to test my things, and I only got hello triangle sample to work and Swapchain recreation , so thanks for figuring it out

hodayfa000-h avatar Apr 15 '26 14:04 hodayfa000-h

@hodayfa000-h it's easy to workaround, just replace the default function object type in the std::set for a custom one that implements operator<(..) properly.

cmannett85 avatar Apr 15 '26 15:04 cmannett85

Alright thanks I'll try that and see Edit: I tried, it absolutely works now! So that's great.

hodayfa000-h avatar Apr 15 '26 15:04 hodayfa000-h

This looks like a bug indeed. We'll have it fixed.

SaschaWillems avatar Apr 15 '26 15:04 SaschaWillems

We could resolve this issue very specifically, by providing a bool operator<(vk::Extent2D const & lhs, vk::Extent2D const & rhs).

Or we could resolve it somewhat more generally, by #include <vulkan/vulkan_hash.hpp>, which provide overloads of std::hash for all the vulkan structs and handles, and use a std::unordered_set<vk::Extent2D> instead of a std::set<vk::Extent2D>

As we're actually not interested in sorting the extents, but just determining different ones, and a std::unordered_set mirrors that intent more naturally, I would prefer to unconditionally use the approach using the std::unordered_set.

asuessenbach avatar Apr 16 '26 08:04 asuessenbach