diff --git a/src/Magnum/Vk/CMakeLists.txt b/src/Magnum/Vk/CMakeLists.txt index f5e55f7ec..ed1896432 100644 --- a/src/Magnum/Vk/CMakeLists.txt +++ b/src/Magnum/Vk/CMakeLists.txt @@ -34,6 +34,7 @@ set(MagnumVk_SRCS Framebuffer.cpp Handle.cpp Instance.cpp + Queue.cpp Result.cpp Shader.cpp Version.cpp diff --git a/src/Magnum/Vk/Queue.cpp b/src/Magnum/Vk/Queue.cpp new file mode 100644 index 000000000..0f1cb52da --- /dev/null +++ b/src/Magnum/Vk/Queue.cpp @@ -0,0 +1,42 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Queue.h" + +#include +#include + +namespace Magnum { namespace Vk { + +Queue Queue::wrap(Device& device, VkQueue handle) { + Queue out{NoCreate}; + out._device = &device; + out._handle = handle; + return out; +} + +Queue::Queue(NoCreateT): _device{}, _handle{} {} + +}} diff --git a/src/Magnum/Vk/Queue.h b/src/Magnum/Vk/Queue.h index 3eca8ca25..af4c2195c 100644 --- a/src/Magnum/Vk/Queue.h +++ b/src/Magnum/Vk/Queue.h @@ -57,12 +57,7 @@ class MAGNUM_VK_EXPORT Queue { * be destroyed at the end, so there's no equivalent of e.g. * @ref Device::release() or @ref Device::handleFlags(). */ - static Queue wrap(Device& device, VkQueue handle) { - Queue out{NoCreate}; - out._device = &device; - out._handle = handle; - return out; - } + static Queue wrap(Device& device, VkQueue handle); /** * @brief Construct without creating the instance @@ -70,7 +65,7 @@ class MAGNUM_VK_EXPORT Queue { * This is the expected way to create a queue that's later populated * on @ref Device creation through @ref DeviceCreateInfo::addQueues(). */ - explicit Queue(NoCreateT): _device{}, _handle{} {} + explicit Queue(NoCreateT); /** @brief Underlying @type_vk{Queue} handle */ VkQueue handle() { return _handle; } diff --git a/src/Magnum/Vk/Test/CMakeLists.txt b/src/Magnum/Vk/Test/CMakeLists.txt index 64d1760b6..adac619c1 100644 --- a/src/Magnum/Vk/Test/CMakeLists.txt +++ b/src/Magnum/Vk/Test/CMakeLists.txt @@ -42,6 +42,7 @@ corrade_add_test(VkInstanceTest InstanceTest.cpp LIBRARIES MagnumVk) corrade_add_test(VkIntegrationTest IntegrationTest.cpp LIBRARIES MagnumVk) corrade_add_test(VkLayerPropertiesTest LayerPropertiesTest.cpp LIBRARIES MagnumVk) corrade_add_test(VkMemoryTest MemoryTest.cpp LIBRARIES MagnumVkTestLib) +corrade_add_test(VkQueueTest QueueTest.cpp LIBRARIES MagnumVk) corrade_add_test(VkResultTest ResultTest.cpp LIBRARIES MagnumVk) corrade_add_test(VkRenderPassTest RenderPassTest.cpp LIBRARIES MagnumVkTestLib) corrade_add_test(VkShaderTest ShaderTest.cpp LIBRARIES MagnumVk) @@ -133,6 +134,7 @@ set_target_properties( VkIntegrationTest VkLayerPropertiesTest VkMemoryTest + VkQueueTest VkResultTest VkRenderPassTest VkShaderTest diff --git a/src/Magnum/Vk/Test/QueueTest.cpp b/src/Magnum/Vk/Test/QueueTest.cpp new file mode 100644 index 000000000..1de73540e --- /dev/null +++ b/src/Magnum/Vk/Test/QueueTest.cpp @@ -0,0 +1,70 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include "Magnum/Vk/Device.h" +#include "Magnum/Vk/Queue.h" + +namespace Magnum { namespace Vk { namespace Test { namespace { + +struct QueueTest: TestSuite::Tester { + explicit QueueTest(); + + void constructNoCreate(); + + void wrap(); +}; + +QueueTest::QueueTest() { + addTests({&QueueTest::constructNoCreate, + + &QueueTest::wrap}); +} + +void QueueTest::constructNoCreate() { + { + Queue queue{NoCreate}; + CORRADE_VERIFY(!queue.handle()); + } + + /* Implicit construction is not allowed */ + CORRADE_VERIFY(!(std::is_convertible::value)); +} + +void QueueTest::wrap() { + /* Queues are not getting destroyed in any way, so it's enough to do it in + a non-Vulkan-enabled test */ + + Device device{NoCreate}; + auto vkQueue = reinterpret_cast(0xbadcafe); + + Queue queue = Queue::wrap(device, vkQueue); + CORRADE_COMPARE(queue.handle(), vkQueue); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::Vk::Test::QueueTest)