Browse Source

Vk: convenience overload for DeviceProperties::pickMemory().

pull/234/head
Vladimír Vondruš 6 years ago
parent
commit
fc08125661
  1. 8
      src/Magnum/Vk/DeviceProperties.cpp
  2. 16
      src/Magnum/Vk/DeviceProperties.h
  3. 6
      src/Magnum/Vk/Test/DevicePropertiesVkTest.cpp

8
src/Magnum/Vk/DeviceProperties.cpp

@ -244,6 +244,10 @@ UnsignedInt DeviceProperties::pickMemory(const MemoryFlags requiredFlags, const
std::exit(1); /* LCOV_EXCL_LINE */
}
UnsignedInt DeviceProperties::pickMemory(const MemoryFlags requiredFlags, const UnsignedInt memories) {
return pickMemory(requiredFlags, {}, memories);
}
Containers::Optional<UnsignedInt> DeviceProperties::tryPickMemory(const MemoryFlags requiredFlags, const MemoryFlags preferredFlags, const UnsignedInt memories) {
const VkPhysicalDeviceMemoryProperties properties = memoryProperties().memoryProperties;
@ -277,6 +281,10 @@ Containers::Optional<UnsignedInt> DeviceProperties::tryPickMemory(const MemoryFl
return {};
}
Containers::Optional<UnsignedInt> DeviceProperties::tryPickMemory(const MemoryFlags requiredFlags, const UnsignedInt memories) {
return tryPickMemory(requiredFlags, {}, memories);
}
Containers::Array<DeviceProperties> enumerateDevices(Instance& instance) {
/* Retrieve total device count */
UnsignedInt count;

16
src/Magnum/Vk/DeviceProperties.h

@ -455,6 +455,14 @@ class MAGNUM_VK_EXPORT DeviceProperties {
*/
UnsignedInt pickMemory(MemoryFlags requiredFlags, MemoryFlags preferredFlags = {}, UnsignedInt memories = ~UnsignedInt{});
/**
* @overload
*
* Equivalent to calling @ref pickMemory(MemoryFlags, MemoryFlags, UnsignedInt)
* with empty @p preferredFlags.
*/
UnsignedInt pickMemory(MemoryFlags requiredFlags, UnsignedInt memories);
/**
* @brief Try to pick a memory type satisfying given flags
*
@ -464,6 +472,14 @@ class MAGNUM_VK_EXPORT DeviceProperties {
*/
Containers::Optional<UnsignedInt> tryPickMemory(MemoryFlags requiredFlags, MemoryFlags preferredFlags = {}, UnsignedInt memories = ~UnsignedInt{});
/**
* @overload
*
* Equivalent to calling @ref tryPickMemory(MemoryFlags, MemoryFlags, UnsignedInt)
* with empty @p preferredFlags.
*/
Containers::Optional<UnsignedInt> tryPickMemory(MemoryFlags requiredFlags, UnsignedInt memories);
private:
friend Implementation::InstanceState;

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

@ -444,8 +444,10 @@ void DevicePropertiesVkTest::memoryTypesPick() {
MemoryFlag::HostVisible|MemoryFlag::HostCoherent,
TestSuite::Compare::GreaterOrEqual);
/* Pick should return the same ID, and shouldn't exit */
/* Pick should return the same ID, and shouldn't exit. Test also the
overload with no preferred flags. */
CORRADE_COMPARE(devices[0].pickMemory(MemoryFlag::HostVisible|MemoryFlag::HostCoherent), id);
CORRADE_COMPARE(devices[0].pickMemory(MemoryFlag::HostVisible|MemoryFlag::HostCoherent, ~UnsignedInt{}), id);
/* If we put the same into preferred flags and leave the required empty, it
should pick the same (the first one as well) */
@ -482,8 +484,10 @@ void DevicePropertiesVkTest::memoryTypesPickFailed() {
Error redirectError{&out};
CORRADE_VERIFY(!devices[0].tryPickMemory(MemoryFlag(0xc0ffeee0)));
CORRADE_VERIFY(!devices[0].tryPickMemory({}, {}, 0));
CORRADE_VERIFY(!devices[0].tryPickMemory({}, 0));
CORRADE_COMPARE(out.str(), Utility::formatString(
"Vk::DeviceProperties::tryPickMemory(): no Vk::MemoryFlag(0xc0ffeee0) found among {} considered memory types\n"
"Vk::DeviceProperties::tryPickMemory(): no Vk::MemoryFlags{{}} found among 0 considered memory types\n"
"Vk::DeviceProperties::tryPickMemory(): no Vk::MemoryFlags{{}} found among 0 considered memory types\n", devices[0].memoryCount()));
}

Loading…
Cancel
Save