Browse Source

Vk: and thus VulkanTester doesn't need a DeviceProperties instance.

pull/234/head
Vladimír Vondruš 6 years ago
parent
commit
c402c97307
  1. 8
      src/Magnum/Vk/Test/CommandBufferVkTest.cpp
  2. 10
      src/Magnum/Vk/Test/CommandPoolVkTest.cpp
  3. 6
      src/Magnum/Vk/Test/ImageVkTest.cpp
  4. 6
      src/Magnum/Vk/Test/MemoryVkTest.cpp
  5. 9
      src/Magnum/Vk/VulkanTester.cpp
  6. 27
      src/Magnum/Vk/VulkanTester.h

8
src/Magnum/Vk/Test/CommandBufferVkTest.cpp

@ -52,7 +52,7 @@ CommandBufferVkTest::CommandBufferVkTest() {
void CommandBufferVkTest::construct() { void CommandBufferVkTest::construct() {
CommandPool pool{device(), CommandPoolCreateInfo{ CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics)}}; device().properties().pickQueueFamily(QueueFlag::Graphics)}};
{ {
CommandBuffer buffer = pool.allocate(); CommandBuffer buffer = pool.allocate();
@ -66,7 +66,7 @@ void CommandBufferVkTest::construct() {
void CommandBufferVkTest::constructMove() { void CommandBufferVkTest::constructMove() {
CommandPool pool{device(), CommandPoolCreateInfo{ CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics)}}; device().properties().pickQueueFamily(QueueFlag::Graphics)}};
CommandBuffer a = pool.allocate(); CommandBuffer a = pool.allocate();
VkCommandBuffer handle = a.handle(); VkCommandBuffer handle = a.handle();
@ -89,7 +89,7 @@ void CommandBufferVkTest::constructMove() {
void CommandBufferVkTest::wrap() { void CommandBufferVkTest::wrap() {
CommandPool pool{device(), CommandPoolCreateInfo{ CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics)}}; device().properties().pickQueueFamily(QueueFlag::Graphics)}};
VkCommandBuffer buffer{}; VkCommandBuffer buffer{};
VkCommandBufferAllocateInfo info{}; VkCommandBufferAllocateInfo info{};
@ -111,7 +111,7 @@ void CommandBufferVkTest::wrap() {
void CommandBufferVkTest::reset() { void CommandBufferVkTest::reset() {
CommandPool pool{device(), CommandPoolCreateInfo{ CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics), device().properties().pickQueueFamily(QueueFlag::Graphics),
CommandPoolCreateInfo::Flag::ResetCommandBuffer}}; CommandPoolCreateInfo::Flag::ResetCommandBuffer}};
CommandBuffer a = pool.allocate(); CommandBuffer a = pool.allocate();

10
src/Magnum/Vk/Test/CommandPoolVkTest.cpp

@ -55,7 +55,7 @@ CommandPoolVkTest::CommandPoolVkTest() {
void CommandPoolVkTest::construct() { void CommandPoolVkTest::construct() {
{ {
CommandPool pool{device(), CommandPoolCreateInfo{ CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics), device().properties().pickQueueFamily(QueueFlag::Graphics),
CommandPoolCreateInfo::Flag::ResetCommandBuffer}}; CommandPoolCreateInfo::Flag::ResetCommandBuffer}};
CORRADE_VERIFY(pool.handle()); CORRADE_VERIFY(pool.handle());
CORRADE_COMPARE(pool.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(pool.handleFlags(), HandleFlag::DestroyOnDestruction);
@ -67,7 +67,7 @@ void CommandPoolVkTest::construct() {
void CommandPoolVkTest::constructMove() { void CommandPoolVkTest::constructMove() {
CommandPool a{device(), CommandPoolCreateInfo{ CommandPool a{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics), device().properties().pickQueueFamily(QueueFlag::Graphics),
CommandPoolCreateInfo::Flag::Transient}}; CommandPoolCreateInfo::Flag::Transient}};
VkCommandPool handle = a.handle(); VkCommandPool handle = a.handle();
@ -91,7 +91,7 @@ void CommandPoolVkTest::wrap() {
VkCommandPool pool{}; VkCommandPool pool{};
CORRADE_COMPARE(Result(device()->CreateCommandPool(device(), CORRADE_COMPARE(Result(device()->CreateCommandPool(device(),
CommandPoolCreateInfo{ CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics)}, device().properties().pickQueueFamily(QueueFlag::Graphics)},
nullptr, &pool)), Result::Success); nullptr, &pool)), Result::Success);
CORRADE_VERIFY(pool); CORRADE_VERIFY(pool);
@ -106,7 +106,7 @@ void CommandPoolVkTest::wrap() {
void CommandPoolVkTest::reset() { void CommandPoolVkTest::reset() {
CommandPool pool{device(), CommandPoolCreateInfo{ CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics)}}; device().properties().pickQueueFamily(QueueFlag::Graphics)}};
pool.reset(CommandPoolResetFlag::ReleaseResources); pool.reset(CommandPoolResetFlag::ReleaseResources);
@ -116,7 +116,7 @@ void CommandPoolVkTest::reset() {
void CommandPoolVkTest::allocate() { void CommandPoolVkTest::allocate() {
CommandPool pool{device(), CommandPoolCreateInfo{ CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics)}}; device().properties().pickQueueFamily(QueueFlag::Graphics)}};
CommandBuffer a = pool.allocate(CommandBufferLevel::Secondary); CommandBuffer a = pool.allocate(CommandBufferLevel::Secondary);
CORRADE_VERIFY(a.handle()); CORRADE_VERIFY(a.handle());

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

@ -164,7 +164,7 @@ void ImageVkTest::constructMove() {
/* Verify that also the dedicated memory gets moved */ /* Verify that also the dedicated memory gets moved */
MemoryRequirements requirements = a.memoryRequirements(); MemoryRequirements requirements = a.memoryRequirements();
a.bindDedicatedMemory(Vk::Memory{device(), Vk::MemoryAllocateInfo{requirements.size(), a.bindDedicatedMemory(Vk::Memory{device(), Vk::MemoryAllocateInfo{requirements.size(),
deviceProperties().pickMemory(Vk::MemoryFlag::DeviceLocal, requirements.memories())}}); device().properties().pickMemory(Vk::MemoryFlag::DeviceLocal, requirements.memories())}});
VkDeviceMemory memoryHandle = a.dedicatedMemory().handle(); VkDeviceMemory memoryHandle = a.dedicatedMemory().handle();
Image b = std::move(a); Image b = std::move(a);
@ -230,7 +230,7 @@ void ImageVkTest::bindMemory() {
Vk::Memory memory{device(), Vk::MemoryAllocateInfo{ Vk::Memory memory{device(), Vk::MemoryAllocateInfo{
requirements.size() + offset, requirements.size() + offset,
deviceProperties().pickMemory(Vk::MemoryFlag::DeviceLocal, requirements.memories())}}; device().properties().pickMemory(Vk::MemoryFlag::DeviceLocal, requirements.memories())}};
image.bindMemory(memory, offset); image.bindMemory(memory, offset);
CORRADE_VERIFY(!image.hasDedicatedMemory()); CORRADE_VERIFY(!image.hasDedicatedMemory());
@ -245,7 +245,7 @@ void ImageVkTest::bindDedicatedMemory() {
Vk::Memory memory{device(), Vk::MemoryAllocateInfo{ Vk::Memory memory{device(), Vk::MemoryAllocateInfo{
requirements.size(), requirements.size(),
deviceProperties().pickMemory(Vk::MemoryFlag::DeviceLocal, requirements.memories())}}; device().properties().pickMemory(Vk::MemoryFlag::DeviceLocal, requirements.memories())}};
VkDeviceMemory handle = memory.handle(); VkDeviceMemory handle = memory.handle();
CORRADE_VERIFY(handle); CORRADE_VERIFY(handle);

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

@ -48,13 +48,13 @@ MemoryVkTest::MemoryVkTest() {
} }
void MemoryVkTest::construct() { void MemoryVkTest::construct() {
Memory memory{device(), MemoryAllocateInfo{1024*1024, deviceProperties().pickMemory(MemoryFlag::DeviceLocal)}}; Memory memory{device(), MemoryAllocateInfo{1024*1024, device().properties().pickMemory(MemoryFlag::DeviceLocal)}};
CORRADE_VERIFY(memory.handle()); CORRADE_VERIFY(memory.handle());
CORRADE_COMPARE(memory.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(memory.handleFlags(), HandleFlag::DestroyOnDestruction);
} }
void MemoryVkTest::constructMove() { void MemoryVkTest::constructMove() {
Memory a{device(), MemoryAllocateInfo{1024*1024, deviceProperties().pickMemory(MemoryFlag::DeviceLocal)}}; Memory a{device(), MemoryAllocateInfo{1024*1024, device().properties().pickMemory(MemoryFlag::DeviceLocal)}};
VkDeviceMemory handle = a.handle(); VkDeviceMemory handle = a.handle();
Memory b = std::move(a); Memory b = std::move(a);
@ -76,7 +76,7 @@ void MemoryVkTest::constructMove() {
void MemoryVkTest::wrap() { void MemoryVkTest::wrap() {
VkDeviceMemory memory{}; VkDeviceMemory memory{};
CORRADE_COMPARE(Result(device()->AllocateMemory(device(), CORRADE_COMPARE(Result(device()->AllocateMemory(device(),
MemoryAllocateInfo{1024*1024, deviceProperties().pickMemory(MemoryFlag::DeviceLocal)}, MemoryAllocateInfo{1024*1024, device().properties().pickMemory(MemoryFlag::DeviceLocal)},
nullptr, &memory)), Result::Success); nullptr, &memory)), Result::Success);
CORRADE_VERIFY(memory); CORRADE_VERIFY(memory);

9
src/Magnum/Vk/VulkanTester.cpp

@ -33,9 +33,10 @@
namespace Magnum { namespace Vk { namespace Magnum { namespace Vk {
VulkanTester::VulkanTester(): VulkanTester{NoCreate} { VulkanTester::VulkanTester(): VulkanTester{NoCreate} {
*_deviceProperties = pickDevice(_instance); DeviceProperties deviceProperties = pickDevice(_instance);
_device = Vk::Device{_instance, Vk::DeviceCreateInfo{*_deviceProperties} UnsignedInt graphicsQueue = deviceProperties.pickQueueFamily(Vk::QueueFlag::Graphics);
.addQueues(_deviceProperties->pickQueueFamily(Vk::QueueFlag::Graphics), {0.0f}, {_queue}) _device = Vk::Device{_instance, Vk::DeviceCreateInfo{std::move(deviceProperties)}
.addQueues(graphicsQueue, {0.0f}, {_queue})
}; };
} }
@ -45,6 +46,6 @@ VulkanTester::VulkanTester(NoCreateT): VulkanTester{NoCreate, NoCreate} {
}; };
} }
VulkanTester::VulkanTester(NoCreateT, NoCreateT): TestSuite::Tester{TestSuite::Tester::TesterConfiguration{}.setSkippedArgumentPrefixes({"magnum"})}, _instance{NoCreate}, _device{NoCreate}, _deviceProperties{Containers::InPlaceInit, NoCreate}, _queue{NoCreate} {} VulkanTester::VulkanTester(NoCreateT, NoCreateT): TestSuite::Tester{TestSuite::Tester::TesterConfiguration{}.setSkippedArgumentPrefixes({"magnum"})}, _instance{NoCreate}, _device{NoCreate}, _queue{NoCreate} {}
}} }}

27
src/Magnum/Vk/VulkanTester.h

@ -77,8 +77,7 @@ See @ref building, @ref cmake and @ref testsuite for more information.
The class implicitly creates a Vulkan @ref Instance and @ref Device with The class implicitly creates a Vulkan @ref Instance and @ref Device with
default layers and extensions and one graphics queue. These are then available default layers and extensions and one graphics queue. These are then available
through @ref instance(), @ref device(), @ref deviceProperties() and through @ref instance(), @ref device() and @ref queue() getters.
@ref queue() getters.
If you want to create a custom device, use the @ref VulkanTester(NoCreateT) If you want to create a custom device, use the @ref VulkanTester(NoCreateT)
constructor. You can then move the device and queue instances to the getters to constructor. You can then move the device and queue instances to the getters to
@ -93,8 +92,7 @@ class VulkanTester: public TestSuite::Tester {
* *
* Creates an instance using implicit settings, picks a default device * Creates an instance using implicit settings, picks a default device
* and creates a graphics queue on that device. These are then exposed * and creates a graphics queue on that device. These are then exposed
* through @ref instance(), @ref device(), @ref deviceProperties() and * through @ref instance(), @ref device() and @ref queue() getters.
* @ref queue() getters.
*/ */
explicit VulkanTester(); explicit VulkanTester();
@ -102,8 +100,8 @@ class VulkanTester: public TestSuite::Tester {
* @brief Construct without creating a device * @brief Construct without creating a device
* *
* Use the @ref instance() to pick and create a device. You can then * Use the @ref instance() to pick and create a device. You can then
* move it to @ref device(), @ref deviceProperties() and @ref queue() * move it to @ref device() and @ref queue() to have them accessible
* to have them accessible through common interfaces again. * through common interfaces again.
*/ */
explicit VulkanTester(NoCreateT); explicit VulkanTester(NoCreateT);
@ -111,8 +109,8 @@ class VulkanTester: public TestSuite::Tester {
* @brief Construct without creating an instance or device * @brief Construct without creating an instance or device
* *
* Leaves the initialization completely on the user. You can move the * Leaves the initialization completely on the user. You can move the
* instances to @ref instance(), @ref device(), @ref deviceProperties() * instances to @ref instance(), @ref device() and @ref queue() to have
* and @ref queue() to have them accessible through common interfaces. * them accessible through common interfaces.
*/ */
explicit VulkanTester(NoCreateT, NoCreateT); explicit VulkanTester(NoCreateT, NoCreateT);
@ -136,22 +134,12 @@ class VulkanTester: public TestSuite::Tester {
*/ */
Device& device() { return _device; } Device& device() { return _device; }
/**
* @brief Vulkan device properties
*
* In case the class was constructed using @ref VulkanTester(NoCreateT)
* or @ref VulkanTester(NoCreateT, NoCreateT), this instance is
* initially not created. Move a created instance onto it to make it
* useful.
*/
DeviceProperties& deviceProperties() { return *_deviceProperties; }
/** /**
* @brief Vulkan queue * @brief Vulkan queue
* *
* In case the calss was constructed using @ref VulkanTester(), the * In case the calss was constructed using @ref VulkanTester(), the
* queue corresponds to @ref DeviceProperties::pickQueueFamily() with * queue corresponds to @ref DeviceProperties::pickQueueFamily() with
* @ref QueueFlag::Graphics called on @ref deviceProperties(). * @ref QueueFlag::Graphics called on @ref Device::properties().
* *
* In case the class was constructed using @ref VulkanTester(NoCreateT) * In case the class was constructed using @ref VulkanTester(NoCreateT)
* or @ref VulkanTester(NoCreateT, NoCreateT), this instance is * or @ref VulkanTester(NoCreateT, NoCreateT), this instance is
@ -163,7 +151,6 @@ class VulkanTester: public TestSuite::Tester {
private: private:
Instance _instance; Instance _instance;
Device _device; Device _device;
Containers::Pointer<DeviceProperties> _deviceProperties;
Queue _queue; Queue _queue;
}; };

Loading…
Cancel
Save