@@ -138,6 +138,16 @@ std::vector<vkb::detail::FeaturesChain::StructInfo>::const_iterator FeaturesChai
138138 });
139139}
140140
141+ void add_all_pnext_structures (std::vector<void *>& pNext_chain, void * structure_to_add) {
142+ auto pNext_iter = structure_to_add;
143+ while (pNext_iter != nullptr ) {
144+ pNext_chain.push_back (pNext_iter);
145+ VkBaseOutStructure out_structure{};
146+ memcpy (&out_structure, pNext_iter, sizeof (VkBaseOutStructure));
147+ pNext_iter = out_structure.pNext ;
148+ }
149+ }
150+
141151
142152class VulkanFunctions {
143153 private:
@@ -455,6 +465,17 @@ template <typename T> void setup_pNext_chain(T& structure, std::vector<void*> co
455465 structure.pNext = nullptr ;
456466 if (structs.empty ()) return ;
457467 for (size_t i = 0 ; i < structs.size () - 1 ; i++) {
468+ // Make sure we aren't adding the same struct more than once. We do not care about duplicate sTypes here.
469+ bool is_duplicate = false ;
470+ for (size_t j = 0 ; j != i; j++) {
471+ if (structs.at (i) == structs.at (j)) {
472+ is_duplicate = true ;
473+ break ;
474+ }
475+ }
476+ if (is_duplicate) {
477+ continue ;
478+ }
458479 VkBaseOutStructure out_structure{};
459480 memcpy (&out_structure, structs.at (i), sizeof (VkBaseOutStructure));
460481#if !defined(NDEBUG)
@@ -1568,11 +1589,17 @@ Result<uint32_t> Device::get_queue_index(QueueType type) const {
15681589 break ;
15691590 case QueueType::compute:
15701591 index = detail::get_separate_queue_index (queue_families, VK_QUEUE_COMPUTE_BIT , VK_QUEUE_TRANSFER_BIT );
1571- if (index == detail::QUEUE_INDEX_MAX_VALUE ) return Result<uint32_t >{ QueueError::compute_unavailable };
1592+ if (index == detail::QUEUE_INDEX_MAX_VALUE ) {
1593+ index = detail::get_first_queue_index (queue_families, VK_QUEUE_COMPUTE_BIT );
1594+ if (index == detail::QUEUE_INDEX_MAX_VALUE ) return Result<uint32_t >{ QueueError::compute_unavailable };
1595+ }
15721596 break ;
15731597 case QueueType::transfer:
15741598 index = detail::get_separate_queue_index (queue_families, VK_QUEUE_TRANSFER_BIT , VK_QUEUE_COMPUTE_BIT );
1575- if (index == detail::QUEUE_INDEX_MAX_VALUE ) return Result<uint32_t >{ QueueError::transfer_unavailable };
1599+ if (index == detail::QUEUE_INDEX_MAX_VALUE ) {
1600+ index = detail::get_first_queue_index (queue_families, VK_QUEUE_TRANSFER_BIT );
1601+ if (index == detail::QUEUE_INDEX_MAX_VALUE ) return Result<uint32_t >{ QueueError::transfer_unavailable };
1602+ }
15761603 break ;
15771604 default :
15781605 return Result<uint32_t >{ QueueError::invalid_queue_family_index };
@@ -1611,6 +1638,22 @@ Result<VkQueue> Device::get_dedicated_queue(QueueType type) const {
16111638 return out_queue;
16121639}
16131640
1641+ Result<std::pair<VkQueue, uint32_t >> Device::get_queue_and_index (QueueType type) const {
1642+ auto index = get_queue_index (type);
1643+ if (!index.has_value ()) return { index.error () };
1644+ VkQueue out_queue;
1645+ internal_table.fp_vkGetDeviceQueue (device, index.value (), 0 , &out_queue);
1646+ return std::pair<VkQueue, uint32_t >(out_queue, index.value ());
1647+ }
1648+
1649+ Result<std::pair<VkQueue, uint32_t >> Device::get_dedicated_queue_and_index (QueueType type) const {
1650+ auto index = get_dedicated_queue_index (type);
1651+ if (!index.has_value ()) return { index.error () };
1652+ VkQueue out_queue;
1653+ internal_table.fp_vkGetDeviceQueue (device, index.value (), 0 , &out_queue);
1654+ return std::pair<VkQueue, uint32_t >(out_queue, index.value ());
1655+ }
1656+
16141657// ---- Dispatch ---- //
16151658
16161659DispatchTable Device::make_table () const { return { device, fp_vkGetDeviceProcAddr }; }
@@ -1691,8 +1734,8 @@ Result<Device> DeviceBuilder::build() const {
16911734 }
16921735 }
16931736
1694- for (auto & pnext : info.pNext_chain ) {
1695- final_pnext_chain.push_back (pnext );
1737+ for (auto & pNext : info.pNext_chain ) {
1738+ final_pnext_chain.push_back (pNext );
16961739 }
16971740
16981741 detail::setup_pNext_chain (device_create_info, final_pnext_chain);
@@ -1744,6 +1787,10 @@ DeviceBuilder& DeviceBuilder::custom_queue_setup(std::span<const CustomQueueDesc
17441787 return *this ;
17451788}
17461789#endif
1790+ DeviceBuilder& DeviceBuilder::add_pNext (void * structure_to_add) {
1791+ detail::add_all_pnext_structures (info.pNext_chain , structure_to_add);
1792+ return *this ;
1793+ }
17471794
17481795// ---- Swapchain ---- //
17491796
@@ -1875,8 +1922,8 @@ SwapchainBuilder::SwapchainBuilder(Device const& device) {
18751922 auto present = device.get_queue_index (QueueType::present);
18761923 auto graphics = device.get_queue_index (QueueType::graphics);
18771924 assert (graphics.has_value () && present.has_value () && " Graphics and Present queue indexes must be valid" );
1878- info.graphics_queue_index = present .value ();
1879- info.present_queue_index = graphics .value ();
1925+ info.graphics_queue_index = graphics .value ();
1926+ info.present_queue_index = present .value ();
18801927}
18811928SwapchainBuilder::SwapchainBuilder (Device const & device, VkSurfaceKHR const surface) {
18821929 info.physical_device = device.physical_device .physical_device ;
@@ -2146,6 +2193,10 @@ SwapchainBuilder& SwapchainBuilder::set_allocation_callbacks(VkAllocationCallbac
21462193 info.allocation_callbacks = callbacks;
21472194 return *this ;
21482195}
2196+ SwapchainBuilder& SwapchainBuilder::add_pNext (void * structure_to_add) {
2197+ detail::add_all_pnext_structures (info.pNext_chain , structure_to_add);
2198+ return *this ;
2199+ }
21492200SwapchainBuilder& SwapchainBuilder::set_image_usage_flags (VkImageUsageFlags usage_flags) {
21502201 info.image_usage_flags = usage_flags;
21512202 return *this ;
0 commit comments