@@ -82,11 +82,13 @@ class Device
8282 * @param surface The surface
8383 * @param debug_utils The debug utils to be associated to this device
8484 * @param requested_extensions (Optional) List of required device extensions and whether support is optional or not
85+ * @param request_gpu_features (Optional) A function that will be called to request specific gpu features before device creation
8586 */
86- Device (PhysicalDevice<bindingType> &gpu,
87- SurfaceType surface,
88- std::unique_ptr<DebugUtilsType> &&debug_utils,
89- std::unordered_map<const char *, bool > const &requested_extensions = {});
87+ Device (PhysicalDevice<bindingType> &gpu,
88+ SurfaceType surface,
89+ std::unique_ptr<DebugUtilsType> &&debug_utils,
90+ std::unordered_map<const char *, bool > const &requested_extensions = {},
91+ std::function<void (vkb::core::PhysicalDevice<bindingType> &)> request_gpu_features = {});
9092
9193 /* *
9294 * @brief Device constructor
@@ -134,7 +136,7 @@ class Device
134136 void flush_command_buffer_impl (
135137 vk::Device device, vk::CommandBuffer command_buffer, vk::Queue queue, bool free = true , vk::Semaphore signal_semaphore = nullptr ) const ;
136138 vkb::core::HPPQueue const &get_queue_by_flags_impl (vk::QueueFlags queue_flags, uint32_t queue_index) const ;
137- void init (std::unordered_map<const char *, bool > const &requested_extensions);
139+ void init (std::unordered_map<const char *, bool > const &requested_extensions, std::function< void (vkb::core::PhysicalDevice<bindingType> &)> request_gpu_features );
138140
139141 private:
140142 std::unique_ptr<vkb::core::CommandPoolCpp> command_pool;
@@ -161,23 +163,25 @@ namespace core
161163{
162164
163165template <>
164- inline Device<vkb::BindingType::Cpp>::Device(vkb::core::PhysicalDeviceCpp &gpu,
165- vk::SurfaceKHR surface,
166- std::unique_ptr<vkb::core::HPPDebugUtils> &&debug_utils,
167- std::unordered_map<const char *, bool > const &requested_extensions) :
166+ inline Device<vkb::BindingType::Cpp>::Device(vkb::core::PhysicalDeviceCpp &gpu,
167+ vk::SurfaceKHR surface,
168+ std::unique_ptr<vkb::core::HPPDebugUtils> &&debug_utils,
169+ std::unordered_map<const char *, bool > const &requested_extensions,
170+ std::function<void (vkb::core::PhysicalDeviceCpp &)> request_gpu_features) :
168171 vkb::core::VulkanResourceCpp<vk::Device>{nullptr , this }, debug_utils{std::move (debug_utils)}, gpu{gpu}, resource_cache{*this }, surface(surface)
169172{
170- init (requested_extensions);
173+ init (requested_extensions, request_gpu_features );
171174}
172175
173176template <>
174- inline Device<vkb::BindingType::C>::Device(vkb::core::PhysicalDeviceC &gpu,
175- VkSurfaceKHR surface,
176- std::unique_ptr<vkb::DebugUtils> &&debug_utils,
177- std::unordered_map<const char *, bool > const &requested_extensions) :
177+ inline Device<vkb::BindingType::C>::Device(vkb::core::PhysicalDeviceC &gpu,
178+ VkSurfaceKHR surface,
179+ std::unique_ptr<vkb::DebugUtils> &&debug_utils,
180+ std::unordered_map<const char *, bool > const &requested_extensions,
181+ std::function<void (vkb::core::PhysicalDeviceC &)> request_gpu_features) :
178182 vkb::core::VulkanResourceC<VkDevice>{VK_NULL_HANDLE, this }, debug_utils{reinterpret_cast <vkb::core::HPPDebugUtils *>(debug_utils.release ())}, gpu{reinterpret_cast <vkb::core::PhysicalDeviceCpp &>(gpu)}, resource_cache{*reinterpret_cast <vkb::core::DeviceCpp *>(this )}, surface(static_cast <vk::SurfaceKHR>(surface))
179183{
180- init (requested_extensions);
184+ init (requested_extensions, request_gpu_features );
181185}
182186
183187template <>
@@ -615,7 +619,7 @@ vkb::core::HPPQueue const &Device<bindingType>::get_queue_by_flags_impl(vk::Queu
615619}
616620
617621template <vkb::BindingType bindingType>
618- inline void Device<bindingType>::init(std::unordered_map<const char *, bool > const &requested_extensions)
622+ inline void Device<bindingType>::init(std::unordered_map<const char *, bool > const &requested_extensions, std::function< void (vkb::core::PhysicalDevice<bindingType> &)> request_gpu_features )
619623{
620624 LOGI (" Selected GPU: {}" , *gpu.get_properties ().deviceName );
621625
@@ -719,6 +723,15 @@ inline void Device<bindingType>::init(std::unordered_map<const char *, bool> con
719723 }
720724 }
721725
726+ if constexpr (bindingType == vkb::BindingType::Cpp)
727+ {
728+ request_gpu_features (gpu);
729+ }
730+ else
731+ {
732+ request_gpu_features (reinterpret_cast <vkb::core::PhysicalDeviceC &>(gpu));
733+ }
734+
722735 // Latest requested feature will have the pNext's all set up for device creation.
723736 vk::DeviceCreateInfo create_info{.pNext = gpu.get_extension_feature_chain (),
724737 .queueCreateInfoCount = static_cast <uint32_t >(queue_create_infos.size ()),
0 commit comments