Browse Source

Vk: pass VkPhysicalDevice to Device::wrap().

It's needed in order to access Device::properties(), which is
mandatory for the driver workarounds happening in the next commit.
pull/494/head
Vladimír Vondruš 5 years ago
parent
commit
1a1eacc844
  1. 7
      src/Magnum/Vk/Device.cpp
  2. 34
      src/Magnum/Vk/Device.h
  3. 6
      src/Magnum/Vk/Test/DeviceVkTest.cpp

7
src/Magnum/Vk/Device.cpp

@ -612,7 +612,7 @@ constexpr Version KnownVersionsForExtensions[]{
} }
void Device::wrap(Instance& instance, const VkDevice handle, const Version version, const Containers::ArrayView<const Containers::StringView> enabledExtensions, const DeviceFeatures& enabledFeatures, const HandleFlags flags) { void Device::wrap(Instance& instance, const VkPhysicalDevice physicalDevice, const VkDevice handle, const Version version, const Containers::ArrayView<const Containers::StringView> enabledExtensions, const DeviceFeatures& enabledFeatures, const HandleFlags flags) {
CORRADE_ASSERT(!_handle, CORRADE_ASSERT(!_handle,
"Vk::Device::wrap(): device already created", ); "Vk::Device::wrap(): device already created", );
@ -620,12 +620,13 @@ void Device::wrap(Instance& instance, const VkDevice handle, const Version versi
repeating what was passed via the arguments */ repeating what was passed via the arguments */
_handle = handle; _handle = handle;
_flags = flags; _flags = flags;
_properties.emplace(DeviceProperties::wrap(instance, physicalDevice));
initializeExtensions(enabledExtensions); initializeExtensions(enabledExtensions);
initialize(instance, version, enabledFeatures); initialize(instance, version, enabledFeatures);
} }
void Device::wrap(Instance& instance, const VkDevice handle, const Version version, const std::initializer_list<Containers::StringView> enabledExtensions, const DeviceFeatures& enabledFeatures, const HandleFlags flags) { void Device::wrap(Instance& instance, const VkPhysicalDevice physicalDevice, const VkDevice handle, const Version version, const std::initializer_list<Containers::StringView> enabledExtensions, const DeviceFeatures& enabledFeatures, const HandleFlags flags) {
wrap(instance, handle, version, Containers::arrayView(enabledExtensions), enabledFeatures, flags); wrap(instance, physicalDevice, handle, version, Containers::arrayView(enabledExtensions), enabledFeatures, flags);
} }
Device::Device(Instance& instance, const DeviceCreateInfo& info): Device{NoCreate} { Device::Device(Instance& instance, const DeviceCreateInfo& info): Device{NoCreate} {

34
src/Magnum/Vk/Device.h

@ -209,15 +209,17 @@ class MAGNUM_VK_EXPORT Device {
public: public:
/** /**
* @brief Wrap existing Vulkan handle * @brief Wrap existing Vulkan handle
* @param instance Vulkan instance the device is created on * @param instance Vulkan instance the device is created on
* @param handle The @type_vk{Device} handle * @param physicalDevice Physical device the @type_vk{VkDevice} was
* @param version Vulkan version that's assumed to be used on the * created from. Used to populate @ref properties().
* device * @param handle The @type_vk{Device} handle
* @param version Vulkan version that's assumed to be used on
* the device
* @param enabledExtensions Extensions that are assumed to be enabled * @param enabledExtensions Extensions that are assumed to be enabled
* on the device * on the device
* @param enabledFeatures Features that are assumed to be enabled on * @param enabledFeatures Features that are assumed to be enabled on
* the device * the device
* @param flags Handle flags * @param flags Handle flags
* *
* <b></b> * <b></b>
* *
@ -230,14 +232,14 @@ class MAGNUM_VK_EXPORT Device {
* instance. See @ref Vk-Device-disabled-move for more * instance. See @ref Vk-Device-disabled-move for more
* information. * information.
* *
* The @p handle is expected to be originating from @p instance. The * The @p handle is expected to be originating from @p instance and
* @p version, @p enabledExtensions and @p enabledFeatures parameters * @p physicalDevice. The @p version, @p enabledExtensions and
* populate internal info about supported version, enabled extensions * @p enabledFeatures parameters populate internal info about supported
* and enabled features and will be reflected in * version, enabled extensions and enabled features and will be
* @ref isVersionSupported(), @ref isExtensionEnabled() and * reflected in @ref isVersionSupported(), @ref isExtensionEnabled()
* @ref enabledFeatures(), among other things. If @p enabledExtensions * and @ref enabledFeatures(), among other things. If
* / @p enabledFeatures is empty, the device will behave as if no * @p enabledExtensions / @p enabledFeatures is empty, the device will
* extensions / no features were enabled. * behave as if no extensions / no features were enabled.
* *
* Note that this function retrieves all device-specific Vulkan * Note that this function retrieves all device-specific Vulkan
* function pointers, which is a relatively costly operation. It's thus * function pointers, which is a relatively costly operation. It's thus
@ -249,10 +251,10 @@ class MAGNUM_VK_EXPORT Device {
* for different behavior. * for different behavior.
* @see @ref release() * @see @ref release()
*/ */
void wrap(Instance& instance, VkDevice handle, Version version, Containers::ArrayView<const Containers::StringView> enabledExtensions, const DeviceFeatures& enabledFeatures, HandleFlags flags = {}); void wrap(Instance& instance, VkPhysicalDevice physicalDevice, VkDevice handle, Version version, Containers::ArrayView<const Containers::StringView> enabledExtensions, const DeviceFeatures& enabledFeatures, HandleFlags flags = {});
/** @overload */ /** @overload */
void wrap(Instance& instance, VkDevice handle, Version version, std::initializer_list<Containers::StringView> enabledExtensions, const DeviceFeatures& enabledFeatures, HandleFlags flags = {}); void wrap(Instance& instance, VkPhysicalDevice physicalDevice, VkDevice handle, Version version, std::initializer_list<Containers::StringView> enabledExtensions, const DeviceFeatures& enabledFeatures, HandleFlags flags = {});
/** /**
* @brief Constructor * @brief Constructor

6
src/Magnum/Vk/Test/DeviceVkTest.cpp

@ -1081,7 +1081,7 @@ void DeviceVkTest::wrap() {
{ {
/* Wrapping should load the basic function pointers */ /* Wrapping should load the basic function pointers */
Device wrapped{NoCreate}; Device wrapped{NoCreate};
wrapped.wrap(instance2, device, Version::Vk11, { wrapped.wrap(instance2, deviceProperties, device, Version::Vk11, {
Extensions::EXT::debug_marker::string() Extensions::EXT::debug_marker::string()
}, DeviceFeature::RobustBufferAccess, HandleFlag::DestroyOnDestruction); }, DeviceFeature::RobustBufferAccess, HandleFlag::DestroyOnDestruction);
CORRADE_VERIFY(wrapped->DestroyDevice); CORRADE_VERIFY(wrapped->DestroyDevice);
@ -1113,7 +1113,7 @@ void DeviceVkTest::wrap() {
/* ...so we can wrap it again, non-owned, and then destroy it manually */ /* ...so we can wrap it again, non-owned, and then destroy it manually */
Device wrapped{NoCreate}; Device wrapped{NoCreate};
wrapped.wrap(instance2, device, Version::Vk10, {}, {}); wrapped.wrap(instance2, deviceProperties, device, Version::Vk10, {}, {});
CORRADE_VERIFY(wrapped->DestroyDevice); CORRADE_VERIFY(wrapped->DestroyDevice);
wrapped->DestroyDevice(device, nullptr); wrapped->DestroyDevice(device, nullptr);
} }
@ -1131,7 +1131,7 @@ void DeviceVkTest::wrapAlreadyCreated() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
device.wrap(instance(), {}, {}, {}, {}); device.wrap(instance(), {}, {}, {}, {}, {});
CORRADE_COMPARE(out.str(), "Vk::Device::wrap(): device already created\n"); CORRADE_COMPARE(out.str(), "Vk::Device::wrap(): device already created\n");
} }

Loading…
Cancel
Save