andy-thomason / Vookoo

A set of utilities for taking the pain out of Vulkan in header only modern C++
MIT License
522 stars 52 forks source link

Structured Binding compile error on createComputePipelineUnique #52

Open oceanusxiv opened 2 years ago

oceanusxiv commented 2 years ago

I think the fixes in #49 now causes incompatibility with the old vulkan 1.2 headers. Now you get when you compile.

error: cannot decompose inaccessible member ‘vk::UniqueHandle<vk::Pipeline, vk::DispatchLoaderStatic>::m_value’ of ‘vk::UniqueHandle<vk::Pipeline, vk::DispatchLoaderStatic>’

More specifically, it appears that at least on Ubuntu 20.04, the Vulkan headers being installed look like

  template<typename Dispatch>
  VULKAN_HPP_INLINE typename ResultValueType<UniqueHandle<Pipeline,Dispatch>>::type Device::createComputePipelineUnique( VULKAN_HPP_NAMESPACE::PipelineCache pipelineCache, const ComputePipelineCreateInfo & createInfo, Optional<const AllocationCallbacks> allocator, Dispatch const &d ) const
  {
    Pipeline pipeline;
    Result result = static_cast<Result>( d.vkCreateComputePipelines( m_device, static_cast<VkPipelineCache>( pipelineCache ), 1 , reinterpret_cast<const VkComputePipelineCreateInfo*>( &createInfo ), reinterpret_cast<const VkAllocationCallbacks*>( static_cast<const AllocationCallbacks*>( allocator ) ), reinterpret_cast<VkPipeline*>( &pipeline ) ) );

    ObjectDestroy<Device,Dispatch> deleter( *this, allocator, d );
    return createResultValue<Pipeline,Dispatch>( result, pipeline, VULKAN_HPP_NAMESPACE_STRING"::Device::createComputePipelineUnique", deleter );
  }

which returns ResultValueType instead of just ResultValue, which looks like

  template <typename T>
  struct ResultValueType
  {
#ifdef VULKAN_HPP_NO_EXCEPTIONS
    typedef ResultValue<T>  type;
#else
    typedef T               type;
#endif
  };

This is important because if you then do not define VULKAN_HPP_NO_EXCEPTIONS which by default is not defined, the contained type, which in this case is UniqueHandle would directly be forwarded, causing the structured binding breakage.

Given that structured binding for called results have not been used anywhere else in vku, I would say the assumption of the project is that VULKAN_HPP_NO_EXCEPTIONS is not defined, so I think the change made in https://github.com/tomix1024/Vookoo/blob/2b0f8f218b634e43b976408968a440bf63e3bc8a/include/vku/vku.hpp#L1333 and https://github.com/tomix1024/Vookoo/blob/2b0f8f218b634e43b976408968a440bf63e3bc8a/include/vku/vku.hpp#L1041 should be reverted to be in line with all the other return call handles.